diff --git a/.clang-format b/.clang-format index 4e081ec..f0cdb58 100644 --- a/.clang-format +++ b/.clang-format @@ -12,7 +12,7 @@ BraceWrapping: AfterUnion: true BeforeWhile: true -ColumnLimit: 120 +ColumnLimit: 130 PointerAlignment: Left UseTab: Always BreakConstructorInitializers: BeforeComma @@ -23,8 +23,6 @@ IncludeBlocks: Regroup IncludeCategories: - Regex: '^"(box3d\/)' Priority: 2 - - Regex: '^:Debug>") +set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") if (MSVC OR APPLE OR UNIX) option(BOX3D_SANITIZE "Enable sanitizers for some builds" OFF) @@ -33,16 +41,15 @@ if (MSVC OR APPLE OR UNIX) add_link_options("$<$:/INCREMENTAL:NO>") elseif(APPLE) # more sanitizers on Apple clang - # UBSan recovers by default, no-recover makes the first report fatal so CI fails if(BOX3D_SANITIZER_TYPE STREQUAL "thread") add_compile_options(-fsanitize=thread -fno-omit-frame-pointer) add_link_options(-fsanitize=thread) elseif(BOX3D_SANITIZER_TYPE STREQUAL "undefined") - add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) + add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) add_link_options(-fsanitize=undefined) else() # default to address sanitizer - add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined -fno-sanitize-recover=all) + add_compile_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined) add_link_options(-fsanitize=address -fsanitize-address-use-after-scope -fsanitize=undefined) endif() elseif(UNIX) @@ -53,19 +60,19 @@ if (MSVC OR APPLE OR UNIX) add_compile_options(-fsanitize=thread -fno-omit-frame-pointer -fPIE) add_link_options(-fsanitize=thread -pie) elseif(BOX3D_SANITIZER_TYPE STREQUAL "undefined") - add_compile_options(-fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) + add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer) add_link_options(-fsanitize=undefined) elseif(BOX3D_SANITIZER_TYPE STREQUAL "memory") add_compile_options(-fsanitize=memory -fno-omit-frame-pointer) add_link_options(-fsanitize=memory) else() # default to address sanitizer - add_compile_options(-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) - add_link_options(-fsanitize=address -fsanitize=undefined) + add_compile_options(-fsanitize=address -fno-omit-frame-pointer) + add_link_options(-fsanitize=address) endif() endif() else() - if(MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" AND PROJECT_IS_TOP_LEVEL) + if(MSVC) # enable hot reloading add_compile_options("$<$:/ZI>") add_link_options("$<$:/INCREMENTAL>") @@ -75,71 +82,27 @@ endif() # Deterministic math # https://box2d.org/posts/2024/08/determinism/ -# Contraction into FMA is the one value changing transform enabled by default, and whether -# it fires depends on the target. Test the compiler, not the platform, so every gcc and -# clang gets the flag including a clang that is neither MinGW nor clang-cl. -if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang") - if (CMAKE_C_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC") - # clang-cl defaults to contraction on and silently drops the GNU spelling - add_compile_options(/clang:-ffp-contract=off) - else() - add_compile_options(-ffp-contract=off) - endif() +if (MINGW OR APPLE OR UNIX) + add_compile_options(-ffp-contract=off) endif() option(BOX3D_DISABLE_SIMD "Disable SIMD math (slower)" OFF) 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. -if(PROJECT_IS_TOP_LEVEL) - option(BOX3D_PROFILE "Enable profiling with Tracy" OFF) - option(BOX3D_VALIDATE "Enable heavy validation" ON) -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 -# consumer keeps control of its own threading model. -if (EMSCRIPTEN AND PROJECT_IS_TOP_LEVEL) - set(EMSCRIPTEN_PTHREADS_COMPILER_FLAGS "-pthread -s USE_PTHREADS=1") - set(EMSCRIPTEN_PTHREADS_LINKER_FLAGS "${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS} -s ALLOW_MEMORY_GROWTH") - string(APPEND CMAKE_C_FLAGS " ${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS}") - string(APPEND CMAKE_CXX_FLAGS " ${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS}") - string(APPEND CMAKE_EXE_LINKER_FLAGS " ${EMSCRIPTEN_PTHREADS_LINKER_FLAGS}") -endif() - set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON) -# Leaving this here for testing -# set(CMAKE_VERBOSE_MAKEFILE ON) +set(CMAKE_VERBOSE_MAKEFILE ON) -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") +# 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") - # 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() +# 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() include(FetchContent) @@ -151,6 +114,8 @@ if(PROJECT_IS_TOP_LEVEL) option(BOX3D_SAMPLES "Build the Box3D samples" ON) option(BOX3D_BENCHMARKS "Build the Box3D benchmarks" OFF) option(BOX3D_DOCS "Build the Box3D documentation" OFF) + option(BOX3D_PROFILE "Enable profiling with Tracy" OFF) + option(BOX3D_VALIDATE "Enable heavy validation" ON) option(BOX3D_UNIT_TESTS "Build the Box3D unit tests" ON) # Enable this for shader development using sokol-shdc. @@ -158,6 +123,16 @@ if(PROJECT_IS_TOP_LEVEL) option(BOX3D_BUILD_SHADERS "Recompile shaders with sokol-shdc" OFF) if(BOX3D_UNIT_TESTS OR BOX3D_SAMPLES OR BOX3D_BENCHMARKS) + + # Emscripten pthread support + if(EMSCRIPTEN) + set(EMSCRIPTEN_PTHREADS_COMPILER_FLAGS "-pthread -s USE_PTHREADS=1") + set(EMSCRIPTEN_PTHREADS_LINKER_FLAGS "${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS} -s ALLOW_MEMORY_GROWTH") + string(APPEND CMAKE_C_FLAGS " ${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS}") + string(APPEND CMAKE_CXX_FLAGS " ${EMSCRIPTEN_PTHREADS_COMPILER_FLAGS}") + string(APPEND CMAKE_EXE_LINKER_FLAGS " ${EMSCRIPTEN_PTHREADS_LINKER_FLAGS}") + endif() + add_subdirectory(shared) endif() @@ -166,7 +141,7 @@ if(PROJECT_IS_TOP_LEVEL) message(STATUS "Adding Box3D unit tests") add_subdirectory(test) set_target_properties(test PROPERTIES XCODE_GENERATE_SCHEME TRUE) - elseif(BOX3D_UNIT_TESTS) + else() message(STATUS "Skipping Box3D unit tests") endif() @@ -179,11 +154,9 @@ 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) @@ -198,4 +171,4 @@ endif() # https://stackoverflow.com/questions/72635402/how-to-set-working-directory-in-cmake-visual-studio-2022 # launch.vs.json -# "currentDir": "${workspaceRoot}" +# "currentDir": "${workspaceRoot}" \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 95a5d2c..04b0cd2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -28,68 +28,6 @@ "generator": "Xcode", "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" }, "binaryDir": "${sourceDir}/build" - }, - { - "name": "mingw-debug", - "displayName": "Windows MinGW Debug (Ninja, needs gcc on PATH)", - "generator": "Ninja", - "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, - "binaryDir": "${sourceDir}/build/mingw", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++", - "FETCHCONTENT_BASE_DIR": "${sourceDir}/.fetchcontent-cache/mingw" - } - }, - { - "name": "mingw-release", - "displayName": "Windows MinGW Release (Ninja, needs gcc on PATH)", - "generator": "Ninja", - "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, - "binaryDir": "${sourceDir}/build/mingw", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_C_COMPILER": "gcc", - "CMAKE_CXX_COMPILER": "g++", - "FETCHCONTENT_BASE_DIR": "${sourceDir}/.fetchcontent-cache/mingw" - } - }, - { - "name": "windows-clang-cl", - "displayName": "Windows clang-cl (Visual Studio solution, ClangCL toolset)", - "toolset": "ClangCL", - "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, - "binaryDir": "${sourceDir}/build/clang-cl-vs", - "cacheVariables": { - "FETCHCONTENT_BASE_DIR": "${sourceDir}/.fetchcontent-cache/clang-cl-vs" - } - }, - { - "name": "clang-cl-debug", - "displayName": "Windows clang-cl Debug (Ninja, needs LLVM on PATH)", - "generator": "Ninja", - "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, - "binaryDir": "${sourceDir}/build/clang-cl", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_C_COMPILER": "clang-cl", - "CMAKE_CXX_COMPILER": "clang-cl", - "FETCHCONTENT_BASE_DIR": "${sourceDir}/.fetchcontent-cache/clang-cl" - } - }, - { - "name": "clang-cl-release", - "displayName": "Windows clang-cl Release (Ninja, needs LLVM on PATH)", - "generator": "Ninja", - "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" }, - "binaryDir": "${sourceDir}/build/clang-cl", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "CMAKE_C_COMPILER": "clang-cl", - "CMAKE_CXX_COMPILER": "clang-cl", - "FETCHCONTENT_BASE_DIR": "${sourceDir}/.fetchcontent-cache/clang-cl" - } } ], "buildPresets": [ @@ -98,12 +36,6 @@ { "name": "linux-debug", "configurePreset": "linux-debug" }, { "name": "linux-release", "configurePreset": "linux-release" }, { "name": "macos-debug", "configurePreset": "macos", "configuration": "Debug" }, - { "name": "macos-release", "configurePreset": "macos", "configuration": "Release" }, - { "name": "mingw-debug", "configurePreset": "mingw-debug" }, - { "name": "mingw-release", "configurePreset": "mingw-release" }, - { "name": "windows-clang-cl-debug", "configurePreset": "windows-clang-cl", "configuration": "Debug" }, - { "name": "windows-clang-cl-release", "configurePreset": "windows-clang-cl", "configuration": "Release" }, - { "name": "clang-cl-debug", "configurePreset": "clang-cl-debug" }, - { "name": "clang-cl-release", "configurePreset": "clang-cl-release" } + { "name": "macos-release", "configurePreset": "macos", "configuration": "Release" } ] } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 35f53d0..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,108 +0,0 @@ -# Contributing to Box3D - -This project is open source under the [MIT License](LICENSE). Please read this document -before opening a pull request — **PRs that skip these steps will be closed.** - ---- - -## TL;DR - -1. **Discuss first.** Open an issue (or a [Discussion](../../discussions)) and - wait for it to be labeled `ready-for-pr` before writing code. -2. **Sign the CLA.** A bot will prompt you on your first PR. One signature - covers all future contributions. -3. **Link the issue.** Put `Closes #123` in your PR description. A required - check enforces this. -4. **Follow the style.** C17, no compiler warnings, formatted with - `clang-format`. -5. **Comments** Comment your code with human words. Create Doxygen comments for public APIs. -6. **Follow the LLM guidelines.** See the LLM guidelines in README.md - ---- - -## 1. Discuss before you build - -Open an issue or discussion before creating a PR. - -I will review the issue or discussion and apply the **`ready-for-pr`** label. Please don't open -a PR until you get the label. - -Please wait follow this process. I don't want people wasting time writing a PR that won't be accepted. - ---- - -## 2. Contributor License Agreement (CLA) - -Before your first contribution can be merged, you must sign the project's -**Individual Contributor License Agreement**. When you open your first pull -request, a bot will post a link; signing takes about a minute and covers all -your future contributions. - -**What this means:** you retain the copyright to your contribution. The CLA -grants the project maintainer a broad, perpetual, irrevocable license to use, -modify, sublicense, and **relicense** your contribution. This lets the project -adapt its licensing in the future (for example, offering a commercial edition) -without having to track down every past contributor. - -If you're contributing on behalf of an employer, make sure you have the right -to do so — some employment agreements assign your work to your employer, in -which case a Corporate CLA may be required. Contact the maintainer if you're -unsure. - -By submitting a contribution you also confirm that it is your original work and -that you have the right to submit it under these terms. - ---- - -## 3. Opening a pull request - -Once your issue is labeled `ready-for-pr`: - -1. **Fork** the repository and create a branch from `main`: - - ```bash - git checkout -b fix/short-description - ``` - -2. Make your change in small, focused commits. -3. **Reference the issue** in your PR description using a closing keyword: - - ```text - Closes #(Issue Number) - ``` - - A required status check parses this and will fail if no linked, approved - issue is found — the PR cannot be merged without it. -4. Ensure the full test suite and CI pass. -5. Fill out the PR template completely. - -Keep PRs scoped to a single logical change. If you find yourself touching -unrelated things, split them into separate PRs (each with its own approved -issue). - ---- - -## 4. Coding conventions - -Source files must be in C17. Samples use C++20. Please follow existing coding -conventions and use clang format. - ---- - -## 5. Tests and documentation - -- Comment your code. -- Public API must have Doxygen comments. - ---- - -## 6. LLM Policy - -- Follow the LLM policy in README.md - ---- - -## Questions? - -Open a [Discussion](../../discussions) — that's the best place for anything not -covered here. Thanks for helping make Box3D better! diff --git a/README.md b/README.md index ba89e27..49eadc3 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # Box3D -[![Build Status](https://github.com/erincatto/box3d/actions/workflows/build.yml/badge.svg)](https://github.com/erincatto/box3d/actions) -[![CLA assistant](https://cla-assistant.io/readme/badge/erincatto/box3d)](https://cla-assistant.io/erincatto/box3d) - ![Box3D Logo](https://box2d.org/images/logo.svg) Box3D is a 3D physics engine for games. -[![Introducing Box3D](https://img.youtube.com/vi/jr_Fzl2XwKU/maxresdefault.jpg)](https://www.youtube.com/watch?v=jr_Fzl2XwKU) +## Build status + +[![Build Status](https://github.com/erincatto/box3d/actions/workflows/build.yml/badge.svg)](https://github.com/erincatto/box3d/actions) ## Features @@ -20,14 +19,13 @@ Box3D is a 3D physics engine for games. - Collision filtering - Ray casts, shape casts, and overlap queries - Sensor system -- Character mover ### Physics - Robust _Soft Step_ rigid body solver - Continuous physics for fast translations and rotations - Island based sleep -- Revolute, prismatic, distance, motor, weld, and wheel joints +- Revolute, prismatic, distance, mouse joint, weld, and wheel joints - Joint limits, motors, springs, and friction - Joint and contact forces - Body movement events and sleep notification @@ -38,14 +36,12 @@ Box3D is a 3D physics engine for games. - Written in portable C17 - Extensive multithreading and SIMD - Optimized for large piles of bodies -- Cross platform determinism -- Recording and replay ### Samples -- Uses sokol to run with D3D11 on Windows, Metal on macOS, and OpenGL 4.5 on Linux. -- Graphical user interface with imgui. -- Many samples to demonstrate features and performance. +- Uses sokol to run with D3D11 on Window, Metal on macOS, and OpenGL 4.3 on Linux +- Graphical user interface with imgui +- Many samples to demonstrate features and performance ## Building all platforms @@ -55,12 +51,11 @@ Box3D is a 3D physics engine for games. ## Building with CMake presets (recommended) -This uses the presets in `CMakePresets.json`. +The presets in `CMakePresets.json` give one build flow on every platform and are picked up automatically by Visual Studio, VS Code, and CLion (open the folder and choose a preset). From the command line: - Windows: `cmake --preset windows` then `cmake --build --preset windows-release` - Linux: `cmake --preset linux-release` then `cmake --build --preset linux-release` - macOS: `cmake --preset macos` then `cmake --build --preset macos-release` -- Windows MinGW: `cmake --preset mingw-release` then `cmake --build --preset mingw-release` Run the samples app (must be in the Box3D directory). @@ -88,14 +83,6 @@ Run the samples app (must be in the Box3D directory). - Select the samples scheme - Build and run the samples -## Building for Web - -- [Emscripten SDK](https://emscripten.org/docs/getting_started/downloads.html) -- `emcmake cmake -B build -DBOX3D_SAMPLES=OFF` -- `cmake --build build` - -Box3D uses SSE2 with WebAssembly. Define `BOX3D_DISABLE_SIMD` to disable SSE2. - ## Building and installing - mkdir build @@ -107,9 +94,10 @@ Box3D uses SSE2 with WebAssembly. Define `BOX3D_DISABLE_SIMD` to disable SSE2. ## Using Box3D in your project The core library has no dependencies beyond the C runtime (and `libm` on Unix). Linking it -gives you the `box3d::box3d` target. +gives you the `box3d::box3d` target. When Box3D is consumed as a subproject it builds the +library only; samples, tests, and benchmarks are skipped. -I recommend to use FetchContent: +The recommended path is FetchContent, which pins a tag and needs no separate install step: ```cmake include(FetchContent) @@ -147,9 +135,7 @@ 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, 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. +Box3D uses SSE2 and Neon SIMD math to improve performance. This can be disabled by defining `BOX3D_DISABLE_SIMD`. ## Documentation @@ -161,7 +147,7 @@ The user manual lives in [`docs/`](docs/) and is built with Doxygen. Enable the ## Contributing -Pull requests are currently disabled. Instead, please file an issue for bugs or feature requests. For support, please visit the Discord server. +Please do not submit pull requests. Instead, please file an issue for bugs or feature requests. For support, please visit the Discord server. ## Giving feedback @@ -176,16 +162,3 @@ Box3D is developed by Erin Catto and uses the [MIT license](https://en.wikipedia Support development of Box3D through [Github Sponsors](https://github.com/sponsors/erincatto). Please consider starring this repository and subscribing to my [YouTube channel](https://www.youtube.com/@erin_catto). - -## LLM Usage - -LLMs are used in the following areas: - -- unit tests -- samples app -- migrating code between Box2D and Box3D -- build configuration -- code reviews -- benchmarking - -Elsewhere all code is developed and written by me. I take responsibility for every line of code in Box2D/3D. diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 2650a34..73f7210 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -2,54 +2,12 @@ set(BOX3D_BENCHMARK_FILES main.c - mesh_benchmark.c - mesh_benchmark.h ) add_executable(benchmark ${BOX3D_BENCHMARK_FILES}) -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() +set_target_properties(benchmark PROPERTIES C_STANDARD 17) target_link_libraries(benchmark PRIVATE box3d shared) -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${BOX3D_BENCHMARK_FILES}) -# Mesh drop soak. Uses internal threads, so it needs the static library. -if (NOT BUILD_SHARED_LIBS) - add_executable(mesh_soak mesh_soak.c) - - set_target_properties(mesh_soak PROPERTIES - C_STANDARD 17 - C_STANDARD_REQUIRED YES - C_EXTENSIONS NO - ) - - if (BOX3D_COMPILE_WARNING_AS_ERROR) - set_target_properties(mesh_soak PROPERTIES COMPILE_WARNING_AS_ERROR ON) - endif() - - target_include_directories(mesh_soak PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src) - target_link_libraries(mesh_soak PRIVATE box3d shared) -endif() - -# Headless Ghost Collisions sample. Counts ghost manifolds per scene and body. -add_executable(ghost_scan ghost_scan.c) - -set_target_properties(ghost_scan PROPERTIES - C_STANDARD 17 - C_STANDARD_REQUIRED YES - C_EXTENSIONS NO -) - -if (BOX3D_COMPILE_WARNING_AS_ERROR) - set_target_properties(ghost_scan PROPERTIES COMPILE_WARNING_AS_ERROR ON) -endif() - -target_link_libraries(ghost_scan PRIVATE box3d shared) +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX "" FILES ${BOX3D_BENCHMARK_FILES}) \ No newline at end of file diff --git a/benchmark/amd7950x_avx2/convex_pile.csv b/benchmark/amd7950x_avx2/convex_pile.csv deleted file mode 100644 index 19ef32e..0000000 --- a/benchmark/amd7950x_avx2/convex_pile.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,5092.98 -2,2683.53 -3,1843.54 -4,1439.27 -5,1192.14 -6,1033.23 -7,923.268 -8,846.347 diff --git a/benchmark/amd7950x_avx2/joint_grid.csv b/benchmark/amd7950x_avx2/joint_grid.csv deleted file mode 100644 index 31fc1f6..0000000 --- a/benchmark/amd7950x_avx2/joint_grid.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1332.87 -2,689.909 -3,463.412 -4,352.244 -5,282.623 -6,239.524 -7,207.957 -8,185.382 diff --git a/benchmark/amd7950x_avx2/junkyard.csv b/benchmark/amd7950x_avx2/junkyard.csv deleted file mode 100644 index 8846ec1..0000000 --- a/benchmark/amd7950x_avx2/junkyard.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,11236.9 -2,5885.02 -3,4063.23 -4,3147.56 -5,2601.85 -6,2248.15 -7,2001.73 -8,1822.96 diff --git a/benchmark/amd7950x_avx2/large_pyramid.csv b/benchmark/amd7950x_avx2/large_pyramid.csv deleted file mode 100644 index 8809f8f..0000000 --- a/benchmark/amd7950x_avx2/large_pyramid.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1099.9 -2,567.505 -3,392.791 -4,302.607 -5,250.85 -6,218.705 -7,193.731 -8,175.831 diff --git a/benchmark/amd7950x_avx2/large_world.csv b/benchmark/amd7950x_avx2/large_world.csv deleted file mode 100644 index 757e17c..0000000 --- a/benchmark/amd7950x_avx2/large_world.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,5.2893 -2,6.8593 -3,8.2452 -4,8.7965 -5,8.88 -6,8.8702 -7,9.0274 -8,9.3917 diff --git a/benchmark/amd7950x_avx2/many_pyramids.csv b/benchmark/amd7950x_avx2/many_pyramids.csv deleted file mode 100644 index d950ecf..0000000 --- a/benchmark/amd7950x_avx2/many_pyramids.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1252.28 -2,603.36 -3,412.994 -4,311.517 -5,249.951 -6,210.331 -7,185.742 -8,162.021 diff --git a/benchmark/amd7950x_avx2/mesh_drop.csv b/benchmark/amd7950x_avx2/mesh_drop.csv deleted file mode 100644 index bcfa419..0000000 --- a/benchmark/amd7950x_avx2/mesh_drop.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1287.05 -2,665.133 -3,463.048 -4,360.315 -5,300.983 -6,262.112 -7,236.27 -8,214.998 diff --git a/benchmark/amd7950x_avx2/rain.csv b/benchmark/amd7950x_avx2/rain.csv deleted file mode 100644 index 1ead3d8..0000000 --- a/benchmark/amd7950x_avx2/rain.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1832.38 -2,995.626 -3,699.212 -4,547.216 -5,456.76 -6,396.698 -7,356.024 -8,325.755 diff --git a/benchmark/amd7950x_avx2/sleep.csv b/benchmark/amd7950x_avx2/sleep.csv deleted file mode 100644 index 8296ea7..0000000 --- a/benchmark/amd7950x_avx2/sleep.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,625.709 -2,330.685 -3,233.065 -4,187.897 -5,160.823 -6,143.489 -7,131.729 -8,125.636 diff --git a/benchmark/amd7950x_avx2/spinner.csv b/benchmark/amd7950x_avx2/spinner.csv deleted file mode 100644 index ae89955..0000000 --- a/benchmark/amd7950x_avx2/spinner.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,2274.2 -2,1328.84 -3,960.76 -4,782.728 -5,679.039 -6,633.552 -7,567.926 -8,541.742 diff --git a/benchmark/amd7950x_avx2/trees100.csv b/benchmark/amd7950x_avx2/trees100.csv deleted file mode 100644 index caf3120..0000000 --- a/benchmark/amd7950x_avx2/trees100.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,103.803 -2,69.6303 -3,59.0807 -4,53.6692 -5,50.927 -6,49.0812 -7,48.3124 -8,47.7709 diff --git a/benchmark/amd7950x_avx2/trees25.csv b/benchmark/amd7950x_avx2/trees25.csv deleted file mode 100644 index d3968d4..0000000 --- a/benchmark/amd7950x_avx2/trees25.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,357.883 -2,217.829 -3,169.684 -4,147.551 -5,135.274 -6,126.444 -7,122.615 -8,119.284 diff --git a/benchmark/amd7950x_avx2/trees50.csv b/benchmark/amd7950x_avx2/trees50.csv deleted file mode 100644 index b90215e..0000000 --- a/benchmark/amd7950x_avx2/trees50.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,162.522 -2,103.266 -3,84.4805 -4,74.2779 -5,70.0241 -6,66.3925 -7,64.5923 -8,63.7022 diff --git a/benchmark/amd7950x_avx2/washer.csv b/benchmark/amd7950x_avx2/washer.csv deleted file mode 100644 index 75cdfdf..0000000 --- a/benchmark/amd7950x_avx2/washer.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,15659.7 -2,8342.79 -3,5752.42 -4,4424.66 -5,3715.88 -6,3211.79 -7,2848.87 -8,2534.36 diff --git a/benchmark/amd7950x_scalar/convex_pile.csv b/benchmark/amd7950x_scalar/convex_pile.csv deleted file mode 100644 index 6134458..0000000 --- a/benchmark/amd7950x_scalar/convex_pile.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,40706 -2,20798.5 -3,13788.7 -4,10323.8 -5,8358.62 -6,6957.96 -7,6005.53 -8,5292.26 diff --git a/benchmark/amd7950x_scalar/joint_grid.csv b/benchmark/amd7950x_scalar/joint_grid.csv deleted file mode 100644 index 83d11be..0000000 --- a/benchmark/amd7950x_scalar/joint_grid.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,1525.94 -2,780.126 -3,524.776 -4,401.402 -5,325.756 -6,273.225 -7,238.761 -8,213.639 diff --git a/benchmark/amd7950x_scalar/junkyard.csv b/benchmark/amd7950x_scalar/junkyard.csv deleted file mode 100644 index df2f358..0000000 --- a/benchmark/amd7950x_scalar/junkyard.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,31501.3 -2,16601.6 -3,11227.1 -4,8563.17 -5,6942.15 -6,5857.2 -7,5070.54 -8,4517.74 diff --git a/benchmark/amd7950x_scalar/large_pyramid.csv b/benchmark/amd7950x_scalar/large_pyramid.csv deleted file mode 100644 index 930f930..0000000 --- a/benchmark/amd7950x_scalar/large_pyramid.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,5026.74 -2,2674.22 -3,1794.82 -4,1368.46 -5,1105.67 -6,939.709 -7,808.349 -8,720.536 diff --git a/benchmark/amd7950x_scalar/large_world.csv b/benchmark/amd7950x_scalar/large_world.csv deleted file mode 100644 index 61bc940..0000000 --- a/benchmark/amd7950x_scalar/large_world.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,24.5593 -2,26.5894 -3,27.5323 -4,27.8544 -5,27.8073 -6,28.2759 -7,28.1201 -8,28.7588 diff --git a/benchmark/amd7950x_scalar/many_pyramids.csv b/benchmark/amd7950x_scalar/many_pyramids.csv deleted file mode 100644 index 8abe613..0000000 --- a/benchmark/amd7950x_scalar/many_pyramids.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,4932.85 -2,2561.79 -3,1704.06 -4,1272.41 -5,1017.39 -6,850.793 -7,724.552 -8,635.926 diff --git a/benchmark/amd7950x_scalar/rain.csv b/benchmark/amd7950x_scalar/rain.csv deleted file mode 100644 index 41d830e..0000000 --- a/benchmark/amd7950x_scalar/rain.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,2540.8 -2,1420.77 -3,992.02 -4,783.73 -5,650.823 -6,570.124 -7,510.213 -8,467.848 diff --git a/benchmark/amd7950x_scalar/trees100.csv b/benchmark/amd7950x_scalar/trees100.csv deleted file mode 100644 index e4f26e3..0000000 --- a/benchmark/amd7950x_scalar/trees100.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,221.556 -2,143.138 -3,113.761 -4,100.076 -5,93.3681 -6,89.6276 -7,88.2381 -8,85.6611 diff --git a/benchmark/amd7950x_scalar/trees25.csv b/benchmark/amd7950x_scalar/trees25.csv deleted file mode 100644 index 0d566ff..0000000 --- a/benchmark/amd7950x_scalar/trees25.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,815.263 -2,468.217 -3,344.646 -4,296.781 -5,269.952 -6,252.229 -7,240.146 -8,234.044 diff --git a/benchmark/amd7950x_scalar/trees50.csv b/benchmark/amd7950x_scalar/trees50.csv deleted file mode 100644 index b44d02b..0000000 --- a/benchmark/amd7950x_scalar/trees50.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,346.159 -2,201.958 -3,154.425 -4,134.719 -5,126.168 -6,118.983 -7,114.768 -8,113.253 diff --git a/benchmark/amd7950x_scalar/washer.csv b/benchmark/amd7950x_scalar/washer.csv index 350d561..83bc876 100644 --- a/benchmark/amd7950x_scalar/washer.csv +++ b/benchmark/amd7950x_scalar/washer.csv @@ -1,9 +1,9 @@ threads,ms -1,42026.4 -2,22031.7 -3,15189.6 -4,11643.4 -5,9501.71 -6,8106.17 -7,7077.93 -8,6338.72 +1,0 +2,0 +3,0 +4,0 +5,0 +6,0 +7,0 +8,5488.14 diff --git a/benchmark/amd7950x_sse2/convex_pile.csv b/benchmark/amd7950x_sse2/convex_pile.csv deleted file mode 100644 index ed56bc5..0000000 --- a/benchmark/amd7950x_sse2/convex_pile.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,5834.56 -2,3071.09 -3,2104.65 -4,1629.92 -5,1347.05 -6,1160.72 -7,1031.3 -8,938.203 diff --git a/benchmark/amd7950x_sse2/joint_grid.csv b/benchmark/amd7950x_sse2/joint_grid.csv index b1e7573..01362c8 100644 --- a/benchmark/amd7950x_sse2/joint_grid.csv +++ b/benchmark/amd7950x_sse2/joint_grid.csv @@ -1,9 +1,9 @@ threads,ms -1,1311.69 -2,684.485 -3,463.171 -4,351.927 -5,283.58 -6,239.664 -7,208.766 -8,185.503 +1,1405.95 +2,771.262 +3,525.161 +4,396.555 +5,319.261 +6,273.429 +7,236.346 +8,212.377 diff --git a/benchmark/amd7950x_sse2/junkyard.csv b/benchmark/amd7950x_sse2/junkyard.csv index da36de0..096c056 100644 --- a/benchmark/amd7950x_sse2/junkyard.csv +++ b/benchmark/amd7950x_sse2/junkyard.csv @@ -1,9 +1,9 @@ threads,ms -1,12295.2 -2,6543.68 -3,4507.87 -4,3479.32 -5,2860.52 -6,2465.78 -7,2181.07 -8,1976.01 +1,24484.3 +2,13666.7 +3,9769.51 +4,7573.72 +5,6165.49 +6,5234.91 +7,4569.35 +8,4096.21 diff --git a/benchmark/amd7950x_sse2/large_pyramid.csv b/benchmark/amd7950x_sse2/large_pyramid.csv index b3ce44e..19b651d 100644 --- a/benchmark/amd7950x_sse2/large_pyramid.csv +++ b/benchmark/amd7950x_sse2/large_pyramid.csv @@ -1,9 +1,9 @@ threads,ms -1,1482.54 -2,779.924 -3,539.552 -4,412.933 -5,337.409 -6,296.132 -7,258.414 -8,234.912 +1,1776.98 +2,887.705 +3,611.107 +4,477.959 +5,393.24 +6,338.688 +7,301.258 +8,272.38 diff --git a/benchmark/amd7950x_sse2/large_world.csv b/benchmark/amd7950x_sse2/large_world.csv index 74537db..cc2e0e8 100644 --- a/benchmark/amd7950x_sse2/large_world.csv +++ b/benchmark/amd7950x_sse2/large_world.csv @@ -1,9 +1,9 @@ threads,ms -1,6.4003 -2,8.3039 -3,9.2919 -4,9.5648 -5,10.014 -6,9.8492 -7,9.9471 -8,10.1759 +1,9.6721 +2,12.2776 +3,13.8174 +4,15.0718 +5,14.2408 +6,14.8061 +7,15.4252 +8,15.7804 diff --git a/benchmark/amd7950x_sse2/many_pyramids.csv b/benchmark/amd7950x_sse2/many_pyramids.csv index eb5af42..a340236 100644 --- a/benchmark/amd7950x_sse2/many_pyramids.csv +++ b/benchmark/amd7950x_sse2/many_pyramids.csv @@ -1,9 +1,9 @@ threads,ms -1,1589.75 -2,818.695 -3,552.764 -4,419.151 -5,335.022 -6,282.792 -7,244.754 -8,217.593 +1,2540.44 +2,1220.31 +3,813.901 +4,609.715 +5,497.305 +6,413.889 +7,361.679 +8,319.254 diff --git a/benchmark/amd7950x_sse2/rain.csv b/benchmark/amd7950x_sse2/rain.csv index 3ab8c71..8684c76 100644 --- a/benchmark/amd7950x_sse2/rain.csv +++ b/benchmark/amd7950x_sse2/rain.csv @@ -1,9 +1,9 @@ threads,ms -1,2062.84 -2,1128.22 -3,787.495 -4,615.21 -5,510.128 -6,441.225 -7,393.722 -8,360.659 +1,2314.36 +2,1306.31 +3,932.724 +4,735.735 +5,610.991 +6,529.984 +7,478.004 +8,442.816 diff --git a/benchmark/amd7950x_sse2/sleep.csv b/benchmark/amd7950x_sse2/sleep.csv deleted file mode 100644 index 410101e..0000000 --- a/benchmark/amd7950x_sse2/sleep.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,844.093 -2,457.862 -3,318.846 -4,250.452 -5,209.426 -6,185.657 -7,169.441 -8,159.537 diff --git a/benchmark/amd7950x_sse2/spinner.csv b/benchmark/amd7950x_sse2/spinner.csv deleted file mode 100644 index a76590f..0000000 --- a/benchmark/amd7950x_sse2/spinner.csv +++ /dev/null @@ -1,9 +0,0 @@ -threads,ms -1,3134.14 -2,1823.2 -3,1303 -4,1047.41 -5,895.276 -6,799.402 -7,736.174 -8,697.184 diff --git a/benchmark/amd7950x_sse2/trees100.csv b/benchmark/amd7950x_sse2/trees100.csv index e806a76..29fac99 100644 --- a/benchmark/amd7950x_sse2/trees100.csv +++ b/benchmark/amd7950x_sse2/trees100.csv @@ -1,9 +1,9 @@ threads,ms -1,167.791 -2,110.927 -3,87.9977 -4,78.3566 -5,73.6954 -6,71.5957 -7,70.7282 -8,69.9302 +1,252.889 +2,159.521 +3,130.152 +4,114.981 +5,110.742 +6,98.8688 +7,99.0887 +8,99.0417 diff --git a/benchmark/amd7950x_sse2/trees25.csv b/benchmark/amd7950x_sse2/trees25.csv index 28f489d..83313ef 100644 --- a/benchmark/amd7950x_sse2/trees25.csv +++ b/benchmark/amd7950x_sse2/trees25.csv @@ -1,9 +1,9 @@ threads,ms -1,659.503 -2,387.181 -3,283.605 -4,245.555 -5,222.887 -6,208.297 -7,198.029 -8,191.382 +1,816.219 +2,486.479 +3,371.869 +4,315.809 +5,282.72 +6,262.329 +7,252.624 +8,244.159 diff --git a/benchmark/amd7950x_sse2/trees50.csv b/benchmark/amd7950x_sse2/trees50.csv index d23b525..7b2874c 100644 --- a/benchmark/amd7950x_sse2/trees50.csv +++ b/benchmark/amd7950x_sse2/trees50.csv @@ -1,9 +1,9 @@ threads,ms -1,285.725 -2,176.941 -3,135.635 -4,119.013 -5,109.379 -6,104.485 -7,101.719 -8,99.5091 +1,334.239 +2,226.053 +3,182.466 +4,159.489 +5,149.676 +6,140.113 +7,132.326 +8,132.251 diff --git a/benchmark/amd7950x_sse2/washer.csv b/benchmark/amd7950x_sse2/washer.csv index 010b74d..997ec05 100644 --- a/benchmark/amd7950x_sse2/washer.csv +++ b/benchmark/amd7950x_sse2/washer.csv @@ -1,9 +1,9 @@ threads,ms -1,17570 -2,9467.24 -3,6511.07 -4,5051.22 -5,4128.07 -6,3545.32 -7,3142.81 -8,2844.68 +1,30675.7 +2,16370.1 +3,11431 +4,8895.99 +5,7391.02 +6,6300.97 +7,5618.21 +8,5073.84 diff --git a/benchmark/ghost_baseline.csv b/benchmark/ghost_baseline.csv deleted file mode 100644 index 2a569ec..0000000 --- a/benchmark/ghost_baseline.csv +++ /dev/null @@ -1,109 +0,0 @@ -scene,preset,mirror,body,ghosts,runs -flat,0,0,box,0,2 -flat,0,0,capsule,0,2 -flat,0,0,upright,0,2 -flat,0,0,sphere,0,2 -flat,0,0,cylinder,0,2 -flat,0,1,box,0,2 -flat,0,1,capsule,0,2 -flat,0,1,upright,0,2 -flat,0,1,sphere,0,2 -flat,0,1,cylinder,0,2 -ramp,0,0,box,0,3 -ramp,0,0,capsule,0,3 -ramp,0,0,upright,0,3 -ramp,0,0,sphere,0,3 -ramp,0,0,cylinder,0,3 -ramp,0,1,box,0,3 -ramp,0,1,capsule,0,3 -ramp,0,1,upright,0,3 -ramp,0,1,sphere,0,3 -ramp,0,1,cylinder,0,3 -cliff,0,0,box,0,2 -cliff,0,0,capsule,0,2 -cliff,0,0,upright,0,2 -cliff,0,0,sphere,0,2 -cliff,0,0,cylinder,0,2 -cliff,0,1,box,0,2 -cliff,0,1,capsule,0,2 -cliff,0,1,upright,0,2 -cliff,0,1,sphere,0,2 -cliff,0,1,cylinder,0,2 -crest,0,0,box,0,2 -crest,0,0,capsule,0,2 -crest,0,0,upright,0,2 -crest,0,0,sphere,0,2 -crest,0,0,cylinder,0,2 -crest,0,1,box,0,2 -crest,0,1,capsule,0,2 -crest,0,1,upright,0,2 -crest,0,1,sphere,0,2 -crest,0,1,cylinder,0,2 -bumps,0,0,box,0,1 -bumps,0,0,capsule,0,1 -bumps,0,0,upright,0,1 -bumps,0,0,sphere,0,1 -bumps,0,0,cylinder,0,1 -bumps,0,1,box,0,1 -bumps,0,1,capsule,0,1 -bumps,0,1,upright,0,1 -bumps,0,1,sphere,0,1 -bumps,0,1,cylinder,0,1 -peel,0,0,box,0,2 -peel,0,0,capsule,0,2 -peel,0,0,upright,0,2 -peel,0,0,sphere,0,2 -peel,0,0,cylinder,0,2 -peel,0,1,box,0,2 -peel,0,1,capsule,0,2 -peel,0,1,upright,0,2 -peel,0,1,sphere,0,2 -peel,0,1,cylinder,0,2 -peel,1,0,box,0,2 -peel,1,0,capsule,0,2 -peel,1,0,upright,0,2 -peel,1,0,sphere,0,2 -peel,1,0,cylinder,0,2 -peel,1,1,box,0,2 -peel,1,1,capsule,0,2 -peel,1,1,upright,0,2 -peel,1,1,sphere,0,2 -peel,1,1,cylinder,0,2 -peel,2,0,box,0,2 -peel,2,0,capsule,0,2 -peel,2,0,upright,0,2 -peel,2,0,sphere,0,2 -peel,2,0,cylinder,0,2 -peel,2,1,box,0,2 -peel,2,1,capsule,0,2 -peel,2,1,upright,0,2 -peel,2,1,sphere,0,2 -peel,2,1,cylinder,0,2 -peel,3,0,box,0,2 -peel,3,0,capsule,0,2 -peel,3,0,upright,0,2 -peel,3,0,sphere,0,2 -peel,3,0,cylinder,0,2 -peel,3,1,box,0,2 -peel,3,1,capsule,0,2 -peel,3,1,upright,0,2 -peel,3,1,sphere,0,2 -peel,3,1,cylinder,0,2 -chamfer,0,0,box,0,2 -chamfer,0,0,cylinder,0,2 -chamfer,0,1,box,0,2 -chamfer,0,1,cylinder,0,2 -rail,0,0,box,0,2 -rail,0,0,capsule,0,2 -rail,0,0,upright,0,5 -rail,0,0,sphere,0,4 -rail,0,0,cylinder,0,3 -rail,0,1,box,0,2 -rail,0,1,capsule,0,2 -rail,0,1,upright,0,5 -rail,0,1,sphere,0,4 -rail,0,1,cylinder,0,3 -beams,0,0,box,0,3 -beams,0,0,cylinder,0,3 -beams,0,1,box,0,3 -beams,0,1,cylinder,0,3 diff --git a/benchmark/ghost_baseline_hf.csv b/benchmark/ghost_baseline_hf.csv deleted file mode 100644 index b4b385c..0000000 --- a/benchmark/ghost_baseline_hf.csv +++ /dev/null @@ -1,109 +0,0 @@ -scene,preset,mirror,body,ghosts,runs -flat,0,0,box,0,2 -flat,0,0,capsule,0,2 -flat,0,0,upright,0,2 -flat,0,0,sphere,0,2 -flat,0,0,cylinder,0,2 -flat,0,1,box,0,2 -flat,0,1,capsule,0,2 -flat,0,1,upright,0,2 -flat,0,1,sphere,0,2 -flat,0,1,cylinder,0,2 -ramp,0,0,box,0,3 -ramp,0,0,capsule,0,3 -ramp,0,0,upright,0,3 -ramp,0,0,sphere,0,3 -ramp,0,0,cylinder,0,3 -ramp,0,1,box,0,3 -ramp,0,1,capsule,0,3 -ramp,0,1,upright,0,3 -ramp,0,1,sphere,0,3 -ramp,0,1,cylinder,0,3 -cliff,0,0,box,0,2 -cliff,0,0,capsule,0,2 -cliff,0,0,upright,0,2 -cliff,0,0,sphere,0,2 -cliff,0,0,cylinder,0,2 -cliff,0,1,box,0,2 -cliff,0,1,capsule,0,2 -cliff,0,1,upright,0,2 -cliff,0,1,sphere,0,2 -cliff,0,1,cylinder,0,2 -crest,0,0,box,0,2 -crest,0,0,capsule,0,2 -crest,0,0,upright,0,2 -crest,0,0,sphere,0,2 -crest,0,0,cylinder,0,2 -crest,0,1,box,0,2 -crest,0,1,capsule,0,2 -crest,0,1,upright,0,2 -crest,0,1,sphere,0,2 -crest,0,1,cylinder,0,2 -bumps,0,0,box,0,1 -bumps,0,0,capsule,0,1 -bumps,0,0,upright,0,1 -bumps,0,0,sphere,0,1 -bumps,0,0,cylinder,0,1 -bumps,0,1,box,0,1 -bumps,0,1,capsule,0,1 -bumps,0,1,upright,0,1 -bumps,0,1,sphere,0,1 -bumps,0,1,cylinder,0,1 -peel,0,0,box,0,2 -peel,0,0,capsule,0,2 -peel,0,0,upright,0,2 -peel,0,0,sphere,0,2 -peel,0,0,cylinder,0,2 -peel,0,1,box,0,2 -peel,0,1,capsule,0,2 -peel,0,1,upright,0,2 -peel,0,1,sphere,0,2 -peel,0,1,cylinder,0,2 -peel,1,0,box,0,2 -peel,1,0,capsule,0,2 -peel,1,0,upright,0,2 -peel,1,0,sphere,0,2 -peel,1,0,cylinder,0,2 -peel,1,1,box,0,2 -peel,1,1,capsule,0,2 -peel,1,1,upright,0,2 -peel,1,1,sphere,0,2 -peel,1,1,cylinder,0,2 -peel,2,0,box,0,2 -peel,2,0,capsule,0,2 -peel,2,0,upright,0,2 -peel,2,0,sphere,0,2 -peel,2,0,cylinder,0,2 -peel,2,1,box,0,2 -peel,2,1,capsule,0,2 -peel,2,1,upright,0,2 -peel,2,1,sphere,0,2 -peel,2,1,cylinder,0,2 -peel,3,0,box,0,2 -peel,3,0,capsule,0,2 -peel,3,0,upright,0,2 -peel,3,0,sphere,0,2 -peel,3,0,cylinder,0,2 -peel,3,1,box,0,2 -peel,3,1,capsule,0,2 -peel,3,1,upright,0,2 -peel,3,1,sphere,0,2 -peel,3,1,cylinder,0,2 -chamfer,0,0,box,0,2 -chamfer,0,0,cylinder,0,2 -chamfer,0,1,box,0,2 -chamfer,0,1,cylinder,0,2 -rail,0,0,box,0,5 -rail,0,0,capsule,0,4 -rail,0,0,upright,0,5 -rail,0,0,sphere,0,5 -rail,0,0,cylinder,0,4 -rail,0,1,box,0,5 -rail,0,1,capsule,0,4 -rail,0,1,upright,0,5 -rail,0,1,sphere,0,5 -rail,0,1,cylinder,0,4 -beams,0,0,box,0,3 -beams,0,0,cylinder,0,3 -beams,0,1,box,0,3 -beams,0,1,cylinder,0,3 diff --git a/benchmark/ghost_scan.c b/benchmark/ghost_scan.c deleted file mode 100644 index 25aa4d6..0000000 --- a/benchmark/ghost_scan.c +++ /dev/null @@ -1,535 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// Headless scan of the Mesh / Ghost Collisions sample. Runs every scene, body, mirror and PEEL -// preset for a fixed number of steps and counts the ghost manifolds that pushed on the body. A -// written result file can be compared against a later build, which fails on any count that grew. It -// also fails on a config that completed fewer runs, because a body stopped on an edge or dropped -// through the ground crosses fewer edges and so logs fewer ghosts. - -#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS ) -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include "ghost_collisions.h" - -#include "box3d/box3d.h" - -#include -#include -#include - -// Command line and result file keys -static const char* s_sceneKeys[e_ghostSceneCount] = { - "flat", "ramp", "cliff", "crest", "bumps", "peel", "chamfer", "rail", "beams", -}; -static const char* s_bodyKeys[e_ghostBodyCount] = { "box", "capsule", "upright", "sphere", "cylinder" }; - -#define MAX_CONFIGS 256 - -static bool s_recycling = true; - -typedef struct Config -{ - GhostScene scene; - int preset; - bool mirror; - GhostBody body; - int ghostCount; - int runCount; - - // From the compare file, -1 when absent - int baseGhostCount; - int baseRunCount; -} Config; - -static const char* MatchValue( const char* arg, const char* shortName, const char* longName ) -{ - size_t shortLength = strlen( shortName ); - if ( strncmp( arg, shortName, shortLength ) == 0 ) - { - return arg + shortLength; - } - - size_t longLength = strlen( longName ); - if ( strncmp( arg, longName, longLength ) == 0 ) - { - return arg + longLength; - } - - return NULL; -} - -// Returns -1 for all, -2 for unknown -static int ParseKey( const char* value, const char** keys, int count ) -{ - if ( strcmp( value, "all" ) == 0 ) - { - return -1; - } - - for ( int i = 0; i < count; ++i ) - { - if ( strcmp( value, keys[i] ) == 0 ) - { - return i; - } - } - - char* end; - long index = strtol( value, &end, 10 ); - if ( *end == '\0' && 0 <= index && index < count ) - { - return (int)index; - } - - return -2; -} - -static void RunConfig( Config* config, GhostSettings settings, int stepCount, bool verbose ) -{ - settings.scene = config->scene; - settings.peelPreset = config->preset; - settings.mirror = config->mirror; - settings.body = config->body; - - // The s&box character is a fixed rotation hull without speculative contact. Speculative contact or - // rotation hide the ghost. - if ( config->scene == e_ghostChamfer ) - { - settings.fixedRotation = true; - settings.speculative = false; - } - - // The s&box character over the beam pits, hovering on speculative contacts. A resting cull that keeps - // the chamfers flush with the top launches it. - if ( config->scene == e_ghostBeams ) - { - settings.fixedRotation = true; - settings.speculative = true; - settings.speed = GHOST_BEAM_SPEED; - } - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - if ( s_recycling == false ) - { - b3World_SetContactRecycleDistance( worldId, 0.0f ); - } - - GhostCollisionsData data = CreateGhostCollisions( worldId, settings ); - - for ( int step = 0; step < stepCount; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - GhostReport reports[16]; - int ghostCount = UpdateGhostCollisions( worldId, &data, reports, 16 ); - if ( verbose ) - { - ghostCount = b3MinInt( ghostCount, 16 ); - for ( int i = 0; i < ghostCount; ++i ) - { - GhostReport* r = reports + i; - printf( " ghost step %d run %d n (%.3f %.3f %.3f) p (%.2f %.2f %.2f) sep %.4f impulse %.3f\n", step + 1, data.runCount, - r->normal.x, r->normal.y, r->normal.z, (float)r->point.x, (float)r->point.y, (float)r->point.z, - r->separation, r->impulse ); - } - } - } - - config->ghostCount = data.ghostCount; - config->runCount = data.runCount; - - b3DestroyWorld( worldId ); - DestroyGhostCollisions( &data ); -} - -static void FormatRow( char* buffer, size_t size, const Config* config ) -{ - if ( config->scene == e_ghostInternal ) - { - snprintf( buffer, size, "%s %d%s", s_sceneKeys[config->scene], config->preset, config->mirror ? " mirror" : "" ); - } - else - { - snprintf( buffer, size, "%s%s", s_sceneKeys[config->scene], config->mirror ? " mirror" : "" ); - } -} - -static bool SameConfig( const Config* a, const Config* b ) -{ - return a->scene == b->scene && a->preset == b->preset && a->mirror == b->mirror && a->body == b->body; -} - -// Filters are -1 for all -static int BuildConfigs( Config* configs, int sceneFilter, int presetFilter, int mirrorFilter, int bodyFilter ) -{ - int configCount = 0; - for ( int scene = 0; scene < e_ghostSceneCount; ++scene ) - { - if ( sceneFilter >= 0 && scene != sceneFilter ) - { - continue; - } - - int presetCount = scene == e_ghostInternal ? GHOST_PEEL_PRESET_COUNT : 1; - for ( int preset = 0; preset < presetCount; ++preset ) - { - if ( scene == e_ghostInternal && presetFilter >= 0 && preset != presetFilter ) - { - continue; - } - - for ( int mirror = 0; mirror < 2; ++mirror ) - { - if ( mirrorFilter >= 0 && mirror != mirrorFilter ) - { - continue; - } - - for ( int body = 0; body < e_ghostBodyCount; ++body ) - { - if ( bodyFilter >= 0 && body != bodyFilter ) - { - continue; - } - - // Only a flat bottom can rest on the chamfer edges - bool chamferScene = scene == e_ghostChamfer || scene == e_ghostBeams; - if ( chamferScene && body != e_ghostBox && body != e_ghostCylinder ) - { - continue; - } - - B3_ASSERT( configCount < MAX_CONFIGS ); - configs[configCount++] = (Config){ - .scene = (GhostScene)scene, - .preset = preset, - .mirror = mirror != 0, - .body = (GhostBody)body, - .baseGhostCount = -1, - .baseRunCount = -1, - }; - } - } - } - } - - return configCount; -} - -static bool ReadBaseline( const char* path, Config* configs, int configCount ) -{ - FILE* file = fopen( path, "r" ); - if ( file == NULL ) - { - printf( "cannot read %s\n", path ); - return false; - } - - char line[256]; - while ( fgets( line, sizeof( line ), file ) != NULL ) - { - char sceneKey[32], bodyKey[32]; - int preset, mirror, ghosts, runs; - if ( sscanf( line, "%31[^,],%d,%d,%31[^,],%d,%d", sceneKey, &preset, &mirror, bodyKey, &ghosts, &runs ) != 6 ) - { - continue; - } - - int scene = ParseKey( sceneKey, s_sceneKeys, e_ghostSceneCount ); - int body = ParseKey( bodyKey, s_bodyKeys, e_ghostBodyCount ); - for ( int i = 0; i < configCount; ++i ) - { - Config* c = configs + i; - if ( (int)c->scene == scene && c->preset == preset && c->mirror == ( mirror != 0 ) && (int)c->body == body ) - { - c->baseGhostCount = ghosts; - c->baseRunCount = runs; - } - } - } - - fclose( file ); - return true; -} - -// Replaces only the rows of this run and keeps the rest of an existing file, in canonical order -static bool WriteResults( const char* path, const Config* configs, int configCount ) -{ - Config allConfigs[MAX_CONFIGS]; - int allCount = BuildConfigs( allConfigs, -1, -1, -1, -1 ); - - FILE* existing = fopen( path, "r" ); - if ( existing != NULL ) - { - fclose( existing ); - if ( ReadBaseline( path, allConfigs, allCount ) == false ) - { - return false; - } - } - - FILE* file = fopen( path, "w" ); - if ( file == NULL ) - { - printf( "cannot write %s\n", path ); - return false; - } - - fprintf( file, "scene,preset,mirror,body,ghosts,runs\n" ); - for ( int i = 0; i < allCount; ++i ) - { - const Config* c = allConfigs + i; - int ghostCount = c->baseGhostCount; - int runCount = c->baseRunCount; - for ( int j = 0; j < configCount; ++j ) - { - if ( SameConfig( c, configs + j ) ) - { - ghostCount = configs[j].ghostCount; - runCount = configs[j].runCount; - break; - } - } - - if ( ghostCount < 0 ) - { - continue; - } - - fprintf( file, "%s,%d,%d,%s,%d,%d\n", s_sceneKeys[c->scene], c->preset, c->mirror ? 1 : 0, s_bodyKeys[c->body], ghostCount, - runCount ); - } - - fclose( file ); - return true; -} - -int main( int argc, char** argv ) -{ - int sceneFilter = -1; - int bodyFilter = -1; - int mirrorFilter = -1; - int presetFilter = -1; - int stepCount = 900; - bool verbose = false; - const char* writePath = NULL; - const char* comparePath = NULL; - GhostSettings settings = GetDefaultGhostSettings(); - - for ( int i = 1; i < argc; ++i ) - { - const char* arg = argv[i]; - const char* value; - - if ( ( value = MatchValue( arg, "-s=", "--scene=" ) ) != NULL ) - { - sceneFilter = ParseKey( value, s_sceneKeys, e_ghostSceneCount ); - } - else if ( ( value = MatchValue( arg, "-b=", "--body=" ) ) != NULL ) - { - bodyFilter = ParseKey( value, s_bodyKeys, e_ghostBodyCount ); - } - else if ( ( value = MatchValue( arg, "-m=", "--mirror=" ) ) != NULL ) - { - mirrorFilter = strcmp( value, "all" ) == 0 ? -1 : atoi( value ) != 0; - } - else if ( ( value = MatchValue( arg, "-p=", "--preset=" ) ) != NULL ) - { - presetFilter = strcmp( value, "all" ) == 0 ? -1 : b3ClampInt( atoi( value ), 0, GHOST_PEEL_PRESET_COUNT - 1 ); - } - else if ( ( value = MatchValue( arg, "-n=", "--steps=" ) ) != NULL ) - { - stepCount = atoi( value ); - } - else if ( ( value = MatchValue( arg, "-w=", "--write=" ) ) != NULL ) - { - writePath = value; - } - else if ( ( value = MatchValue( arg, "-c=", "--compare=" ) ) != NULL ) - { - comparePath = value; - } - else if ( ( value = MatchValue( arg, "--speed=", "--speed=" ) ) != NULL ) - { - settings.speed = (float)atof( value ); - } - else if ( ( value = MatchValue( arg, "--yaw=", "--yaw=" ) ) != NULL ) - { - settings.yaw = (float)atof( value ); - } - else if ( ( value = MatchValue( arg, "--friction=", "--friction=" ) ) != NULL ) - { - settings.friction = (float)atof( value ); - } - else if ( ( value = MatchValue( arg, "--cell=", "--cell=" ) ) != NULL ) - { - settings.cellSize = (float)atof( value ); - } - else if ( strcmp( arg, "--fixed-rotation" ) == 0 ) - { - settings.fixedRotation = true; - } - else if ( strcmp( arg, "--no-speculative" ) == 0 ) - { - settings.speculative = false; - } - else if ( strcmp( arg, "--no-recycling" ) == 0 ) - { - s_recycling = false; - } - else if ( strcmp( arg, "--height-field" ) == 0 ) - { - settings.heightField = true; - } - else if ( strcmp( arg, "-v" ) == 0 || strcmp( arg, "--verbose" ) == 0 ) - { - verbose = true; - } - else - { - sceneFilter = -2; - } - - if ( sceneFilter == -2 || bodyFilter == -2 ) - { - printf( "Usage: ghost_scan [options]\n" - "Runs the Ghost Collisions sample headless and counts ghost manifolds per scene and body.\n" - " -s, --scene= flat, ramp, cliff, crest, bumps, peel, chamfer, rail, beams (default all)\n" - " chamfer runs only the box and cylinder, fixed rotation without speculative\n" - " beams runs only the box and cylinder, fixed rotation with speculative,\n" - " always at 8 m/s\n" - " -b, --body= box, capsule, upright, sphere, cylinder (default all)\n" - " -m, --mirror=<0|1|all> mirrored mesh (default all)\n" - " -p, --preset=<0-3|all> PEEL preset (default all)\n" - " -n, --steps= steps per config (default 900)\n" - " -w, --write= write results as csv, replacing only the rows of this run\n" - " -c, --compare= compare with a written csv, fail if any count grew, any config\n" - " completed fewer runs, or has no row\n" - " --speed=, --yaw=, --friction=, --cell=, --fixed-rotation, --no-speculative\n" - " --height-field height field ground, one static body per height field\n" - " --no-recycling disable contact recycling\n" - " -v, --verbose print every ghost\n" - "Exit code is 1 when a compared count grew, completed fewer runs or has no row, 0 otherwise.\n" ); - return 2; - } - } - - Config configs[MAX_CONFIGS]; - int configCount = BuildConfigs( configs, sceneFilter, presetFilter, mirrorFilter, bodyFilter ); - - if ( comparePath != NULL && ReadBaseline( comparePath, configs, configCount ) == false ) - { - return 2; - } - - printf( "ghost scan: %d configs, %d steps, speed %.1f, yaw %.0f, friction %.2f, cell %.2f%s\n", configCount, stepCount, - settings.speed, settings.yaw, settings.friction, settings.cellSize, settings.heightField ? ", height field" : "" ); - fflush( stdout ); - - uint64_t ticks = b3GetTicks(); - for ( int i = 0; i < configCount; ++i ) - { - if ( verbose ) - { - char row[64]; - FormatRow( row, sizeof( row ), configs + i ); - printf( "%s %s\n", row, s_bodyKeys[configs[i].body] ); - } - - RunConfig( configs + i, settings, stepCount, verbose ); - } - float seconds = 0.001f * b3GetMilliseconds( ticks ); - - // One row per ground, one column per body. A compared cell that changed prints as old>new. - printf( "\n%-18s", "" ); - for ( int body = 0; body < e_ghostBodyCount; ++body ) - { - if ( bodyFilter < 0 || body == bodyFilter ) - { - printf( "%10s", s_bodyKeys[body] ); - } - } - printf( "\n" ); - - int totalGhosts = 0; - int grewCount = 0; - int shrankCount = 0; - int missingCount = 0; - int fewerRunsCount = 0; - int column = 0; - for ( int i = 0; i < configCount; ++i ) - { - const Config* c = configs + i; - bool newRow = i == 0 || c->scene != configs[i - 1].scene || c->preset != configs[i - 1].preset || - c->mirror != configs[i - 1].mirror; - if ( newRow ) - { - char row[64]; - FormatRow( row, sizeof( row ), c ); - printf( "%s%-18s", i == 0 ? "" : "\n", row ); - column = 0; - } - - // A scene that skips a body leaves its column empty - int bodyColumn = bodyFilter >= 0 ? 0 : (int)c->body; - while ( column < bodyColumn ) - { - printf( "%10s", "-" ); - column += 1; - } - column += 1; - - char cell[32]; - if ( comparePath != NULL && c->baseGhostCount < 0 ) - { - snprintf( cell, sizeof( cell ), "?>%d", c->ghostCount ); - } - else if ( c->baseGhostCount >= 0 && c->baseGhostCount != c->ghostCount ) - { - snprintf( cell, sizeof( cell ), "%d>%d", c->baseGhostCount, c->ghostCount ); - } - else - { - snprintf( cell, sizeof( cell ), "%d", c->ghostCount ); - } - printf( "%10s", cell ); - - totalGhosts += c->ghostCount; - grewCount += c->baseGhostCount >= 0 && c->ghostCount > c->baseGhostCount; - shrankCount += c->baseGhostCount >= 0 && c->ghostCount < c->baseGhostCount; - missingCount += c->baseGhostCount < 0; - fewerRunsCount += c->baseRunCount >= 0 && c->runCount < c->baseRunCount; - } - - printf( "\n\ntotal ghosts %d, time %.1f s\n", totalGhosts, seconds ); - - for ( int i = 0; i < configCount && fewerRunsCount > 0; ++i ) - { - const Config* c = configs + i; - if ( c->baseRunCount >= 0 && c->runCount < c->baseRunCount ) - { - char row[64]; - FormatRow( row, sizeof( row ), c ); - printf( "fewer runs: %s %s %d>%d\n", row, s_bodyKeys[c->body], c->baseRunCount, c->runCount ); - } - } - - if ( writePath != NULL && WriteResults( writePath, configs, configCount ) == false ) - { - return 2; - } - - if ( comparePath != NULL ) - { - bool pass = grewCount == 0 && missingCount == 0 && fewerRunsCount == 0; - printf( "compared with %s: %d grew, %d shrank, %d missing, %d with fewer runs\n", comparePath, grewCount, shrankCount, - missingCount, fewerRunsCount ); - printf( pass ? "PASS\n" : "FAIL\n" ); - return pass ? 0 : 1; - } - - return 0; -} diff --git a/benchmark/m2air_neon/convex_pile.csv b/benchmark/m2air_neon/convex_pile.csv deleted file mode 100644 index 652d979..0000000 --- a/benchmark/m2air_neon/convex_pile.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,15032.6 -2,7877.68 -3,5546.68 -4,4296.53 diff --git a/benchmark/m2air_neon/joint_grid.csv b/benchmark/m2air_neon/joint_grid.csv deleted file mode 100644 index 6439c4e..0000000 --- a/benchmark/m2air_neon/joint_grid.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,1089.82 -2,569.935 -3,399.883 -4,309.318 diff --git a/benchmark/m2air_neon/junkyard.csv b/benchmark/m2air_neon/junkyard.csv deleted file mode 100644 index 9b73cc6..0000000 --- a/benchmark/m2air_neon/junkyard.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,13501.4 -2,7288.19 -3,5229.53 -4,4253.67 diff --git a/benchmark/m2air_neon/large_pyramid.csv b/benchmark/m2air_neon/large_pyramid.csv deleted file mode 100644 index db51073..0000000 --- a/benchmark/m2air_neon/large_pyramid.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,1810.73 -2,976.492 -3,687.311 -4,563.518 diff --git a/benchmark/m2air_neon/large_world.csv b/benchmark/m2air_neon/large_world.csv deleted file mode 100644 index 48ea598..0000000 --- a/benchmark/m2air_neon/large_world.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,8.9855 -2,10.7568 -3,14.1527 -4,14.9816 diff --git a/benchmark/m2air_neon/many_pyramids.csv b/benchmark/m2air_neon/many_pyramids.csv deleted file mode 100644 index 6070afb..0000000 --- a/benchmark/m2air_neon/many_pyramids.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,1917.44 -2,1025.05 -3,727.266 -4,621.283 diff --git a/benchmark/m2air_neon/rain.csv b/benchmark/m2air_neon/rain.csv deleted file mode 100644 index 5abbe15..0000000 --- a/benchmark/m2air_neon/rain.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,1954.85 -2,1079.88 -3,789.64 -4,626.161 diff --git a/benchmark/m2air_neon/trees100.csv b/benchmark/m2air_neon/trees100.csv deleted file mode 100644 index 44df54a..0000000 --- a/benchmark/m2air_neon/trees100.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,186.082 -2,119.994 -3,103.081 -4,91.2481 diff --git a/benchmark/m2air_neon/trees25.csv b/benchmark/m2air_neon/trees25.csv deleted file mode 100644 index 9ef25d8..0000000 --- a/benchmark/m2air_neon/trees25.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,609.865 -2,348.635 -3,272.314 -4,236.167 diff --git a/benchmark/m2air_neon/trees50.csv b/benchmark/m2air_neon/trees50.csv deleted file mode 100644 index 04448b0..0000000 --- a/benchmark/m2air_neon/trees50.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,288.292 -2,184.331 -3,144.592 -4,156.867 diff --git a/benchmark/m2air_neon/washer.csv b/benchmark/m2air_neon/washer.csv deleted file mode 100644 index 47a7ad1..0000000 --- a/benchmark/m2air_neon/washer.csv +++ /dev/null @@ -1,5 +0,0 @@ -threads,ms -1,21065.2 -2,11419.4 -3,8383.39 -4,7675.16 diff --git a/benchmark/main.c b/benchmark/main.c index d8ec5ce..68658fc 100644 --- a/benchmark/main.c +++ b/benchmark/main.c @@ -6,19 +6,13 @@ #endif #include "benchmarks.h" -#include "mesh_benchmark.h" #include "utils.h" -#ifdef BOX3D_INTERNAL_BENCHMARKS -#include "sat_benchmark.h" -#endif - #include "box3d/box3d.h" #include "box3d/constants.h" #include "box3d/math_functions.h" #include -#include #include #include #include @@ -57,139 +51,6 @@ static void MinProfile( b3Profile* p1, const b3Profile* p2 ) p1->sleepIslands = b3MinFloat( p1->sleepIslands, p2->sleepIslands ); } -// Match a name=value option in either its short or long spelling. Returns the value or NULL. -static const char* MatchValue( const char* arg, const char* shortName, const char* longName ) -{ - size_t n = strlen( shortName ); - if ( strncmp( arg, shortName, n ) == 0 ) - { - return arg + n; - } - n = strlen( longName ); - if ( strncmp( arg, longName, n ) == 0 ) - { - return arg + n; - } - return NULL; -} - -// Distinguish a numeric benchmark index from a name. Empty string is not numeric. -static bool IsAllDigits( const char* s ) -{ - if ( *s == 0 ) - { - return false; - } - for ( ; *s != 0; ++s ) - { - if ( isdigit( (unsigned char)*s ) == 0 ) - { - return false; - } - } - return true; -} - -static bool EqualsIgnoreCase( const char* a, const char* b ) -{ - while ( *a != 0 && *b != 0 ) - { - if ( tolower( (unsigned char)*a ) != tolower( (unsigned char)*b ) ) - { - return false; - } - ++a; - ++b; - } - return *a == *b; -} - -static int FindBenchmark( const Benchmark* benchmarks, int count, const char* name ) -{ - for ( int i = 0; i < count; ++i ) - { - if ( EqualsIgnoreCase( benchmarks[i].name, name ) ) - { - return i; - } - } - return -1; -} - -#ifdef BOX3D_INTERNAL_BENCHMARKS -// GJK versus SAT on hull pairs held inside the speculative margin. Reports the min time per query over the runs. -static void RunSatBenchmarks( int runCount ) -{ -#ifdef NDEBUG - int repeatCount = 20; -#else - int repeatCount = 1; -#endif - - printf( "benchmark: sat, pairs = %d, repeats = %d, simd width = %d\n", SAT_PAIR_COUNT, repeatCount, GetSimdWidth() ); - printf( "time per query (us), sat full has the inscribed sphere bound disabled\n" ); - printf( "%-20s %10s %10s %10s %10s\n", "pair", "gjk cold", "gjk warm", "sat", "sat full" ); - - for ( int typeA = 0; typeA < satHull_count; ++typeA ) - { - for ( int typeB = typeA; typeB < satHull_count; ++typeB ) - { - SatBenchmarkData* data = CreateSatBenchmark( (SatHullType)typeA, (SatHullType)typeB ); - - float coldMs = FLT_MAX; - float warmMs = FLT_MAX; - float satMs = FLT_MAX; - float fullMs = FLT_MAX; - int queryCount = 0; - int earlyReturnCount = 0; - - for ( int runIndex = 0; runIndex < runCount; ++runIndex ) - { - EnableSatInscribedSphere( data, true ); - SatBenchmarkResult cold = RunSatBenchmark( data, repeatCount, false ); - SatBenchmarkResult warm = RunSatBenchmark( data, repeatCount, true ); - - EnableSatInscribedSphere( data, false ); - SatBenchmarkResult full = RunSatBenchmark( data, repeatCount, false ); - - coldMs = b3MinFloat( coldMs, cold.distanceMs ); - warmMs = b3MinFloat( warmMs, warm.distanceMs ); - satMs = b3MinFloat( satMs, b3MinFloat( cold.satMs, warm.satMs ) ); - fullMs = b3MinFloat( fullMs, full.satMs ); - queryCount = cold.queryCount; - earlyReturnCount += cold.earlyReturnCount + full.earlyReturnCount; - } - - char name[32]; - snprintf( name, sizeof( name ), "%s/%s", GetSatHullName( (SatHullType)typeA ), GetSatHullName( (SatHullType)typeB ) ); - - float scale = 1000.0f / queryCount; - printf( "%-20s %10.3f %10.3f %10.3f %10.3f\n", name, scale * coldMs, scale * warmMs, scale * satMs, - scale * fullMs ); - - if ( earlyReturnCount > 0 || data->maxPlacementError > 0.01f * data->targetDistance ) - { - printf( " warning: early returns = %d, max placement error = %g\n", earlyReturnCount, - data->maxPlacementError ); - } - - DestroySatBenchmark( data ); - } - } - - printf( "\n" ); -} -#endif - -static void PrintBenchmarks( const Benchmark* benchmarks, int count ) -{ - printf( "Registered benchmarks:\n" ); - for ( int i = 0; i < count; ++i ) - { - printf( " %2d %s\n", i, benchmarks[i].name ); - } -} - // Box3D benchmark application. On Windows it is important to use affinity avoid cross CCD // usage or efficiency cores. Also on Windows create a power plan with Processor power management // Min/Max of 99%. This prevents boosting and makes the benchmarks more repeatable. @@ -201,11 +62,7 @@ static void PrintBenchmarks( const Benchmark* benchmarks, int count ) // Run all benchmarks with 4 workers only. // start /affinity 0x5555 .\build\bin\Release\benchmark.exe -t=4 -w=4 -// List the registered benchmarks. -// .\build\bin\Release\benchmark.exe -l - -// Run a single benchmark by name with 4 workers. -// start /affinity 0x5555 .\build\bin\Release\benchmark.exe -t=4 -w=4 --benchmark=many_pyramids -r=5 +// start /affinity 0x5555 .\build\bin\Release\benchmark.exe -t=4 -w=4 -b=5 -r=5 // Run benchmark 3 with 4 workers and repeat 20 times. Record the step times. // start /affinity 0x5555 .\build\bin\Release\benchmark.exe -t=4 -w=4 -b=3 -r=20 -s @@ -213,12 +70,6 @@ static void PrintBenchmarks( const Benchmark* benchmarks, int count ) // Run benchmark 3 with 4 workers and run once. Disable continuous collision. Record the step times. // start /affinity 0x5555 .\build\bin\Release\benchmark.exe -t=4 -w=4 -b=3 -r=1 -nc -s -// Compare GJK and SAT on hull pairs in the speculative regime. Static Box3D only. -// start /affinity 0x5555 .\build\bin\Release\benchmark.exe --sat -r=5 - -// Time mesh creation. -// start /affinity 0x5555 .\build\bin\Release\benchmark.exe --mesh -r=5 - int main( int argc, char** argv ) { #ifdef TRACY_ENABLE @@ -226,25 +77,18 @@ int main( int argc, char** argv ) #endif Benchmark benchmarks[] = { - { "convex_pile", GetConvexPileCapacity, CreateConvexPile, NULL, NULL, 500 }, - { "joint_grid", NULL, CreateJointGrid, NULL, NULL, 100 }, - { "junkyard", GetJunkyardCapacity, CreateJunkyard, NULL, StepJunkyard, 500 }, - { "large_pyramid", NULL, CreateLargePyramid, NULL, NULL, 200 }, - { "large_world", GetLargeWorldCapacity, CreateLargeWorld, NULL, StepLargeWorld, 500 }, - { "many_pyramids", NULL, CreateManyPyramids, NULL, NULL, 100 }, - { "mesh_drop", NULL, CreateMeshDropBenchmark, DestroyMeshDropBenchmark, NULL, 170 }, - { "rain", GetRainCapacity, CreateRain, DestroyRain, StepRain, 400 }, - { "sleep", GetSleepCapacity, CreateSleep, NULL, StepSleep, 300 }, - { "spinner", GetSpinnerCapacity, CreateSpinner, DestroySpinner, NULL, 800 }, { "trees100", NULL, CreateTrees100, DestroyTrees, NULL, 500 }, { "trees50", NULL, CreateTrees50, DestroyTrees, NULL, 500 }, { "trees25", NULL, CreateTrees25, DestroyTrees, NULL, 500 }, - { "trees100hf", NULL, CreateTrees100HeightField, DestroyTrees, NULL, 500 }, - { "trees50hf", NULL, CreateTrees50HeightField, DestroyTrees, NULL, 500 }, - { "trees25hf", NULL, CreateTrees25HeightField, DestroyTrees, NULL, 500 }, - { "village", GetVillageCapacity, CreateVillage, DestroyVillage, StepVillage, VILLAGE_STEP_COUNT }, + { "joint_grid", NULL, CreateJointGrid, NULL, NULL, 100 }, + { "junkyard", NULL, CreateJunkyard, NULL, StepJunkyard, 500 }, + { "large_pyramid", NULL, CreateLargePyramid, NULL, NULL, 200 }, + { "many_pyramids", NULL, CreateManyPyramids, NULL, NULL, 100 }, + { "rain", GetRainCapacity, CreateRain, DestroyRain, StepRain, 400 }, { "washer", GetWasherCapacity, CreateWasher, NULL, NULL, 1000 }, + { "large_world", GetLargeWorldCapacity, CreateLargeWorld, NULL, StepLargeWorld, 500 }, //{ "smash", CreateSmash, NULL, 300 }, + //{ "spinner", CreateSpinner, StepSpinner, 1400 }, //{ "tumbler", CreateTumbler, NULL, 750 }, }; @@ -269,7 +113,7 @@ int main( int argc, char** argv ) .solveImpulses = FLT_MAX, .integratePositions = FLT_MAX, .relaxImpulses = FLT_MAX, - .restitution = FLT_MAX, + .applyRestitution = FLT_MAX, .storeImpulses = FLT_MAX, .splitIslands = FLT_MAX, .transforms = FLT_MAX, @@ -292,114 +136,49 @@ int main( int argc, char** argv ) b3Counters counters = { 0 }; bool enableContinuous = true; bool recordStepTimes = false; - bool runSat = false; - bool runMesh = false; - const char* meshCase = NULL; - int simdWidth = 0; assert( maxThreadCount <= B3_MAX_WORKERS ); for ( int i = 1; i < argc; ++i ) { const char* arg = argv[i]; - const char* value; - if ( ( value = MatchValue( arg, "-t=", "--threads=" ) ) != NULL ) + if ( strncmp( arg, "-t=", 3 ) == 0 ) { - int threadCount = atoi( value ); + int threadCount = atoi( arg + 3 ); maxThreadCount = b3ClampInt( threadCount, 1, maxThreadCount ); } - else if ( ( value = MatchValue( arg, "-b=", "--benchmark=" ) ) != NULL ) + else if ( strncmp( arg, "-b=", 3 ) == 0 ) { - // Accept an index for backward compatibility, otherwise an exact name - if ( IsAllDigits( value ) ) - { - singleBenchmark = b3ClampInt( atoi( value ), 0, benchmarkCount - 1 ); - } - else - { - singleBenchmark = FindBenchmark( benchmarks, benchmarkCount, value ); - if ( singleBenchmark == -1 ) - { - printf( "No benchmark named \"%s\"\n", value ); - PrintBenchmarks( benchmarks, benchmarkCount ); - exit( 1 ); - } - } + singleBenchmark = atoi( arg + 3 ); + singleBenchmark = b3ClampInt( singleBenchmark, 0, benchmarkCount - 1 ); } - else if ( ( value = MatchValue( arg, "-w=", "--workers=" ) ) != NULL ) + else if ( strncmp( arg, "-w=", 3 ) == 0 ) { - singleWorkerCount = atoi( value ); + singleWorkerCount = atoi( arg + 3 ); } - else if ( ( value = MatchValue( arg, "-r=", "--repeats=" ) ) != NULL ) + else if ( strncmp( arg, "-r=", 3 ) == 0 ) { - runCount = b3ClampInt( atoi( value ), 1, 1000 ); + runCount = b3ClampInt( atoi( arg + 3 ), 1, 1000 ); } - else if ( strcmp( arg, "-nc" ) == 0 || strcmp( arg, "--no-continuous" ) == 0 ) + else if ( strncmp( arg, "-nc", 3 ) == 0 ) { enableContinuous = false; printf( "Continuous disabled\n" ); } - else if ( strcmp( arg, "-s" ) == 0 || strcmp( arg, "--record-steps" ) == 0 ) + else if ( strncmp( arg, "-s", 3 ) == 0 ) { recordStepTimes = true; } - else if ( strcmp( arg, "-sat" ) == 0 || strcmp( arg, "--sat" ) == 0 ) - { -#ifdef BOX3D_INTERNAL_BENCHMARKS - runSat = true; -#else - printf( "The SAT benchmark requires static linkage\n" ); - exit( 1 ); -#endif - } - else if ( ( value = MatchValue( arg, "-mesh=", "--mesh=" ) ) != NULL ) - { - runMesh = true; - meshCase = value; - } - else if ( strcmp( arg, "-mesh" ) == 0 || strcmp( arg, "--mesh" ) == 0 ) - { - runMesh = true; - } - else if ( ( value = MatchValue( arg, "-simd=", "--simd-width=" ) ) != NULL ) - { - simdWidth = atoi( value ); - if ( simdWidth != 4 && simdWidth != 8 ) - { - printf( "The SIMD width must be 4 or 8\n" ); - exit( 1 ); - } - -#ifndef BOX3D_INTERNAL_BENCHMARKS - printf( "Forcing the SIMD width requires static linkage\n" ); - exit( 1 ); -#endif - } - else if ( strcmp( arg, "-l" ) == 0 || strcmp( arg, "--list" ) == 0 ) - { - PrintBenchmarks( benchmarks, benchmarkCount ); - exit( 0 ); - } - else if ( strcmp( arg, "-h" ) == 0 || strcmp( arg, "--help" ) == 0 ) + else if ( strcmp( arg, "-h" ) == 0 ) { printf( "Usage\n" - "-t, --threads=: the maximum number of threads to use\n" - "-b, --benchmark=: run a single benchmark by index or name\n" - "-w, --workers=: run a single worker count\n" - "-r, --repeats=: number of repeats (default is 4)\n" - "-nc, --no-continuous: disable continuous collision\n" - "-s, --record-steps: record step times\n" - "-sat, --sat: compare GJK and SAT on hull pairs, then exit\n" - "-mesh, --mesh[=]: time b3CreateMesh on several meshes, or one case, then exit\n" - "-simd, --simd-width=<4|8>: force the SIMD width (static Box3D only)\n" - "-l, --list: list the registered benchmarks\n" - "-h, --help: print this help\n" ); + "-t=: the maximum number of threads to use\n" + "-b=: run a single benchmark\n" + "-w=: run a single worker count\n" + "-r=: number of repeats (default is 4)\n" + "-s: record step times\n" ); exit( 0 ); } - else - { - printf( "Unknown option \"%s\", use -h for help\n", arg ); - } } if ( singleWorkerCount != -1 ) @@ -407,32 +186,8 @@ int main( int argc, char** argv ) singleWorkerCount = b3ClampInt( singleWorkerCount, 1, maxThreadCount ); } -#ifdef BOX3D_INTERNAL_BENCHMARKS - if ( simdWidth != 0 ) - { - SetSimdWidth( simdWidth ); - } - - if ( runSat ) - { - RunSatBenchmarks( runCount ); - free( profiles ); - return 0; - } -#endif - - if ( runMesh ) - { - RunMeshBenchmarks( runCount, meshCase ); - free( profiles ); - return 0; - } - printf( "Starting benchmarks\n" ); printf( "======================================\n" ); -#ifdef BOX3D_INTERNAL_BENCHMARKS - printf( "simd width = %d\n", GetSimdWidth() ); -#endif for ( int benchmarkIndex = 0; benchmarkIndex < benchmarkCount; ++benchmarkIndex ) { diff --git a/benchmark/mesh_benchmark.c b/benchmark/mesh_benchmark.c deleted file mode 100644 index b1621b1..0000000 --- a/benchmark/mesh_benchmark.c +++ /dev/null @@ -1,233 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#include "mesh_benchmark.h" - -#include "box3d/box3d.h" -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include -#include -#include -#include -#include - -typedef enum MeshShape -{ - meshShape_wave, - meshShape_torus, - meshShape_soup, -} MeshShape; - -typedef struct MeshCase -{ - const char* name; - MeshShape shape; - int countA; - int countB; - bool useMedianSplit; - bool identifyEdges; - bool weldVertices; -} MeshCase; - -typedef struct MeshSource -{ - b3Vec3* vertices; - int32_t* indices; - int vertexCount; - int triangleCount; -} MeshSource; - -static float WaveHeight( int i, int j ) -{ - return 0.5f * sinf( 0.31f * (float)i ) * cosf( 0.23f * (float)j ) + 0.25f * sinf( 0.07f * (float)( i + 2 * j ) ); -} - -// Shared-vertex grid, or a triangle soup with three vertices per triangle when unshared is set -static MeshSource MakeWave( int xCount, int zCount, bool unshared ) -{ - float cellWidth = 0.5f; - MeshSource source = { 0 }; - source.triangleCount = 2 * xCount * zCount; - source.indices = malloc( 3 * source.triangleCount * sizeof( int32_t ) ); - - if ( unshared == false ) - { - source.vertexCount = ( xCount + 1 ) * ( zCount + 1 ); - source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) ); - for ( int i = 0; i <= xCount; ++i ) - { - for ( int j = 0; j <= zCount; ++j ) - { - source.vertices[i * ( zCount + 1 ) + j] = (b3Vec3){ cellWidth * i, WaveHeight( i, j ), cellWidth * j }; - } - } - - int index = 0; - for ( int i = 0; i < xCount; ++i ) - { - for ( int j = 0; j < zCount; ++j ) - { - int a = i * ( zCount + 1 ) + j; - int b = a + 1; - int c = a + ( zCount + 1 ) + 1; - int d = a + ( zCount + 1 ); - source.indices[index++] = a; - source.indices[index++] = b; - source.indices[index++] = c; - source.indices[index++] = a; - source.indices[index++] = c; - source.indices[index++] = d; - } - } - } - else - { - source.vertexCount = 3 * source.triangleCount; - source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) ); - int index = 0; - for ( int i = 0; i < xCount; ++i ) - { - for ( int j = 0; j < zCount; ++j ) - { - b3Vec3 a = { cellWidth * i, WaveHeight( i, j ), cellWidth * j }; - b3Vec3 b = { cellWidth * i, WaveHeight( i, j + 1 ), cellWidth * ( j + 1 ) }; - b3Vec3 c = { cellWidth * ( i + 1 ), WaveHeight( i + 1, j + 1 ), cellWidth * ( j + 1 ) }; - b3Vec3 d = { cellWidth * ( i + 1 ), WaveHeight( i + 1, j ), cellWidth * j }; - b3Vec3 tris[6] = { a, b, c, a, c, d }; - for ( int k = 0; k < 6; ++k ) - { - source.vertices[index] = tris[k]; - source.indices[index] = index; - index += 1; - } - } - } - } - - return source; -} - -static MeshSource MakeTorus( int radialCount, int tubularCount ) -{ - float radius = 8.0f; - float thickness = 2.0f; - MeshSource source = { 0 }; - source.vertexCount = radialCount * tubularCount; - source.triangleCount = 2 * radialCount * tubularCount; - source.vertices = malloc( source.vertexCount * sizeof( b3Vec3 ) ); - source.indices = malloc( 3 * source.triangleCount * sizeof( int32_t ) ); - - for ( int i = 0; i < radialCount; ++i ) - { - float u = 2.0f * B3_PI * i / radialCount; - for ( int j = 0; j < tubularCount; ++j ) - { - float v = 2.0f * B3_PI * j / tubularCount; - float r = radius + thickness * cosf( v ); - source.vertices[i * tubularCount + j] = (b3Vec3){ r * cosf( u ), thickness * sinf( v ), r * sinf( u ) }; - } - } - - int index = 0; - for ( int i = 0; i < radialCount; ++i ) - { - int i2 = ( i + 1 ) % radialCount; - for ( int j = 0; j < tubularCount; ++j ) - { - int j2 = ( j + 1 ) % tubularCount; - int a = i * tubularCount + j; - int b = i2 * tubularCount + j; - int c = i2 * tubularCount + j2; - int d = i * tubularCount + j2; - source.indices[index++] = a; - source.indices[index++] = c; - source.indices[index++] = b; - source.indices[index++] = a; - source.indices[index++] = d; - source.indices[index++] = c; - } - } - - return source; -} - -void RunMeshBenchmarks( int runCount, const char* caseName ) -{ - MeshCase cases[] = { - { "wave_64", meshShape_wave, 64, 64, true, true, false }, - { "wave_128", meshShape_wave, 128, 128, true, true, false }, - { "wave_256", meshShape_wave, 256, 256, true, true, false }, - { "wave_128_no_edges", meshShape_wave, 128, 128, true, false, false }, - { "wave_128_sah", meshShape_wave, 128, 128, false, true, false }, - { "torus_128x64", meshShape_torus, 128, 64, false, true, false }, - { "soup_128_weld", meshShape_soup, 128, 128, true, true, true }, - }; - int caseCount = sizeof( cases ) / sizeof( cases[0] ); - -#ifdef NDEBUG - int targetTriangles = 1 << 20; -#else - int targetTriangles = 1 << 14; -#endif - - printf( "benchmark: mesh creation, runs = %d\n", runCount ); - printf( "%-20s %10s %8s %12s %12s\n", "case", "triangles", "builds", "ms / build", "ns / tri" ); - - for ( int caseIndex = 0; caseIndex < caseCount; ++caseIndex ) - { - const MeshCase* mc = cases + caseIndex; - if ( caseName != NULL && strcmp( caseName, mc->name ) != 0 ) - { - continue; - } - - MeshSource source; - if ( mc->shape == meshShape_torus ) - { - source = MakeTorus( mc->countA, mc->countB ); - } - else - { - source = MakeWave( mc->countA, mc->countB, mc->shape == meshShape_soup ); - } - - b3MeshDef def = { 0 }; - def.vertices = source.vertices; - def.vertexCount = source.vertexCount; - def.indices = source.indices; - def.triangleCount = source.triangleCount; - def.useMedianSplit = mc->useMedianSplit; - def.identifyEdges = mc->identifyEdges; - def.weldVertices = mc->weldVertices; - def.weldTolerance = mc->weldVertices ? 0.001f : 0.0f; - - int buildCount = targetTriangles / source.triangleCount; - if ( buildCount < 1 ) - { - buildCount = 1; - } - - float bestMs = FLT_MAX; - for ( int runIndex = 0; runIndex < runCount; ++runIndex ) - { - uint64_t ticks = b3GetTicks(); - for ( int buildIndex = 0; buildIndex < buildCount; ++buildIndex ) - { - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - b3DestroyMesh( mesh ); - } - float ms = b3GetMilliseconds( ticks ) / buildCount; - bestMs = b3MinFloat( bestMs, ms ); - } - - float nsPerTriangle = 1.0e6f * bestMs / source.triangleCount; - printf( "%-20s %10d %8d %12.3f %12.1f\n", mc->name, source.triangleCount, buildCount, bestMs, nsPerTriangle ); - - free( source.vertices ); - free( source.indices ); - } - - printf( "\n" ); -} diff --git a/benchmark/mesh_benchmark.h b/benchmark/mesh_benchmark.h deleted file mode 100644 index b942ed6..0000000 --- a/benchmark/mesh_benchmark.h +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-FileCopyrightText: 2025 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -void RunMeshBenchmarks( int runCount, const char* caseName ); diff --git a/benchmark/mesh_soak.c b/benchmark/mesh_soak.c deleted file mode 100644 index dd41e89..0000000 --- a/benchmark/mesh_soak.c +++ /dev/null @@ -1,730 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// Headless soak of the Continuous / Mesh Drop sample. Each generation drops 1024 small bodies on a -// wave mesh and steps until every body sleeps. A generation fails if a body falls through the mesh -// or the pile is still awake at the step limit. Tunnels are rare, so the soak also counts bodies that -// sink into the wave past a few depth levels and can compare those counts against a baseline. -// Generations run in parallel, one single threaded world per thread. The printed seed reproduces a -// generation in the sample. The rough wave has bumps smaller than the bodies, so mesh contacts reach -// the manifold cap. It is far slower per generation, so run it with fewer of them. - -#define _CRT_SECURE_NO_WARNINGS - -#include "core.h" -#include "mesh_drop.h" - -#include "box3d/box3d.h" -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include -#include -#include -#include -#include - -#define MAX_REPORTED_FAILURES 32 -#define MAX_THREADS 64 - -typedef enum FailureKind -{ - e_tunnel, - e_awake, -} FailureKind; - -typedef struct Failure -{ - FailureKind kind; - MeshDropShape shape; - int generation; - uint32_t seed; - int step; - int index; - b3Pos position; -} Failure; - -typedef struct ShapeStats -{ - int generationCount; - int tunnelCount; - int awakeCount; - int depthCounts[MESH_DROP_DEPTH_LEVEL_COUNT]; - - float maxDepth; - uint32_t maxSeed; - int maxGeneration; - int maxIndex; - int maxStep; -} ShapeStats; - -typedef struct Soak -{ - b3Mutex* mutex; - b3MeshData* groundMesh; - b3HullData* cylinder; - MeshDropSettings settings; - uint32_t baseSeed; - int generationCount; - int nextGeneration; - - // -1 rotates through the shapes - int shapeFilter; - - bool fixedSeed; - bool recycling; - - int completedCount; - int failureCount; - int64_t totalSteps; - int maxSteps; - - // Mesh contact updates by manifold count, rough wave only - int64_t manifoldCounts[B3_MAX_MANIFOLDS]; - - ShapeStats stats[e_meshDropShapeCount]; - Failure failures[MAX_REPORTED_FAILURES]; -} Soak; - -static void RecordFailure( Soak* soak, const Failure* failure ) -{ - b3LockMutex( soak->mutex ); - if ( soak->failureCount < MAX_REPORTED_FAILURES ) - { - soak->failures[soak->failureCount] = *failure; - } - soak->failureCount += 1; - b3UnlockMutex( soak->mutex ); - - const char* kind = failure->kind == e_tunnel ? "TUNNEL" : "AWAKE"; - printf( "%s: generation %d, %s, seed %u, step %d, body (%d, %d) at (%.2f, %.2f, %.2f)\n", kind, failure->generation, - g_meshDropShapeNames[failure->shape], failure->seed, failure->step, failure->index / MESH_DROP_GRID_COUNT, - failure->index % MESH_DROP_GRID_COUNT, (float)failure->position.x, (float)failure->position.y, - (float)failure->position.z ); -} - -// Mirrors MeshDrop::Generate and the auto generate step loop. Returns the step count. -static int RunGeneration( Soak* soak, int generation, uint32_t seed, MeshDropShape shape, b3BodyId* bodies, - MeshDropDepth* depth, int* failureKind, int64_t* manifoldCounts ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 1; - - // The world registry is global and not thread safe - b3LockMutex( soak->mutex ); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3UnlockMutex( soak->mutex ); - - if ( soak->recycling == false ) - { - b3World_SetContactRecycleDistance( worldId, 0.0f ); - } - - CreateMeshDropGround( worldId, soak->groundMesh, soak->settings ); - - MeshDropSettings settings = soak->settings; - settings.shape = shape; - CreateMeshDropBodies( worldId, settings, seed, soak->cylinder, bodies ); - ResetMeshDropDepth( depth, settings, soak->cylinder ); - - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; - int maxSteps = GetMeshDropStepLimit( shape ); - float tunnelHeight = GetMeshDropTunnelHeight(); - int step = 0; - bool failed = false; - - while ( failed == false ) - { - b3World_Step( worldId, timeStep, subStepCount ); - UpdateMeshDropDepth( worldId, depth ); - step += 1; - - // Counters walk the world, so only pay for them where the cap matters - if ( soak->settings.rough ) - { - b3Counters counters = b3World_GetCounters( worldId ); - for ( int i = 0; i < B3_MAX_MANIFOLDS; ++i ) - { - manifoldCounts[i] += counters.manifoldCounts[i]; - } - } - - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) - { - b3Pos center = b3Body_GetWorldCenter( bodies[i] ); - if ( center.y < tunnelHeight ) - { - Failure failure = { e_tunnel, shape, generation, seed, step, i, center }; - RecordFailure( soak, &failure ); - *failureKind = e_tunnel; - failed = true; - break; - } - } - - if ( b3World_GetBodyEvents( worldId ).moveCount == 0 ) - { - break; - } - - if ( failed == false && step > maxSteps ) - { - int awakeIndex = 0; - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) - { - if ( b3Body_IsAwake( bodies[i] ) ) - { - awakeIndex = i; - break; - } - } - - b3Pos center = b3Body_GetWorldCenter( bodies[awakeIndex] ); - Failure failure = { e_awake, shape, generation, seed, step, awakeIndex, center }; - RecordFailure( soak, &failure ); - *failureKind = e_awake; - failed = true; - } - } - - b3LockMutex( soak->mutex ); - b3DestroyWorld( worldId ); - b3UnlockMutex( soak->mutex ); - - return step; -} - -static void SoakWorker( void* context ) -{ - Soak* soak = context; - b3BodyId* bodies = malloc( MESH_DROP_BODY_COUNT * sizeof( b3BodyId ) ); - MeshDropDepth* depth = malloc( sizeof( MeshDropDepth ) ); - - while ( true ) - { - b3LockMutex( soak->mutex ); - int generation = soak->nextGeneration; - soak->nextGeneration += 1; - b3UnlockMutex( soak->mutex ); - - if ( generation >= soak->generationCount ) - { - break; - } - - uint32_t seed = soak->fixedSeed ? soak->baseSeed : GetMeshDropSeed( soak->baseSeed, generation ); - MeshDropShape shape = - soak->shapeFilter >= 0 ? (MeshDropShape)soak->shapeFilter : (MeshDropShape)( generation % e_meshDropShapeCount ); - - int failureKind = -1; - int64_t manifoldCounts[B3_MAX_MANIFOLDS] = { 0 }; - int steps = RunGeneration( soak, generation, seed, shape, bodies, depth, &failureKind, manifoldCounts ); - - int depthCounts[MESH_DROP_DEPTH_LEVEL_COUNT]; - GetMeshDropDepthCounts( depth, depthCounts ); - - b3LockMutex( soak->mutex ); - soak->completedCount += 1; - soak->totalSteps += steps; - soak->maxSteps = b3MaxInt( soak->maxSteps, steps ); - for ( int i = 0; i < B3_MAX_MANIFOLDS; ++i ) - { - soak->manifoldCounts[i] += manifoldCounts[i]; - } - - ShapeStats* stats = soak->stats + shape; - stats->generationCount += 1; - stats->tunnelCount += failureKind == e_tunnel ? 1 : 0; - stats->awakeCount += failureKind == e_awake ? 1 : 0; - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - stats->depthCounts[i] += depthCounts[i]; - } - - // Ties go to the earlier generation so the report does not depend on thread timing - if ( depth->maxDepth > stats->maxDepth || - ( depth->maxDepth == stats->maxDepth && generation < stats->maxGeneration ) ) - { - stats->maxDepth = depth->maxDepth; - stats->maxSeed = seed; - stats->maxGeneration = generation; - stats->maxIndex = depth->maxIndex; - stats->maxStep = depth->maxStep; - } - - int completed = soak->completedCount; - b3UnlockMutex( soak->mutex ); - - if ( completed % b3MaxInt( 100, soak->generationCount / 10 ) == 0 ) - { - printf( "%d generations, %d bodies\n", completed, completed * MESH_DROP_BODY_COUNT ); - fflush( stdout ); - } - } - - free( depth ); - free( bodies ); -} - -// The rough wave gets its own names so its baseline rows never match a run on the broad wave -static const char* GetFilterName( int shapeFilter, bool rough ) -{ - static const char* roughNames[e_meshDropShapeCount] = { "rough_box", "rough_capsule", "rough_cylinder", "rough_sphere" }; - - if ( shapeFilter < 0 ) - { - return rough ? "rough_all" : "all"; - } - - return rough ? roughNames[shapeFilter] : g_meshDropShapeNames[shapeFilter]; -} - -// A baseline row starts with the run that made it, so one file can hold several runs -static void GetBaselineKey( const Soak* soak, char* key, int size ) -{ - snprintf( key, size, "%s,%u,%d,", GetFilterName( soak->shapeFilter, soak->settings.rough ), soak->baseSeed, - soak->generationCount ); -} - -// Replaces the rows of this run and keeps the rest -static void WriteBaseline( const Soak* soak, const char* path ) -{ - char key[64]; - GetBaselineKey( soak, key, sizeof( key ) ); - size_t keyLength = strlen( key ); - - // Read the whole file so neither a row count nor a row length can drop a row - char* text = NULL; - FILE* file = fopen( path, "rb" ); - if ( file != NULL ) - { - fseek( file, 0, SEEK_END ); - long textLength = ftell( file ); - fseek( file, 0, SEEK_SET ); - text = malloc( textLength + 1 ); - textLength = (long)fread( text, 1, textLength, file ); - text[textLength] = '\0'; - fclose( file ); - } - - file = fopen( path, "w" ); - if ( file == NULL ) - { - printf( "cannot write %s\n", path ); - free( text ); - return; - } - - fprintf( file, "filter,base,generations,shape,tunnels,awake" ); - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - fprintf( file, ",depth%g", g_meshDropDepthLevels[i] ); - } - fprintf( file, "\n" ); - - if ( text != NULL ) - { - bool header = true; - char* line = text; - while ( *line != '\0' ) - { - char* next = strchr( line, '\n' ); - size_t lineLength = next != NULL ? (size_t)( next - line ) : strlen( line ); - if ( lineLength > 0 && line[lineLength - 1] == '\r' ) - { - lineLength -= 1; - } - - if ( header == false && lineLength > 0 && strncmp( line, key, keyLength ) != 0 ) - { - fprintf( file, "%.*s\n", (int)lineLength, line ); - } - - header = false; - line = next != NULL ? next + 1 : line + strlen( line ); - } - - free( text ); - } - - for ( int shape = 0; shape < e_meshDropShapeCount; ++shape ) - { - const ShapeStats* stats = soak->stats + shape; - if ( stats->generationCount == 0 ) - { - continue; - } - - fprintf( file, "%s,%u,%d,%s,%d,%d", GetFilterName( soak->shapeFilter, soak->settings.rough ), soak->baseSeed, - soak->generationCount, g_meshDropShapeNames[shape], stats->tunnelCount, stats->awakeCount ); - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - fprintf( file, ",%d", stats->depthCounts[i] ); - } - fprintf( file, "\n" ); - } - - fclose( file ); - printf( "wrote %s\n", path ); -} - -// Returns 0 when no count grew past its noise band, 1 when one did, 2 when the baseline has no rows for this run -static int CompareBaseline( const Soak* soak, const char* path ) -{ - FILE* file = fopen( path, "r" ); - if ( file == NULL ) - { - printf( "cannot read %s\n", path ); - return 2; - } - - char line[512]; - if ( fgets( line, sizeof( line ), file ) == NULL ) - { - fclose( file ); - printf( "empty baseline %s\n", path ); - return 2; - } - - int result = 0; - int changedCount = 0; - int matchedCount = 0; - - while ( fgets( line, sizeof( line ), file ) != NULL ) - { - char filter[32]; - char shapeName[32]; - unsigned int base; - int generations; - int counts[2 + MESH_DROP_DEPTH_LEVEL_COUNT]; - - _Static_assert( MESH_DROP_DEPTH_LEVEL_COUNT == 4, "update the baseline row format" ); - int fieldCount = sscanf( line, "%31[^,],%u,%d,%31[^,],%d,%d,%d,%d,%d,%d", filter, &base, &generations, shapeName, - counts + 0, counts + 1, counts + 2, counts + 3, counts + 4, counts + 5 ); - if ( fieldCount != 10 ) - { - continue; - } - - if ( strcmp( filter, GetFilterName( soak->shapeFilter, soak->settings.rough ) ) != 0 || base != soak->baseSeed || - generations != soak->generationCount ) - { - continue; - } - - int shape = -1; - for ( int i = 0; i < e_meshDropShapeCount; ++i ) - { - if ( strcmp( shapeName, g_meshDropShapeNames[i] ) == 0 ) - { - shape = i; - } - } - - if ( shape < 0 ) - { - continue; - } - - matchedCount += 1; - - const ShapeStats* stats = soak->stats + shape; - int current[2 + MESH_DROP_DEPTH_LEVEL_COUNT] = { stats->tunnelCount, stats->awakeCount }; - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - current[2 + i] = stats->depthCounts[i]; - } - - for ( int i = 0; i < 2 + MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - if ( current[i] == counts[i] ) - { - continue; - } - - // Any collision change reshuffles the chaotic pile, so a count moves by about its square root - // even when nothing got worse. Flag growth past three of those. A count that was zero flags on any - // growth, since a good build never sinks that deep. - float band = 3.0f * sqrtf( (float)counts[i] ); - bool regressed = i < 2 ? current[i] > counts[i] : current[i] > counts[i] + band; - - char column[32]; - if ( i < 2 ) - { - snprintf( column, sizeof( column ), i == 0 ? "tunnels" : "awake" ); - } - else - { - snprintf( column, sizeof( column ), "> %g slop", g_meshDropDepthLevels[i - 2] ); - } - - printf( " %-9s %-11s %d>%d%s\n", shapeName, column, counts[i], current[i], regressed ? " GREW" : "" ); - changedCount += 1; - result = regressed ? 1 : result; - } - } - - fclose( file ); - - if ( matchedCount == 0 ) - { - printf( "%s has no rows for %s-s=%s -b=%u -g=%d\n", path, soak->settings.rough ? "--rough " : "", - GetFilterName( soak->shapeFilter, false ), soak->baseSeed, soak->generationCount ); - return 2; - } - - printf( "compared with %s: %d changed, %s\n", path, changedCount, result == 0 ? "none grew past noise" : "GREW" ); - return result; -} - -static const char* MatchValue( const char* arg, const char* shortName, const char* longName ) -{ - size_t shortLength = strlen( shortName ); - if ( strncmp( arg, shortName, shortLength ) == 0 ) - { - return arg + shortLength; - } - - size_t longLength = strlen( longName ); - if ( strncmp( arg, longName, longLength ) == 0 ) - { - return arg + longLength; - } - - return NULL; -} - -int main( int argc, char** argv ) -{ - int generationCount = 1000; - int threadCount = 8; - int shapeFilter = e_meshDropBox; - uint32_t seed = (uint32_t)b3GetTicks(); - bool fixedSeed = false; - bool recycling = true; - bool amplitudeSet = false; - const char* writePath = NULL; - const char* comparePath = NULL; - MeshDropSettings settings = GetDefaultMeshDropSettings(); - - for ( int i = 1; i < argc; ++i ) - { - const char* arg = argv[i]; - const char* value; - - if ( ( value = MatchValue( arg, "-g=", "--generations=" ) ) != NULL ) - { - generationCount = atoi( value ); - } - else if ( ( value = MatchValue( arg, "-t=", "--threads=" ) ) != NULL ) - { - threadCount = b3ClampInt( atoi( value ), 1, MAX_THREADS ); - } - else if ( ( value = MatchValue( arg, "-s=", "--shape=" ) ) != NULL ) - { - shapeFilter = -2; - for ( int k = 0; k < e_meshDropShapeCount; ++k ) - { - if ( strcmp( value, g_meshDropShapeNames[k] ) == 0 ) - { - shapeFilter = k; - } - } - - if ( strcmp( value, "all" ) == 0 ) - { - shapeFilter = -1; - } - - if ( shapeFilter == -2 ) - { - printf( "unknown shape: %s\n", value ); - return 2; - } - } - else if ( ( value = MatchValue( arg, "-seed=", "--seed=" ) ) != NULL ) - { - seed = (uint32_t)strtoul( value, NULL, 10 ); - fixedSeed = true; - } - else if ( ( value = MatchValue( arg, "-b=", "--base-seed=" ) ) != NULL ) - { - seed = (uint32_t)strtoul( value, NULL, 10 ); - } - else if ( ( value = MatchValue( arg, "-a=", "--amplitude=" ) ) != NULL ) - { - settings.amplitude = (float)atof( value ); - amplitudeSet = true; - } - else if ( strcmp( arg, "--rough" ) == 0 ) - { - settings.rough = true; - } - else if ( ( value = MatchValue( arg, "-w=", "--write=" ) ) != NULL ) - { - writePath = value; - } - else if ( ( value = MatchValue( arg, "-c=", "--compare=" ) ) != NULL ) - { - comparePath = value; - } - else if ( strcmp( arg, "--no-recycling" ) == 0 ) - { - recycling = false; - } - else - { - printf( "Usage: mesh_soak [options]\n" - "Drops %d bodies per generation on the Mesh Drop wave mesh until they sleep.\n" - "Fails on a body below y = -2 (tunnel) or a pile awake past the step limit.\n" - "Counts bodies that sink into the wave deeper than each depth level.\n" - " -g, --generations= generation count (default 1000)\n" - " -t, --threads= worker threads, one world each (default 8)\n" - " -s, --shape= box, capsule, cylinder, sphere or all (default box)\n" - " -b, --base-seed= base seed, each generation hashes its own seed from it (default random)\n" - " --seed= run every generation with this exact seed (replay)\n" - " -a, --amplitude= wave amplitude (default 0.5, rough 0.015)\n" - " --rough fine bumps smaller than the bodies, reaches the manifold cap\n" - " -w, --write= write the counts as a baseline, replacing only the rows of this run\n" - " -c, --compare= compare the counts with the baseline rows from the same wave, -s, -b and -g\n" - " --no-recycling disable contact recycling\n" - "Exit code is 0 when every generation passes and no count grew past noise, 1 otherwise,\n" - "2 for bad arguments or a baseline from a different run.\n", - MESH_DROP_BODY_COUNT ); - return 2; - } - } - - if ( settings.rough && amplitudeSet == false ) - { - settings.amplitude = GetMeshDropDefaultAmplitude( true ); - } - - if ( fixedSeed && ( writePath != NULL || comparePath != NULL ) ) - { - printf( "a baseline needs a base seed, not --seed\n" ); - return 2; - } - - Soak soak = { 0 }; - soak.mutex = b3CreateMutex(); - soak.settings = settings; - soak.recycling = recycling; - soak.groundMesh = CreateMeshDropMesh( settings ); - soak.cylinder = CreateMeshDropCylinder(); - soak.baseSeed = seed; - soak.fixedSeed = fixedSeed; - soak.generationCount = generationCount; - soak.shapeFilter = shapeFilter; - - for ( int i = 0; i < e_meshDropShapeCount; ++i ) - { - soak.stats[i].maxDepth = -FLT_MAX; - soak.stats[i].maxGeneration = INT32_MAX; - } - - printf( "mesh soak: %d generations, %d threads, %sshape %s, %s seed %u\n", generationCount, threadCount, - settings.rough ? "rough wave, " : "", GetFilterName( shapeFilter, false ), fixedSeed ? "fixed" : "base", seed ); - fflush( stdout ); - - uint64_t ticks = b3GetTicks(); - - b3Thread* threads[MAX_THREADS]; - for ( int i = 0; i < threadCount; ++i ) - { - threads[i] = b3CreateThread( SoakWorker, &soak, "soak" ); - } - - for ( int i = 0; i < threadCount; ++i ) - { - b3JoinThread( threads[i] ); - } - - float seconds = 0.001f * b3GetMilliseconds( ticks ); - double averageSteps = soak.completedCount > 0 ? (double)soak.totalSteps / soak.completedCount : 0.0; - float slop = B3_LINEAR_SLOP; - - printf( "\n%-9s %8s %8s %6s", "shape", "bodies", "tunnels", "awake" ); - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - char label[32]; - snprintf( label, sizeof( label ), "> %g slop", g_meshDropDepthLevels[i] ); - printf( " %10s", label ); - } - printf( " deepest\n" ); - - for ( int shape = 0; shape < e_meshDropShapeCount; ++shape ) - { - const ShapeStats* stats = soak.stats + shape; - if ( stats->generationCount == 0 ) - { - continue; - } - - printf( "%-9s %8d %8d %6d", g_meshDropShapeNames[shape], stats->generationCount * MESH_DROP_BODY_COUNT, - stats->tunnelCount, stats->awakeCount ); - for ( int i = 0; i < MESH_DROP_DEPTH_LEVEL_COUNT; ++i ) - { - printf( " %10d", stats->depthCounts[i] ); - } - - if ( stats->maxIndex >= 0 ) - { - printf( " %.1f slop, seed %u body (%d, %d) step %d\n", stats->maxDepth / slop, stats->maxSeed, - stats->maxIndex / MESH_DROP_GRID_COUNT, stats->maxIndex % MESH_DROP_GRID_COUNT, stats->maxStep ); - } - else - { - printf( "\n" ); - } - } - - printf( "\nsteps to sleep: average %.0f, max %d, time %.1f s\n", averageSteps, soak.maxSteps, seconds ); - - if ( settings.rough ) - { - int64_t total = 0; - for ( int i = 0; i < B3_MAX_MANIFOLDS; ++i ) - { - total += soak.manifoldCounts[i]; - } - - // The last bucket is the cap, so it holds every contact that was reduced - printf( "contact updates by manifold count:" ); - for ( int i = 0; i < B3_MAX_MANIFOLDS; ++i ) - { - printf( " %d: %.1f%%", i + 1, total > 0 ? 100.0 * soak.manifoldCounts[i] / total : 0.0 ); - } - printf( "\n" ); - } - - int reported = b3MinInt( soak.failureCount, MAX_REPORTED_FAILURES ); - for ( int i = 0; i < reported; ++i ) - { - Failure* f = soak.failures + i; - printf( " %s %s seed %u body (%d, %d)\n", f->kind == e_tunnel ? "tunnel" : "awake", g_meshDropShapeNames[f->shape], - f->seed, f->index / MESH_DROP_GRID_COUNT, f->index % MESH_DROP_GRID_COUNT ); - } - - int exitCode = soak.failureCount == 0 ? 0 : 1; - - if ( writePath != NULL ) - { - WriteBaseline( &soak, writePath ); - } - - if ( comparePath != NULL ) - { - int compareResult = CompareBaseline( &soak, comparePath ); - exitCode = b3MaxInt( exitCode, compareResult ); - } - - printf( exitCode == 0 ? "PASS\n" : "FAIL\n" ); - - b3DestroyHull( soak.cylinder ); - b3DestroyMesh( soak.groundMesh ); - b3DestroyMutex( soak.mutex ); - - return exitCode; -} diff --git a/benchmark/soak_baseline.csv b/benchmark/soak_baseline.csv deleted file mode 100644 index f364117..0000000 --- a/benchmark/soak_baseline.csv +++ /dev/null @@ -1,13 +0,0 @@ -filter,base,generations,shape,tunnels,awake,depth4,depth8,depth16,depth32 -all,12345,16000,box,0,0,23676,3191,44,0 -all,12345,16000,capsule,0,0,231496,54552,515,0 -all,12345,16000,cylinder,0,0,178981,37441,480,0 -all,12345,16000,sphere,0,0,987,0,0,0 -all,12345,1000,box,0,0,1503,218,3,0 -all,12345,1000,capsule,0,0,14507,3488,28,0 -all,12345,1000,cylinder,0,0,10859,2193,36,0 -all,12345,1000,sphere,0,0,56,0,0,0 -rough_all,12345,1000,box,0,0,2107,535,6,0 -rough_all,12345,1000,capsule,0,0,3603,177,1,0 -rough_all,12345,1000,cylinder,0,0,3239,726,21,0 -rough_all,12345,1000,sphere,0,0,0,0,0,0 diff --git a/build_vs2022.bat b/build_vs2022.bat deleted file mode 100644 index bf862e7..0000000 --- a/build_vs2022.bat +++ /dev/null @@ -1,24 +0,0 @@ -@echo off -rem Use this batch file to generate Visual Studio 2022 project files for box3d. -rem -rem Usage: -rem build_vs2022.bat Configure or update project files in build\ -rem build_vs2022.bat fresh Delete build\ first, then configure from scratch -rem -rem Re-running without "fresh" updates the existing project files in place. -rem CMake rewrites .vcxproj/.sln files atomically, so this works even while -rem Visual Studio has the solution open -- VS will detect the change and -rem prompt to reload. - -if /i "%~1"=="fresh" ( - if exist build ( - echo Fresh build requested, removing build\ ... - rmdir /s /q build - if exist build ( - echo ERROR: failed to remove build\ -- is something holding files open? - exit /b 1 - ) - ) -) - -cmake -S . -B build -G "Visual Studio 17 2022" diff --git a/data/dumps/single_box/box3d_dump.inl b/data/dumps/single_box/box3d_dump.inl new file mode 100644 index 0000000..9b60dea --- /dev/null +++ b/data/dumps/single_box/box3d_dump.inl @@ -0,0 +1,85 @@ +b3Vec3 gravity = {0, -10, 0}; +b3World_SetGravity(m_worldId, gravity); +std::vector bodies; +std::vector joints; + +{ + b3BodyDef bd = b3DefaultBodyDef(); + bd.name = "cube"; + bd.type = b3BodyType(2); + bd.position = {-7.98573353e-07, 0.499929696, -9.86034479e-07}; + bd.rotation = {{-4.03613463e-08, 0.825855613, 4.68083634e-08}, 0.563881755}; + bd.linearVelocity = {2.47239775e-08, -1.7695136e-08, 8.65693384e-09}; + bd.angularVelocity = {1.73163173e-08, -4.2026933e-15, -4.94549042e-08}; + bd.linearDamping = 0; + bd.angularDamping = 0; + bd.enableSleep = bool(1); + bd.isAwake = bool(1); + bd.gravityScale = 1; + b3BodyId bodyId = b3CreateBody(m_worldId, &bd); + bodies.push_back(bodyId); + + { + b3ShapeDef sd = b3DefaultShapeDef(); + sd.density = 1000; + sd.isSensor = bool(0); + sd.filter.categoryBits = 0x1; + sd.filter.maskBits = 0xffffffffffffffff; + sd.filter.groupIndex = 0; + sd.baseMaterial.friction = 0.600000024; + sd.baseMaterial.restitution = 0; + sd.baseMaterial.rollingResistance = 0; + b3Vec3 vs[8]; + vs[0] = {0.5, 0.5, 0.5}; + vs[1] = {-0.5, 0.5, 0.5}; + vs[2] = {-0.5, -0.5, 0.5}; + vs[3] = {0.5, -0.5, 0.5}; + vs[4] = {0.5, 0.5, -0.5}; + vs[5] = {-0.5, 0.5, -0.5}; + vs[6] = {-0.5, -0.5, -0.5}; + vs[7] = {0.5, -0.5, -0.5}; + b3HullData* hullData = b3CreateHull(vs, 8, 8); + b3CreateHullShape(bodyId, &sd, hullData); + b3DestroyHull(hullData); + } +} +{ + b3BodyDef bd = b3DefaultBodyDef(); + bd.name = "ground"; + bd.type = b3BodyType(0); + bd.position = {0, -1, 0}; + bd.rotation = {{0, 0, 0}, 1}; + bd.linearVelocity = {0, 0, 0}; + bd.angularVelocity = {0, 0, 0}; + bd.linearDamping = 0; + bd.angularDamping = 0; + bd.enableSleep = bool(1); + bd.isAwake = bool(0); + bd.gravityScale = 1; + b3BodyId bodyId = b3CreateBody(m_worldId, &bd); + bodies.push_back(bodyId); + + { + b3ShapeDef sd = b3DefaultShapeDef(); + sd.density = 1000; + sd.isSensor = bool(0); + sd.filter.categoryBits = 0x1; + sd.filter.maskBits = 0xffffffffffffffff; + sd.filter.groupIndex = 0; + sd.baseMaterial.friction = 0.600000024; + sd.baseMaterial.restitution = 0; + sd.baseMaterial.rollingResistance = 0; + b3Vec3 vs[8]; + vs[0] = {15, 1, 15}; + vs[1] = {-15, 1, 15}; + vs[2] = {-15, -1, 15}; + vs[3] = {15, -1, 15}; + vs[4] = {15, 1, -15}; + vs[5] = {-15, 1, -15}; + vs[6] = {-15, -1, -15}; + vs[7] = {15, -1, -15}; + b3HullData* hullData = b3CreateHull(vs, 8, 8); + b3CreateHullShape(bodyId, &sd, hullData); + b3DestroyHull(hullData); + } +} diff --git a/data/hulls/axe.txt b/data/hulls/axe.txt deleted file mode 100644 index fe3e7ce..0000000 --- a/data/hulls/axe.txt +++ /dev/null @@ -1 +0,0 @@ --0.420565814, 6.27311516, 0.624139011, -0.423157126, 6.43531513, 0.624940872, -0.400363564, 6.24441338, 0.702014863, -0.416245729, 6.17266893, 0.622810602, -0.433529437, 6.29105663, 0.573231816, -0.424020022, 6.62839079, 0.625214338, -0.403299004, 6.41980267, 0.702534437, -0.435781032, 6.44498682, 0.573748231, -0.39546892, 6.13546467, 0.701158941, -0.376558542, 6.21027279, 0.793354034, -0.429776281, 6.19607162, 0.572380662, -0.404258847, 6.12016535, 0.608667254, -0.440633416, 6.30049419, 0.527119458, -0.42315498, 6.82146406, 0.624956846, -0.404275864, 6.62841082, 0.702715218, -0.436531276, 6.62838888, 0.573927343, -0.379765004, 6.40131187, 0.793307424, -0.442748815, 6.45009136, 0.527064621, -0.380489528, 6.07763004, 0.693229854, -0.371210814, 6.09141397, 0.793445706, -0.352786303, 6.17601395, 0.884651542, -0.437107563, 6.20831585, 0.527223408, -0.421900928, 6.14674568, 0.555683434, -0.378666759, 6.10179329, 0.56942004, -0.443256766, 6.30368519, 0.463627696, -0.420562118, 6.98365641, 0.624166369, -0.403294712, 6.83701468, 0.702553868, -0.435780197, 6.81178904, 0.573766887, -0.380831331, 6.62843847, 0.793302, -0.443453908, 6.62839603, 0.52705586, -0.356113642, 6.3827033, 0.88403821, -0.445638776, 6.45190096, 0.462998569, -0.347299904, 6.055583, 0.671490133, -0.354736507, 6.02676058, 0.792831719, -0.347236216, 6.047472, 0.885690987, -0.332682669, 6.14695787, 0.962401867, -0.439286768, 6.21204424, 0.464693397, -0.430589259, 6.16906166, 0.521244645, -0.407282561, 6.1297946, 0.507628977, -0.322530925, 6.10475826, 0.476746678, -0.443575919, 6.30373383, 0.360556096, -0.416241884, 7.08408976, 0.622840762, -0.400356293, 7.01239157, 0.702047944, -0.433527976, 6.96571302, 0.57326442, -0.379758388, 6.85555887, 0.79333353, -0.442748666, 6.80669832, 0.527089894, -0.357219428, 6.62846327, 0.883846343, -0.44643271, 6.62840271, 0.462801337, -0.335903198, 6.36683941, 0.96150583, -0.446347833, 6.4520278, 0.359647483, -0.318150342, 5.99833679, 0.79076165, -0.277453154, 6.0510149, 0.648446918, -0.331143022, 5.97517681, 0.890933752, -0.327310175, 6.01059294, 0.963914692, -0.319883317, 6.12842607, 1.01310015, -0.438956082, 6.21159744, 0.362091303, -0.428903759, 6.15980482, 0.476069212, -0.391884565, 6.13054276, 0.404339224, -0.165798873, 6.09137678, 0.458747327, -0.302039534, 6.1235323, 0.238368377, -0.443767488, 6.30374575, 0.195703521, -0.404255658, 7.13657808, 0.60869509, -0.395461231, 7.12131977, 0.701194584, -0.429774731, 7.06068754, 0.572417438, -0.376547217, 7.04658031, 0.793398738, -0.440633088, 6.95628834, 0.527163327, -0.356105059, 6.8742156, 0.884071171, -0.445638776, 6.80490112, 0.463031411, -0.336973041, 6.62847519, 0.96122092, -0.447271824, 6.62839937, 0.359359771, -0.322692037, 6.35658121, 1.01248837, -0.44677335, 6.45208454, 0.19510901, -0.296186596, 5.93722773, 0.904156804, -0.249230281, 5.98962021, 0.788263321, -0.152502596, 6.0456171, 0.636606455, -0.313261539, 5.93217945, 0.972767949, -0.315197587, 5.98773193, 1.01413727, -0.310311168, 6.11343765, 1.04989588, -0.438757658, 6.21131516, 0.196717665, -0.424416304, 6.1593051, 0.373577535, -0.381670475, 6.13431787, 0.22193633, -7.34580681e-08, 6.08772421, 0.454057723, -0.165297493, 6.11621714, 0.239674717, -0.296461612, 6.12875175, -1.09191251e-05, -0.443831295, 6.30372858, -3.83076112e-05, -0.38048315, 7.17913008, 0.693260372, -0.421899676, 7.11000204, 0.55572027, -0.378664732, 7.15493488, 0.569444001, -0.371198803, 7.16540956, 0.793493092, -0.437107146, 7.04845524, 0.52727282, -0.35277158, 7.0808835, 0.884707689, -0.443256766, 6.95310783, 0.46368432, -0.335893631, 6.89010334, 0.961542308, -0.446347833, 6.80476713, 0.359687001, -0.323624909, 6.62846375, 1.01229727, -0.447775304, 6.62837696, 0.194927484, -0.312764168, 6.34827375, 1.04985118, -0.44691509, 6.45208025, -2.25071708e-05, -0.231420755, 5.92051983, 0.917008758, -0.284012824, 5.88615227, 0.995684922, -0.135754183, 5.98408937, 0.78636533, -1.98313501e-07, 6.04270792, 0.633488476, -0.304644406, 5.90706873, 1.02356648, -0.306217968, 5.96934509, 1.04998815, -0.299889147, 6.09501314, 1.08593857, -0.438691556, 6.21120358, -4.06680119e-05, -0.42147997, 6.15982771, 0.203634292, -0.377859384, 6.13695669, -2.24082669e-05, 0.16579853, 6.09136963, 0.458753914, -2.24478196e-08, 6.10835075, 0.279498875, -0.138670072, 6.11576748, 0.239171118, -0.165076017, 6.11664724, 0.225328684, -0.302039385, 6.12352228, -0.238388941, -0.279497296, 6.12807941, -1.00816333e-05, -0.443767488, 6.30368996, -0.195777908, -0.354731649, 7.23000145, 0.792840838, -0.347295642, 7.20115232, 0.671512187, -0.430588692, 7.08769798, 0.521291852, -0.407281756, 7.1269455, 0.507667124, -0.32253018, 7.15195227, 0.476763695, -0.34722051, 7.20938873, 0.88575083, -0.439286768, 7.044734, 0.464755625, -0.332666337, 7.10996151, 0.962464392, -0.443575948, 6.95305204, 0.360623807, -0.322683156, 6.90034008, 1.0125221, -0.44677332, 6.80466747, 0.195152655, -0.313579917, 6.62847233, 1.0498426, -0.447943091, 6.62834549, 0, -0.302403748, 6.33826208, 1.08645916, -0.44677332, 6.45202351, -0.19515267, -0.12589927, 5.91194773, 0.921137631, -0.225511238, 5.83923531, 1.04820025, -0.284233212, 5.85900593, 1.04935467, -3.23225322e-07, 5.98211765, 0.785567641, 0.152501747, 6.04560709, 0.636612177, -0.301061481, 5.91173029, 1.04980791, -0.295690835, 5.94588757, 1.08509719, -0.285476804, 6.06730127, 1.13435495, -0.438757658, 6.2112689, -0.196796864, -0.420399696, 6.16033602, -3.39308936e-05, -0.381670326, 6.13429689, -0.221979678, 0.32253018, 6.10473871, 0.476763695, 0.165297419, 6.11621332, 0.239682525, 0.086369887, 6.11119843, 0.265819222, -8.3297147e-09, 1.3441813, 0.279498726, -0.0863699168, 6.11149788, 0.265819222, -0.164285332, 6.11605644, 0.226119369, -0.182904437, 6.11789989, 0.207500264, -0.32253021, 6.10473871, -0.476763725, -0.165297419, 6.11621332, -0.23968251, -0.279498905, 6.12807894, 4.02538269e-09, -0.272587925, 6.12646961, -0.0436344296, -0.443575919, 6.30363894, -0.360623807, -0.318164319, 7.25831223, 0.790665567, -0.331150413, 7.28153563, 0.890861154, -0.277451128, 7.20569944, 0.648459554, -0.42890352, 7.09695435, 0.476123691, -0.391884238, 7.12618637, 0.404379696, -0.16579853, 7.16532135, 0.458753914, -0.302039385, 7.1331687, 0.238388941, -0.327292442, 7.2462883, 0.963982165, -0.438956082, 7.04517269, 0.36216414, -0.319868058, 7.12847614, 1.01315844, -0.443767488, 6.95300102, 0.195777923, -0.312761307, 6.90865183, 1.04985857, -0.44691515, 6.80461073, 2.25071708e-05, -0.303243041, 6.62854338, 1.08662438, -0.447775304, 6.62831402, -0.194927514, -0.288269371, 6.32334375, 1.13516843, -0.446347833, 6.45192385, -0.359687001, -3.43185093e-07, 5.90969229, 0.921022594, -0.11619395, 5.8294673, 1.04748738, -0.181410655, 5.74001026, 1.17642462, -0.257047713, 5.81331062, 1.10132825, -0.29030636, 5.87313557, 1.07566071, 0.135752946, 5.98407793, 0.786370695, 0.277451128, 6.05099154, 0.648459554, -0.280808836, 5.91007566, 1.1330471, -0.263933629, 6.02445316, 1.20827043, -0.438956082, 6.21151829, -0.36216414, -0.42147997, 6.15979338, -0.203700453, -0.391884238, 6.13050461, -0.404379696, 0.302039385, 6.12352228, 0.238388941, 0.378664732, 6.1017561, 0.569444001, 0.391884238, 6.13050461, 0.404379696, 0.165075839, 6.11664391, 0.225328803, 0.138657346, 6.11576414, 0.239177421, 0.086369887, 1.3441813, 0.265819073, -0.0863699168, 1.3441813, 0.265819073, -8.61839577e-09, 1.28562617, 0.254942268, -0.164285332, 1.3441813, 0.226119503, -0.226119384, 6.12120199, 0.164285332, -0.378664732, 6.1017561, -0.569443941, -0.16579853, 6.09136963, -0.458753914, -0.277451128, 6.05099154, -0.648459554, -0.165075839, 6.11664391, -0.225328937, -0.138657674, 6.11576414, -0.239177421, -0.279498905, 1.3441813, 1.33275464e-07, -0.272592217, 6.12647057, 0.0436073244, -0.265819341, 6.12511873, -0.0863699093, -0.443256766, 6.30358315, -0.46368432, -0.24925819, 7.26689911, 0.788037598, -0.296260297, 7.31912899, 0.903698802, -0.313283414, 7.32448053, 0.972614944, -0.152501747, 7.21108389, 0.636612177, -0.424416244, 7.09744596, 0.373639077, -0.381670326, 7.12239408, 0.221979663, 8.34697857e-08, 7.16896677, 0.454057723, -0.165297419, 7.14047766, 0.23968251, -0.296461612, 7.12793922, 1.09203329e-05, -0.315180749, 7.26913834, 1.01420152, -0.438757688, 7.04542208, 0.196796849, -0.310311139, 7.14343166, 1.04988754, -0.443831295, 6.9529624, 3.83100269e-05, -0.30241558, 6.91876459, 1.0863992, -0.44677332, 6.80460644, -0.195108995, -0.289206415, 6.62872124, 1.1354053, -0.447271824, 6.62829161, -0.359359771, -0.267019719, 6.3003149, 1.20883405, -0.445638776, 6.45178986, -0.463031411, 0.125897869, 5.91193533, 0.921142876, -3.18628736e-07, 5.82673359, 1.04730546, -0.0998942629, 5.73692417, 1.17197931, -0.15263997, 5.64101887, 1.2949971, -0.226171315, 5.73974991, 1.18931413, -0.272065639, 5.83197594, 1.12433982, 0.249227121, 5.98959064, 0.788276851, 0.347295642, 6.05553865, 0.671512187, -0.258764625, 5.85462618, 1.20741999, -0.238956943, 5.97377586, 1.29493284, -0.439286739, 6.21195698, -0.464755625, -0.424416274, 6.15924549, -0.373639077, -0.407281756, 6.12974548, -0.507667124, 0.381670326, 6.13429689, 0.221979663, 0.296461612, 6.12875175, 1.09203329e-05, 0.407281756, 6.12974548, 0.507667124, 0.404255658, 6.1201129, 0.60869509, 0.424416244, 6.15924501, 0.373639077, 0.164285302, 6.11604118, 0.226119339, 0.182916105, 6.11789751, 0.207488537, 0.164285302, 1.3441813, 0.22611919, 0.0787815228, 1.28562617, 0.242464468, -0.0787815526, 1.28562617, 0.242464468, -9.31532984e-09, 1.26137209, 0.195657715, -0.149851412, 1.28562617, 0.206252888, -0.226119384, 1.3441813, 0.164285466, -0.265819341, 6.12512016, 0.0863699168, -0.404255658, 6.1201129, -0.60869509, -0.347295672, 6.05553865, -0.671512067, 8.3935447e-08, 6.08772421, -0.454057723, -0.152501762, 6.04560709, -0.636612177, -0.249227121, 5.98959112, -0.788276851, -0.164285362, 6.11605835, -0.226119414, -0.182915941, 6.11789751, -0.20748882, -0.0863699391, 6.11133337, -0.265819401, -0.265819341, 1.3441813, 0.0863700435, -0.254942447, 1.28562617, 1.33275464e-07, -0.265819341, 1.3441813, -0.0863697827, -0.226119399, 6.12119913, -0.164285347, -0.440633088, 6.30040264, -0.527163327, -0.135774553, 7.2723217, 0.786026418, -0.231541172, 7.33540201, 0.91606617, -0.284150362, 7.36993647, 0.994881928, -0.304674238, 7.34958363, 1.02339602, 1.98313501e-07, 7.21398306, 0.633488476, -0.42147994, 7.0968976, 0.203700453, -0.377859354, 7.11973381, 2.2412647e-05, 0.165798873, 7.1653142, 0.458747327, 1.51007473e-08, 7.14834023, 0.279498905, -0.165075839, 7.14004707, 0.225328848, -0.138657719, 7.14092684, 0.239177421, -0.302039534, 7.13315868, -0.238368362, -0.279497296, 7.12861156, 1.00826892e-05, -0.306232214, 7.28743124, 1.0499177, -0.438691556, 7.0454874, 4.06390209e-05, -0.299929738, 7.16183329, 1.08574927, -0.443767488, 6.95294523, -0.195703536, -0.288308054, 6.93395376, 1.13498354, -0.446347833, 6.80466318, -0.359647483, -0.268062264, 6.62904978, 1.20894837, -0.44643271, 6.62828827, -0.462801337, -0.242273688, 6.27264404, 1.29497945, -0.442748666, 6.44999266, -0.527089894, 0.231416866, 5.9204855, 0.91702354, 0.116192684, 5.82945538, 1.04749227, -2.22877134e-07, 5.73454285, 1.17186856, -0.0828618631, 5.63490438, 1.2949146, -0.196217477, 5.65075827, 1.29506195, -0.131680921, 5.53568459, 1.41265607, -0.247511044, 5.76750231, 1.20239663, 0.318143785, 5.99827671, 0.790788293, 0.38048315, 6.0775609, 0.693260372, -0.233388737, 5.78941584, 1.29499769, -0.214244157, 5.922575, 1.3815906, -0.437107146, 6.20823574, -0.52727282, -0.42890352, 6.15973663, -0.476123691, -0.421899676, 6.14668894, -0.55572027, 0.377859354, 6.13695717, 2.2412647e-05, 0.42147994, 6.15979338, 0.203700453, 0.302039534, 6.1235323, -0.238368362, 0.279497236, 6.12807941, 1.00814714e-05, 0.421899676, 6.14668894, 0.55572027, 0.42890352, 6.15973663, 0.476123691, 0.416241884, 6.17260122, 0.622840762, 0.438956082, 6.21151829, 0.36216414, 0.226119339, 6.12119913, 0.164285302, 0.226119339, 1.3441813, 0.164285153, 0.149851367, 1.28562617, 0.206252575, 0.0604615882, 1.26137209, 0.186081529, -0.0604616255, 1.26137209, 0.186081529, 0, 1.26137209, 0, -0.206252769, 1.28562617, 0.149851531, -0.115004838, 1.26137209, 0.158290386, -0.38048315, 6.0775609, -0.693260372, -0.416241884, 6.17260122, -0.622840762, -0.318143785, 5.99827671, -0.790788293, 0.165798873, 6.09137678, -0.458747327, 1.98488124e-07, 6.04270792, -0.633488476, 1.93174348e-08, 6.10835075, -0.279499024, -0.135752946, 5.98407793, -0.786370695, -0.231416866, 5.9204855, -0.91702354, -0.164285362, 1.3441813, -0.22611928, -0.0863699391, 1.3441813, -0.265819341, -0.242464721, 1.28562617, 0.0787816867, -0.195657909, 1.26137209, 1.33275464e-07, -0.242464721, 1.28562617, -0.0787814185, -0.226119399, 1.3441813, -0.164285213, -0.433527976, 6.29097795, -0.57326442, -0.125984326, 7.34358931, 0.919766307, -1.56361784e-06, 7.27423811, 0.785173655, -0.225884482, 7.41538906, 1.04568243, -0.284401506, 7.39706802, 1.04848611, -0.3011235, 7.34484911, 1.04951715, 0.152502596, 7.21107388, 0.636606455, -0.420399666, 7.09635496, 3.39203725e-05, -0.381670475, 7.1223731, -0.22193639, 0.322530895, 7.15193272, 0.476746678, 0.165297523, 7.14047384, 0.239674702, -0.0863699168, 7.14467192, 0.265819252, -8.3297147e-09, 7.51029158, 0.279498905, 0.086369887, 7.14462614, 0.265819252, -0.164285332, 7.14005041, 0.226119354, -0.18291603, 7.13879347, 0.207488656, -0.322530925, 7.15193272, -0.476746678, -0.165297493, 7.14047384, -0.239674717, -0.279498905, 7.12861204, -2.3006745e-08, -0.272587925, 7.13022137, 0.043634437, -0.295793891, 7.31065845, 1.08463991, -0.438757658, 7.04537582, -0.196717694, -0.285594136, 7.18956089, 1.13382041, -0.443575919, 6.95295715, -0.360556066, -0.267100781, 6.95749617, 1.20845032, -0.445638746, 6.80479002, -0.462998539, -0.243394509, 6.62857056, 1.29488754, -0.443453968, 6.62829494, -0.52705586, -0.21765025, 6.24379826, 1.3811276, -0.435780197, 6.44490194, -0.573766887, 0.296178102, 5.93715286, 0.904189169, 0.225507602, 5.83920288, 1.04821408, 0.0998933986, 5.73691654, 1.17198241, 1.46375078e-05, 5.6327486, 1.29487169, -0.0709583387, 5.52399302, 1.41659379, -0.220748916, 5.69119883, 1.29507399, -0.171799481, 5.55877066, 1.40032125, -0.118125923, 5.41381836, 1.53769684, 0.354726493, 6.02666378, 0.792871535, 0.395461231, 6.13537121, 0.701194584, -0.20851171, 5.72432184, 1.38256216, -0.193492502, 5.87815857, 1.45549119, -0.429774731, 6.19600344, -0.572417438, -0.430588663, 6.168993, -0.521291852, 0.381670505, 6.13431787, -0.22193639, 0.420399666, 6.16033602, 3.39348662e-05, 0.438757658, 6.2112689, 0.196796849, 0.322530955, 6.10475826, -0.476746678, 0.165297523, 6.11621714, -0.239674702, 0.279498845, 6.12807894, -1.14942331e-08, 0.272587776, 6.12646961, 0.043634709, 0.430588692, 6.168993, 0.521291852, 0.429774731, 6.19600344, 0.572417438, 0.439286739, 6.21195698, 0.464755625, 0.420562148, 6.27303457, 0.624166429, 0.443575919, 6.30363894, 0.360623807, 0.265819192, 6.12511873, 0.0863699019, 0.265819192, 1.3441813, 0.0863697454, 0.206252739, 1.28562617, 0.149851218, 0.115004793, 1.26137209, 0.158290371, 0.186081797, 1.26137209, -0.0604617298, 0.158290669, 1.26137209, -0.115004897, 0.115004912, 1.26137209, -0.15829064, 0.0604616627, 1.26137209, -0.186081842, 1.41108716e-08, 1.26137209, -0.195657983, -0.0604616292, 1.26137209, -0.186081782, -0.115004838, 1.26137209, -0.158290505, -0.15829058, 1.26137209, -0.115004703, -0.186081752, 1.26137209, -0.0604614913, -0.186081752, 1.26137209, 0.0604617558, -0.15829058, 1.26137209, 0.115004949, 0.15829052, 1.26137209, 0.115004636, 0.186081663, 1.26137209, 0.0604614429, 0.195657864, 1.26137209, -1.54655382e-07, -0.354726493, 6.02666378, -0.792871535, -0.395461231, 6.13537121, -0.701194584, -0.420562118, 6.27303457, -0.624166369, -0.296178102, 5.93715286, -0.904189169, 0.152502537, 6.0456171, -0.636606455, 3.03434717e-07, 5.98211765, -0.785567641, 0, 1.3441813, -0.279498965, 0.0863699391, 6.11137819, -0.265819401, -0.125897869, 5.91193533, -0.921142876, -0.225507602, 5.83920288, -1.04821408, -0.149851456, 1.28562617, -0.206252679, -0.0787815675, 1.28562617, -0.242464751, -0.206252798, 1.28562617, -0.149851277, -7.17531657e-06, 7.34565639, 0.919446766, -0.116455019, 7.42408895, 1.04377484, 0.135772571, 7.2723074, 0.786019921, -0.257534236, 7.44143343, 1.09880614, -0.182427585, 7.51092958, 1.16946995, -0.290465444, 7.38311243, 1.07493198, 0.277453154, 7.20567608, 0.648446918, -0.42147997, 7.09686327, -0.203634292, -0.391884565, 7.12614822, -0.404339224, 0.378666759, 7.15489769, 0.56942004, 0.302039534, 7.13315868, 0.238368377, 0.391884565, 7.12614822, 0.404339284, 0.138669819, 7.1409235, 0.239171103, 0.165076047, 7.14004374, 0.225328624, -0.0863699168, 7.51029158, 0.265819252, -8.61839577e-09, 7.56884527, 0.254942477, 0.086369887, 7.51029158, 0.265819252, -0.164285332, 7.51029158, 0.226119339, -0.226119384, 7.13549185, 0.164285317, -0.277453154, 7.20567608, -0.648446918, -0.165798873, 7.1653142, -0.458747327, -0.378666759, 7.15489769, -0.56942004, -0.138670087, 7.1409235, -0.239171118, -0.165076017, 7.14004374, -0.225328773, -0.279498905, 7.51029158, -3.33188659e-08, -0.272592247, 7.13022041, -0.0436073169, -0.265819341, 7.13157225, 0.086369887, -0.281084716, 7.34606075, 1.13183379, -0.438956082, 7.04509354, -0.362091303, -0.264174789, 7.23249292, 1.2071768, -0.443256766, 6.95300579, -0.463627696, -0.242374972, 6.98410416, 1.2944082, -0.442748815, 6.80659962, -0.527064621, -0.218787104, 6.62632561, 1.38085747, -0.436531276, 6.6283021, -0.573927343, -0.196768254, 6.21724606, 1.45480144, -0.42315498, 6.43522692, -0.624956846, 0.284003228, 5.88606691, 0.995721519, 0.331129879, 5.97505283, 0.890983939, 0.181408972, 5.73999453, 1.17643082, 0.257042885, 5.81326675, 1.10134661, 0.0828872696, 5.63488531, 1.294927, 5.89085903e-05, 5.5209794, 1.41647434, -0.0605682731, 5.40043592, 1.53679967, -0.195885792, 5.61455011, 1.38761473, -0.155908078, 5.48248768, 1.48746622, -0.0877592564, 5.26322508, 1.66027737, -0.132033154, 5.3718133, 1.58911765, 0.371198803, 6.09128141, 0.793493092, 0.400356293, 6.24429941, 0.702047944, -0.187964052, 5.66922092, 1.45689499, -0.180399314, 5.84783316, 1.50388217, 0.42147997, 6.15982771, -0.203634292, 0.391884565, 6.13054276, -0.404339284, 0.438691556, 6.21120358, 4.06392865e-05, 0.443767488, 6.30368996, 0.195777923, 0.277453154, 6.0510149, -0.648446918, 0.378666759, 6.10179329, -0.56942004, 0.138670206, 6.11576748, -0.239171103, 0.165076047, 6.11664724, -0.225328892, 0.279498845, 1.3441813, -1.66594333e-07, 0.272592187, 6.12647057, -0.0436073951, 0.437107146, 6.20823574, 0.52727282, 0.433527976, 6.29097795, 0.57326442, 0.443256766, 6.30358315, 0.46368432, 0.42315498, 6.43522692, 0.624956846, 0.446347833, 6.45192385, 0.359687001, 0.242464617, 1.28562617, 0.0787813812, 0.242464766, 1.28562617, -0.0787816197, 0.206252888, 1.28562617, -0.149851471, 0.149851486, 1.28562617, -0.206252873, 0.0787815824, 1.28562617, -0.242464766, 4.13297885e-09, 1.28562617, -0.254942507, 0.254942447, 1.28562617, -9.24175012e-08, -0.371198803, 6.09128141, -0.793493092, -0.331129879, 5.97505283, -0.890983939, -0.400356293, 6.24429941, -0.702047944, -0.284003228, 5.88606691, -0.995721519, 0.135754183, 5.98408937, -0.78636533, 3.43185093e-07, 5.90969229, -0.921022594, 0.0863699391, 1.3441813, -0.265819341, -0.116192684, 5.82945538, -1.04749227, -0.181408972, 5.73999453, -1.17643082, -0.257042885, 5.81326675, -1.10134661, 0.125972882, 7.34356785, 0.919755757, -1.90703722e-05, 7.42648506, 1.04322731, -0.100510523, 7.51302147, 1.16399562, 0.249259219, 7.26686621, 0.788022101, -0.272493392, 7.42337704, 1.12237763, -0.22724396, 7.51252317, 1.18369079, -0.154114068, 7.59775734, 1.27728057, 0.347299904, 7.20110798, 0.671490133, -0.424416333, 7.09738588, -0.373577565, -0.407282531, 7.12689638, -0.507628977, 0.407282561, 7.12689638, 0.507628977, 0.404258847, 7.13652563, 0.608667254, 0.381670445, 7.1223731, 0.22193633, 0.296461612, 7.12793922, -1.09215407e-05, 0.424416304, 7.09738588, 0.373577535, 0.164285302, 7.13977194, 0.226119369, 0.182904527, 7.13879108, 0.207500145, -0.0787815526, 7.56884527, 0.242464662, -9.31532984e-09, 7.59310007, 0.195657909, 0.0787815228, 7.56884527, 0.242464662, 0.164285302, 7.51029158, 0.226119384, -0.226119384, 7.51029158, 0.164285302, -0.149851412, 7.56884527, 0.206252724, -0.249259219, 7.26686621, -0.788022101, -0.152502537, 7.21107388, -0.636606455, -0.347299904, 7.20110798, -0.671490133, -7.36908987e-08, 7.16896677, -0.454057723, -0.404258847, 7.13652563, -0.608667254, -0.164285362, 7.14004517, -0.226119429, -0.0863699391, 7.14450407, -0.265819401, -0.182904348, 7.13879108, -0.207500428, -0.265819341, 7.51029158, -0.0863699466, -0.254942447, 7.56884527, -3.33188659e-08, -0.265819341, 7.51029158, 0.0863698795, -0.265819341, 7.13157082, -0.0863699391, -0.259323657, 7.40087843, 1.20496547, -0.439286768, 7.04464674, -0.464693397, -0.239270881, 7.28179407, 1.29329097, -0.440633416, 6.95619678, -0.527119458, -0.217711896, 7.00849152, 1.38046527, -0.435781032, 6.81170416, -0.573748231, -0.197824031, 6.62135839, 1.45449197, -0.424020022, 6.62830019, -0.625214338, -0.183246627, 6.19645405, 1.50352371, -0.403294712, 6.4196763, -0.702553868, 0.313246608, 5.93203878, 0.972824752, 0.284223408, 5.85891914, 1.04939187, 0.34722051, 6.04730225, 0.88575083, 0.152657047, 5.64098644, 1.295017, 0.226168826, 5.73972654, 1.18932343, 0.27206108, 5.83192062, 1.12435734, 0.0710614175, 5.5239296, 1.41663849, 0.000152599809, 5.39668751, 1.53658283, -0.048076205, 5.26048088, 1.65531445, -0.176622659, 5.55060577, 1.46541834, -0.151534066, 5.44061136, 1.53887141, -0.0674578622, 5.12431622, 1.76779604, -0.109993391, 5.2592659, 1.67399967, -0.139934972, 5.39250278, 1.61204028, 0.376547217, 6.21011066, 0.793398738, 0.403294742, 6.4196763, 0.702553868, -0.175576344, 5.63398933, 1.50477803, -0.171244964, 5.81763649, 1.53953564, 0.424416333, 6.1593051, -0.373577565, 0.438757658, 6.21131516, -0.196717694, 0.407282531, 6.1297946, -0.507628977, 0.443831325, 6.30372858, 3.83076112e-05, 0.44677338, 6.45202351, 0.195152655, 0.249230281, 5.98962021, -0.788263321, 0.347299904, 6.055583, -0.671490133, 0.404258847, 6.12016535, -0.608667254, 0.164285421, 6.11633635, -0.226119518, 0.182904199, 6.11789989, -0.207500741, 0.265819371, 1.3441813, -0.0863699466, 0.265819371, 6.12512016, -0.0863699988, 0.440633059, 6.30040264, 0.527163327, 0.435780168, 6.44490194, 0.573766887, 0.445638776, 6.45178986, 0.463031441, 0.424020022, 6.62830019, 0.625214219, 0.447271824, 6.62829161, 0.359359801, 0.226119488, 1.3441813, -0.164285421, 0.164285421, 1.3441813, -0.226119474, -0.34722051, 6.04730225, -0.88575083, -0.376547217, 6.21011066, -0.793398738, -0.313246608, 5.93203878, -0.972824752, -0.284223408, 5.85891914, -1.04939187, 0.12589927, 5.91194773, -0.921137631, 3.18628736e-07, 5.82673359, -1.04730546, -0.0998933986, 5.73691654, -1.17198241, -0.152652979, 5.64097738, -1.29502368, -0.226168826, 5.73972654, -1.18932343, -0.27206108, 5.83192062, -1.12435734, 0.231536552, 7.33535433, 0.91604346, 0.116421811, 7.42405033, 1.0437535, -3.97457625e-05, 7.5149703, 1.16343486, -0.0837713629, 7.60101795, 1.2749846, 0.318169862, 7.25824928, 0.790637732, -0.248396859, 7.48633003, 1.19830656, -0.197733015, 7.59357834, 1.28236389, -0.133080393, 7.67464352, 1.37233925, 0.380489528, 7.17906094, 0.693229854, -0.428903759, 7.09688616, -0.476069212, -0.421900928, 7.1099453, -0.555683434, 0.421900928, 7.1099453, 0.555683434, 0.428903759, 7.09688616, 0.476069212, 0.416245729, 7.08402205, 0.622810602, 0.377859384, 7.11973429, -2.24082669e-05, 0.42147997, 7.09686327, 0.203634292, 0.302039385, 7.1331687, -0.238388941, 0.279497236, 7.12861156, -1.00825264e-05, 0.438956082, 7.04509354, 0.362091303, 0.226119339, 7.13548899, 0.164285332, -0.0604616255, 7.59310007, 0.186081737, 0.0604615882, 7.59310007, 0.186081737, 0, 7.59310007, 0, 0.149851367, 7.56884527, 0.206252769, 0.226119339, 7.51029158, 0.164285347, -0.206252769, 7.56884527, 0.149851367, -0.115004838, 7.59310007, 0.15829058, -0.318169862, 7.25824928, -0.790637732, -0.231536552, 7.33535433, -0.91604346, -0.135772571, 7.2723074, -0.786019921, -1.98488124e-07, 7.21398306, -0.633488476, -0.380489528, 7.17906094, -0.693229854, 0.16579853, 7.16532135, -0.458753914, -1.83059665e-08, 7.14834023, -0.279499024, -0.416245729, 7.08402205, -0.622810602, -0.164285362, 7.51029158, -0.226119444, -0.0863699391, 7.51029158, -0.265819401, -0.226119399, 7.13548899, -0.164285362, -0.226119399, 7.51029158, -0.164285377, -0.242464721, 7.56884527, -0.0787815824, -0.195657909, 7.59310007, -3.33188659e-08, -0.242464721, 7.56884527, 0.0787815154, -0.234137714, 7.46419048, 1.29128766, -0.437107563, 7.04837513, -0.527223408, -0.214481756, 7.32862949, 1.37963545, -0.433529437, 6.96563435, -0.573231816, -0.196692616, 7.02537203, 1.45423019, -0.423157126, 6.82137585, -0.624940872, -0.184089303, 6.61271, 1.50342572, -0.404275864, 6.62828016, -0.702715218, -0.173716366, 6.16901445, 1.53983116, -0.379758388, 6.40113211, -0.79333353, 0.327292442, 6.01040268, 0.963982165, 0.304629743, 5.9069314, 1.02362251, 0.290297121, 5.87304449, 1.07569623, 0.35277158, 6.17580748, 0.884707689, 0.196224973, 5.65072536, 1.29507935, 0.131752342, 5.53558636, 1.41272449, 0.247509077, 5.76745892, 1.20240414, 0.280805796, 5.90999365, 1.13305914, 0.0608473271, 5.40024948, 1.53693473, 0.000315719255, 5.25732327, 1.65510249, -0.0361039303, 5.11989498, 1.76587057, -0.166660354, 5.51241732, 1.51388383, -0.153856233, 5.45831108, 1.56439376, -0.051867079, 4.99970007, 1.86274755, -0.0882846341, 5.12922621, 1.77260506, -0.121579073, 5.28846741, 1.68832004, -0.146261826, 5.49427271, 1.62141442, 0.379758388, 6.40113211, 0.79333353, 0.404275864, 6.62828016, 0.702715218, -0.167041779, 5.60303307, 1.5393852, -0.162309721, 5.7736063, 1.57522488, 0.438956082, 6.21159744, -0.362091303, 0.428903759, 6.15980482, -0.476069212, 0.443767488, 6.30374575, -0.195703536, 0.421900928, 6.14674568, -0.555683434, 0.44691509, 6.45208025, 2.25071708e-05, 0.447775304, 6.62831402, 0.194927514, 0.318150342, 5.99833679, -0.79076165, 0.231420755, 5.92051983, -0.917008758, 0.380489528, 6.07763004, -0.693229854, 0.416245729, 6.17266893, -0.622810602, 0.226119488, 6.12120199, -0.164285466, 0.442748636, 6.44999266, 0.527089894, 0.436531246, 6.6283021, 0.573927343, 0.44643271, 6.62828827, 0.462801337, 0.423157126, 6.82137585, 0.624940872, 0.446347833, 6.80466318, 0.359647483, -0.327292442, 6.01040268, -0.963982165, -0.35277158, 6.17580748, -0.884707689, -0.304629743, 5.9069314, -1.02362251, -0.290297121, 5.87304449, -1.07569623, 0.11619395, 5.8294673, -1.04748738, 2.22877134e-07, 5.73454285, -1.17186856, -0.0828776583, 5.63486338, -1.29494286, -0.196223646, 5.6507225, -1.2950815, -0.131736115, 5.53554964, -1.41275144, -0.247509077, 5.76745892, -1.20240414, -0.280805796, 5.90999365, -1.13305914, 0.296264559, 7.31904459, 0.903661013, 0.225867122, 7.41530323, 1.04563987, 0.100437641, 7.51294899, 1.16395378, -6.26124965e-05, 7.60239077, 1.27451706, -0.0718580559, 7.67871094, 1.37129664, 0.354741335, 7.22990417, 0.792800844, -0.221962705, 7.5589118, 1.28783321, -0.173203558, 7.66784096, 1.37404954, -0.118389323, 7.73362541, 1.44812167, 0.39546892, 7.12122631, 0.701159, -0.430589259, 7.08762932, -0.521244645, -0.429776281, 7.06061935, -0.572380662, 0.430589229, 7.08762932, 0.521244526, 0.429776281, 7.06061935, 0.572380662, 0.439286768, 7.04464674, 0.464693427, 0.420565814, 6.98357582, 0.624139011, 0.381670356, 7.12239408, -0.221979678, 0.420399696, 7.09635496, -3.39308936e-05, 0.438757658, 7.04537582, 0.196717665, 0.32253018, 7.15195227, -0.476763725, 0.165297419, 7.14047766, -0.239682525, 0.279498845, 7.12861204, 2.09443201e-08, 0.272587895, 7.13022137, -0.0436344929, 0.443575948, 6.95295715, 0.360556096, 0.265819192, 7.13157082, 0.0863699317, 0.115004793, 7.59310007, 0.158290565, 0.195657864, 7.59310007, -8.80176501e-08, 0.186081663, 7.59310007, 0.0604616441, 0.15829052, 7.59310007, 0.115004838, -0.15829058, 7.59310007, 0.115004778, -0.186081752, 7.59310007, 0.0604615882, -0.186081752, 7.59310007, -0.060461659, -0.15829058, 7.59310007, -0.115004867, -0.115004838, 7.59310007, -0.158290669, -0.0604616292, 7.59310007, -0.186081856, 1.41108716e-08, 7.59310007, -0.195658043, 0.0604616627, 7.59310007, -0.186081901, 0.115004912, 7.59310007, -0.158290699, 0.158290669, 7.59310007, -0.115004957, 0.186081797, 7.59310007, -0.0604617968, 0.206252739, 7.56884527, 0.149851412, 0.265819192, 7.51029158, 0.0863699466, -0.296264559, 7.31904459, -0.903661013, -0.354741365, 7.22990417, -0.792800784, -0.125972882, 7.34356785, -0.919755757, -0.225867122, 7.41530323, -1.04563987, 1.57607428e-06, 7.27423811, -0.785173655, 0.152501762, 7.21108389, -0.636612177, -0.39546892, 7.12122631, -0.701158941, 0.0863699391, 7.14480782, -0.265819401, 0, 7.51029158, -0.279499024, -0.420565814, 6.98357582, -0.624139011, -0.149851456, 7.56884527, -0.206252843, -0.0787815675, 7.56884527, -0.242464826, -0.206252798, 7.56884527, -0.149851456, -0.209153906, 7.52507401, 1.37805271, -0.193406716, 7.36416292, 1.45368183, -0.182898492, 7.029459, 1.50331092, -0.403299004, 6.83688831, -0.702534437, -0.174380168, 6.58932781, 1.54009831, -0.380831331, 6.62825251, -0.793302, -0.164808542, 6.12251854, 1.57625866, -0.356105059, 6.38247538, -0.884071171, 0.315180749, 5.98755264, 1.01420152, 0.332666337, 6.14672947, 0.962464333, 0.301048696, 5.91160393, 1.0498569, 0.295682311, 5.94577789, 1.08512998, 0.356105059, 6.38247538, 0.884071171, 0.171834812, 5.55869246, 1.40037119, 0.220750496, 5.69114923, 1.29507947, 0.11831709, 5.41353464, 1.53790116, 0.258765846, 5.85453892, 1.2074163, 0.285477847, 6.06717491, 1.13435245, 0.0486764275, 5.2600441, 1.65563273, 0.000496374036, 5.11762619, 1.76576054, -0.0272732545, 4.99444771, 1.86220205, -0.16278553, 5.51774311, 1.53923464, -0.158053547, 5.56075668, 1.57389069, -0.0697767287, 5.00795269, 1.86402178, -0.0406090058, 4.9021678, 1.93815839, -0.101418696, 5.16672325, 1.77801585, -0.129316807, 5.39069462, 1.69507611, -0.150852427, 5.70313454, 1.62369382, 0.380831361, 6.62825251, 0.79330194, 0.403299004, 6.83688831, 0.702534437, 0.443575919, 6.30373383, -0.360556066, 0.439286768, 6.21204424, -0.464693397, 0.430589229, 6.16906166, -0.521244526, 0.44677335, 6.45208454, -0.19510901, 0.429776281, 6.19607162, -0.572380662, 0.447943091, 6.62834549, 0, 0.44677332, 6.80460644, 0.195108995, 0.296186596, 5.93722773, -0.904156804, 0.354736477, 6.02676058, -0.792831779, 0.225511238, 5.83923531, -1.04820025, 0.39546892, 6.13546467, -0.701159, 0.420565814, 6.27311516, -0.624139011, 0.443453908, 6.62829494, 0.5270558, 0.435781032, 6.81170416, 0.573748231, 0.445638776, 6.80479002, 0.462998539, -0.315180749, 5.98755264, -1.01420152, -0.332666337, 6.14672947, -0.962464392, -0.301048696, 5.91160393, -1.0498569, -0.295682341, 5.94577789, -1.08512998, 0.0998942629, 5.73692417, -1.17197931, 1.06754669e-07, 5.63271523, -1.29489601, -0.0710229874, 5.52384281, -1.41670203, -0.171829507, 5.55868053, -1.40038002, -0.220750168, 5.69114828, -1.29508007, -0.118282102, 5.41345549, -1.53795898, -0.258765846, 5.85453892, -1.2074163, -0.285477847, 6.06717491, -1.13435256, 0.284153521, 7.36982727, 0.994833052, 0.331162542, 7.28140974, 0.890809834, 0.182371825, 7.51076508, 1.16938436, 0.257524669, 7.44125843, 1.0987289, 0.0836544409, 7.60090685, 1.27491915, -8.10358761e-05, 7.68002558, 1.37092125, -0.0638381392, 7.73844814, 1.44730675, 0.371210814, 7.165277, 0.793445706, -0.196977943, 7.62806463, 1.37607217, -0.154556111, 7.7255621, 1.4494499, -0.10910362, 7.76674175, 1.4981035, 0.400363564, 7.0122776, 0.702014863, 0.437107563, 7.04837513, 0.527223408, 0.433529437, 6.96563435, 0.573231816, 0.443256766, 6.95300579, 0.463627696, 0.42147997, 7.0968976, -0.203700453, 0.391884238, 7.12618637, -0.404379696, 0.438691556, 7.0454874, -4.06682775e-05, 0.443767488, 6.95294523, 0.195703521, 0.277451128, 7.20569944, -0.648459554, 0.378664732, 7.15493488, -0.569443941, 0.165075839, 7.14004707, -0.225329116, 0.138657808, 7.14092684, -0.239177436, 0.279498845, 7.51029158, 3.33188659e-08, 0.272592068, 7.13022041, 0.0436075963, 0.265819371, 7.13157225, -0.0863700062, 0.254942447, 7.56884527, -2.57797712e-08, 0.242464617, 7.56884527, 0.0787815824, 4.13297885e-09, 7.56884527, -0.254942596, 0.0787815824, 7.56884527, -0.24246484, 0.149851486, 7.56884527, -0.206252947, 0.206252888, 7.56884527, -0.149851531, 0.242464766, 7.56884527, -0.0787816867, -0.331162542, 7.28140974, -0.890809834, -0.284153521, 7.36982727, -0.994833052, -0.371210814, 7.165277, -0.793445706, 7.17531657e-06, 7.34565639, -0.919446766, -0.116421811, 7.42405033, -1.04375362, -0.18237181, 7.51076508, -1.16938436, -0.257524669, 7.44125843, -1.0987289, 0.135774553, 7.2723217, -0.786026418, -0.400363564, 7.0122776, -0.702014863, 0.0863699391, 7.51029158, -0.265819401, -0.187999129, 7.57260704, 1.4525131, -0.179645151, 7.37955856, 1.50290215, -0.173160419, 7.0107379, 1.54016471, -0.379765004, 6.8553791, -0.793307424, -0.165493831, 6.54015923, 1.57694769, -0.357219428, 6.62822771, -0.883846343, -0.153545499, 6.04509926, 1.62533224, -0.335893631, 6.36658764, -0.961542308, 0.306204319, 5.96919584, 1.05004025, 0.319868058, 6.12821484, 1.01315844, 0.335893631, 6.36658764, 0.961542308, 0.299883217, 6.09487534, 1.08596206, 0.357219428, 6.62822771, 0.883846343, 0.195894644, 5.61448097, 1.38762712, 0.155970037, 5.48235846, 1.48755264, 0.233392969, 5.78930521, 1.29498291, 0.0882868022, 5.26247549, 1.66082299, 0.132228702, 5.3714323, 1.58939183, 0.263942152, 6.02428675, 1.20824122, 0.288278252, 6.32315159, 1.13513815, 0.037062306, 5.11917448, 1.7663964, 0.000642645173, 4.99233627, 1.86228371, -0.0211372972, 4.89682102, 1.9381752, -0.055291675, 4.91052818, 1.93853223, -0.0820840374, 5.04778862, 1.8659091, -0.0333057195, 4.84451103, 1.98705602, -0.109694481, 5.26890564, 1.78174603, -0.134131908, 5.59361362, 1.69768822, 0.379765004, 6.8553791, 0.793307424, 0.443256766, 6.30368519, -0.463627696, 0.446347833, 6.4520278, -0.359647483, 0.437107563, 6.20831585, -0.527223408, 0.447775304, 6.62837696, -0.194927484, 0.433529437, 6.29105663, -0.573231816, 0.44691515, 6.80461073, -2.25071708e-05, 0.331143022, 5.97517681, -0.890933752, 0.284012824, 5.88615227, -0.995684922, 0.371210814, 6.09141397, -0.793445706, 0.181410655, 5.74001026, -1.17642462, 0.257047713, 5.81331062, -1.10132825, 0.400363564, 6.24441338, -0.702014863, 0.423157126, 6.43531513, -0.624940872, 0.442748845, 6.80659962, 0.527064621, -0.306204319, 5.96919584, -1.05004025, -0.319868058, 6.12821484, -1.01315844, -0.299883217, 6.09487534, -1.08596206, 0.0828780904, 5.63486767, -1.29494143, 6.83430699e-08, 5.52084589, -1.41657174, -0.0607482605, 5.40002537, -1.53709853, -0.195893317, 5.61447763, -1.38762927, -0.155962095, 5.48234034, -1.48756576, -0.233392969, 5.78930521, -1.29498291, -0.0881877318, 5.26225138, -1.66098678, -0.132212475, 5.37139559, -1.58941877, -0.263942152, 6.02428675, -1.20824122, -0.288278252, 6.32315159, -1.13513815, 0.313296705, 7.32433367, 0.972555041, 0.284406453, 7.39693022, 1.04842651, 0.347236216, 7.20921898, 0.885690987, 0.154021353, 7.597507, 1.27714825, 0.227212876, 7.5122261, 1.18355775, 0.272495985, 7.42312765, 1.12227738, 0.0717062131, 7.67856789, 1.37121189, -8.9138397e-05, 7.74001026, 1.44700408, -0.0587791502, 7.77257824, 1.49738884, 0.376558542, 7.04641819, 0.793354034, -0.176404133, 7.68248177, 1.45100784, -0.142691046, 7.75699043, 1.4992671, -0.10281264, 7.76332045, 1.53556836, 0.440633446, 6.95619678, 0.527119458, 0.424416274, 7.09744549, -0.373639077, 0.438757658, 7.04542208, -0.196796864, 0.407281756, 7.1269455, -0.507667124, 0.443831295, 6.9529624, -3.83076112e-05, 0.24925819, 7.26689911, -0.788037598, 0.347295672, 7.20115232, -0.671512067, 0.404255658, 7.13657808, -0.60869509, 0.164285421, 7.14006519, -0.226119533, 0.182915717, 7.13879347, -0.207489237, 0.265819371, 7.51029158, -0.0863700137, 0.226119488, 7.13549185, -0.164285481, 0.164285421, 7.51029158, -0.226119533, 0.226119488, 7.51029158, -0.164285481, -0.347236216, 7.20921898, -0.885690987, -0.313296705, 7.32433367, -0.972555041, -0.284406453, 7.39693022, -1.04842651, -0.376558542, 7.04641819, -0.793354034, 0.125984326, 7.34358931, -0.919766366, 1.90713035e-05, 7.42648506, -1.04322731, -0.100437641, 7.51294899, -1.1639539, -0.154021338, 7.59750748, -1.27714837, -0.227212861, 7.51222658, -1.18355787, -0.272495985, 7.42312813, -1.12227738, -0.174300417, 7.59586811, 1.50192142, -0.169981226, 7.36540604, 1.53985846, -0.164309457, 6.95919514, 1.5772475, -0.356113642, 6.87398767, -0.88403821, -0.154325411, 6.4542861, 1.62641227, -0.336973041, 6.62821579, -0.96122092, -0.136949673, 5.92489004, 1.69957638, -0.322683156, 6.3563509, -1.0125221, 0.310299516, 6.11326361, 1.04994082, 0.322683156, 6.3563509, 1.0125221, 0.336973071, 6.62821579, 0.96122098, 0.302403659, 6.33809233, 1.08646119, 0.356113642, 6.87398767, 0.88403821, 0.208517715, 5.72418499, 1.38254106, 0.176638067, 5.55051804, 1.46544015, 0.151602283, 5.44045544, 1.53897703, 0.238972232, 5.97354603, 1.29487979, 0.0683183298, 5.12308788, 1.76869166, 0.11042776, 5.25845146, 1.67459226, 0.140092447, 5.39214706, 1.61228883, 0.267041177, 6.30002451, 1.20875967, 0.28922382, 6.62846136, 1.13534176, 0.0285185073, 4.99350357, 1.86289096, 0.00070787681, 4.89463997, 1.93847227, -0.0172492098, 4.83969688, 1.98765767, -0.0656933337, 4.94938707, 1.9395808, -0.0456514843, 4.85203505, 1.98641872, -0.089870885, 5.14778948, 1.86829364, -0.0293797553, 4.84592104, 2.01536703, -0.11453151, 5.46486425, 1.78430808, 0.445638776, 6.45190096, -0.462998539, 0.440633446, 6.30049419, -0.527119458, 0.447271824, 6.62839937, -0.359359771, 0.44677332, 6.80466747, -0.195152655, 0.435781032, 6.44498682, -0.573748231, 0.313261539, 5.93217945, -0.972767949, 0.347236216, 6.047472, -0.885690987, 0.284233212, 5.85900593, -1.04935467, 0.376558542, 6.21027279, -0.793354034, 0.152653962, 5.64098692, -1.29502034, 0.226171315, 5.73974991, -1.18931413, 0.272065639, 5.83197594, -1.12433982, 0.403299004, 6.41980267, -0.702534437, 0.424020022, 6.62839079, -0.625214219, -0.310299516, 6.11326361, -1.04994082, -0.302403688, 6.33809233, -1.08646119, 0.0710232779, 5.52384567, -1.41670108, 6.11908035e-08, 5.39634132, -1.53683519, -0.0484723262, 5.25958157, -1.65596998, -0.208517715, 5.72418499, -1.38254106, -0.176636085, 5.55051327, -1.46544337, -0.151596978, 5.44044352, -1.53898585, -0.238972232, 5.97354603, -1.29487979, -0.0681531355, 5.12271261, -1.76895523, -0.110389329, 5.25836468, -1.6746558, -0.140088379, 5.392138, -1.61229551, -0.267041177, 6.30002451, -1.20875967, -0.28922379, 6.62846136, -1.13534188, 0.327310175, 7.24609804, 0.963914692, 0.304687709, 7.34943342, 1.0233345, 0.290474147, 7.38294411, 1.07486367, 0.352786303, 7.08067703, 0.884651542, 0.132959202, 7.67432117, 1.37216854, 0.197679698, 7.59313011, 1.28216159, 0.248393595, 7.48589611, 1.19813228, 0.281099916, 7.34575224, 1.13171983, 0.0636710972, 7.73829126, 1.44721365, -8.1035716e-05, 7.77448273, 1.497123, -0.0553583764, 7.77013493, 1.53492284, -0.163202837, 7.71085548, 1.5006249, -0.13459222, 7.75194597, 1.53662348, -0.0971057191, 7.71269083, 1.57380068, 0.438956082, 7.04517269, -0.36216414, 0.42890352, 7.09695435, -0.476123691, 0.443767488, 6.95300102, -0.195777908, 0.421899676, 7.11000204, -0.55572027, 0.231541172, 7.33540201, -0.91606617, 0.318164319, 7.25831223, -0.790665567, 0.38048315, 7.17913008, -0.693260372, 0.416241884, 7.08408976, -0.622840762, -0.352786303, 7.08067703, -0.884651542, -0.327310175, 7.24609804, -0.963914692, -0.304687709, 7.34943342, -1.0233345, -0.290474147, 7.38294411, -1.07486367, 0.116455011, 7.42408943, -1.04377484, 3.97457625e-05, 7.51497078, -1.16343486, -0.083654426, 7.60090733, -1.27491939, -0.132959202, 7.67432165, -1.37216854, -0.197679684, 7.59313011, -1.28216183, -0.248393595, 7.48589659, -1.19813228, -0.281099916, 7.34575224, -1.13171983, -0.164766684, 7.58549356, 1.53900731, -0.161199227, 7.31229305, 1.57711267, -0.153176561, 6.86481619, 1.62701607, -0.335903198, 6.88985157, -0.96150583, -0.137769997, 6.32079172, 1.70092726, -0.323624909, 6.62822723, -1.01229727, -0.117349282, 5.78369045, 1.78621399, -0.312758297, 6.34808064, -1.04987407, 0.312758267, 6.34808064, 1.04987407, 0.323624879, 6.62822723, 1.01229727, 0.335903198, 6.88985157, 0.96150583, 0.303250045, 6.62834406, 1.08659887, 0.187970579, 5.66906881, 1.45687211, 0.214264363, 5.92228556, 1.38152015, 0.166677192, 5.51232624, 1.51391125, 0.153916508, 5.45814562, 1.56449294, 0.24230817, 6.27222395, 1.29485953, 0.0529922247, 4.99808931, 1.86392248, 0.0889889374, 5.12791729, 1.77355981, 0.121905051, 5.2877655, 1.68882775, 0.14636676, 5.49400234, 1.62158072, 0.268097013, 6.62862492, 1.20882142, 0.288331389, 6.93364, 1.1348896, 0.0225109458, 4.89577341, 1.93893945, 0.000645406079, 4.83772469, 1.9881264, -0.0152063211, 4.84176111, 2.01661038, -0.072322011, 5.04623032, 1.94158816, -0.0543647781, 4.8892436, 1.98661113, -0.0404602811, 4.85246658, 2.01357675, -0.0944345891, 5.3367095, 1.87065363, -0.0282536652, 4.92558861, 2.02901626, 0.442748845, 6.45009136, -0.527064621, 0.44643271, 6.62840271, -0.462801337, 0.446347833, 6.80476713, -0.359687001, 0.436531246, 6.62838888, -0.573927343, 0.327310175, 6.01059294, -0.963914692, 0.304644406, 5.90706873, -1.02356648, 0.352786303, 6.17601395, -0.884651542, 0.29030636, 5.87313557, -1.07566071, 0.379765004, 6.40131187, -0.793307424, 0.19622542, 5.65074062, -1.29507506, 0.131736919, 5.53555775, -1.41274858, 0.247511044, 5.76750231, -1.20239663, 0.280808836, 5.91007566, -1.1330471, 0.404275864, 6.62841082, -0.702715218, 0.42315498, 6.82146406, -0.624956846, -0.303250015, 6.62834406, -1.08659887, 0.0607485175, 5.40002775, -1.53709745, 4.00759745e-08, 5.25660801, -1.65562439, -0.0367304198, 5.11841965, -1.76692557, -0.187970579, 5.66906929, -1.45687211, -0.214264363, 5.92228556, -1.38152027, -0.166675866, 5.51232338, -1.51391339, -0.153915182, 5.45814276, -1.56449509, -0.24230817, 6.27222395, -1.29485953, -0.0527618378, 4.99756145, -1.86426473, -0.0889231563, 5.12776756, -1.77366471, -0.12189544, 5.28774405, -1.68884361, -0.14636676, 5.49400234, -1.62158072, -0.268097013, 6.62862492, -1.20882142, -0.288331419, 6.93364048, -1.1348896, 0.332682669, 7.1097331, 0.962401867, 0.315197587, 7.26895905, 1.01413727, 0.301136047, 7.34468889, 1.04945374, 0.295807272, 7.31045818, 1.08456635, 0.173133478, 7.66726589, 1.37378943, 0.11825601, 7.73327065, 1.44793379, 0.221954599, 7.55825949, 1.28757071, 0.259346724, 7.40033817, 1.20476532, 0.285617799, 7.18922472, 1.13370693, 0.0586272925, 7.77243567, 1.49730432, -6.28032212e-05, 7.77237415, 1.53468573, -0.0522531196, 7.72014999, 1.5732882, -0.154106975, 7.70350504, 1.53784931, -0.127243415, 7.70024729, 1.57464099, -0.0895721465, 7.60418129, 1.62608337, 0.439286739, 7.044734, -0.464755625, 0.443575919, 6.95305204, -0.360623807, 0.430588663, 7.08769798, -0.521291852, 0.429774731, 7.06068754, -0.572417438, 0.296260297, 7.31912899, -0.903698802, 0.225884482, 7.41538906, -1.04568243, 0.354731649, 7.23000145, -0.792840838, 0.395461231, 7.12131977, -0.701194584, 0.420562148, 6.98365641, -0.624166429, -0.332682669, 7.1097331, -0.962401867, -0.315197587, 7.26895905, -1.01413727, -0.301136047, 7.34468889, -1.04945362, -0.295807272, 7.31045818, -1.08456635, 0.100510508, 7.51302147, -1.16399562, 6.26124965e-05, 7.60239124, -1.2745173, -0.0717062056, 7.67856884, -1.37121224, -0.173133478, 7.66726637, -1.37378967, -0.11825601, 7.7332716, -1.44793403, -0.221954569, 7.55825996, -1.28757071, -0.259346753, 7.40033865, -1.20476532, -0.285617799, 7.1892252, -1.13370705, -0.156106949, 7.53212023, 1.57649887, -0.150083318, 7.21080923, 1.62722635, -0.136592746, 6.71758652, 1.70192695, -0.322692037, 6.90010977, -1.01248837, -0.118304692, 6.1628499, 1.78703046, -0.313581645, 6.62826824, -1.0498364, -0.0970725417, 5.64330053, 1.87246788, 0.313581616, 6.62826824, 1.04983628, 0.322692007, 6.90010977, 1.01248837, 0.302428544, 6.91854572, 1.0863477, 0.175582141, 5.6338501, 1.50475788, 0.19351469, 5.87783957, 1.45541382, 0.217695028, 6.24326372, 1.38097167, 0.162813172, 5.51762104, 1.53927541, 0.158097699, 5.5605917, 1.57394946, 0.243448347, 6.62794304, 1.29469085, 0.070701696, 5.00623274, 1.86527681, 0.0418563336, 4.90037441, 1.93946683, 0.101935402, 5.16562271, 1.77881742, 0.129524454, 5.39021111, 1.69541645, 0.150909185, 5.70294428, 1.62376213, 0.267143816, 6.95696163, 1.20827627, 0.0185055118, 4.838727, 1.98836493, 0.000502004696, 4.84008598, 2.01723552, -0.0146059608, 4.92170238, 2.0309937, -0.0762245208, 5.22897053, 1.94382489, -0.0595238917, 4.98311138, 1.98849988, -0.0479834527, 4.88813686, 2.00653005, -0.0393222012, 4.93181562, 2.02590203, -0.0284292735, 5.10120678, 2.03431559, 0.443453908, 6.62839603, -0.5270558, 0.445638776, 6.80490112, -0.463031441, 0.435780168, 6.81178904, -0.573766887, 0.332682669, 6.14695787, -0.962401867, 0.315197587, 5.98773193, -1.01413727, 0.301061511, 5.91173029, -1.04980803, 0.356113642, 6.3827033, -0.88403821, 0.295690864, 5.94588757, -1.08509731, 0.380831361, 6.62843847, -0.79330194, 0.17183128, 5.55869865, -1.40037382, 0.220750898, 5.69119453, -1.29507732, 0.11828284, 5.41346264, -1.53795636, 0.258764595, 5.85462618, -1.20741987, 0.285476804, 6.06730127, -1.13435483, 0.403294742, 6.83701468, -0.702553868, -0.302428544, 6.91854572, -1.0863477, 0.048472479, 5.259583, -1.65596926, 1.82675722e-05, 5.11645603, -1.76658082, -0.0280577261, 4.99244785, -1.86357558, -0.175582141, 5.6338501, -1.50475788, -0.19351469, 5.87783957, -1.45541382, -0.217695028, 6.2432642, -1.38097167, -0.162812591, 5.51761961, -1.53927648, -0.158097714, 5.5605917, -1.57394958, -0.243448362, 6.62794304, -1.29469073, -0.0706095472, 5.0060215, -1.86541367, -0.0415702723, 4.89971161, -1.9398433, -0.101918958, 5.16558552, -1.77884376, -0.129524454, 5.39021111, -1.69541645, -0.1509092, 5.70294476, -1.62376201, -0.267143816, 6.95696163, -1.20827627, 0.319883317, 7.1282649, 1.01310015, 0.306247085, 7.28725958, 1.04985535, 0.299945563, 7.16161203, 1.08567941, 0.196966678, 7.62722778, 1.37573528, 0.154478997, 7.72492886, 1.44916391, 0.108982429, 7.76641941, 1.49793279, 0.234171137, 7.46337795, 1.29098642, 0.264215678, 7.23190832, 1.20697439, 0.0552406907, 7.7700243, 1.53485727, -4.05141618e-05, 7.7226162, 1.57310331, -0.0481406599, 7.61165762, 1.62586439, -0.145849407, 7.65074778, 1.57560778, -0.117628343, 7.59171486, 1.6264416, -0.0778012723, 7.42712021, 1.70570052, 0.437107146, 7.04845524, -0.52727282, 0.443256766, 6.95310783, -0.46368432, 0.433527976, 6.96571302, -0.57326442, 0.331150413, 7.28153563, -0.890861154, 0.284150362, 7.36993647, -0.994881928, 0.182427585, 7.51093006, -1.16946995, 0.257534236, 7.44143391, -1.09880614, 0.371198803, 7.16540956, -0.793493092, 0.400356293, 7.01239157, -0.702047944, -0.319883317, 7.1282649, -1.01310015, -0.306247085, 7.28725958, -1.04985535, -0.299945563, 7.16161203, -1.08567941, 0.0837713629, 7.60101843, -1.2749846, 8.10358761e-05, 7.68002605, -1.37092137, -0.0636710972, 7.73829174, -1.44721377, -0.196966678, 7.62722826, -1.3757354, -0.154478982, 7.72492981, -1.44916403, -0.108982429, 7.76642036, -1.49793291, -0.234171137, 7.46337843, -1.29098642, -0.264215708, 7.23190832, -1.20697439, -0.145030111, 7.4263854, 1.6271255, -0.133417845, 7.05154228, 1.70276117, -0.11755465, 6.5398078, 1.78632295, -0.312770367, 6.90844631, -1.04982316, -0.0984066576, 6.00363398, 1.87125874, -0.0784476548, 5.52552032, 1.94556034, 0.312770396, 6.90844631, 1.04982316, 0.167056456, 5.60290003, 1.53938723, 0.1804194, 5.84754229, 1.50381219, 0.196817473, 6.21665764, 1.4546299, 0.218856618, 6.62552404, 1.38060355, 0.162340373, 5.77341318, 1.5752244, 0.242440447, 6.98330593, 1.29414308, 0.056328468, 4.90859222, 1.93994462, 0.0827646628, 5.04634047, 1.86696541, 0.0344584771, 4.84283829, 1.98827696, 0.110019051, 5.26816702, 1.78228164, 0.134237453, 5.59334946, 1.69785237, 0.153577358, 6.04491806, 1.62532771, 0.0161872022, 4.8409934, 2.01717043, 0.000324430963, 4.92021942, 2.03179026, -0.0146771679, 5.09760809, 2.03692341, -0.062284641, 5.16146994, 1.99092174, -0.0492620952, 4.94833803, 2.01471043, -0.0399999246, 5.10707903, 2.03006029, -0.0284084044, 5.3904686, 2.0375762, 0.442748636, 6.80669832, -0.527089894, 0.319883317, 6.12842607, -1.01310015, 0.335903198, 6.36683941, -0.96150583, 0.306217968, 5.96934509, -1.04998815, 0.357219428, 6.62846327, -0.883846343, 0.299889147, 6.09501314, -1.08593857, 0.379758388, 6.85555887, -0.79333353, 0.195893735, 5.61453199, -1.38762784, 0.155964077, 5.48236084, -1.48755884, 0.233388737, 5.78941584, -1.29499769, 0.0881879926, 5.26225376, -1.66098583, 0.132213399, 5.37140512, -1.58941555, 0.263933599, 6.02445316, -1.20827043, 0.288269341, 6.32334375, -1.13516843, 0.0367661901, 5.11838913, -1.76692545, 7.30314059e-05, 4.99069643, -1.86334574, -0.021938825, 4.89444828, -1.93969238, -0.167056456, 5.60290003, -1.53938723, -0.1804194, 5.84754229, -1.50381219, -0.196817473, 6.21665764, -1.4546299, -0.218856618, 6.62552404, -1.38060355, -0.162340373, 5.77341318, -1.5752244, -0.242440447, 6.98330593, -1.29414308, -0.0562140457, 4.9083271, -1.94009519, -0.0827416182, 5.04628754, -1.86699975, -0.0341348536, 4.84207582, -1.98861909, -0.110019051, 5.26816702, -1.78228164, -0.134237453, 5.59334946, -1.69785237, -0.153577358, 6.04491854, -1.62532771, 0.310325265, 7.14323664, 1.04983115, 0.209196433, 7.52403212, 1.37766635, 0.176391736, 7.68156052, 1.45063758, 0.142620966, 7.75641489, 1.49900711, 0.102718733, 7.76307106, 1.53543627, 0.239332169, 7.28091669, 1.2929852, 0.0521771871, 7.72007847, 1.57324588, -2.02571537e-05, 7.61413956, 1.6257844, -0.0416983068, 7.43369055, 1.70603061, -0.135163039, 7.54290199, 1.62682641, -0.102730788, 7.41616774, 1.7051475, -0.0640050694, 7.18740559, 1.79826725, 0.440633059, 6.95628834, -0.527163327, 0.313283414, 7.32448053, -0.972614944, 0.34722051, 7.20938873, -0.88575083, 0.284401506, 7.39706802, -1.04848611, 0.154114053, 7.59775829, -1.27728057, 0.22724396, 7.51252317, -1.18369091, 0.272493392, 7.42337704, -1.12237763, 0.376547217, 7.04658031, -0.793398738, -0.310325265, 7.14323664, -1.04983115, 0.0718580484, 7.67871141, -1.37129664, 8.91421223e-05, 7.74001074, -1.44700432, -0.0586272925, 7.77243662, -1.49730432, -0.209196419, 7.52403259, -1.37766635, -0.176391736, 7.68156147, -1.4506377, -0.142620966, 7.75641584, -1.49900734, -0.102718711, 7.76307154, -1.53543627, -0.239332169, 7.28091717, -1.29298532, -0.12824516, 7.25892591, 1.70361686, -0.114653997, 6.85336113, 1.78643, -0.0990588889, 6.35377979, 1.86454809, -0.0801491663, 5.87332535, 1.94200945, -0.0638028458, 5.45214939, 1.99271357, 0.171265617, 5.81739855, 1.53949034, 0.183291346, 6.19591904, 1.50336802, 0.197900489, 6.62047625, 1.4542129, 0.217796043, 7.00746918, 1.38012445, 0.164839149, 6.12223148, 1.57619464, 0.0664671287, 4.94773769, 1.94078422, 0.0466316715, 4.85019016, 1.98776472, 0.0902988538, 5.14682007, 1.86900091, 0.0302912649, 4.84458351, 2.01634312, 0.114694223, 5.46448946, 1.78457451, 0.136995539, 5.9247427, 1.69962943, 0.154347941, 6.45407391, 1.62635732, 0.0152410129, 4.92120218, 2.0313592, 0.000162212949, 5.09631491, 2.03786111, -0.0146489833, 5.38756657, 2.04051328, -0.0508110635, 5.12418175, 2.01773643, -0.0402561575, 5.39525461, 2.03271747, -0.0293928236, 5.75372314, 2.03175616, 0.322692007, 6.35658121, -1.01248837, 0.310311168, 6.11343765, -1.04989588, 0.336973071, 6.62847519, -0.96122098, 0.356105059, 6.8742156, -0.884071171, 0.302403748, 6.33826208, -1.0864594, 0.20851171, 5.72432184, -1.38256216, 0.176636651, 5.5505743, -1.46544158, 0.151599005, 5.44046402, -1.5389787, 0.238956958, 5.97377586, -1.29493284, 0.0681866035, 5.12265873, -1.76895475, 0.110389657, 5.25836802, -1.6746546, 0.140088752, 5.39215422, -1.61229444, 0.267019719, 6.3003149, -1.20883405, 0.289206415, 6.62872124, -1.1354053, 0.0282006841, 4.99232292, -1.8635757, 0.000182578282, 4.89257717, -1.93964219, -0.0178582687, 4.83720303, -1.98904943, -0.171265617, 5.81739855, -1.53949034, -0.183291376, 6.19591904, -1.50336802, -0.197900474, 6.62047625, -1.45421302, -0.217796043, 7.00746965, -1.38012445, -0.164839163, 6.12223196, -1.57619464, -0.0664385259, 4.94767094, -1.94082189, -0.0465022214, 4.84988499, -1.98790157, -0.0902988538, 5.14682055, -1.86900091, -0.02995014, 4.84376574, -2.01660824, -0.114694223, 5.46448994, -1.78457451, -0.136995554, 5.9247427, -1.69962943, -0.154347956, 6.45407438, -1.6263572, 0.21456033, 7.32750416, 1.37924266, 0.188045904, 7.5714612, 1.45208812, 0.163191572, 7.71001863, 1.50028789, 0.134537905, 7.75150013, 1.53642201, 0.0970451236, 7.71252966, 1.57371521, 0.0481026955, 7.61162186, 1.62584317, -8.10393249e-06, 7.43587637, 1.70613778, -0.03414068, 7.19243813, 1.79928768, -0.118780777, 7.37028551, 1.70443249, -0.0853212401, 7.17901707, 1.79656541, -0.0503955372, 6.89093542, 1.88939822, 0.327292442, 7.2462883, -0.963982165, 0.304674238, 7.34958363, -1.02339602, 0.35277158, 7.0808835, -0.884707689, 0.290465444, 7.38311243, -1.07493198, 0.133080393, 7.67464447, -1.37233925, 0.197733015, 7.59357882, -1.28236389, 0.248396859, 7.48633003, -1.19830656, 0.281084716, 7.34606075, -1.13183379, 0.0638381392, 7.7384491, -1.44730675, 8.10394413e-05, 7.77448368, -1.49712312, -0.0552406833, 7.77002525, -1.53485739, -0.21456033, 7.32750463, -1.37924266, -0.188045889, 7.57146168, -1.45208812, -0.163191572, 7.71001911, -1.50028813, -0.134537905, 7.75150061, -1.53642213, -0.0970451161, 7.71253061, -1.57371521, -0.10915757, 7.04230785, 1.78968847, -0.0972430035, 6.6351347, 1.86094463, -0.082486771, 6.20983076, 1.92838871, -0.0656055138, 5.80210447, 1.98768187, -0.0515887886, 5.41234255, 2.01980615, 0.173753068, 6.16859484, 1.53971398, 0.184158802, 6.61190796, 1.50317168, 0.196785197, 7.02424765, 1.4538554, 0.165530637, 6.53975296, 1.57682431, 0.0728121102, 5.04512024, 1.94239831, 0.0551171787, 4.88763285, 1.98778594, 0.041256167, 4.85095501, 2.01468015, 0.0946485773, 5.33622456, 1.87100732, 0.0288472995, 4.92471313, 2.02965498, 0.117415287, 5.78353024, 1.78631759, 0.137787297, 6.32068825, 1.70091891, 0.153197616, 6.8645606, 1.62693083, 0.014994693, 5.09735823, 2.0371058, 6.4885855e-05, 5.38656187, 2.04152012, -0.0151784141, 5.75188637, 2.03474689, -0.0416460857, 5.75677204, 2.02678132, -0.0325843059, 6.15131998, 2.0098145, 0.312764198, 6.34827375, -1.04985118, 0.323624879, 6.62846375, -1.01229727, 0.335893631, 6.89010334, -0.961542308, 0.303243071, 6.62854338, -1.08662438, 0.214244157, 5.92257547, -1.3815906, 0.187964052, 5.66922092, -1.45689499, 0.166676581, 5.5123806, -1.51391077, 0.153915957, 5.45817566, -1.56449246, 0.242273688, 6.27264404, -1.29497945, 0.0528954677, 4.99734306, -1.86426473, 0.0889527649, 5.12770557, -1.77366424, 0.121895567, 5.28775024, -1.68884313, 0.146365374, 5.49403811, -1.62158537, 0.268062264, 6.62904978, -1.20894837, 0.288308054, 6.93395424, -1.13498354, 0.0222962108, 4.89413595, -1.93969238, 0.000365157146, 4.83534431, -1.98919296, -0.0155049535, 4.83935833, -2.01770115, -0.173753068, 6.16859484, -1.53971398, -0.184158802, 6.61190796, -1.5031718, -0.196785197, 7.02424812, -1.45385551, -0.165530637, 6.53975344, -1.57682431, -0.0728121102, 5.04512024, -1.94239831, -0.0550848171, 4.88755655, -1.98782027, -0.0411197171, 4.8506279, -2.01478624, -0.0946485773, 5.33622456, -1.87100732, -0.0285106804, 4.9238925, -2.02982616, -0.117415287, 5.78353024, -1.78631759, -0.137787297, 6.32068872, -1.70091891, -0.153197616, 6.86456108, -1.62693083, 0.193493158, 7.36292505, 1.45324957, 0.174342945, 7.59482622, 1.50153518, 0.154098243, 7.70285606, 1.53758824, 0.127208352, 7.69995975, 1.57451105, 0.0895418376, 7.6041007, 1.6260407, 0.0416831151, 7.43367624, 1.70602214, -2.02603223e-06, 7.19411469, 1.79962707, -0.0266824048, 6.89409161, 1.89113569, -0.0998013616, 7.13980675, 1.79382503, -0.0681701154, 6.88567495, 1.88650262, -0.039184615, 6.54360771, 1.96470904, 0.315180749, 7.26913834, -1.01420152, 0.332666337, 7.10996151, -0.962464333, 0.3011235, 7.34484911, -1.04951715, 0.295793921, 7.31065845, -1.08463979, 0.173203558, 7.66784191, -1.37404954, 0.118389308, 7.73362637, -1.44812167, 0.221962705, 7.55891228, -1.28783321, 0.259323657, 7.40087891, -1.20496547, 0.285594165, 7.18956089, -1.13382041, 0.0587791502, 7.77257967, -1.49738884, 6.27994959e-05, 7.77237511, -1.53468609, -0.0521771871, 7.72007942, -1.57324588, -0.193493158, 7.36292553, -1.45324957, -0.174342945, 7.5948267, -1.50153518, -0.154098243, 7.70285702, -1.53758836, -0.127208337, 7.69996071, -1.57451129, -0.0895418376, 7.60410166, -1.6260407, -0.0911727995, 6.78909683, 1.86905718, -0.0852598995, 6.45125151, 1.90921497, -0.0692196041, 6.15828943, 1.96963215, -0.0532722846, 5.76993275, 2.01402259, 0.174434513, 6.58870506, 1.53990257, 0.182982653, 7.02843666, 1.50297034, 0.164351523, 6.95868397, 1.57707715, 0.0764695629, 5.22841549, 1.94422984, 0.0600070842, 4.98201656, 1.98929834, 0.0486608408, 4.88673162, 2.00755525, 0.0398468077, 4.93081474, 2.02663231, 0.097158134, 5.64310694, 1.87260938, 0.0287260916, 5.10076904, 2.03463507, 0.118322663, 6.16279316, 1.78705096, 0.136601165, 6.71748447, 1.70189261, 0.150102973, 7.2105279, 1.62712824, 0.0147759952, 5.38746643, 2.04058647, 1.62229662e-05, 5.75126457, 2.03575087, -0.0169224627, 6.15087461, 2.01260638, -0.0457249172, 6.15206146, 2.00516105, 0.313579887, 6.62847233, -1.0498426, 0.322683156, 6.90034008, -1.0125221, 0.30241555, 6.91876459, -1.08639932, 0.193492502, 5.87815905, -1.45549119, 0.21765025, 6.24379873, -1.3811276, 0.175576344, 5.63398933, -1.50477803, 0.162812069, 5.51768303, -1.53927839, 0.158094957, 5.56066322, -1.57395911, 0.243394509, 6.62857056, -1.29488754, 0.0707276389, 5.00577164, -1.86541367, 0.0419043526, 4.89916468, -1.9398433, 0.101945616, 5.16552353, -1.77884352, 0.129523903, 5.39022541, -1.69541848, 0.150904208, 5.70301771, -1.62377942, 0.267100841, 6.95749617, -1.2084502, 0.0185730439, 4.83657789, -1.98904943, 0.00056502287, 4.83752823, -2.01806498, -0.0145677729, 4.91956091, -2.03170156, -0.174434543, 6.58870506, -1.53990245, -0.182982638, 7.02843714, -1.50297046, -0.164351523, 6.95868444, -1.57707715, -0.0764695629, 5.22841549, -1.94422984, -0.0600070879, 4.98201656, -1.98929834, -0.0486001968, 4.88658619, -2.00760245, -0.0397121608, 4.93048668, -2.02670097, -0.097158134, 5.64310741, -1.87260938, -0.0284179356, 5.10000706, -2.03472042, -0.118322648, 6.16279364, -1.78705096, -0.136601165, 6.71748495, -1.70189285, -0.150102958, 7.21052837, -1.62712812, 0.179723725, 7.37843323, 1.50250936, 0.16479966, 7.5846858, 1.53870797, 0.145843774, 7.65032911, 1.57543921, 0.117610797, 7.59157085, 1.62637663, 0.0777891502, 7.42708778, 1.70568359, 0.0341368802, 7.19243479, 1.79928517, 7.27595761e-12, 6.89514399, 1.89171505, -0.0205381233, 6.54484034, 1.96707523, -0.0813234448, 6.85837412, 1.88040352, -0.0540478602, 6.54155254, 1.96076524, 0.306232214, 7.28743172, -1.0499177, 0.319868058, 7.12847614, -1.01315844, 0.299929738, 7.16183329, -1.08574927, 0.196977943, 7.62806511, -1.37607217, 0.154556096, 7.72556305, -1.4494499, 0.10910362, 7.76674271, -1.4981035, 0.234137714, 7.46419096, -1.29128766, 0.264174789, 7.23249292, -1.2071768, 0.0553583764, 7.77013588, -1.53492296, 4.05216124e-05, 7.72261667, -1.57310343, -0.0481026955, 7.61162281, -1.62584317, -0.179723725, 7.37843418, -1.50250936, -0.16479966, 7.58468676, -1.53870797, -0.145843759, 7.65033007, -1.57543921, -0.117610797, 7.59157181, -1.62637663, -0.0777891502, 7.42708874, -1.70568371, -0.0769678131, 6.49564123, 1.93220913, -0.0575385913, 6.1540637, 1.99348664, 0.173225656, 7.00994587, 1.53990054, 0.161238521, 7.31173038, 1.57691634, 0.0785456598, 5.5252986, 1.94572222, 0.0625262335, 5.16092253, 1.99132133, 0.0497349314, 4.94731426, 2.01545763, 0.0402622335, 5.10657883, 2.03042531, 0.0984280631, 6.00358582, 1.87129414, 0.0285271313, 5.39029312, 2.03770375, 0.117556743, 6.53978205, 1.78631449, 0.133425713, 7.05142975, 1.70272171, 0.145040736, 7.42612505, 1.62702906, 0.0152101666, 5.7518611, 2.03476501, 4.36557457e-11, 6.15072632, 2.01353717, 0.312761277, 6.90865183, -1.04985857, 0.196768254, 6.21724606, -1.45480144, 0.180399314, 5.84783363, -1.50388217, 0.218787104, 6.62632608, -1.38085747, 0.167052135, 5.60301018, -1.53940237, 0.162330419, 5.77355957, -1.57525921, 0.242374972, 6.98410416, -1.2944082, 0.0565092787, 4.90770197, -1.94009519, 0.0828480497, 5.04603195, -1.86699975, 0.034803018, 4.84098196, -1.98861897, 0.110046104, 5.26810217, -1.78228211, 0.134235442, 5.59337902, -1.69785917, 0.153566197, 6.04505253, -1.62536645, 0.0166089684, 4.83839893, -2.01770115, 0.000726428814, 4.91765785, -2.03232622, -0.0143783782, 5.09583426, -2.03727698, -0.173225656, 7.00994635, -1.53990054, -0.161238521, 7.31173134, -1.57691634, -0.0785456598, 5.5252986, -1.94572222, -0.0625262335, 5.160923, -1.99132133, -0.0497012697, 4.94723177, -2.0154748, -0.0401389711, 5.10627413, -2.03045964, -0.0984280631, 6.00358582, -1.87129414, -0.0282733459, 5.38966084, -2.03773785, -0.117556743, 6.53978252, -1.78631449, -0.133425713, 7.05143023, -1.70272171, -0.145040736, 7.426126, -1.62702906, 0.170042127, 7.3645339, 1.539554, 0.156128198, 7.53159952, 1.57630551, 0.135160223, 7.54269266, 1.62674236, 0.102723777, 7.41611004, 1.70512152, 0.0640020519, 7.18739748, 1.79826307, 0.0266824029, 6.89409161, 1.89113569, -1.07684173e-09, 6.54525137, 1.96786404, -0.0662636533, 6.52884197, 1.95125997, 0.310311139, 7.14343166, -1.04988742, 0.209153906, 7.52507448, -1.37805271, 0.176404133, 7.68248224, -1.45100784, 0.142691046, 7.75699139, -1.4992671, 0.10281264, 7.76332188, -1.53556836, 0.239270881, 7.28179455, -1.29329097, 0.0522531159, 7.72015095, -1.5732882, 2.0260879e-05, 7.61414051, -1.6257844, -0.0416831151, 7.4336772, -1.70602214, -0.170042127, 7.36453438, -1.539554, -0.156128198, 7.5316, -1.57630575, -0.135160223, 7.54269361, -1.62674236, -0.102723777, 7.41611099, -1.70512152, -0.0639962256, 7.18738413, -1.79826307, 0.0801736712, 5.87327003, 1.9420501, 0.0638994798, 5.45193052, 1.99287343, 0.0510474816, 5.12366915, 2.01811004, 0.0403610803, 5.39505434, 2.03286338, 0.0990588814, 6.35377979, 1.86454821, 0.0294225067, 5.75367928, 2.03178811, 0.114655957, 6.853333, 1.78641987, 0.128249422, 7.25882149, 1.70357823, 0.0169224609, 6.15087461, 2.01260662, 0.197824061, 6.62135887, -1.45449209, 0.183246642, 6.19645452, -1.50352371, 0.171250135, 5.81762505, -1.53954434, 0.217711896, 7.00849199, -1.38046527, 0.164816827, 6.12249994, -1.57627249, 0.0667046234, 4.9470315, -1.94082212, 0.0470926873, 4.84863472, -1.98790157, 0.0904076248, 5.14654684, -1.86900091, 0.0309760757, 4.84209442, -2.016608, 0.114721313, 5.46442795, -1.7845763, 0.136991099, 5.92479658, -1.69964492, 0.154330596, 6.45427513, -1.62642062, 0.0159817841, 4.91834974, -2.03170109, 0.000796743843, 5.09394455, -2.03812909, -0.0142684197, 5.3862009, -2.04065466, -0.0801736638, 5.87327051, -1.9420501, -0.0638994798, 5.451931, -1.99287343, -0.0510166772, 5.12359333, -2.01811862, -0.0402595624, 5.39480162, -2.03287697, -0.0990588814, 6.35378027, -1.86454821, -0.0292366911, 5.75321388, -2.03179669, -0.114655957, 6.85333395, -1.78642011, -0.128249422, 7.25882244, -1.70357835, 0.118779637, 7.37020159, 1.70439863, 0.0853194892, 7.17900276, 1.79655874, 0.0503955372, 6.89093542, 1.88939822, 0.0205381233, 6.54484034, 1.96707499, 0.214481756, 7.32862997, -1.37963545, 0.187999129, 7.57260799, -1.4525131, 0.163202837, 7.71085644, -1.5006249, 0.13459222, 7.75194693, -1.53662348, 0.0971057191, 7.71269178, -1.57380068, 0.0481406599, 7.61165857, -1.62586439, 8.10393249e-06, 7.43587732, -1.70613778, -0.0341252275, 7.19240665, -1.79928517, -0.118779637, 7.37020254, -1.70439863, -0.0853171572, 7.17899799, -1.79655874, -0.0503722318, 6.89087772, -1.88939822, 0.082486771, 6.20983076, 1.92838871, 0.0656296685, 5.80204964, 1.98772156, 0.0516833588, 5.41213799, 2.01995587, 0.0416723192, 5.75672245, 2.02681804, 0.0972430035, 6.6351347, 1.86094463, 0.0325843059, 6.1513195, 2.0098145, 0.109158643, 7.04228163, 1.78967881, 0.196692616, 7.02537251, -1.45423019, 0.184089303, 6.61271048, -1.50342548, 0.173718452, 6.16901016, -1.5398345, 0.165495887, 6.54015446, -1.57695115, 0.073084034, 5.04443645, -1.94239819, 0.0556170121, 4.8862772, -1.98782039, 0.0420155227, 4.84873867, -2.01478624, 0.094758898, 5.33594751, -1.87100732, 0.0298081543, 4.92180204, -2.02982616, 0.117438249, 5.78348351, -1.78632128, 0.137780353, 6.32076883, -1.70094442, 0.153176561, 6.86481667, -1.62701619, 0.0159244686, 5.09452534, -2.03727674, 0.000723321922, 5.38459682, -2.04162741, -0.01483854, 5.75092983, -2.03478217, -0.082486771, 6.20983171, -1.9283886, -0.0656296685, 5.80205011, -1.98772168, -0.0516579822, 5.41207457, -2.01995921, -0.0415979922, 5.75653648, -2.02682137, -0.0972430035, 6.63513565, -1.86094463, -0.0324677639, 6.15102768, -2.0098145, -0.109158643, 7.04228258, -1.78967881, 0.0998010784, 7.13978577, 1.79381657, 0.0681701154, 6.88567495, 1.88650262, 0.0391846187, 6.54360771, 1.96470904, 0.193406716, 7.3641634, -1.45368159, 0.174300402, 7.59586906, -1.50192142, 0.154106975, 7.70350599, -1.53784931, 0.127243415, 7.70024824, -1.57464099, 0.0895721465, 7.60418224, -1.62608337, 0.0416983068, 7.4336915, -1.70603061, 2.00896739e-05, 7.19407034, -1.79962707, -0.0266357865, 6.89397526, -1.89113569, -0.0998004973, 7.13978529, -1.79381657, -0.0681607947, 6.88565254, -1.88650262, -0.0391263478, 6.5434618, -1.96470904, 0.0852598995, 6.45125151, 1.90921497, 0.0692196041, 6.15828943, 1.96963215, 0.0532959253, 5.76988173, 2.01406002, 0.0457249172, 6.15206146, 2.00516129, 0.0911727995, 6.78909683, 1.86905718, 0.182898507, 7.02945948, -1.50331092, 0.17438069, 6.58932686, -1.54009914, 0.164309457, 6.95919561, -1.5772475, 0.076745376, 5.22772217, -1.94422984, 0.0605509356, 4.98064947, -1.98929834, 0.0493626259, 4.88483047, -2.00760245, 0.0408154055, 4.92818165, -2.02670074, 0.09725447, 5.64286518, -1.87260938, 0.0298218466, 5.0977664, -2.03472042, 0.118339621, 6.16276646, -1.78705704, 0.136592761, 6.71758747, -1.70192683, 0.150083318, 7.21080971, -1.62722635, 0.0156700015, 5.38502121, -2.04065466, 0.000560166256, 5.74981976, -2.03577757, -0.0166893825, 6.15028954, -2.01260638, -0.0852598995, 6.45125198, -1.90921497, -0.0692196041, 6.15829039, -1.96963215, -0.0532773472, 5.76983547, -2.01406097, -0.0456783026, 6.15194511, -2.00516129, -0.0911727995, 6.78909779, -1.86905718, 0.0813234448, 6.85837412, 1.8804034, 0.0540478602, 6.54155254, 1.96076524, 0.179645151, 7.37955952, -1.50290215, 0.164766684, 7.58549452, -1.53900731, 0.145849407, 7.65074873, -1.57560778, 0.117628343, 7.59171581, -1.6264416, 0.0778012723, 7.42712116, -1.70570052, 0.0341639854, 7.19238091, -1.79928768, 7.22545592e-05, 6.89496326, -1.89171505, -0.0204215832, 6.54454851, -1.96707499, -0.0813211128, 6.85836887, -1.8804034, -0.0540245548, 6.54149485, -1.96076524, 0.0769678131, 6.49564123, 1.93220913, 0.0575385913, 6.1540637, 1.99348664, 0.173160419, 7.01073837, -1.54016447, 0.161199227, 7.31229401, -1.57711267, 0.0787865147, 5.52469301, -1.94572222, 0.0630778521, 5.15953588, -1.99132097, 0.0505481251, 4.94521999, -2.0154748, 0.0413059145, 5.10385561, -2.03045964, 0.0985028967, 6.00339794, -1.87129414, 0.0295397416, 5.38764858, -2.03773785, 0.11756812, 6.53977442, -1.78632295, 0.133417845, 7.05154276, -1.70276117, 0.145030111, 7.42638636, -1.6271255, 0.0159231331, 5.75001955, -2.03478217, 0.00036127257, 6.14981842, -2.01353717, -0.0769678131, 6.49564219, -1.93220913, -0.0575269386, 6.15403509, -1.99348676, 0.0662636608, 6.52884197, 1.95125997, 0.169981226, 7.36540699, -1.53985834, 0.156106949, 7.53212118, -1.57649887, 0.135163039, 7.54290295, -1.62682641, 0.102730788, 7.41616869, -1.7051475, 0.0640307143, 7.18734217, -1.79826725, 0.0267756358, 6.89385843, -1.89113569, 0.000180636518, 6.5447979, -1.96786392, -0.0662578344, 6.52882814, -1.95125997, 0.0803589672, 5.87280464, -1.94204998, 0.0643811747, 5.45071983, -1.99287343, 0.0518876165, 5.12153244, -2.01811862, 0.0413006507, 5.39265299, -2.03287721, 0.0991127566, 6.35364485, -1.86454809, 0.0302140731, 5.75166512, -2.03179693, 0.114664868, 6.85333443, -1.78643, 0.12824516, 7.25892687, -1.70361686, 0.0173886195, 6.14970303, -2.01260638, 0.118780777, 7.37028646, -1.70443249, 0.0853445455, 7.17895937, -1.79656541, 0.0504980907, 6.89067841, -1.88939822, 0.0207712017, 6.54425526, -1.96707523, 0.0826141834, 6.20951128, -1.9283886, 0.0659966394, 5.80112743, -1.98772156, 0.0524240322, 5.41026592, -2.01995921, 0.0423966795, 5.7548914, -2.02682137, 0.0972865149, 6.63502645, -1.86094463, 0.0330970809, 6.15003109, -2.0098145, 0.10917104, 7.04227495, -1.78968847, 0.0998198763, 7.13976097, -1.79382503, 0.0682633519, 6.8854413, -1.88650262, 0.0394410044, 6.5429635, -1.96470904, 0.0853538215, 6.45101595, -1.90921497, 0.0694599375, 6.15768576, -1.96963215, 0.0538608842, 5.76845932, -2.01406097, 0.0461910777, 6.15089035, -2.00516129, 0.0912266672, 6.78896236, -1.86905718, 0.0813975111, 6.85818863, -1.88040352, 0.0542809404, 6.54096746, -1.96076524, 0.0770952329, 6.49532175, -1.93220913, 0.0579016767, 6.15315151, -1.99348676, 0.0664470047, 6.52838182, -1.95125997 \ No newline at end of file diff --git a/deploy_docs.sh b/deploy_docs.sh new file mode 100644 index 0000000..69bb6ea --- /dev/null +++ b/deploy_docs.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Copies documentation to blog +cp -R build/docs/html/. ../box2d_blog/public/documentation3d/ diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4a65521..9014cdd 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -1,7 +1,4 @@ -# 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) +find_package(Doxygen REQUIRED dot) set(DOXYGEN_PROJECT_NAME "Box3D") set(DOXYGEN_GENERATE_HTML YES) @@ -34,25 +31,16 @@ 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 restyles it in the Box2D grays and accent +# Dark theme baked by doxygen, extra.css only adds the Box3D 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" @@ -69,10 +57,4 @@ doxygen_add_docs(doc "reading.md" ALL COMMENT "Generate HTML documentation") - - -# 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) + \ No newline at end of file diff --git a/docs/collision.md b/docs/collision.md index 07dbef1..91ee199 100644 --- a/docs/collision.md +++ b/docs/collision.md @@ -1,7 +1,6 @@ # Collision Box3D provides geometric types and functions. These include: - - primitives: spheres, capsules, and convex hulls - triangle meshes and height fields for static terrain - convex hull construction from point clouds @@ -25,7 +24,6 @@ physics simulation. At a minimum, you should understand how to create primitives that can later be attached to rigid bodies. Box3D shape primitives support several operations: - - Test a point or proxy for overlap with the primitive - Perform a ray cast against the primitive - Compute the primitive's bounding box @@ -383,7 +381,6 @@ this for stable stacking. Normally you do not compute manifolds directly — you use the contact data returned by the simulation. The `b3Manifold` struct contains: - - `normal`: unit normal from shape A toward shape B - `points[B3_MAX_MANIFOLD_POINTS]`: contact points with separation, impulses, and feature ids @@ -404,16 +401,15 @@ b3CollideHulls(&manifold, B3_MAX_MANIFOLD_POINTS, ``` Available collide functions: - - `b3CollideSpheres` - `b3CollideCapsuleAndSphere` - `b3CollideCapsules` - `b3CollideHullAndSphere` - `b3CollideHullAndCapsule` - `b3CollideHulls` -- `b3CollideTriangleAndCapsule` -- `b3CollideTriangleAndHull` -- `b3CollideTriangleAndSphere` +- `b3CollideCapsuleAndTriangle` +- `b3CollideHullAndTriangle` +- `b3CollideSphereAndTriangle` The SAT cache in `b3CollideHulls` warm-starts the separating axis search between frames, the same idea as the simplex cache for GJK distance. diff --git a/docs/compound.md b/docs/compound.md index a5bd7a1..82d79fe 100644 --- a/docs/compound.md +++ b/docs/compound.md @@ -13,9 +13,10 @@ not a runtime mutation primitive. The intended workflow is: 1. Author geometry offline (level mesh, terrain tile, building shell). 2. Bake the compound once with `b3CreateCompound`. -3. Write the compound bytes to disk or a streaming cache. -4. At runtime, load the bytes and check them with `b3ValidateCompound`, then - attach the compound to a static body. +3. Serialize it to a byte buffer with `b3ConvertCompoundToBytes` and store it on + disk or in a streaming cache. +4. At runtime, load the bytes and reconstruct the compound with + `b3ConvertBytesToCompound`, then attach it to a static body. This makes compounds well-suited to open-world streaming: tiles are baked offline, kept in memory as flat byte buffers (which the engine uses directly @@ -54,48 +55,46 @@ b3Compound* compound = b3CreateCompound(&def); can be freed immediately after the call. Mesh children share the mesh pointer rather than cloning triangle data — the -`b3MeshData` must remain valid for the lifetime of the compound. A compound's -shared material table holds at most 64K unique materials. +`b3MeshData` must remain valid for the lifetime of the compound. Triangle +materials are limited to `B3_MAX_COMPOUND_MESH_MATERIALS` (4) slots per mesh +child; if your mesh needs more materials, attach it as a standalone mesh shape +on the static body instead. ## The b3Compound Structure ```c typedef struct b3Compound { - uint64_t version; // versioned against the mesh/hull formats + uint64_t version; // versioned against the tree/mesh/hull formats int byteCount; // total size when serialized - // tree offsets and counts, child arrays, material table + // internal tree, child arrays, material table // ... (treat as opaque) } b3Compound; ``` `version` is a compile-time constant (`B3_COMPOUND_VERSION`) that incorporates -the mesh and hull format versions. A version mismatch at load time means the -bytes were baked with a different engine version and cannot be used. +the dynamic tree, mesh, and hull format versions. A version mismatch at load +time means the bytes were baked with a different engine version and cannot be +used. ## Serialization -A compound is a single flat blob that contains no pointers. Everything inside it -is addressed by byte offset from the start of the struct, so the bytes are -position independent. Write `compound->byteCount` bytes starting at the compound -address to disk. A plain `memcpy`, file read, or memory map of those bytes is a -valid compound, and no fixup step is needed. - -Validate bytes at runtime before using them (zero-copy; bytes must remain in -scope and must not be modified while a shape uses them): +Convert a live compound to a self-contained byte buffer: ```c -const b3CompoundData* compound = b3ValidateCompound(bytes, byteCount); -if (compound == NULL) -{ - // wrong version, wrong size, or corrupt offsets -} +uint8_t* bytes = b3ConvertCompoundToBytes(compound); +// compound is now in an unusable state; its pointers have been nullified. +// Write bytes[0 .. compound->byteCount - 1] to disk. ``` -`b3ValidateCompound` never modifies the bytes. It returns `NULL` unless the -version matches, `byteCount` equals the size stored in the compound, and the tree -node array lies fully inside the buffer. On success it returns the -input address. Multiple static bodies can use the same byte buffer -simultaneously (instancing), since the compound itself holds no per-body state. +Reconstruct from bytes at runtime (zero-copy; bytes must remain in scope): + +```c +b3Compound* compound = b3ConvertBytesToCompound(bytes, byteCount); +``` + +The bytes are mutated in place to fixup internal pointers. Multiple static +bodies can use the same byte buffer simultaneously (instancing), since the +compound itself holds no per-body state. ## Attaching to a Static Body @@ -154,5 +153,5 @@ you manage the buffer lifetime yourself): b3DestroyCompound(compound); ``` -Do not call `b3DestroyCompound` on a compound validated from bytes with -`b3ValidateCompound` — free the byte buffer instead. +Do not call `b3DestroyCompound` on a compound reconstructed from bytes with +`b3ConvertBytesToCompound` — free the byte buffer instead. diff --git a/docs/deploy_docs.sh b/docs/deploy_docs.sh deleted file mode 100644 index 1f604f8..0000000 --- a/docs/deploy_docs.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -# Copies documentation to blog -cp -R build/docs/html/. ../blog/public/documentation3d/ diff --git a/docs/extra.css b/docs/extra.css index 19aecdf..fb75491 100644 --- a/docs/extra.css +++ b/docs/extra.css @@ -1,41 +1,61 @@ /* -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, +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, so plain overrides win by order. */ -/* 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; +/* 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; } -/* Page */ +h2.groupheader, +.memtitle { + color: #67d8ef; +} -/* Soften contrast. Doxygen's dark is near black, restore the Box2D grays */ +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 */ body { - background-color: var(--b3-page); - color: var(--b3-text); + background-color: #292a2d; + color: #D8D8D8; } #titlearea, div.header, #side-nav, #nav-tree { - background-color: var(--b3-page); -} - -#titlearea, -div.header { - border-bottom-color: var(--b3-edge); + background-color: #292a2d; } /* Panels and selection sit one step lighter than the page */ @@ -49,371 +69,17 @@ 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: var(--b3-panel); + background-color: #32363d; } .directory tr.odd { - background-color: var(--b3-page); + background-color: #292a2d; } -/* 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, +/* Caution callouts, filled olive box with a full border and real padding */ 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); + background-color: #456114; + border: 1px solid #000000; + padding: 12px 16px; + margin: 10px 24px 10px 4px; } diff --git a/docs/faq.md b/docs/faq.md index 246624c..d504ef7 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -44,24 +44,6 @@ for orientation and 3x3 inertia tensors for rotational dynamics. If you come acr understand, please read about it on Wikipedia. Visit this [page](https://box2d.org/publications/) if you want a deeper knowledge of the algorithms used in Box3D. -### Working with Unreal - -You can use Box3D in Unreal as a plug-in. Here is the module file I use: - -[Box3D module](https://gist.github.com/erincatto/6f08df5f1e6e9a79fb4be6298a3e1125) - -Unreal uses centimeters as units while Box3D has tolerances tuned for meters. You can either scale dimensions you send and recieve from Box3D or you can use this to set the length units: - -```c -b3SetLengthUnitsPerMeter(100.0f); -``` - -This doesn't scale the units. Instead it scales the tolerances used internally in Box3D to be more appropriate for centimeters. - -Another issue is that Box3D is right-handed while Unreal is left-handed. Box3D has way too much math for it to be reasonable to support a left-handed option. However, it doesn't matter. In practice you don't need to do any conversions. Box3D will run in a mirrored world and the outputs from Box3D are fully compatible with the Unreal coordinates. - -I would just be careful about using Box3D math functions like `b3Cross` and expecting it to give the same result as the Unreal cross product. - ## API ### What units does Box3D use? @@ -121,41 +103,6 @@ approximately solve the differential equations. Box3D also does not have exact c moving shapes may have small overlap for a few time steps. In extreme stacking scenarios, shapes may have sustained overlap. -## Shapes - -### Why doesn't Box3D have a cylinder shape? - -Cylinders look simple but they are one of the hardest shapes to make work well in a 3D physics engine. Other engines -that support cylinders tend to document them as their least stable shape. A cylinder combines three kinds of geometry -that each need different handling: - -* flat caps, like a polytope -* a sharp circular rim, like an edge that is curved -* a curved side, like a capsule that has no rounded ends - -These cause several problems: - -**Collision algorithms don't fit.** The other shapes in Box3D fall into two families. Spheres and capsules are a point -or a segment with a radius, so their collision is closed form and exact. Convex hulls have a finite set of faces and -edges, so Box3D can find the separating axis directly and clip faces to build a contact manifold. A cylinder belongs to -neither family. Its side has infinitely many face normals, and the rim is a curved edge. Testing the rim against a box -edge means solving a quartic. So engines fall back on GJK with a support function, which converges slowly on smooth -shapes. They also need extra machinery such as EPA or shrunken cores with margins for overlapping shapes. - -GJK only gives one contact point but a cylinder resting on the end cap needs at least 4 points. Some physics engines -just clip a predefined polygon. In this case it is not really a cylinder being simulated. - -### What should I use instead of a cylinder? - -It depends on what the cylinder is for: -* **Barrels, logs, and pipes that roll:** a capsule rolls perfectly smoothly on its side. The rounded ends are often not - noticeable. Box3D supports rolling resistance for capsules as well. -* **Wheels:** use a sphere for the wheel collision, together with a wheel joint or revolute joint. A sphere rolls - perfectly and is the cheapest shape to collide. Box3D can reject ghost collisions between spheres and internal mesh edges. - Many vehicle setups instead skip wheel collision entirely and use ray casts or shape casts to find the ground. -* **Pillars, coins, and anything that mostly rests on its cap:** use a hull from `b3CreateCylinder()`. It makes a - tessellated cylinder along the y-axis with between 3 and 32 sides. Use the fewest sides that looks acceptable. - ## Making Games ### Tile / Voxel Based Environments diff --git a/docs/foundation.md b/docs/foundation.md index ab6457b..607b266 100644 --- a/docs/foundation.md +++ b/docs/foundation.md @@ -1,10 +1,8 @@ # Foundations - Box3D provides minimal base functionality for allocation hooks and vector math. The C interface allows most runtime data and types to be defined internally in the `src` folder. ## Assertions - Box3D will assert on bad input. This includes things like sending in NaN or infinity for values. It will assert if you use negative values for things that should only be positive, such as density. @@ -15,7 +13,6 @@ You may wish to capture assertions in your application. In that case use `b3SetA lets you override the debugger break and/or perform your own error handling. ## Allocation - Box3D uses memory efficiently and minimizes per-frame allocations by pooling memory. The engine quickly adapts to the simulation size. After the first step or two of simulation there should be no further per-frame allocations. @@ -32,7 +29,6 @@ You can provide a custom allocator using `b3SetAllocator()` and query the total allocated using `b3GetByteCount()`. ## Version - The `b3Version` structure holds the current version so you can query it at run-time using `b3GetVersion()`. @@ -42,13 +38,11 @@ printf("Box3D version %d.%d.%d\n", version.major, version.minor, version.revisio ``` ## Vector Math - Box3D includes a vector math library covering types `b3Vec3`, `b3Quat`, `b3Transform`, `b3Matrix3`, and `b3AABB`. The library is designed to suit the internal needs of Box3D and its interface. All members are exposed, so you can use them freely in your application. ### b3Vec3 - Three-component float vector with fields `x`, `y`, `z`. Useful constants and operations: ```c @@ -66,7 +60,6 @@ b3Vec3 q = b3Lerp(a, b, 0.5f); // linear interpolation ``` ### b3Quat - Unit quaternion representing orientation. Stored as a vector part `q.v` (x, y, z) and a scalar part `q.s`. The identity quaternion is `b3Quat_identity`. @@ -106,7 +99,6 @@ Because orientation in 3D is three-dimensional, there is no single scalar angle in 2D. Always work with the full quaternion or the derived matrix. ### b3Transform - A rigid transform: a position vector `t.p` (`b3Vec3`) combined with an orientation `t.q` (`b3Quat`). The identity transform is `b3Transform_identity`. @@ -128,111 +120,90 @@ b3Transform inv = b3InvertTransform(t); ``` ### b3Matrix3 - 3×3 matrix stored as three column vectors `cx`, `cy`, `cz`. Primarily used for inertia tensors and rotation matrices. Useful operations include `b3MulMV` (matrix-vector multiply), `b3MulMM` (matrix-matrix multiply), `b3Transpose`, `b3InvertMatrix`, and `b3MakeMatrixFromQuat`. ### b3AABB - Axis-aligned bounding box with `lowerBound` and `upperBound` as `b3Vec3`. Helpers include `b3AABB_Overlaps`, `b3AABB_Contains`, `b3AABB_ContainsPoint`, `b3AABB_Union`, `b3AABB_Center`, `b3AABB_Extents`, `b3AABB_Inflate`, and `b3AABB_Transform`. ## Multithreading {#multi} +Box3D has been highly optimized for multithreading. Multithreading is not required and by +default Box3D runs single-threaded. If performance matters, you should consider wiring up +the multithreading interface. -Box3D has been optimized for multithreading. Multithreading is not required and by default Box3D will run single-threaded. If performance is important for your application, you should consider using the multithreading features. - -### Internal scheduler - -Box3D has a built-in task scheduler that creates threads. You can use the built-in scheduler by setting the worker count in the world definition. This example shows how to use 4 workers. In this case Box3D will create 3 threads, and count the thread that calls `b3World_Step` as the fourth worker. I recommend to use the core count of the CPU as the worker count, not counting hyper-threads or efficiency cores. +Box3D does **not** create threads itself. You supply your own thread pool and hook it up through +the world definition before calling `b3CreateWorld`. See `b3EnqueueTaskCallback`, +`b3FinishTaskCallback`, `b3WorldDef::workerCount`, `b3WorldDef::enqueueTask`, and +`b3WorldDef::finishTask`: ```c b3WorldDef worldDef = b3DefaultWorldDef(); -worldDef.workerCount = 4; +worldDef.workerCount = myThreadCount; +worldDef.enqueueTask = MyEnqueueTask; +worldDef.finishTask = MyFinishTask; +worldDef.userTaskContext = myScheduler; + +b3WorldId worldId = b3CreateWorld(&worldDef); ``` -### External scheduler - -You can optionally connect your own task scheduler if you want more control. Multithreading is established for each Box3D world you create and must be hooked up to the world definition. See `b3TaskCallback()`, `b3EnqueueTaskCallback()`, and `b3FinishTaskCallback()` for more details. Also see `b3WorldDef::workerCount`, `b3WorldDef::enqueueTask`, and `b3WorldDef::finishTask`. +Your `MyEnqueueTask` callback receives a `b3TaskCallback*` function pointer plus a context +pointer that must be forwarded to the task exactly once on a worker thread. Return a non-null +`void*` handle representing your pending task object, or null if the work was executed +serially inside the callback (Box3D then skips the corresponding `b3FinishTaskCallback`). ```c -// Implement b3EnqueueTaskCallback +// Enqueue callback signature void* MyEnqueueTask(b3TaskCallback* task, void* taskContext, - void* userContext, b3TaskType taskType) + void* userContext, const char* taskName) { MyTask* t = AllocTask(); t->task = task; t->taskContext = taskContext; - Scheduler* myScheduler = (Scheduler*)userContext; - SubmitToThreadPool(myScheduler, t); - return t; + SubmitToThreadPool(t); // runs task(taskContext) on a worker + return t; // non-null => Box3D will call MyFinishTask(t, ...) } -// Implement b3FinishTaskCallback +// Finish callback signature void MyFinishTask(void* userTask, void* userContext) { MyTask* t = (MyTask*)userTask; WaitForCompletion(t); FreeTask(t); } - -b3WorldDef worldDef = b3DefaultWorldDef(); -worldDef.enqueueTask = MyEnqueueTask; -worldDef.finishTask = MyFinishTask; -worldDef.userTaskContext = myScheduler; -worldDef.workerCount = GetMyWorkerCount(); ``` -The finish callback is optional. Without it `b3World_Step()` waits on an internal semaphore that -the last task of each phase signals. This suits task systems that can launch work but cannot wait -on a single task. +`MyFinishTask` must block until the task has completed. Because the step blocks here on the tasks it +spawned, `b3World_Step` holds its stack across every fork and join inside the step. This has a +consequence for how you drive it. Run `b3World_Step` from a thread you can dedicate to the step, or +from a fiber that `MyFinishTask` can park so the underlying thread is freed to run the queued tasks. +In a job system that cannot park a job's stack, do not call `b3World_Step` from inside a job: a job +that blocks on the sub-jobs it spawned without yielding its thread starves the workers it is waiting +on and can deadlock. The alternative is help-while-wait, where the waiting thread runs other pending +tasks itself. This is what the in-tree scheduler does, which is why it needs no fiber. -### Stepping without blocking - -`b3World_Step()` holds the calling thread until the step is done. Some task systems cannot allow -this, for example a phased or wavefront scheduler where a thread that joins a parallel job cannot -leave it. For these you can drive the step yourself with `b3World_BeginStep()` and -`b3World_ContinueStep()`. Each call runs the serial work between two phases and returns the next -batch of tasks. An empty batch means the step is complete. +Box3D ships an in-tree scheduler (`src/scheduler.h`) used by the test suite and samples. +You can adapt it or use it directly: ```c -b3TaskBatch batch = b3World_BeginStep( worldId, timeStep, subStepCount ); -while ( batch.count > 0 ) -{ - // Run every task in the batch on any threads, in any order, then wait for them. - // MyRunTasks is a function you implement. - MyRunTasks( batch.tasks, batch.count ); +#include "scheduler.h" - batch = b3World_ContinueStep( worldId ); -} +b3Scheduler* scheduler = b3CreateScheduler(workerCount); + +b3WorldDef worldDef = b3DefaultWorldDef(); +worldDef.workerCount = workerCount; +worldDef.enqueueTask = b3SchedulerEnqueueTask; +worldDef.finishTask = b3SchedulerFinishTask; +worldDef.userTaskContext = scheduler; + +b3WorldId worldId = b3CreateWorld(&worldDef); +// ... simulate ... +b3DestroyWorld(worldId); +b3DestroyScheduler(scheduler); ``` -No callbacks are needed and the built-in scheduler is never created. The worker count still sets -the most tasks in a batch, `workerCount + 2`, and the size of the per-worker data. Each parallel -task claims blocks of work from a shared counter until none are left, so the tasks that run first -do most of the work and a task that starts late returns right away. Fewer threads than tasks costs -only the extra task launches, and you can adjust the worker count with `b3World_SetWorkerCount()` at -runtime. - -The rules: - -- Call each task function exactly once. Tasks in a batch may run concurrently on any threads. -- Begin and continue may be called from any thread, but never while a task of the current batch is - running. -- The world is locked until the step completes. Do not read or write it in between. -- The tasks of the constraint solver wait on each other. They work with any number of threads, - even when run one after another on a single thread, but a solver task that has started must not - be suspended indefinitely. - -One task may be marked `b3Task::deferred`. This is the rebuild of the dynamic tree, which overlaps -the narrow phase and the solver. You may leave it running across continue calls. A later batch -lists it in `b3TaskBatch::joinTasks` and it must be complete before the continue that follows that -batch. If you ignore the flag and run it with the rest of its batch, the step is still correct, it -just loses the overlap. - -### Threading model - The multithreading design for Box3D is focused on [data parallelism](https://en.wikipedia.org/wiki/Data_parallelism). The goal is to use multiple cores to finish the world simulation as fast as possible. Box3D multithreading is not designed for [task parallelism](https://en.wikipedia.org/wiki/Task_parallelism). @@ -242,34 +213,26 @@ main thread. Those are examples of task parallelism. So when you design your game loop, you should let Box3D *go wide* and use multiple cores to finish its work quickly, without other threads interacting with the Box3D world at the same time. -It is expected that the thread that calls `b3World_Step` participates in making progress. Do not call -`b3World_Step` and park that fiber. Tasks will only be enqueued on the thread that calls `b3World_Step`. -`MyFinishTask` must block until the task has completed. Ideally your scheduler is helping make progress -when `MyFinishTask` is called. - -### Avoiding race conditions - In a multithreaded environment you must be careful to avoid [race conditions](https://en.wikipedia.org/wiki/Race_condition). Modifying the world while it is simulating will lead to unpredictable behavior and is never safe. -It is also not safe to read data from a Box3D world while it is simulating. Box3D may move data +It is also not safe to read data from a Box3D world while it is simulating; Box3D may move data structures to improve cache performance, so you could easily read garbage. > **Caution**: -> Do not perform read or write operations on a Box3D world during `b3World_Step()`. -> Do not write to the Box3D world from multiple threads. Any operation that wakes -> a body is not thread-safe. +> Do not perform read or write operations on a Box3D world during `b3World_Step()` + +> **Caution**: +> Do not write to the Box3D world from multiple threads It *is safe* to do ray-casts, shape-casts, and overlap tests from multiple threads outside of `b3World_Step()`. Generally any read-only operation is safe to do multithreaded outside of `b3World_Step()`. This can be very useful if you have multithreaded game logic. ## Multithreading Multiple Worlds - Some applications may wish to create multiple Box3D worlds and simulate them on different threads. This works fine because Box3D has very limited use of globals. There are a few caveats: - - You will get a race condition if you create or destroy Box3D worlds from multiple threads. Use a mutex to guard those operations. - If you simulate multiple Box3D worlds simultaneously, they should probably not share a task system. Otherwise you risk preemption between worlds competing for the same workers. - Any callbacks you hook up to Box3D must be thread-safe, including memory allocators. diff --git a/docs/images/build.sh b/docs/images/build.sh deleted file mode 100644 index 068f65c..0000000 --- a/docs/images/build.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# Usage: ./build.sh [--force] [name.asy ...] -# https://asymptote.sourceforge.io/doc/colors.png - -asy="/c/Program Files/Asymptote/asy.exe" -if [ ! -x "$asy" ]; then - echo "missing $asy" - exit 1 -fi - -cd "$(dirname "$0")" || exit 1 - -force=0 -sources=() -for arg in "$@"; do - case "$arg" in - --force) force=1 ;; - *) sources+=("$arg") ;; - esac -done - -if [ ${#sources[@]} -eq 0 ]; then - sources=(*.asy) -fi - -# asy can exit 0 after a failed TeX run, so judge success by a fresh svg -marker=$(mktemp) -trap 'rm -f "$marker"' EXIT - -status=0 -failed=0 -for src in "${sources[@]}"; do - name=$(basename "$src" .asy) - svg="$name.svg" - - # Never clobber a hand drawn svg of the same name, delete it first to replace it - if [ -f "$svg" ] && ! head -c 300 "$svg" | grep -q dvisvgm; then - echo "skip $src: $svg was not made by asy" - status=1 - continue - fi - - if [ $force -eq 0 ] && [ "$svg" -nt "$src" ]; then - echo "fresh $svg" - continue - fi - - touch "$marker" - "$asy" -noV -o "$name" "$src" - if [ "$svg" -nt "$marker" ]; then - echo "built $svg" - else - echo "failed $src" - status=1 - failed=1 - fi -done - -# Leftovers from asy's TeX pipe. Keep the log after a failure, it has the TeX error. -rm -f texput.aux -if [ $failed -eq 0 ]; then - rm -f texput.log -fi -exit $status diff --git a/docs/images/manifolds.svg b/docs/images/manifolds.svg index 30d3a51..564fe9f 100644 --- a/docs/images/manifolds.svg +++ b/docs/images/manifolds.svg @@ -2,23 +2,22 @@ + inkscape:export-ydpi="90"> + fit-margin-bottom="0" /> @@ -139,6 +135,7 @@ image/svg+xml + diff --git a/docs/images/saddle_region.asy b/docs/images/saddle_region.asy deleted file mode 100644 index f4ad105..0000000 --- a/docs/images/saddle_region.asy +++ /dev/null @@ -1,267 +0,0 @@ -settings.outformat = "svg"; -settings.render = 0; -settings.prc = false; - -import three; - -real px = 0.75bp; - -pen ink = rgb("231f20"); -pen meshPen = ink + 0.6px; -pen regionFill = rgb("f2d4d0"); -pen regionPen = rgb("a8322a") + 1.0px; -pen ridgeColor = rgb("c26a17"); -pen gullyColor = rgb("1f5c99"); -pen sliceFill = gray(0.93) + opacity(0.75); -pen guidePen = gray(0.55) + 0.5px + linetype(new real[] {4, 3}); -pen hullPen = ink + 0.7px + linetype(new real[] {5, 3}); - -real arrowSize = 5px; -triple lightDirection = unit((1, 4, 2)); - -// The Saddle Vertex sample hub, spokes alternate 8 degree ridges and 32 degree gullies -int spokeCount = 6; -real fanRadius = 1.5; -real[] drops = {8, 32, 8, 32, 8, 32}; - -// The slice plane sits this far above the hub. Planes through the hub cut it in lines. -real sliceHeight = 1.6; -real sliceRadius = sliceHeight * Tan(40); - -triple[] spokes; -for (int i = 0; i < spokeCount; ++i) -{ - real angle = 60 * i; - spokes.push(fanRadius * (Cos(angle), -Tan(drops[i]), Sin(angle))); -} - -bool IsRidge(int i) -{ - return i % 2 == 0; -} - -pen SpokePen(int i) -{ - return IsRidge(i) ? ridgeColor : gullyColor; -} - -// Gnomonic coordinates: a normal n maps to (n.x, n.z) / n.y on the slice, so every plane through -// the hub maps to a line and n . e <= 0 maps to a half plane -pair Gnomonic(triple n) -{ - return (n.x / n.y, n.z / n.y); -} - -// Half plane of spoke i on the unit slice: dot(p, u) <= offset -pair SpokeDirection(int i) -{ - return (Cos(60 * i), Sin(60 * i)); -} - -real SpokeOffset(int i) -{ - return Tan(drops[i]); -} - -// Sutherland Hodgman clip of a convex polygon against dot(p, u) <= offset -pair[] ClipPolygon(pair[] poly, pair u, real offset) -{ - pair[] result; - int n = poly.length; - for (int k = 0; k < n; ++k) - { - pair a = poly[k]; - pair b = poly[(k + 1) % n]; - real da = dot(a, u) - offset; - real db = dot(b, u) - offset; - if (da <= 0) - result.push(a); - if (da * db < 0) - result.push(a + da / (da - db) * (b - a)); - } - return result; -} - -pair[] region = { (-10, -10), (10, -10), (10, 10), (-10, 10) }; -for (int i = 0; i < spokeCount; ++i) - region = ClipPolygon(region, SpokeDirection(i), SpokeOffset(i)); - -// Each face normal is perpendicular to its two spokes, so it lies on both of their lines -pair[] faceNormals; -for (int i = 0; i < spokeCount; ++i) -{ - triple n = cross(spokes[(i + 1) % spokeCount], spokes[i]); - if (n.y < 0) - n = -n; - faceNormals.push(Gnomonic(n)); -} - -// A face normal leans past the gully it borders, so sort by angle before drawing the hull -pair[] hullPoints = sort(faceNormals, new bool(pair a, pair b) { return degrees(a, false) < degrees(b, false); }); - -// End points of the line of spoke i, clipped to a disk of the given radius on the unit slice -pair[] SpokeLine(int i, real radius) -{ - pair u = SpokeDirection(i); - pair t = (-u.y, u.x); - real c = SpokeOffset(i); - real half = sqrt(radius * radius - c * c); - return new pair[] { c * u - half * t, c * u + half * t }; -} - -pen Shade(path3 face) -{ - triple n = unit(cross(point(face, 1) - point(face, 0), point(face, 2) - point(face, 0))); - real k = 0.74 + 0.26 * abs(dot(n, lightDirection)); - return rgb(k * 0.843, k * 0.890, k * 0.957); -} - -triple Lift(pair p) -{ - return sliceHeight * (p.x, 1, p.y); -} - -frame[] panels; -string[] titles; - -// 3D view: the fan, the slice above it and the cone of the region -{ - currentprojection = orthographic((3.4, 3.0, 2.6), up = Y); - picture pic; - size(pic, 250px, 250px); - triple hub = (0, 0, 0); - - for (int i = 0; i < spokeCount; ++i) - { - path3 t = hub -- spokes[i] -- spokes[(i + 1) % spokeCount] -- cycle; - draw(pic, surface(t), Shade(t), nolight); - draw(pic, t, meshPen); - } - - triple offset[] = {(0.1, 0, 0.1), (0.3, 0, 0.3), (0, 0, 0), (-0.1, 0, 0), (0, 0, -0.3), (0, 0, 0)}; - for (int i = 0; i < spokeCount; ++i) - { - draw(pic, hub -- spokes[i], SpokePen(i) + 1.4px); - label(pic, "$e_" + string(i) + "$", spokes[i] + offset[i], unit(Gnomonic((spokes[i].x, 1, 4 * spokes[i].z))), SpokePen(i)); - } - - // The boundary plane of one ridge spoke, it holds the hub and its line on the slice - pair[] line0 = SpokeLine(0, Tan(40)); - path3 wall = hub -- Lift(line0[0]) -- Lift(line0[1]) -- cycle; - draw(pic, surface(wall), ridgeColor + opacity(0.18), nolight); - draw(pic, hub -- Lift(line0[0]), ridgeColor + 0.5px + linetype(new real[] {4, 3})); - draw(pic, hub -- Lift(line0[1]), ridgeColor + 0.5px + linetype(new real[] {4, 3})); - - path3 slice = shift((0, sliceHeight, 0)) * rotate(90, X) * scale3(sliceRadius) * unitcircle3; - draw(pic, surface(slice), sliceFill, nolight); - draw(pic, slice, gray(0.6) + 0.5px); - - for (int i = 0; i < spokeCount; ++i) - { - pair[] ends = SpokeLine(i, Tan(40)); - draw(pic, Lift(ends[0]) -- Lift(ends[1]), SpokePen(i) + 0.8px); - } - - path3 top = Lift(region[0]); - for (int k = 1; k < region.length; ++k) - top = top -- Lift(region[k]); - top = top -- cycle; - draw(pic, surface(top), regionFill, nolight); - draw(pic, top, regionPen); - - for (pair p : region) - draw(pic, hub -- Lift(p), regionPen); - - dot(pic, hub, ink + 3px); - label(pic, "slice", Lift((0, -Tan(40))) + (0, 0.1, 0), N, gray(0.35)); - - panels.push(pic.fit()); - titles.push("Saddle Vertex Voronoi"); -} - -// Top view of the slice, in units of tan(tilt) -{ - picture pic; - unitsize(pic, 190px); - real radius = Tan(40); - - // Looking down on the slice: x to the right, z down the page - pair View(pair p) - { - return (p.x, -p.y); - } - - path hull = View(hullPoints[0]); - for (int i = 1; i < spokeCount; ++i) - hull = hull -- View(hullPoints[i]); - hull = hull -- cycle; - fill(pic, hull, gray(0.92)); - - // Excluded side of each line, a band inside the disk - real band = 0.035; - for (int i = 0; i < spokeCount; ++i) - { - pair u = SpokeDirection(i); - pair[] ends = SpokeLine(i, radius - band); - path strip = View(ends[0]) -- View(ends[1]) -- View(ends[1] + band * u) -- View(ends[0] + band * u) -- cycle; - fill(pic, strip, SpokePen(i) + opacity(0.25)); - } - - for (int i = 0; i < spokeCount; ++i) - { - pair[] ends = SpokeLine(i, radius); - draw(pic, View(ends[0]) -- View(ends[1]), SpokePen(i) + 1.0px); - pair u = SpokeDirection(i); - label(pic, "$e_" + string(i) + "$", View((SpokeOffset(i) + (IsRidge(i) ? 0.11 : 0.075)) * u), SpokePen(i)); - } - - draw(pic, hull, hullPen); - - path area = View(region[0]); - for (int k = 1; k < region.length; ++k) - area = area -- View(region[k]); - area = area -- cycle; - filldraw(pic, area, regionFill, regionPen); - - // Tilt from up, drawn over the fills so they read through the region - for (real tilt : new real[] {10, 20, 30, 40}) - { - draw(pic, scale(Tan(tilt)) * unitcircle, tilt == 40 ? gray(0.6) + 0.5px : guidePen); - label(pic, string(tilt) + "$^\circ$", Tan(tilt) * dir(90), N, gray(0.45) + fontsize(7pt)); - } - - for (pair n : faceNormals) - dot(pic, View(n), ink + 3.5px); - label(pic, "face normals", View(faceNormals[1]), NE, ink + fontsize(8pt)); - - dot(pic, (0, 0), ink + 2.5px); - label(pic, "up", (0, 0), SW, ink + fontsize(8pt)); - - frame f = pic.fit(); - panels.push(f); - titles.push("Top View"); -} - -real gap = 36px; -real x = 0; -real bottom = 0; -for (int i = 0; i < panels.length; ++i) -{ - frame f = panels[i]; - pair lo = min(f); - pair hi = max(f); - add(shift(x - lo.x, -lo.y) * f); - label(titles[i], (x + 0.5 * (hi.x - lo.x), -8px), S, ink); - x += hi.x - lo.x + gap; -} - -// Legend -pair legend = (0, -40px); -draw((legend.x, legend.y) -- (legend.x + 18px, legend.y), ridgeColor + 1.4px); -label("ridge spoke, 8$^\circ$ drop", (legend.x + 22px, legend.y), E, ink + fontsize(8pt)); -draw((legend.x + 150px, legend.y) -- (legend.x + 168px, legend.y), gullyColor + 1.4px); -label("gully spoke, 32$^\circ$ drop", (legend.x + 172px, legend.y), E, ink + fontsize(8pt)); -filldraw(shift(legend.x + 300px, legend.y - 5px) * scale(10px) * unitsquare, regionFill, regionPen); -label("vertex region", (legend.x + 314px, legend.y), E, ink + fontsize(8pt)); -draw((legend.x + 410px, legend.y) -- (legend.x + 428px, legend.y), hullPen); -label("cone of face normals", (legend.x + 432px, legend.y), E, ink + fontsize(8pt)); diff --git a/docs/images/saddle_region.svg b/docs/images/saddle_region.svg deleted file mode 100644 index d2c1307..0000000 --- a/docs/images/saddle_region.svg +++ /dev/null @@ -1,442 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/images/vertex_regions.asy b/docs/images/vertex_regions.asy deleted file mode 100644 index 07c8975..0000000 --- a/docs/images/vertex_regions.asy +++ /dev/null @@ -1,323 +0,0 @@ -settings.outformat = "svg"; -settings.render = 0; -settings.prc = false; - -import three; - -real px = 0.75bp; - -pen ink = rgb("231f20"); -pen meshPen = ink + 0.6px; -// Half opacity over white matches the opaque f2d4d0 of the other figures -pen regionFill = rgb("e5a9a1") + opacity(0.5); -pen regionShade = rgb("7a1f18"); -pen regionPen = rgb("a8322a") + 0.9px; -pen rayPen = rgb("a8322a") + 0.6px; -pen spokePen = rgb("1f5c99") + 1.0px; -pen cliffFill = gray(0.88) + opacity(0.6); -pen guidePen = gray(0.45) + 0.6px + linetype(new real[] {4, 3}); - -real panelSize = 170px; -real capRadius = 0.55; -real arrowSize = 5px; - -triple lightDirection = unit((1, 4, 2)); - -// Extreme rays of the cone of normals n with n . d <= 0 for every direction d -triple[] RegionRays(triple[] d) -{ - triple[] rays; - for (int i = 0; i < d.length; ++i) - { - for (int j = i + 1; j < d.length; ++j) - { - triple c = cross(d[i], d[j]); - if (abs(c) < 1e-6) - continue; - - for (real s : new real[] {1, -1}) - { - triple r = s * unit(c); - bool inside = true; - for (triple e : d) - inside = inside && dot(r, unit(e)) <= 1e-6; - - bool duplicate = false; - for (triple q : rays) - duplicate = duplicate || dot(r, q) > 1 - 1e-6; - - if (inside && !duplicate) - rays.push(r); - } - } - } - - triple axis = (0, 0, 0); - for (triple r : rays) - axis += r; - axis = unit(axis); - - triple t1 = unit(cross(axis, abs(axis.x) < 0.9 ? X : Y)); - triple t2 = cross(axis, t1); - real[] angles; - for (triple r : rays) - angles.push(atan2(dot(r, t2), dot(r, t1))); - - int[] order = sequence(rays.length); - order = sort(order, new bool(int a, int b) { return angles[a] < angles[b]; }); - triple[] sorted; - for (int k : order) - sorted.push(rays[k]); - return sorted; -} - -triple Arc(triple a, triple b, real t) -{ - return unit((1 - t) * a + t * b); -} - -// Extreme rays of the region, drawn as arrows leaving the rim -void DrawRayTips(picture pic, triple v, triple[] rays, real radius) -{ - for (triple r : rays) - draw(pic, (v + radius * r) -- (v + (radius + 0.3) * r), regionPen, Arrow3(arrowSize)); -} - -// Convex hull by monotone chain -pair[] ConvexHull(pair[] points) -{ - pair[] p = sort(points, new bool(pair a, pair b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }); - pair[] hull; - for (int pass = 0; pass < 2; ++pass) - { - int base = hull.length; - for (pair q : p) - { - while (hull.length >= base + 2 && cross(hull[hull.length - 1] - hull[hull.length - 2], q - hull[hull.length - 2]) <= 0) - hull.pop(); - hull.push(q); - } - hull.pop(); - p = reverse(p); - } - return hull; -} - -// The region is convex, so its outline is the hull of its projected points. Filling that once -// avoids the seams that overlapping translucent patches would show. -void FillProjected(picture pic, triple v, triple[] points) -{ - triple view = unit(currentprojection.camera - currentprojection.target); - triple u1 = unit(cross(currentprojection.up, view)); - triple u2 = cross(view, u1); - - pair[] flat; - for (triple q : points) - flat.push((dot(q - v, u1), dot(q - v, u2))); - - pair[] hull = ConvexHull(flat); - path3 outline = v + hull[0].x * u1 + hull[0].y * u2; - for (int k = 1; k < hull.length; ++k) - outline = outline -- (v + hull[k].x * u1 + hull[k].y * u2); - draw(pic, surface(outline -- cycle, planar = true), regionFill, nolight); -} - -void DrawRegion(picture pic, triple v, triple[] rays, real radius) -{ - int arcSteps = 12; - int n = rays.length; - - triple axis = (0, 0, 0); - for (triple r : rays) - axis += r; - axis = unit(axis); - - triple[] points = { v }; - path3 rim; - for (int i = 0; i < n; ++i) - { - if (n == 2 && i == 1) - break; - - triple a = rays[i]; - triple b = rays[(i + 1) % n]; - for (int k = 0; k <= arcSteps; ++k) - { - triple p = v + radius * Arc(a, b, k / arcSteps); - rim = i == 0 && k == 0 ? p : rim -- p; - points.push(p); - - // Interior points for the silhouette of the spherical cap - for (int j = 1; j < 6 && n > 2; ++j) - points.push(v + radius * Arc(axis, Arc(a, b, k / arcSteps), j / 6)); - } - } - - FillProjected(pic, v, points); - - // Darken the flat sides with the same light as the mesh. Sides on the near half of the cone never - // overlap each other in projection, nor do sides on the far half, so each adds one layer. - for (int i = 0; i < n; ++i) - { - if (n == 2 && i == 1) - break; - - triple a = rays[i]; - triple b = rays[(i + 1) % n]; - triple side = unit(cross(a, b)); - - path3 sector = v + radius * a; - for (int k = 1; k <= arcSteps; ++k) - sector = sector -- (v + radius * Arc(a, b, k / arcSteps)); - sector = v -- sector -- cycle; - - real shade = 1 - abs(dot(side, lightDirection)); - draw(pic, surface(sector, planar = true), regionShade + opacity(0.35 * shade), nolight); - } - - draw(pic, n == 2 ? rim : rim -- cycle, regionPen); - for (triple r : rays) - draw(pic, v -- (v + radius * r), rayPen); - DrawRayTips(pic, v, rays, radius); -} - -// Flat shading in world space, so every panel is lit the same way -pen Shade(path3 face) -{ - triple n = unit(cross(point(face, 1) - point(face, 0), point(face, 2) - point(face, 0))); - real k = 0.74 + 0.26 * abs(dot(n, lightDirection)); - return rgb(k * 0.843, k * 0.890, k * 0.957); -} - -void DrawFan(picture pic, triple v, triple[] rim, bool closed) -{ - int count = closed ? rim.length : rim.length - 1; - for (int i = 0; i < count; ++i) - { - path3 t = v -- rim[i] -- rim[(i + 1) % rim.length] -- cycle; - draw(pic, surface(t), Shade(t), nolight); - draw(pic, t, meshPen); - } -} - -void DrawSpokes(picture pic, triple v, triple[] ends) -{ - for (triple e : ends) - draw(pic, v -- (v + 0.45 * (e - v)), spokePen, Arrow3(arrowSize)); -} - -frame[] panels; -string[] titles; - -// Box corner, three faces meet at a convex vertex -{ - currentprojection = orthographic((3.5, 2.6, 2.8), up = Y); - picture pic; - size(pic, panelSize, panelSize); - triple v = (0, 0, 0); - - path3[] faces = { - (0, 0, 0) -- (0, -1, 0) -- (0, -1, -1) -- (0, 0, -1) -- cycle, - (0, 0, 0) -- (0, 0, -1) -- (-1, 0, -1) -- (-1, 0, 0) -- cycle, - (0, 0, 0) -- (-1, 0, 0) -- (-1, -1, 0) -- (0, -1, 0) -- cycle, - }; - for (path3 f : faces) - { - draw(pic, surface(f), Shade(f), nolight); - draw(pic, f, meshPen); - } - - triple[] ends = { (-1, 0, 0), (0, -1, 0), (0, 0, -1) }; - DrawSpokes(pic, v, ends); - DrawRegion(pic, v, RegionRays(ends), capRadius); - dot(pic, v, ink + 3px); - - panels.push(pic.fit()); - titles.push("convex corner"); -} - -// A vertex on a ridge, the region collapses to a flat wedge -{ - currentprojection = orthographic((3.0, 2.4, 2.2), up = Y); - picture pic; - size(pic, panelSize, panelSize); - triple v = (0, 0, 0); - real h = tan(30 * pi / 180); - - triple[] rim = { (1, 0, 0), (1, -h, 1), (-1, -h, 1), (-1, 0, 0), (-1, -h, -1), (1, -h, -1) }; - DrawFan(pic, v, rim, true); - DrawSpokes(pic, v, rim); - DrawRegion(pic, v, RegionRays(rim), capRadius); - dot(pic, v, ink + 3px); - - panels.push(pic.fit()); - titles.push("ridge"); -} - -// Saddle hub, spokes alternate 8 degree ridges and 32 degree gullies -{ - currentprojection = orthographic((2.0, 4.0, 3.0), up = Y); - picture pic; - size(pic, panelSize, panelSize); - triple v = (0, 0, 0); - - triple[] rim; - for (int i = 0; i < 6; ++i) - { - real angle = i * 60; - real drop = i % 2 == 1 ? 32 : 8; - rim.push((Cos(angle), -Tan(drop), Sin(angle))); - } - - DrawFan(pic, v, rim, true); - DrawSpokes(pic, v, rim); - DrawRegion(pic, v, RegionRays(rim), 1.2); - dot(pic, v, ink + 3px); - - panels.push(pic.fit()); - titles.push("saddle hub"); -} - -// Corner of an open sheet, the cliffs below the boundary edges close the region -{ - currentprojection = orthographic((3.5, 2.6, 2.8), up = Y); - picture pic; - size(pic, panelSize, panelSize); - triple v = (0, 0, 0); - real depth = 0.6; - - path3[] cliffs = { - (0, 0, 0) -- (0, 0, -1) -- (0, -depth, -1) -- (0, -depth, 0) -- cycle, - (0, 0, 0) -- (-1, 0, 0) -- (-1, -depth, 0) -- (0, -depth, 0) -- cycle, - }; - for (path3 c : cliffs) - { - draw(pic, surface(c), cliffFill, nolight); - draw(pic, c, guidePen); - } - - triple[] rim = { (-1, 0, 0), (-1, 0, -1), (0, 0, -1) }; - DrawFan(pic, v, rim, false); - DrawSpokes(pic, v, rim); - - triple[] directions = copy(rim); - directions.push((0, -1, 0)); - DrawRegion(pic, v, RegionRays(directions), capRadius); - dot(pic, v, ink + 3px); - label(pic, "cliff", (0, -depth, -0.5), S, gray(0.35)); - - panels.push(pic.fit()); - titles.push("open corner"); -} - -real gap = 24px; -real x = 0; -for (int i = 0; i < panels.length; ++i) -{ - frame f = panels[i]; - pair lo = min(f); - pair hi = max(f); - add(shift(x - lo.x, -lo.y) * f); - label(titles[i], (x + 0.5 * (hi.x - lo.x), -8px), S, ink); - x += hi.x - lo.x + gap; -} diff --git a/docs/images/vertex_regions.svg b/docs/images/vertex_regions.svg deleted file mode 100644 index e192437..0000000 --- a/docs/images/vertex_regions.svg +++ /dev/null @@ -1,1050 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/docs/instant_scroll.cmake b/docs/instant_scroll.cmake deleted file mode 100644 index c82b9b4..0000000 --- a/docs/instant_scroll.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# 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/large_worlds.md b/docs/large_worlds.md index 6641514..25e5ba2 100644 --- a/docs/large_worlds.md +++ b/docs/large_worlds.md @@ -46,7 +46,7 @@ quaternions in both modes, so the trig and the cross-platform determinism proper The public API uses these types wherever it accepts or returns a world position: `b3BodyDef.position`, `b3Body_GetPosition` / `b3Body_GetTransform`, `b3Body_SetTransform`, `b3Body_GetWorldPoint` / -`b3Body_GetLocalPoint`, `b3Body_GetWorldCenter`, the explosion and ray-cast origins, contact +`b3Body_GetLocalPoint`, `b3Body_GetWorldCenterOfMass`, the explosion and ray-cast origins, contact and ray-cast result points, and the body move event. With double precision off these are all the float types they have always been, so existing code compiles unchanged. diff --git a/docs/layout.xml b/docs/layout.xml index 331a4ac..e93b6cf 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/docs/loose_ends.md b/docs/loose_ends.md index d7f2bbd..47892b9 100644 --- a/docs/loose_ends.md +++ b/docs/loose_ends.md @@ -91,6 +91,7 @@ Category flags on the struct control what gets drawn: | `drawContacts` | Contact points and anchors | | `drawContactNormals` | Contact normal directions | | `drawContactForces` | Normal impulse magnitudes | +| `drawFrictionForces` | Friction impulse magnitudes | | `drawGraphColors` | Constraint-graph color assignment | | `drawContactFeatures` | Raw contact feature indices | | `drawIslands` | Island bounding boxes | diff --git a/docs/overview.md b/docs/overview.md index 7e14fc2..6d7473d 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -1,10 +1,4 @@ # Overview {#mainpage} - -> **Caution**: -> The written part of this manual is a work in progress. -> It will be updated as v1.0 approaches. -> The reference section should be complete and accurate. - Box3D is a 3D rigid body simulation library for games. Programmers can use it in their games to make objects move in realistic ways and make the game world more interactive. From the game engine's point of view, @@ -20,7 +14,6 @@ engine begin with the `b3` prefix. Hopefully this is sufficient to avoid name clashing with your application. ## Prerequisites - In this manual I'll assume you are familiar with basic physics concepts, such as mass, force, torque, and impulses. If not, please first consult Google search and Wikipedia. @@ -40,7 +33,6 @@ should be comfortable with compiling, linking, and debugging. > Box3D. There are many resources for this online. ## Scope - This manual covers the majority of the Box3D API. However, not every aspect is covered. Please look at the Reference section and samples application included with Box3D to learn more. @@ -53,7 +45,6 @@ Box3D may be out of sync with this manual. > latest version on the main branch. ## Feedback and Bugs - Please file bugs and feature requests here: [Box3D Issues](https://github.com/erincatto/box3d/issues) @@ -139,7 +130,6 @@ the first time of impact (TOI). Second, speculative collision is used to create contact constraints between bodies before they touch. ### events - World simulation leads to the creation of events that are available at the end of the time step: @@ -151,7 +141,6 @@ of the time step: These events allow your application to react to changes in the simulation. ## Modules - Box3D's primary purpose is to provide rigid body simulation. However, there are math and collision features that may be useful apart from the rigid body simulation. These are provided in the `include` directory. Anything @@ -164,7 +153,6 @@ study the code and ask questions. I'm happy to share all the details of how Box3D works internally. ## Units - Box3D works with floating point numbers and tolerances have to be used to make Box3D perform well. These tolerances have been tuned to work well with meters-kilogram-second (MKS) units. In particular, Box3D has @@ -197,7 +185,6 @@ the full 3D rotation is tracked continuously. > Box3D uses radians, not degrees. ## Changing the length units - Advanced users may change the length unit by calling `b3SetLengthUnitsPerMeter()` at application startup. If you keep Box3D in a shared library, you will need to call this if the shared library is reloaded. @@ -208,7 +195,6 @@ One of the benefits of using MKS units for physics simulation is that you can use real world values to get reasonable results. ## Ids and Definitions - Fast memory management plays a central role in the design of the Box3D interface. When you create a world, body, shape or joint, you will receive a handle called an *id*. These ids are opaque and are passed to various functions diff --git a/docs/simulation.md b/docs/simulation.md index 89a3fad..456de15 100644 --- a/docs/simulation.md +++ b/docs/simulation.md @@ -490,12 +490,11 @@ The body's mass data is available through the following functions: ```c float mass = b3Body_GetMass(myBodyId); b3Matrix3 inertia = b3Body_GetLocalRotationalInertia(myBodyId); -b3Vec3 localCenter = b3Body_GetLocalCenter(myBodyId); +b3Vec3 localCenter = b3Body_GetLocalCenterOfMass(myBodyId); b3MassData massData = b3Body_GetMassData(myBodyId); ``` ### State Information - There are many aspects to the body's state. You can access this state data through the following functions: @@ -538,8 +537,8 @@ body that is a box. The body origin might be a corner of the box, while the center of mass is located at the center of the box. ```c -b3Pos worldCenter = b3Body_GetWorldCenter(myBodyId); -b3Vec3 localCenter = b3Body_GetLocalCenter(myBodyId); +b3Vec3 worldCenter = b3Body_GetWorldCenterOfMass(myBodyId); +b3Vec3 localCenter = b3Body_GetLocalCenterOfMass(myBodyId); ``` You can access the linear and angular velocity. The linear velocity is @@ -705,25 +704,22 @@ instead of bodies. Since you can attach multiple shapes to a body, this allows f possible setups. For example, you can make a vehicle that is heavier in the back. ### Density - The shape density is used to compute the mass properties of the parent body. The density can be zero or positive. You should generally use similar densities for all your shapes. This will improve stacking stability. -You may adjust the density of an existing body. You may choose to update the body mass immediately -or defer for a later call to `b3Body_ApplyMassFromShapes()`. Generally you should establish -the shape density in `b3ShapeDef` and avoid modifying it later because this can be expensive, -especially on a body with many shapes. +The mass of a body is not adjusted when you set the density. You must +call `b3Body_ApplyMassFromShapes()` for this to occur. Generally you should establish +the shape density in `b3ShapeDef` and avoid modifying it later because this +can be expensive, especially on a compound body. ```c -bool updateMass = false; -b3Shape_SetDensity(myShapeId, 5.0f, updateMass); +b3Shape_SetDensity(myShapeId, 5.0f, true); b3Body_ApplyMassFromShapes(myBodyId); ``` ### Friction - Friction is used to make objects slide along each other realistically. Box3D supports static and dynamic friction, but uses the same parameter for both. Box3D attempts to simulate friction accurately and the friction @@ -749,7 +745,6 @@ shapeDef.baseMaterial.friction = 0.5f; ``` ### Restitution - [Restitution](https://en.wikipedia.org/wiki/Coefficient_of_restitution) is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. @@ -777,7 +772,6 @@ shapeDef.baseMaterial.restitution = 0.3f; ``` ### Friction and Restitution Callbacks - Advanced users can override friction and restitution mixing using `b3FrictionCallback` and `b3RestitutionCallback`. These should be very lightweight functions because they are called frequently. The callbacks receive the two friction (or restitution) values @@ -800,7 +794,6 @@ worldDef.frictionCallback = MyFrictionCallback; ``` ### Filtering {#filtering} - Collision filtering allows you to efficiently prevent collision between shapes. For example, say you make a character that rides a bicycle. You want the bicycle to collide with the terrain and the character to collide with @@ -873,7 +866,6 @@ Collision groups have a higher priority than categories and masks. Note that additional collision filtering occurs automatically in Box3D. Here is a list: - - A shape on a static body can only collide with a dynamic body. - A shape on a kinematic body can only collide with a dynamic body. - Shapes on the same body never collide with each other. @@ -886,7 +878,6 @@ an existing shape using `b3Shape_GetFilter()` and it causes contacts to be destroyed. ### Sensors - Sometimes game logic needs to know when two shapes overlap yet there should be no collision response. This is done by using sensors. A sensor is a shape that detects overlap but does not produce a response. diff --git a/extern/imguizmo/ImGuizmo.cpp b/extern/imguizmo/ImGuizmo.cpp deleted file mode 100644 index 01ab141..0000000 --- a/extern/imguizmo/ImGuizmo.cpp +++ /dev/null @@ -1,3537 +0,0 @@ -// https://github.com/CedricGuillemet/ImGuizmo -// v1.92.5 WIP -// -// The MIT License(MIT) -// -// Copyright(c) 2016-2026 Cedric Guillemet and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files(the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions : -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif -#include "imgui.h" -#include "imgui_internal.h" -#include "ImGuizmo.h" - -#if defined(_MSC_VER) || defined(__MINGW32__) -#include -#endif -#if !defined(_MSC_VER) && !defined(__MINGW64_VERSION_MAJOR) -#define _malloca(x) alloca(x) -#define _freea(x) -#endif - -// includes patches for multiview from -// https://github.com/CedricGuillemet/ImGuizmo/issues/15 - -namespace IMGUIZMO_NAMESPACE -{ - static const float ZPI = 3.14159265358979323846f; - static const float RAD2DEG = (180.f / ZPI); - static const float DEG2RAD = (ZPI / 180.f); - const float screenRotateSize = 0.06f; - // scale a bit so translate axis do not touch when in universal - const float rotationDisplayFactor = 1.2f; - - static OPERATION operator&(OPERATION lhs, OPERATION rhs) - { - return static_cast(static_cast(lhs) & static_cast(rhs)); - } - - static bool operator!=(OPERATION lhs, int rhs) - { - return static_cast(lhs) != rhs; - } - - static bool Intersects(OPERATION lhs, OPERATION rhs) - { - return (lhs & rhs) != 0; - } - - // True if lhs contains rhs - static bool Contains(OPERATION lhs, OPERATION rhs) - { - return (lhs & rhs) == rhs; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // utility and math - - void FPU_MatrixF_x_MatrixF(const float* a, const float* b, float* r) - { - r[0] = a[0] * b[0] + a[1] * b[4] + a[2] * b[8] + a[3] * b[12]; - r[1] = a[0] * b[1] + a[1] * b[5] + a[2] * b[9] + a[3] * b[13]; - r[2] = a[0] * b[2] + a[1] * b[6] + a[2] * b[10] + a[3] * b[14]; - r[3] = a[0] * b[3] + a[1] * b[7] + a[2] * b[11] + a[3] * b[15]; - - r[4] = a[4] * b[0] + a[5] * b[4] + a[6] * b[8] + a[7] * b[12]; - r[5] = a[4] * b[1] + a[5] * b[5] + a[6] * b[9] + a[7] * b[13]; - r[6] = a[4] * b[2] + a[5] * b[6] + a[6] * b[10] + a[7] * b[14]; - r[7] = a[4] * b[3] + a[5] * b[7] + a[6] * b[11] + a[7] * b[15]; - - r[8] = a[8] * b[0] + a[9] * b[4] + a[10] * b[8] + a[11] * b[12]; - r[9] = a[8] * b[1] + a[9] * b[5] + a[10] * b[9] + a[11] * b[13]; - r[10] = a[8] * b[2] + a[9] * b[6] + a[10] * b[10] + a[11] * b[14]; - r[11] = a[8] * b[3] + a[9] * b[7] + a[10] * b[11] + a[11] * b[15]; - - r[12] = a[12] * b[0] + a[13] * b[4] + a[14] * b[8] + a[15] * b[12]; - r[13] = a[12] * b[1] + a[13] * b[5] + a[14] * b[9] + a[15] * b[13]; - r[14] = a[12] * b[2] + a[13] * b[6] + a[14] * b[10] + a[15] * b[14]; - r[15] = a[12] * b[3] + a[13] * b[7] + a[14] * b[11] + a[15] * b[15]; - } - - void Frustum(float left, float right, float bottom, float top, float znear, float zfar, float* m16, bool rightHanded = true) - { - float temp, temp2, temp3, temp4; - temp = 2.0f * znear; - temp2 = right - left; - temp3 = top - bottom; - temp4 = zfar - znear; - float sign = rightHanded ? -1.0f : 1.0f; - m16[0] = temp / temp2; - m16[1] = 0.0; - m16[2] = 0.0; - m16[3] = 0.0; - m16[4] = 0.0; - m16[5] = temp / temp3; - m16[6] = 0.0; - m16[7] = 0.0; - m16[8] = (right + left) / temp2; - m16[9] = (top + bottom) / temp3; - m16[10] = sign * (zfar + znear) / temp4; - m16[11] = sign; - m16[12] = 0.0; - m16[13] = 0.0; - m16[14] = (-temp * zfar) / temp4; - m16[15] = 0.0; - } - - void Perspective(float fovyInDegrees, float aspectRatio, float znear, float zfar, float* m16, bool rightHanded = true) - { - float ymax, xmax; - ymax = znear * tanf(fovyInDegrees * DEG2RAD); - xmax = ymax * aspectRatio; - Frustum(-xmax, xmax, -ymax, ymax, znear, zfar, m16, rightHanded); - } - - void Cross(const float* a, const float* b, float* r) - { - r[0] = a[1] * b[2] - a[2] * b[1]; - r[1] = a[2] * b[0] - a[0] * b[2]; - r[2] = a[0] * b[1] - a[1] * b[0]; - } - - float Dot(const float* a, const float* b) - { - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; - } - - void Normalize(const float* a, float* r) - { - float il = 1.f / (sqrtf(Dot(a, a)) + FLT_EPSILON); - r[0] = a[0] * il; - r[1] = a[1] * il; - r[2] = a[2] * il; - } - - void LookAt(const float* eye, const float* at, const float* up, float* m16, bool rightHanded = true) - { - float X[3], Y[3], Z[3], tmp[3]; - - if (rightHanded) - { - tmp[0] = eye[0] - at[0]; - tmp[1] = eye[1] - at[1]; - tmp[2] = eye[2] - at[2]; - } - else - { - tmp[0] = at[0] - eye[0]; - tmp[1] = at[1] - eye[1]; - tmp[2] = at[2] - eye[2]; - } - Normalize(tmp, Z); - Normalize(up, Y); - Cross(Y, Z, tmp); - Normalize(tmp, X); - Cross(Z, X, tmp); - Normalize(tmp, Y); - - m16[0] = X[0]; - m16[1] = Y[0]; - m16[2] = Z[0]; - m16[3] = 0.0f; - m16[4] = X[1]; - m16[5] = Y[1]; - m16[6] = Z[1]; - m16[7] = 0.0f; - m16[8] = X[2]; - m16[9] = Y[2]; - m16[10] = Z[2]; - m16[11] = 0.0f; - m16[12] = -Dot(X, eye); - m16[13] = -Dot(Y, eye); - m16[14] = -Dot(Z, eye); - m16[15] = 1.0f; - } - - template T Clamp(T x, T y, T z) { return ((x < y) ? y : ((x > z) ? z : x)); } - template T max(T x, T y) { return (x > y) ? x : y; } - template T min(T x, T y) { return (x < y) ? x : y; } - template bool IsWithin(T x, T y, T z) { return (x >= y) && (x <= z); } - - struct matrix_t; - struct vec_t - { - public: - float x, y, z, w; - - vec_t() = default; - vec_t(float _x, float _y, float _z, float _w = 0.f) : x(_x), y(_y), z(_z), w(_w) {} - - void Lerp(const vec_t& v, float t) - { - x += (v.x - x) * t; - y += (v.y - y) * t; - z += (v.z - z) * t; - w += (v.w - w) * t; - } - - void Set(float v) { x = y = z = w = v; } - void Set(float _x, float _y, float _z = 0.f, float _w = 0.f) { x = _x; y = _y; z = _z; w = _w; } - - vec_t& operator -= (const vec_t& v) { x -= v.x; y -= v.y; z -= v.z; w -= v.w; return *this; } - vec_t& operator += (const vec_t& v) { x += v.x; y += v.y; z += v.z; w += v.w; return *this; } - vec_t& operator *= (const vec_t& v) { x *= v.x; y *= v.y; z *= v.z; w *= v.w; return *this; } - vec_t& operator *= (float v) { x *= v; y *= v; z *= v; w *= v; return *this; } - - vec_t operator * (float f) const; - vec_t operator - () const; - vec_t operator - (const vec_t& v) const; - vec_t operator + (const vec_t& v) const; - vec_t operator * (const vec_t& v) const; - - const vec_t& operator + () const { return (*this); } - float Length() const { return sqrtf(x * x + y * y + z * z); }; - float LengthSq() const { return (x * x + y * y + z * z); }; - vec_t Normalize() { (*this) *= (1.f / ( Length() > FLT_EPSILON ? Length() : FLT_EPSILON ) ); return (*this); } - vec_t Normalize(const vec_t& v) { this->Set(v.x, v.y, v.z, v.w); this->Normalize(); return (*this); } - vec_t Abs() const; - - void Cross(const vec_t& v) - { - vec_t res; - res.x = y * v.z - z * v.y; - res.y = z * v.x - x * v.z; - res.z = x * v.y - y * v.x; - - x = res.x; - y = res.y; - z = res.z; - w = 0.f; - } - - void Cross(const vec_t& v1, const vec_t& v2) - { - x = v1.y * v2.z - v1.z * v2.y; - y = v1.z * v2.x - v1.x * v2.z; - z = v1.x * v2.y - v1.y * v2.x; - w = 0.f; - } - - float Dot(const vec_t& v) const - { - return (x * v.x) + (y * v.y) + (z * v.z) + (w * v.w); - } - - float Dot3(const vec_t& v) const - { - return (x * v.x) + (y * v.y) + (z * v.z); - } - - void Transform(const matrix_t& matrix); - void Transform(const vec_t& s, const matrix_t& matrix); - - void TransformVector(const matrix_t& matrix); - void TransformPoint(const matrix_t& matrix); - void TransformVector(const vec_t& v, const matrix_t& matrix) { (*this) = v; this->TransformVector(matrix); } - void TransformPoint(const vec_t& v, const matrix_t& matrix) { (*this) = v; this->TransformPoint(matrix); } - - float& operator [] (size_t index) { return ((float*)&x)[index]; } - const float& operator [] (size_t index) const { return ((float*)&x)[index]; } - bool operator!=(const vec_t& other) const { return memcmp(this, &other, sizeof(vec_t)) != 0; } - }; - - vec_t makeVect(float _x, float _y, float _z = 0.f, float _w = 0.f) { vec_t res; res.x = _x; res.y = _y; res.z = _z; res.w = _w; return res; } - vec_t makeVect(ImVec2 v) { vec_t res; res.x = v.x; res.y = v.y; res.z = 0.f; res.w = 0.f; return res; } - vec_t vec_t::operator * (float f) const { return makeVect(x * f, y * f, z * f, w * f); } - vec_t vec_t::operator - () const { return makeVect(-x, -y, -z, -w); } - vec_t vec_t::operator - (const vec_t& v) const { return makeVect(x - v.x, y - v.y, z - v.z, w - v.w); } - vec_t vec_t::operator + (const vec_t& v) const { return makeVect(x + v.x, y + v.y, z + v.z, w + v.w); } - vec_t vec_t::operator * (const vec_t& v) const { return makeVect(x * v.x, y * v.y, z * v.z, w * v.w); } - vec_t vec_t::Abs() const { return makeVect(fabsf(x), fabsf(y), fabsf(z)); } - - vec_t Normalized(const vec_t& v) { vec_t res; res = v; res.Normalize(); return res; } - vec_t Cross(const vec_t& v1, const vec_t& v2) - { - vec_t res; - res.x = v1.y * v2.z - v1.z * v2.y; - res.y = v1.z * v2.x - v1.x * v2.z; - res.z = v1.x * v2.y - v1.y * v2.x; - res.w = 0.f; - return res; - } - - float Dot(const vec_t& v1, const vec_t& v2) - { - return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z); - } - - vec_t BuildPlan(const vec_t& p_point1, const vec_t& p_normal) - { - vec_t normal, res; - normal.Normalize(p_normal); - res.w = normal.Dot(p_point1); - res.x = normal.x; - res.y = normal.y; - res.z = normal.z; - return res; - } - - struct matrix_t - { - public: - - union - { - float m[4][4]; - float m16[16]; - struct - { - vec_t right, up, dir, position; - } v; - vec_t component[4]; - }; - - operator float* () { return m16; } - operator const float* () const { return m16; } - void Translation(float _x, float _y, float _z) { this->Translation(makeVect(_x, _y, _z)); } - - void Translation(const vec_t& vt) - { - v.right.Set(1.f, 0.f, 0.f, 0.f); - v.up.Set(0.f, 1.f, 0.f, 0.f); - v.dir.Set(0.f, 0.f, 1.f, 0.f); - v.position.Set(vt.x, vt.y, vt.z, 1.f); - } - - void Scale(float _x, float _y, float _z) - { - v.right.Set(_x, 0.f, 0.f, 0.f); - v.up.Set(0.f, _y, 0.f, 0.f); - v.dir.Set(0.f, 0.f, _z, 0.f); - v.position.Set(0.f, 0.f, 0.f, 1.f); - } - void Scale(const vec_t& s) { Scale(s.x, s.y, s.z); } - - matrix_t& operator *= (const matrix_t& mat) - { - matrix_t tmpMat; - tmpMat = *this; - tmpMat.Multiply(mat); - *this = tmpMat; - return *this; - } - matrix_t operator * (const matrix_t& mat) const - { - matrix_t matT; - matT.Multiply(*this, mat); - return matT; - } - - void Multiply(const matrix_t& matrix) - { - matrix_t tmp; - tmp = *this; - - FPU_MatrixF_x_MatrixF((float*)&tmp, (float*)&matrix, (float*)this); - } - - void Multiply(const matrix_t& m1, const matrix_t& m2) - { - FPU_MatrixF_x_MatrixF((float*)&m1, (float*)&m2, (float*)this); - } - - float GetDeterminant() const - { - return m[0][0] * m[1][1] * m[2][2] + m[0][1] * m[1][2] * m[2][0] + m[0][2] * m[1][0] * m[2][1] - - m[0][2] * m[1][1] * m[2][0] - m[0][1] * m[1][0] * m[2][2] - m[0][0] * m[1][2] * m[2][1]; - } - - float Inverse(const matrix_t& srcMatrix, bool affine = false); - void SetToIdentity() - { - v.right.Set(1.f, 0.f, 0.f, 0.f); - v.up.Set(0.f, 1.f, 0.f, 0.f); - v.dir.Set(0.f, 0.f, 1.f, 0.f); - v.position.Set(0.f, 0.f, 0.f, 1.f); - } - void Transpose() - { - matrix_t tmpm; - for (int l = 0; l < 4; l++) - { - for (int c = 0; c < 4; c++) - { - tmpm.m[l][c] = m[c][l]; - } - } - (*this) = tmpm; - } - - void RotationAxis(const vec_t& axis, float angle); - - void OrthoNormalize() - { - v.right.Normalize(); - v.up.Normalize(); - v.dir.Normalize(); - } - }; - - void vec_t::Transform(const matrix_t& matrix) - { - vec_t out; - - out.x = x * matrix.m[0][0] + y * matrix.m[1][0] + z * matrix.m[2][0] + w * matrix.m[3][0]; - out.y = x * matrix.m[0][1] + y * matrix.m[1][1] + z * matrix.m[2][1] + w * matrix.m[3][1]; - out.z = x * matrix.m[0][2] + y * matrix.m[1][2] + z * matrix.m[2][2] + w * matrix.m[3][2]; - out.w = x * matrix.m[0][3] + y * matrix.m[1][3] + z * matrix.m[2][3] + w * matrix.m[3][3]; - - x = out.x; - y = out.y; - z = out.z; - w = out.w; - } - - void vec_t::Transform(const vec_t& s, const matrix_t& matrix) - { - *this = s; - Transform(matrix); - } - - void vec_t::TransformPoint(const matrix_t& matrix) - { - vec_t out; - - out.x = x * matrix.m[0][0] + y * matrix.m[1][0] + z * matrix.m[2][0] + matrix.m[3][0]; - out.y = x * matrix.m[0][1] + y * matrix.m[1][1] + z * matrix.m[2][1] + matrix.m[3][1]; - out.z = x * matrix.m[0][2] + y * matrix.m[1][2] + z * matrix.m[2][2] + matrix.m[3][2]; - out.w = x * matrix.m[0][3] + y * matrix.m[1][3] + z * matrix.m[2][3] + matrix.m[3][3]; - - x = out.x; - y = out.y; - z = out.z; - w = out.w; - } - - void vec_t::TransformVector(const matrix_t& matrix) - { - vec_t out; - - out.x = x * matrix.m[0][0] + y * matrix.m[1][0] + z * matrix.m[2][0]; - out.y = x * matrix.m[0][1] + y * matrix.m[1][1] + z * matrix.m[2][1]; - out.z = x * matrix.m[0][2] + y * matrix.m[1][2] + z * matrix.m[2][2]; - out.w = x * matrix.m[0][3] + y * matrix.m[1][3] + z * matrix.m[2][3]; - - x = out.x; - y = out.y; - z = out.z; - w = out.w; - } - - float matrix_t::Inverse(const matrix_t& srcMatrix, bool affine) - { - float det = 0; - - if (affine) - { - det = GetDeterminant(); - float s = 1 / det; - m[0][0] = (srcMatrix.m[1][1] * srcMatrix.m[2][2] - srcMatrix.m[1][2] * srcMatrix.m[2][1]) * s; - m[0][1] = (srcMatrix.m[2][1] * srcMatrix.m[0][2] - srcMatrix.m[2][2] * srcMatrix.m[0][1]) * s; - m[0][2] = (srcMatrix.m[0][1] * srcMatrix.m[1][2] - srcMatrix.m[0][2] * srcMatrix.m[1][1]) * s; - m[1][0] = (srcMatrix.m[1][2] * srcMatrix.m[2][0] - srcMatrix.m[1][0] * srcMatrix.m[2][2]) * s; - m[1][1] = (srcMatrix.m[2][2] * srcMatrix.m[0][0] - srcMatrix.m[2][0] * srcMatrix.m[0][2]) * s; - m[1][2] = (srcMatrix.m[0][2] * srcMatrix.m[1][0] - srcMatrix.m[0][0] * srcMatrix.m[1][2]) * s; - m[2][0] = (srcMatrix.m[1][0] * srcMatrix.m[2][1] - srcMatrix.m[1][1] * srcMatrix.m[2][0]) * s; - m[2][1] = (srcMatrix.m[2][0] * srcMatrix.m[0][1] - srcMatrix.m[2][1] * srcMatrix.m[0][0]) * s; - m[2][2] = (srcMatrix.m[0][0] * srcMatrix.m[1][1] - srcMatrix.m[0][1] * srcMatrix.m[1][0]) * s; - m[3][0] = -(m[0][0] * srcMatrix.m[3][0] + m[1][0] * srcMatrix.m[3][1] + m[2][0] * srcMatrix.m[3][2]); - m[3][1] = -(m[0][1] * srcMatrix.m[3][0] + m[1][1] * srcMatrix.m[3][1] + m[2][1] * srcMatrix.m[3][2]); - m[3][2] = -(m[0][2] * srcMatrix.m[3][0] + m[1][2] * srcMatrix.m[3][1] + m[2][2] * srcMatrix.m[3][2]); - } - else - { - // transpose matrix - float src[16]; - for (int i = 0; i < 4; ++i) - { - src[i] = srcMatrix.m16[i * 4]; - src[i + 4] = srcMatrix.m16[i * 4 + 1]; - src[i + 8] = srcMatrix.m16[i * 4 + 2]; - src[i + 12] = srcMatrix.m16[i * 4 + 3]; - } - - // calculate pairs for first 8 elements (cofactors) - float tmp[12]; // temp array for pairs - tmp[0] = src[10] * src[15]; - tmp[1] = src[11] * src[14]; - tmp[2] = src[9] * src[15]; - tmp[3] = src[11] * src[13]; - tmp[4] = src[9] * src[14]; - tmp[5] = src[10] * src[13]; - tmp[6] = src[8] * src[15]; - tmp[7] = src[11] * src[12]; - tmp[8] = src[8] * src[14]; - tmp[9] = src[10] * src[12]; - tmp[10] = src[8] * src[13]; - tmp[11] = src[9] * src[12]; - - // calculate first 8 elements (cofactors) - m16[0] = (tmp[0] * src[5] + tmp[3] * src[6] + tmp[4] * src[7]) - (tmp[1] * src[5] + tmp[2] * src[6] + tmp[5] * src[7]); - m16[1] = (tmp[1] * src[4] + tmp[6] * src[6] + tmp[9] * src[7]) - (tmp[0] * src[4] + tmp[7] * src[6] + tmp[8] * src[7]); - m16[2] = (tmp[2] * src[4] + tmp[7] * src[5] + tmp[10] * src[7]) - (tmp[3] * src[4] + tmp[6] * src[5] + tmp[11] * src[7]); - m16[3] = (tmp[5] * src[4] + tmp[8] * src[5] + tmp[11] * src[6]) - (tmp[4] * src[4] + tmp[9] * src[5] + tmp[10] * src[6]); - m16[4] = (tmp[1] * src[1] + tmp[2] * src[2] + tmp[5] * src[3]) - (tmp[0] * src[1] + tmp[3] * src[2] + tmp[4] * src[3]); - m16[5] = (tmp[0] * src[0] + tmp[7] * src[2] + tmp[8] * src[3]) - (tmp[1] * src[0] + tmp[6] * src[2] + tmp[9] * src[3]); - m16[6] = (tmp[3] * src[0] + tmp[6] * src[1] + tmp[11] * src[3]) - (tmp[2] * src[0] + tmp[7] * src[1] + tmp[10] * src[3]); - m16[7] = (tmp[4] * src[0] + tmp[9] * src[1] + tmp[10] * src[2]) - (tmp[5] * src[0] + tmp[8] * src[1] + tmp[11] * src[2]); - - // calculate pairs for second 8 elements (cofactors) - tmp[0] = src[2] * src[7]; - tmp[1] = src[3] * src[6]; - tmp[2] = src[1] * src[7]; - tmp[3] = src[3] * src[5]; - tmp[4] = src[1] * src[6]; - tmp[5] = src[2] * src[5]; - tmp[6] = src[0] * src[7]; - tmp[7] = src[3] * src[4]; - tmp[8] = src[0] * src[6]; - tmp[9] = src[2] * src[4]; - tmp[10] = src[0] * src[5]; - tmp[11] = src[1] * src[4]; - - // calculate second 8 elements (cofactors) - m16[8] = (tmp[0] * src[13] + tmp[3] * src[14] + tmp[4] * src[15]) - (tmp[1] * src[13] + tmp[2] * src[14] + tmp[5] * src[15]); - m16[9] = (tmp[1] * src[12] + tmp[6] * src[14] + tmp[9] * src[15]) - (tmp[0] * src[12] + tmp[7] * src[14] + tmp[8] * src[15]); - m16[10] = (tmp[2] * src[12] + tmp[7] * src[13] + tmp[10] * src[15]) - (tmp[3] * src[12] + tmp[6] * src[13] + tmp[11] * src[15]); - m16[11] = (tmp[5] * src[12] + tmp[8] * src[13] + tmp[11] * src[14]) - (tmp[4] * src[12] + tmp[9] * src[13] + tmp[10] * src[14]); - m16[12] = (tmp[2] * src[10] + tmp[5] * src[11] + tmp[1] * src[9]) - (tmp[4] * src[11] + tmp[0] * src[9] + tmp[3] * src[10]); - m16[13] = (tmp[8] * src[11] + tmp[0] * src[8] + tmp[7] * src[10]) - (tmp[6] * src[10] + tmp[9] * src[11] + tmp[1] * src[8]); - m16[14] = (tmp[6] * src[9] + tmp[11] * src[11] + tmp[3] * src[8]) - (tmp[10] * src[11] + tmp[2] * src[8] + tmp[7] * src[9]); - m16[15] = (tmp[10] * src[10] + tmp[4] * src[8] + tmp[9] * src[9]) - (tmp[8] * src[9] + tmp[11] * src[10] + tmp[5] * src[8]); - - // calculate determinant - det = src[0] * m16[0] + src[1] * m16[1] + src[2] * m16[2] + src[3] * m16[3]; - - // calculate matrix inverse - float invdet = 1 / det; - for (int j = 0; j < 16; ++j) - { - m16[j] *= invdet; - } - } - - return det; - } - - void matrix_t::RotationAxis(const vec_t& axis, float angle) - { - float length2 = axis.LengthSq(); - if (length2 < FLT_EPSILON) - { - SetToIdentity(); - return; - } - - vec_t n = axis * (1.f / sqrtf(length2)); - float s = sinf(angle); - float c = cosf(angle); - float k = 1.f - c; - - float xx = n.x * n.x * k + c; - float yy = n.y * n.y * k + c; - float zz = n.z * n.z * k + c; - float xy = n.x * n.y * k; - float yz = n.y * n.z * k; - float zx = n.z * n.x * k; - float xs = n.x * s; - float ys = n.y * s; - float zs = n.z * s; - - m[0][0] = xx; - m[0][1] = xy + zs; - m[0][2] = zx - ys; - m[0][3] = 0.f; - m[1][0] = xy - zs; - m[1][1] = yy; - m[1][2] = yz + xs; - m[1][3] = 0.f; - m[2][0] = zx + ys; - m[2][1] = yz - xs; - m[2][2] = zz; - m[2][3] = 0.f; - m[3][0] = 0.f; - m[3][1] = 0.f; - m[3][2] = 0.f; - m[3][3] = 1.f; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - - static bool IsTranslateType(MOVETYPE type) - { - return type >= MT_MOVE_X && type <= MT_MOVE_SCREEN; - } - - static bool IsRotateType(MOVETYPE type) - { - return type >= MT_ROTATE_X && type <= MT_ROTATE_SCREEN; - } - - static bool IsScaleType(MOVETYPE type) - { - return type >= MT_SCALE_X && type <= MT_SCALE_XYZ; - } - - // Matches MT_MOVE_AB order - static const OPERATION TRANSLATE_PLANS[3] = { TRANSLATE_Y | TRANSLATE_Z, TRANSLATE_X | TRANSLATE_Z, TRANSLATE_X | TRANSLATE_Y }; - - Style::Style() - { - // default values - TranslationLineThickness = 3.0f; - TranslationLineArrowSize = 6.0f; - RotationLineThickness = 2.0f; - RotationOuterLineThickness = 3.0f; - ScaleLineThickness = 3.0f; - ScaleLineCircleSize = 6.0f; - HatchedAxisLineThickness = 6.0f; - CenterCircleSize = 6.0f; - - // initialize default colors - Colors[DIRECTION_X] = ImVec4(0.666f, 0.000f, 0.000f, 1.000f); - Colors[DIRECTION_Y] = ImVec4(0.000f, 0.666f, 0.000f, 1.000f); - Colors[DIRECTION_Z] = ImVec4(0.000f, 0.000f, 0.666f, 1.000f); - Colors[PLANE_X] = ImVec4(0.666f, 0.000f, 0.000f, 0.380f); - Colors[PLANE_Y] = ImVec4(0.000f, 0.666f, 0.000f, 0.380f); - Colors[PLANE_Z] = ImVec4(0.000f, 0.000f, 0.666f, 0.380f); - Colors[SELECTION] = ImVec4(1.000f, 0.500f, 0.062f, 0.541f); - Colors[INACTIVE] = ImVec4(0.600f, 0.600f, 0.600f, 0.600f); - Colors[TRANSLATION_LINE] = ImVec4(0.666f, 0.666f, 0.666f, 0.666f); - Colors[SCALE_LINE] = ImVec4(0.250f, 0.250f, 0.250f, 1.000f); - Colors[ROTATION_USING_BORDER] = ImVec4(1.000f, 0.500f, 0.062f, 1.000f); - Colors[ROTATION_USING_FILL] = ImVec4(1.000f, 0.500f, 0.062f, 0.500f); - Colors[HATCHED_AXIS_LINES] = ImVec4(0.000f, 0.000f, 0.000f, 0.500f); - Colors[TEXT] = ImVec4(1.000f, 1.000f, 1.000f, 1.000f); - Colors[TEXT_SHADOW] = ImVec4(0.000f, 0.000f, 0.000f, 1.000f); - } - - // Per-id state of a ViewManipulate widget, so several view cubes (one per viewport) - // can be manipulated independently through the PushID/PopID mechanism. - struct ViewManipulateState - { - ImGuiID mID = (ImGuiID)-1; - bool mIsDragging = false; - bool mIsClicking = false; - int mInterpolationFrames = 0; - vec_t mInterpolationUp; - vec_t mInterpolationDir; - }; - - struct TripodState - { - bool mBelowAxisLimit[3] = {}; - bool mBelowPlaneLimit[3] = {}; - float mAxisFactor[3] = { 1.f, 1.f, 1.f }; - }; - - struct Context - { - Context() : mbUsing(false), mbUsingViewManipulate(false), mbEnable(true), mIsViewManipulatorHovered(false), mbUsingBounds(false) - { - } - - ImDrawList* mDrawList; - Style mStyle; - - MODE mMode; - matrix_t mViewMat; - matrix_t mProjectionMat; - matrix_t mModel; - matrix_t mModelLocal; // orthonormalized model - matrix_t mModelInverse; - matrix_t mModelSource; - matrix_t mModelSourceInverse; - matrix_t mMVP; - matrix_t mMVPLocal; // MVP with full model matrix whereas mMVP's model matrix might only be translation in case of World space edition - matrix_t mViewProjection; - - vec_t mModelScaleOrigin; - vec_t mCameraEye; - vec_t mCameraRight; - vec_t mCameraDir; - vec_t mCameraUp; - vec_t mRayOrigin; - vec_t mRayVector; - - float mRadiusSquareCenter; - ImVec2 mScreenSquareCenter; - ImVec2 mScreenSquareMin; - ImVec2 mScreenSquareMax; - - float mScreenFactor; - vec_t mRelativeOrigin; - - bool mbUsing; - bool mbUsingViewManipulate; - bool mbEnable; - bool mbMouseOver; - bool mIsViewManipulatorHovered; - - // translation - vec_t mTranslationPlan; - vec_t mTranslationPlanOrigin; - vec_t mMatrixOrigin; - vec_t mTranslationLastDelta; - - // rotation - vec_t mRotationVectorSource; - float mRotationAngle; - float mRotationAngleOrigin; - //vec_t mWorldToLocalAxis; - - // scale - vec_t mScale; - vec_t mScaleValueOrigin; - vec_t mScaleLast; - float mSaveMousePosx; - - int mAxisMask = 0; - // Current camera-dependent state and the frozen state of the active drag. - TripodState mTripodState; - TripodState mActiveTripodState; - - float mAxisLimit=0.0025f; - float mPlaneLimit=0.02f; - - // bounds stretching - vec_t mBoundsPivot; - vec_t mBoundsAnchor; - vec_t mBoundsPlan; - vec_t mBoundsLocalPivot; - int mBoundsBestAxis; - int mBoundsAxis[2]; - bool mbUsingBounds; - matrix_t mBoundsMatrix; - - // - MOVETYPE mCurrentHandleType = MT_NONE; - MOVETYPE mHoveredHandleType = MT_NONE; - - float mX = 0.f; - float mY = 0.f; - float mWidth = 0.f; - float mHeight = 0.f; - float mXMax = 0.f; - float mYMax = 0.f; - float mDisplayRatio = 1.f; - - bool mIsOrthographic = false; - // check to not have multiple gizmo highlighted at the same time - bool mbOverGizmoHotspot = false; - // snapshot of mbOverGizmoHotspot from the previous complete frame, so IsOver() - // reports hovering over any gizmo regardless of when it is called - bool mbOverGizmoHotspotLastFrame = false; - - ImGuiWindow* mAlternativeWindow = nullptr; - ImVector mIDStack; - ImGuiID mEditingID = -1; - OPERATION mOperation = OPERATION(0); - - // per-id ViewManipulate widget states (see ViewManipulateState) - ImVector mViewManipulateStates; - - bool mAllowAxisFlip = true; - float mGizmoSizeClipSpace = 0.1f; - - inline ImGuiID GetCurrentID() - { - if (mIDStack.empty()) - { - mIDStack.push_back(-1); - } - return mIDStack.back(); - } - - inline TripodState& GetTripodState() - { - return mbUsing && GetCurrentID() == mEditingID ? mActiveTripodState : mTripodState; - } - - // Retrieve (creating if needed) the ViewManipulate state bound to the current id. - inline ViewManipulateState& GetViewManipulateState() - { - const ImGuiID id = GetCurrentID(); - for (int i = 0; i < mViewManipulateStates.Size; i++) - { - if (mViewManipulateStates[i].mID == id) - { - return mViewManipulateStates[i]; - } - } - ViewManipulateState state; - state.mID = id; - mViewManipulateStates.push_back(state); - return mViewManipulateStates.back(); - } - }; - - static Context gContext; - - static const vec_t directionUnary[3] = { makeVect(1.f, 0.f, 0.f), makeVect(0.f, 1.f, 0.f), makeVect(0.f, 0.f, 1.f) }; - static const char* translationInfoMask[] = { "X : %5.3f", "Y : %5.3f", "Z : %5.3f", - "Y : %5.3f Z : %5.3f", "X : %5.3f Z : %5.3f", "X : %5.3f Y : %5.3f", - "X : %5.3f Y : %5.3f Z : %5.3f" }; - static const char* scaleInfoMask[] = { "X : %5.2f", "Y : %5.2f", "Z : %5.2f", "XYZ : %5.2f" }; - static const char* rotationInfoMask[] = { "X : %5.2f deg %5.2f rad", "Y : %5.2f deg %5.2f rad", "Z : %5.2f deg %5.2f rad", "Screen : %5.2f deg %5.2f rad" }; - static const int translationInfoIndex[] = { 0,0,0, 1,0,0, 2,0,0, 1,2,0, 0,2,0, 0,1,0, 0,1,2 }; - static const float quadMin = 0.5f; - static const float quadMax = 0.8f; - static const float quadUV[8] = { quadMin, quadMin, quadMin, quadMax, quadMax, quadMax, quadMax, quadMin }; - static const int halfCircleSegmentCount = 64; - static const float snapTension = 0.5f; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - static MOVETYPE GetMoveType(OPERATION op, vec_t* gizmoHitProportion); - static MOVETYPE GetRotateType(OPERATION op); - static MOVETYPE GetScaleType(OPERATION op); - - Style& GetStyle() - { - return gContext.mStyle; - } - - static ImU32 GetColorU32(int idx) - { - IM_ASSERT(idx < COLOR::COUNT); - return ImGui::ColorConvertFloat4ToU32(gContext.mStyle.Colors[idx]); - } - - static ImVec2 worldToPos(const vec_t& worldPos, const matrix_t& mat, ImVec2 position = ImVec2(gContext.mX, gContext.mY), ImVec2 size = ImVec2(gContext.mWidth, gContext.mHeight)) - { - vec_t trans; - trans.TransformPoint(worldPos, mat); - if (fabsf(trans.w) < FLT_EPSILON) - return ImVec2(-FLT_MAX, -FLT_MAX); - trans *= 0.5f / trans.w; - trans += makeVect(0.5f, 0.5f); - trans.y = 1.f - trans.y; - trans.x *= size.x; - trans.y *= size.y; - trans.x += position.x; - trans.y += position.y; - return ImVec2(trans.x, trans.y); - } - - static void ComputeCameraRay(vec_t& rayOrigin, vec_t& rayDir, const matrix_t& viewMatrix, const matrix_t& projectionMatrix, const ImVec2& mousePosition, ImVec2 position, ImVec2 size) - { - matrix_t mViewProjInverse; - mViewProjInverse.Inverse(viewMatrix * projectionMatrix); - - const float mox = ((mousePosition.x - position.x) / size.x) * 2.f - 1.f; - const float moy = (1.f - ((mousePosition.y - position.y) / size.y)) * 2.f - 1.f; - - // Unproject the mouse at both depth extremes of the clip volume. - // A near-zero w means the extreme lies at infinity (an infinite far plane): keep the - // homogeneous coordinates in that case instead of dividing by ~0. - vec_t hA, hB; - hA.Transform(makeVect(mox, moy, 0.f, 1.f), mViewProjInverse); - hB.Transform(makeVect(mox, moy, 1.f - FLT_EPSILON, 1.f), mViewProjInverse); - const bool aAtInfinity = fabsf(hA.w) < FLT_EPSILON; - const bool bAtInfinity = fabsf(hB.w) < FLT_EPSILON; - const vec_t pointA = aAtInfinity ? hA : hA * (1.f / hA.w); - const vec_t pointB = bAtInfinity ? hB : hB * (1.f / hB.w); - - // Camera position. Derived from the view matrix so it is also correct when this is - // called for the ViewManipulate cube (which swaps the view/projection matrices). - matrix_t viewInverse; - viewInverse.Inverse(viewMatrix); - const vec_t eye = viewInverse.v.position; - - // Use the unprojected extreme closest to the camera as the ray origin. This is always - // the near plane: finite and close to the geometry, regardless of whether the - // projection uses a reversed and/or (near-)infinite depth range. Picking the far - // extreme instead (as a mis-detected "reversed" flag could) puts the origin thousands - // of units away and makes 'rayOrigin + rayDir * len' a catastrophic float cancellation, - // which is the jitter reported in issue #423. - vec_t nearPoint, farPoint; - bool farAtInfinity; - if ((pointA - eye).LengthSq() <= (pointB - eye).LengthSq()) - { - nearPoint = pointA; farPoint = pointB; farAtInfinity = bAtInfinity; - } - else - { - nearPoint = pointB; farPoint = pointA; farAtInfinity = aAtInfinity; - } - - rayOrigin = nearPoint; - // With an infinite far plane the far extreme is unusable, so take the direction from - // the camera through the near point (equivalent, and always finite for perspective). - rayDir = farAtInfinity ? Normalized(nearPoint - eye) : Normalized(farPoint - nearPoint); - } - - static void ComputeCameraRay(vec_t& rayOrigin, vec_t& rayDir, ImVec2 position = ImVec2(gContext.mX, gContext.mY), ImVec2 size = ImVec2(gContext.mWidth, gContext.mHeight)) - { - ImGuiIO& io = ImGui::GetIO(); - ComputeCameraRay(rayOrigin, rayDir, gContext.mViewMat, gContext.mProjectionMat, io.MousePos, position, size); - } - - void ComputeMouseRay(const float* view, const float* projection, const ImVec2& mousePosition, const ImVec2& rectPosition, const ImVec2& rectSize, float* rayOrigin, float* rayDirection) - { - vec_t origin, dir; - ComputeCameraRay(origin, dir, *(const matrix_t*)view, *(const matrix_t*)projection, mousePosition, rectPosition, rectSize); - rayOrigin[0] = origin.x; rayOrigin[1] = origin.y; rayOrigin[2] = origin.z; - rayDirection[0] = dir.x; rayDirection[1] = dir.y; rayDirection[2] = dir.z; - } - - static float GetSegmentLengthClipSpace(const vec_t& start, const vec_t& end, const bool localCoordinates = false) - { - vec_t startOfSegment = start; - const matrix_t& mvp = localCoordinates ? gContext.mMVPLocal : gContext.mMVP; - startOfSegment.TransformPoint(mvp); - if (fabsf(startOfSegment.w) > FLT_EPSILON) // check for axis aligned with camera direction - { - startOfSegment *= 1.f / startOfSegment.w; - } - - vec_t endOfSegment = end; - endOfSegment.TransformPoint(mvp); - if (fabsf(endOfSegment.w) > FLT_EPSILON) // check for axis aligned with camera direction - { - endOfSegment *= 1.f / endOfSegment.w; - } - - vec_t clipSpaceAxis = endOfSegment - startOfSegment; - if (gContext.mDisplayRatio < 1.0) - clipSpaceAxis.x *= gContext.mDisplayRatio; - else - clipSpaceAxis.y /= gContext.mDisplayRatio; - float segmentLengthInClipSpace = sqrtf(clipSpaceAxis.x * clipSpaceAxis.x + clipSpaceAxis.y * clipSpaceAxis.y); - return segmentLengthInClipSpace; - } - - static float GetParallelogram(const vec_t& ptO, const vec_t& ptA, const vec_t& ptB) - { - vec_t pts[] = { ptO, ptA, ptB }; - for (unsigned int i = 0; i < 3; i++) - { - pts[i].TransformPoint(gContext.mMVP); - if (fabsf(pts[i].w) > FLT_EPSILON) // check for axis aligned with camera direction - { - pts[i] *= 1.f / pts[i].w; - } - } - vec_t segA = pts[1] - pts[0]; - vec_t segB = pts[2] - pts[0]; - segA.y /= gContext.mDisplayRatio; - segB.y /= gContext.mDisplayRatio; - vec_t segAOrtho = makeVect(-segA.y, segA.x); - segAOrtho.Normalize(); - float dt = segAOrtho.Dot3(segB); - float surface = sqrtf(segA.x * segA.x + segA.y * segA.y) * fabsf(dt); - return surface; - } - - inline vec_t PointOnSegment(const vec_t& point, const vec_t& vertPos1, const vec_t& vertPos2) - { - vec_t c = point - vertPos1; - vec_t V; - - V.Normalize(vertPos2 - vertPos1); - float d = (vertPos2 - vertPos1).Length(); - float t = V.Dot3(c); - - if (t < 0.f) - { - return vertPos1; - } - - if (t > d) - { - return vertPos2; - } - - return vertPos1 + V * t; - } - - static float IntersectRayPlane(const vec_t& rOrigin, const vec_t& rVector, const vec_t& plan) - { - const float numer = plan.Dot3(rOrigin) - plan.w; - const float denom = plan.Dot3(rVector); - - if (fabsf(denom) < FLT_EPSILON) // normal is orthogonal to vector, cant intersect - { - return -1.0f; - } - - return -(numer / denom); - } - - static float DistanceToPlane(const vec_t& point, const vec_t& plan) - { - return plan.Dot3(point) + plan.w; - } - - static bool IsInContextRect(ImVec2 p) - { - return IsWithin(p.x, gContext.mX, gContext.mXMax) && IsWithin(p.y, gContext.mY, gContext.mYMax); - } - - static bool IsHoveringWindow() - { - ImGuiContext& g = *ImGui::GetCurrentContext(); - ImGuiWindow* window = ImGui::FindWindowByName(gContext.mDrawList->_OwnerName); - if (g.HoveredWindow == window) // Mouse hovering drawlist window - return true; - if (gContext.mAlternativeWindow != nullptr && g.HoveredWindow == gContext.mAlternativeWindow) - return true; - if (g.HoveredWindow != NULL) // Any other window is hovered - return false; - if (ImGui::IsMouseHoveringRect(window->InnerRect.Min, window->InnerRect.Max, false)) // Hovering drawlist window rect, while no other window is hovered (for _NoInputs windows) - return true; - return false; - } - - void SetRect(float x, float y, float width, float height) - { - gContext.mX = x; - gContext.mY = y; - gContext.mWidth = width; - gContext.mHeight = height; - gContext.mXMax = gContext.mX + gContext.mWidth; - gContext.mYMax = gContext.mY + gContext.mHeight; - gContext.mDisplayRatio = width / height; - } - - void SetOrthographic(bool isOrthographic) - { - gContext.mIsOrthographic = isOrthographic; - } - - void SetDrawlist(ImDrawList* drawlist) - { - gContext.mDrawList = drawlist ? drawlist : ImGui::GetWindowDrawList(); - } - - void SetImGuiContext(ImGuiContext* ctx) - { - ImGui::SetCurrentContext(ctx); - } - - void BeginFrame() - { - const ImU32 flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoBringToFrontOnFocus; - -#ifdef IMGUI_HAS_VIEWPORT - ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size); - ImGui::SetNextWindowPos(ImGui::GetMainViewport()->Pos); -#else - ImGuiIO& io = ImGui::GetIO(); - ImGui::SetNextWindowSize(io.DisplaySize); - ImGui::SetNextWindowPos(ImVec2(0, 0)); -#endif - - ImGui::PushStyleColor(ImGuiCol_WindowBg, 0); - ImGui::PushStyleColor(ImGuiCol_Border, 0); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - - ImGui::Begin("gizmo", NULL, flags); - gContext.mDrawList = ImGui::GetWindowDrawList(); - gContext.mbOverGizmoHotspotLastFrame = gContext.mbOverGizmoHotspot; - gContext.mbOverGizmoHotspot = false; - // view manipulate flags accumulate across every ViewManipulate call of the frame - gContext.mbUsingViewManipulate = false; - gContext.mIsViewManipulatorHovered = false; - ImGui::End(); - ImGui::PopStyleVar(); - ImGui::PopStyleColor(2); - } - - bool IsUsing() - { - return (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) || gContext.mbUsingBounds; - } - - bool IsUsingViewManipulate() - { - return gContext.mbUsingViewManipulate; - } - - bool IsViewManipulateHovered() - { - return gContext.mIsViewManipulatorHovered; - } - - bool IsUsingAny() - { - return gContext.mbUsing || gContext.mbUsingBounds; - } - - bool IsOver() - { - // mbOverGizmoHotspotLastFrame is accumulated across every Manipulate call of the - // previous frame, so this reports hovering over any gizmo instead of only the last one. - // IsUsingAny() (not IsUsing()) is used so an active drag is detected even when IsOver() - // is queried outside the PushID scope of the gizmo being manipulated. - return gContext.mbOverGizmoHotspotLastFrame || IsUsingAny(); - } - - bool IsOver(OPERATION op) - { - if(IsUsing()) - { - return true; - } - if(Intersects(op, SCALE | SCALEU) && GetScaleType(op) != MT_NONE) - { - return true; - } - if(Intersects(op, ROTATE) && GetRotateType(op) != MT_NONE) - { - return true; - } - if(Intersects(op, TRANSLATE) && GetMoveType(op, NULL) != MT_NONE) - { - return true; - } - return false; - } - - MOVETYPE GetActiveHandleType() - { - if (!gContext.mbUsing || gContext.GetCurrentID() != gContext.mEditingID) - { - return MT_NONE; - } - return gContext.mCurrentHandleType; - } - - MOVETYPE GetHoveredHandleType() - { - return gContext.mHoveredHandleType; - } - - MOVETYPE GetActiveMoveType() - { - return GetActiveHandleType(); - } - - MOVETYPE GetHoveredMoveType() - { - return GetHoveredHandleType(); - } - - void Enable(bool enable) - { - gContext.mbEnable = enable; - if (!enable) - { - // Only cancel an ongoing interaction when the gizmo being disabled is the one - // currently edited. Otherwise disabling one gizmo would wipe the shared using - // state and break another gizmo that is still enabled/being manipulated. - if (!gContext.mbUsing || gContext.GetCurrentID() == gContext.mEditingID) - { - gContext.mbUsing = false; - gContext.mbUsingBounds = false; - gContext.mCurrentHandleType = MT_NONE; - gContext.mHoveredHandleType = MT_NONE; - } - } - } - - static void ComputeContext(const float* view, const float* projection, float* matrix, MODE mode) - { - gContext.mMode = mode; - gContext.mViewMat = *(matrix_t*)view; - gContext.mProjectionMat = *(matrix_t*)projection; - gContext.mbMouseOver = IsHoveringWindow(); - - gContext.mModelLocal = *(matrix_t*)matrix; - gContext.mModelLocal.OrthoNormalize(); - - if (mode == LOCAL) - { - gContext.mModel = gContext.mModelLocal; - } - else - { - gContext.mModel.Translation(((matrix_t*)matrix)->v.position); - } - gContext.mModelSource = *(matrix_t*)matrix; - gContext.mModelScaleOrigin.Set(gContext.mModelSource.v.right.Length(), gContext.mModelSource.v.up.Length(), gContext.mModelSource.v.dir.Length()); - - gContext.mModelInverse.Inverse(gContext.mModel); - gContext.mModelSourceInverse.Inverse(gContext.mModelSource); - gContext.mViewProjection = gContext.mViewMat * gContext.mProjectionMat; - gContext.mMVP = gContext.mModel * gContext.mViewProjection; - gContext.mMVPLocal = gContext.mModelLocal * gContext.mViewProjection; - - matrix_t viewInverse; - viewInverse.Inverse(gContext.mViewMat); - gContext.mCameraDir = viewInverse.v.dir; - gContext.mCameraEye = viewInverse.v.position; - gContext.mCameraRight = viewInverse.v.right; - gContext.mCameraUp = viewInverse.v.up; - - // compute scale from the size of camera right vector projected on screen at the matrix position - vec_t pointRight = viewInverse.v.right; - pointRight.TransformPoint(gContext.mViewProjection); - - vec_t rightViewInverse = viewInverse.v.right; - rightViewInverse.TransformVector(gContext.mModelInverse); - float rightLength = GetSegmentLengthClipSpace(makeVect(0.f, 0.f), rightViewInverse); - gContext.mScreenFactor = gContext.mGizmoSizeClipSpace / rightLength; - - ImVec2 centerSSpace = worldToPos(makeVect(0.f, 0.f), gContext.mMVP); - gContext.mScreenSquareCenter = centerSSpace; - gContext.mScreenSquareMin = ImVec2(centerSSpace.x - 10.f, centerSSpace.y - 10.f); - gContext.mScreenSquareMax = ImVec2(centerSSpace.x + 10.f, centerSSpace.y + 10.f); - - ComputeCameraRay(gContext.mRayOrigin, gContext.mRayVector); - } - - static void ComputeColors(ImU32* colors, int type, OPERATION operation) - { - if (gContext.mbEnable) - { - ImU32 selectionColor = GetColorU32(SELECTION); - - switch (operation) - { - case TRANSLATE: - colors[0] = (type == MT_MOVE_SCREEN) ? selectionColor : IM_COL32_WHITE; - for (int i = 0; i < 3; i++) - { - colors[i + 1] = (type == (int)(MT_MOVE_X + i)) ? selectionColor : GetColorU32(DIRECTION_X + i); - colors[i + 4] = (type == (int)(MT_MOVE_YZ + i)) ? selectionColor : GetColorU32(PLANE_X + i); - colors[i + 4] = (type == MT_MOVE_SCREEN) ? selectionColor : colors[i + 4]; - } - break; - case ROTATE: - colors[0] = (type == MT_ROTATE_SCREEN) ? selectionColor : IM_COL32_WHITE; - for (int i = 0; i < 3; i++) - { - colors[i + 1] = (type == (int)(MT_ROTATE_X + i)) ? selectionColor : GetColorU32(DIRECTION_X + i); - } - break; - case SCALEU: - case SCALE: - colors[0] = (type == MT_SCALE_XYZ) ? selectionColor : IM_COL32_WHITE; - for (int i = 0; i < 3; i++) - { - colors[i + 1] = (type == (int)(MT_SCALE_X + i)) ? selectionColor : GetColorU32(DIRECTION_X + i); - } - break; - // note: this internal function is only called with three possible values for operation - default: - break; - } - } - else - { - ImU32 inactiveColor = GetColorU32(INACTIVE); - for (int i = 0; i < 7; i++) - { - colors[i] = inactiveColor; - } - } - } - - static void ComputeTripodAxisAndVisibility(const int axisIndex, vec_t& dirAxis, vec_t& dirPlaneX, vec_t& dirPlaneY, bool& belowAxisLimit, bool& belowPlaneLimit, const bool localCoordinates = false) - { - dirAxis = directionUnary[axisIndex]; - dirPlaneX = directionUnary[(axisIndex + 1) % 3]; - dirPlaneY = directionUnary[(axisIndex + 2) % 3]; - TripodState& tripodState = gContext.GetTripodState(); - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) - { - // when using, use stored factors so the gizmo doesn't flip when we translate - - // Apply axis mask to axes and planes - belowAxisLimit = tripodState.mBelowAxisLimit[axisIndex] && !((1< FLT_EPSILON) ? -1.f : 1.f; - float mulAxisX = (allowFlip && lenDirPlaneX < lenDirMinusPlaneX&& fabsf(lenDirPlaneX - lenDirMinusPlaneX) > FLT_EPSILON) ? -1.f : 1.f; - float mulAxisY = (allowFlip && lenDirPlaneY < lenDirMinusPlaneY&& fabsf(lenDirPlaneY - lenDirMinusPlaneY) > FLT_EPSILON) ? -1.f : 1.f; - dirAxis *= mulAxis; - dirPlaneX *= mulAxisX; - dirPlaneY *= mulAxisY; - - // for axis - float axisLengthInClipSpace = GetSegmentLengthClipSpace(makeVect(0.f, 0.f, 0.f), dirAxis * gContext.mScreenFactor, localCoordinates); - - float paraSurf = GetParallelogram(makeVect(0.f, 0.f, 0.f), dirPlaneX * gContext.mScreenFactor, dirPlaneY * gContext.mScreenFactor); - // Apply axis mask to axes and planes - belowPlaneLimit = (paraSurf > gContext.mAxisLimit) && (((1< gContext.mPlaneLimit) && !((1< (1.f - snapTension)) - { - *value = *value - modulo + snap * ((*value < 0.f) ? -1.f : 1.f); - } - } - static void ComputeSnap(vec_t& value, const float* snap) - { - for (int i = 0; i < 3; i++) - { - ComputeSnap(&value[i], snap[i]); - } - } - - static float ComputeAngleOnPlan() - { - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - vec_t localPos = Normalized(gContext.mRayOrigin + gContext.mRayVector * len - gContext.mModel.v.position); - - vec_t perpendicularVector; - perpendicularVector.Cross(gContext.mRotationVectorSource, gContext.mTranslationPlan); - perpendicularVector.Normalize(); - float acosAngle = Clamp(Dot(localPos, gContext.mRotationVectorSource), -1.f, 1.f); - float angle = acosf(acosAngle); - angle *= (Dot(localPos, perpendicularVector) < 0.f) ? 1.f : -1.f; - return angle; - } - - static void DrawRotationGizmo(OPERATION op, MOVETYPE type) - { - if(!Intersects(op, ROTATE)) - { - return; - } - ImDrawList* drawList = gContext.mDrawList; - - bool isMultipleAxesMasked = (gContext.mAxisMask & (gContext.mAxisMask - 1)) != 0; - bool isNoAxesMasked = !gContext.mAxisMask; - - // colors - ImU32 colors[7]; - ComputeColors(colors, type, ROTATE); - - vec_t viewDirNormalized; - matrix_t viewInverse; - if (gContext.mIsOrthographic) - { - viewInverse.Inverse(*(matrix_t*)&gContext.mViewMat); - viewDirNormalized = -viewInverse.v.dir; - } - else - { - // In left-handed view matrices, mCameraDir points toward the scene instead of - // toward the camera; negate it so we always get the "toward camera" direction, - // which selects the correct front-facing half of each rotation ring. - viewInverse.Inverse(*(matrix_t*)&gContext.mViewMat); - const float handSign = (Dot(Cross(viewInverse.v.right, viewInverse.v.up), viewInverse.v.dir) >= 0.f) ? 1.f : -1.f; - viewDirNormalized = Normalized(gContext.mCameraDir) * handSign; - } - - viewDirNormalized.TransformVector(gContext.mModelInverse); - - gContext.mRadiusSquareCenter = screenRotateSize * gContext.mHeight; - - bool hasRSC = Intersects(op, ROTATE_SCREEN); - for (int axis = 0; axis < 3; axis++) - { - if(!Intersects(op, static_cast(ROTATE_Z >> axis))) - { - continue; - } - - bool isAxisMasked = ((1 << (2 - axis)) & gContext.mAxisMask) != 0; - - if ((!isAxisMasked || isMultipleAxesMasked) && !isNoAxesMasked) - { - continue; - } - const bool usingAxis = (gContext.mbUsing && type == MT_ROTATE_Z - axis); - const int circleMul = (hasRSC && !usingAxis) ? 1 : 2; - - ImVec2* circlePos = (ImVec2*)alloca(sizeof(ImVec2) * (circleMul * halfCircleSegmentCount + 1)); - const bool rightHanded = gContext.mProjectionMat.m[2][3] < 0.f; - float angleStart = atan2f(viewDirNormalized[(4 - axis) % 3], viewDirNormalized[(3 - axis) % 3]) + (gContext.mIsOrthographic ? ZPI : -ZPI) * 0.5f + (rightHanded ? 0.f : ZPI); - - for (int i = 0; i < circleMul * halfCircleSegmentCount + 1; i++) - { - float ng = angleStart + (float)circleMul * ZPI * ((float)i / (float)(circleMul * halfCircleSegmentCount)); - vec_t axisPos = makeVect(cosf(ng), sinf(ng), 0.f); - vec_t pos = makeVect(axisPos[axis], axisPos[(axis + 1) % 3], axisPos[(axis + 2) % 3]) * gContext.mScreenFactor * rotationDisplayFactor; - circlePos[i] = worldToPos(pos, gContext.mMVP); - } - if (!gContext.mbUsing || usingAxis) - { -#if IMGUI_VERSION_NUM < 19276 - drawList->AddPolyline(circlePos, circleMul* halfCircleSegmentCount + 1, colors[3 - axis], 0, gContext.mStyle.RotationLineThickness ); -#else - drawList->AddPolyline(circlePos, circleMul* halfCircleSegmentCount + 1, colors[3 - axis], gContext.mStyle.RotationLineThickness, 0 ); -#endif - } - - float radiusAxis = sqrtf((ImLengthSqr(worldToPos(gContext.mModel.v.position, gContext.mViewProjection) - circlePos[0]))); - if (radiusAxis > gContext.mRadiusSquareCenter) - { - gContext.mRadiusSquareCenter = radiusAxis; - } - } - if(hasRSC && (!gContext.mbUsing || type == MT_ROTATE_SCREEN) && (!isMultipleAxesMasked && isNoAxesMasked)) - { - drawList->AddCircle(worldToPos(gContext.mModel.v.position, gContext.mViewProjection), gContext.mRadiusSquareCenter, colors[0], 64, gContext.mStyle.RotationOuterLineThickness); - } - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsRotateType(type)) - { - ImVec2 circlePos[halfCircleSegmentCount + 1]; - - circlePos[0] = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - for (unsigned int i = 1; i < halfCircleSegmentCount + 1; i++) - { - float ng = gContext.mRotationAngle * ((float)(i - 1) / (float)(halfCircleSegmentCount - 1)); - matrix_t rotateVectorMatrix; - rotateVectorMatrix.RotationAxis(gContext.mTranslationPlan, ng); - vec_t pos; - pos.TransformPoint(gContext.mRotationVectorSource, rotateVectorMatrix); - pos *= gContext.mScreenFactor * rotationDisplayFactor; - circlePos[i] = worldToPos(pos + gContext.mModel.v.position, gContext.mViewProjection); - } - drawList->AddConvexPolyFilled(circlePos, halfCircleSegmentCount + 1, GetColorU32(ROTATION_USING_FILL)); -#if IMGUI_VERSION_NUM < 19276 - drawList->AddPolyline(circlePos, halfCircleSegmentCount + 1, GetColorU32(ROTATION_USING_BORDER), ImDrawFlags_Closed, gContext.mStyle.RotationLineThickness ); -#else - drawList->AddPolyline(circlePos, halfCircleSegmentCount + 1, GetColorU32(ROTATION_USING_BORDER), gContext.mStyle.RotationLineThickness, ImDrawFlags_Closed ); -#endif - - ImVec2 destinationPosOnScreen = circlePos[1]; - char tmps[512]; - ImFormatString(tmps, sizeof(tmps), rotationInfoMask[type - MT_ROTATE_X], (gContext.mRotationAngle / ZPI) * 180.f, gContext.mRotationAngle); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 15, destinationPosOnScreen.y + 15), GetColorU32(TEXT_SHADOW), tmps); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 14, destinationPosOnScreen.y + 14), GetColorU32(TEXT), tmps); - } - } - - static void DrawHatchedAxis(const vec_t& axis) - { - if (gContext.mStyle.HatchedAxisLineThickness <= 0.0f) - { - return; - } - - for (int j = 1; j < 10; j++) - { - ImVec2 baseSSpace2 = worldToPos(axis * 0.05f * (float)(j * 2) * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpace2 = worldToPos(axis * 0.05f * (float)(j * 2 + 1) * gContext.mScreenFactor, gContext.mMVP); - gContext.mDrawList->AddLine(baseSSpace2, worldDirSSpace2, GetColorU32(HATCHED_AXIS_LINES), gContext.mStyle.HatchedAxisLineThickness); - } - } - - static void DrawScaleGizmo(OPERATION op, MOVETYPE type) - { - ImDrawList* drawList = gContext.mDrawList; - - if(!Intersects(op, SCALE)) - { - return; - } - - // colors - ImU32 colors[7]; - ComputeColors(colors, type, SCALE); - - // draw - vec_t scaleDisplay = { 1.f, 1.f, 1.f, 1.f }; - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) - { - scaleDisplay = gContext.mScale; - } - - for (int i = 0; i < 3; i++) - { - if(!Intersects(op, static_cast(SCALE_X << i))) - { - continue; - } - const bool usingAxis = (gContext.mbUsing && type == MT_SCALE_X + i); - if (!gContext.mbUsing || usingAxis) - { - vec_t dirPlaneX, dirPlaneY, dirAxis; - bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); - - // draw axis - if (belowAxisLimit) - { - bool hasTranslateOnAxis = Contains(op, static_cast(TRANSLATE_X << i)); - float markerScale = hasTranslateOnAxis ? 1.4f : 1.0f; - ImVec2 baseSSpace = worldToPos(dirAxis * 0.1f * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpaceNoScale = worldToPos(dirAxis * markerScale * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpace = worldToPos((dirAxis * markerScale * scaleDisplay[i]) * gContext.mScreenFactor, gContext.mMVP); - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) - { - ImU32 scaleLineColor = GetColorU32(SCALE_LINE); - drawList->AddLine(baseSSpace, worldDirSSpaceNoScale, scaleLineColor, gContext.mStyle.ScaleLineThickness); - drawList->AddCircleFilled(worldDirSSpaceNoScale, gContext.mStyle.ScaleLineCircleSize, scaleLineColor); - } - - if (!hasTranslateOnAxis || gContext.mbUsing) - { - drawList->AddLine(baseSSpace, worldDirSSpace, colors[i + 1], gContext.mStyle.ScaleLineThickness); - } - drawList->AddCircleFilled(worldDirSSpace, gContext.mStyle.ScaleLineCircleSize, colors[i + 1]); - - if (gContext.GetTripodState().mAxisFactor[i] < 0.f) - { - DrawHatchedAxis(dirAxis * scaleDisplay[i]); - } - } - } - } - - // draw screen cirle - drawList->AddCircleFilled(gContext.mScreenSquareCenter, gContext.mStyle.CenterCircleSize, colors[0], 32); - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsScaleType(type)) - { - //ImVec2 sourcePosOnScreen = worldToPos(gContext.mMatrixOrigin, gContext.mViewProjection); - ImVec2 destinationPosOnScreen = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - /*vec_t dif(destinationPosOnScreen.x - sourcePosOnScreen.x, destinationPosOnScreen.y - sourcePosOnScreen.y); - dif.Normalize(); - dif *= 5.f; - drawList->AddCircle(sourcePosOnScreen, 6.f, translationLineColor); - drawList->AddCircle(destinationPosOnScreen, 6.f, translationLineColor); - drawList->AddLine(ImVec2(sourcePosOnScreen.x + dif.x, sourcePosOnScreen.y + dif.y), ImVec2(destinationPosOnScreen.x - dif.x, destinationPosOnScreen.y - dif.y), translationLineColor, 2.f); - */ - char tmps[512]; - //vec_t deltaInfo = gContext.mModel.v.position - gContext.mMatrixOrigin; - int componentInfoIndex = (type - MT_SCALE_X) * 3; - ImFormatString(tmps, sizeof(tmps), scaleInfoMask[type - MT_SCALE_X], scaleDisplay[translationInfoIndex[componentInfoIndex]]); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 15, destinationPosOnScreen.y + 15), GetColorU32(TEXT_SHADOW), tmps); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 14, destinationPosOnScreen.y + 14), GetColorU32(TEXT), tmps); - } - } - - - static void DrawScaleUniveralGizmo(OPERATION op, MOVETYPE type) - { - ImDrawList* drawList = gContext.mDrawList; - - if (!Intersects(op, SCALEU)) - { - return; - } - - // colors - ImU32 colors[7]; - ComputeColors(colors, type, SCALEU); - - // draw - vec_t scaleDisplay = { 1.f, 1.f, 1.f, 1.f }; - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) - { - scaleDisplay = gContext.mScale; - } - - for (int i = 0; i < 3; i++) - { - if (!Intersects(op, static_cast(SCALE_XU << i))) - { - continue; - } - const bool usingAxis = (gContext.mbUsing && type == MT_SCALE_X + i); - if (!gContext.mbUsing || usingAxis) - { - vec_t dirPlaneX, dirPlaneY, dirAxis; - bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); - - // draw axis - if (belowAxisLimit) - { - bool hasTranslateOnAxis = Contains(op, static_cast(TRANSLATE_X << i)); - float markerScale = hasTranslateOnAxis ? 1.4f : 1.0f; - //ImVec2 baseSSpace = worldToPos(dirAxis * 0.1f * gContext.mScreenFactor, gContext.mMVPLocal); - //ImVec2 worldDirSSpaceNoScale = worldToPos(dirAxis * markerScale * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpace = worldToPos((dirAxis * markerScale * scaleDisplay[i]) * gContext.mScreenFactor, gContext.mMVPLocal); - -#if 0 - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID)) - { - drawList->AddLine(baseSSpace, worldDirSSpaceNoScale, IM_COL32(0x40, 0x40, 0x40, 0xFF), 3.f); - drawList->AddCircleFilled(worldDirSSpaceNoScale, 6.f, IM_COL32(0x40, 0x40, 0x40, 0xFF)); - } - /* - if (!hasTranslateOnAxis || gContext.mbUsing) - { - drawList->AddLine(baseSSpace, worldDirSSpace, colors[i + 1], 3.f); - } - */ -#endif - drawList->AddCircleFilled(worldDirSSpace, 12.f, colors[i + 1]); - } - } - } - - // draw screen cirle - drawList->AddCircle(gContext.mScreenSquareCenter, 20.f, colors[0], 32, gContext.mStyle.CenterCircleSize); - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsScaleType(type)) - { - //ImVec2 sourcePosOnScreen = worldToPos(gContext.mMatrixOrigin, gContext.mViewProjection); - ImVec2 destinationPosOnScreen = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - /*vec_t dif(destinationPosOnScreen.x - sourcePosOnScreen.x, destinationPosOnScreen.y - sourcePosOnScreen.y); - dif.Normalize(); - dif *= 5.f; - drawList->AddCircle(sourcePosOnScreen, 6.f, translationLineColor); - drawList->AddCircle(destinationPosOnScreen, 6.f, translationLineColor); - drawList->AddLine(ImVec2(sourcePosOnScreen.x + dif.x, sourcePosOnScreen.y + dif.y), ImVec2(destinationPosOnScreen.x - dif.x, destinationPosOnScreen.y - dif.y), translationLineColor, 2.f); - */ - char tmps[512]; - //vec_t deltaInfo = gContext.mModel.v.position - gContext.mMatrixOrigin; - int componentInfoIndex = (type - MT_SCALE_X) * 3; - ImFormatString(tmps, sizeof(tmps), scaleInfoMask[type - MT_SCALE_X], scaleDisplay[translationInfoIndex[componentInfoIndex]]); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 15, destinationPosOnScreen.y + 15), GetColorU32(TEXT_SHADOW), tmps); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 14, destinationPosOnScreen.y + 14), GetColorU32(TEXT), tmps); - } - } - - static void DrawTranslationGizmo(OPERATION op, MOVETYPE type) - { - ImDrawList* drawList = gContext.mDrawList; - if (!drawList) - { - return; - } - - if(!Intersects(op, TRANSLATE)) - { - return; - } - - // colors - ImU32 colors[7]; - ComputeColors(colors, type, TRANSLATE); - - const ImVec2 origin = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - - // draw - bool belowAxisLimit = false; - bool belowPlaneLimit = false; - for (int i = 0; i < 3; ++i) - { - vec_t dirPlaneX, dirPlaneY, dirAxis; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit); - - if (!gContext.mbUsing || (gContext.mbUsing && type == MT_MOVE_X + i)) - { - // draw axis - if (belowAxisLimit && Intersects(op, static_cast(TRANSLATE_X << i))) - { - ImVec2 baseSSpace = worldToPos(dirAxis * 0.1f * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpace = worldToPos(dirAxis * gContext.mScreenFactor, gContext.mMVP); - - drawList->AddLine(baseSSpace, worldDirSSpace, colors[i + 1], gContext.mStyle.TranslationLineThickness); - - // Arrow head begin - ImVec2 dir(origin - worldDirSSpace); - - float d = sqrtf(ImLengthSqr(dir)); - dir /= d; // Normalize - dir *= gContext.mStyle.TranslationLineArrowSize; - - ImVec2 ortogonalDir(dir.y, -dir.x); // Perpendicular vector - ImVec2 a(worldDirSSpace + dir); - drawList->AddTriangleFilled(worldDirSSpace - dir, a + ortogonalDir, a - ortogonalDir, colors[i + 1]); - // Arrow head end - - if (gContext.GetTripodState().mAxisFactor[i] < 0.f) - { - DrawHatchedAxis(dirAxis); - } - } - } - // draw plane - if (!gContext.mbUsing || (gContext.mbUsing && type == MT_MOVE_YZ + i)) - { - if (belowPlaneLimit && Contains(op, TRANSLATE_PLANS[i])) - { - ImVec2 screenQuadPts[4]; - for (int j = 0; j < 4; ++j) - { - vec_t cornerWorldPos = (dirPlaneX * quadUV[j * 2] + dirPlaneY * quadUV[j * 2 + 1]) * gContext.mScreenFactor; - screenQuadPts[j] = worldToPos(cornerWorldPos, gContext.mMVP); - } -#if IMGUI_VERSION_NUM < 19276 - drawList->AddPolyline(screenQuadPts, 4, GetColorU32(DIRECTION_X + i), ImDrawFlags_Closed, 1.0f ); -#else - drawList->AddPolyline(screenQuadPts, 4, GetColorU32(DIRECTION_X + i), 1.0f, ImDrawFlags_Closed ); -#endif - drawList->AddConvexPolyFilled(screenQuadPts, 4, colors[i + 4]); - } - } - } - - drawList->AddCircleFilled(gContext.mScreenSquareCenter, gContext.mStyle.CenterCircleSize, colors[0], 32); - - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsTranslateType(type)) - { - ImU32 translationLineColor = GetColorU32(TRANSLATION_LINE); - - ImVec2 sourcePosOnScreen = worldToPos(gContext.mMatrixOrigin, gContext.mViewProjection); - ImVec2 destinationPosOnScreen = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - vec_t dif = { destinationPosOnScreen.x - sourcePosOnScreen.x, destinationPosOnScreen.y - sourcePosOnScreen.y, 0.f, 0.f }; - dif.Normalize(); - dif *= 5.f; - drawList->AddCircle(sourcePosOnScreen, 6.f, translationLineColor); - drawList->AddCircle(destinationPosOnScreen, 6.f, translationLineColor); - drawList->AddLine(ImVec2(sourcePosOnScreen.x + dif.x, sourcePosOnScreen.y + dif.y), ImVec2(destinationPosOnScreen.x - dif.x, destinationPosOnScreen.y - dif.y), translationLineColor, 2.f); - - char tmps[512]; - vec_t deltaInfo = gContext.mModel.v.position - gContext.mMatrixOrigin; - int componentInfoIndex = (type - MT_MOVE_X) * 3; - ImFormatString(tmps, sizeof(tmps), translationInfoMask[type - MT_MOVE_X], deltaInfo[translationInfoIndex[componentInfoIndex]], deltaInfo[translationInfoIndex[componentInfoIndex + 1]], deltaInfo[translationInfoIndex[componentInfoIndex + 2]]); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 15, destinationPosOnScreen.y + 15), GetColorU32(TEXT_SHADOW), tmps); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 14, destinationPosOnScreen.y + 14), GetColorU32(TEXT), tmps); - } - } - - static bool CanActivate() - { - if (ImGui::IsMouseClicked(0) && !ImGui::IsAnyItemHovered() && !ImGui::IsAnyItemActive()) - { - return true; - } - return false; - } - - static bool HandleAndDrawLocalBounds(const float* bounds, matrix_t* matrix, const float* snapValues, OPERATION operation) - { - ImGuiIO& io = ImGui::GetIO(); - ImDrawList* drawList = gContext.mDrawList; - - bool manipulated = false; - - // compute best projection axis - vec_t axesWorldDirections[3]; - vec_t bestAxisWorldDirection = { 0.0f, 0.0f, 0.0f, 0.0f }; - int axes[3]; - unsigned int numAxes = 1; - axes[0] = gContext.mBoundsBestAxis; - int bestAxis = axes[0]; - if (!gContext.mbUsingBounds) - { - numAxes = 0; - float bestDot = 0.f; - for (int i = 0; i < 3; i++) - { - vec_t dirPlaneNormalWorld; - dirPlaneNormalWorld.TransformVector(directionUnary[i], gContext.mModelSource); - dirPlaneNormalWorld.Normalize(); - - float dt = fabsf(Dot(Normalized(gContext.mCameraEye - gContext.mModelSource.v.position), dirPlaneNormalWorld)); - if (dt >= bestDot) - { - bestDot = dt; - bestAxis = i; - bestAxisWorldDirection = dirPlaneNormalWorld; - } - - if (dt >= 0.1f) - { - axes[numAxes] = i; - axesWorldDirections[numAxes] = dirPlaneNormalWorld; - ++numAxes; - } - } - } - - if (numAxes == 0) - { - axes[0] = bestAxis; - axesWorldDirections[0] = bestAxisWorldDirection; - numAxes = 1; - } - - else if (bestAxis != axes[0]) - { - unsigned int bestIndex = 0; - for (unsigned int i = 0; i < numAxes; i++) - { - if (axes[i] == bestAxis) - { - bestIndex = i; - break; - } - } - int tempAxis = axes[0]; - axes[0] = axes[bestIndex]; - axes[bestIndex] = tempAxis; - vec_t tempDirection = axesWorldDirections[0]; - axesWorldDirections[0] = axesWorldDirections[bestIndex]; - axesWorldDirections[bestIndex] = tempDirection; - } - - for (unsigned int axisIndex = 0; axisIndex < numAxes; ++axisIndex) - { - bestAxis = axes[axisIndex]; - bestAxisWorldDirection = axesWorldDirections[axisIndex]; - - // corners - vec_t aabb[4]; - - int secondAxis = (bestAxis + 1) % 3; - int thirdAxis = (bestAxis + 2) % 3; - - for (int i = 0; i < 4; i++) - { - aabb[i][3] = aabb[i][bestAxis] = 0.f; - aabb[i][secondAxis] = bounds[secondAxis + 3 * (i >> 1)]; - aabb[i][thirdAxis] = bounds[thirdAxis + 3 * ((i >> 1) ^ (i & 1))]; - } - - // draw bounds - unsigned int anchorAlpha = gContext.mbEnable ? IM_COL32_BLACK : IM_COL32(0, 0, 0, 0x80); - - matrix_t boundsMVP = gContext.mModelSource * gContext.mViewProjection; - for (int i = 0; i < 4; i++) - { - // Clip the segment against the near plane (w >= eps) so the dashed - // line still draws when an endpoint is behind the camera or outside - // the viewport. ImDrawList clips to the 2D clip rect on its own. - vec_t p0; p0.TransformPoint(aabb[i], boundsMVP); - vec_t p1; p1.TransformPoint(aabb[(i + 1) % 4], boundsMVP); - const float wEps = 1e-3f; - bool in0 = p0.w >= wEps; - bool in1 = p1.w >= wEps; - if (!in0 && !in1) - { - continue; - } - if (!in0) - { - float t = (p1.w - wEps) / (p1.w - p0.w); - p0.x = p1.x + (p0.x - p1.x) * t; - p0.y = p1.y + (p0.y - p1.y) * t; - p0.z = p1.z + (p0.z - p1.z) * t; - p0.w = wEps; - } - else if (!in1) - { - float t = (p0.w - wEps) / (p0.w - p1.w); - p1.x = p0.x + (p1.x - p0.x) * t; - p1.y = p0.y + (p1.y - p0.y) * t; - p1.z = p0.z + (p1.z - p0.z) * t; - p1.w = wEps; - } - auto clipToScreen = [](const vec_t& c) -> ImVec2 - { - float nx = c.x * (0.5f / c.w) + 0.5f; - float ny = c.y * (0.5f / c.w) + 0.5f; - ny = 1.f - ny; - return ImVec2(gContext.mX + nx * gContext.mWidth, gContext.mY + ny * gContext.mHeight); - }; - ImVec2 worldBound1 = clipToScreen(p0); - ImVec2 worldBound2 = clipToScreen(p1); - float boundDistance = sqrtf(ImLengthSqr(worldBound1 - worldBound2)); - int stepCount = (int)(boundDistance / 10.f); - stepCount = min(stepCount, 1000); - for (int j = 0; j < stepCount; j++) - { - float stepLength = 1.f / (float)stepCount; - float t1 = (float)j * stepLength; - float t2 = (float)j * stepLength + stepLength * 0.5f; - ImVec2 worldBoundSS1 = ImLerp(worldBound1, worldBound2, ImVec2(t1, t1)); - ImVec2 worldBoundSS2 = ImLerp(worldBound1, worldBound2, ImVec2(t2, t2)); - //drawList->AddLine(worldBoundSS1, worldBoundSS2, IM_COL32(0, 0, 0, 0) + anchorAlpha, 3.f); - drawList->AddLine(worldBoundSS1, worldBoundSS2, IM_COL32(0xAA, 0xAA, 0xAA, 0) + anchorAlpha, 2.f); - } - vec_t midPoint = (aabb[i] + aabb[(i + 1) % 4]) * 0.5f; - // Per-anchor visibility: big anchor depends only on corner i; - // small anchor depends only on the midpoint of edge (i, i+1). - vec_t pCorner; pCorner.TransformPoint(aabb[i], boundsMVP); - vec_t pMid; pMid.TransformPoint(midPoint, boundsMVP); - ImVec2 worldBoundOrig = worldToPos(aabb[i], boundsMVP); - ImVec2 midBound = worldToPos(midPoint, boundsMVP); - bool bigAnchorVisible = pCorner.w >= wEps && IsInContextRect(worldBoundOrig); - bool smallAnchorVisible = pMid.w >= wEps && IsInContextRect(midBound); - - static const float AnchorBigRadius = 8.f; - static const float AnchorSmallRadius = 6.f; - bool overBigAnchor = bigAnchorVisible && ImLengthSqr(worldBoundOrig - io.MousePos) <= (AnchorBigRadius * AnchorBigRadius); - bool overSmallAnchor = smallAnchorVisible && ImLengthSqr(midBound - io.MousePos) <= (AnchorBigRadius * AnchorBigRadius); - - MOVETYPE type = MT_NONE; - vec_t gizmoHitProportion; - - if(Intersects(operation, TRANSLATE)) - { - type = GetMoveType(operation, &gizmoHitProportion); - } - if(Intersects(operation, ROTATE) && type == MT_NONE) - { - type = GetRotateType(operation); - } - if(Intersects(operation, SCALE) && type == MT_NONE) - { - type = GetScaleType(operation); - } - - if (type != MT_NONE) - { - overBigAnchor = false; - overSmallAnchor = false; - } - - ImU32 selectionColor = GetColorU32(SELECTION); - - unsigned int bigAnchorColor = overBigAnchor ? selectionColor : (IM_COL32(0xAA, 0xAA, 0xAA, 0) + anchorAlpha); - unsigned int smallAnchorColor = overSmallAnchor ? selectionColor : (IM_COL32(0xAA, 0xAA, 0xAA, 0) + anchorAlpha); - - if (bigAnchorVisible) - { - drawList->AddCircleFilled(worldBoundOrig, AnchorBigRadius, IM_COL32_BLACK); - drawList->AddCircleFilled(worldBoundOrig, AnchorBigRadius - 1.2f, bigAnchorColor); - } - - if (smallAnchorVisible) - { - drawList->AddCircleFilled(midBound, AnchorSmallRadius, IM_COL32_BLACK); - drawList->AddCircleFilled(midBound, AnchorSmallRadius - 1.2f, smallAnchorColor); - } - int oppositeIndex = (i + 2) % 4; - // big anchor on corners - if (!gContext.mbUsingBounds && gContext.mbEnable && overBigAnchor && CanActivate()) - { - gContext.mBoundsPivot.TransformPoint(aabb[(i + 2) % 4], gContext.mModelSource); - gContext.mBoundsAnchor.TransformPoint(aabb[i], gContext.mModelSource); - gContext.mBoundsPlan = BuildPlan(gContext.mBoundsAnchor, bestAxisWorldDirection); - gContext.mBoundsBestAxis = bestAxis; - gContext.mBoundsAxis[0] = secondAxis; - gContext.mBoundsAxis[1] = thirdAxis; - - gContext.mBoundsLocalPivot.Set(0.f); - gContext.mBoundsLocalPivot[secondAxis] = aabb[oppositeIndex][secondAxis]; - gContext.mBoundsLocalPivot[thirdAxis] = aabb[oppositeIndex][thirdAxis]; - - gContext.mbUsingBounds = true; - gContext.mEditingID = gContext.GetCurrentID(); - gContext.mBoundsMatrix = gContext.mModelSource; - } - // small anchor on middle of segment - if (!gContext.mbUsingBounds && gContext.mbEnable && overSmallAnchor && CanActivate()) - { - vec_t midPointOpposite = (aabb[(i + 2) % 4] + aabb[(i + 3) % 4]) * 0.5f; - gContext.mBoundsPivot.TransformPoint(midPointOpposite, gContext.mModelSource); - gContext.mBoundsAnchor.TransformPoint(midPoint, gContext.mModelSource); - gContext.mBoundsPlan = BuildPlan(gContext.mBoundsAnchor, bestAxisWorldDirection); - gContext.mBoundsBestAxis = bestAxis; - int indices[] = { secondAxis , thirdAxis }; - gContext.mBoundsAxis[0] = indices[i % 2]; - gContext.mBoundsAxis[1] = -1; - - gContext.mBoundsLocalPivot.Set(0.f); - gContext.mBoundsLocalPivot[gContext.mBoundsAxis[0]] = aabb[oppositeIndex][indices[i % 2]];// bounds[gContext.mBoundsAxis[0]] * (((i + 1) & 2) ? 1.f : -1.f); - - gContext.mbUsingBounds = true; - gContext.mEditingID = gContext.GetCurrentID(); - gContext.mBoundsMatrix = gContext.mModelSource; - } - } - - if (gContext.mbUsingBounds && (gContext.GetCurrentID() == gContext.mEditingID)) - { - matrix_t scale; - scale.SetToIdentity(); - - // compute projected mouse position on plan - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mBoundsPlan); - vec_t newPos = gContext.mRayOrigin + gContext.mRayVector * len; - - // compute a reference and delta vectors base on mouse move - vec_t deltaVector = (newPos - gContext.mBoundsPivot).Abs(); - vec_t referenceVector = (gContext.mBoundsAnchor - gContext.mBoundsPivot).Abs(); - - // for 1 or 2 axes, compute a ratio that's used for scale and snap it based on resulting length - for (int i = 0; i < 2; i++) - { - int axisIndex1 = gContext.mBoundsAxis[i]; - if (axisIndex1 == -1) - { - continue; - } - - float ratioAxis = 1.f; - vec_t axisDir = gContext.mBoundsMatrix.component[axisIndex1].Abs(); - - float dtAxis = axisDir.Dot(referenceVector); - float boundSize = bounds[axisIndex1 + 3] - bounds[axisIndex1]; - if (dtAxis > FLT_EPSILON) - { - ratioAxis = axisDir.Dot(deltaVector) / dtAxis; - } - - if (snapValues) - { - float length = boundSize * ratioAxis; - ComputeSnap(&length, snapValues[axisIndex1]); - if (boundSize > FLT_EPSILON) - { - ratioAxis = length / boundSize; - } - } - scale.component[axisIndex1] *= ratioAxis; - - if (fabsf(ratioAxis - 1.0f) > FLT_EPSILON) { - manipulated = true; - } - } - - // transform matrix - matrix_t preScale, postScale; - preScale.Translation(-gContext.mBoundsLocalPivot); - postScale.Translation(gContext.mBoundsLocalPivot); - matrix_t res = preScale * scale * postScale * gContext.mBoundsMatrix; - *matrix = res; - - // info text - char tmps[512]; - ImVec2 destinationPosOnScreen = worldToPos(gContext.mModel.v.position, gContext.mViewProjection); - ImFormatString(tmps, sizeof(tmps), "X: %.2f Y: %.2f Z: %.2f" - , (bounds[3] - bounds[0]) * gContext.mBoundsMatrix.component[0].Length() * scale.component[0].Length() - , (bounds[4] - bounds[1]) * gContext.mBoundsMatrix.component[1].Length() * scale.component[1].Length() - , (bounds[5] - bounds[2]) * gContext.mBoundsMatrix.component[2].Length() * scale.component[2].Length() - ); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 15, destinationPosOnScreen.y + 15), GetColorU32(TEXT_SHADOW), tmps); - drawList->AddText(ImVec2(destinationPosOnScreen.x + 14, destinationPosOnScreen.y + 14), GetColorU32(TEXT), tmps); - } - - if (!io.MouseDown[0]) { - gContext.mbUsingBounds = false; - gContext.mEditingID = -1; - } - if (gContext.mbUsingBounds) - { - break; - } - } - - return manipulated; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // - - static MOVETYPE GetScaleType(OPERATION op) - { - if (gContext.mbUsing) - { - return MT_NONE; - } - ImGuiIO& io = ImGui::GetIO(); - MOVETYPE type = MT_NONE; - - // screen - if (io.MousePos.x >= gContext.mScreenSquareMin.x && io.MousePos.x <= gContext.mScreenSquareMax.x && - io.MousePos.y >= gContext.mScreenSquareMin.y && io.MousePos.y <= gContext.mScreenSquareMax.y && - Contains(op, SCALE)) - { - type = MT_SCALE_XYZ; - } - - // compute - for (int i = 0; i < 3 && type == MT_NONE; i++) - { - if(!Intersects(op, static_cast(SCALE_X << i))) - { - continue; - } - bool isAxisMasked = ((1 << i) & gContext.mAxisMask) != 0; - - vec_t dirPlaneX, dirPlaneY, dirAxis; - bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); - dirAxis.TransformVector(gContext.mModelLocal); - dirPlaneX.TransformVector(gContext.mModelLocal); - dirPlaneY.TransformVector(gContext.mModelLocal); - - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, BuildPlan(gContext.mModelLocal.v.position, dirAxis)); - vec_t posOnPlan = gContext.mRayOrigin + gContext.mRayVector * len; - - const float startOffset = Contains(op, static_cast(TRANSLATE_X << i)) ? 1.0f : 0.1f; - const float endOffset = Contains(op, static_cast(TRANSLATE_X << i)) ? 1.4f : 1.0f; - const ImVec2 posOnPlanScreen = worldToPos(posOnPlan, gContext.mViewProjection); - const ImVec2 axisStartOnScreen = worldToPos(gContext.mModelLocal.v.position + dirAxis * gContext.mScreenFactor * startOffset, gContext.mViewProjection); - const ImVec2 axisEndOnScreen = worldToPos(gContext.mModelLocal.v.position + dirAxis * gContext.mScreenFactor * endOffset, gContext.mViewProjection); - - vec_t closestPointOnAxis = PointOnSegment(makeVect(posOnPlanScreen), makeVect(axisStartOnScreen), makeVect(axisEndOnScreen)); - - if ((closestPointOnAxis - makeVect(posOnPlanScreen)).Length() < 12.f) // pixel size - { - if (!isAxisMasked) - type = static_cast(MT_SCALE_X + i); - } - } - - // universal - - vec_t deltaScreen = { io.MousePos.x - gContext.mScreenSquareCenter.x, io.MousePos.y - gContext.mScreenSquareCenter.y, 0.f, 0.f }; - float dist = deltaScreen.Length(); - if (Contains(op, SCALEU) && dist >= 17.0f && dist < 23.0f) - { - type = MT_SCALE_XYZ; - } - - for (int i = 0; i < 3 && type == MT_NONE; i++) - { - if (!Intersects(op, static_cast(SCALE_XU << i))) - { - continue; - } - - vec_t dirPlaneX, dirPlaneY, dirAxis; - bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit, true); - - // draw axis - if (belowAxisLimit) - { - bool hasTranslateOnAxis = Contains(op, static_cast(TRANSLATE_X << i)); - float markerScale = hasTranslateOnAxis ? 1.4f : 1.0f; - //ImVec2 baseSSpace = worldToPos(dirAxis * 0.1f * gContext.mScreenFactor, gContext.mMVPLocal); - //ImVec2 worldDirSSpaceNoScale = worldToPos(dirAxis * markerScale * gContext.mScreenFactor, gContext.mMVP); - ImVec2 worldDirSSpace = worldToPos((dirAxis * markerScale) * gContext.mScreenFactor, gContext.mMVPLocal); - - float distance = sqrtf(ImLengthSqr(worldDirSSpace - io.MousePos)); - if (distance < 12.f) - { - type = static_cast(MT_SCALE_X + i); - } - } - } - return type; - } - - static MOVETYPE GetRotateType(OPERATION op) - { - if (gContext.mbUsing) - { - return MT_NONE; - } - - bool isNoAxesMasked = !gContext.mAxisMask; - bool isMultipleAxesMasked = (gContext.mAxisMask & (gContext.mAxisMask - 1)) != 0; - - ImGuiIO& io = ImGui::GetIO(); - MOVETYPE type = MT_NONE; - - vec_t deltaScreen = { io.MousePos.x - gContext.mScreenSquareCenter.x, io.MousePos.y - gContext.mScreenSquareCenter.y, 0.f, 0.f }; - float dist = deltaScreen.Length(); - if (Intersects(op, ROTATE_SCREEN) && dist >= (gContext.mRadiusSquareCenter - 4.0f) && dist < (gContext.mRadiusSquareCenter + 4.0f)) - { - if (!isNoAxesMasked) - return MT_NONE; - type = MT_ROTATE_SCREEN; - } - - const vec_t planNormals[] = { gContext.mModel.v.right, gContext.mModel.v.up, gContext.mModel.v.dir }; - - vec_t modelViewPos; - modelViewPos.TransformPoint(gContext.mModel.v.position, gContext.mViewMat); - - for (int i = 0; i < 3 && type == MT_NONE; i++) - { - if(!Intersects(op, static_cast(ROTATE_X << i))) - { - continue; - } - bool isAxisMasked = ((1 << i) & gContext.mAxisMask) != 0; - // pickup plan - vec_t pickupPlan = BuildPlan(gContext.mModel.v.position, planNormals[i]); - - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, pickupPlan); - const vec_t intersectWorldPos = gContext.mRayOrigin + gContext.mRayVector * len; - vec_t intersectViewPos; - intersectViewPos.TransformPoint(intersectWorldPos, gContext.mViewMat); - - if (ImAbs(modelViewPos.z) - ImAbs(intersectViewPos.z) < -FLT_EPSILON) - { - continue; - } - - const vec_t localPos = intersectWorldPos - gContext.mModel.v.position; - vec_t idealPosOnCircle = Normalized(localPos); - idealPosOnCircle.TransformVector(gContext.mModelInverse); - const ImVec2 idealPosOnCircleScreen = worldToPos(idealPosOnCircle * rotationDisplayFactor * gContext.mScreenFactor, gContext.mMVP); - - //gContext.mDrawList->AddCircle(idealPosOnCircleScreen, 5.f, IM_COL32_WHITE); - const ImVec2 distanceOnScreen = idealPosOnCircleScreen - io.MousePos; - - const float distance = makeVect(distanceOnScreen).Length(); - if (distance < 8.f) // pixel size - { - if ((!isAxisMasked || isMultipleAxesMasked) && !isNoAxesMasked) - break; - type = static_cast(MT_ROTATE_X + i); - } - } - - return type; - } - - static MOVETYPE GetMoveType(OPERATION op, vec_t* gizmoHitProportion) - { - if(!Intersects(op, TRANSLATE) || gContext.mbUsing || !gContext.mbMouseOver) - { - return MT_NONE; - } - - bool isNoAxesMasked = !gContext.mAxisMask; - bool isMultipleAxesMasked = (gContext.mAxisMask & (gContext.mAxisMask - 1)) != 0; - - ImGuiIO& io = ImGui::GetIO(); - MOVETYPE type = MT_NONE; - - // screen - if (io.MousePos.x >= gContext.mScreenSquareMin.x && io.MousePos.x <= gContext.mScreenSquareMax.x && - io.MousePos.y >= gContext.mScreenSquareMin.y && io.MousePos.y <= gContext.mScreenSquareMax.y && - Contains(op, TRANSLATE)) - { - type = MT_MOVE_SCREEN; - } - - const vec_t screenCoord = makeVect(io.MousePos - ImVec2(gContext.mX, gContext.mY)); - - // compute - for (int i = 0; i < 3 && type == MT_NONE; i++) - { - bool isAxisMasked = ((1 << i) & gContext.mAxisMask) != 0; - vec_t dirPlaneX, dirPlaneY, dirAxis; - bool belowAxisLimit, belowPlaneLimit; - ComputeTripodAxisAndVisibility(i, dirAxis, dirPlaneX, dirPlaneY, belowAxisLimit, belowPlaneLimit); - dirAxis.TransformVector(gContext.mModel); - dirPlaneX.TransformVector(gContext.mModel); - dirPlaneY.TransformVector(gContext.mModel); - - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, BuildPlan(gContext.mModel.v.position, dirAxis)); - vec_t posOnPlan = gContext.mRayOrigin + gContext.mRayVector * len; - - const ImVec2 axisStartOnScreen = worldToPos(gContext.mModel.v.position + dirAxis * gContext.mScreenFactor * 0.1f, gContext.mViewProjection) - ImVec2(gContext.mX, gContext.mY); - const ImVec2 axisEndOnScreen = worldToPos(gContext.mModel.v.position + dirAxis * gContext.mScreenFactor, gContext.mViewProjection) - ImVec2(gContext.mX, gContext.mY); - - vec_t closestPointOnAxis = PointOnSegment(screenCoord, makeVect(axisStartOnScreen), makeVect(axisEndOnScreen)); - if ((closestPointOnAxis - screenCoord).Length() < 12.f && Intersects(op, static_cast(TRANSLATE_X << i))) // pixel size - { - if (isAxisMasked) - break; - type = static_cast(MT_MOVE_X + i); - } - - const float dx = dirPlaneX.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); - const float dy = dirPlaneY.Dot3((posOnPlan - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor)); - if (belowPlaneLimit && dx >= quadUV[0] && dx <= quadUV[4] && dy >= quadUV[1] && dy <= quadUV[3] && Contains(op, TRANSLATE_PLANS[i])) - { - if ((!isAxisMasked || isMultipleAxesMasked) && !isNoAxesMasked) - break; - type = static_cast(MT_MOVE_YZ + i); - } - - if (gizmoHitProportion) - { - *gizmoHitProportion = makeVect(dx, dy, 0.f); - } - } - return type; - } - - static bool HandleTranslation(float* matrix, float* deltaMatrix, OPERATION op, MOVETYPE& type, const float* snap) - { - if(!Intersects(op, TRANSLATE) || type != MT_NONE) - { - return false; - } - const ImGuiIO& io = ImGui::GetIO(); - const bool applyRotationLocaly = gContext.mMode == LOCAL || gContext.mCurrentHandleType == MT_MOVE_SCREEN; - bool modified = false; - - // move - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsTranslateType(gContext.mCurrentHandleType)) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - const float signedLength = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - const float len = fabsf(signedLength); // near plan - const vec_t newPos = gContext.mRayOrigin + gContext.mRayVector * len; - - // compute delta - const vec_t newOrigin = newPos - gContext.mRelativeOrigin * gContext.mScreenFactor; - vec_t delta = newOrigin - gContext.mModel.v.position; - - // 1 axis constraint - if (gContext.mCurrentHandleType >= MT_MOVE_X && gContext.mCurrentHandleType <= MT_MOVE_Z) - { - const int axisIndex = gContext.mCurrentHandleType - MT_MOVE_X; - const vec_t& axisValue = *(vec_t*)&gContext.mModel.m[axisIndex]; - const float lengthOnAxis = Dot(axisValue, delta); - delta = axisValue * lengthOnAxis; - } - - // snap - if (snap) - { - vec_t cumulativeDelta = gContext.mModel.v.position + delta - gContext.mMatrixOrigin; - if (applyRotationLocaly) - { - matrix_t modelSourceNormalized = gContext.mModelSource; - modelSourceNormalized.OrthoNormalize(); - matrix_t modelSourceNormalizedInverse; - modelSourceNormalizedInverse.Inverse(modelSourceNormalized); - cumulativeDelta.TransformVector(modelSourceNormalizedInverse); - ComputeSnap(cumulativeDelta, snap); - cumulativeDelta.TransformVector(modelSourceNormalized); - } - else - { - ComputeSnap(cumulativeDelta, snap); - } - delta = gContext.mMatrixOrigin + cumulativeDelta - gContext.mModel.v.position; - - } - - if (delta != gContext.mTranslationLastDelta) - { - modified = true; - } - gContext.mTranslationLastDelta = delta; - - // compute matrix & delta - matrix_t deltaMatrixTranslation; - deltaMatrixTranslation.Translation(delta); - if (deltaMatrix) - { - memcpy(deltaMatrix, deltaMatrixTranslation.m16, sizeof(float) * 16); - } - - const matrix_t res = gContext.mModelSource * deltaMatrixTranslation; - *(matrix_t*)matrix = res; - - if (!io.MouseDown[0]) - { - gContext.mbUsing = false; - } - - type = gContext.mCurrentHandleType; - } - else - { - // find new possible way to move - vec_t gizmoHitProportion; - type = gContext.mbOverGizmoHotspot ? MT_NONE : GetMoveType(op, &gizmoHitProportion); - gContext.mbOverGizmoHotspot |= type != MT_NONE; - if (type != MT_NONE) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - } - if (CanActivate() && type != MT_NONE) - { - gContext.mActiveTripodState = gContext.mTripodState; - gContext.mbUsing = true; - gContext.mEditingID = gContext.GetCurrentID(); - gContext.mCurrentHandleType = type; - vec_t movePlanNormal[] = { gContext.mModel.v.right, gContext.mModel.v.up, gContext.mModel.v.dir, - gContext.mModel.v.right, gContext.mModel.v.up, gContext.mModel.v.dir, - -gContext.mCameraDir }; - - vec_t cameraToModelNormalized = Normalized(gContext.mModel.v.position - gContext.mCameraEye); - for (unsigned int i = 0; i < 3; i++) - { - vec_t orthoVector = Cross(movePlanNormal[i], cameraToModelNormalized); - movePlanNormal[i].Cross(orthoVector); - movePlanNormal[i].Normalize(); - } - // pickup plan - gContext.mTranslationPlan = BuildPlan(gContext.mModel.v.position, movePlanNormal[type - MT_MOVE_X]); - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - gContext.mTranslationPlanOrigin = gContext.mRayOrigin + gContext.mRayVector * len; - gContext.mMatrixOrigin = gContext.mModel.v.position; - - gContext.mRelativeOrigin = (gContext.mTranslationPlanOrigin - gContext.mModel.v.position) * (1.f / gContext.mScreenFactor); - } - } - return modified; - } - - static bool HandleScale(float* matrix, float* deltaMatrix, OPERATION op, MOVETYPE& type, const float* snap) - { - if((!Intersects(op, SCALE) && !Intersects(op, SCALEU)) || type != MT_NONE || !gContext.mbMouseOver) - { - return false; - } - ImGuiIO& io = ImGui::GetIO(); - bool modified = false; - - if (!gContext.mbUsing) - { - // find new possible way to scale - type = gContext.mbOverGizmoHotspot ? MT_NONE : GetScaleType(op); - gContext.mbOverGizmoHotspot |= type != MT_NONE; - - if (type != MT_NONE) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - } - if (CanActivate() && type != MT_NONE) - { - gContext.mActiveTripodState = gContext.mTripodState; - gContext.mbUsing = true; - gContext.mEditingID = gContext.GetCurrentID(); - gContext.mCurrentHandleType = type; - const vec_t movePlanNormal[] = { gContext.mModelLocal.v.up, gContext.mModelLocal.v.dir, gContext.mModelLocal.v.right, gContext.mModelLocal.v.dir, gContext.mModelLocal.v.up, gContext.mModelLocal.v.right, -gContext.mCameraDir }; - // pickup plan - - gContext.mTranslationPlan = BuildPlan(gContext.mModelLocal.v.position, movePlanNormal[type - MT_SCALE_X]); - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - gContext.mTranslationPlanOrigin = gContext.mRayOrigin + gContext.mRayVector * len; - gContext.mMatrixOrigin = gContext.mModelLocal.v.position; - gContext.mScale.Set(1.f, 1.f, 1.f); - gContext.mRelativeOrigin = (gContext.mTranslationPlanOrigin - gContext.mModelLocal.v.position) * (1.f / gContext.mScreenFactor); - gContext.mScaleValueOrigin = makeVect(gContext.mModelSource.v.right.Length(), gContext.mModelSource.v.up.Length(), gContext.mModelSource.v.dir.Length()); - gContext.mSaveMousePosx = io.MousePos.x; - } - } - // scale - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsScaleType(gContext.mCurrentHandleType)) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - vec_t newPos = gContext.mRayOrigin + gContext.mRayVector * len; - vec_t newOrigin = newPos - gContext.mRelativeOrigin * gContext.mScreenFactor; - vec_t delta = newOrigin - gContext.mModelLocal.v.position; - - // 1 axis constraint - if (gContext.mCurrentHandleType >= MT_SCALE_X && gContext.mCurrentHandleType <= MT_SCALE_Z) - { - int axisIndex = gContext.mCurrentHandleType - MT_SCALE_X; - const vec_t& axisValue = *(vec_t*)&gContext.mModelLocal.m[axisIndex]; - float lengthOnAxis = Dot(axisValue, delta); - delta = axisValue * lengthOnAxis; - - vec_t baseVector = gContext.mTranslationPlanOrigin - gContext.mModelLocal.v.position; - float ratio = Dot(axisValue, baseVector + delta) / Dot(axisValue, baseVector); - - gContext.mScale[axisIndex] = max(ratio, 0.001f); - } - else - { - float scaleDelta = (io.MousePos.x - gContext.mSaveMousePosx) * 0.01f; - gContext.mScale.Set(max(1.f + scaleDelta, 0.001f)); - } - - // snap - if (snap) - { - float scaleSnap[] = { snap[0], snap[0], snap[0] }; - ComputeSnap(gContext.mScale, scaleSnap); - } - - // no 0 allowed - for (int i = 0; i < 3; i++) - gContext.mScale[i] = max(gContext.mScale[i], 0.001f); - - if (gContext.mScaleLast != gContext.mScale) - { - modified = true; - } - gContext.mScaleLast = gContext.mScale; - - // compute matrix & delta - matrix_t deltaMatrixScale; - deltaMatrixScale.Scale(gContext.mScale * gContext.mScaleValueOrigin); - - matrix_t res = deltaMatrixScale * gContext.mModelLocal; - *(matrix_t*)matrix = res; - - if (deltaMatrix) - { - vec_t deltaScale = gContext.mScale * gContext.mScaleValueOrigin; - - vec_t originalScaleDivider; - originalScaleDivider.x = 1 / gContext.mModelScaleOrigin.x; - originalScaleDivider.y = 1 / gContext.mModelScaleOrigin.y; - originalScaleDivider.z = 1 / gContext.mModelScaleOrigin.z; - - deltaScale = deltaScale * originalScaleDivider; - - deltaMatrixScale.Scale(deltaScale); - memcpy(deltaMatrix, deltaMatrixScale.m16, sizeof(float) * 16); - } - - if (!io.MouseDown[0]) - { - gContext.mbUsing = false; - gContext.mScale.Set(1.f, 1.f, 1.f); - } - - type = gContext.mCurrentHandleType; - } - return modified; - } - - static bool HandleRotation(float* matrix, float* deltaMatrix, OPERATION op, MOVETYPE& type, const float* snap) - { - if(!Intersects(op, ROTATE) || type != MT_NONE || !gContext.mbMouseOver) - { - return false; - } - ImGuiIO& io = ImGui::GetIO(); - bool applyRotationLocaly = gContext.mMode == LOCAL; - bool modified = false; - - if (!gContext.mbUsing) - { - type = gContext.mbOverGizmoHotspot ? MT_NONE : GetRotateType(op); - gContext.mbOverGizmoHotspot |= type != MT_NONE; - - if (type != MT_NONE) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - } - - if (type == MT_ROTATE_SCREEN) - { - applyRotationLocaly = true; - } - - if (CanActivate() && type != MT_NONE) - { - gContext.mbUsing = true; - gContext.mEditingID = gContext.GetCurrentID(); - gContext.mCurrentHandleType = type; - const vec_t rotatePlanNormal[] = { gContext.mModel.v.right, gContext.mModel.v.up, gContext.mModel.v.dir, -gContext.mCameraDir }; - // pickup plan - if (applyRotationLocaly) - { - gContext.mTranslationPlan = BuildPlan(gContext.mModel.v.position, rotatePlanNormal[type - MT_ROTATE_X]); - } - else - { - gContext.mTranslationPlan = BuildPlan(gContext.mModelSource.v.position, directionUnary[type - MT_ROTATE_X]); - } - - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, gContext.mTranslationPlan); - vec_t localPos = gContext.mRayOrigin + gContext.mRayVector * len - gContext.mModel.v.position; - gContext.mRotationVectorSource = Normalized(localPos); - gContext.mRotationAngleOrigin = ComputeAngleOnPlan(); - } - } - - // rotation - if (gContext.mbUsing && (gContext.GetCurrentID() == gContext.mEditingID) && IsRotateType(gContext.mCurrentHandleType)) - { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - gContext.mRotationAngle = ComputeAngleOnPlan(); - if (snap) - { - float snapInRadian = snap[0] * DEG2RAD; - ComputeSnap(&gContext.mRotationAngle, snapInRadian); - } - vec_t rotationAxisLocalSpace; - - rotationAxisLocalSpace.TransformVector(makeVect(gContext.mTranslationPlan.x, gContext.mTranslationPlan.y, gContext.mTranslationPlan.z, 0.f), gContext.mModelInverse); - rotationAxisLocalSpace.Normalize(); - - matrix_t deltaRotation; - deltaRotation.RotationAxis(rotationAxisLocalSpace, gContext.mRotationAngle - gContext.mRotationAngleOrigin); - if (gContext.mRotationAngle != gContext.mRotationAngleOrigin) - { - modified = true; - } - gContext.mRotationAngleOrigin = gContext.mRotationAngle; - - matrix_t scaleOrigin; - scaleOrigin.Scale(gContext.mModelScaleOrigin); - - if (applyRotationLocaly) - { - *(matrix_t*)matrix = scaleOrigin * deltaRotation * gContext.mModelLocal; - } - else - { - matrix_t res = gContext.mModelSource; - res.v.position.Set(0.f); - - *(matrix_t*)matrix = res * deltaRotation; - ((matrix_t*)matrix)->v.position = gContext.mModelSource.v.position; - } - - if (deltaMatrix) - { - *(matrix_t*)deltaMatrix = gContext.mModelInverse * deltaRotation * gContext.mModel; - } - - if (!io.MouseDown[0]) - { - gContext.mbUsing = false; - gContext.mEditingID = -1; - } - type = gContext.mCurrentHandleType; - } - return modified; - } - - void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale) - { - matrix_t mat = *(matrix_t*)matrix; - - scale[0] = mat.v.right.Length(); - scale[1] = mat.v.up.Length(); - scale[2] = mat.v.dir.Length(); - - mat.OrthoNormalize(); - - rotation[0] = RAD2DEG * atan2f(mat.m[1][2], mat.m[2][2]); - rotation[1] = RAD2DEG * atan2f(-mat.m[0][2], sqrtf(mat.m[1][2] * mat.m[1][2] + mat.m[2][2] * mat.m[2][2])); - rotation[2] = RAD2DEG * atan2f(mat.m[0][1], mat.m[0][0]); - - translation[0] = mat.v.position.x; - translation[1] = mat.v.position.y; - translation[2] = mat.v.position.z; - } - - void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix) - { - matrix_t& mat = *(matrix_t*)matrix; - - matrix_t rot[3]; - for (int i = 0; i < 3; i++) - { - rot[i].RotationAxis(directionUnary[i], rotation[i] * DEG2RAD); - } - - mat = rot[0] * rot[1] * rot[2]; - - float validScale[3]; - for (int i = 0; i < 3; i++) - { - if (fabsf(scale[i]) < FLT_EPSILON) - { - validScale[i] = 0.001f; - } - else - { - validScale[i] = scale[i]; - } - } - mat.v.right *= validScale[0]; - mat.v.up *= validScale[1]; - mat.v.dir *= validScale[2]; - mat.v.position.Set(translation[0], translation[1], translation[2], 1.f); - } - - void SetAlternativeWindow(ImGuiWindow* window) - { - gContext.mAlternativeWindow = window; - } - - void SetID(int id) - { - if (gContext.mIDStack.empty()) - { - gContext.mIDStack.push_back(-1); - } - gContext.mIDStack.back() = id; - } - - ImGuiID GetID(const char* str, const char* str_end) - { - ImGuiID seed = gContext.GetCurrentID(); - ImGuiID id = ImHashStr(str, str_end ? (str_end - str) : 0, seed); - return id; - } - - ImGuiID GetID(const char* str) - { - return GetID(str, nullptr); - } - - ImGuiID GetID(const void* ptr) - { - ImGuiID seed = gContext.GetCurrentID(); - ImGuiID id = ImHashData(&ptr, sizeof(void*), seed); - return id; - } - - ImGuiID GetID(int n) - { - ImGuiID seed = gContext.GetCurrentID(); - ImGuiID id = ImHashData(&n, sizeof(n), seed); - return id; - } - - void PushID(const char* str_id) - { - ImGuiID id = GetID(str_id); - gContext.mIDStack.push_back(id); - } - - void PushID(const char* str_id_begin, const char* str_id_end) - { - ImGuiID id = GetID(str_id_begin, str_id_end); - gContext.mIDStack.push_back(id); - } - - void PushID(const void* ptr_id) - { - ImGuiID id = GetID(ptr_id); - gContext.mIDStack.push_back(id); - } - - void PushID(int int_id) - { - ImGuiID id = GetID(int_id); - gContext.mIDStack.push_back(id); - } - - void PopID() - { - IM_ASSERT(gContext.mIDStack.Size > 1); // Too many PopID(), or could be popping in a wrong/different window? - gContext.mIDStack.pop_back(); - if (gContext.mIDStack.empty()) - { - gContext.mIDStack.clear(); - } - } - - void AllowAxisFlip(bool value) - { - gContext.mAllowAxisFlip = value; - } - - void SetAxisLimit(float value) - { - gContext.mAxisLimit=value; - } - - void SetAxisMask(bool x, bool y, bool z) - { - gContext.mAxisMask = (x ? 1 : 0) + (y ? 2 : 0) + (z ? 4 : 0); - } - - void SetPlaneLimit(float value) - { - gContext.mPlaneLimit = value; - } - - bool IsOver(float* position, float pixelRadius) - { - const ImGuiIO& io = ImGui::GetIO(); - - float radius = sqrtf((ImLengthSqr(worldToPos({ position[0], position[1], position[2], 0.0f }, gContext.mViewProjection) - io.MousePos))); - return radius < pixelRadius; - } - - bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix, const float* snap, const float* localBounds, const float* boundsSnap) - { - gContext.mDrawList->PushClipRect (ImVec2 (gContext.mX, gContext.mY), ImVec2 (gContext.mX + gContext.mWidth, gContext.mY + gContext.mHeight), false); - - // Scale is always local or matrix will be skewed when applying world scale or oriented matrix - ComputeContext(view, projection, matrix, (operation & SCALE) ? LOCAL : mode); - gContext.mHoveredHandleType = MT_NONE; - - // set delta to identity - if (deltaMatrix) - { - ((matrix_t*)deltaMatrix)->SetToIdentity(); - } - - // behind camera - vec_t camSpacePosition; - camSpacePosition.TransformPoint(makeVect(0.f, 0.f, 0.f), gContext.mMVP); - if (!gContext.mIsOrthographic && camSpacePosition.z < 0.001f && !gContext.mbUsing) - { - return false; - } - - // -- - MOVETYPE type = MT_NONE; - bool manipulated = false; - if (gContext.mbEnable) - { - if (!gContext.mbUsingBounds) - { - manipulated = HandleTranslation(matrix, deltaMatrix, operation, type, snap) || - HandleScale(matrix, deltaMatrix, operation, type, snap) || - HandleRotation(matrix, deltaMatrix, operation, type, snap); - } - } - - if (localBounds && !gContext.mbUsing) - { - manipulated |= HandleAndDrawLocalBounds(localBounds, (matrix_t*)matrix, boundsSnap, operation); - } - - gContext.mOperation = operation; - gContext.mHoveredHandleType = (!gContext.mbUsing && !gContext.mbUsingBounds) ? type : MT_NONE; - if (!gContext.mbUsingBounds) - { - DrawRotationGizmo(operation, type); - DrawTranslationGizmo(operation, type); - DrawScaleGizmo(operation, type); - DrawScaleUniveralGizmo(operation, type); - } - - gContext.mDrawList->PopClipRect (); - return manipulated; - } - - void SetGizmoSizeClipSpace(float value) - { - gContext.mGizmoSizeClipSpace = value; - } - - /////////////////////////////////////////////////////////////////////////////////////////////////// - void ComputeFrustumPlanes(vec_t* frustum, const float* clip) - { - frustum[0].x = clip[3] - clip[0]; - frustum[0].y = clip[7] - clip[4]; - frustum[0].z = clip[11] - clip[8]; - frustum[0].w = clip[15] - clip[12]; - - frustum[1].x = clip[3] + clip[0]; - frustum[1].y = clip[7] + clip[4]; - frustum[1].z = clip[11] + clip[8]; - frustum[1].w = clip[15] + clip[12]; - - frustum[2].x = clip[3] + clip[1]; - frustum[2].y = clip[7] + clip[5]; - frustum[2].z = clip[11] + clip[9]; - frustum[2].w = clip[15] + clip[13]; - - frustum[3].x = clip[3] - clip[1]; - frustum[3].y = clip[7] - clip[5]; - frustum[3].z = clip[11] - clip[9]; - frustum[3].w = clip[15] - clip[13]; - - frustum[4].x = clip[3] - clip[2]; - frustum[4].y = clip[7] - clip[6]; - frustum[4].z = clip[11] - clip[10]; - frustum[4].w = clip[15] - clip[14]; - - frustum[5].x = clip[3] + clip[2]; - frustum[5].y = clip[7] + clip[6]; - frustum[5].z = clip[11] + clip[10]; - frustum[5].w = clip[15] + clip[14]; - - for (int i = 0; i < 6; i++) - { - frustum[i].Normalize(); - } - } - - void DrawAxes(const float* view, const float* projection, const float* matrices, int matrixCount) - { - matrix_t viewM = *(matrix_t*)view; - matrix_t projM = *(matrix_t*)projection; - matrix_t viewProj = viewM * projM; - - // build frustum - vec_t frustum[6]; - ComputeFrustumPlanes(frustum, viewProj.m16); - - for (int i = 0; i < matrixCount; i++) - { - const float* matrix = &matrices[i * 16]; - matrix_t model = *(matrix_t*)matrix; - matrix_t mvp = model * viewProj; - - // world-space origin - vec_t origin; - origin.TransformPoint(vec_t(0.f, 0.f, 0.f), model); - - struct Axis - { - vec_t dir; - ImU32 color; - }; - - Axis axes[3] = { - { vec_t(1.f, 0.f, 0.f), IM_COL32(255, 0, 0, 255) }, // X - red - { vec_t(0.f, 1.f, 0.f), IM_COL32(0, 255, 0, 255) }, // Y - green - { vec_t(0.f, 0.f, 1.f), IM_COL32(0, 0, 255, 255) } // Z - blue - }; - - for (int a = 0; a < 3; a++) - { - vec_t endLocal = axes[a].dir; - - // world-space endpoint - vec_t end; - end.TransformPoint(endLocal, model); - - // frustum test - bool visible = true; - for (int f = 0; f < 6; f++) - { - float d0 = DistanceToPlane(origin, frustum[f]); - float d1 = DistanceToPlane(end, frustum[f]); - - // both outside - reject - if (d0 < 0.f && d1 < 0.f) - { - visible = false; - break; - } - } - - if (!visible) - { - continue; - } - - // project to screen - ImVec2 p0 = worldToPos(vec_t(0.f, 0.f, 0.f), mvp); - ImVec2 p1 = worldToPos(endLocal, mvp); - - // reject behind camera (clip space) - vec_t clip0, clip1; - clip0.TransformPoint(vec_t(0.f, 0.f, 0.f), mvp); - clip1.TransformPoint(endLocal, mvp); - - if (clip0.w <= 0.f && clip1.w <= 0.f) - { - continue; - } - - // draw - gContext.mDrawList->AddLine(p0, p1, axes[a].color, 2.0f); - } - } - } - - void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount) - { - matrix_t viewInverse; - viewInverse.Inverse(*(matrix_t*)view); - - struct CubeFace - { - float z; - ImVec2 faceCoordsScreen[4]; - ImU32 color; - }; - CubeFace* faces = (CubeFace*)_malloca(sizeof(CubeFace) * matrixCount * 6); - - if (!faces) - { - return; - } - - vec_t frustum[6]; - matrix_t viewProjection = *(matrix_t*)view * *(matrix_t*)projection; - ComputeFrustumPlanes(frustum, viewProjection.m16); - - int cubeFaceCount = 0; - for (int cube = 0; cube < matrixCount; cube++) - { - const float* matrix = &matrices[cube * 16]; - - matrix_t res = *(matrix_t*)matrix * *(matrix_t*)view * *(matrix_t*)projection; - - for (int iFace = 0; iFace < 6; iFace++) - { - const int normalIndex = (iFace % 3); - const int perpXIndex = (normalIndex + 1) % 3; - const int perpYIndex = (normalIndex + 2) % 3; - const float invert = (iFace > 2) ? -1.f : 1.f; - - const vec_t faceCoords[4] = { directionUnary[normalIndex] + directionUnary[perpXIndex] + directionUnary[perpYIndex], - directionUnary[normalIndex] + directionUnary[perpXIndex] - directionUnary[perpYIndex], - directionUnary[normalIndex] - directionUnary[perpXIndex] - directionUnary[perpYIndex], - directionUnary[normalIndex] - directionUnary[perpXIndex] + directionUnary[perpYIndex], - }; - - // clipping - /* - bool skipFace = false; - for (unsigned int iCoord = 0; iCoord < 4; iCoord++) - { - vec_t camSpacePosition; - camSpacePosition.TransformPoint(faceCoords[iCoord] * 0.5f * invert, res); - if (camSpacePosition.z < 0.001f) - { - skipFace = true; - break; - } - } - if (skipFace) - { - continue; - } - */ - vec_t centerPosition, centerPositionVP; - centerPosition.TransformPoint(directionUnary[normalIndex] * 0.5f * invert, *(matrix_t*)matrix); - centerPositionVP.TransformPoint(directionUnary[normalIndex] * 0.5f * invert, res); - - bool inFrustum = true; - for (int iFrustum = 0; iFrustum < 6; iFrustum++) - { - const vec_t& plane = frustum[iFrustum]; - - bool allOutside = true; - - for (unsigned int iCoord = 0; iCoord < 4; iCoord++) - { - vec_t worldPos; - worldPos.TransformPoint(faceCoords[iCoord] * 0.5f * invert, *(matrix_t*)matrix); - - if (DistanceToPlane(worldPos, plane) >= 0.f) - { - allOutside = false; - break; - } - } - - if (allOutside) - { - continue; // face is fully outside this plane - discard - } - } - - if (!inFrustum) - { - continue; - } - CubeFace& cubeFace = faces[cubeFaceCount]; - - // 3D->2D - //ImVec2 faceCoordsScreen[4]; - for (unsigned int iCoord = 0; iCoord < 4; iCoord++) - { - cubeFace.faceCoordsScreen[iCoord] = worldToPos(faceCoords[iCoord] * 0.5f * invert, res); - } - - ImU32 directionColor = GetColorU32(DIRECTION_X + normalIndex); - cubeFace.color = directionColor | IM_COL32(0x80, 0x80, 0x80, 0); - - cubeFace.z = centerPositionVP.z / centerPositionVP.w; - cubeFaceCount++; - } - } - qsort(faces, cubeFaceCount, sizeof(CubeFace), [](void const* _a, void const* _b) { - CubeFace* a = (CubeFace*)_a; - CubeFace* b = (CubeFace*)_b; - if (a->z < b->z) - { - return 1; - } - return -1; - }); - // draw face with lighter color - for (int iFace = 0; iFace < cubeFaceCount; iFace++) - { - const CubeFace& cubeFace = faces[iFace]; - gContext.mDrawList->AddConvexPolyFilled(cubeFace.faceCoordsScreen, 4, cubeFace.color); - } - - _freea(faces); - } - - void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize) - { - matrix_t viewProjection = *(matrix_t*)view * *(matrix_t*)projection; - vec_t frustum[6]; - ComputeFrustumPlanes(frustum, viewProjection.m16); - matrix_t res = *(matrix_t*)matrix * viewProjection; - - for (float f = -gridSize; f <= gridSize; f += 1.f) - { - for (int dir = 0; dir < 2; dir++) - { - vec_t ptA = makeVect(dir ? -gridSize : f, 0.f, dir ? f : -gridSize); - vec_t ptB = makeVect(dir ? gridSize : f, 0.f, dir ? f : gridSize); - bool visible = true; - for (int i = 0; i < 6; i++) - { - float dA = DistanceToPlane(ptA, frustum[i]); - float dB = DistanceToPlane(ptB, frustum[i]); - if (dA < 0.f && dB < 0.f) - { - visible = false; - break; - } - if (dA > 0.f && dB > 0.f) - { - continue; - } - if (dA < 0.f) - { - float len = fabsf(dA - dB); - float t = fabsf(dA) / len; - ptA.Lerp(ptB, t); - } - if (dB < 0.f) - { - float len = fabsf(dB - dA); - float t = fabsf(dB) / len; - ptB.Lerp(ptA, t); - } - } - if (visible) - { - ImU32 col = IM_COL32(0x80, 0x80, 0x80, 0xFF); - col = (fmodf(fabsf(f), 10.f) < FLT_EPSILON) ? IM_COL32(0x90, 0x90, 0x90, 0xFF) : col; - col = (fabsf(f) < FLT_EPSILON) ? IM_COL32(0x40, 0x40, 0x40, 0xFF): col; - - float thickness = 1.f; - thickness = (fmodf(fabsf(f), 10.f) < FLT_EPSILON) ? 1.5f : thickness; - thickness = (fabsf(f) < FLT_EPSILON) ? 2.3f : thickness; - - gContext.mDrawList->AddLine(worldToPos(ptA, res), worldToPos(ptB, res), col, thickness); - } - } - } - } - - void DrawGridCustom(const float* view, const float* projection, const float* matrix, const float gridSize, const float majorStep, const unsigned int subdivision) - { - const ImU32 majorCol = IM_COL32(0x80, 0x80, 0x80, 0xFF); - const ImU32 minorCol = IM_COL32(0x90, 0x90, 0x90, 0xFF); - const ImU32 centerCol = IM_COL32(0x40, 0x40, 0x40, 0xFF); - DrawGridCustomColor(view, projection, matrix, gridSize, majorStep, subdivision, majorCol, minorCol, centerCol); - } - - void DrawGridCustomColor(const float* view, const float* projection, const float* matrix, const float gridSize, const float majorStep, const unsigned int subdivision, const ImU32 majorCol, const ImU32 minorCol, const ImU32 centerCol) - { - // Must have at least 1 subdivision - IM_ASSERT(subdivision > 0 && "At least 1 segment required!"); - - matrix_t viewProjection = *(matrix_t*)view * *(matrix_t*)projection; - - vec_t frustum[6]; - ComputeFrustumPlanes(frustum, viewProjection.m16); - - matrix_t res = *(matrix_t*)matrix * viewProjection; - - const float minorStep = majorStep / (float)subdivision; - const int lineCount = (int)ceilf(gridSize / minorStep); - - for (int i = -lineCount; i <= lineCount; i++) - { - float f = i * minorStep; - - const bool isMajor = (i % (int)subdivision) == 0; - const bool isCenter = (i == 0); - - // Styling - ImU32 col = minorCol; - if (isMajor) - col = majorCol; - if (isCenter) - col = centerCol; - - float thickness = 1.0f; - if (isMajor) - thickness = 1.5f; - if (isCenter) - thickness = 2.3f; - - for (int dir = 0; dir < 2; dir++) - { - vec_t ptA = makeVect(dir ? -gridSize : f, 0.f, dir ? f : -gridSize); - vec_t ptB = makeVect(dir ? gridSize : f, 0.f, dir ? f : gridSize); - - bool visible = true; - - // Frustum clipping - for (int p = 0; p < 6; p++) - { - float dA = DistanceToPlane(ptA, frustum[p]); - float dB = DistanceToPlane(ptB, frustum[p]); - - if (dA < 0.f && dB < 0.f) - { - visible = false; - break; - } - - if (dA > 0.f && dB > 0.f) - continue; - - if (dA < 0.f) - { - float t = fabsf(dA) / fabsf(dA - dB); - ptA.Lerp(ptB, t); - } - - if (dB < 0.f) - { - float t = fabsf(dB) / fabsf(dB - dA); - ptB.Lerp(ptA, t); - } - } - - if (visible) - { - gContext.mDrawList->AddLine( - worldToPos(ptA, res), - worldToPos(ptB, res), - col, - thickness); - } - } - } - } - - void ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor) - { - // Scale is always local or matrix will be skewed when applying world scale or oriented matrix - ComputeContext(view, projection, matrix, (operation & SCALE) ? LOCAL : mode); - ViewManipulate(view, length, position, size, backgroundColor); - } - - void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor) - { - // State is bound to the current id (PushID/PopID) so multiple view cubes are independent. - ViewManipulateState& vms = gContext.GetViewManipulateState(); - bool& isDraging = vms.mIsDragging; - bool& isClicking = vms.mIsClicking; - vec_t& interpolationUp = vms.mInterpolationUp; - vec_t& interpolationDir = vms.mInterpolationDir; - int& interpolationFrames = vms.mInterpolationFrames; - const vec_t referenceUp = makeVect(0.f, 1.f, 0.f); - - // Recompute hovering for this widget's own window instead of relying on the last - // Manipulate() call, otherwise only the most recently drawn view would react. - gContext.mbMouseOver = IsHoveringWindow(); - - matrix_t svgView, svgProjection; - svgView = gContext.mViewMat; - svgProjection = gContext.mProjectionMat; - - ImGuiIO& io = ImGui::GetIO(); - const bool viewManipulateHovered = gContext.mbMouseOver && ImRect(position, position + size).Contains(io.MousePos); - gContext.mDrawList->AddRectFilled(position, position + size, backgroundColor); - matrix_t viewInverse; - viewInverse.Inverse(*(matrix_t*)view); - const bool rightHanded = gContext.mProjectionMat.m[2][3] < 0.f; - const float handednessSign = rightHanded ? 1.f : -1.f; - const vec_t camTarget = viewInverse.v.position - viewInverse.v.dir * handednessSign * length; - - // view/projection matrices - const float distance = 3.f; - matrix_t cubeProjection, cubeView; - float fov = acosf(distance / (sqrtf(distance * distance + 3.f))) * RAD2DEG; - Perspective(fov / sqrtf(2.f), size.x / size.y, 0.01f, 1000.f, cubeProjection.m16, rightHanded); - - vec_t dir = makeVect(viewInverse.m[2][0], viewInverse.m[2][1], viewInverse.m[2][2]); - vec_t up = makeVect(viewInverse.m[1][0], viewInverse.m[1][1], viewInverse.m[1][2]); - vec_t eye = dir * handednessSign * distance; - vec_t zero = makeVect(0.f, 0.f); - LookAt(&eye.x, &zero.x, &up.x, cubeView.m16, rightHanded); - - // set context - gContext.mViewMat = cubeView; - gContext.mProjectionMat = cubeProjection; - ComputeCameraRay(gContext.mRayOrigin, gContext.mRayVector, position, size); - - const matrix_t res = cubeView * cubeProjection; - - // panels - static const ImVec2 panelPosition[9] = { ImVec2(0.75f,0.75f), ImVec2(0.25f, 0.75f), ImVec2(0.f, 0.75f), - ImVec2(0.75f, 0.25f), ImVec2(0.25f, 0.25f), ImVec2(0.f, 0.25f), - ImVec2(0.75f, 0.f), ImVec2(0.25f, 0.f), ImVec2(0.f, 0.f) }; - - static const ImVec2 panelSize[9] = { ImVec2(0.25f,0.25f), ImVec2(0.5f, 0.25f), ImVec2(0.25f, 0.25f), - ImVec2(0.25f, 0.5f), ImVec2(0.5f, 0.5f), ImVec2(0.25f, 0.5f), - ImVec2(0.25f, 0.25f), ImVec2(0.5f, 0.25f), ImVec2(0.25f, 0.25f) }; - - // tag faces - bool boxes[27]{}; - static int overBox = -1; - for (int iPass = 0; iPass < 2; iPass++) - { - for (int iFace = 0; iFace < 6; iFace++) - { - const int normalIndex = (iFace % 3); - const int perpXIndex = (normalIndex + 1) % 3; - const int perpYIndex = (normalIndex + 2) % 3; - const float invert = (iFace > 2) ? -1.f : 1.f; - const vec_t indexVectorX = directionUnary[perpXIndex] * invert; - const vec_t indexVectorY = directionUnary[perpYIndex] * invert; - const vec_t boxOrigin = directionUnary[normalIndex] * -invert - indexVectorX - indexVectorY; - - // plan local space - const vec_t n = directionUnary[normalIndex] * invert; - vec_t viewSpaceNormal = n; - vec_t viewSpacePoint = n * 0.5f; - viewSpaceNormal.TransformVector(cubeView); - viewSpaceNormal.Normalize(); - viewSpacePoint.TransformPoint(cubeView); - const vec_t viewSpaceFacePlan = BuildPlan(viewSpacePoint, viewSpaceNormal); - - // back face culling - if (viewSpaceFacePlan.w > 0.f) - { - continue; - } - - const vec_t facePlan = BuildPlan(n * 0.5f, n); - - const float len = IntersectRayPlane(gContext.mRayOrigin, gContext.mRayVector, facePlan); - vec_t posOnPlan = gContext.mRayOrigin + gContext.mRayVector * len - (n * 0.5f); - - float localx = Dot(directionUnary[perpXIndex], posOnPlan) * invert + 0.5f; - float localy = Dot(directionUnary[perpYIndex], posOnPlan) * invert + 0.5f; - - // panels - const vec_t dx = directionUnary[perpXIndex]; - const vec_t dy = directionUnary[perpYIndex]; - const vec_t origin = directionUnary[normalIndex] - dx - dy; - for (int iPanel = 0; iPanel < 9; iPanel++) - { - vec_t boxCoord = boxOrigin + indexVectorX * float(iPanel % 3) + indexVectorY * float(iPanel / 3) + makeVect(1.f, 1.f, 1.f); - const ImVec2 p = panelPosition[iPanel] * 2.f; - const ImVec2 s = panelSize[iPanel] * 2.f; - ImVec2 faceCoordsScreen[4]; - vec_t panelPos[4] = { dx * p.x + dy * p.y, - dx * p.x + dy * (p.y + s.y), - dx * (p.x + s.x) + dy * (p.y + s.y), - dx * (p.x + s.x) + dy * p.y }; - - for (unsigned int iCoord = 0; iCoord < 4; iCoord++) - { - faceCoordsScreen[iCoord] = worldToPos((panelPos[iCoord] + origin) * 0.5f * invert, res, position, size); - } - - const ImVec2 panelCorners[2] = { panelPosition[iPanel], panelPosition[iPanel] + panelSize[iPanel] }; - bool insidePanel = localx > panelCorners[0].x && localx < panelCorners[1].x && localy > panelCorners[0].y && localy < panelCorners[1].y; - int boxCoordInt = int(boxCoord.x * 9.f + boxCoord.y * 3.f + boxCoord.z); - IM_ASSERT(boxCoordInt < 27); - boxes[boxCoordInt] |= insidePanel && (!isDraging) && gContext.mbMouseOver; - - // draw face with lighter color - if (iPass) - { - ImU32 directionColor = GetColorU32(DIRECTION_X + normalIndex); - gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, (directionColor | IM_COL32(0x80, 0x80, 0x80, 0x80)) | (viewManipulateHovered ? IM_COL32(0x08, 0x08, 0x08, 0) : 0)); - if (boxes[boxCoordInt]) - { - ImU32 selectionColor = GetColorU32(SELECTION); - gContext.mDrawList->AddConvexPolyFilled(faceCoordsScreen, 4, selectionColor); - - if (io.MouseDown[0] && !isClicking && !isDraging && GImGui->ActiveId == 0) { - overBox = boxCoordInt; - isClicking = true; - isDraging = true; - } - } - } - } - } - } - if (interpolationFrames) - { - interpolationFrames--; - vec_t newDir = viewInverse.v.dir * handednessSign; - newDir.Lerp(interpolationDir * handednessSign, 0.2f); - newDir.Normalize(); - - vec_t newUp = viewInverse.v.up; - newUp.Lerp(interpolationUp, 0.3f); - newUp.Normalize(); - newUp = interpolationUp; - vec_t newEye = camTarget + newDir * length; - LookAt(&newEye.x, &camTarget.x, &newUp.x, view, rightHanded); - } - gContext.mIsViewManipulatorHovered |= viewManipulateHovered; - - if (io.MouseDown[0] && (fabsf(io.MouseDelta[0]) || fabsf(io.MouseDelta[1])) && isClicking) - { - isClicking = false; - } - - if (!io.MouseDown[0]) - { - if (isClicking) - { - // apply new view direction - int cx = overBox / 9; - int cy = (overBox - cx * 9) / 3; - int cz = overBox % 3; - interpolationDir = makeVect(1.f - (float)cx, 1.f - (float)cy, 1.f - (float)cz) * handednessSign; - interpolationDir.Normalize(); - - if (fabsf(Dot(interpolationDir, referenceUp)) > 1.0f - 0.01f) - { - vec_t right = viewInverse.v.right; - if (fabsf(right.x) > fabsf(right.z)) - { - right.z = 0.f; - } - else - { - right.x = 0.f; - } - right.Normalize(); - interpolationUp = Cross(interpolationDir * handednessSign, right); - interpolationUp.Normalize(); - } - else - { - interpolationUp = referenceUp; - } - interpolationFrames = 40; - - } - isClicking = false; - isDraging = false; - } - - - if (isDraging) - { - matrix_t rx, ry, roll; - - rx.RotationAxis(referenceUp, -io.MouseDelta.x * 0.01f * handednessSign); - ry.RotationAxis(viewInverse.v.right, -io.MouseDelta.y * 0.01f * handednessSign); - - roll = rx * ry; - - vec_t newDir = viewInverse.v.dir; - newDir.TransformVector(roll); - newDir.Normalize(); - - // clamp - vec_t planDir = Cross(viewInverse.v.right, referenceUp); - planDir.y = 0.f; - planDir.Normalize(); - float dt = Dot(planDir, newDir); - if (dt < 0.0f) - { - newDir += planDir * dt; - newDir.Normalize(); - } - - vec_t newEye = camTarget + newDir * handednessSign * length; - LookAt(&newEye.x, &camTarget.x, &referenceUp.x, view, rightHanded); - } - - const bool thisUsingViewManipulate = (interpolationFrames != 0) || isDraging; - gContext.mbUsingViewManipulate |= thisUsingViewManipulate; - if (isClicking || thisUsingViewManipulate || viewManipulateHovered) { -#if IMGUI_VERSION_NUM >= 18723 - ImGui::SetNextFrameWantCaptureMouse(true); -#else - ImGui::CaptureMouseFromApp(); -#endif - } - - // restore view/projection because it was used to compute ray - ComputeContext(svgView.m16, svgProjection.m16, gContext.mModelSource.m16, gContext.mMode); - } -}; diff --git a/extern/imguizmo/ImGuizmo.h b/extern/imguizmo/ImGuizmo.h deleted file mode 100644 index ab893f1..0000000 --- a/extern/imguizmo/ImGuizmo.h +++ /dev/null @@ -1,348 +0,0 @@ -// https://github.com/CedricGuillemet/ImGuizmo -// v1.92.5 WIP -// -// The MIT License(MIT) -// -// Copyright(c) 2016-2026 Cedric Guillemet and contributors -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files(the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions : -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// ------------------------------------------------------------------------------------------- -// History : -// 2026/05/03 v1.9 release. CMake build system, vcpkg support, many fixes and new features from contributors. -// 2019/11/03 View gizmo -// 2016/09/11 Behind camera culling. Scaling Delta matrix not multiplied by source matrix scales. local/world rotation and translation fixed. Display message is incorrect (X: ... Y:...) in local mode. -// 2016/09/09 Hatched negative axis. Snapping. Documentation update. -// 2016/09/04 Axis switch and translation plan autohiding. Scale transform stability improved -// 2016/09/01 Mogwai changed to Manipulate. Draw debug cube. Fixed inverted scale. Mixing scale and translation/rotation gives bad results. -// 2016/08/31 First version -// -// ------------------------------------------------------------------------------------------- -// Future (no order): -// -// - Multi view -// - display rotation/translation/scale infos in local/world space and not only local -// - finish local/world matrix application -// - OPERATION as bitmask -// -// ------------------------------------------------------------------------------------------- -// Example -#if 0 -void EditTransform(const Camera& camera, matrix_t& matrix) -{ - static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::ROTATE); - static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD); - if (ImGui::IsKeyPressed(90)) - mCurrentGizmoOperation = ImGuizmo::TRANSLATE; - if (ImGui::IsKeyPressed(69)) - mCurrentGizmoOperation = ImGuizmo::ROTATE; - if (ImGui::IsKeyPressed(82)) // r Key - mCurrentGizmoOperation = ImGuizmo::SCALE; - if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) - mCurrentGizmoOperation = ImGuizmo::TRANSLATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE)) - mCurrentGizmoOperation = ImGuizmo::ROTATE; - ImGui::SameLine(); - if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE)) - mCurrentGizmoOperation = ImGuizmo::SCALE; - float matrixTranslation[3], matrixRotation[3], matrixScale[3]; - ImGuizmo::DecomposeMatrixToComponents(matrix.m16, matrixTranslation, matrixRotation, matrixScale); - ImGui::InputFloat3("Tr", matrixTranslation, 3); - ImGui::InputFloat3("Rt", matrixRotation, 3); - ImGui::InputFloat3("Sc", matrixScale, 3); - ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, matrix.m16); - - if (mCurrentGizmoOperation != ImGuizmo::SCALE) - { - if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL)) - mCurrentGizmoMode = ImGuizmo::LOCAL; - ImGui::SameLine(); - if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD)) - mCurrentGizmoMode = ImGuizmo::WORLD; - } - static bool useSnap(false); - if (ImGui::IsKeyPressed(83)) - useSnap = !useSnap; - ImGui::Checkbox("", &useSnap); - ImGui::SameLine(); - vec_t snap; - switch (mCurrentGizmoOperation) - { - case ImGuizmo::TRANSLATE: - snap = config.mSnapTranslation; - ImGui::InputFloat3("Snap", &snap.x); - break; - case ImGuizmo::ROTATE: - snap = config.mSnapRotation; - ImGui::InputFloat("Angle Snap", &snap.x); - break; - case ImGuizmo::SCALE: - snap = config.mSnapScale; - ImGui::InputFloat("Scale Snap", &snap.x); - break; - } - ImGuiIO& io = ImGui::GetIO(); - ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); - ImGuizmo::Manipulate(camera.mView.m16, camera.mProjection.m16, mCurrentGizmoOperation, mCurrentGizmoMode, matrix.m16, NULL, useSnap ? &snap.x : NULL); -} -#endif -#pragma once - -#ifdef USE_IMGUI_API -#include "imconfig.h" -#endif -#ifndef IMGUI_API -#define IMGUI_API -#endif - -#ifndef IMGUIZMO_NAMESPACE -#define IMGUIZMO_NAMESPACE ImGuizmo -#endif - -struct ImGuiWindow; - -namespace IMGUIZMO_NAMESPACE -{ - // call inside your own window and before Manipulate() in order to draw gizmo to that window. - // Or pass a specific ImDrawList to draw to (e.g. ImGui::GetForegroundDrawList()). - IMGUI_API void SetDrawlist(ImDrawList* drawlist = nullptr); - - // call BeginFrame right after ImGui_XXXX_NewFrame(); - IMGUI_API void BeginFrame(); - - // this is necessary because when imguizmo is compiled into a dll, and imgui into another - // globals are not shared between them. - // More details at https://stackoverflow.com/questions/19373061/what-happens-to-global-and-static-variables-in-a-shared-library-when-it-is-dynam - // expose method to set imgui context - IMGUI_API void SetImGuiContext(ImGuiContext* ctx); - - // return true if mouse cursor is over any gizmo control (axis, plan or screen component) - IMGUI_API bool IsOver(); - - // return true if mouse IsOver or if the gizmo is in moving state - IMGUI_API bool IsUsing(); - - // return true if the view gizmo is in moving state - IMGUI_API bool IsUsingViewManipulate(); - // only check if your mouse is over the view manipulator - no matter whether it's active or not - IMGUI_API bool IsViewManipulateHovered(); - - // return true if any gizmo is in moving state - IMGUI_API bool IsUsingAny(); - - // enable/disable the gizmo. Stay in the state until next call to Enable. - // gizmo is rendered with gray half transparent color when disabled - IMGUI_API void Enable(bool enable); - - // helper functions for manualy editing translation/rotation/scale with an input float - // translation, rotation and scale float points to 3 floats each - // Angles are in degrees (more suitable for human editing) - // example: - // float matrixTranslation[3], matrixRotation[3], matrixScale[3]; - // ImGuizmo::DecomposeMatrixToComponents(gizmoMatrix.m16, matrixTranslation, matrixRotation, matrixScale); - // ImGui::InputFloat3("Tr", matrixTranslation, 3); - // ImGui::InputFloat3("Rt", matrixRotation, 3); - // ImGui::InputFloat3("Sc", matrixScale, 3); - // ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, gizmoMatrix.m16); - // - // These functions have some numerical stability issues for now. Use with caution. - IMGUI_API void DecomposeMatrixToComponents(const float* matrix, float* translation, float* rotation, float* scale); - IMGUI_API void RecomposeMatrixFromComponents(const float* translation, const float* rotation, const float* scale, float* matrix); - - IMGUI_API void SetRect(float x, float y, float width, float height); - // default is false - IMGUI_API void SetOrthographic(bool isOrthographic); - - // Render coordinate system axes (red X, green Y and blue Z). Usefull for debug/tests - IMGUI_API void DrawAxes(const float* view, const float* projection, const float* matrices, int matrixCount); - // Render a cube with face color corresponding to face normal. Usefull for debug/tests - IMGUI_API void DrawCubes(const float* view, const float* projection, const float* matrices, int matrixCount); - IMGUI_API void DrawGrid(const float* view, const float* projection, const float* matrix, const float gridSize); - // Render grid with customizable major line step and amount of segments between major lines. - // NOTE(m.wlasiuk) : calling this function with majorStep = 1.0f and subdivision = 1 is equivalent to DrawGrid in terms of the end result but performs more calculations - IMGUI_API void DrawGridCustom(const float* view, const float* projection, const float* matrix, const float gridSize, const float majorStep, const unsigned int subdivision); - // Render grid with customizable major line step and amount of segments between major lines and with possibility to set custom colors for major, minor and center lines - IMGUI_API void DrawGridCustomColor(const float* view, const float* projection, const float* matrix, const float gridSize, const float majorStep, const unsigned int subdivision, const ImU32 majorCol, const ImU32 minorCol, const ImU32 centerCol); - - // call it when you want a gizmo - // Needs view and projection matrices. - // matrix parameter is the source matrix (where will be gizmo be drawn) and might be transformed by the function. Return deltaMatrix is optional - // translation is applied in world space - enum OPERATION - { - TRANSLATE_X = (1u << 0), - TRANSLATE_Y = (1u << 1), - TRANSLATE_Z = (1u << 2), - ROTATE_X = (1u << 3), - ROTATE_Y = (1u << 4), - ROTATE_Z = (1u << 5), - ROTATE_SCREEN = (1u << 6), - SCALE_X = (1u << 7), - SCALE_Y = (1u << 8), - SCALE_Z = (1u << 9), - BOUNDS = (1u << 10), - SCALE_XU = (1u << 11), - SCALE_YU = (1u << 12), - SCALE_ZU = (1u << 13), - - TRANSLATE = TRANSLATE_X | TRANSLATE_Y | TRANSLATE_Z, - ROTATE = ROTATE_X | ROTATE_Y | ROTATE_Z | ROTATE_SCREEN, - SCALE = SCALE_X | SCALE_Y | SCALE_Z, - SCALEU = SCALE_XU | SCALE_YU | SCALE_ZU, // universal - UNIVERSAL = TRANSLATE | ROTATE | SCALEU - }; - - inline OPERATION operator|(OPERATION lhs, OPERATION rhs) - { - return static_cast(static_cast(lhs) | static_cast(rhs)); - } - - enum MODE - { - LOCAL, - WORLD - }; - - IMGUI_API bool Manipulate(const float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float* deltaMatrix = NULL, const float* snap = NULL, const float* localBounds = NULL, const float* boundsSnap = NULL); - // - // Please note that this cubeview is patented by Autodesk : https://patents.google.com/patent/US7782319B2/en - // It seems to be a defensive patent in the US. I don't think it will bring troubles using it as - // other software are using the same mechanics. But just in case, you are now warned! - // - IMGUI_API void ViewManipulate(float* view, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor); - - // use this version if you did not call Manipulate before and you are just using ViewManipulate - IMGUI_API void ViewManipulate(float* view, const float* projection, OPERATION operation, MODE mode, float* matrix, float length, ImVec2 position, ImVec2 size, ImU32 backgroundColor); - - IMGUI_API void SetAlternativeWindow(ImGuiWindow* window); - - [[deprecated("Use PushID/PopID instead.")]] - IMGUI_API void SetID(int id); - - // ID stack/scopes - // Read the FAQ (docs/FAQ.md or http://dearimgui.org/faq) for more details about how ID are handled in dear imgui. - // - Those questions are answered and impacted by understanding of the ID stack system: - // - "Q: Why is my widget not reacting when I click on it?" - // - "Q: How can I have widgets with an empty label?" - // - "Q: How can I have multiple widgets with the same label?" - // - Short version: ID are hashes of the entire ID stack. If you are creating widgets in a loop you most likely - // want to push a unique identifier (e.g. object pointer, loop index) to uniquely differentiate them. - // - You can also use the "Label##foobar" syntax within widget label to distinguish them from each others. - // - In this header file we use the "label"/"name" terminology to denote a string that will be displayed + used as an ID, - // whereas "str_id" denote a string that is only used as an ID and not normally displayed. - IMGUI_API void PushID(const char* str_id); // push string into the ID stack (will hash string). - IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end); // push string into the ID stack (will hash string). - IMGUI_API void PushID(const void* ptr_id); // push pointer into the ID stack (will hash pointer). - IMGUI_API void PushID(int int_id); // push integer into the ID stack (will hash integer). - IMGUI_API void PopID(); // pop from the ID stack. - IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). e.g. if you want to query into ImGuiStorage yourself - IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end); - IMGUI_API ImGuiID GetID(const void* ptr_id); - - // return true if the cursor is over the operation's gizmo - IMGUI_API bool IsOver(OPERATION op); - IMGUI_API void SetGizmoSizeClipSpace(float value); - - // Handle type used by the translate/rotate/scale gizmos. - enum MOVETYPE - { - MT_NONE, - MT_MOVE_X, - MT_MOVE_Y, - MT_MOVE_Z, - MT_MOVE_YZ, - MT_MOVE_ZX, - MT_MOVE_XY, - MT_MOVE_SCREEN, - MT_ROTATE_X, - MT_ROTATE_Y, - MT_ROTATE_Z, - MT_ROTATE_SCREEN, - MT_SCALE_X, - MT_SCALE_Y, - MT_SCALE_Z, - MT_SCALE_XYZ - }; - - // Returns which handle is actively being dragged, or MT_NONE. - IMGUI_API MOVETYPE GetActiveHandleType(); - // Returns which handle is currently hovered, or MT_NONE. - IMGUI_API MOVETYPE GetHoveredHandleType(); - // Aliases matching the MOVETYPE enum name. - IMGUI_API MOVETYPE GetActiveMoveType(); - IMGUI_API MOVETYPE GetHoveredMoveType(); - - // Allow axis to flip - // When true (default), the guizmo axis flip for better visibility - // When false, they always stay along the positive world/local axis - IMGUI_API void AllowAxisFlip(bool value); - - // Configure the limit where axis are hidden - IMGUI_API void SetAxisLimit(float value); - // Set an axis mask to permanently hide a given axis (true -> hidden, false -> shown) - IMGUI_API void SetAxisMask(bool x, bool y, bool z); - // Configure the limit where planes are hiden - IMGUI_API void SetPlaneLimit(float value); - // from a x,y,z point in space and using Manipulation view/projection matrix, check if mouse is in pixel radius distance of that projected point - IMGUI_API bool IsOver(float* position, float pixelRadius); - - // Compute the world-space mouse picking ray from explicit inputs, without reading ImGui IO. - // Useful for tests/headless usage. view and projection are column-major float[16] (same - // layout as Manipulate). rayOrigin and rayDirection receive a float[3] each. - IMGUI_API void ComputeMouseRay(const float* view, const float* projection, const ImVec2& mousePosition, const ImVec2& rectPosition, const ImVec2& rectSize, float* rayOrigin, float* rayDirection); - - enum COLOR - { - DIRECTION_X, // directionColor[0] - DIRECTION_Y, // directionColor[1] - DIRECTION_Z, // directionColor[2] - PLANE_X, // planeColor[0] - PLANE_Y, // planeColor[1] - PLANE_Z, // planeColor[2] - SELECTION, // selectionColor - INACTIVE, // inactiveColor - TRANSLATION_LINE, // translationLineColor - SCALE_LINE, - ROTATION_USING_BORDER, - ROTATION_USING_FILL, - HATCHED_AXIS_LINES, - TEXT, - TEXT_SHADOW, - COUNT - }; - - struct Style - { - IMGUI_API Style(); - - float TranslationLineThickness; // Thickness of lines for translation gizmo - float TranslationLineArrowSize; // Size of arrow at the end of lines for translation gizmo - float RotationLineThickness; // Thickness of lines for rotation gizmo - float RotationOuterLineThickness; // Thickness of line surrounding the rotation gizmo - float ScaleLineThickness; // Thickness of lines for scale gizmo - float ScaleLineCircleSize; // Size of circle at the end of lines for scale gizmo - float HatchedAxisLineThickness; // Thickness of hatched axis lines - float CenterCircleSize; // Size of circle at the center of the translate/scale gizmo - - ImVec4 Colors[COLOR::COUNT]; - }; - - IMGUI_API Style& GetStyle(); -} diff --git a/extern/imguizmo/LICENSE b/extern/imguizmo/LICENSE deleted file mode 100644 index dcbee45..0000000 --- a/extern/imguizmo/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Cedric Guillemet - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/extern/sokol/sokol_app.h b/extern/sokol/sokol_app.h index 8ab8baf..37dcc38 100644 --- a/extern/sokol/sokol_app.h +++ b/extern/sokol/sokol_app.h @@ -5893,9 +5893,7 @@ _SOKOL_PRIVATE void _sapp_macos_frame(void) { [NSApp activateIgnoringOtherApps:YES]; [_sapp.macos.window makeKeyAndOrderFront:nil]; _sapp_macos_update_dimensions(); - - // See https://github.com/erincatto/box3d/issues/37 - // [NSEvent setMouseCoalescingEnabled:NO]; + [NSEvent setMouseCoalescingEnabled:NO]; // workaround for window not being focused during a long init callback // for details see: https://github.com/floooh/sokol/pull/982 diff --git a/include/box3d/base.h b/include/box3d/base.h index 8ae8e05..2c0bb93 100644 --- a/include/box3d/base.h +++ b/include/box3d/base.h @@ -4,7 +4,6 @@ #pragma once #include -#include #include // Compile-time options. Edit box3d/config.h, or define BOX3D_USER_CONFIG to @@ -39,7 +38,7 @@ #ifdef __cplusplus #define B3_API extern "C" BOX3D_EXPORT #define B3_INLINE inline - #define B3_ALIGN_AS(N) alignas(N) + #if defined( _MSC_VER ) #define B3_FORCE_INLINE __forceinline #elif defined( __GNUC__ ) || defined( __clang__ ) @@ -53,7 +52,6 @@ #else #define B3_API BOX3D_EXPORT #define B3_INLINE static inline - #define B3_ALIGN_AS(N) _Alignas(N) #if defined( _MSC_VER ) #define B3_FORCE_INLINE static __forceinline @@ -69,13 +67,6 @@ #endif // clang-format on -// This is used to validate arguments for functions similar to printf. -#if defined( __GNUC__ ) || defined( __clang__ ) -#define B3_PRINTF_FORMAT( INDEX1, INDEX2 ) __attribute__( ( format( printf, INDEX1, INDEX2 ) ) ) -#else -#define B3_PRINTF_FORMAT( INDEX1, INDEX2 ) -#endif - #if defined( BOX3D_VALIDATE ) && !defined( NDEBUG ) #define B3_ENABLE_VALIDATION 1 #else @@ -94,12 +85,11 @@ /// Prototype for user allocation function. /// @param size the allocation size in bytes /// @param alignment the required alignment, guaranteed to be a power of 2 -typedef void* b3AllocFcn( size_t size, int32_t alignment ); +typedef void* b3AllocFcn( int32_t size, int32_t alignment ); /// Prototype for user free function. /// @param mem the memory previously allocated through `b3AllocFcn` -/// @param size the size of the allocation in bytes. -typedef void b3FreeFcn( void* mem, size_t size ); +typedef void b3FreeFcn( void* mem ); /// Prototype for the user assert callback. Return 0 to skip the debugger break. typedef int b3AssertFcn( const char* condition, const char* fileName, int lineNumber ); @@ -112,7 +102,7 @@ typedef void b3LogFcn( const char* message ); B3_API void b3SetAllocator( b3AllocFcn* allocFcn, b3FreeFcn* freeFcn ); /// Total bytes allocated by Box3D -B3_API int64_t b3GetByteCount( void ); +B3_API int32_t b3GetByteCount( void ); /// Override the default assert callback. /// @param assertFcn a non-null assert callback @@ -134,7 +124,7 @@ B3_API void b3SetAssertFcn( b3AssertFcn* assertFcn ); /// Internal assertion handler. Allows for host intervention. B3_API int b3InternalAssert( const char* condition, const char* fileName, int lineNumber ); /// Assert that a condition is true. -#define B3_ASSERT( condition ) \ +#define B3_ASSERT( condition ) \ ( (void)( ( !!( condition ) ) || ( b3InternalAssert( #condition, __FILE__, (int)( __LINE__ ) ), 0 ) ) ) #else #define B3_ASSERT( ... ) ( (void)0 ) @@ -173,13 +163,6 @@ B3_API b3Version b3GetVersion( void ); /// @return true if the library was built with BOX3D_DOUBLE_PRECISION (large world mode) B3_API bool b3IsDoublePrecision( void ); -/// @return the value of B3_MAX_MANIFOLD_POINTS the library was compiled with. Useful for -/// an ABI test. -B3_API int b3GetMaxManifoldPoints( void ); - -/// @return true if the current CPU has the AVX2 instruction set. -B3_API bool b3IsAVX2Available( void ); - /**@}*/ //! @cond @@ -203,4 +186,8 @@ B3_API void b3Sleep( int milliseconds ); #define B3_HASH_INIT 5381 B3_API uint32_t b3Hash( uint32_t hash, const uint8_t* data, int count ); +// Dump file support functions +B3_API void b3WriteBinaryFile( void* data, int size, const char* fileName ); +B3_API void* b3ReadBinaryFile( const char* prefix, const char* fileName, int* memSize ); + //! @endcond diff --git a/include/box3d/box3d.h b/include/box3d/box3d.h index ae107fa..2275663 100644 --- a/include/box3d/box3d.h +++ b/include/box3d/box3d.h @@ -15,10 +15,10 @@ * @defgroup world World * These functions allow you to create a simulation world. * - * You can add rigid bodies and joint constraints to the world and run the simulation. You can get - * contact information to get contact points and normals as well as events. You can query the world, - * checking for overlaps and casting rays or shapes. There is also debugging information such as - * debug draw, timing information, and counters. You can find documentation here: https://box2d.org/ + * You can add rigid bodies and joint constraints to the world and run the simulation. You can get contact + * information to get contact points and normals as well as events. You can query the world, checking for overlaps and casting + * rays or shapes. There is also debugging information such as debug draw, timing information, and counters. You can find + * documentation here: https://box2d.org/ * @{ */ @@ -29,9 +29,8 @@ #define b3CreateWorld b3CreateWorldDoublePrecision #endif -/// Create a world for rigid body simulation. A world contains bodies, shapes, and constraints. You -/// may create up to 128 worlds. Each world is completely independent and may be simulated in -/// parallel. +/// Create a world for rigid body simulation. A world contains bodies, shapes, and constraints. You may create +/// up to 128 worlds. Each world is completely independent and may be simulated in parallel. /// @return the world id. B3_API b3WorldId b3CreateWorld( const b3WorldDef* def ); @@ -47,57 +46,42 @@ B3_API int b3GetMaxWorldCount( void ); /// World id validation. Provides validation for up to 64K allocations. B3_API bool b3World_IsValid( b3WorldId id ); -/// Simulate a world for one time step. This performs collision detection, integration, and -/// constraint solution. A time step of zero runs the broad-phase and collision, but skips the -/// solver. So you can still get contact and sensor events. +/// Simulate a world for one time step. This performs collision detection, integration, and constraint solution. /// @param worldId The world to simulate /// @param timeStep The amount of time to simulate, this should be a fixed number. Usually 1/60. -/// @param subStepCount The number of sub-steps, increasing the sub-step count can increase -/// accuracy. Usually 4. +/// @param subStepCount The number of sub-steps, increasing the sub-step count can increase accuracy. Usually 4. B3_API void b3World_Step( b3WorldId worldId, float timeStep, int subStepCount ); -/// The pull model for tasking. Instead of getting task callbacks from b3World_Step you can call -/// this to kick off a step and get an array of tasks to execute. -B3_API b3TaskBatch b3World_BeginStep( b3WorldId worldId, float timeStep, int subStepCount ); - -/// Call this after executing each task batch. The step is done when the batch is empty. -B3_API b3TaskBatch b3World_ContinueStep( b3WorldId worldId ); - /// Call this to draw shapes and other debug draw data B3_API void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ); -/// Get the world's bounds. This is the bounding box that covers the current simulation. May have a -/// small amount of padding. +/// Get the world's bounds. This is the bounding box that covers the current simulation. May have a small +/// amount of padding. B3_API b3AABB b3World_GetBounds( b3WorldId worldId ); -/// Get the body events for the current time step. The event data is transient. Do not store a -/// reference to this data. +/// Get the body events for the current time step. The event data is transient. Do not store a reference to this data. B3_API b3BodyEvents b3World_GetBodyEvents( b3WorldId worldId ); -/// Get sensor events for the current time step. The event data is transient. Do not store a -/// reference to this data. +/// Get sensor events for the current time step. The event data is transient. Do not store a reference to this data. B3_API b3SensorEvents b3World_GetSensorEvents( b3WorldId worldId ); -/// Get contact events for this current time step. The event data is transient. Do not store a -/// reference to this data. +/// Get contact events for this current time step. The event data is transient. Do not store a reference to this data. B3_API b3ContactEvents b3World_GetContactEvents( b3WorldId worldId ); -/// Get the joint events for the current time step. The event data is transient. Do not store a -/// reference to this data. +/// Get the joint events for the current time step. The event data is transient. Do not store a reference to this data. B3_API b3JointEvents b3World_GetJointEvents( b3WorldId worldId ); -/// Overlap test for all shapes that *potentially* overlap the provided AABB. +/// Overlap test for all shapes that *potentially* overlap the provided AABB B3_API b3TreeStats b3World_OverlapAABB( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context ); /// Overlap test for all shapes that overlap the provided shape proxy. The proxy points are relative /// to the world origin, which lets the query stay precise far from the world origin. -B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, - b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context ); +B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, b3QueryFilter filter, + b3OverlapResultFcn* fcn, void* context ); /// Cast a ray into the world to collect shapes in the path of the ray. /// Your callback function controls whether you get the closest point, any point, or n-points. -/// Ignores back-side collision on meshes and height-fields. /// @note The callback function may receive shapes in any order /// @param worldId The world to cast the ray against /// @param origin The start point of the ray @@ -109,43 +93,20 @@ B3_API b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const B3_API b3TreeStats b3World_CastRay( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, b3CastResultFcn* fcn, void* context ); -/// Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores -/// initial overlap. This is less general than b3World_CastRay() and does not allow for custom -/// filtering. Ignores back-side collision on meshes and height-fields. +/// Cast a ray into the world to collect the closest hit. This is a convenience function. Ignores initial overlap. +/// This is less general than b3World_CastRay() and does not allow for custom filtering. B3_API b3RayResult b3World_CastRayClosest( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter ); -/// Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a -/// point. The proxy points are relative to the origin and the hit points come back as world -/// positions, so the cast stays precise far from the world origin. Ignores back-side collision on -/// meshes and height-fields. +/// Cast a shape through the world. Similar to a cast ray except that a shape is cast instead of a point. +/// The proxy points are relative to the origin and the hit points come back as world positions, so the +/// cast stays precise far from the world origin. /// @see b3World_CastRay B3_API b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation, b3QueryFilter filter, b3CastResultFcn* fcn, void* context ); -/// Overlap test for all shapes that *potentially* overlap the provided AABB. This only considers static bodies, -/// so it may be invoked concurrently with b3World_Step. This is not thread-safe with creation and destruction -/// operations. This is a workaround for The Legend of California and may be removed later if the workaround is no -/// longer needed. This is not part of a strategy to make concurrent queries thread-safe. -B3_API b3TreeStats b3World_OverlapAABB_Static( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter, - b3OverlapResultFcn* fcn, void* context ); - -/// Similar for shape overlap. -B3_API b3TreeStats b3World_OverlapShape_Static( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, - b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context ); - -/// Similar for cast ray. -B3_API b3TreeStats b3World_CastRay_Static( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, - b3CastResultFcn* fcn, void* context ); - -/// Similar for cast shape. -B3_API b3TreeStats b3World_CastShape_Static( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, - b3Vec3 translation, b3QueryFilter filter, b3CastResultFcn* fcn, - void* context ); - -/// Cast a capsule mover through the world. This is a special shape cast that handles sliding along -/// other shapes while reducing clipping. This is not a good source of information about what the -/// mover is touching. Instead use the planes returned by b3World_CollideMover. Ignores back-side -/// collision on meshes and height-fields. +/// Cast a capsule mover through the world. This is a special shape cast that handles sliding along other shapes while reducing +/// clipping. This is not a good source of information about what the mover is touching. Instead use the planes returned by +/// b3World_CollideMover. /// @param worldId World to cast the mover against /// @param origin World position the mover capsule is relative to /// @param mover Capsule mover, relative to the origin @@ -154,12 +115,11 @@ B3_API b3TreeStats b3World_CastShape_Static( b3WorldId worldId, b3Pos origin, co /// @param fcn Optional callback for custom shape filtering /// @param context A user context that is passed along to the callback function /// @return the translation fraction -B3_API float b3World_CastMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3Vec3 translation, - b3QueryFilter filter, b3MoverFilterFcn* fcn, void* context ); +B3_API float b3World_CastMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3Vec3 translation, b3QueryFilter filter, + b3MoverFilterFcn* fcn, void* context ); -/// Collide a capsule mover with the world, gathering collision planes that can be fed to -/// b3SolvePlanes. Useful for kinematic character movement. The mover and the returned planes are -/// relative to the origin. Ignores back-side collision on meshes and height-fields. +/// Collide a capsule mover with the world, gathering collision planes that can be fed to b3SolvePlanes. Useful for +/// kinematic character movement. The mover and the returned planes are relative to the origin. B3_API void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mover, b3QueryFilter filter, b3PlaneResultFcn* fcn, void* context ); @@ -171,9 +131,9 @@ B3_API void b3World_EnableSleeping( b3WorldId worldId, bool flag ); /// Is body sleeping enabled? B3_API bool b3World_IsSleepingEnabled( b3WorldId worldId ); -/// Enable/disable continuous collision between dynamic and static bodies. Generally you should keep -/// continuous collision enabled to prevent fast moving objects from going through static objects. -/// The performance gain from disabling continuous collision is minor. +/// Enable/disable continuous collision between dynamic and static bodies. Generally you should keep continuous +/// collision enabled to prevent fast moving objects from going through static objects. The performance gain from +/// disabling continuous collision is minor. /// @see b3WorldDef B3_API void b3World_EnableContinuous( b3WorldId worldId, bool flag ); @@ -188,21 +148,8 @@ B3_API void b3World_SetRestitutionThreshold( b3WorldId worldId, float value ); /// Get the restitution speed threshold. Usually in meters per second. B3_API float b3World_GetRestitutionThreshold( b3WorldId worldId ); -/// Set the number of iterations used by the restitution solver. -/// @see B3_MAX_RESTITUTION_ITERATIONS -B3_API void b3World_SetRestitutionIterations( b3WorldId worldId, int iterations ); - -/// Get the number of iterations used by the restitution solver. -B3_API int b3World_GetRestitutionIterations( b3WorldId worldId ); - -/// Enable restitution propagation. -B3_API void b3World_EnableRestitutionPropagation( b3WorldId worldId, bool flag ); - -/// Is restitution propagation enabled? -B3_API bool b3World_IsRestitutionPropagationEnabled( b3WorldId worldId ); - -/// Adjust the hit event threshold. This controls the collision speed needed to generate a -/// b3ContactHitEvent. Usually in meters per second. +/// Adjust the hit event threshold. This controls the collision speed needed to generate a b3ContactHitEvent. +/// Usually in meters per second. /// @see b3WorldDef::hitEventThreshold B3_API void b3World_SetHitEventThreshold( b3WorldId worldId, float value ); @@ -249,13 +196,6 @@ B3_API void b3World_SetMaximumLinearSpeed( b3WorldId worldId, float maximumLinea /// Get the maximum linear speed. Usually in m/s. B3_API float b3World_GetMaximumLinearSpeed( b3WorldId worldId ); -/// Set the tolerance for gyroscopic torque. [0, 1] -/// @note modifying this only affects new bodies or bodies that get their mass updated. -B3_API void b3World_SetIsotropicInertiaTolerance( b3WorldId worldId, float tolerance ); - -/// Get the tolerance for gyroscopic torque. [0, 1] -B3_API float b3World_GetIsotropicInertiaTolerance( b3WorldId worldId ); - /// Enable/disable constraint warm starting. Advanced feature for testing. Disabling /// warm starting greatly reduces stability and provides no performance gain. B3_API void b3World_EnableWarmStarting( b3WorldId worldId, bool flag ); @@ -263,10 +203,6 @@ B3_API void b3World_EnableWarmStarting( b3WorldId worldId, bool flag ); /// Is constraint warm starting enabled? B3_API bool b3World_IsWarmStartingEnabled( b3WorldId worldId ); -/// Enable the SSE2 fallback even when AVX2 is present. This is for testing. -/// Normally you should use the CMake build settings to disable AVX2. -B3_API void b3World_EnableSSE2Fallback( b3WorldId worldId, bool flag ); - /// Get the number of awake bodies B3_API int b3World_GetAwakeBodyCount( b3WorldId worldId ); @@ -303,9 +239,19 @@ B3_API void b3World_DumpMemoryStats( b3WorldId worldId ); /// Dump shape bounds to box3d_bounds.txt B3_API void b3World_DumpShapeBounds( b3WorldId worldId, b3BodyType type ); +/// This is for internal testing +B3_API void b3World_RebuildStaticTree( b3WorldId worldId ); + /// This is for internal testing B3_API void b3World_EnableSpeculative( b3WorldId worldId, bool flag ); +/// Dump world to a text file. Saves only awake bodies and associated static bodies. +/// Meshes are saved to binary b3m files. +B3_API void b3World_DumpAwake( b3WorldId worldId ); + +/// Dump world to a text file. Meshes are saved to binary b3m files. +B3_API void b3World_Dump( b3WorldId worldId ); + /** * @defgroup recording Recording * @brief Record and replay world state for debugging. @@ -369,12 +315,12 @@ typedef struct b3RecPlayer b3RecPlayer; /// Summary of a recording, read once at open so a viewer can frame and label it. typedef struct b3RecPlayerInfo { - int frameCount; // total recorded steps - int workerCount; // worker count requested for the replay world - float timeStep; // dt of the recorded steps - int subStepCount; // recorded sub-steps - float lengthScale; // length units per meter in effect when recorded - b3AABB bounds; // accumulated world bounds over the recording, zero-extent if unavailable + int frameCount; // total recorded steps + int workerCount; // worker count requested for the replay world + float timeStep; // dt of the recorded steps + int subStepCount; // recorded sub-steps + float lengthScale; // length units per meter in effect when recorded + b3AABB bounds; // accumulated world bounds over the recording, zero-extent if unavailable } b3RecPlayerInfo; /// Create a player over a recording. Owns a private copy of the bytes. @@ -384,20 +330,15 @@ typedef struct b3RecPlayerInfo /// Replaying at a different count re-partitions the constraint graph, so the StateHash check /// becomes a cross-thread determinism test. Adjustable later with b3RecPlayer_SetWorkerCount. /// @return a new player, or NULL on bad header or deserialization failure -B3_API b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount ); +B3_API b3RecPlayer* b3RecPlayer_Create( const void* data, int size, int workerCount ); /// Destroy the player and free all memory. Restores the previous global length scale. -B3_API void b3DestroyPlayer( b3RecPlayer* player ); +B3_API void b3RecPlayer_Destroy( b3RecPlayer* player ); -/// Advance one frame. dispatch ops until the next Step completes. +/// Advance one frame: dispatch ops until the next Step completes. /// @return true when a frame was stepped, false at end-of-recording B3_API bool b3RecPlayer_StepFrame( b3RecPlayer* player ); -/// Sub-step one frame. This will sub-step and return immediately after body creation. -/// The next call will execute the time step. This allows bodies to be rendered -/// at the creation pose. -B3_API void b3RecPlayer_SubStepFrame( b3RecPlayer* player ); - /// Rewind to frame 0 (in-place restore so the world id stays stable). B3_API void b3RecPlayer_Restart( b3RecPlayer* player ); @@ -417,9 +358,6 @@ B3_API int b3RecPlayer_GetFrameCount( const b3RecPlayer* player ); /// @return true when the op stream is exhausted B3_API bool b3RecPlayer_IsAtEnd( const b3RecPlayer* player ); -/// @return true when the op stream is paused between body creation and world step. -B3_API bool b3RecPlayer_IsAtPreStep( const b3RecPlayer* player ); - /// @return true when any StateHash mismatch has been detected B3_API bool b3RecPlayer_HasDiverged( const b3RecPlayer* player ); @@ -431,8 +369,8 @@ B3_API int b3RecPlayer_GetDivergeFrame( const b3RecPlayer* player ); /// Set the worker count of the replay world. Clamped to [1, B3_MAX_WORKERS]. Applied to the live /// world at once and reused whenever the player rebuilds its world on Restart or a backward seek. -/// Replaying at a different count than recorded re-partitions the constraint graph, so the -/// StateHash check becomes a cross-thread determinism test. +/// Replaying at a different count than recorded re-partitions the constraint graph, so the StateHash +/// check becomes a cross-thread determinism test. B3_API void b3RecPlayer_SetWorkerCount( b3RecPlayer* player, int count ); /// Tune the keyframe ring used to speed up backward seeking. A keyframe is a periodic snapshot the @@ -474,15 +412,14 @@ B3_API b3BodyId b3RecPlayer_GetBodyId( const b3RecPlayer* player, int index ); /// @param destroyDebugShape called when a replayed shape is removed; may be NULL /// @param context user context passed to both callbacks B3_API void b3RecPlayer_SetDebugShapeCallbacks( b3RecPlayer* player, b3CreateDebugShapeCallback* createDebugShape, - b3DestroyDebugShapeCallback* destroyDebugShape, void* context ); + b3DestroyDebugShapeCallback* destroyDebugShape, void* context ); /// Draw the spatial queries recorded during the most recently replayed frame, layered on top of the /// world. Call after b3World_Draw. NULL draw function pointers are skipped. /// @param player a valid player handle /// @param draw debug draw callbacks /// @param queryIndex index of the frame query to draw, or -1 to draw all of them -/// @param selectedIndex index of the query to emphasize (reserved color plus a label), or -1 for -/// none +/// @param selectedIndex index of the query to emphasize (reserved color plus a label), or -1 for none B3_API void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int queryIndex, int selectedIndex ); /// The kind of a recorded spatial query, matching the public query and cast functions. @@ -501,23 +438,23 @@ typedef enum b3RecQueryType typedef struct b3RecQueryInfo { b3RecQueryType type; - b3QueryFilter filter; - b3AABB aabb; // world-space bounds of the query, swept for casts - b3Pos origin; // query origin (zero for overlap AABB) - b3Vec3 translation; // ray and cast translation - int hitCount; // number of recorded results - uint64_t key; // identity key, the hash of (id, name), 0 if untagged - uint64_t id; // query id, 0 if none - const char* name; // query label, NULL if none + b3QueryFilter filter; + b3AABB aabb; // world-space bounds of the query, swept for casts + b3Pos origin; // query origin (zero for overlap AABB) + b3Vec3 translation; // ray and cast translation + int hitCount; // number of recorded results + uint64_t key; // identity key, the hash of (id, name), 0 if untagged + uint64_t id; // query id, 0 if none + const char* name; // query label, NULL if none } b3RecQueryInfo; /// One result of a recorded spatial query. typedef struct b3RecQueryHit { b3ShapeId shape; - b3Pos point; - b3Vec3 normal; - float fraction; + b3Pos point; + b3Vec3 normal; + float fraction; } b3RecQueryHit; /// @return the number of spatial queries recorded for the most recently replayed frame @@ -539,8 +476,8 @@ B3_API b3RecQueryHit b3RecPlayer_GetFrameQueryHit( const b3RecPlayer* player, in * @{ */ -/// Create a rigid body given a definition. No reference to the definition is retained. So you can -/// create the definition on the stack and pass it as a pointer. +/// Create a rigid body given a definition. No reference to the definition is retained. So you can create the definition +/// on the stack and pass it as a pointer. /// @code{.c} /// b3BodyDef bodyDef = b3DefaultBodyDef(); /// b3BodyId myBodyId = b3CreateBody(myWorldId, &bodyDef); @@ -563,10 +500,10 @@ B3_API b3BodyType b3Body_GetType( b3BodyId bodyId ); /// properties regardless of the automatic mass setting. B3_API void b3Body_SetType( b3BodyId bodyId, b3BodyType type ); -/// Set the body name. +/// Set the body name. Up to B3_BODY_NAME_LENGTH characters including null termination. B3_API void b3Body_SetName( b3BodyId bodyId, const char* name ); -/// Get the body name. Returns an empty string if the name isn't set. +/// Get the body name. B3_API const char* b3Body_GetName( b3BodyId bodyId ); /// Set the user data for a body @@ -586,31 +523,31 @@ B3_API b3WorldTransform b3Body_GetTransform( b3BodyId bodyId ); /// Set the world transform of a body. This acts as a teleport and is fairly expensive. /// @note Generally you should create a body with the intended transform. -/// @see b3BodyDef::position and b3BodyDef::rotation. +/// @see b3BodyDef::position and b3BodyDef::rotation B3_API void b3Body_SetTransform( b3BodyId bodyId, b3Pos position, b3Quat rotation ); -/// Get a local point on a body given a world point. +/// Get a local point on a body given a world point B3_API b3Vec3 b3Body_GetLocalPoint( b3BodyId bodyId, b3Pos worldPoint ); -/// Get a world point on a body given a local point. +/// Get a world point on a body given a local point B3_API b3Pos b3Body_GetWorldPoint( b3BodyId bodyId, b3Vec3 localPoint ); -/// Get a local vector on a body given a world vector. +/// Get a local vector on a body given a world vector B3_API b3Vec3 b3Body_GetLocalVector( b3BodyId bodyId, b3Vec3 worldVector ); -/// Get a world vector on a body given a local vector. +/// Get a world vector on a body given a local vector B3_API b3Vec3 b3Body_GetWorldVector( b3BodyId bodyId, b3Vec3 localVector ); /// Get the linear velocity of a body's center of mass. Usually in meters per second. B3_API b3Vec3 b3Body_GetLinearVelocity( b3BodyId bodyId ); -/// Get the angular velocity of a body in radians per second. +/// Get the angular velocity of a body in radians per second B3_API b3Vec3 b3Body_GetAngularVelocity( b3BodyId bodyId ); -/// Set the linear velocity of a body at the center of mass. Usually in meters per second. +/// Set the linear velocity of a body. Usually in meters per second. B3_API void b3Body_SetLinearVelocity( b3BodyId bodyId, b3Vec3 linearVelocity ); -/// Set the angular velocity of a body in radians per second. +/// Set the angular velocity of a body in radians per second B3_API void b3Body_SetAngularVelocity( b3BodyId bodyId, b3Vec3 angularVelocity ); /// Set the velocity to reach the given transform after a given time step. @@ -691,10 +628,10 @@ B3_API float b3Body_GetInverseMass( b3BodyId bodyId ); B3_API b3Matrix3 b3Body_GetWorldInverseRotationalInertia( b3BodyId bodyId ); /// Get the center of mass position of the body in local space -B3_API b3Vec3 b3Body_GetLocalCenter( b3BodyId bodyId ); +B3_API b3Vec3 b3Body_GetLocalCenterOfMass( b3BodyId bodyId ); /// Get the center of mass position of the body in world space -B3_API b3Pos b3Body_GetWorldCenter( b3BodyId bodyId ); +B3_API b3Pos b3Body_GetWorldCenterOfMass( b3BodyId bodyId ); /// Override the body's mass properties. Normally this is computed automatically using the /// shape geometry and density. This information is lost if a shape is added or removed or if the @@ -734,8 +671,8 @@ B3_API float b3Body_GetGravityScale( b3BodyId bodyId ); B3_API bool b3Body_IsAwake( b3BodyId bodyId ); /// Wake a body from sleep. This wakes the entire island the body is touching. -/// @warning Putting a body to sleep will put the entire island of bodies touching this body to -/// sleep, which can be expensive and possibly unintuitive. +/// @warning Putting a body to sleep will put the entire island of bodies touching this body to sleep, +/// which can be expensive and possibly unintuitive. B3_API void b3Body_SetAwake( b3BodyId bodyId, bool awake ); /// Enable or disable sleeping for this body. If sleeping is disabled the body will wake. @@ -750,13 +687,6 @@ B3_API void b3Body_SetSleepThreshold( b3BodyId bodyId, float sleepThreshold ); /// Get the sleep threshold, usually in meters per second. B3_API float b3Body_GetSleepThreshold( b3BodyId bodyId ); -/// Set the continuous collision safety factor. Smaller is safer but can lead to hitching. -/// Recommended range [0.01, 0.5]. Non-dimensional. -B3_API void b3Body_SetSafetyFactor( b3BodyId bodyId, float safetyFactor ); - -/// Get the continuous collision safety factor. Non-dimensional. -B3_API float b3Body_GetSafetyFactor( b3BodyId bodyId ); - /// Returns true if this body is enabled B3_API bool b3Body_IsEnabled( b3BodyId bodyId ); @@ -779,18 +709,10 @@ B3_API void b3Body_SetBullet( b3BodyId bodyId, bool flag ); /// Is this body a bullet? B3_API bool b3Body_IsBullet( b3BodyId bodyId ); -/// Allow this body to rotate fast. Useful for axially symmetric bodies, such as vehicle wheels. -/// Normally rotation speed is clamped to improve CCD. However, this clamping is unnecessary for -/// bodies that only rotate fast around an axis of symmetry. -B3_API void b3Body_AllowFastRotation( b3BodyId bodyId, bool flag ); - -/// Is this body allowed to rotate fast? -B3_API bool b3Body_IsFastRotationAllowed( b3BodyId bodyId ); - -/// Enable or disable contact recycling for this body. Contact recycling is a performance -/// optimization that reuses contact manifolds when bodies move slightly. Disabling it can avoid -/// ghost collisions on characters at the cost of higher per-step work. Existing contacts retain -/// their prior setting; only contacts created after this call see the new value. +/// Enable or disable contact recycling for this body. Contact recycling is a performance optimization +/// that reuses contact manifolds when bodies move slightly. Disabling it can avoid ghost collisions +/// on characters at the cost of higher per-step work. Existing contacts retain their prior setting; +/// only contacts created after this call see the new value. /// @see b3BodyDef::enableContactRecycling B3_API void b3Body_EnableContactRecycling( b3BodyId bodyId, bool flag ); @@ -799,7 +721,7 @@ B3_API bool b3Body_IsContactRecyclingEnabled( b3BodyId bodyId ); /// Enable/disable hit events on all shapes /// @see b3ShapeDef::enableHitEvents -B3_API void b3Body_EnableHitEvents( b3BodyId bodyId, bool flag ); +B3_API void b3Body_EnableHitEvents( b3BodyId bodyId, bool enableHitEvents ); /// Get the world that owns this body B3_API b3WorldId b3Body_GetWorld( b3BodyId bodyId ); @@ -824,30 +746,18 @@ B3_API int b3Body_GetContactCapacity( b3BodyId bodyId ); /// Get the touching contact data for a body B3_API int b3Body_GetContactData( b3BodyId bodyId, b3ContactData* contactData, int capacity ); -/// Get the current world AABB that contains all the attached shapes. Note that this may not -/// encompass the body origin. If there are no shapes attached then the returned AABB is empty and -/// centered on the body origin. +/// Get the current world AABB that contains all the attached shapes. Note that this may not encompass the body origin. +/// If there are no shapes attached then the returned AABB is empty and centered on the body origin. B3_API b3AABB b3Body_ComputeAABB( b3BodyId bodyId ); -/// The minimum distance from any shape to the shape centroid. -B3_API float b3Body_GetMinExtent( b3BodyId bodyId ); - -/// The maximum extent vector from any point on the body shapes to the center of mass. -B3_API b3Vec3 b3Body_GetMaxExtent( b3BodyId bodyId ); - -/// The maximum extent vector from any point on the body shapes to the body origin. Conservative. -B3_API b3Vec3 b3Body_GetMaxExtentOrigin( b3BodyId bodyId ); - /// Get the closest point on a body to a world target. B3_API float b3Body_GetClosestPoint( b3BodyId bodyId, b3Vec3* result, b3Vec3 target ); /// Cast a ray at a specific body using a specified body transform. -/// Ignores back-side collision on meshes and height-fields. B3_API b3BodyCastResult b3Body_CastRay( b3BodyId bodyId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, float maxFraction, b3WorldTransform bodyTransform ); /// Cast a shape at a specific body using a specified body transform. -/// Ignores back-side collision on meshes and height-fields. B3_API b3BodyCastResult b3Body_CastShape( b3BodyId bodyId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation, b3QueryFilter filter, float maxFraction, bool canEncroach, b3WorldTransform bodyTransform ); @@ -857,78 +767,58 @@ B3_API bool b3Body_OverlapShape( b3BodyId bodyId, b3Pos origin, const b3ShapePro b3WorldTransform bodyTransform ); /// Collide a character mover with a specific body using a specified body transform. -/// Only considers convex shapes on the body. -B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin, - const b3Capsule* mover, b3QueryFilter filter, b3WorldTransform bodyTransform ); - -/// Perform a time of impact between a character mover and a body using specified sweep transforms. -/// Initial overlap of any shape on the body is ignored. A non-overlapped shape can still be hit. -/// Only considers convex shapes on the body. -B3_API b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover, - b3Vec3 moverTranslation, b3QueryFilter filter, - b3WorldTransform bodyTransform1, b3WorldTransform bodyTransform2 ); +B3_API int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int planeCapacity, b3Pos origin, const b3Capsule* mover, + b3QueryFilter filter, b3WorldTransform bodyTransform ); /** @} */ // body /** * @defgroup shape Shape * Functions to create, destroy, and access. - * Shapes bind raw geometry to bodies and hold material properties including friction and - * restitution. You may add multiple shapes to a single body. There are no hard limits on shape - * count per body. - * - * When you create a shape on a body the center of mass moves. This can lead to the body linear - * velocity changing if the angular velocity is non-zero. + * Shapes bind raw geometry to bodies and hold material properties including friction and restitution. * @{ */ -/// Create a circle shape and attach it to a body. The shape definition and geometry are fully -/// cloned. Contacts are not created until the next time step. +/// Create a circle shape and attach it to a body. The shape definition and geometry are fully cloned. +/// Contacts are not created until the next time step. /// @return the shape id for accessing the shape B3_API b3ShapeId b3CreateSphereShape( b3BodyId bodyId, const b3ShapeDef* def, const b3Sphere* sphere ); -/// Create a capsule shape and attach it to a body. The shape definition and geometry are fully -/// cloned. Contacts are not created until the next time step. +/// Create a capsule shape and attach it to a body. The shape definition and geometry are fully cloned. +/// Contacts are not created until the next time step. /// @return the shape id for accessing the shape B3_API b3ShapeId b3CreateCapsuleShape( b3BodyId bodyId, const b3ShapeDef* def, const b3Capsule* capsule ); -/// Create a convex hull shape and attach it to a body. The shape definition is fully cloned. -/// Contacts are not created until the next time step. +/// Create a convex hull shape and attach it to a body. The shape definition is fully cloned. Contacts are not created +/// until the next time step. /// @return the shape id for accessing the shape B3_API b3ShapeId b3CreateHullShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HullData* hull ); -/// Create a convex hull shape and attach it to a body. The hull is cloned then transformed with -/// scale applied first. Use this for non-uniform or mirrored scale or a baked local transform. The -/// baked result is shared through the world hull database. The shape definition and geometry are -/// fully cloned. Contacts are not created until the next time step. +/// Create a convex hull shape and attach it to a body. The hull is cloned then transformed with scale applied first. +/// Use this for non-uniform or mirrored scale or a baked local transform. The baked result is shared through the +/// world hull database. The shape definition and geometry are fully cloned. Contacts are not created until the next time step. /// @return the shape id for accessing the shape B3_API b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HullData* hull, b3Transform transform, b3Vec3 scale ); -/// Create a mesh hull shape and attach it to a body. The shape definition is fully cloned but the -/// mesh is not. Contacts are not created until the next time step. Mesh collision only creates -/// contacts on static bodies. -/// @warning this holds reference to the input mesh data which must remain valid for the lifetime of -/// this shape +/// Create a mesh hull shape and attach it to a body. The shape definition is fully cloned but the mesh is not. +/// Contacts are not created until the next time step. +/// Mesh collision only creates contacts on static bodies. +/// @warning this holds reference to the input mesh data which must remain valid for the lifetime of this shape /// @return the shape id for accessing the shape B3_API b3ShapeId b3CreateMeshShape( b3BodyId bodyId, const b3ShapeDef* def, const b3MeshData* mesh, b3Vec3 scale ); -/// Create a height-field shape and attach it to a body. The shape definition is fully cloned but -/// the height field is not. Contacts are not created until the next time step. Height field is only -/// allowed on static bodies. -/// @warning this holds reference to the input height field which must remain valid for the lifetime -/// of this shape +/// Create a height-field shape and attach it to a body. The shape definition is fully cloned but the height field is not. +/// Contacts are not created until the next time step. +/// Height field is only allowed on static bodies. +/// @warning this holds reference to the input height field which must remain valid for the lifetime of this shape /// @return the shape id for accessing the shape -B3_API b3ShapeId b3CreateHeightFieldShape( b3BodyId bodyId, const b3ShapeDef* def, - const b3HeightFieldData* heightField ); +B3_API b3ShapeId b3CreateHeightFieldShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HeightFieldData* heightField ); -/// Baked compound shapes are only allowed on static bodies. -/// Note: runtime compounds are achieved by adding multiple shapes to a body. -/// Runtime compounds can be dynamic and/or kinematic. -B3_API b3ShapeId b3CreateBakedCompoundShape( b3BodyId bodyId, b3ShapeDef* def, const b3CompoundData* compound ); +/// Compound shapes are only allowed on static bodies. +B3_API b3ShapeId b3CreateCompoundShape( b3BodyId bodyId, b3ShapeDef* def, const b3CompoundData* compound ); -/// Destroy a shape. You may defer the body mass update which can improve performance if several -/// shapes on a +/// Destroy a shape. You may defer the body mass update which can improve performance if several shapes on a /// body are destroyed at once. /// @see b3Body_ApplyMassFromShapes B3_API void b3DestroyShape( b3ShapeId shapeId, bool updateBodyMass ); @@ -948,12 +838,6 @@ B3_API b3WorldId b3Shape_GetWorld( b3ShapeId shapeId ); /// Returns true if the shape is a sensor B3_API bool b3Shape_IsSensor( b3ShapeId shapeId ); -/// Set the shape name. -B3_API void b3Shape_SetName( b3ShapeId shapeId, const char* name ); - -/// Get the shape name. Returns an empty string if the name isn't set. -B3_API const char* b3Shape_GetName( b3ShapeId shapeId ); - /// Set the user data for a shape B3_API void b3Shape_SetUserData( b3ShapeId shapeId, void* userData ); @@ -1003,28 +887,25 @@ B3_API b3Filter b3Shape_GetFilter( b3ShapeId shapeId ); /// @see b3ShapeDef::filter /// @param shapeId the shape /// @param filter the new filter -/// @param invokeContacts if true then the shape will have all contacts recomputed the next time -/// step (expensive) +/// @param invokeContacts if true then the shape will have all contacts recomputed the next time step (expensive) B3_API void b3Shape_SetFilter( b3ShapeId shapeId, b3Filter filter, bool invokeContacts ); -/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for -/// sensors. +/// Enable sensor events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. /// @see b3ShapeDef::isSensor B3_API void b3Shape_EnableSensorEvents( b3ShapeId shapeId, bool flag ); /// Returns true if sensor events are enabled B3_API bool b3Shape_AreSensorEventsEnabled( b3ShapeId shapeId ); -/// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for -/// sensors. +/// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. /// @see b3ShapeDef::enableContactEvents B3_API void b3Shape_EnableContactEvents( b3ShapeId shapeId, bool flag ); /// Returns true if contact events are enabled B3_API bool b3Shape_AreContactEventsEnabled( b3ShapeId shapeId ); -/// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are -/// expensive and must be carefully handled due to multithreading. Ignored for sensors. +/// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive +/// and must be carefully handled due to multithreading. Ignored for sensors. /// @see b3PreSolveFcn B3_API void b3Shape_EnablePreSolveEvents( b3ShapeId shapeId, bool flag ); @@ -1057,9 +938,6 @@ B3_API b3Mesh b3Shape_GetMesh( b3ShapeId shapeId ); /// Get the shape's height field. Asserts the type is correct. B3_API const b3HeightFieldData* b3Shape_GetHeightField( b3ShapeId shapeId ); -/// Get the shape's compound. Asserts the type is correct. -B3_API const b3CompoundData* b3Shape_GetCompound( b3ShapeId shapeId ); - /// Allows you to change a shape to be a sphere or update the current sphere. /// This does not modify the mass properties. /// @see b3Body_ApplyMassFromShapes @@ -1083,8 +961,7 @@ B3_API void b3Shape_SetMesh( b3ShapeId shapeId, const b3MeshData* meshData, b3Ve /// Get the maximum capacity required for retrieving all the touching contacts on a shape B3_API int b3Shape_GetContactCapacity( b3ShapeId shapeId ); -/// Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or -/// shapeIdB on the contact data. +/// Get the touching contact data for a shape. The provided shapeId will be either shapeIdA or shapeIdB on the contact data. /// @note Box3D uses speculative collision so some contact points may be separated. /// @returns the number of elements filled in the provided array /// @warning do not ignore the return value, it specifies the valid number of elements @@ -1121,8 +998,7 @@ B3_API b3Vec3 b3Shape_GetClosestPoint( b3ShapeId shapeId, b3Vec3 target ); /// @param wind the wind velocity in world space /// @param drag the drag coefficient, the force that opposes the relative velocity /// @param lift the lift coefficient, the force that is perpendicular to the relative velocity -/// @param maxSpeed the maximum relative speed. Speed cap is necessary for stability. Typically -/// 10m/s or less. +/// @param maxSpeed the maximum relative speed. Speed cap is necessary for stability. Typically 10m/s or less. /// @param wake should this wake the body B3_API void b3Shape_ApplyWind( b3ShapeId shapeId, b3Vec3 wind, float drag, float lift, float maxSpeed, bool wake ); @@ -1130,8 +1006,7 @@ B3_API void b3Shape_ApplyWind( b3ShapeId shapeId, b3Vec3 wind, float drag, float /** * @defgroup joint Joint - * @brief Joints allow you to connect rigid bodies together while allowing various forms of relative - * motions. + * @brief Joints allow you to connect rigid bodies together while allowing various forms of relative motions. * @{ */ @@ -1180,21 +1055,16 @@ B3_API void* b3Joint_GetUserData( b3JointId jointId ); /// Wake the bodies connect to this joint B3_API void b3Joint_WakeBodies( b3JointId jointId ); -/// Is the joint awake? If true then an attached body is awake. -B3_API bool b3Joint_IsAwake( b3JointId jointId ); - /// Get the current constraint force for this joint B3_API b3Vec3 b3Joint_GetConstraintForce( b3JointId jointId ); /// Get the current constraint torque for this joint B3_API b3Vec3 b3Joint_GetConstraintTorque( b3JointId jointId ); -/// Get the current linear separation error for this joint. Does not consider admissible movement. -/// Usually in meters. +/// Get the current linear separation error for this joint. Does not consider admissible movement. Usually in meters. B3_API float b3Joint_GetLinearSeparation( b3JointId jointId ); -/// Get the current angular separation error for this joint. Does not consider admissible movement. -/// Usually in radians. +/// Get the current angular separation error for this joint. Does not consider admissible movement. Usually in radians. B3_API float b3Joint_GetAngularSeparation( b3JointId jointId ); /// Set the joint constraint tuning. Advanced feature. @@ -1290,8 +1160,8 @@ B3_API float b3DistanceJoint_GetSpringHertz( b3JointId jointId ); /// Get the spring damping ratio B3_API float b3DistanceJoint_GetSpringDampingRatio( b3JointId jointId ); -/// Enable joint limit. The limit only works if the joint spring is enabled. Otherwise the joint is -/// rigid and the limit has no effect. +/// Enable joint limit. The limit only works if the joint spring is enabled. Otherwise the joint is rigid +/// and the limit has no effect. B3_API void b3DistanceJoint_EnableLimit( b3JointId jointId, bool enableLimit ); /// Is the distance joint limit enabled? @@ -1410,101 +1280,12 @@ B3_API float b3MotorJoint_GetMaxSpringTorque( b3JointId jointId ); /**@}*/ // motor_joint -/** - * @defgroup mover_joint Mover Joint - * @brief Functions for the mover joint. - * - * The mover joint is designed for a dynamic character mover. - * - * @warning Experimental. The mover joint may change in future versions. - * @{ - */ - -/// Create a mover joint. -/// @see b3MoverJointDef for details -B3_API b3JointId b3CreateMoverJoint( b3WorldId worldId, const b3MoverJointDef* def ); - -/// Set the desired relative linear velocity, usually in meters per second. -B3_API void b3MoverJoint_SetLinearVelocity( b3JointId jointId, b3Vec3 velocity ); - -/// Get the desired relative linear velocity, usually in meters per second. -B3_API b3Vec3 b3MoverJoint_GetLinearVelocity( b3JointId jointId ); - -/// Set the joint maximum force, usually in newtons. -B3_API void b3MoverJoint_SetMaxVelocityForce( b3JointId jointId, float maxForce ); - -/// Get the joint maximum force, usually in newtons. -B3_API float b3MoverJoint_GetMaxVelocityForce( b3JointId jointId ); - -/**@}*/ // mover_joint - -/** - * @defgroup pogo_joint Pogo Joint - * @brief Functions for the pogo joint. Used for dynamic character movers. - * - * @warning Experimental. The pogo joint may change in future versions. - * @{ - */ - -/// Create a pogo joint -/// @see b3PogoJointDef for details -B3_API b3JointId b3CreatePogoJoint( b3WorldId worldId, const b3PogoJointDef* def ); - -/// Set the rest length of a pogo joint -/// @param jointId The id for a pogo joint -/// @param length The new pogo joint length -B3_API void b3PogoJoint_SetRestLength( b3JointId jointId, float length ); - -/// Get the rest length of a pogo joint -B3_API float b3PogoJoint_GetRestLength( b3JointId jointId ); - -/// Set the spring stiffness in Hertz -B3_API void b3PogoJoint_SetSpringHertz( b3JointId jointId, float hertz ); - -/// Get the spring Hertz -B3_API float b3PogoJoint_GetSpringHertz( b3JointId jointId ); - -/// Set the spring damping ratio, non-dimensional -B3_API void b3PogoJoint_SetSpringDampingRatio( b3JointId jointId, float dampingRatio ); - -/// Get the spring damping ratio -B3_API float b3PogoJoint_GetSpringDampingRatio( b3JointId jointId ); - -/// Set the max tension force, usually in Newtons. -B3_API void b3PogoJoint_SetMaxTensionForce( b3JointId jointId, float force ); - -/// Get the max tension force, usually in Newtons. -B3_API float b3PogoJoint_GetMaxTensionForce( b3JointId jointId ); - -/// Set the max compression force, usually in Newtons. -B3_API void b3PogoJoint_SetMaxCompressionForce( b3JointId jointId, float force ); - -/// Get the max compression force, usually in Newtons. -B3_API float b3PogoJoint_GetMaxCompressionForce( b3JointId jointId ); - -// Set the unit ground normal. -B3_API void b3PogoJoint_SetNormal( b3JointId jointId, b3Vec3 normal ); - -// Get the unit ground normal. -B3_API b3Vec3 b3PogoJoint_GetNormal( b3JointId jointId ); - -/// Get the current length of the pogo. -B3_API float b3PogoJoint_GetCurrentLength( b3JointId jointId ); - -/// Get the internal pogo velocity. -B3_API float b3PogoJoint_GetCurrentSpeed( b3JointId jointId ); - -/// Get the internal pogo impulse. -B3_API float b3PogoJoint_GetImpulse( b3JointId jointId ); - -/**@}*/ // pogo_joint - /** * @defgroup filter_joint Filter Joint * @brief Functions for the filter joint. * - * The filter joint is used to disable collision between two bodies. As a side effect of being a - * joint, it also keeps the two bodies in the same simulation island. + * The filter joint is used to disable collision between two bodies. As a side effect of being a joint, it also + * keeps the two bodies in the same simulation island. * @{ */ @@ -1518,8 +1299,8 @@ B3_API b3JointId b3CreateFilterJoint( b3WorldId worldId, const b3FilterJointDef* * @defgroup prismatic_joint Prismatic Joint * @brief A prismatic joint allows for translation along a single axis with no rotation. * - * The prismatic joint is useful for things like pistons and moving platforms, where you want a body - * to translate along an axis and have no rotation. Also called a *slider* joint. + * The prismatic joint is useful for things like pistons and moving platforms, where you want a body to translate + * along an axis and have no rotation. Also called a *slider* joint. * @{ */ @@ -1534,8 +1315,8 @@ B3_API void b3PrismaticJoint_EnableSpring( b3JointId jointId, bool enableSpring B3_API bool b3PrismaticJoint_IsSpringEnabled( b3JointId jointId ); /// Set the prismatic joint stiffness in Hertz. -/// This should usually be less than a quarter of the simulation rate. For example, if the -/// simulation runs at 60Hz then the joint stiffness should be 15Hz or less. +/// This should usually be less than a quarter of the simulation rate. For example, if the simulation +/// runs at 60Hz then the joint stiffness should be 15Hz or less. B3_API void b3PrismaticJoint_SetSpringHertz( b3JointId jointId, float hertz ); /// Get the prismatic joint stiffness in Hertz @@ -1599,8 +1380,7 @@ B3_API float b3PrismaticJoint_GetSpeed( b3JointId jointId ); /** * @defgroup revolute_joint Revolute Joint - * @brief A revolute joint allows for relative rotation about a single axis with no relative - * translation. + * @brief A revolute joint allows for relative rotation about a single axis with no relative translation. * * Also called a *hinge* or *pin* joint. * @{ @@ -1678,8 +1458,7 @@ B3_API float b3RevoluteJoint_GetMaxMotorTorque( b3JointId jointId ); /** * @defgroup spherical_joint Spherical Joint - * @brief A spherical joint allows for relative rotation in the 3D space with no relative - * translation. + * @brief A spherical joint allows for relative rotation in the 3D space with no relative translation. * * Also called a *ball-in-socket* or *point-to-point* joint. * @{ @@ -1752,9 +1531,7 @@ B3_API void b3SphericalJoint_EnableMotor( b3JointId jointId, bool enableMotor ); /// Is the spherical joint motor enabled? B3_API bool b3SphericalJoint_IsMotorEnabled( b3JointId jointId ); -/// Set the spherical joint motor velocity in radians per second. This is the relative angular -/// velocity between the two bodies in world space. -/// motorVelocity = angularVelocityB - angularVelocityA +/// Set the spherical joint motor velocity in radians per second B3_API void b3SphericalJoint_SetMotorVelocity( b3JointId jointId, b3Vec3 motorVelocity ); /// Get the spherical joint motor velocity in radians per second @@ -1773,14 +1550,12 @@ B3_API float b3SphericalJoint_GetMaxMotorTorque( b3JointId jointId ); /** * @defgroup weld_joint Weld Joint - * @brief A weld joint fully constrains the relative transform between two bodies while allowing for - * springiness + * @brief A weld joint fully constrains the relative transform between two bodies while allowing for springiness * - * A weld joint constrains the relative rotation and translation between two bodies. Both rotation - * and translation can have damped springs. + * A weld joint constrains the relative rotation and translation between two bodies. Both rotation and translation + * can have damped springs. * - * @note The accuracy of weld joint is limited by the accuracy of the solver. Long chains of weld - * joints may flex. + * @note The accuracy of weld joint is limited by the accuracy of the solver. Long chains of weld joints may flex. * @{ */ diff --git a/include/box3d/collision.h b/include/box3d/collision.h index cae180a..30cc957 100644 --- a/include/box3d/collision.h +++ b/include/box3d/collision.h @@ -39,28 +39,24 @@ B3_API void b3DynamicTree_SetCategoryBits( b3DynamicTree* tree, int proxyId, uin /// Get the category bits on a proxy. B3_API uint64_t b3DynamicTree_GetCategoryBits( b3DynamicTree* tree, int proxyId ); -/// Query an AABB for overlapping proxies. The callback function is called for each proxy that overlaps the supplied -/// AABB. +/// Query an AABB for overlapping proxies. The callback function is called for each proxy that overlaps the supplied AABB. /// @return performance data B3_API b3TreeStats b3DynamicTree_Query( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, b3TreeQueryCallbackFcn* callback, void* context ); -/// Query an AABB for the closest object. The callback function is called for each proxy that might be closest to the -/// supplied point. +/// Query an AABB for the closest object. The callback function is called for each proxy that might be closest to the supplied point. /// @param tree the dynamic tree to query /// @param point the query point -/// @param maskBits proxies are skipped if the bit-wise AND with the proxy category bits is zero -/// @param requireAllBits proxies are skipped if the bit-wise AND with the proxy category bits does not equal the -/// maskBits +/// @param maskBits nodes are skipped if the bit-wise AND with the node category bits is zero +/// @param requireAllBits nodes are skipped if the bit-wise AND with the node category bits does not equal the maskBits /// @param callback a user provided instance of b3TreeQueryClosestCallbackFcn /// @param context a user context object that is provided to the callback -/// @param minDistanceSqr the initial and final minimum squared distance. Provide a small initial to restrict the search -/// and improve performance. If the value is large this query has performance that scales linearly with the number of -/// proxies and would be slower than a brute force search. +/// @param minDistanceSqr the initial and final minimum squared distance. Provide a small initial to restrict the search and +/// improve performance. If the value is large this query has performance that scales linearly with the number of proxies and +/// would be slower than a brute force search. /// @return performance data -B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, - bool requireAllBits, b3TreeQueryClosestCallbackFcn* callback, - void* context, float* minDistanceSqr ); +B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits, + b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr ); /// Ray cast against the proxies in the tree. This relies on the callback /// to perform an exact ray cast in the case where the proxy contains a shape. @@ -71,8 +67,8 @@ B3_API b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 /// However, this filtering may be approximate, so the user should still apply filtering to results. /// @param tree the dynamic tree to ray cast /// @param input the ray cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1) -/// @param maskBits bit mask test: `bool accept = (maskBits & proxy->categoryBits) != 0;` -/// @param requireAllBits modifies bit mask test: `bool accept = (maskBits & proxy->categoryBits) == maskBits;` +/// @param maskBits bit mask test: `bool accept = (maskBits & node->categoryBits) != 0;` +/// @param requireAllBits modifies bit mask test: `bool accept = (maskBits & node->categoryBits) == maskBits;` /// @param callback a callback function that is called for each proxy that is hit by the ray /// @param context user context that is passed to the callback /// @return performance data @@ -85,6 +81,9 @@ B3_API b3TreeStats b3DynamicTree_RayCast( const b3DynamicTree* tree, const b3Ray B3_API b3TreeStats b3DynamicTree_BoxCast( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits, bool requireAllBits, b3TreeBoxCastCallbackFcn* callback, void* context ); +/// Validate this tree. For testing. +B3_API void b3DynamicTree_Validate( const b3DynamicTree* tree ); + /// Get the height of the binary tree. B3_API int b3DynamicTree_GetHeight( const b3DynamicTree* tree ); @@ -106,8 +105,8 @@ B3_API int b3DynamicTree_GetByteCount( const b3DynamicTree* tree ); /// Validate this tree. For testing. B3_API void b3DynamicTree_Validate( const b3DynamicTree* tree ); -/// Validate this tree has no moved nodes. For testing. -B3_API void b3DynamicTree_ValidateNoMoved( const b3DynamicTree* tree ); +/// Validate this tree has no enlarged AABBs. For testing. +B3_API void b3DynamicTree_ValidateNoEnlarged( const b3DynamicTree* tree ); /// Save this tree to a file for debugging B3_API void b3DynamicTree_Save( const b3DynamicTree* tree, const char* fileName ); @@ -118,13 +117,13 @@ B3_API b3DynamicTree b3DynamicTree_Load( const char* fileName, float scale ); /// Get proxy user data B3_INLINE uint64_t b3DynamicTree_GetUserData( const b3DynamicTree* tree, int proxyId ) { - return tree->proxies[proxyId].userData; + return tree->nodes[proxyId].userData; } /// Get the AABB of a proxy B3_INLINE b3AABB b3DynamicTree_GetAABB( const b3DynamicTree* tree, int proxyId ) { - return tree->nodes[tree->proxies[proxyId].node].aabb; + return tree->nodes[proxyId].aabb; } /**@}*/ // tree @@ -167,17 +166,6 @@ B3_INLINE const b3HullHalfEdge* b3GetHullEdges( const b3HullData* hull ) return (const b3HullHalfEdge*)( (intptr_t)hull + hull->edgeOffset ); } -/// Get read only hull planes. -B3_INLINE const b3Plane* b3GetHullPlanes( const b3HullData* hull ) -{ - if ( hull->planeOffset == 0 ) - { - return NULL; - } - - return (const b3Plane*)( (intptr_t)hull + hull->planeOffset ); -} - /// Get read only hull faces. B3_INLINE const b3HullFace* b3GetHullFaces( const b3HullData* hull ) { @@ -189,41 +177,15 @@ B3_INLINE const b3HullFace* b3GetHullFaces( const b3HullData* hull ) return (const b3HullFace*)( (intptr_t)hull + hull->faceOffset ); } -/// Get read only SOA vertices. This is an array of vertices with all x values, -/// y values, and z values as separate arrays. The array lengths are padded to -/// a multiple of 8. The padded values are repeats of the first value. -B3_INLINE const float* b3GetHullSoaVertices( const b3HullData* hull ) +/// Get read only hull planes. +B3_INLINE const b3Plane* b3GetHullPlanes( const b3HullData* hull ) { - if ( hull->soaVertexOffset == 0 ) + if ( hull->planeOffset == 0 ) { return NULL; } - return (const float*)( (intptr_t)hull + hull->soaVertexOffset ); -} - -/// Get read only SOA unit normal vectors. This is an array of normals with all x values, -/// y values, and z values as separate arrays. The array lengths are padded to -/// a multiple of 8. The padded values are 0. -B3_INLINE const float* b3GetHullSoaNormals( const b3HullData* hull ) -{ - if ( hull->soaNormalOffset == 0 ) - { - return NULL; - } - - return (const float*)( (intptr_t)hull + hull->soaNormalOffset ); -} - -/// Get the dot products of the two adjacent face normals for each full edge. -B3_INLINE const float* b3GetHullEdgeCosines( const b3HullData* hull ) -{ - if ( hull->edgeCosineOffset == 0 ) - { - return NULL; - } - - return (const float*)( (intptr_t)hull + hull->edgeCosineOffset ); + return (const b3Plane*)( (intptr_t)hull + hull->planeOffset ); } /// Create a tessellated cylinder as a hull. @@ -235,11 +197,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. -B3_API b3HullData* b3CreateComplexHull( float radius ); - -/// Create a generic convex hull. This can fail if B3_MAX_HULL_VERTICES, B3_MAX_HULL_FACES, -/// or B3_MAX_HULL_EDGES is exceeded. +/// Create a generic convex hull. B3_API b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCount ); /// Deep clone a hull. @@ -345,28 +303,6 @@ B3_INLINE const uint8_t* b3GetMeshFlags( const b3MeshData* mesh ) return (const uint8_t*)( (intptr_t)mesh + mesh->flagsOffset ); } -/// Get read only quantized angles between neighboring triangle normals. -B3_INLINE const int8_t* b3GetMeshEdgeAngles( const b3MeshData* mesh ) -{ - if ( mesh->edgeAngleOffset == 0 ) - { - return NULL; - } - - return (const int8_t*)( (intptr_t)mesh + mesh->edgeAngleOffset ); -} - -/// Get read only vertex flags. -B3_INLINE const uint8_t* b3GetMeshVertexFlags( const b3MeshData* mesh ) -{ - if ( mesh->vertexFlagOffset == 0 ) - { - return NULL; - } - - return (const uint8_t*)( (intptr_t)mesh + mesh->vertexFlagOffset ); -} - /// Create a grid mesh along the x and z axes. /// @param xCount the number of rows in the x direction /// @param zCount the number of rows in the z direction @@ -447,8 +383,8 @@ B3_API b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data ); B3_API b3HeightFieldData* b3CreateGrid( int rowCount, int columnCount, b3Vec3 scale, bool makeHoles ); /// Create a wave grid as a height field. -B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, - float columnFrequency, bool makeHoles ); +B3_API b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency, + bool makeHoles ); /// Destroy a height field. B3_API void b3DestroyHeightField( b3HeightFieldData* heightField ); @@ -493,8 +429,15 @@ 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. -B3_API const b3CompoundData* b3ValidateCompound( const uint8_t* bytes, int byteCount ); +/// If bytes is null then this returns the number of required bytes. This clones all the +/// data into the bytes buffer. This is expected to run offline or asynchronously. +/// This mutates the compound to nullify pointers, leaving the compound in an unusable state. +B3_API uint8_t* b3ConvertCompoundToBytes( b3CompoundData* compound ); + +/// Convert bytes to compound. This does not clone. The bytes must remain in scope while the +/// compound is used. This is done to improve run-time performance and allow for instancing. +/// The bytes are mutated to fixup pointers. +B3_API b3CompoundData* b3ConvertBytesToCompound( uint8_t* bytes, int byteCount ); /**@}*/ // compound @@ -547,8 +490,7 @@ B3_API bool b3OverlapCapsule( const b3Capsule* shape, b3Transform shapeTransform B3_API bool b3OverlapCompound( const b3CompoundData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy ); /// Overlap shape versus height field -B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform, - const b3ShapeProxy* proxy ); +B3_API bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy ); /// Overlap shape versus hull B3_API bool b3OverlapHull( const b3HullData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy ); @@ -606,34 +548,29 @@ B3_API b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* shape, cons /// Query callback. typedef bool b3MeshQueryFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ); -/// Query a mesh for triangles overlapping a bounding box in local space. May have false positives. Useful for debug -/// draw. +/// Query a mesh for triangles overlapping a bounding box in local space. May have false positives. Useful for debug draw. /// @param mesh the mesh to query, includes scale /// @param bounds the bounding box in local space /// @param fcn a user function to collect triangles /// @param context the context sent to the user function. B3_API void b3QueryMesh( const b3Mesh* mesh, const b3AABB bounds, b3MeshQueryFcn* fcn, void* context ); -/// Query a height field for triangles overlapping a bounding box in local space. May have false positives. Useful for -/// debug draw. +/// Query a height field for triangles overlapping a bounding box in local space. May have false positives. Useful for debug draw. /// @param heightField the height field to query /// @param bounds the bounding box in local space /// @param fcn a user function to collect triangles /// @param context the context sent to the user function. -B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn, - void* context ); +B3_API void b3QueryHeightField( const b3HeightFieldData* heightField, b3AABB bounds, b3MeshQueryFcn* fcn, void* context ); /// Compute the closest points between two shapes represented as point clouds. /// b3SimplexCache cache is input/output. On the first call set b3SimplexCache.count to zero. /// The query runs in frame A, so the witness points and normal are returned in frame A. -/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 -/// for these. +/// The underlying GJK algorithm may be debugged by passing in debug simplexes and capacity. You may pass in NULL and 0 for these. B3_API b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* cache, b3Simplex* simplexes, int simplexCapacity ); -/// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation -/// fraction. The query runs in frame A, so the hit point and normal are returned in frame A. Initially touching shapes -/// are a miss. +/// Perform a linear shape cast of shape B moving and shape A fixed. Determines the hit point, normal, and translation fraction. +/// The query runs in frame A, so the hit point and normal are returned in frame A. Initially touching shapes are a miss. B3_API b3CastOutput b3ShapeCast( const b3ShapeCastPairInput* input ); /// Evaluate the transform sweep at a specific time. @@ -661,68 +598,32 @@ B3_API void b3CollideCapsuleAndSphere( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereB, b3Transform transformBtoA ); /// Collide a hull and a sphere. -B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, - const b3Sphere* sphereB, b3Transform transformBtoA, b3SimplexCache* cache ); +B3_API void b3CollideHullAndSphere( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Sphere* sphereB, + b3Transform transformBtoA, b3SimplexCache* cache ); /// Collide two capsules. -B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, - const b3Capsule* capsuleB, b3Transform transformBtoA ); +B3_API void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, const b3Capsule* capsuleB, + b3Transform transformBtoA ); /// Collide a hull and a capsule. -B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, - const b3Capsule* capsuleB, b3Transform transformBtoA, b3SimplexCache* cache ); +B3_API void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3Capsule* capsuleB, + b3Transform transformBtoA, b3SimplexCache* cache ); /// Collide two hulls. B3_API void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, b3Transform transformBtoA, b3SATCache* cache ); -/// Collide a triangle and capsule. Normal points from triangle to capsule. -B3_API void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA, - const b3Capsule* capsuleB, b3SimplexCache* cache ); +/// Collide a capsule and a triangle. +B3_API void b3CollideCapsuleAndTriangle( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, + const b3Vec3* triangleB, b3SimplexCache* cache ); -/// Collide a triangle and hull. Normal points from triangle to hull. -B3_API void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, - const b3HullData* hullB, b3SATCache* cache, bool enableSpeculative ); +/// Collide a hull and a triangle. +B3_API void b3CollideHullAndTriangle( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, b3Vec3 v1, b3Vec3 v2, + b3Vec3 v3, int triangleFlags, b3SATCache* cache ); -/// Collide a triangle and sphere. Normal points from triangle to sphere. -B3_API void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA, - const b3Sphere* sphereB ); - -/// Collide a mesh and hull for testing. -B3_API int b3CollideMeshAndHull( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3HullData* hull, - b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts ); - -/// Collide a mesh and sphere for testing. -B3_API int b3CollideMeshAndSphere( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3Sphere* sphere, - b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts ); - -/// This is used for computing 2D hulls in service of contact manifold simplification. -/// Placed here for testing. Internal. -typedef struct b3Point2D -{ - b3Vec2 p; ///< 2D point - float separation; ///< separation of the associated contact point - int originalIndex; ///< original index of the associated contact point -} b3Point2D; - -/// Options for how a 2D hull is built. -typedef enum b3Hull2DFlags -{ - /// Keep collinear points. - b3_hull2DKeepCollinear = 0x01, - - /// Only merge identical points. - b3_hull2DExactMerge = 0x02, - - /// Order the output points by the input order. - b3_hull2DIndexOrder = 0x04, -} b3Hull2DFlags; - -/// Compute a 2D hull. Used internally for contact manifold simplification. Here for testing. -B3_API int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags ); - -/// Simplify a 2D hull. Used internally for contact manifold simplification. Here for testing. -B3_API int b3SimplifyHull2D( b3Point2D* hull, int count, int target ); +/// Collide a sphere and a triangle. +B3_API void b3CollideSphereAndTriangle( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA, + const b3Vec3* triangleB ); /**@}*/ // collision diff --git a/include/box3d/config.h b/include/box3d/config.h index 011a5cf..2790fc0 100644 --- a/include/box3d/config.h +++ b/include/box3d/config.h @@ -15,19 +15,17 @@ // A define passed on the compiler command line still wins over this file. // Large world mode. Stores world positions in double precision. Affects ABI. -// #define BOX3D_DOUBLE_PRECISION +//#define BOX3D_DOUBLE_PRECISION // Build the scalar fallback instead of SSE2/NEON. -// #define BOX3D_DISABLE_SIMD +//#define BOX3D_DISABLE_SIMD // Enable internal validation in debug builds. -// #define BOX3D_VALIDATE +//#define BOX3D_VALIDATE // Decorate the public API with your own export macro instead of Box3D's // box3d_EXPORTS/BOX3D_DLL scheme, for example when compiling Box3D into another // shared library. A single value cannot switch between dllexport and dllimport, // so this suits embedding more than shipping Box3D as its own DLL. -// #define BOX3D_EXPORT MYENGINE_API +//#define BOX3D_EXPORT MYENGINE_API -// Enable assertions when NDEBUG is defined -// #define B3_ENABLE_ASSERT diff --git a/include/box3d/constants.h b/include/box3d/constants.h index f702d2d..e32b737 100644 --- a/include/box3d/constants.h +++ b/include/box3d/constants.h @@ -14,9 +14,15 @@ B3_API void b3SetLengthUnitsPerMeter( float lengthUnits ); /// Get the current length units per meter. B3_API float b3GetLengthUnitsPerMeter( void ); -/// Used to detect bad values. In float mode positions greater than about 16km have precision -/// problems, so 100km is a safe limit. Large world mode keeps coordinates accurate much farther -/// from the origin, so the sanity limit widens to keep valid far-field positions from tripping it. +/// Set the threshold for logging stalls. +B3_API void b3SetStallThreshold( float seconds ); + +/// Get the threshold for logging stalls. +B3_API float b3GetStallThreshold( void ); + +// Used to detect bad values. In float mode positions greater than about 16km have precision +// problems, so 100km is a safe limit. Large world mode keeps coordinates accurate much farther +// from the origin, so the sanity limit widens to keep valid far-field positions from tripping it. #if defined( BOX3D_DOUBLE_PRECISION ) #define B3_HUGE ( 1.0e9f * b3GetLengthUnitsPerMeter() ) #else @@ -32,24 +38,22 @@ B3_API float b3GetLengthUnitsPerMeter( void ); /// size array for Box3D task, which may help with creating stable user task pointers. #define B3_MAX_TASKS 256 -/// Maximum number of colors in the constraint graph. Constraints that cannot -/// find a color are added to the overflow set which are solved single-threaded. -/// The compound barrel benchmark has minor overflow with 24 colors +// Maximum number of colors in the constraint graph. Constraints that cannot +// find a color are added to the overflow set which are solved single-threaded. +// The compound barrel benchmark has minor overflow with 24 colors #define B3_GRAPH_COLOR_COUNT 24 -/// A small length used as a collision and constraint tolerance. Usually it is -/// chosen to be numerically significant, but visually insignificant. In meters. -/// @warning modifying this can have a significant impact on stability +// Number of contact point buckets for counting the number of contact points per +// shape contact pair. This is just for reporting and doesn't affect simulation. +#define B3_CONTACT_MANIFOLD_COUNT_BUCKETS 8 + +// A small length used as a collision and constraint tolerance. Usually it is +// chosen to be numerically significant, but visually insignificant. In meters. +// @warning modifying this can have a significant impact on stability #define B3_LINEAR_SLOP ( 0.005f * b3GetLengthUnitsPerMeter() ) -/// The minimum length of a capsules. Very short capsules should be created as spheres -/// to avoid numerical problems. #define B3_MIN_CAPSULE_LENGTH ( B3_LINEAR_SLOP ) -/// Minimum contact point friction weight, lower bound for speculative points. Made small -/// enough to be washed away by weights that hit 1. -#define B3_MIN_FRICTION_WEIGHT ( 1e-10f ) - /// The distance between shapes where they are considered overlapped. This is needed /// because GJK may return small positive values for overlapped shapes in degenerate /// configurations. @@ -66,9 +70,7 @@ B3_API float b3GetLengthUnitsPerMeter( void ); #define B3_MAX_ROTATION ( 0.25f * B3_PI ) /// @warning modifying this can have a significant impact on performance and stability -#ifndef B3_SPECULATIVE_DISTANCE #define B3_SPECULATIVE_DISTANCE ( 4.0f * B3_LINEAR_SLOP ) -#endif /// The rest offset is used for mesh contact to reduce ghost collisions and assist with CCD. /// The rest offset adjusts the contact point separation value, making the solver push the shapes @@ -95,43 +97,24 @@ B3_API float b3GetLengthUnitsPerMeter( void ); /// The time that a body must be still before it will go to sleep. In seconds. #define B3_TIME_TO_SLEEP 0.5f -/// The maximum number of restitution iterations. Needed to avoid a solver overflow. -#define B3_MAX_RESTITUTION_ITERATIONS 63 +/// Maximum length of the body name. Can be 0 if you don't need names. +/// Note: this gates recording capability. +#ifndef B3_BODY_NAME_LENGTH +#define B3_BODY_NAME_LENGTH 18 +#endif -/// The maximum number of contact manifolds between shape pairs. Excess manifolds are dropped using heuristics until -/// this number is reached. Culling can lead to contact dither across time steps. Contact recycling mitigates the -/// dithering. -#define B3_MAX_MANIFOLDS 8 +/// Maximum length of the shape name. Can be 0 if you don't need names. +/// Note: this gates recording capability. +/// todo waiting on this because it breaks existing recordings +#ifndef B3_SHAPE_NAME_LENGTH +#define B3_SHAPE_NAME_LENGTH 18 +#endif /// The maximum number of contact points between two touching shapes. -/// The default and minimum is 4 and this case uses a fast approximate hull to reduce the -/// point count. A larger value builds a 2D convex hull of the candidate points and then -/// simplifies it to the target by dropping the vertices that contribute the least area. -/// Useful for testing, but I don't recommend shipping with it adjusted. -/// WARNING: if you change this you risk breaking ABI and a corrupted runtime. -#ifndef B3_MAX_MANIFOLD_POINTS #define B3_MAX_MANIFOLD_POINTS 4 -#endif - -/// The number of iterations for gyroscopic torques. -#ifndef B3_GYROSCOPIC_ITERATIONS -#define B3_GYROSCOPIC_ITERATIONS 1 -#endif - -/// The maximum number of convex hull vertices. This is fixed for performance reasons. -#define B3_MAX_HULL_VERTICES 128 - -/// The maximum number of convex hull faces. -#define B3_MAX_HULL_FACES 128 - -/// The maximum number of convex hull edges. Full edges, not half-edges. -#define B3_MAX_HULL_EDGES 128 - -/// Relative tolerance used to determine if two edges are parallel. -#define B3_PARALLEL_EDGE_TOL 0.005f /// The maximum number points to use for shape cast proxies (swept point cloud). -#define B3_MAX_SHAPE_CAST_POINTS B3_MAX_HULL_VERTICES +#define B3_MAX_SHAPE_CAST_POINTS 64 /// These generous limits allow for easy hashing. See b3ShapePairKey. #define B3_SHAPE_POWER 22 diff --git a/include/box3d/id.h b/include/box3d/id.h index 9f05e12..447fd34 100644 --- a/include/box3d/id.h +++ b/include/box3d/id.h @@ -96,14 +96,13 @@ static const b3JointId b3_nullJointId = B3_NULL_ID; static const b3ContactId b3_nullContactId = B3_NULL_ID; /// Macro to determine if any id is null. -#define B3_IS_NULL( id ) ( ( id ).index1 == 0 ) +#define B3_IS_NULL( id ) ( id.index1 == 0 ) /// Macro to determine if any id is non-null. -#define B3_IS_NON_NULL( id ) ( ( id ).index1 != 0 ) +#define B3_IS_NON_NULL( id ) ( id.index1 != 0 ) /// Compare two ids for equality. Doesn't work for b3WorldId. Don't mix types. -#define B3_ID_EQUALS( id1, id2 ) \ - ( ( id1 ).index1 == ( id2 ).index1 && ( id1 ).world0 == ( id2 ).world0 && ( id1 ).generation == ( id2 ).generation ) +#define B3_ID_EQUALS( id1, id2 ) ( id1.index1 == id2.index1 && id1.world0 == id2.world0 && id1.generation == id2.generation ) /// Store a world id into a uint32_t. B3_ID_INLINE uint32_t b3StoreWorldId( b3WorldId id ) diff --git a/include/box3d/math_functions.h b/include/box3d/math_functions.h index 86c77c3..7ef7354 100644 --- a/include/box3d/math_functions.h +++ b/include/box3d/math_functions.h @@ -155,6 +155,9 @@ B3_INLINE int b3ClampInt( int a, int lower, int upper ) return a < lower ? lower : ( upper < a ? upper : a ); } +/// @return is this float valid (finite and not NaN). +B3_API bool b3IsValidFloat( float a ); + /// @return the absolute value of a float. B3_INLINE float b3AbsFloat( float a ) { @@ -189,61 +192,20 @@ B3_INLINE float b3LerpFloat( float a, float b, float alpha ) /// This is hand coded for cross-platform determinism. The atan2f /// function in the standard library is not cross-platform deterministic. /// Accurate to around 0.0023 degrees. -/// https://stackoverflow.com/questions/46210708/atan2-approximation-with-11bits-in-mantissa-on-x86with-sse2-and-armwith-vfpv4 -B3_INLINE float b3Atan2( float y, float x ) -{ - // Added check for (0,0) to match atan2f and avoid NaN - if ( x == 0.0f && y == 0.0f ) - { - return 0.0f; - } - - float ax = b3AbsFloat( x ); - float ay = b3AbsFloat( y ); - float mx = b3MaxFloat( ay, ax ); - float mn = b3MinFloat( ay, ax ); - float a = mn / mx; - - // Minimax polynomial approximation to atan(a) on [0,1] - float s = a * a; - float c = s * a; - float q = s * s; - float r = 0.024840285f * q + 0.18681418f; - float t = -0.094097948f * q - 0.33213072f; - r = r * s + t; - r = r * c + a; - - // Map to full circle - if ( ay > ax ) - { - r = 1.57079637f - r; - } - - if ( x < 0 ) - { - r = 3.14159274f - r; - } - - if ( y < 0 ) - { - r = -r; - } - - return r; -} +B3_API float b3Atan2( float y, float x ); /// Compute the cosine and sine of an angle in radians. Implemented /// for cross-platform determinism. B3_API b3CosSin b3ComputeCosSin( float radians ); -/// @deprecated +/// @deprecated B3_INLINE float b3Sin( float radians ) { b3CosSin cs = b3ComputeCosSin( radians ); return cs.sine; } -/// @deprecated +/// @deprecated B3_INLINE float b3Cos( float radians ) { b3CosSin cs = b3ComputeCosSin( radians ); @@ -314,15 +276,17 @@ B3_INLINE float b3DistanceSquared( b3Vec3 a, b3Vec3 b ) } /// Normalize a vector. Returns a zero vector if the input vector is very small. -B3_FORCE_INLINE b3Vec3 b3Normalize( b3Vec3 a ) +B3_INLINE b3Vec3 b3Normalize( b3Vec3 a ) { float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z; + if ( lengthSquared > 1000.0f * FLT_MIN ) { float s = 1.0f / sqrtf( lengthSquared ); b3Vec3 u = { s * a.x, s * a.y, s * a.z }; return u; } + return B3_LITERAL( b3Vec3 ){ 0.0f, 0.0f, 0.0f }; } @@ -330,17 +294,15 @@ B3_FORCE_INLINE b3Vec3 b3Normalize( b3Vec3 a ) /// if the input is very small. B3_INLINE b3Vec3 b3GetLengthAndNormalize( float* length, b3Vec3 a ) { - float lengthSquared = a.x * a.x + a.y * a.y + a.z * a.z; - if ( lengthSquared > 1000.0f * FLT_MIN ) + *length = b3Length( a ); + if ( *length < FLT_EPSILON ) { - *length = sqrtf( lengthSquared ); - float s = 1.0f / *length; - b3Vec3 u = { s * a.x, s * a.y, s * a.z }; - return u; + return b3Vec3_zero; } - *length = 0.0f; - return B3_LITERAL( b3Vec3 ){ 0.0f, 0.0f, 0.0f }; + float invLength = 1.0f / *length; + b3Vec3 n = { invLength * a.x, invLength * a.y, invLength * a.z }; + return n; } /// Get a unit vector that is perpendicular to the supplied vector. @@ -612,7 +574,7 @@ B3_INLINE float b3GetTwistAngle( b3Quat q ) } /// Swing angle used for cone limit -B3_FORCE_INLINE float b3GetSwingAngle( b3Quat q ) +B3_INLINE float b3GetSwingAngle( b3Quat q ) { // Polarity should not matter because all terms are squared. float x = sqrtf( q.v.z * q.v.z + q.s * q.s ); @@ -670,7 +632,7 @@ B3_INLINE b3Transform b3InvertTransform( b3Transform t ) } /// Transform a point. -B3_FORCE_INLINE b3Vec3 b3TransformPoint( b3Transform t, b3Vec3 v ) +B3_INLINE b3Vec3 b3TransformPoint( b3Transform t, b3Vec3 v ) { b3Vec3 rv = b3RotateVector( t.q, v ); return b3Add( rv, t.p ); @@ -759,18 +721,8 @@ B3_INLINE b3Vec3 b3InvTransformWorldPoint( b3WorldTransform t, b3Pos p ) return b3InvRotateVector( t.q, d ); } -/// Compose a world transform with a local transform. -B3_FORCE_INLINE b3WorldTransform b3MulWorldTransforms( b3WorldTransform A, b3Transform B ) -{ - b3WorldTransform C; - C.q = b3MulQuat( A.q, B.q ); - b3Vec3 r = b3RotateVector( A.q, B.p ); - C.p = B3_LITERAL( b3Pos ){ A.p.x + r.x, A.p.y + r.y, A.p.z + r.z }; - return C; -} - /// Relative transform of frame B in frame A. The narrow phase boundary. -B3_FORCE_INLINE b3Transform b3InvMulWorldTransforms( b3WorldTransform A, b3WorldTransform B ) +B3_INLINE b3Transform b3InvMulWorldTransforms( b3WorldTransform A, b3WorldTransform B ) { b3Transform C; C.q = b3InvMulQuat( A.q, B.q ); @@ -779,6 +731,16 @@ B3_FORCE_INLINE b3Transform b3InvMulWorldTransforms( b3WorldTransform A, b3World return C; } +/// Compose a world transform with a local transform. +B3_INLINE b3WorldTransform b3MulWorldTransforms( b3WorldTransform A, b3Transform B ) +{ + b3WorldTransform C; + C.q = b3MulQuat( A.q, B.q ); + b3Vec3 r = b3RotateVector( A.q, B.p ); + C.p = B3_LITERAL( b3Pos ){ A.p.x + r.x, A.p.y + r.y, A.p.z + r.z }; + return C; +} + /// Shift a world transform into the frame of a base position. B3_INLINE b3Transform b3ToRelativeTransform( b3WorldTransform t, b3Pos base ) { @@ -797,10 +759,9 @@ B3_INLINE b3WorldTransform b3MakeWorldTransform( b3Transform t ) return w; } -/// Translate a local AABB by a world position, rounding outward so the single precision box -/// encloses the double precision box. Far from the origin a plain conversion could clip a -/// shape out of its own box. -/// In single precision mode the the rounding is a no-op. +/// Translate a local AABB by a world origin, rounding outward so the float box always contains +/// the double box. Far from the origin a plain conversion could clip a shape out of its own box. +/// In float mode the origin is float and the rounding is a no-op. B3_INLINE b3AABB b3OffsetAABB( b3AABB localBox, b3Pos origin ) { b3AABB out; @@ -914,7 +875,7 @@ B3_INLINE b3Matrix3 b3InvertMatrix( b3Matrix3 m ) /// Solve a matrix equation. /// @return inv(m) * a -B3_FORCE_INLINE b3Vec3 b3Solve3( b3Matrix3 m, b3Vec3 a ) +B3_INLINE b3Vec3 b3Solve3( b3Matrix3 m, b3Vec3 a ) { float det = b3Det( m ); if ( b3AbsFloat( det ) > 1000.0f * FLT_MIN ) @@ -1079,7 +1040,7 @@ B3_INLINE bool b3AABB_Overlaps( b3AABB a, b3AABB b ) /// Transform an axis-aligned bounding box. This can create a larger box /// than if you recomputed the AABB of the original shape with the transform /// applied. -B3_FORCE_INLINE b3AABB b3AABB_Transform( b3Transform transform, b3AABB a ) +B3_INLINE b3AABB b3AABB_Transform( b3Transform transform, b3AABB a ) { b3Vec3 center = b3TransformPoint( transform, b3AABB_Center( a ) ); b3Matrix3 m = b3MakeMatrixFromQuat( transform.q ); @@ -1094,18 +1055,6 @@ B3_INLINE b3Vec3 b3ClosestPointToAABB( b3Vec3 point, b3AABB a ) return b3Clamp( point, a.lowerBound, a.upperBound ); } -/// One-dimensional mass-spring-damper simulation. Returns the new velocity given the position and -/// time step. You can then compute the new position using: -/// position += timeStep * newVelocity -/// This drives towards a zero position. By using implicit integration we get a stable solution that -/// doesn't require transcendental functions. -B3_INLINE float b3SpringDamper( float hertz, float dampingRatio, float position, float velocity, float timeStep ) -{ - float omega = 2.0f * B3_PI * hertz; - float omegaH = omega * timeStep; - return ( velocity - omega * omegaH * position ) / ( 1.0f + 2.0f * dampingRatio * omegaH + omegaH * omegaH ); -} - /// The closest points between to segments or infinite lines. typedef struct b3SegmentDistanceResult { diff --git a/include/box3d/types.h b/include/box3d/types.h index 6a6a1a2..1e52e4d 100644 --- a/include/box3d/types.h +++ b/include/box3d/types.h @@ -8,120 +8,56 @@ #include "id.h" #include "math_functions.h" -#include #include #define B3_DEFAULT_CATEGORY_BITS UINT64_MAX #define B3_DEFAULT_MASK_BITS UINT64_MAX -/// The task type for the pull model. -/// @ingroup world -typedef enum b3TaskType -{ - b3_taskPairs, ///< Finding pairs of potentially colliding shapes. The broad-phase. - b3_taskCollide, ///< Computing contact manifolds. The narrow-phase. - b3_taskTreeRebuild, ///< Rebuilding the bounding volume hierarchy. A long running side task. - b3_taskIslandSplit, ///< Splitting an island in order to let an island sleep. - b3_taskSolver, ///< Solving constraints. - b3_taskFinalize, ///< Updating body transforms and shape bounding boxes. - b3_taskContinuous, ///< Continuous collision detection. - b3_taskSensors, ///< Sensor overlaps and events. - b3_taskTypeCount ///< The type count. -} b3TaskType; - -/// Helper to get a string for a task type. -B3_API const char* b3GetTaskTypeName( b3TaskType type ); - /// Task interface -/// This is the prototype for a Box3D task. Your task system is expected to run this callback on a -/// worker thread, exactly once per enqueue, passing back the same taskContext pointer supplied to -/// b3EnqueueTaskCallback. +/// This is the prototype for a Box3D task. Your task system is expected to run this callback on a worker thread, +/// exactly once per enqueue, passing back the same taskContext pointer supplied to b3EnqueueTaskCallback. /// @ingroup world typedef void b3TaskCallback( void* taskContext ); /// These functions can be provided to Box3D to invoke a task system. -/// Returns a pointer to the user's task object. May be nullptr. A nullptr indicates to Box3D that -/// the work was executed serially within the callback and there is no need to call -/// b3FinishTaskCallback. Otherwise the returned value must be non-null will be passed to -/// b3FinishTaskCallback as the userTask. +/// Returns a pointer to the user's task object. May be nullptr. A nullptr indicates to Box3D that the work was executed +/// serially within the callback and there is no need to call b3FinishTaskCallback. Otherwise the returned +/// value must be non-null will be passed to b3FinishTaskCallback as the userTask. /// @param task the Box3D task to be called by the scheduler /// @param taskContext the Box3D context object that the scheduler must pass to the task /// @param userContext the scheduler context object that is opaque to Box3D -/// @param taskType the task type that the scheduler can use for diagnostics +/// @param taskName the Box3D task name that the scheduler can use for diagnostics /// @ingroup world -typedef void* b3EnqueueTaskCallback( b3TaskCallback* task, void* taskContext, void* userContext, b3TaskType taskType ); +typedef void* b3EnqueueTaskCallback( b3TaskCallback* task, void* taskContext, void* userContext, const char* taskName ); -/// Finishes a user task object that wraps a Box3D task. This must block until the task has -/// completed. The step blocks here on the tasks it spawned, so b3World_Step holds its stack across -/// every fork/join. Drive it from a thread you can dedicate to the step, or from a fiber this -/// callback can park to free the underlying thread. In a job system that cannot park a job's stack, -/// do not call b3World_Step from inside a job: a job that blocks on its own sub-jobs without -/// yielding its thread can deadlock. The in-tree scheduler instead runs other pending tasks on the -/// waiting thread. -/// This callback is optional. Without it b3World_Step waits on an internal semaphore that the last -/// task of each phase signals, which suits task systems that can launch work but cannot wait on a -/// single task. +/// Finishes a user task object that wraps a Box3D task. This must block until the task has completed. +/// The step blocks here on the tasks it spawned, so b3World_Step holds its stack across every +/// fork/join. Drive it from a thread you can dedicate to the step, or from a fiber this callback can +/// park to free the underlying thread. In a job system that cannot park a job's stack, do not call +/// b3World_Step from inside a job: a job that blocks on its own sub-jobs without yielding its thread +/// can deadlock. The in-tree scheduler instead runs other pending tasks on the waiting thread. /// @ingroup world typedef void b3FinishTaskCallback( void* userTask, void* userContext ); -/// A task in the pull model. -/// @ingroup world -typedef struct b3Task -{ - /// The task function. - b3TaskCallback* fcn; - - /// The context that must be passed to the task function. - void* context; - - /// The task type. Informational. - b3TaskType type; - - /// Is this task deferred? This indicates that this task must be joined - /// at a later stage instead of immediately before the next stage. - /// @see b3TaskBatch::joinTasks - bool deferred; -} b3Task; - -/// A batch of tasks for the pull model. -/// @ingroup world -typedef struct b3TaskBatch -{ - /// The regular tasks that must be executed in this stage. - const b3Task* tasks; - - /// The task count. - int count; - - /// Earlier tasks that must now be joined before the next stage. - const b3Task* joinTasks; - - /// The join task count. - int joinCount; -} b3TaskBatch; - typedef struct b3DebugShape b3DebugShape; -/// The user needs to be able to create debug draw shapes for multi-pass rendering to work -/// efficiently. These user shapes are created and destroyed via callback so they can be bound to -/// shape lifetime and scaling updates. +/// The user needs to be able to create debug draw shapes for multi-pass rendering to work efficiently. +/// These user shapes are created and destroyed via callback so they can be bound to shape lifetime and scaling updates. /// @ingroup debug_draw typedef void* b3CreateDebugShapeCallback( const b3DebugShape* debugShape, void* userContext ); typedef void b3DestroyDebugShapeCallback( void* userShape, void* userContext ); -/// Optional friction mixing callback. This intentionally provides no context objects because this -/// is called from a worker thread. +/// Optional friction mixing callback. This intentionally provides no context objects because this is called +/// from a worker thread. /// @warning This function should not attempt to modify Box3D state or user application state. /// @ingroup world -typedef float b3FrictionCallback( float frictionA, uint64_t userMaterialIdA, float frictionB, - uint64_t userMaterialIdB ); +typedef float b3FrictionCallback( float frictionA, uint64_t userMaterialIdA, float frictionB, uint64_t userMaterialIdB ); -/// Optional restitution mixing callback. This intentionally provides no context objects because -/// this is called from a worker thread. +/// Optional restitution mixing callback. This intentionally provides no context objects because this is called +/// from a worker thread. /// @warning This function should not attempt to modify Box3D state or user application state. /// @ingroup world -typedef float b3RestitutionCallback( float restitutionA, uint64_t userMaterialIdA, float restitutionB, - uint64_t userMaterialIdB ); +typedef float b3RestitutionCallback( float restitutionA, uint64_t userMaterialIdA, float restitutionB, uint64_t userMaterialIdB ); /// Prototype for a contact filter callback. /// This is called when a contact pair is considered for collision. This allows you to @@ -170,8 +106,7 @@ typedef bool b3OverlapResultFcn( b3ShapeId shapeId, void* context ); /// @param normal the normal vector at the point of intersection /// @param fraction the fraction along the ray at the point of intersection /// @param userMaterialId the shape or triangle surface type -/// @param triangleIndex the triangle index for mesh or height field shapes or -1 for other shape -/// types +/// @param triangleIndex the triangle index for mesh or height field shapes or -1 for other shape types /// @param childIndex the child shape index for compound shapes /// @param context the user context /// @return -1 to filter, 0 to terminate, fraction to clip the ray for closest hit, 1 to continue @@ -211,38 +146,25 @@ typedef struct b3WorldDef /// speed have restitution applied (will bounce). float restitutionThreshold; - /// Number of iterations of the restitution solver. More iterations can lead to less box - /// spinning. - /// @see B3_MAX_RESTITUTION_ITERATIONS - int restitutionIterations; - - /// Enable full contact propagation in the restitution solver. Expensive. - bool enableRestitutionPropagation; - /// Hit event speed threshold, usually in m/s. Collisions above this /// speed can generate hit events if the shape also enables hit events. float hitEventThreshold; - /// Contact stiffness. Cycles per second. Increasing this increases the speed of overlap - /// recovery, but can introduce jitter. + /// Contact stiffness. Cycles per second. Increasing this increases the speed of overlap recovery, but can introduce jitter. float contactHertz; - /// Contact bounciness. Non-dimensional. You can speed up overlap recovery by decreasing this - /// with the trade-off that overlap resolution becomes more energetic. + /// Contact bounciness. Non-dimensional. You can speed up overlap recovery by decreasing this with + /// the trade-off that overlap resolution becomes more energetic. float contactDampingRatio; - /// This parameter controls how fast overlap is resolved and usually has units of meters per - /// second. This only puts a cap on the resolution speed. The resolution speed is increased by - /// increasing the hertz and/or decreasing the damping ratio. + /// This parameter controls how fast overlap is resolved and usually has units of meters per second. This only + /// puts a cap on the resolution speed. The resolution speed is increased by increasing the hertz and/or + /// decreasing the damping ratio. float contactSpeed; /// Maximum linear speed. Usually meters per second. float maximumLinearSpeed; - /// Use this to disable gyroscopic torque on sphere-like objects automatically. - /// Range is [0, 1]. A sphere is 0 and a 1x1x2 box is 0.5. - float isotropicInertiaTolerance; - /// Optional mixing callback for friction. The default uses sqrt(frictionA * frictionB). b3FrictionCallback* frictionCallback; @@ -256,17 +178,17 @@ typedef struct b3WorldDef bool enableContinuous; /// Number of workers to use with the provided task system. Box3D performs best when using only - /// performance cores and accessing a single L2 cache. Efficiency cores and hyper-threading - /// provide little benefit and may even harm performance. This is clamped to the range [1, - /// B3_MAX_WORKERS]. Using a value above 1 will turn on multithreading. If task callbacks are - /// provided then Box3D will use the user provided task system. Otherwise Box3D will create - /// threads and use an internal scheduler. + /// performance cores and accessing a single L2 cache. Efficiency cores and hyper-threading provide + /// little benefit and may even harm performance. + /// This is clamped to the range [1, B3_MAX_WORKERS]. Using a value above 1 will turn on multithreading. + /// If task callbacks are provided then Box3D will use the user provided task system. Otherwise Box3D + /// will create threads and use an internal scheduler. uint32_t workerCount; /// function to spawn task b3EnqueueTaskCallback* enqueueTask; - /// function to finish a task. Blocks and helps make progress. + /// function to finish a task b3FinishTaskCallback* finishTask; /// User context that is provided to enqueueTask and finishTask @@ -297,8 +219,7 @@ typedef struct b3WorldDef B3_API b3WorldDef b3DefaultWorldDef( void ); /// The body simulation type. -/// Each body is one of these three types. The type determines how the body behaves in the -/// simulation. +/// Each body is one of these three types. The type determines how the body behaves in the simulation. /// @ingroup body typedef enum b3BodyType { @@ -349,8 +270,8 @@ typedef struct b3BodyDef b3BodyType type; /// The initial world position of the body. Bodies should be created with the desired position. - /// @note Creating bodies at the origin and then moving them nearly doubles the cost of body - /// creation, especially if the body is moved after shapes have been added. + /// @note Creating bodies at the origin and then moving them nearly doubles the cost of body creation, especially + /// if the body is moved after shapes have been added. b3Pos position; /// The initial world rotation of the body. @@ -381,15 +302,7 @@ typedef struct b3BodyDef /// Sleep speed threshold, default is 0.05 meters per second float sleepThreshold; - /// Continuous collision safety factor. The solver only uses continuous collision if there is a - /// risk of tunneling. If the body is moving fast enough to risk tunneling then it is considered - /// a "fast body". This improves performance and prevents movement hitches. If a body moving N - /// meter risks tunneling, then the body will be considered fast if it moves more than a - /// safetyFactor times N meters over one full time step. Non-dimensional. Recommended range - /// [0.01, 0.5]. Default is 0.5 for high performance with low tunneling risk. - float safetyFactor; - - /// Optional body name for debugging. + /// Optional body name for debugging. Up to B3_BODY_NAME_LENGTH characters (including null termination) const char* name; /// Use this to store application specific body data. @@ -406,19 +319,18 @@ typedef struct b3BodyDef /// Treat this body as a high speed object that performs continuous collision detection /// against dynamic and kinematic bodies, but not other bullet bodies. - /// @warning Bullets should be used sparingly. They are not a solution for general - /// dynamic-versus-dynamic continuous collision. They do not guarantee accurate collision if - /// both bodies are fast moving because the bullet does a continuous check after all non-bullet - /// bodies have moved. You could get unlucky and have the bullet body end a time step very close - /// to a non-bullet body and the non-bullet body then moves over the bullet body. In continuous - /// collision, initial overlap is ignored to avoid freezing bodies in place. I do not recommend - /// using them for game projectiles if precise collision timing is needed. Instead consider - /// using a ray or shape cast. You can use a marching ray or shape cast for projectile that - /// moves over time. If you want a fast moving projectile to collide with a fast moving target, - /// you need to consider the relative movement in your ray or shape cast. This is out of the - /// scope of Box3D. So what are good use cases for bullets? Pinball games or games with dynamic - /// containers that hold other objects. It should be a use case where it doesn't break the game - /// if there is a collision missed, but having them captured improves the quality of the game. + /// @warning Bullets should be used sparingly. They are not a solution for general dynamic-versus-dynamic + /// continuous collision. They do not guarantee accurate collision if both bodies are fast moving because + /// the bullet does a continuous check after all non-bullet bodies have moved. You could get unlucky and have + /// the bullet body end a time step very close to a non-bullet body and the non-bullet body then moves over + /// the bullet body. In continuous collision, initial overlap is ignored to avoid freezing bodies in place. + /// I do not recommend using them for game projectiles if precise collision timing is needed. Instead consider + /// using a ray or shape cast. You can use a marching ray or shape cast for projectile that moves over time. + /// If you want a fast moving projectile to collide with a fast moving target, you need to consider the relative + /// movement in your ray or shape cast. This is out of the scope of Box3D. + /// So what are good use cases for bullets? Pinball games or games with dynamic containers that hold other objects. + /// It should be a use case where it doesn't break the game if there is a collision missed, but having them + /// captured improves the quality of the game. bool isBullet; /// Used to disable a body. A disabled body does not move or collide. @@ -472,8 +384,8 @@ typedef struct b3Filter /// or always collide (positive). A group index of zero has no effect. Non-zero group filtering /// always wins against the mask bits. /// For example, you may want ragdolls to collide with other ragdolls but you don't want - /// ragdoll self-collision. In this case you would give each ragdoll a unique negative group - /// index and apply that group index to all shapes on the ragdoll. + /// ragdoll self-collision. In this case you would give each ragdoll a unique negative group index + /// and apply that group index to all shapes on the ragdoll. int groupIndex; } b3Filter; @@ -492,8 +404,7 @@ typedef struct b3SurfaceMaterial /// https://en.wikipedia.org/wiki/Coefficient_of_restitution float restitution; - /// The rolling resistance usually in the range [0,1]. This is only used for spheres and - /// capsules. + /// The rolling resistance usually in the range [0,1]. This is only used for spheres and capsules. float rollingResistance; /// The tangent velocity for conveyor belts. This is local to the shape and will be projected @@ -508,9 +419,6 @@ typedef struct b3SurfaceMaterial /// carry a b3DebugMaterial preset, see b3MakeDebugColor. /// @see b3HexColor uint32_t customColor; - - /// Explicit padding. Must be zero. - uint32_t padding; } b3SurfaceMaterial; /// Use this to initialize your surface material @@ -524,7 +432,7 @@ typedef enum b3ShapeType /// A capsule is an extruded sphere b3_capsuleShape, - /// A baked compound shape composed of spheres, capsules, hulls, and meshes + /// A compound shape composed of up to 64K spheres, capsules, hulls, and meshes b3_compoundShape, /// A height field useful for terrain @@ -547,14 +455,10 @@ typedef enum b3ShapeType /// @ingroup shape typedef struct b3ShapeDef { - /// Optional shape name for debugging - const char* name; - /// Use this to store application specific shape data. void* userData; - /// Surface material used on mesh shapes per triangle. Ignored for convex shapes. Ignored for - /// compound shapes. + /// Surface material used on mesh shapes per triangle. Ignored for convex shapes. Ignored for compound shapes. b3SurfaceMaterial* materials; /// Surface material count. @@ -572,51 +476,37 @@ typedef struct b3ShapeDef /// Contact filtering data. b3Filter filter; - /// Enable custom filtering. Only one of the two shapes needs to enable custom filtering. See - /// b3WorldDef. + /// Enable custom filtering. Only one of the two shapes needs to enable custom filtering. See b3WorldDef. bool enableCustomFiltering; /// A sensor shape generates overlap events but never generates a collision response. - /// Sensors do not have continuous collision. Instead, use a ray or shape cast for those - /// scenarios. Sensors still contribute to the body mass if they have non-zero density. + /// Sensors do not have continuous collision. Instead, use a ray or shape cast for those scenarios. + /// Sensors still contribute to the body mass if they have non-zero density. /// @note Sensor events are disabled by default. /// @see enableSensorEvents bool isSensor; - /// Enable sensor events for this shape. This applies to sensors and non-sensors. False by - /// default, even for sensors. Only convex shapes may act as sensor visitors. + /// Enable sensor events for this shape. This applies to sensors and non-sensors. False by default, even for sensors. bool enableSensorEvents; - /// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored - /// for sensors. False by default. + /// Enable contact events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default. bool enableContactEvents; - /// Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for - /// sensors. False by default. + /// Enable hit events for this shape. Only applies to kinematic and dynamic bodies. Ignored for sensors. False by default. bool enableHitEvents; - /// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are - /// expensive + /// Enable pre-solve contact events for this shape. Only applies to dynamic bodies. These are expensive /// and must be carefully handled due to multithreading. Ignored for sensors. bool enablePreSolveEvents; - /// When shapes are created they will scan the environment for collision the next time step. - /// This can significantly slow down static body creation when there are many static shapes. - /// This is flag is ignored for dynamic and kinematic shapes which always invoke contact - /// creation. + /// When shapes are created they will scan the environment for collision the next time step. This can significantly slow down + /// static body creation when there are many static shapes. + /// This is flag is ignored for dynamic and kinematic shapes which always invoke contact creation. bool invokeContactCreation; /// Should the body update the mass properties when this shape is created. Default is true. - /// Warning: if this is false, you MUST call b3Body_ApplyMassFromShapes or b3Body_SetMassData - /// before simulating the world. bool updateBodyMass; - /// Enable speculative collision. Leave this true unless you care about reducing ghost collision - /// more than continuous collision under rotation. - /// Experimental: this can only disable speculative contact between hulls and triangles (meshes - /// and height fields). - bool enableSpeculativeContact; - /// Used internally to detect a valid definition. DO NOT SET. int internalValue; @@ -626,72 +516,69 @@ typedef struct b3ShapeDef /// @ingroup shape B3_API b3ShapeDef b3DefaultShapeDef( void ); +//! @cond /// Profiling data. Times are in milliseconds. /// @ingroup world typedef struct b3Profile { - float step; ///< - float pairs; ///< - float collide; ///< - float solve; ///< - float solverSetup; ///< - float constraints; ///< - float prepareConstraints; ///< - float integrateVelocities; ///< - float warmStart; ///< - float solveImpulses; ///< - float integratePositions; ///< - float relaxImpulses; ///< - float restitution; ///< - float storeImpulses; ///< - float splitIslands; ///< - float transforms; ///< - float sensorHits; ///< - float jointEvents; ///< - float hitEvents; ///< - float refit; ///< - float bullets; ///< - float sleepIslands; ///< - float sensors; ///< + float step; + float pairs; + float collide; + float solve; + float solverSetup; + float constraints; + float prepareConstraints; + float integrateVelocities; + float warmStart; + float solveImpulses; + float integratePositions; + float relaxImpulses; + float applyRestitution; + float storeImpulses; + float splitIslands; + float transforms; + float sensorHits; + float jointEvents; + float hitEvents; + float refit; + float bullets; + float sleepIslands; + float sensors; } b3Profile; /// Counters that give details of the simulation size. /// @ingroup world typedef struct b3Counters { - int64_t byteCount; ///< - int bodyCount; ///< - int shapeCount; ///< - int contactCount; ///< - int jointCount; ///< - int islandCount; ///< - int stackUsed; ///< - int arenaCapacity; ///< - int staticTreeHeight; ///< - int treeHeight; ///< - int satCallCount; ///< - int satCacheHitCount; ///< - int taskCount; ///< - int enqueueCount; ///< - int colorCounts[24]; ///< - int manifoldCounts[B3_MAX_MANIFOLDS]; ///< + int bodyCount; + int shapeCount; + int contactCount; + int jointCount; + int islandCount; + int stackUsed; + int arenaCapacity; + int staticTreeHeight; + int treeHeight; + int satCallCount; + int satCacheHitCount; + int byteCount; + int taskCount; + int colorCounts[24]; + int manifoldCounts[B3_CONTACT_MANIFOLD_COUNT_BUCKETS]; /// Number of contacts touched by the collide pass /// graph contacts + awake-set non-touching - int awakeContactCount; // + int awakeContactCount; /// Number of contacts recycled in the most recent step. int recycledContactCount; - /// Maximum number of time of impact outer iterations + /// Maximum number of time of impact iterations int distanceIterations; - - /// Maximum TOI push backs. int pushBackIterations; - - /// Maximum TOI root solver iterations. int rootIterations; } b3Counters; +//! @endcond /// Joint type enumeration. This is useful because all joint types use b3JointId and sometimes you /// want to get the type of a joint. @@ -707,8 +594,6 @@ typedef enum b3JointType b3_sphericalJoint, b3_weldJoint, b3_wheelJoint, - b3_moverJoint, - b3_pogoJoint, } b3JointType; /// Base joint definition used by all joint types. The local frames are measured from the @@ -848,64 +733,6 @@ typedef struct b3MotorJointDef /// @ingroup motor_joint B3_API b3MotorJointDef b3DefaultMotorJointDef( void ); -/// A mover joint is used to move a dynamic character mover through velocity commands. Force is only -/// applied in the xz plane of joint frame B. Does not affect rotation. -/// @ingroup mover_joint -typedef struct b3MoverJointDef -{ - /// Base joint definition - b3JointDef base; - - /// The desired linear velocity - b3Vec3 linearVelocity; - - /// The maximum motor force in newtons. - float maxForce; -} b3MoverJointDef; - -/// Use this to initialize your joint definition -/// @ingroup mover_joint -B3_API b3MoverJointDef b3DefaultMoverJointDef( void ); - -/// The pogo joint is used for the dynamic character mover. The pogo axis is along the frame B -/// y-axis. -/// @ingroup pogo_joint -typedef struct b3PogoJointDef -{ - /// Base joint definition - b3JointDef base; - - /// Normal vector at the contact - b3Vec3 normal; - - /// The spring stiffness Hertz, cycles per second - float hertz; - - /// The spring damping ratio, non-dimensional - float dampingRatio; - - /// Spring length. - float restLength; - - /// Maximum tension force. Controls how sticky the mover is to ground. - float maxTensionForce; - - /// Maximum compression force. How hard the pogo pushes the mover up from the ground. - float maxCompressionForce; - - /// The initial pogo internal impulse. The pogo is typically recreated every frame. This gives a - /// way to move the internal state forward for smoother spring behavior. - float impulse; - - /// The initial pogo internal velocity. The pogo is typically recreated every frame. This gives - /// a way to move the internal state forward for smoother spring behavior. - float velocity; -} b3PogoJointDef; - -/// Use this to initialize your joint definition -/// @ingroup pogo_joint -B3_API b3PogoJointDef b3DefaultPogoJointDef( void ); - /// A filter joint is used to disable collision between two specific bodies. /// @ingroup filter_joint typedef struct b3FilterJointDef @@ -1072,9 +899,7 @@ typedef struct b3SphericalJointDef /// The maximum motor torque, typically in newton-meters. Non-negative number. float maxMotorTorque; - /// The desired motor angular velocity in radians per second. This is the relative angular - /// velocity between the two bodies in world space. - /// motorVelocity = angularVelocityB - angularVelocityA + /// The desired motor angular velocity in radians per second. b3Vec3 motorVelocity; } b3SphericalJointDef; @@ -1214,9 +1039,8 @@ B3_API b3ExplosionDef b3DefaultExplosionDef( void ); * Also when events occur in the simulation step it may be problematic to modify the world, which is * often what applications want to do when events occur. * - * With event arrays, you can scan the events in a loop and modify the world. However, you need to - * be careful that some event data may become invalid. There are several samples that show how to do - * this safely. + * With event arrays, you can scan the events in a loop and modify the world. However, you need to be careful + * that some event data may become invalid. There are several samples that show how to do this safely. * * @{ */ @@ -1275,8 +1099,8 @@ typedef struct b3ContactBeginTouchEvent /// Id of the second shape b3ShapeId shapeIdB; - /// The transient contact id. This contact may be destroyed automatically when the world is - /// modified or simulated. Use b3Contact_IsValid before using this id. + /// The transient contact id. This contact may be destroyed automatically when the world is modified or simulated. + /// Use b3Contact_IsValid before using this id. b3ContactId contactId; } b3ContactBeginTouchEvent; @@ -1302,8 +1126,8 @@ typedef struct b3ContactEndTouchEvent b3ContactId contactId; } b3ContactEndTouchEvent; -/// A hit touch event is generated when two shapes collide with a speed faster than the hit speed -/// threshold. This may be reported for speculative contacts that have a confirmed impulse. +/// A hit touch event is generated when two shapes collide with a speed faster than the hit speed threshold. +/// This may be reported for speculative contacts that have a confirmed impulse. typedef struct b3ContactHitEvent { /// Id of the first shape @@ -1367,8 +1191,8 @@ typedef struct b3ContactEvents /// On the other hand if the flag does not indicate the body went to sleep then the application /// can treat the actor/entity/object associated with the body as awake. /// This is an efficient way for an application to update game object transforms rather than -/// calling functions such as b3Body_GetTransform() because this data is delivered as a contiguous -/// array and it is only populated with bodies that have moved. +/// calling functions such as b3Body_GetTransform() because this data is delivered as a contiguous array +/// and it is only populated with bodies that have moved. /// @note If sleeping is disabled all dynamic and kinematic bodies will trigger move events. typedef struct b3BodyMoveEvent { @@ -1439,8 +1263,7 @@ typedef struct b3ContactData /// this pointer. const struct b3Manifold* manifolds; - /// The number of contact manifolds. For mesh and height-field collision there can be multiple - /// manifolds. + /// The number of contact manifolds. For mesh and height-field collision there can be multiple manifolds. int manifoldCount; } b3ContactData; @@ -1466,15 +1289,14 @@ typedef struct b3QueryFilter /// query would accept for collision. uint64_t maskBits; - /// Optional id combined with @ref name to identify this query in a recording, e.g. an entity - /// id. Need not be unique on its own. 0 with a null name means untagged. Ignored when not - /// recording. + /// Optional id combined with @ref name to identify this query in a recording, e.g. an entity id. + /// Need not be unique on its own. 0 with a null name means untagged. Ignored when not recording. uint64_t id; - /// Optional label combined with @ref id to identify this query, e.g. "bullet". Need not be - /// unique on its own. The recorder hashes (id, name) into one stable key the viewer tracks the - /// query by, so the same id and name pair identifies the same query across frames. NULL means - /// none. Ignored when not recording. + /// Optional label combined with @ref id to identify this query, e.g. "bullet". Need not be unique + /// on its own. The recorder hashes (id, name) into one stable key the viewer tracks the query by, + /// so the same id and name pair identifies the same query across frames. NULL means none. Ignored + /// when not recording. const char* name; } b3QueryFilter; @@ -1558,8 +1380,7 @@ typedef struct b3ShapeCastInput /// The maximum fraction of the translation to consider, typically 1. float maxFraction; - /// Allow shape cast to encroach when initially touching. This only works if the radius is - /// greater than zero. + /// Allow shape cast to encroach when initially touching. This only works if the radius is greater than zero. bool canEncroach; } b3ShapeCastInput; @@ -1683,6 +1504,7 @@ typedef struct b3SimplexCache /// Value use to compare length, area, volume of two simplexes. float metric; + // todo use an index of 0xFF as a sentinel and remove the count /// The number of stored simplex points uint16_t count; @@ -1717,8 +1539,7 @@ typedef struct b3DistanceInput b3ShapeProxy proxyB; /// Transform of shape B in shape A's frame, the relative pose B in A - /// (b3InvMulWorldTransforms( worldA, worldB )). The query is origin independent and runs in - /// frame A. + /// (b3InvMulWorldTransforms( worldA, worldB )). The query is origin independent and runs in frame A. b3Transform transform; /// Should the proxy radius be considered? @@ -1754,9 +1575,9 @@ typedef struct b3Simplex int count; ///< number of valid vertices } b3Simplex; -/// This describes the motion of a body/shape for TOI computation. Shapes are defined with respect -/// to the body origin, which may not coincide with the center of mass. However, to support dynamics -/// we must interpolate the center of mass position. +/// This describes the motion of a body/shape for TOI computation. Shapes are defined with respect to the body origin, +/// which may not coincide with the center of mass. However, to support dynamics we must interpolate the center of mass +/// position. typedef struct b3Sweep { b3Vec3 localCenter; ///< Local center of mass position @@ -1786,31 +1607,31 @@ typedef enum b3TOIState b3_toiStateSeparated } b3TOIState; -/// Time of impact output. +/// Time of impact output typedef struct b3TOIOutput { - /// The type of result. + /// The type of result b3TOIState state; - /// The hit point. A shared point if overlapped. + /// The hit point b3Vec3 point; - /// The hit normal. Zero if overlapped. + /// The hit normal b3Vec3 normal; - /// The sweep time of the collision. 0 if overlapped. + /// The sweep time of the collision float fraction; - /// The final distance. 0 if overlapped. + /// The final distance float distance; - /// Number of outer iterations. + /// Number of outer iterations int distanceIterations; - /// Total number of push back iterations. + /// Total number of push back iterations int pushBackIterations; - /// Total number of root iterations. + /// Total number of root iterations int rootIterations; /// Indicates that the time of impact detected initial @@ -1825,9 +1646,9 @@ typedef struct b3TOIOutput * @defgroup tree Dynamic Tree * The dynamic tree is a binary AABB tree to organize and query large numbers of geometric objects * - * Box3D uses the dynamic tree internally to sort collision shapes into a binary bounding volume - * hierarchy. This data structure may have uses in games for organizing other geometry data and may - * be used independently of Box3D rigid body simulation. + * Box3D uses the dynamic tree internally to sort collision shapes into a binary bounding volume hierarchy. + * This data structure may have uses in games for organizing other geometry data and may be used independently + * of Box3D rigid body simulation. * * A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. * A dynamic tree arranges data in a binary tree to accelerate @@ -1839,46 +1660,58 @@ typedef struct b3TOIOutput * @{ */ -/// A node in the dynamic tree. Siblings sit together at an even index so two nodes fit in -/// a 64 byte cache line. The root is at index zero and index one always empty. +/// Flags for tree nodes. For internal usage. +typedef enum b3TreeNodeFlags +{ + b3_allocatedNode = 0x0001, + b3_enlargedNode = 0x0002, + b3_leafNode = 0x0004, +} b3TreeNodeFlags; + +/// Tree node child indices. For internal usage. +typedef struct b3TreeNodeChildren +{ + int child1; ///< child node index 1 + int child2; ///< child node index 2 +} b3TreeNodeChildren; + +/// A node in the dynamic tree. This is private data placed here for performance reasons. +/// todo test padding to 64 bytes to avoid straddling cache lines typedef struct b3TreeNode { /// The node bounding box b3AABB aabb; // 24 - /// bit 31 : 1 for leaf node - /// bit 30 : 1 for moved flag - /// bits 0-29 : index of the sibling pair node or the proxy id for a leaf - uint32_t flagIndex; // 4 + /// Category bits for collision filtering + uint64_t categoryBits; // 8 union { - /// The height of an internal node. A leaf has zero height. - int32_t height; + /// Children (internal node) + b3TreeNodeChildren children; - /// The shape index for a leaf. Truncated from proxy user data. - int32_t shapeIndex; + /// User data (leaf node) + uint64_t userData; + }; // 8 + + union + { + /// The node parent index (allocated node) + int parent; + + /// The node freelist next index (free node) + int next; }; // 4 + + /// Height of the node. Leaves have a height of 0. + uint16_t height; // 2 + + /// @see b3TreeNodeFlags + uint16_t flags; // 2 } b3TreeNode; -/// Separate storage for tree leaves. -typedef struct b3TreeProxy -{ - /// User data is an index instead of void* because it is used internally as a shape index. - uint64_t userData; - - /// Category bits for collision filtering. - uint64_t categoryBits; - - /// The leaf node. B3_NULL_INDEX for a free proxy. - int32_t node; - - /// Next free proxy. - int32_t next; -} b3TreeProxy; - /// Dynamic tree version for compatibility testing. -#define B3_DYNAMIC_TREE_VERSION 0x1D6F4C2A73B80E91ull +#define B3_DYNAMIC_TREE_VERSION 0x93EDAF889FD30B4Aull /// The dynamic tree structure. This should be considered private data. /// It is placed here for performance reasons. @@ -1888,42 +1721,26 @@ typedef struct b3DynamicTree /// if the tree is serialized. uint64_t version; - /// Array of nodes. The root is at index zero and index 1 is empty. - /// Otherwise siblings are paired at even indices. Has holes for free node pairs. + /// The tree nodes b3TreeNode* nodes; - /// Parent index per node. The free list is interweaved. - int32_t* parents; + /// The root index + int root; - /// Proxy data split from node array as cold data. - b3TreeProxy* proxies; - - /// Every allocated node has a lower index than this. - int32_t nodeEnd; + /// The number of nodes + int nodeCount; /// The allocated node space - int32_t nodeCapacity; - - /// Free pairs below nodeEnd - int32_t pairFreeList; + int nodeCapacity; /// Number of proxies created - int32_t proxyCount; + int proxyCount; - /// The allocated proxy space - int32_t proxyCapacity; - - /// Proxy free list - int32_t proxyFreeList; - - /// Array of nodes for rebuild. - b3TreeNode* swapNodes; + /// Node free list + int freeList; /// Leaf indices for rebuild - int32_t* leafIndices; - - /// Leaves for the rebuild. May represent a proxy or a retained subtree. - b3TreeNode* leafNodes; + int* leafIndices; /// Leaf bounding boxes for rebuild b3AABB* leafBoxes; @@ -1932,14 +1749,10 @@ typedef struct b3DynamicTree b3Vec3* leafCenters; /// Bins for sorting during rebuild - int32_t* binIndices; + int* binIndices; /// Allocated space for rebuilding - int32_t rebuildCapacity; - - /// Rebuild orders the nodes so the children follow parents. Cache friendly for queries - /// and refitting. The order can be disrupted by proxy creation. - bool dfsOrdered; + int rebuildCapacity; } b3DynamicTree; /// These are performance results returned by dynamic tree queries. @@ -1956,8 +1769,7 @@ typedef struct b3TreeStats /// @return true if the query should continue typedef bool b3TreeQueryCallbackFcn( int proxyId, uint64_t userData, void* context ); -/// This function receives the minimum distance squared so far and proxy to check in the closest -/// query. +/// This function receives the minimum distance squared so far and proxy to check in the closest query. /// @return minimum distance squared to user objects in the proxy typedef float b3TreeQueryClosestCallbackFcn( float distanceSqrMin, int proxyId, uint64_t userData, void* context ); @@ -1992,15 +1804,6 @@ typedef struct b3PlaneResult /// Closest point on the shape. May not be unique. b3Vec3 point; - /// The index of the mesh or height field triangle hit. - int triangleIndex; - - /// The index of the compound child shape. - int childIndex; - - /// The material index. - int materialIndex; - } b3PlaneResult; /// These are collision planes that can be fed to b3SolvePlanes. Normally @@ -2017,8 +1820,7 @@ typedef struct b3CollisionPlane /// The push on the mover determined by b3SolvePlanes. Usually in meters. float push; - /// Indicates if b3ClipVector should clip against this plane. Should be false for soft - /// collision. + /// Indicates if b3ClipVector should clip against this plane. Should be false for soft collision. bool clipVelocity; } b3CollisionPlane; @@ -2042,22 +1844,6 @@ typedef struct b3BodyPlaneResult b3PlaneResult result; } b3BodyPlaneResult; -/// Body time of impact result for movers. -typedef struct b3BodyTOIResult -{ - /// The hit point in world space. - b3Pos point; - - /// The hit normal. Points from the body to the mover. - b3Vec3 normal; - - /// The sweep time of the collision. - float fraction; - - /// The hit shape. - b3ShapeId shapeId; -} b3BodyTOIResult; - /// Used to collect collision planes for character movers. /// Return true to continue gathering planes. typedef bool b3PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* plane, int planeCount, void* context ); @@ -2113,7 +1899,8 @@ typedef struct b3Sphere * @{ */ -/// A solid capsule can be viewed as two hemispheres connected by a cylinder. +/// A solid capsule can be viewed as two hemispheres connected +/// by a rectangle. typedef struct b3Capsule { /// Local center of the first hemisphere @@ -2134,7 +1921,8 @@ typedef struct b3Capsule * @{ */ -/// A hull vertex. Identified by a half-edge with this vertex as its tail. +/// A hull vertex. Identified by a half-edge with this +/// vertex as its tail. typedef struct b3HullVertex { /// A half-edge that has this vertex as the origin @@ -2168,7 +1956,7 @@ typedef struct b3HullFace } b3HullFace; /// 64-bit hull version. Useful for validating serialized data. -#define B3_HULL_VERSION 0x6B1E39D4A87C25F3ull +#define B3_HULL_VERSION 0x9D4716CE3793900Eull /// A convex hull. /// @note This data structure has data hanging off the end and cannot be directly copied. @@ -2177,8 +1965,11 @@ typedef struct b3HullData /// Version must be first and match B3_HULL_VERSION uint64_t version; + /// The total number of bytes for this hull. + int byteCount; + /// Hash of this hull (this field is zero when the hash is computed). - uint64_t hash; + uint32_t hash; /// Axis-aligned box in local space. b3AABB aabb; @@ -2192,52 +1983,39 @@ typedef struct b3HullData /// The radius of the largest sphere at the center. float innerRadius; - /// The local centroid. + /// The local centroid b3Vec3 center; /// The inertia tensor about the centroid. b3Matrix3 centralInertia; /// The vertex count. - int32_t vertexCount; + int vertexCount; /// Offset of the vertex array in bytes from the struct address. - int32_t vertexOffset; + int vertexOffset; /// Offset of the point array in bytes from the struct address. - int32_t pointOffset; + int pointOffset; - /// This is the half-edge count (double the edge count). - int32_t edgeCount; + /// This is the half-edge count (double the edge count) + int edgeCount; /// Offset of the edge array in bytes from the struct address. - int32_t edgeOffset; + int edgeOffset; /// The face count. Hulls faces are convex polygons. - int32_t faceCount; - - /// Offset of the face plane array in bytes from the struct address. - int32_t planeOffset; + int faceCount; /// Offset of the face array in bytes from the struct address. - int32_t faceOffset; + int faceOffset; - /// Offset of structure of array (SOA) vertices. - int32_t soaVertexOffset; + /// Offset of the face plane array in bytes from the struct address. + int planeOffset; - /// Offset of structure of array (SOA) unit normal vectors. - int32_t soaNormalOffset; - - /// Offset of dot(n1, n2) for each full edge. - int32_t edgeCosineOffset; - - /// The total number of bytes for this hull. - int32_t byteCount; - - /// Explicit padding for determinism. - int32_t padding; - - /// Any padding must be explicit. + /// Explicit padding. Hull identity is a content hash and memcmp over raw bytes, + /// so there must be no unnamed padding for struct copies to scramble. + int padding; } b3HullData; /// Efficient box hull @@ -2248,16 +2026,9 @@ typedef struct b3BoxHull b3HullVertex boxVertices[8]; ///< Box vertices. b3Vec3 boxPoints[8]; ///< Box points. b3HullHalfEdge boxEdges[24]; ///< Box half-edges. - b3Plane boxPlanes[6]; ///< Box face planes. b3HullFace boxFaces[6]; ///< Box faces. - uint8_t padding[2]; ///< Explicit padding. - float vx[8]; ///< vertex x - float vy[8]; ///< vertex y - float vz[8]; ///< vertex z - float nx[8]; ///< normal x, padded to multiple of 8 - float ny[8]; ///< normal y, padded to multiple of 8 - float nz[8]; ///< normal z, padded to multiple of 8 - float edgeCosines[12]; ///< dot(n1, n2) for each full edge. + uint8_t padding[2]; ///< Explicit padding, see b3HullData::padding. + b3Plane boxPlanes[6]; ///< Box face planes. } b3BoxHull; /**@}*/ // hull @@ -2268,17 +2039,13 @@ typedef struct b3BoxHull * @{ */ -/// This is used to create a re-usable collision mesh. No pointers -/// are held to this data in b3MeshData. So all this data can be temporary. +/// This is used to create a re-usable collision mesh typedef struct b3MeshDef { - /// Triangle vertices. + /// Triangle vertices b3Vec3* vertices; - /// Stride between vertices. Use 0 for contiguous vertices. - size_t stride; - - /// Triangle vertex indices. 3 for each triangle. CCW winding unless CW is indicated below. + /// Triangle vertex indices. 3 for each triangle. int32_t* indices; /// Triangle material index. 1 per triangle. Indexes into b3ShapeDef::materials. @@ -2304,13 +2071,10 @@ typedef struct b3MeshDef /// Compute triangle adjacency information using shared edges bool identifyEdges; - - /// Input indices have clockWise winding order. - bool clockWiseWinding; } b3MeshDef; /// 64-bit mesh version. Useful for validating serialized data. -#define B3_MESH_VERSION 0x24AA0BF74682501Dull +#define B3_MESH_VERSION 0xABD11AB62A6E886Dull /// Triangle mesh edge flags. typedef enum b3MeshEdgeFlags @@ -2341,16 +2105,6 @@ typedef struct b3MeshTriangle int32_t index3; ///< Index of vertex 3. } b3MeshTriangle; -/// Indicates an isolated edge (treated as a cliff). -#define B3_BOUNDARY_EDGE_ANGLE ( -128 ) - -/// Mesh vertex flags. Used for ghost collision handling. -typedef enum b3MeshVertexFlags -{ - b3_flatVertex = 0x01, ///< All edges are flat. - b3_concaveVertex = 0x02, ///< Any edge is concave. -} b3MeshVertexFlags; - /// A mesh BVH node. typedef struct b3MeshNode { @@ -2387,19 +2141,18 @@ typedef struct b3MeshNode uint32_t triangleOffset; } b3MeshNode; -/// This is a sorted triangle collision bounding volume hierarchy. Offsets are a byte -/// count offset from the struct address. +/// This is a sorted triangle collision bounding volume hierarchy. /// @note This struct has data hanging off the end and cannot be directly copied. typedef struct b3MeshData { /// Version must be first. uint64_t version; - /// Hash of this mesh (this field is zero when the hash is computed) - uint64_t hash; - /// The total number of bytes for this mesh. - int32_t byteCount; + int byteCount; + + /// Hash of this mesh (this field is zero when the hash is computed) + uint32_t hash; /// Local axis-aligned box. b3AABB bounds; @@ -2408,46 +2161,37 @@ typedef struct b3MeshData float surfaceArea; /// The height of the bounding volume hierarchy. - int32_t treeHeight; + int treeHeight; /// The number of degenerate triangles. Diagnostic. - int32_t degenerateCount; + int degenerateCount; - /// Offset of the node array. - int32_t nodeOffset; + /// Offset of the node array in bytes from the struct address. + int nodeOffset; /// The number of BVH nodes. - int32_t nodeCount; + int nodeCount; - /// Offset of the vertex array. - int32_t vertexOffset; + /// Offset of the vertex array in bytes from the struct address. + int vertexOffset; /// The number of vertices. - int32_t vertexCount; + int vertexCount; - /// Offset of the triangle array. - int32_t triangleOffset; + /// Offset of the triangle array in bytes from the struct address. + int triangleOffset; /// The number of triangles. - int32_t triangleCount; + int triangleCount; - /// Offset of the material array. - int32_t materialOffset; + /// Offset of the material array in bytes from the struct address. + int materialOffset; /// The number of materials. - int32_t materialCount; + int materialCount; - /// Offset of the triangle flag array. - int32_t flagsOffset; - - // Offset to the edge neighbor angles. - int32_t edgeAngleOffset; - - /// Offset of the vertex flag array. - int32_t vertexFlagOffset; - - /// Offset the vertex neighbor angle ring. - int32_t vertexRingOffset; + /// Offset of the triangle flag array in bytes from the struct address. + int flagsOffset; } b3MeshData; /// This allows mesh data to be re-used with different scales. @@ -2469,7 +2213,7 @@ typedef struct b3Mesh * @{ */ -/// Data used to create a height field. No pointers are held to this data. +/// Data used to create a height field typedef struct b3HeightFieldDef { /// Grid point heights @@ -2508,7 +2252,7 @@ typedef struct b3HeightFieldDef #define B3_HEIGHT_FIELD_HOLE 0xFF /// 64-bit height-field version. Useful for validating serialized data. -#define B3_HEIGHT_FIELD_VERSION 0x5A69A297D7ACE1CDull +#define B3_HEIGHT_FIELD_VERSION 0x8B18CBD138A6BC84ull /// A height field with compressed storage. /// @note This data structure has data hanging off the end and cannot be directly copied. @@ -2517,12 +2261,12 @@ typedef struct b3HeightFieldData /// Version must be first and match B3_HEIGHT_FIELD_VERSION uint64_t version; - /// Hash of this height field (this field is zero when the hash is computed). - uint64_t hash; - /// The total number of bytes for this height field. int byteCount; + /// Hash of this height field (this field is zero when the hash is computed). + uint32_t hash; + /// The local axis-aligned bounding box. b3AABB aabb; @@ -2539,32 +2283,29 @@ typedef struct b3HeightFieldData b3Vec3 scale; /// The number of grid columns along the local x-axis. - int32_t columnCount; + int columnCount; /// The number of grid rows along the local z-axis. - int32_t rowCount; + int rowCount; /// Offset of the compressed height array in bytes from the struct address. /// uint16_t, one per grid point. - int32_t heightsOffset; + int heightsOffset; /// Offset of the material index array in bytes from the struct address. /// uint8_t, one per cell. - int32_t materialOffset; + int materialOffset; /// Offset of the flag array in bytes from the struct address. /// uint8_t, one per triangle. - int32_t flagsOffset; - - /// Offset to the vertex ghost collision flag. Array of bits. - int32_t vertexFlagOffset; + int flagsOffset; /// Triangle winding. - uint8_t clockwise; + bool clockwise; - /// Explicit padding. + /// Explicit padding. Identity is a content hash over raw bytes, so there must + /// be no unnamed padding for struct copies to scramble. uint8_t padding[3]; - } b3HeightFieldData; /**@}*/ // height_field @@ -2657,16 +2398,18 @@ typedef struct b3CompoundDef int sphereCount; } b3CompoundDef; -/// The baked compound version depends on the mesh and hull versions. -#define B3_COMPOUND_VERSION ( 0x9E4B17D3A25C68F1ull ^ B3_MESH_VERSION ^ B3_HULL_VERSION ) +/// The compound version depends on the tree, mesh, and hull versions. +#define B3_COMPOUND_VERSION ( 0x830778DB07086EB4ull ^ B3_DYNAMIC_TREE_VERSION ^ B3_MESH_VERSION ^ B3_HULL_VERSION ) -/// The data for a baked compound shape. This is a potentially large yet highly optimized +/// Meshes used in compounds have limited space for materials. If you have +/// a mesh with many materials, you can use it outside of the compound. +#define B3_MAX_COMPOUND_MESH_MATERIALS 4 + +/// The runtime data for a compound shape. This is a potentially large yet highly optimized /// data structure. It can contain thousands of child shapes, yet at runtime it populates /// into the world as a single shape in the runtime broad-phase. /// This data structure has data living off the end and must be accessed using offsets. /// Accessors are provided for user relevant data. -/// Note: you don't need to use this to create runtime compounds. For runtime compounds you can -/// add multiple shapes to a body using the regular shape creation functions. typedef struct b3CompoundData { /// The compound version is always first. @@ -2675,17 +2418,11 @@ typedef struct b3CompoundData /// The total number of bytes for this compound. int byteCount; - // Bounds of the tree. - b3AABB bounds; - - // Tree height for diagnostics. - int treeHeight; - /// Offset of the tree node array in bytes from the struct address. int nodeOffset; - // The number of tree nodes. - int nodeCount; + /// Immutable dynamic tree. The tree node pointer must be fixed up using the node offset + b3DynamicTree tree; /// Offset of the material array in bytes from the struct address. int materialOffset; @@ -2731,10 +2468,7 @@ typedef struct b3CompoundCapsule b3Capsule capsule; /// Index to a shared material. - uint16_t materialIndex; - - /// Padding for determinism. - uint16_t padding; + int materialIndex; } b3CompoundCapsule; /// A hull that lives in a compound. @@ -2747,10 +2481,7 @@ typedef struct b3CompoundHull b3Transform transform; /// Index to a shared material. - uint16_t materialIndex; - - /// Padding for determinism. - uint16_t padding; + int materialIndex; } b3CompoundHull; /// A mesh with non-uniform scale that lives in a compound. @@ -2766,12 +2497,10 @@ typedef struct b3CompoundMesh b3Vec3 scale; /// This is used to access the surface material from b3GetCompoundMaterials. - /// Requires an extra level of indirection. + /// Requires an extra level of indirection. The triangle material index + /// is clamped to B3_MAX_COMPOUND_MESH_MATERIALS. /// materialIndex = materialIndices[triangle->materialIndex] - const uint16_t* materialIndices; - - /// The number of materials. 1 for convex hapes. - int materialCount; + int materialIndices[B3_MAX_COMPOUND_MESH_MATERIALS]; } b3CompoundMesh; /// A sphere that lives in a compound. @@ -2781,10 +2510,7 @@ typedef struct b3CompoundSphere b3Sphere sphere; /// Index to a shared material. - uint16_t materialIndex; - - /// Padding for determinism. - uint16_t padding; + int materialIndex; } b3CompoundSphere; /// Child shape of a compound @@ -2793,21 +2519,18 @@ typedef struct b3ChildShape /// Tagged union. union { - b3Capsule capsule; ///< Capsule. + b3Capsule capsule; ///< Capsule. const b3HullData* hull; ///< Hull. - b3Mesh mesh; ///< Mesh. - b3Sphere sphere; ///< Sphere. + b3Mesh mesh; ///< Mesh. + b3Sphere sphere; ///< Sphere. }; /// Transform of the shape into compound local space. b3Transform transform; /// Material indices. Index 0 is used for convex shapes. - const uint16_t* materialIndices; - - /// The number of materials. This is one for convex shapes. For - /// meshes it is determined by the maximum triangle material index. - int materialCount; + /// todo limit to 64K? + int materialIndices[B3_MAX_COMPOUND_MESH_MATERIALS]; /// The shape type (union tag). b3ShapeType type; @@ -2842,22 +2565,23 @@ typedef struct b3ManifoldPoint /// The separation of the contact point, negative if penetrating float separation; + /// Cached separation used for contact recycling + float baseSeparation; + /// The impulse along the manifold normal vector. Since Box3D uses sub-stepping, this is /// result from the final sub-step. float normalImpulse; - /// The total normal impulse applied across sub-stepping and restitution. This is important + /// The total normal impulse applied during sub-stepping. This is important /// to identify speculative contact points that had an interaction in the time step. - /// This includes the warm starting impulse, the sub-step delta impulse, and the restitution - /// impulse. float totalNormalImpulse; - /// Relative normal velocity pre-solve. Negative when approaching. This is only - /// computed if hit events are enabled. - float normalVelocity; + /// Sum over sub-steps of the impulse each sub-step applied, plus restitution: the step impulse. + float stepNormalImpulse; - /// Cached separation used for contact recycling - float baseSeparation; + /// Relative normal velocity pre-solve. Used for hit events. If the normal impulse is + /// zero then there was no hit. Negative means shapes are approaching. + float normalVelocity; /// Local point for matching /// Uniquely identifies a contact point between two shapes @@ -2868,12 +2592,6 @@ typedef struct b3ManifoldPoint /// Did this contact point exist in the previous step? bool persisted; - - // b3TriangleFeature - uint8_t triangleFeature; - - // b3MeshContactFlags - uint8_t meshFlags; } b3ManifoldPoint; /// A contact manifold describes the contact points between colliding shapes. @@ -2901,7 +2619,7 @@ typedef struct b3Manifold } b3Manifold; /// Cached separating axis feature. -typedef enum b3SeparatingFeature +typedef enum { b3_invalidAxis = 0, b3_backsideAxis, @@ -2917,7 +2635,7 @@ typedef enum b3SeparatingFeature } b3SeparatingFeature; /// Cached triangle feature. -typedef enum b3TriangleFeature +typedef enum { b3_featureNone = 0, b3_featureTriangleFace, @@ -2933,14 +2651,6 @@ typedef enum b3TriangleFeature b3_featureVertex3 } b3TriangleFeature; -/// This gives debug information about how a contact point was generated. -typedef enum b3MeshContactFlags -{ - b3_meshContactHullFace = 0x01, ///< Normal is a hull face normal. - b3_meshContactSnapped = 0x02, ///< The normal is snapped to the triangle normal. - b3_meshContactDeep = 0x04, ///< The contact is considered deep (2 * linear slop). -} b3MeshContactFlags; - /// Separating axis test cache. Provides temporal acceleration of collision routines. typedef struct { @@ -2992,12 +2702,6 @@ typedef struct b3LocalManifoldPoint /// The triangle index when collide with a mesh or height-field. int triangleIndex; - - // b3TriangleFeature - uint8_t triangleFeature; - - // b3MeshContactFlags - uint8_t meshFlags; } b3LocalManifoldPoint; /// A local manifold with no dynamic information. Used by b3Collide functions. @@ -3018,8 +2722,18 @@ typedef struct b3LocalManifold /// The index of the triangle. int triangleIndex; + int i1; ///< Vertex 1 index. + int i2; ///< Vertex 2 index. + int i3; ///< Vertex 3 index. + + /// The squared distance of a sphere from a triangle. For ghost collision reduction. + float squaredDistance; + /// The triangle feature involved. b3TriangleFeature feature; + + /// b3MeshEdgeFlags. + int triangleFlags; } b3LocalManifold; /**@}*/ // collision @@ -3208,8 +2922,8 @@ B3_INLINE uint32_t b3MakeDebugColor( b3HexColor rgb, b3DebugMaterial material ) /// (B3_GRAPH_COLOR_COUNT - 1) is the overflow color. B3_API b3HexColor b3GetGraphColor( int index ); -/// This is sent to the user for debug shape creation. The user should know the type in case they -/// have custom sphere or capsule rendering. +/// This is sent to the user for debug shape creation. The user should know the type in case they have +/// custom sphere or capsule rendering. typedef struct b3DebugShape { /// Shape id. @@ -3221,12 +2935,12 @@ typedef struct b3DebugShape /// Tagged union. union { - const b3Capsule* capsule; ///< Capsule shape. + const b3Capsule* capsule; ///< Capsule shape. const b3CompoundData* compound; ///< Compound shape. const b3HeightFieldData* heightField; ///< Height-field shape. - const b3HullData* hull; ///< Convex hull shape. - const b3Mesh* mesh; ///< Mesh shape with scale. - const b3Sphere* sphere; ///< Sphere shape. + const b3HullData* hull; ///< Convex hull shape. + const b3Mesh* mesh; ///< Mesh shape with scale. + const b3Sphere* sphere; ///< Sphere shape. }; } b3DebugShape; @@ -3235,10 +2949,8 @@ typedef struct b3DebugShape /// it stays accurate far from the origin. Shift into your own camera frame inside the callbacks. typedef struct b3DebugDraw { - /// Draws a user shape. The userShape pointer is owned by the application and is known to Box3D - /// as an opaque pointer returned from b3CreateDebugShapeCallback. When this is called the drawn - /// shape has passed a culling test against drawingBounds below. - void ( *DrawShapeFcn )( void* userShape, b3WorldTransform transform, b3HexColor color, void* context ); + /// Draws a shape and returns true if drawing should continue + bool ( *DrawShapeFcn )( void* userShape, b3WorldTransform transform, b3HexColor color, void* context ); /// Draw a line segment. void ( *DrawSegmentFcn )( b3Pos p1, b3Pos p2, b3HexColor color, void* context ); @@ -3288,9 +3000,6 @@ typedef struct b3DebugDraw /// Option to draw the mass and center of mass of dynamic bodies bool drawMass; - /// Option to draw the sleep information for dynamic and kinematic bodies - bool drawSleep; - /// Option to draw body names bool drawBodyNames; @@ -3298,7 +3007,7 @@ typedef struct b3DebugDraw bool drawContacts; /// Draw contact anchor A or B - bool drawAnchorA; + int drawAnchorA; /// Option to visualize the graph coloring used for contacts and joints bool drawGraphColors; @@ -3312,6 +3021,9 @@ typedef struct b3DebugDraw /// Option to draw contact normal forces bool drawContactForces; + /// Option to draw contact friction forces + bool drawFrictionForces; + /// Option to draw islands as bounding boxes bool drawIslands; diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 85081eb..64a31f2 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,12 +1,5 @@ # Box3D samples -# sokol's Cocoa/Metal backends are Objective-C. gfx/sokol_impl.c and -# host/sokol_app_impl.c compile as OBJC, so enable the language here where the -# samples need it. Consumers embedding box3d (no samples) don't require OBJC. -if(APPLE) - enable_language(OBJC) -endif() - FetchContent_Declare(imgui GIT_REPOSITORY https://github.com/ocornut/imgui.git GIT_TAG v1.92.7 @@ -34,16 +27,6 @@ FetchContent_Declare(nfd ) FetchContent_MakeAvailable(nfd) -# meshoptimizer for the s&box Ghost Collisions remesh toggle. Static lib, target meshoptimizer. -set(MESHOPT_INSTALL OFF CACHE BOOL "" FORCE) -FetchContent_Declare(meshoptimizer - GIT_REPOSITORY https://github.com/zeux/meshoptimizer.git - GIT_TAG v1.3 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE -) -FetchContent_MakeAvailable(meshoptimizer) - # The shader compiler is only needed when recompiling shaders. A fresh clone # with BOX3D_BUILD_SHADERS=OFF builds from the committed headers and skips this. if(BOX3D_BUILD_SHADERS) @@ -90,20 +73,6 @@ set_target_properties(implot PROPERTIES POSITION_INDEPENDENT_CODE ON ) -# ImGuizmo vendored from github.com/CedricGuillemet/ImGuizmo at 18cef5e (2026-08-08), ImGuizmo.cpp/.h only. -add_library(imguizmo STATIC - "${CMAKE_SOURCE_DIR}/extern/imguizmo/ImGuizmo.cpp" - "${CMAKE_SOURCE_DIR}/extern/imguizmo/ImGuizmo.h" -) -target_link_libraries(imguizmo PUBLIC imgui) -target_include_directories(imguizmo SYSTEM PUBLIC "${CMAKE_SOURCE_DIR}/extern/imguizmo") -set_target_properties(imguizmo PROPERTIES - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS OFF - POSITION_INDEPENDENT_CODE ON -) - # --- sokol: vendored headers INTERFACE target + per-platform backend. -------- set(sokol_SOURCE_DIR "${CMAKE_SOURCE_DIR}/extern/sokol") add_library(sokol INTERFACE) @@ -179,10 +148,6 @@ set(SAMPLE_FILES sample.h mesh_loader.cpp mesh_loader.h - dynamic_mover.cpp - dynamic_mover.h - geometric_mover.cpp - geometric_mover.h jsmn.h tiny_obj_loader.h earcut.h @@ -197,14 +162,12 @@ set(SAMPLE_FILES sample_determinism.cpp sample_events.cpp sample_geometry.cpp - sample_ghost.cpp sample_issues.cpp sample_joint.cpp sample_manifold.cpp sample_mesh.cpp sample_ragdoll.cpp sample_replay.cpp - sample_restitution.cpp sample_robustness.cpp sample_shapes.cpp sample_stacking.cpp @@ -222,22 +185,14 @@ endif() # Include root is the samples dir so "gfx/..." and "host/..." prefixes resolve. # The data dir is on the path too so samples can #include recorded dumps -# (sample_issues pulls dumps/.../box3d_dump.inl at compile time). src is on the -# path so sample_tree.cpp can reach dynamic_tree.h for the node layout helpers. +# (sample_issues pulls dumps/.../box3d_dump.inl at compile time). target_include_directories(samples PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" - "${CMAKE_CURRENT_SOURCE_DIR}/../data" - "${CMAKE_SOURCE_DIR}/src") + "${CMAKE_CURRENT_SOURCE_DIR}/../data") # gfx: the renderer + Draw*/adapter. shared: human, utils (Random*), the # benchmark/determinism helpers the samples lean on. -target_link_libraries(samples PRIVATE gfx shared imgui implot imguizmo sokol nfd meshoptimizer) - -# MSVC auto-links winmm via a #pragma comment in main.cpp. MinGW ignores that -# pragma, so link the timeBeginPeriod/timeEndPeriod library explicitly. -if (MINGW) - target_link_libraries(samples PRIVATE winmm) -endif() +target_link_libraries(samples PRIVATE gfx shared imgui implot sokol nfd) set_target_properties(samples PROPERTIES CXX_STANDARD 20 diff --git a/samples/dynamic_mover.cpp b/samples/dynamic_mover.cpp deleted file mode 100644 index 7f85b41..0000000 --- a/samples/dynamic_mover.cpp +++ /dev/null @@ -1,584 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "dynamic_mover.h" - -#include "gfx/draw.h" - -#include "box3d/box3d.h" -#include "box3d/math_functions.h" - -#include - -struct CastContext -{ - DynamicMoverCastResult result; - b3BodyId moverId; -}; - -static float CastCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, - uint64_t userMaterialId, int triangleIndex, int childIndex, - void* context ) -{ - (void)triangleIndex; - (void)childIndex; - - CastContext* castContext = (CastContext*)context; - b3BodyId bodyId = b3Shape_GetBody( shapeId ); - - // The probes start inside or on the capsule. Sensors can't hold up the mover. - if ( B3_ID_EQUALS( bodyId, castContext->moverId ) || b3Shape_IsSensor( shapeId ) ) - { - return -1.0f; - } - - DynamicMoverCastResult* result = &castContext->result; - result->point = point; - result->normal = normal; - result->bodyId = bodyId; - result->userMaterialId = userMaterialId; - result->fraction = fraction; - result->hit = true; - return fraction; -} - -DynamicMover::DynamicMover() -{ - DynamicMoverDef def; - m_jumpSpeed = def.jumpSpeed; - m_maxSpeed = def.maxSpeed; - m_minSpeed = def.minSpeed; - m_stopSpeed = def.stopSpeed; - m_accelerate = def.accelerate; - m_airSteer = def.airSteer; - m_friction = def.friction; - m_gravityScale = def.gravityScale; - m_maxGroundForce = def.maxGroundForce; - m_maxAirForce = def.maxAirForce; - m_pogoRestLength = def.pogoRestLength; - m_pogoHertz = def.pogoHertz; - m_pogoDampingRatio = def.pogoDampingRatio; - m_pogoCompressionScale = def.pogoCompressionScale; - m_pogoTensionScale = def.pogoTensionScale; - m_enableSkirtPogo = def.enableSkirtPogo; - m_platformMaterialId = def.platformMaterialId; - m_minGroundNormalY = 0.7f; - - m_capsule = def.capsule; - m_filter = def.filter; - - m_worldId = b3_nullWorldId; - m_groundId = b3_nullBodyId; - m_moverId = b3_nullBodyId; - m_surfaceBodyId = b3_nullBodyId; - m_moverJointId = b3_nullJointId; - m_pogoJointId = b3_nullJointId; - - m_castResult = {}; - - m_velocity = b3Vec3_zero; - m_timeSliding = 0.0f; - m_slideDuration = 0.2f; - m_onGround = false; - m_walkable = false; - m_jumping = false; - m_jumpTicks = 0; - - m_pogoImpulse = 0.0f; - m_pogoVelocity = 0.0f; - m_pogoLength = 0.0f; - - for ( DynamicMoverProbe& probe : m_probes ) - { - probe = { b3Pos_zero, b3Vec3_zero, 1.0f, false }; - } - - m_probeCount = 0; - m_selectedProbe = 0; -} - -void DynamicMover::Create( b3WorldId worldId, const DynamicMoverDef* def ) -{ - m_capsule = def->capsule; - m_filter = def->filter; - m_jumpSpeed = def->jumpSpeed; - m_maxSpeed = def->maxSpeed; - m_minSpeed = def->minSpeed; - m_stopSpeed = def->stopSpeed; - m_accelerate = def->accelerate; - m_airSteer = def->airSteer; - m_friction = def->friction; - m_gravityScale = def->gravityScale; - m_maxGroundForce = def->maxGroundForce; - m_maxAirForce = def->maxAirForce; - m_pogoRestLength = def->pogoRestLength; - m_pogoHertz = def->pogoHertz; - m_pogoDampingRatio = def->pogoDampingRatio; - m_pogoCompressionScale = def->pogoCompressionScale; - m_pogoTensionScale = def->pogoTensionScale; - m_enableSkirtPogo = def->enableSkirtPogo; - m_platformMaterialId = def->platformMaterialId; - - m_worldId = worldId; - m_velocity = b3Vec3_zero; - m_onGround = false; - m_walkable = false; - m_jumping = false; - m_jumpTicks = 0; - m_pogoImpulse = 0.0f; - m_pogoVelocity = 0.0f; - m_pogoLength = 0.0f; - m_pogoJointId = b3_nullJointId; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - m_groundId = b3CreateBody( worldId, &bodyDef ); - - // Position is the center of the capsule. - bodyDef.type = b3_dynamicBody; - bodyDef.position = def->position; - bodyDef.gravityScale = m_gravityScale; - bodyDef.motionLocks.angularX = true; - bodyDef.motionLocks.angularY = true; - bodyDef.motionLocks.angularZ = true; - bodyDef.enableSleep = false; - bodyDef.name = "mover"; - - m_moverId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = def->density; - - // The mover joint and the pogo joint handle all the movement, surface friction would fight - // them. - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - shapeDef.baseMaterial.customColor = b3_colorDodgerBlue; - shapeDef.filter = def->filter; - shapeDef.enablePreSolveEvents = def->enablePreSolveEvents; - shapeDef.enableSensorEvents = def->enableSensorEvents; - - b3CreateCapsuleShape( m_moverId, &shapeDef, &m_capsule ); - - CreateMoverJoint( m_groundId ); -} - -void DynamicMover::CreateMoverJoint( b3BodyId baseId ) -{ - b3MoverJointDef moverDef = b3DefaultMoverJointDef(); - moverDef.linearVelocity = m_velocity; - moverDef.maxForce = m_maxGroundForce; - moverDef.base.bodyIdA = baseId; - moverDef.base.bodyIdB = m_moverId; - moverDef.base.collideConnected = true; - - m_moverJointId = b3CreateMoverJoint( m_worldId, &moverDef ); -} - -void DynamicMover::Destroy() -{ - if ( B3_IS_NON_NULL( m_moverId ) ) - { - b3DestroyBody( m_moverId ); - } - - if ( B3_IS_NON_NULL( m_groundId ) ) - { - b3DestroyBody( m_groundId ); - } - - m_groundId = b3_nullBodyId; - m_moverId = b3_nullBodyId; - - // Joints are implicitly destroyed. - m_moverJointId = b3_nullJointId; - m_pogoJointId = b3_nullJointId; -} - -void DynamicMover::SetGravityScale( float gravityScale ) -{ - m_gravityScale = gravityScale; - - if ( B3_IS_NON_NULL( m_moverId ) ) - { - b3Body_SetGravityScale( m_moverId, gravityScale ); - } -} - -bool DynamicMover::Jump() -{ - if ( m_onGround == false || m_walkable == false ) - { - return false; - } - - float surfaceVelocity = 0.0f; - if ( b3Body_IsValid( m_castResult.bodyId ) ) - { - b3Vec3 v = b3Body_GetWorldPointVelocity( m_castResult.bodyId, m_castResult.point ); - surfaceVelocity = v.y; - } - - float mass = b3Body_GetMass( m_moverId ); - float vy = b3Body_GetLinearVelocity( m_moverId ).y; - - // Remove the pogo constraint velocity but add the surface velocity. - float dv = b3MaxFloat( 0.0f, m_jumpSpeed - vy ) + surfaceVelocity; - b3Body_ApplyLinearImpulseToCenter( m_moverId, { 0.0f, mass * dv, 0.0f }, true ); - - Launch(); - return true; -} - -void DynamicMover::Launch() -{ - // This removes the pogo step down on the next update. - m_onGround = false; - m_walkable = false; - m_jumping = true; - m_jumpTicks = 0; -} - -// Movement follows the Quake ground and air model: -// https://github.com/id-Software/Quake/blob/master/QW/client/pmove.c#L390 - -// onGround - controls friction, mover max force, and pogo step-down extension -// walkable - controls air steer -// jumping - blocks the pogo from pulling down -void DynamicMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, - float speedScale ) -{ - // Reach further while grounded so the spring can find the ground over a step - float stepDownLength = m_pogoRestLength; - float rayLength = m_onGround ? m_pogoRestLength + stepDownLength : m_pogoRestLength; - b3Vec3 translation = { 0.0f, -rayLength, 0.0f }; - - b3Pos position = b3Body_GetPosition( m_moverId ); - b3Pos origin = position + m_capsule.center1; - - b3QueryFilter queryFilter = { - .categoryBits = m_filter.categoryBits, - .maskBits = m_filter.maskBits, - .id = 0, - .name = "dynamic_mover_pogo", - }; - - CastContext castContext = { {}, m_moverId }; - b3World_CastRay( m_worldId, origin, translation, queryFilter, CastCallback, &castContext ); - m_castResult = castContext.result; - - m_probes[0] = { origin, translation, m_castResult.hit ? m_castResult.fraction : 1.0f, - m_castResult.hit }; - m_probeCount = 1; - m_selectedProbe = 0; - - b3Vec3 pogoOffset = b3Vec3_zero; - - bool centerWalkable = m_castResult.hit && m_castResult.normal.y >= m_minGroundNormalY; - if ( centerWalkable == false && m_enableSkirtPogo ) - { - // The skirt turns with the direction of travel so ties go to the leading probe - b3Vec3 moverVelocity = b3Body_GetLinearVelocity( m_moverId ); - b3Vec3 heading = { moverVelocity.x, 0.0f, moverVelocity.z }; - if ( b3LengthSquared( heading ) < FLT_EPSILON ) - { - heading = b3Vec3_axisX; - } - - heading = b3Normalize( heading ); - b3Vec3 side = { -heading.z, 0.0f, heading.x }; - - float bestDisplacement = FLT_MAX; - for ( int i = 0; i < m_skirtCount; ++i ) - { - b3CosSin cs = b3ComputeCosSin( 2.0f * B3_PI * i / m_skirtCount ); - b3Vec3 offset = m_capsule.radius * ( cs.cosine * heading + cs.sine * side ); - - b3Pos skirtOrigin = origin + offset; - CastContext skirtContext = { {}, m_moverId }; - b3World_CastRay( m_worldId, skirtOrigin, translation, queryFilter, CastCallback, - &skirtContext ); - const DynamicMoverCastResult& result = skirtContext.result; - - m_probes[m_probeCount] = { skirtOrigin, translation, - result.hit ? result.fraction : 1.0f, result.hit }; - - // Use the walkable result that causes the least movement. With none the mover keeps - // the central hit and slides off the steep surface. - if ( result.hit && result.normal.y >= m_minGroundNormalY ) - { - float displacement = b3AbsFloat( result.fraction * rayLength - m_pogoRestLength ); - if ( displacement < bestDisplacement ) - { - bestDisplacement = displacement; - m_castResult = result; - m_selectedProbe = m_probeCount; - pogoOffset = offset; - } - } - - m_probeCount += 1; - } - } - - // Should jumping end? - if ( m_jumping ) - { - m_jumpTicks += 1; - - // Jump ticks allow time for the jump to leave the ground. Otherwise jumping ends - // when the character approaches the current ground. - if ( m_jumpTicks > 2 && m_castResult.hit && - b3Dot( m_velocity, m_castResult.normal ) <= 0.0f ) - { - m_jumping = false; - } - } - - if ( m_castResult.hit ) - { - // Is the ground too steep to walk? - m_walkable = m_castResult.normal.y >= m_minGroundNormalY; - - // The cast can still hit while jumping. - m_onGround = m_jumping == false; - - if ( m_onGround ) - { - if ( m_walkable ) - { - m_timeSliding = b3MaxFloat( m_timeSliding - timeStep, 0.0f ); - } - else - { - m_timeSliding = b3MinFloat( m_timeSliding + timeStep, m_slideDuration ); - } - } - } - else - { - m_onGround = false; - m_walkable = false; - m_timeSliding = b3MaxFloat( m_timeSliding - timeStep, 0.0f ); - } - - // Connect the mover joint to platform. Acts like friction. - b3BodyId baseId = m_groundId; - if ( m_castResult.hit && m_platformMaterialId != 0 && - m_castResult.userMaterialId == m_platformMaterialId && - b3Body_GetType( m_castResult.bodyId ) == b3_kinematicBody ) - { - baseId = m_castResult.bodyId; - } - - // The mover joint can be destroyed if attached to a platform that gets destroyed. - bool moverJointValid = b3Joint_IsValid( m_moverJointId ); - - if ( moverJointValid == false || - B3_ID_EQUALS( b3Joint_GetBodyA( m_moverJointId ), baseId ) == false ) - { - if ( moverJointValid ) - { - b3DestroyJoint( m_moverJointId, false ); - } - - CreateMoverJoint( baseId ); - } - - m_velocity = b3Body_GetLinearVelocity( m_moverId ) - b3Body_GetLinearVelocity( baseId ); - - // Friction acts in the horizontal plane. The pogo owns the vertical motion. - if ( m_onGround ) - { - float speed = sqrtf( m_velocity.x * m_velocity.x + m_velocity.z * m_velocity.z ); - if ( speed < m_minSpeed ) - { - m_velocity.x = 0.0f; - m_velocity.z = 0.0f; - } - else - { - // Linear damping above stopSpeed and fixed reduction below stopSpeed - float control = speed < m_stopSpeed ? m_stopSpeed : speed; - - // friction has units of 1/time - float drop = control * m_friction * timeStep; - float newSpeed = b3MaxFloat( 0.0f, speed - drop ); - float ratio = newSpeed / speed; - m_velocity.x *= ratio; - m_velocity.z *= ratio; - } - } - - // Mover force - float maxForce; - if ( m_onGround ) - { - if ( m_slideDuration > 0.0f ) - { - float scale = b3ClampFloat( 1.0f - m_timeSliding / m_slideDuration, 0.0f, 1.0f ); - maxForce = scale * m_maxGroundForce; - } - else - { - maxForce = m_walkable ? m_maxGroundForce : 0.0f; - } - } - else - { - maxForce = m_maxAirForce; - } - - b3MoverJoint_SetMaxVelocityForce( m_moverJointId, maxForce ); - - float maxSpeed = speedScale * m_maxSpeed; - b3Vec3 desiredVelocity = maxSpeed * throttle.x * forward + maxSpeed * throttle.y * right; - desiredVelocity.y = 0.0f; - - float desiredSpeed; - b3Vec3 desiredDirection = b3GetLengthAndNormalize( &desiredSpeed, desiredVelocity ); - - if ( desiredSpeed > maxSpeed ) - { - desiredSpeed = maxSpeed; - } - - // Accelerate - float currentSpeed = b3Dot( m_velocity, desiredDirection ); - float addSpeed = desiredSpeed - currentSpeed; - if ( addSpeed > 0.0f ) - { - float steer = m_walkable ? 1.0f : m_airSteer; - float accelSpeed = steer * m_accelerate * maxSpeed * timeStep; - if ( accelSpeed > addSpeed ) - { - accelSpeed = addSpeed; - } - - m_velocity.x += accelSpeed * desiredDirection.x; - m_velocity.z += accelSpeed * desiredDirection.z; - } - - if ( m_castResult.hit == true && b3IsNormalized( m_castResult.normal ) ) - { - m_pogoLength = m_castResult.fraction * rayLength; - - float moverMass = b3Body_GetMass( m_moverId ); - float gravity = b3Length( b3World_GetGravity( m_worldId ) ); - float moverWeight = m_gravityScale * gravity * moverMass; - - bool pogoJointValid = b3Joint_IsValid( m_pogoJointId ); - - // Create or recreate the pogo joint as needed. - if ( B3_ID_EQUALS( m_castResult.bodyId, m_surfaceBodyId ) == false || - pogoJointValid == false ) - { - if ( pogoJointValid ) - { - m_pogoImpulse = b3PogoJoint_GetImpulse( m_pogoJointId ); - m_pogoVelocity = b3PogoJoint_GetCurrentSpeed( m_pogoJointId ); - - b3DestroyJoint( m_pogoJointId, false ); - m_pogoJointId = b3_nullJointId; - } - - m_surfaceBodyId = m_castResult.bodyId; - - b3PogoJointDef pogoDef = b3DefaultPogoJointDef(); - pogoDef.base.localFrameA.p = - b3Body_GetLocalPoint( m_surfaceBodyId, m_castResult.point ); - pogoDef.base.localFrameB.p = m_capsule.center1 + pogoOffset; - pogoDef.normal = m_castResult.normal; - pogoDef.base.bodyIdA = m_surfaceBodyId; - pogoDef.base.bodyIdB = m_moverId; - pogoDef.base.collideConnected = true; - pogoDef.restLength = m_pogoRestLength; - pogoDef.hertz = m_pogoHertz; - pogoDef.dampingRatio = m_pogoDampingRatio; - pogoDef.maxCompressionForce = m_pogoCompressionScale * moverWeight; - - // Warm start from the joint that was just destroyed - pogoDef.impulse = m_pogoImpulse; - pogoDef.velocity = m_pogoVelocity; - - if ( m_jumping ) - { - // Don't allow the pogo to pull down - pogoDef.maxTensionForce = 0.0f; - } - else - { - // The pogo can pull down at a multiple of the gravity force. - pogoDef.maxTensionForce = m_pogoTensionScale * moverWeight; - } - - m_pogoJointId = b3CreatePogoJoint( m_worldId, &pogoDef ); - } - else - { - // Preserve the joint, improving performance. - - b3Transform localFrameA; - localFrameA.p = b3Body_GetLocalPoint( m_surfaceBodyId, m_castResult.point ); - localFrameA.q = b3Quat_identity; - b3Joint_SetLocalFrameA( m_pogoJointId, localFrameA ); - - b3Transform localFrameB; - localFrameB.p = m_capsule.center1 + pogoOffset; - localFrameB.q = b3Quat_identity; - b3Joint_SetLocalFrameB( m_pogoJointId, localFrameB ); - - b3PogoJoint_SetNormal( m_pogoJointId, m_castResult.normal ); - - if ( m_jumping ) - { - // Don't allow the pogo to pull down - b3PogoJoint_SetMaxTensionForce( m_pogoJointId, 0.0f ); - } - else - { - // The pogo can pull down at a multiple of the gravity force. - b3PogoJoint_SetMaxTensionForce( m_pogoJointId, m_pogoTensionScale * moverWeight ); - } - - b3PogoJoint_SetMaxCompressionForce( m_pogoJointId, - m_pogoCompressionScale * moverWeight ); - - b3PogoJoint_SetSpringHertz( m_pogoJointId, m_pogoHertz ); - b3PogoJoint_SetSpringDampingRatio( m_pogoJointId, m_pogoDampingRatio ); - } - } - else - { - if ( b3Joint_IsValid( m_pogoJointId ) ) - { - b3DestroyJoint( m_pogoJointId, false ); - m_pogoJointId = b3_nullJointId; - } - - m_surfaceBodyId = b3_nullBodyId; - m_pogoImpulse = 0.0f; - m_pogoVelocity = 0.0f; - m_pogoLength = 0.0f; - } - - b3MoverJoint_SetLinearVelocity( m_moverJointId, m_velocity ); -} - -void DynamicMover::Draw() const -{ - for ( int i = 0; i < m_probeCount; ++i ) - { - const DynamicMoverProbe& probe = m_probes[i]; - b3Pos end = b3OffsetPos( probe.origin, probe.fraction * probe.translation ); - - if ( probe.hit == false ) - { - DrawLine( probe.origin, end, MakeColor( b3_colorGray ) ); - continue; - } - - b3HexColor color = i == m_selectedProbe ? b3_colorGreen : b3_colorYellow; - DrawLine( probe.origin, end, MakeColor( color ) ); - DrawPoint( end, 6.0f, MakeColor( color ) ); - } -} diff --git a/samples/dynamic_mover.h b/samples/dynamic_mover.h deleted file mode 100644 index fcb1ed1..0000000 --- a/samples/dynamic_mover.h +++ /dev/null @@ -1,167 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "box3d/types.h" - -struct DynamicMoverDef -{ - b3Pos position = {}; - b3Capsule capsule = { { 0.0f, -0.5f, 0.0f }, { 0.0f, 0.5f, 0.0f }, 0.3f }; - - float density = 200.0f; - - b3Filter filter = b3DefaultFilter(); - float jumpSpeed = 7.0f; - float maxSpeed = 6.0f; - float minSpeed = 0.1f; - float stopSpeed = 3.0f; - float accelerate = 20.0f; - float airSteer = 0.25f; - float friction = 8.0f; - float gravityScale = 1.5f; - float maxGroundForce = 6000.0f; - float maxAirForce = 1500.0f; - float pogoRestLength = 0.9f; - float pogoHertz = 3.0f; - float pogoDampingRatio = 0.8f; - float pogoCompressionScale = 100.0f; - float pogoTensionScale = 100.0f; - uint64_t platformMaterialId = 0; - bool enableSkirtPogo = true; - bool enablePreSolveEvents = false; - bool enableSensorEvents = false; -}; - -struct DynamicMoverCastResult -{ - b3Pos point; - b3Vec3 normal; - b3BodyId bodyId; - uint64_t userMaterialId; - float fraction; - bool hit; -}; - -struct DynamicMoverProbe -{ - b3Pos origin; - b3Vec3 translation; - float fraction; - bool hit; -}; - -// Dynamic character mover. The capsule is a rigid body with locked rotation, so it -// collides and is pushed like everything else in the world. A mover joint drives it to -// the target velocity and a pogo joint holds it above the ground so it can climb -// steps without touching the capsule. -// -// The dynamic mover should be vendored into your project so you can alter it to meet -// your game's specific needs. -// -// This system is inspired by Tom Waterson's presentation: -// https://www.youtube.com/watch?v=_jRLlTDqoGI -class DynamicMover -{ -public: - DynamicMover(); - - void Create( b3WorldId worldId, const DynamicMoverDef* def ); - void Destroy(); - - // Advance the mover. Throttle is the input along the forward and right directions on [-1, 1]. - void Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, float speedScale ); - - // Jump if grounded. Returns false when airborne. - bool Jump(); - - // Release the ground so an external impulse can carry the mover into the air. Otherwise the - // pogo pulls it back down. - void Launch(); - - // Gravity scale is used to size the pogo forces, so change it here. - void SetGravityScale( float gravityScale ); - - b3BodyId GetBodyId() const - { - return m_moverId; - } - - void Draw() const; - - static constexpr int m_skirtCount = 8; - static constexpr int m_probeCapacity = m_skirtCount + 1; - - float m_jumpSpeed; - float m_maxSpeed; - float m_minSpeed; - float m_stopSpeed; - float m_accelerate; - - // Fraction of the ground acceleration available in the air. - float m_airSteer; - - // Ground friction in units of 1/time. - float m_friction; - - // A character usually wants to fall faster than the rest of the world. - float m_gravityScale; - - // Force budget the mover joint has for reaching the target velocity. The air value - // is small so the character keeps its momentum while jumping. - float m_maxGroundForce; - float m_maxAirForce; - - float m_pogoRestLength; - float m_pogoHertz; - float m_pogoDampingRatio; - - // Pogo force limits as a multiple of the mover weight. - float m_pogoCompressionScale; - float m_pogoTensionScale; - - // Casts an octagon skirt of rays around the capsule when the central ray misses or - // lands on a surface too steep to walk, so the mover can stand on a ledge or a thin - // rail, or step off the foot of a steep slope. - bool m_enableSkirtPogo; - - // Used for the pogo to detect moving platforms. - uint64_t m_platformMaterialId; - - // Surfaces steeper than this are not ground. - float m_minGroundNormalY; - - b3Capsule m_capsule; - b3Filter m_filter; - - b3WorldId m_worldId; - b3BodyId m_groundId; - b3BodyId m_moverId; - b3BodyId m_surfaceBodyId; - b3JointId m_moverJointId; - b3JointId m_pogoJointId; - - DynamicMoverCastResult m_castResult; - - b3Vec3 m_velocity; - float m_timeSliding; - float m_slideDuration; - bool m_onGround; - bool m_walkable; - bool m_jumping; - int m_jumpTicks; - - // Pogo joint state, carried across the joint being recreated each update. - float m_pogoImpulse; - float m_pogoVelocity; - float m_pogoLength; - - // Pogo ray cast results for drawing. - DynamicMoverProbe m_probes[m_probeCapacity]; - int m_probeCount; - int m_selectedProbe; - -private: - void CreateMoverJoint( b3BodyId baseId ); -}; diff --git a/samples/earcut.h b/samples/earcut.h index c414181..31c50e4 100644 --- a/samples/earcut.h +++ b/samples/earcut.h @@ -262,8 +262,11 @@ void Earcut::earcutLinked(Node* ear, int pass) { Node* prev; Node* next; + int iterations = 0; + // iterate through ears, slicing them one by one while (ear->prev != ear->next) { + iterations++; prev = ear->prev; next = ear->next; diff --git a/samples/geometric_mover.cpp b/samples/geometric_mover.cpp deleted file mode 100644 index 69f159a..0000000 --- a/samples/geometric_mover.cpp +++ /dev/null @@ -1,351 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "geometric_mover.h" - -#include "gfx/draw.h" - -#include "box3d/box3d.h" -#include "box3d/math_functions.h" - -#include -#include - -static bool MoverFilterCallback( b3ShapeId shapeId, void* context ) -{ - GeometricMover* self = (GeometricMover*)context; - for ( int i = 0; i < self->m_ignoreCount; ++i ) - { - if ( B3_ID_EQUALS( shapeId, self->m_ignoreShapeIds[i] ) ) - { - return false; - } - } - - return true; -} - -static bool PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* planeResults, int planeCount, - void* context ) -{ - if ( MoverFilterCallback( shapeId, context ) == false ) - { - // ignore these planes but continue looking for more - return true; - } - - GeometricMover* self = static_cast( context ); - float maxPush = FLT_MAX; - bool clipVelocity = true; - MoverShapeUserData* userData = - static_cast( b3Shape_GetUserData( shapeId ) ); - if ( userData != nullptr ) - { - maxPush = userData->maxPush; - clipVelocity = userData->clipVelocity; - } - - for ( int i = 0; i < planeCount && self->m_planeCount < GeometricMover::m_planeCapacity; ++i ) - { - assert( b3IsValidPlane( planeResults[i].plane ) ); - self->m_planes[self->m_planeCount] = { - .plane = planeResults[i].plane, - .pushLimit = maxPush, - .push = 0.0f, - .clipVelocity = clipVelocity, - }; - - // The plane point is relative to the origin passed to the collide call - self->m_planeExtras[self->m_planeCount] = { - .point = b3OffsetPos( self->m_position, planeResults[i].point ), - .shapeId = shapeId, - }; - self->m_planeCount += 1; - } - - return true; -} - -GeometricMover::GeometricMover() -{ - GeometricMoverDef def; - m_jumpSpeed = def.jumpSpeed; - m_maxSpeed = def.maxSpeed; - m_minSpeed = def.minSpeed; - m_stopSpeed = def.stopSpeed; - m_accelerate = def.accelerate; - m_friction = def.friction; - m_gravity = def.gravity; - m_pogoRestLength = def.pogoRestLength; - m_pogoHertz = def.pogoHertz; - m_pogoDampingRatio = def.pogoDampingRatio; - m_clipVelocity = true; - m_ignoreShapeIds = nullptr; - m_ignoreCount = 0; - - m_capsule = def.capsule; - m_worldId = b3_nullWorldId; - m_position = def.position; - m_velocity = b3Vec3_zero; - m_pogoVelocity = 0.0f; - m_onGround = false; - - m_planeCount = 0; - m_totalIterations = 0; - - m_pogoOrigin = b3Pos_zero; - m_pogoTranslation = b3Vec3_zero; - m_pogoPoint = b3Pos_zero; - m_pogoHit = false; -} - -void GeometricMover::Create( b3WorldId worldId, const GeometricMoverDef* def ) -{ - m_capsule = def->capsule; - m_jumpSpeed = def->jumpSpeed; - m_maxSpeed = def->maxSpeed; - m_minSpeed = def->minSpeed; - m_stopSpeed = def->stopSpeed; - m_accelerate = def->accelerate; - m_friction = def->friction; - m_gravity = def->gravity; - m_pogoRestLength = def->pogoRestLength; - m_pogoHertz = def->pogoHertz; - m_pogoDampingRatio = def->pogoDampingRatio; - - m_worldId = worldId; - m_position = def->position; - m_velocity = b3Vec3_zero; - m_pogoVelocity = 0.0f; - m_onGround = false; - m_planeCount = 0; - m_totalIterations = 0; - m_pogoHit = false; -} - -bool GeometricMover::Jump() -{ - if ( m_onGround == false ) - { - return false; - } - - m_velocity.y = m_jumpSpeed; - m_onGround = false; - return true; -} - -// Solve a normal constraint between the mover and each touched rigid body. This is the -// same velocity constraint the solver uses for a contact, except the mover is treated as -// having infinite mass, so all of the impulse lands on the body. -void GeometricMover::PushBodies() -{ - for ( int i = 0; i < m_planeCount; ++i ) - { - b3BodyId bodyId = b3Shape_GetBody( m_planeExtras[i].shapeId ); - if ( b3Body_GetType( bodyId ) != b3_dynamicBody ) - { - continue; - } - - MoverShapeUserData* userData = - static_cast( b3Shape_GetUserData( m_planeExtras[i].shapeId ) ); - if ( userData != nullptr && userData->canMoverPush == false ) - { - continue; - } - - // Plane normals point at the mover - b3Pos point = m_planeExtras[i].point; - b3Vec3 normal = b3Neg( m_planes[i].plane.normal ); - - float invMassA = 0.0f; - float invMassB = b3Body_GetInverseMass( bodyId ); - b3Matrix3 invIB = b3Body_GetWorldInverseRotationalInertia( bodyId ); - - b3Pos centerB = b3Body_GetWorldCenter( bodyId ); - b3Vec3 rB = b3SubPos( point, centerB ); - - b3Vec3 rnB = b3Cross( rB, normal ); - float kNormal = invMassA + invMassB + b3Dot( rnB, b3MulMV( invIB, rnB ) ); - float normalMass = kNormal > 0.0f ? 1.0f / kNormal : 0.0f; - - b3Vec3 vB = b3Body_GetLinearVelocity( bodyId ); - b3Vec3 omegaB = b3Body_GetAngularVelocity( bodyId ); - b3Vec3 vrB = b3Add( vB, b3Cross( omegaB, rB ) ); - float vn = b3Dot( b3Sub( vrB, m_velocity ), normal ); - - // Push only, a separating body is left alone - float impulse = b3MaxFloat( -normalMass * vn, 0.0f ); - - b3Vec3 P = b3MulSV( impulse, normal ); - m_velocity = b3MulSub( m_velocity, invMassA, P ); - - b3Body_ApplyLinearImpulse( bodyId, P, point, true ); - } -} - -// Movement follows the Quake ground and air model: -// https://github.com/id-Software/Quake/blob/master/QW/client/pmove.c#L390 -void GeometricMover::Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, - float speedScale ) -{ - // Friction - float speed = b3Length( m_velocity ); - if ( speed < m_minSpeed ) - { - m_velocity.x = 0.0f; - m_velocity.z = 0.0f; - } - else - { - // Linear damping above stopSpeed and fixed reduction below stopSpeed - float control = speed < m_stopSpeed ? m_stopSpeed : speed; - - // friction has units of 1/time - float drop = control * m_friction * timeStep; - float newSpeed = b3MaxFloat( 0.0f, speed - drop ); - float ratio = newSpeed / speed; - m_velocity.x *= ratio; - m_velocity.z *= ratio; - } - - float maxSpeed = speedScale * m_maxSpeed; - - b3Vec3 desiredVelocity = maxSpeed * throttle.x * forward + maxSpeed * throttle.y * right; - float desiredSpeed; - b3Vec3 desiredDirection = b3GetLengthAndNormalize( &desiredSpeed, desiredVelocity ); - - if ( desiredSpeed > maxSpeed ) - { - desiredSpeed = maxSpeed; - } - - if ( m_onGround ) - { - m_velocity.y = 0.0f; - } - - // Accelerate - float currentSpeed = b3Dot( m_velocity, desiredDirection ); - float addSpeed = desiredSpeed - currentSpeed; - if ( addSpeed > 0.0f ) - { - float accelSpeed = m_accelerate * maxSpeed * timeStep; - if ( accelSpeed > addSpeed ) - { - accelSpeed = addSpeed; - } - - m_velocity += accelSpeed * desiredDirection; - } - - m_velocity.y -= m_gravity * timeStep; - - // The probe reaches past the rest length so the spring can be stretched - float rayLength = m_pogoRestLength + m_capsule.radius; - b3Pos rayOrigin = m_position + m_capsule.center1; - b3Vec3 rayTranslation = -rayLength * b3Vec3_axisY; - b3QueryFilter pogoFilter = { 1, ~2ull, 0, "pogo" }; - b3RayResult rayResult = - b3World_CastRayClosest( m_worldId, rayOrigin, rayTranslation, pogoFilter ); - - m_pogoOrigin = rayOrigin; - m_pogoTranslation = rayTranslation; - m_pogoPoint = rayResult.point; - - // After gravity was applied, disable pogo when still moving up. - // Avoids getting pulled back to the ground when jumping. - bool suppressPogo = m_velocity.y > 0.0f; - - if ( rayResult.hit == false || suppressPogo ) - { - m_onGround = false; - m_pogoVelocity = 0.0f; - } - else - { - m_onGround = true; - float pogoCurrentLength = rayResult.fraction * rayLength; - float offset = pogoCurrentLength - m_pogoRestLength; - m_pogoVelocity = - b3SpringDamper( m_pogoHertz, m_pogoDampingRatio, offset, m_pogoVelocity, timeStep ); - } - - m_pogoHit = m_onGround; - - b3Pos startPosition = m_position; - b3Pos target = m_position + timeStep * m_velocity + timeStep * m_pogoVelocity * b3Vec3_axisY; - - // Want the mover to collide with allies - b3QueryFilter moverFilter = { - .categoryBits = 1, .maskBits = ~0ull, .id = 1, .name = "mover_collide" }; - - // The cast should ignore allies - b3QueryFilter castFilter = { - .categoryBits = 1, .maskBits = ~2ull, .id = 1, .name = "mover_cast" }; - - m_totalIterations = 0; - float tolerance = 0.01f; - - for ( int iteration = 0; iteration < 5; ++iteration ) - { - m_planeCount = 0; - - b3World_CollideMover( m_worldId, m_position, &m_capsule, moverFilter, PlaneResultFcn, - this ); - - b3Vec3 targetDelta = target - m_position; - b3PlaneSolverResult result = b3SolvePlanes( targetDelta, m_planes, m_planeCount ); - - m_totalIterations += result.iterationCount; - - float fraction = b3World_CastMover( m_worldId, m_position, &m_capsule, result.delta, - castFilter, MoverFilterCallback, this ); - - b3Vec3 delta = fraction * result.delta; - m_position = m_position + delta; - - if ( b3LengthSquared( delta ) < tolerance * tolerance ) - { - break; - } - } - - PushBodies(); - - if ( m_clipVelocity ) - { - // Stop pushing into surfaces so speed can't accumulate against a wall - m_velocity = b3ClipVector( m_velocity, m_planes, m_planeCount ); - } - else if ( timeStep > 0.0f ) - { - m_velocity = ( 1.0f / timeStep ) * ( m_position - startPosition ); - } -} - -void GeometricMover::Draw() const -{ - if ( m_pogoHit ) - { - DrawLine( m_pogoOrigin, m_pogoPoint, MakeColor( b3_colorGreen ) ); - } - else - { - DrawLine( m_pogoOrigin, b3OffsetPos( m_pogoOrigin, m_pogoTranslation ), - MakeColor( b3_colorGray ) ); - } - - for ( int i = 0; i < m_planeCount; ++i ) - { - b3Plane plane = m_planes[i].plane; - b3Pos p1 = m_position + ( plane.offset - m_capsule.radius ) * plane.normal; - b3Pos p2 = p1 + 0.1f * plane.normal; - DrawPoint( p1, 5.0f, MakeColor( b3_colorYellow ) ); - DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); - } - - DrawSolidCapsule( { m_position, b3Quat_identity }, m_capsule, MakeColor( b3_colorBlue ) ); - DrawLine( m_position, m_position + m_velocity, MakeColor( b3_colorPurple ) ); -} diff --git a/samples/geometric_mover.h b/samples/geometric_mover.h deleted file mode 100644 index e8adac1..0000000 --- a/samples/geometric_mover.h +++ /dev/null @@ -1,114 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "box3d/collision.h" -#include "box3d/types.h" - -struct GeometricMoverDef -{ - b3Pos position = {}; - b3Capsule capsule = { { 0.0f, -0.5f, 0.0f }, { 0.0f, 0.5f, 0.0f }, 0.3f }; - float jumpSpeed = 5.0f; - float maxSpeed = 6.0f; - float minSpeed = 0.01f; - float stopSpeed = 1.0f; - float accelerate = 30.0f; - float friction = 4.0f; - float gravity = 15.0f; - float pogoRestLength = 0.9f; - float pogoHertz = 4.0f; - float pogoDampingRatio = 0.7f; -}; - -// Optional shape user data read by GeometricMover when it gathers collision planes. -// Shapes without user data are treated as rigid, fully clipping, and pushable. -struct MoverShapeUserData -{ - // Distance limit on the push this surface may apply to the mover. FLT_MAX is rigid. - float maxPush; - - // False keeps the velocity along this surface, which is what soft collision needs. - bool clipVelocity; - - // False stops the mover from shoving this body. - bool canMoverPush; -}; - -// Extra data kept alongside each collision plane so the mover can push rigid bodies. -struct PlaneExtra -{ - b3Pos point; - b3ShapeId shapeId; -}; - -// Geometric character mover. The capsule is moved by casting and by solving collision -// planes, so the game keeps full control of the motion. -// -// A pogo spring holds the capsule above the ground so it can move up steps. -class GeometricMover -{ -public: - GeometricMover(); - - void Create( b3WorldId worldId, const GeometricMoverDef* def ); - - // Advance the mover. Throttle is the input along the forward and right directions on [-1, 1]. - void Update( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, float speedScale ); - - // Jump if grounded. Returns false when airborne. - bool Jump(); - - void Draw() const; - - static constexpr int m_planeCapacity = 8; - - float m_jumpSpeed; - float m_maxSpeed; - float m_minSpeed; - float m_stopSpeed; - float m_accelerate; - - // Friction in units of 1/time. - float m_friction; - - // The mover is not simulated so it needs its own gravity. - float m_gravity; - - float m_pogoRestLength; - float m_pogoHertz; - float m_pogoDampingRatio; - - // The clipper avoids picking up velocity from soft collision depenetration. Otherwise the - // velocity comes from the position delta, which is more intuitive in some cases. - bool m_clipVelocity; - - // Shapes the mover passes through. Set before calling Update. - const b3ShapeId* m_ignoreShapeIds; - int m_ignoreCount; - - // The capsule is relative to the mover position. - b3Capsule m_capsule; - - b3WorldId m_worldId; - - b3Pos m_position; - b3Vec3 m_velocity; - float m_pogoVelocity; - bool m_onGround; - - // Planes from the last solve, kept for debug drawing. - b3CollisionPlane m_planes[m_planeCapacity] = {}; - PlaneExtra m_planeExtras[m_planeCapacity] = {}; - int m_planeCount; - int m_totalIterations; - - b3Pos m_pogoOrigin; - b3Vec3 m_pogoTranslation; - b3Pos m_pogoPoint; - bool m_pogoHit; - -private: - void PushBodies(); -}; diff --git a/samples/gfx/CMakeLists.txt b/samples/gfx/CMakeLists.txt index 21bd4a6..e2594e2 100644 --- a/samples/gfx/CMakeLists.txt +++ b/samples/gfx/CMakeLists.txt @@ -10,8 +10,6 @@ set(GFX_FILES draw.h edges.c edges.h - fonts.c - fonts.h geometry_registry.c geometry_registry.h gtao.c @@ -42,18 +40,10 @@ set(GFX_FILES tone_map.c tone_map.h utility.h - world_text.c - world_text.h ) add_library(gfx STATIC ${GFX_FILES}) -set_target_properties(gfx PROPERTIES - C_STANDARD 17 - C_STANDARD_REQUIRED YES - C_EXTENSIONS YES -) - if(APPLE) set_source_files_properties( sokol_impl.c diff --git a/samples/gfx/debug_adapter.c b/samples/gfx/debug_adapter.c index b1b7b0b..04d4430 100644 --- a/samples/gfx/debug_adapter.c +++ b/samples/gfx/debug_adapter.c @@ -19,8 +19,6 @@ #include #include #include -#include -#include #define BOX3D_USER_SHAPE_CAPACITY 65536 #define BOX3D_FREELIST_END ( -1 ) @@ -50,27 +48,11 @@ typedef struct float radius; } DebugCapsule; -// A slice of a mesh holding the triangles that share one material color. -// A zero color draws with the shape color. -typedef struct -{ - MeshHandle handle; - uint32_t color; -} DebugMeshPart; - -// Hull/mesh/heightfield. Scale only for mesh. A top-level mesh whose material -// slots carry different custom colors is drawn as parts, one per color. The -// slot colors are snapshot so a runtime material change rebuilds the parts. -// The whole mesh handle is kept for highlight and material overrides. +// Hull/mesh/heightfield. Scale only for mesh. typedef struct { MeshHandle handle; b3Vec3 scale; - const b3MeshData* data; - uint32_t* slotColors; - int slotCount; - DebugMeshPart* parts; - int partCount; } DebugMesh; typedef struct @@ -97,15 +79,9 @@ typedef struct DebugSphere sphere; DebugCapsule capsule; DebugMesh geom; - // firstChild walks every child. To draw only the visible ones the - // compound tree is queried by child index, so keep the source data - // and a childIndex to pool slot map alongside the list head. struct { int firstChild; - const b3CompoundData* data; - int* childMap; - int childMapCount; } compound; }; } DebugShape; @@ -124,6 +100,9 @@ typedef struct int firstFree; int allocCount; + // For the ground grid + b3ShapeId groundShapeId; + // Per-shape PBR overrides MaterialOverride materialOverrides[BOX3D_MATERIAL_OVERRIDE_CAPACITY]; int materialOverrideCount; @@ -136,19 +115,6 @@ typedef struct b3DebugDraw guiDraw; bool transparentDynamic; - bool transparentKinematic; - - // One body drawn with reduced alpha, such as a character the camera is close to - b3BodyId alphaBodyId; - float bodyAlpha; - - // View box for compound child culling, world space, refreshed once per frame. - b3AABB viewBounds; - bool hasViewBounds; - - // Compound children appended vs total this frame. Diagnostic readout. - int lastCompoundAppended; - int lastCompoundTotal; } AdapterState; static AdapterState s_adapter; @@ -164,138 +130,6 @@ static const float kBodyTypeRoughness[3] = { 0.70f, 0.55f, 0.40f }; static const float kDebugMaterialMetallic[6] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.85f }; static const float kDebugMaterialRoughness[6] = { 0.50f, 0.85f, 0.65f, 0.95f, 0.30f, 0.35f }; -static void ReleaseMeshParts( DebugMesh* geom ) -{ - for ( int i = 0; i < geom->partCount; ++i ) - { - ReleaseMeshReference( geom->parts[i].handle ); - } - free( geom->parts ); - free( geom->slotColors ); - geom->parts = NULL; - geom->partCount = 0; - geom->slotColors = NULL; - geom->slotCount = 0; -} - -// Group the mesh triangles by the custom color of their material slot. Slots -// sharing a color share a part, so a conveyor with many belt slots of one -// color costs one draw. Nothing is split when every used slot has one color. -static void BuildMeshParts( DebugShape* us ) -{ - DebugMesh* geom = &us->geom; - ReleaseMeshParts( geom ); - - const b3MeshData* data = geom->data; - const uint8_t* indices = data != NULL ? b3GetMeshMaterialIndices( data ) : NULL; - const int slotCount = b3Shape_GetMeshMaterialCount( us->shapeId ); - if ( indices == NULL || slotCount <= 1 ) - { - return; - } - - geom->slotColors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) ); - uint8_t* used = (uint8_t*)calloc( (size_t)slotCount, 1 ); - uint8_t* mask = (uint8_t*)malloc( (size_t)slotCount ); - uint32_t* colors = (uint32_t*)malloc( (size_t)slotCount * sizeof( uint32_t ) ); - if ( geom->slotColors == NULL || used == NULL || mask == NULL || colors == NULL ) - { - free( used ); - free( mask ); - free( colors ); - free( geom->slotColors ); - geom->slotColors = NULL; - return; - } - geom->slotCount = slotCount; - - for ( int i = 0; i < slotCount; ++i ) - { - geom->slotColors[i] = b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor; - } - - for ( int t = 0; t < data->triangleCount; ++t ) - { - const int slot = indices[t] < slotCount ? indices[t] : slotCount - 1; - used[slot] = 1; - } - - int colorCount = 0; - for ( int i = 0; i < slotCount; ++i ) - { - if ( used[i] == 0 ) - { - continue; - } - bool found = false; - for ( int j = 0; j < colorCount; ++j ) - { - if ( colors[j] == geom->slotColors[i] ) - { - found = true; - break; - } - } - if ( found == false ) - { - colors[colorCount++] = geom->slotColors[i]; - } - } - - if ( colorCount > 1 ) - { - geom->parts = (DebugMeshPart*)malloc( (size_t)colorCount * sizeof( DebugMeshPart ) ); - for ( int j = 0; geom->parts != NULL && j < colorCount; ++j ) - { - for ( int i = 0; i < slotCount; ++i ) - { - mask[i] = ( used[i] != 0 && geom->slotColors[i] == colors[j] ) ? 1 : 0; - } - - MeshHandle handle = FindOrAddMeshSubset( data, mask, slotCount ); - if ( IsMeshHandleValid( handle ) == false ) - { - // Fall back to drawing the whole mesh in the shape color - for ( int k = 0; k < geom->partCount; ++k ) - { - ReleaseMeshReference( geom->parts[k].handle ); - } - free( geom->parts ); - geom->parts = NULL; - geom->partCount = 0; - break; - } - - geom->parts[geom->partCount].handle = handle; - geom->parts[geom->partCount].color = colors[j]; - geom->partCount += 1; - } - } - - free( used ); - free( mask ); - free( colors ); -} - -// Rebuild the parts when a slot color changed since they were built -static void RefreshMeshParts( DebugShape* us ) -{ - DebugMesh* geom = &us->geom; - if ( geom->slotCount <= 1 ) - { - return; - } - - for ( int i = 0; i < geom->slotCount; ++i ) - { - if ( b3Shape_GetMeshSurfaceMaterial( us->shapeId, i ).customColor != geom->slotColors[i] ) - { - BuildMeshParts( us ); - return; - } - } -} - void InitAdapter( void ) { for ( int i = 0; i < BOX3D_USER_SHAPE_CAPACITY; ++i ) @@ -305,17 +139,11 @@ void InitAdapter( void ) } s_adapter.firstFree = 0; s_adapter.allocCount = 0; + s_adapter.groundShapeId = b3_nullShapeId; s_adapter.materialOverrideCount = 0; s_adapter.selectedBodyId = b3_nullBodyId; s_adapter.selectedShapeId = b3_nullShapeId; s_adapter.transparentDynamic = false; - s_adapter.transparentKinematic = false; - s_adapter.alphaBodyId = b3_nullBodyId; - s_adapter.bodyAlpha = 1.0f; - - s_adapter.hasViewBounds = false; - s_adapter.lastCompoundAppended = 0; - s_adapter.lastCompoundTotal = 0; s_adapter.guiDraw = b3DefaultDebugDraw(); s_adapter.guiDraw.drawShapes = true; @@ -331,33 +159,19 @@ void ResetAdapterPool( void ) DebugShape* us = &s_adapter.pool[i]; if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField ) { - ReleaseMeshParts( &us->geom ); ReleaseMeshReference( us->geom.handle ); } - else if ( us->kind == Box3DUS_Compound ) - { - // A scene switch can sweep the pool before the destroy callback fires, - // so free the child map here too. - free( us->compound.childMap ); - us->compound.childMap = NULL; - } us->kind = Box3DUS_Free; us->nextFree = ( i + 1 < BOX3D_USER_SHAPE_CAPACITY ) ? ( i + 1 ) : BOX3D_FREELIST_END; } s_adapter.firstFree = 0; s_adapter.allocCount = 0; + s_adapter.groundShapeId = b3_nullShapeId; s_adapter.materialOverrideCount = 0; s_adapter.selectedBodyId = b3_nullBodyId; s_adapter.selectedShapeId = b3_nullShapeId; s_adapter.transparentDynamic = false; - s_adapter.transparentKinematic = false; - s_adapter.alphaBodyId = b3_nullBodyId; - s_adapter.bodyAlpha = 1.0f; - - s_adapter.hasViewBounds = false; - s_adapter.lastCompoundAppended = 0; - s_adapter.lastCompoundTotal = 0; } b3DebugDraw* GetGuiDraw( void ) @@ -375,7 +189,6 @@ void ApplyGuiFlags( b3DebugDraw* out ) out->drawJointExtras = s_adapter.guiDraw.drawJointExtras; out->drawBounds = s_adapter.guiDraw.drawBounds; out->drawMass = s_adapter.guiDraw.drawMass; - out->drawSleep = s_adapter.guiDraw.drawSleep; out->drawBodyNames = s_adapter.guiDraw.drawBodyNames; out->drawContacts = s_adapter.guiDraw.drawContacts; out->drawAnchorA = s_adapter.guiDraw.drawAnchorA; @@ -383,6 +196,7 @@ void ApplyGuiFlags( b3DebugDraw* out ) out->drawContactFeatures = s_adapter.guiDraw.drawContactFeatures; out->drawContactNormals = s_adapter.guiDraw.drawContactNormals; out->drawContactForces = s_adapter.guiDraw.drawContactForces; + out->drawFrictionForces = s_adapter.guiDraw.drawFrictionForces; out->drawIslands = s_adapter.guiDraw.drawIslands; } @@ -391,44 +205,14 @@ void SetTransparentDynamic( bool enabled ) s_adapter.transparentDynamic = enabled; } -void SetTransparentKinematic( bool enabled ) +bool GetTransparentDynamic( void ) { - s_adapter.transparentKinematic = enabled; -} - -void SetBodyAlpha( b3BodyId bodyId, float alpha ) -{ - s_adapter.alphaBodyId = bodyId; - s_adapter.bodyAlpha = alpha; -} - -void SetViewBounds( b3AABB bounds ) -{ - s_adapter.viewBounds = bounds; - s_adapter.hasViewBounds = true; - - // Called once per frame ahead of the draw walk, so clear the child tally here. - s_adapter.lastCompoundAppended = 0; - s_adapter.lastCompoundTotal = 0; -} - -int GetLastCompoundDrawStats( int* outTotal ) -{ - if ( outTotal != NULL ) - { - *outTotal = s_adapter.lastCompoundTotal; - } - return s_adapter.lastCompoundAppended; + return s_adapter.transparentDynamic; } void SetGroundShape( b3ShapeId shapeId ) { - if ( b3Shape_IsValid( shapeId ) == false ) - { - return; - } - - b3Shape_SetName( shapeId, BOX3D_GROUND_SHAPE_NAME ); + s_adapter.groundShapeId = shapeId; } void SetShapeMaterial( b3ShapeId shapeId, Vec4 color, float metallic, float roughness ) @@ -618,7 +402,7 @@ static void PopulateCommonFields( DebugShape* us, const b3DebugShape* debugShape { const b3BodyId bodyId = b3Shape_GetBody( debugShape->shapeId ); us->bodyType = b3Body_GetType( bodyId ); - us->isGround = strcmp( b3Shape_GetName( debugShape->shapeId ), BOX3D_GROUND_SHAPE_NAME ) == 0; + us->isGround = B3_ID_EQUALS( debugShape->shapeId, s_adapter.groundShapeId ); us->shapeId = debugShape->shapeId; us->bodyId = bodyId; RefreshMaterialFromOverride( us ); @@ -681,13 +465,11 @@ static int CreateCompoundChild( const b3ChildShape* child, const DebugShape* par break; case b3_hullShape: us->kind = Box3DUS_Hull; - us->geom = (DebugMesh){ 0 }; us->geom.handle = handle; us->geom.scale = b3Vec3_one; break; case b3_meshShape: us->kind = Box3DUS_Mesh; - us->geom = (DebugMesh){ 0 }; us->geom.handle = handle; us->geom.scale = (b3Vec3){ child->mesh.scale.x, child->mesh.scale.y, child->mesh.scale.z }; break; @@ -754,7 +536,6 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont DebugShape* us = &s_adapter.pool[index]; us->kind = Box3DUS_Hull; PopulateCommonFields( us, debugShape ); - us->geom = (DebugMesh){ 0 }; us->geom.handle = handle; us->geom.scale = b3Vec3_one; return us; @@ -777,11 +558,8 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont DebugShape* us = &s_adapter.pool[index]; us->kind = Box3DUS_Mesh; PopulateCommonFields( us, debugShape ); - us->geom = (DebugMesh){ 0 }; us->geom.handle = handle; us->geom.scale = (b3Vec3){ mesh->scale.x, mesh->scale.y, mesh->scale.z }; - us->geom.data = mesh->data; - BuildMeshParts( us ); return us; } @@ -802,7 +580,6 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont DebugShape* us = &s_adapter.pool[index]; us->kind = Box3DUS_HeightField; PopulateCommonFields( us, debugShape ); - us->geom = (DebugMesh){ 0 }; us->geom.handle = handle; us->geom.scale = b3Vec3_one; return us; @@ -818,26 +595,12 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont DebugShape* us = &s_adapter.pool[index]; us->kind = Box3DUS_Compound; PopulateCommonFields( us, debugShape ); + us->compound.firstChild = -1; // Flatten the children once. The fixed pool never relocates, so the // parent pointer stays valid while children are allocated. const b3CompoundData* compound = debugShape->compound; const int total = compound->capsuleCount + compound->hullCount + compound->meshCount + compound->sphereCount; - - // Keep the source data for the cull query and map each tree child index to - // its pool slot. A NULL map falls back to walking every child. - us->compound.firstChild = -1; - us->compound.data = compound; - us->compound.childMapCount = total; - us->compound.childMap = ( total > 0 ) ? (int*)malloc( (size_t)total * sizeof( int ) ) : NULL; - if ( us->compound.childMap != NULL ) - { - for ( int i = 0; i < total; ++i ) - { - us->compound.childMap[i] = -1; - } - } - int prev = -1; for ( int i = 0; i < total; ++i ) { @@ -847,10 +610,6 @@ static void* AdapterCreateDebugShape( const b3DebugShape* debugShape, void* cont { continue; // skip a child we couldn't register, keep the rest } - if ( us->compound.childMap != NULL ) - { - us->compound.childMap[i] = childIndex; - } if ( prev < 0 ) { us->compound.firstChild = childIndex; @@ -891,12 +650,9 @@ static void DestroyDebugShape( void* userShape, void* context ) FreeDebugShape( ci ); ci = next; } - free( us->compound.childMap ); - us->compound.childMap = NULL; } else if ( us->kind == Box3DUS_Hull || us->kind == Box3DUS_Mesh || us->kind == Box3DUS_HeightField ) { - ReleaseMeshParts( &us->geom ); ReleaseMeshReference( us->geom.handle ); } @@ -908,14 +664,14 @@ static void DestroyDebugShape( void* userShape, void* context ) // origin to the same grid period. // Alpha applied to non-static shapes when box3dAdapterSetTransparentDynamic is on. -#define BOX3D_TRANSPARENT_ALPHA 0.5f +#define BOX3D_TRANSPARENT_DYNAMIC_ALPHA 0.5f // Emit one resolved primitive at baseTransform. The per-kind offset (sphere // center, capsule frame) layers on top of baseTransform, so the same path // serves a top-level shape (base = body transform) and a compound child // (base = body transform composed with the child transform). -static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic, - float roughness, TransparentShadowCast shadowCast, HighlightKind hk ) +static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform, Vec4 c, float metallic, float roughness, + TransparentShadowCast shadowCast, HighlightKind hk ) { if ( us->kind == Box3DUS_Sphere ) { @@ -939,24 +695,7 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform { MeshMaterialMode mode = us->isGround ? MESH_MATERIAL_MODE_GROUND_GRID : MESH_MATERIAL_MODE_SOLID; float cell = us->isGround ? BOX3D_GROUND_GRID_CELL_SIZE : 0.0f; - if ( us->geom.partCount > 0 && us->hasMaterial == false ) - { - for ( int i = 0; i < us->geom.partCount; ++i ) - { - const DebugMeshPart* part = &us->geom.parts[i]; - Vec4 pc = c; - if ( part->color != 0 ) - { - pc = HexColorToLinear( (b3HexColor)part->color ); - pc.w = c.w; - } - AppendMesh( part->handle, baseTransform, us->geom.scale, pc, metallic, roughness, mode, cell, shadowCast ); - } - } - else - { - AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast ); - } + AppendMesh( us->geom.handle, baseTransform, us->geom.scale, c, metallic, roughness, mode, cell, shadowCast ); if ( hk != HIGHLIGHT_KIND_NONE ) { AppendHighlightGeometry( us->geom.handle, baseTransform, us->geom.scale, hk ); @@ -964,48 +703,12 @@ static void AppendResolvedShape( const DebugShape* us, b3Transform baseTransform } } -// Context for the compound cull query. Carries the resolved material and the body relative transform so each visited -// child appends exactly as the full walk would. -typedef struct -{ - const DebugShape* parent; - b3Transform shapeRelative; - Vec4 color; - float metallic; - float roughness; - TransparentShadowCast shadowCast; - HighlightKind hk; - int appended; -} CompoundCullContext; - -// The compound tree stores child indices. Remap to the pool slot the flatten -// pass assigned, then append the child under the body transform. -static bool CompoundCullCallback( const b3CompoundData* compound, int childIndex, void* context ) -{ - (void)compound; - CompoundCullContext* ctx = (CompoundCullContext*)context; - if ( childIndex < 0 || childIndex >= ctx->parent->compound.childMapCount ) - { - return true; - } - const int slot = ctx->parent->compound.childMap[childIndex]; - if ( slot < 0 ) - { - return true; // child could not be registered at create - } - const DebugShape* child = &s_adapter.pool[slot]; - b3Transform base = b3MulTransforms( ctx->shapeRelative, child->childTransform ); - AppendResolvedShape( child, base, ctx->color, ctx->metallic, ctx->roughness, ctx->shadowCast, ctx->hk ); - ctx->appended += 1; - return true; -} - -static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexColor color, void* context ) +static bool DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexColor color, void* context ) { (void)context; if ( userShape == NULL ) { - return; + return true; // unsupported shape type, skip and continue } // Shift the world transform into the camera relative frame the primitives render in @@ -1015,11 +718,6 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo RefreshMaterialFromOverride( us ); - if ( us->kind == Box3DUS_Mesh ) - { - RefreshMeshParts( us ); - } - Vec4 c; float metallic; float roughness; @@ -1051,17 +749,7 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo if ( s_adapter.transparentDynamic && us->bodyType == b3_dynamicBody ) { - c.w = BOX3D_TRANSPARENT_ALPHA; - } - - if ( s_adapter.bodyAlpha < 1.0f && B3_ID_EQUALS( us->bodyId, s_adapter.alphaBodyId ) ) - { - c.w = b3MinFloat( c.w, s_adapter.bodyAlpha ); - } - - if ( s_adapter.transparentKinematic && us->bodyType == b3_kinematicBody ) - { - c.w = BOX3D_TRANSPARENT_ALPHA; + c.w = BOX3D_TRANSPARENT_DYNAMIC_ALPHA; } TransparentShadowCast shadowCast = TRANSPARENT_SHADOW_NONE; @@ -1072,51 +760,18 @@ static void DrawShape( void* userShape, b3WorldTransform shapeTransform, b3HexCo if ( us->kind == Box3DUS_Compound ) { - bool cull = s_adapter.hasViewBounds && us->compound.data != NULL && us->compound.childMap != NULL; - - b3AABB viewRel = s_adapter.viewBounds; - if ( cull ) + for ( int ci = us->compound.firstChild; ci != -1; ci = s_adapter.pool[ci].nextChild ) { - // Shift the view box into the draw origin frame the primitives render in. - b3Pos origin = GetDrawOrigin(); - viewRel.lowerBound = b3SubPos( b3ToPos( s_adapter.viewBounds.lowerBound ), origin ); - viewRel.upperBound = b3SubPos( b3ToPos( s_adapter.viewBounds.upperBound ), origin ); - - // If the whole compound sits inside the view the query returns every child, - // so walking the list is cheaper. Both boxes are in the draw origin frame. - b3AABB rootRel = b3AABB_Transform( shapeRelative, us->compound.data->bounds ); - if ( b3AABB_Contains( viewRel, rootRel ) ) - { - cull = false; - } - } - - if ( cull ) - { - // Rotate the view box into compound local space to query the child tree. - b3AABB localCull = b3AABB_Transform( b3InvertTransform( shapeRelative ), viewRel ); - - CompoundCullContext ctx = { us, shapeRelative, c, metallic, roughness, shadowCast, hk, 0 }; - b3QueryCompound( us->compound.data, localCull, CompoundCullCallback, &ctx ); - - s_adapter.lastCompoundAppended += ctx.appended; - s_adapter.lastCompoundTotal += us->compound.childMapCount; - } - else - { - for ( int ci = us->compound.firstChild; ci != -1; ci = s_adapter.pool[ci].nextChild ) - { - b3Transform base = b3MulTransforms( shapeRelative, s_adapter.pool[ci].childTransform ); - AppendResolvedShape( &s_adapter.pool[ci], base, c, metallic, roughness, shadowCast, hk ); - } - s_adapter.lastCompoundAppended += us->compound.childMapCount; - s_adapter.lastCompoundTotal += us->compound.childMapCount; + b3Transform base = b3MulTransforms( shapeRelative, s_adapter.pool[ci].childTransform ); + AppendResolvedShape( &s_adapter.pool[ci], base, c, metallic, roughness, shadowCast, hk ); } } else { AppendResolvedShape( us, shapeRelative, c, metallic, roughness, shadowCast, hk ); } + + return true; } #define BOX3D_LINE_THICKNESS_PX 2.5f @@ -1142,8 +797,8 @@ static void DrawTransformFcn( b3WorldTransform transform, void* context ) Vec4 blue = MakeVec4( 0.0f, 0.0f, 1.0f, 1.0f ); OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cx ), red, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); - OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX, - OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); + OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cy ), green, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, + OVERLAY_OCCLUSION_HIDE ); OverlayAppendLine( origin, b3MulAdd( origin, L, basis.cz ), blue, BOX3D_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_HIDE ); } @@ -1166,22 +821,22 @@ static void DrawCapsuleFcn( b3Pos p1, b3Pos p2, float radius, b3HexColor color, { (void)context; - b3Vec3 e = b3SubPos( p2, p1 ); + b3Vec3 e = b3SubPos(p2, p1); float length = b3Length( e ); - if ( length < FLT_EPSILON ) + if (length < FLT_EPSILON) { - DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ), - DEFAULT_METALLIC, DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE ); + DrawSphereEx( (b3WorldTransform){ p1, b3Quat_identity }, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC, + DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE ); return; } b3Vec3 en = b3MulSV( 1.0f / length, e ); b3WorldTransform transform; - transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e ) ); + transform.p = b3OffsetPos( p1, b3MulSV( 0.5f, e )); transform.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, en ); DrawCapsuleEx( transform, 0.5f * length, radius, HexColorAToVec4( color, alpha ), DEFAULT_METALLIC, - DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE ); + DEFAULT_ROUGHNESS, TRANSPARENT_SHADOW_NONE ); } static void DrawBoundsFcn( b3AABB aabb, b3HexColor color, void* context ) diff --git a/samples/gfx/debug_adapter.h b/samples/gfx/debug_adapter.h index 5d56af4..e421150 100644 --- a/samples/gfx/debug_adapter.h +++ b/samples/gfx/debug_adapter.h @@ -16,9 +16,6 @@ extern "C" // draw origin to the grid period and keep the grid crisp far from the origin. #define BOX3D_GROUND_GRID_CELL_SIZE 1.0f -// Shapes carrying this name draw with the grid instead of a solid material. -#define BOX3D_GROUND_SHAPE_NAME "ground" - void InitAdapter( void ); // Unconditionally flush the debug-shape pool: release the GPU mesh references @@ -34,23 +31,11 @@ b3DebugDraw* GetGuiDraw( void ); void ApplyGuiFlags( b3DebugDraw* out ); int GetDebugShapeCount( void ); -// Tag a Box3D shape so the renderer draws it with the procedural ground grid. The tag is the shape -// name, which lives in the world rather than in the renderer, so it is captured by a recording and -// comes back on replay. Ignores an invalid shape, which lets a scene hand over a ground it may not -// have created. +// Tag a Box3D shape so the renderer draws it with the procedural ground grid. void SetGroundShape( b3ShapeId shapeId ); void SetShapeMaterial( b3ShapeId shapeId, Vec4 color, float metallic, float roughness ); void SetTransparentDynamic( bool enabled ); -void SetTransparentKinematic( bool enabled ); -void SetBodyAlpha( b3BodyId bodyId, float alpha ); - -// View box for compound child culling, world space. Set once per frame before -// b3World_Draw. A compound then submits only the children overlapping this box -// instead of walking its entire child set. -void SetViewBounds( b3AABB bounds ); - -// Children appended in the last draw, and the total across drawn compounds. -int GetLastCompoundDrawStats( int* outTotal ); +bool GetTransparentDynamic( void ); void SetSelectedBody( b3BodyId bodyId ); void SetSelectedShape( b3ShapeId shapeId ); diff --git a/samples/gfx/debug_shapes.c b/samples/gfx/debug_shapes.c index 6cc3a9a..dc74a55 100644 --- a/samples/gfx/debug_shapes.c +++ b/samples/gfx/debug_shapes.c @@ -6,7 +6,6 @@ #include "gfx/qsort.h" #include -#include #include #include #include @@ -302,7 +301,7 @@ static MeshHandle BuildHull( const b3HullData* hull ) const b3Plane* planes = b3GetHullPlanes( hull ); if ( !points || !edges || !faces || !planes ) { - fprintf( stderr, "error: hull missing arrays (hash=0x%016" PRIx64 ")\n", hull->hash ); + fprintf( stderr, "error: hull missing arrays (hash=0x%08x)\n", hull->hash ); return InvalidMeshHandle(); } @@ -331,7 +330,7 @@ static MeshHandle BuildHull( const b3HullData* hull ) e = edges[e].next; if ( loopLen > 256 ) { - fprintf( stderr, "error: hull face loop runaway (hash=0x%016" PRIx64 ")\n", hull->hash ); + fprintf( stderr, "error: hull face loop runaway (hash=0x%08x)\n", hull->hash ); BufferFree( &buf ); return InvalidMeshHandle(); } @@ -420,17 +419,14 @@ static inline int MeshEdgeLess( const EdgeRecord* a, const EdgeRecord* b ) return a->v1 < b->v1; } -// A NULL slotMask builds every triangle. Otherwise only triangles whose material -// slot has a nonzero mask entry are emitted, and their edges with them. -static MeshHandle BuildMeshData( const b3MeshData* meshData, uint64_t hash, const uint8_t* slotMask, int slotCount ) +static MeshHandle BuildMeshData( const b3MeshData* meshData ) { const b3Vec3* verts = b3GetMeshVertices( meshData ); const b3MeshTriangle* tris = b3GetMeshTriangles( meshData ); const uint8_t* flags = b3GetMeshFlags( meshData ); - const uint8_t* materialIndices = slotMask != NULL ? b3GetMeshMaterialIndices( meshData ) : NULL; if ( !verts || !tris || meshData->triangleCount <= 0 ) { - fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%016" PRIx64 ")\n", meshData->hash ); + fprintf( stderr, "error: mesh missing arrays or empty (hash=0x%08x)\n", meshData->hash ); return InvalidMeshHandle(); } @@ -439,15 +435,6 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData, uint64_t hash, cons for ( int t = 0; t < meshData->triangleCount; ++t ) { - if ( materialIndices != NULL ) - { - const int slot = materialIndices[t] < slotCount ? materialIndices[t] : slotCount - 1; - if ( slotMask[slot] == 0 ) - { - continue; - } - } - const b3MeshTriangle tri = tris[t]; const b3Vec3 a = verts[tri.index1]; const b3Vec3 b = verts[tri.index2]; @@ -535,7 +522,7 @@ static MeshHandle BuildMeshData( const b3MeshData* meshData, uint64_t hash, cons eb.count = write + 1; } - const MeshHandle h = RegisterMesh( hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" ); + const MeshHandle h = RegisterMesh( meshData->hash, buf.vertices, buf.vertexCount, buf.indices, buf.indexCount, "geom_mesh" ); if ( IsMeshHandleValid( h ) ) { @@ -572,7 +559,7 @@ static MeshHandle BuildHeightField( const b3HeightFieldData* hf ) { if ( hf->columnCount < 2 || hf->rowCount < 2 ) { - fprintf( stderr, "error: heightfield degenerate (hash=0x%016" PRIx64 ")\n", hf->hash ); + fprintf( stderr, "error: heightfield degenerate (hash=0x%08x)\n", hf->hash ); return InvalidMeshHandle(); } @@ -804,7 +791,7 @@ static MeshHandle BuildHeightField( const b3HeightFieldData* hf ) MeshHandle FindOrAddHull( const b3HullData* hull ) { - if ( !hull || hull->hash == 0 ) + if ( !hull || hull->hash == 0u ) { return InvalidMeshHandle(); } @@ -821,7 +808,7 @@ MeshHandle FindOrAddHull( const b3HullData* hull ) MeshHandle FindOrAddMesh( const b3MeshData* meshData ) { - if ( !meshData || meshData->hash == 0 ) + if ( !meshData || meshData->hash == 0u ) { return InvalidMeshHandle(); } @@ -833,42 +820,12 @@ MeshHandle FindOrAddMesh( const b3MeshData* meshData ) return existing; } - return BuildMeshData( meshData, meshData->hash, NULL, 0 ); -} - -MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount ) -{ - if ( !meshData || meshData->hash == 0 || slotMask == NULL || slotCount <= 0 || - b3GetMeshMaterialIndices( meshData ) == NULL ) - { - return FindOrAddMesh( meshData ); - } - - // FNV-1a over the mask, seeded with the mesh hash - uint64_t hash = meshData->hash ^ 0xcbf29ce484222325ull; - for ( int i = 0; i < slotCount; ++i ) - { - hash ^= slotMask[i] != 0 ? 1u : 0u; - hash *= 0x100000001b3ull; - } - if ( hash == 0 || hash == meshData->hash ) - { - hash += 1; - } - - MeshHandle existing = FindMesh( hash ); - if ( IsMeshHandleValid( existing ) ) - { - AddMeshReference( existing ); - return existing; - } - - return BuildMeshData( meshData, hash, slotMask, slotCount ); + return BuildMeshData( meshData ); } MeshHandle FindOrAddHeightField( const b3HeightFieldData* heightField ) { - if ( !heightField || heightField->hash == 0 ) + if ( !heightField || heightField->hash == 0u ) { return InvalidMeshHandle(); } diff --git a/samples/gfx/debug_shapes.h b/samples/gfx/debug_shapes.h index 1c72a37..ecf024b 100644 --- a/samples/gfx/debug_shapes.h +++ b/samples/gfx/debug_shapes.h @@ -39,12 +39,6 @@ MeshHandle FindOrAddHull( const b3HullData* hull ); // draw time. Two b3Mesh sharing the same b3MeshData share one entry. MeshHandle FindOrAddMesh( const b3MeshData* meshData ); -// Acquire the subset of a mesh whose triangles sit in a material slot with a -// nonzero slotMask entry. Keyed by the mesh hash mixed with the mask, so shapes -// sharing a mesh and a slot grouping share one entry. Falls back to the whole -// mesh when the mesh carries no material indices. -MeshHandle FindOrAddMeshSubset( const b3MeshData* meshData, const uint8_t* slotMask, int slotCount ); - // Acquire for b3HeightFieldData. The `scale` vector is part of the height // field's hash (folded into construction), so two heightfields with // different scales hash to different entries, per-instance scale stays diff --git a/samples/gfx/draw.c b/samples/gfx/draw.c index a870a5b..c9afc3b 100644 --- a/samples/gfx/draw.c +++ b/samples/gfx/draw.c @@ -295,7 +295,7 @@ void DrawGrid( b3Pos center, b3Vec3 normal, float halfExtent, int divisions, Vec void DrawGroundGrid( int size ) { - Vec4 color = MakeVec4( 0.3f, 0.3f, 0.3f, 0.3f ); + Vec4 color = MakeVec4( 0.3f, 0.3f, 0.3f, 1.0f ); DrawGrid( b3Pos_zero, b3Vec3_axisY, (float)size, size, color ); } diff --git a/samples/gfx/draw.h b/samples/gfx/draw.h index de5fec8..6d3def5 100644 --- a/samples/gfx/draw.h +++ b/samples/gfx/draw.h @@ -121,7 +121,6 @@ void DrawWireSphere( b3WorldTransform transform, const b3Sphere* sphere, int seg void DrawWireCapsule( b3WorldTransform transform, const b3Capsule* capsule, int segments, Vec4 color ); // printf-style positioned text label. The renderer projects with its latched camera. -B3_PRINTF_FORMAT(3, 4) void DrawString3D( b3Pos point, Vec4 color, const char* format, ... ); #ifdef __cplusplus diff --git a/samples/gfx/edges.c b/samples/gfx/edges.c index 976b7d3..c11d23e 100644 --- a/samples/gfx/edges.c +++ b/samples/gfx/edges.c @@ -40,8 +40,7 @@ EdgeOverlayParams GetDefaultEdgeParams( void ) p.zBias = 1.0e-6f; p.convexColor = MakeVec4( 0.1f, 0.8f, 0.1f, 0.75f ); p.concaveColor = MakeVec4( 0.8f, 0.10f, 0.10f, 0.75f ); - p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.2f ); - p.alphaScale = 1.0f; + p.flatColor = MakeVec4( 0.6f, 0.6f, 0.6f, 0.5f ); return p; } @@ -107,11 +106,9 @@ void ShutdownEdges( void ) s_edges.ready = false; } -static inline Vec4 Premultiply( Vec4 c, float alphaScale ) +static inline Vec4 Premultiply( Vec4 c ) { - float a = c.w * alphaScale; - a = a < 1.0f ? a : 1.0f; - return MakeVec4( c.x * a, c.y * a, c.z * a, a ); + return MakeVec4( c.x * c.w, c.y * c.w, c.z * c.w, c.w ); } // Per-batch policy: does the toggle want this batch drawn at all? @@ -163,13 +160,13 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4* edge_ub_pass_t passMesh = { 0 }; if ( params->showEdgeConvexity ) { - passMesh.convex_color = Premultiply( params->convexColor, params->alphaScale ); - passMesh.concave_color = Premultiply( params->concaveColor, params->alphaScale ); - passMesh.flat_color = Premultiply( params->flatColor, params->alphaScale ); + passMesh.convex_color = Premultiply( params->convexColor ); + passMesh.concave_color = Premultiply( params->concaveColor ); + passMesh.flat_color = Premultiply( params->flatColor ); } else { - Vec4 flat = Premultiply( params->flatColor, params->alphaScale ); + Vec4 flat = Premultiply( params->flatColor ); passMesh.convex_color = flat; passMesh.concave_color = flat; passMesh.flat_color = flat; @@ -178,7 +175,7 @@ static void SubmitBatches( int width, int height, const Mat4* view, const Mat4* edge_ub_pass_t passHull = { 0 }; Vec4 hullEdgeColor = { 0.5f, 0.5f, 0.5f, 0.5f }; - Vec4 hull = Premultiply( hullEdgeColor, params->alphaScale ); + Vec4 hull = Premultiply( hullEdgeColor ); passHull.convex_color = hull; passHull.concave_color = hull; passHull.flat_color = hull; diff --git a/samples/gfx/edges.h b/samples/gfx/edges.h index 86d1c84..d38d6fd 100644 --- a/samples/gfx/edges.h +++ b/samples/gfx/edges.h @@ -6,14 +6,18 @@ // into two submission paths to match the silhouette quality of the // rest of the scene: // -// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes, heightfields, opaque hulls). Draws inside the caller's -// currently-open MSAA scene pass, picking up the same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's -// color/depth formats and sample_count. +// Opaque path (RenderEdgesInMSAA): opaque-arena batches (meshes, +// heightfields, opaque hulls if policy 1b is ever relaxed). Draws +// inside the caller's currently-open MSAA scene pass, picking up the +// same 4x MSAA as the opaque shapes. Pipeline tracks scene_target's +// color/depth formats and sample_count. // -// Transparent path (RenderEdgesPostTransparent): transparent-arena batches (just hulls). Opens its own single-sample -// pass against the resolved scene color + GTAO prepass depth, so edges sit on top of the transparent draws that have -// already blended into the resolve. MSAA isn't available here (the resolve already happened), the FS's fwidth-based AA -// does what it can. +// Transparent path (RenderEdgesPostTransparent): transparent-arena batches +// (hulls per policy 1b). Opens its own single-sample pass against the +// resolved scene color + GTAO prepass depth, so edges sit on top of the +// transparent draws that have already blended into the resolve. MSAA +// isn't available here (the resolve already happened), the FS's +// fwidth-based AA does what it can. #pragma once @@ -39,7 +43,6 @@ typedef struct EdgeOverlayParams Vec4 convexColor; // straight (non-premultiplied) linear RGBA, premultiplied inside Vec4 concaveColor; Vec4 flatColor; - float alphaScale; // multiplies the alpha of every edge color, clamped to 1 } EdgeOverlayParams; EdgeOverlayParams GetDefaultEdgeParams( void ); diff --git a/samples/gfx/fonts.c b/samples/gfx/fonts.c deleted file mode 100644 index 7bab0c7..0000000 --- a/samples/gfx/fonts.c +++ /dev/null @@ -1,327 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "gfx/fonts.h" - -#include - -// Copied from imgui_draw.cpp -// -// Based on ProggyForever: https://github.com/ocornut/proggyforever -// MIT license / Copyright (c) 2026 Disco Hello, Copyright (c) 2019,2023 Tristan Grimmerom. - -// File: 'data/fonts/ProggyForever-Regular-minimal.ttf' (18556 bytes) -// Exported using binary_to_compressed_c.exe -u8 "data/fonts/ProggyForever-Regular-minimal.ttf" ProggyForeverMinimal -static const unsigned int ProggyForeverMinimal_size = 18556; - -// clang-format off -static const unsigned char ProggyForeverMinimal_data[18556] = -{ - 0,1,0,0,0,14,0,128,0,3,0,96,70,70,84,77,176,111,174,190,0,0,72,96,0,0,0,28,71,68,69,70,0,136,0,105,0,0,72,64,0,0,0,30,79,83,47,50,104,97,19,194,0,0,1,104,0,0,0,96,99,109,97,112,177, - 173,221,139,0,0,3,80,0,0,1,114,99,118,116,32,0,33,2,121,0,0,4,196,0,0,0,4,103,97,115,112,255,255,0,3,0,0,72,56,0,0,0,8,103,108,121,102,239,245,108,207,0,0,6,76,0,0,62,224,104,101,97, - 100,44,57,58,3,0,0,0,236,0,0,0,54,104,104,101,97,4,62,0,230,0,0,1,36,0,0,0,36,104,109,116,120,24,22,19,139,0,0,1,200,0,0,1,136,108,111,99,97,80,9,64,114,0,0,4,200,0,0,1,130,109,97, - 120,112,1,7,0,139,0,0,1,72,0,0,0,32,110,97,109,101,10,160,159,151,0,0,69,44,0,0,1,68,112,111,115,116,70,77,175,253,0,0,70,112,0,0,1,197,0,1,0,0,0,1,0,0,1,224,136,151,95,15,60,245,0, - 11,3,232,0,0,0,0,229,175,187,66,0,0,0,0,229,178,59,232,255,225,255,68,1,215,2,176,0,0,0,8,0,2,0,0,0,0,0,0,0,1,0,0,2,131,255,71,0,0,1,184,255,225,255,226,1,215,0,1,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,4,0,1,0,0,0,192,0,90,0,5,0,0,0,0,0,2,0,0,0,1,0,1,0,0,0,64,0,46,0,0,0,0,0,4,1,184,1,144,0,5,0,0,2,138,2,187,0,0,0,140,2,138,2,187,0,0,1,223,0,49,1,2,0,0,0,0,0,0,0,0,0,0, - 0,0,128,0,0,7,16,0,0,2,0,0,0,0,0,0,0,0,88,88,88,88,0,64,0,32,32,172,2,131,255,71,0,0,2,175,0,187,0,0,0,3,0,0,0,0,1,133,2,6,0,0,0,32,0,1,1,184,0,33,0,0,0,0,1,184,0,0,1,184,0,0,0,166, - 0,116,255,249,0,49,0,5,0,4,0,185,0,135,0,135,0,27,0,22,0,154,0,53,0,166,0,39,0,41,0,79,0,50,0,45,0,22,0,49,0,41,0,46,0,39,0,41,0,166,0,143,0,24,0,24,0,24,0,48,255,225,0,5,0,38,0,47, - 0,39,0,52,0,58,0,35,0,42,0,66,0,65,0,19,0,49,0,19,0,41,0,35,0,44,0,13,0,38,0,42,0,9,0,37,0,13,255,250,0,0,0,5,0,33,0,104,0,39,0,104,0,37,255,242,0,124,0,48,0,50,0,59,0,50,0,37,0,40, - 0,50,0,62,0,139,0,100,0,41,0,133,0,20,0,62,0,42,0,50,0,50,0,69,0,69,0,87,0,54,0,29,255,249,0,20,0,47,0,64,0,63,0,188,0,63,0,22,0,21,0,159,0,63,0,40,0,55,0,5,0,188,0,64,0,109,255,249, - 0,92,0,50,255,249,0,109,0,101,0,24,0,115,0,109,0,131,0,37,0,48,0,159,0,143,0,114,0,83,0,50,0,19,0,19,0,18,0,73,0,5,0,5,0,5,0,5,0,5,0,5,0,2,0,47,0,52,0,52,0,52,0,52,0,66,0,66,0,66,0, - 66,0,17,0,42,0,35,0,35,0,35,0,35,0,46,0,1,0,46,0,46,0,46,0,47,0,5,0,42,0,42,0,38,0,38,0,38,0,38,0,38,0,38,0,5,0,59,0,37,0,37,0,37,0,37,0,51,0,68,0,68,0,68,0,42,0,62,0,43,0,43,0,43, - 0,43,0,43,0,24,0,12,0,61,0,61,0,61,0,61,0,26,0,50,0,26,0,30,0,0,0,3,0,0,0,3,0,0,0,28,0,1,0,0,0,0,0,108,0,3,0,1,0,0,0,28,0,4,0,80,0,0,0,16,0,16,0,3,0,0,0,126,0,133,0,171,0,210,0,211, - 0,255,32,172,255,255,0,0,0,32,0,133,0,161,0,174,0,211,0,212,32,172,255,255,255,227,255,221,255,194,255,192,255,95,255,191,224,19,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,6,0,0,1,0, - 0,0,0,0,0,0,1,2,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45, - 46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,0,132,133,135,137,145,149, - 155,160,159,161,163,162,164,166,168,167,169,170,172,171,173,174,176,178,177,179,181,180,185,184,186,187,0,112,100,101,105,0,118,158,110,107,0,116,106,0,134,151,0,113,0,0,103,117,0, - 0,0,0,0,108,122,0,165,183,127,99,0,0,0,0,0,109,123,0,0,128,131,148,0,0,0,0,0,0,0,0,182,0,190,60,0,191,0,0,0,0,0,119,0,0,0,130,138,129,139,136,141,142,143,140,50,147,0,146,153,154,152, - 0,0,0,111,0,0,0,120,0,0,0,0,0,0,33,2,121,0,0,0,42,0,42,0,42,0,42,0,68,0,86,0,134,0,210,1,14,1,104,1,116,1,148,1,180,1,212,1,232,2,6,2,20,2,38,2,54,2,100,2,122,2,172,2,232,3,2,3,60, - 3,116,3,134,3,210,4,10,4,40,4,82,4,102,4,122,4,142,4,204,5,36,5,60,5,118,5,158,5,184,5,208,5,228,6,24,6,44,6,68,6,94,6,118,6,134,6,160,6,182,6,224,7,14,7,64,7,106,7,182,7,200,7,238, - 8,0,8,28,8,52,8,72,8,96,8,114,8,130,8,148,8,166,8,180,8,194,9,12,9,58,9,92,9,140,9,182,9,214,10,14,10,44,10,74,10,110,10,134,10,150,10,198,10,230,11,4,11,50,11,96,11,130,11,188,11, - 216,11,250,12,14,12,42,12,66,12,114,12,142,12,198,12,210,13,10,13,62,13,126,13,152,13,198,13,238,14,34,14,72,14,90,14,198,14,232,15,32,15,106,15,134,15,200,15,214,15,244,16,16,16,56, - 16,114,16,128,16,182,16,212,16,230,17,2,17,22,17,60,17,86,17,132,17,194,18,20,18,76,18,108,18,140,18,176,18,228,19,24,19,74,19,110,19,168,19,198,19,228,20,6,20,56,20,86,20,116,20,150, - 20,200,20,252,21,44,21,92,21,144,21,212,22,24,22,50,22,112,22,148,22,186,22,226,23,28,23,56,23,90,23,160,23,246,24,76,24,164,25,18,25,124,25,226,26,94,26,150,26,198,26,248,27,44,27, - 114,27,144,27,174,27,208,28,2,28,74,28,136,28,174,28,212,28,254,29,60,29,118,29,172,29,230,30,16,30,58,30,104,30,166,30,206,30,244,31,48,31,112,0,0,0,2,0,33,0,0,1,42,2,154,0,3,0,7, - 0,46,177,1,0,47,60,178,7,4,0,237,50,177,6,5,220,60,178,3,2,0,237,50,0,177,3,0,47,60,178,5,4,0,237,50,178,7,6,1,252,60,178,1,2,0,237,50,51,17,33,17,39,51,17,35,33,1,9,232,199,199,2, - 154,253,102,33,2,88,0,0,2,0,166,255,254,1,18,2,35,0,7,0,13,0,0,54,50,22,20,6,34,38,52,55,35,3,55,51,21,198,44,32,32,44,32,85,59,14,1,83,105,31,44,32,32,44,122,1,4,91,91,0,2,0,116,1, - 70,1,68,2,7,0,3,0,7,0,0,1,35,53,51,7,35,53,51,1,67,64,64,142,65,65,1,70,192,192,192,0,2,255,248,0,3,1,191,2,3,0,3,0,31,0,0,63,1,35,7,37,35,7,51,21,35,7,35,55,35,7,35,55,35,53,51,55, - 35,53,51,55,51,7,51,55,51,7,51,254,30,92,30,1,29,104,31,92,106,38,59,38,92,38,58,38,96,110,31,98,112,38,59,38,92,38,58,38,90,201,115,115,115,115,54,143,143,143,143,54,115,54,144,144, - 144,144,0,0,3,0,49,255,241,1,135,2,22,0,6,0,11,0,52,0,0,55,62,1,53,52,38,47,1,53,6,21,20,23,30,3,21,20,7,21,35,53,46,1,47,1,53,30,2,23,53,46,3,53,52,54,55,53,51,21,30,1,31,1,21,38, - 39,21,50,249,32,41,36,37,60,72,137,22,40,46,28,141,60,36,67,15,15,6,21,69,37,31,44,43,22,75,65,60,25,55,15,15,43,67,3,81,7,37,31,30,32,10,73,135,12,61,44,30,4,15,28,50,33,114,15,44, - 43,1,14,6,6,63,4,11,22,3,162,6,15,26,42,29,53,67,9,45,42,2,11,5,5,62,29,4,150,0,5,0,5,0,11,1,178,1,250,0,3,0,11,0,19,0,27,0,35,0,0,1,51,1,35,36,50,54,52,38,34,6,20,54,50,22,20,6,34, - 38,52,2,20,22,50,54,52,38,34,22,20,6,34,38,52,54,50,1,74,71,254,222,71,1,16,41,30,30,41,29,7,84,60,60,84,59,174,30,41,29,29,41,122,60,84,59,59,84,1,249,254,21,47,27,39,27,27,39,115, - 56,79,56,56,79,1,26,39,27,27,39,27,7,79,56,56,79,56,0,0,0,3,0,4,255,246,1,179,2,21,0,9,0,28,0,62,0,0,55,50,55,46,1,39,6,21,20,22,3,28,2,30,5,23,62,1,53,52,38,35,34,6,1,23,35,38,39, - 6,35,34,38,53,52,54,55,46,2,53,52,54,51,50,22,21,20,14,2,7,22,23,54,53,55,20,206,52,37,25,110,24,65,80,41,1,2,3,6,8,12,7,37,37,31,23,24,35,1,2,67,72,13,21,60,89,72,104,52,44,22,19, - 15,63,60,61,51,15,32,25,24,89,58,36,61,44,36,28,131,28,54,59,48,62,1,125,1,7,3,7,5,10,9,13,16,9,25,40,24,21,25,32,254,143,79,15,24,49,96,66,50,74,33,25,25,40,24,41,69,55,49,20,36,34, - 20,17,107,69,65,72,1,108,0,1,0,185,1,70,0,255,2,8,0,3,0,0,19,35,53,51,254,68,68,1,71,193,0,1,0,135,255,193,1,49,2,62,0,17,0,0,1,14,1,20,22,23,35,46,4,52,62,2,63,1,1,49,43,55,55,43, - 60,4,15,38,29,24,23,32,33,11,11,2,61,60,177,161,177,60,6,21,68,70,103,97,102,75,61,16,16,0,0,1,0,135,255,193,1,49,2,62,0,17,0,0,19,30,4,20,14,2,15,1,35,62,1,52,38,39,195,4,15,38,29, - 24,23,32,33,11,11,60,43,55,55,43,2,61,6,22,68,71,103,97,101,75,60,16,16,60,177,161,177,60,0,0,0,1,0,27,0,69,1,157,1,199,0,17,0,0,1,7,23,7,39,21,35,53,7,39,55,39,55,23,53,51,21,55,1, - 157,131,131,33,128,64,129,32,131,131,32,129,64,128,1,77,71,71,50,70,142,142,70,50,71,71,50,70,142,142,70,0,1,0,22,0,74,1,162,1,185,0,11,0,0,19,51,21,35,21,35,53,35,53,51,53,51,251, - 166,166,62,166,166,62,1,31,59,154,154,59,154,0,1,0,154,255,129,1,30,0,107,0,16,0,0,54,50,22,21,20,14,2,15,1,39,54,55,46,1,53,52,209,45,31,21,31,30,11,11,26,55,10,17,25,107,32,22,32, - 61,40,32,7,7,37,48,41,1,31,21,22,0,0,1,0,53,0,227,1,131,1,32,0,3,0,0,37,33,53,33,1,131,254,178,1,78,228,60,0,0,0,1,0,166,255,255,1,18,0,105,0,7,0,0,54,50,22,20,6,34,38,52,198,44,32, - 32,44,32,105,31,44,31,31,44,0,0,0,1,0,39,255,222,1,144,2,39,0,3,0,0,9,1,35,1,1,144,254,221,69,1,34,2,39,253,184,2,72,0,0,3,0,41,255,247,1,143,2,14,0,10,0,21,0,27,0,0,55,50,62,3,53, - 52,39,7,22,19,34,14,3,21,20,23,55,38,39,50,16,35,34,16,220,17,28,30,21,14,4,190,27,57,17,28,31,20,14,4,189,26,57,178,178,178,51,7,26,44,78,53,40,34,230,52,1,161,8,26,44,78,53,39,33, - 229,52,58,253,234,2,22,0,0,0,1,0,79,0,0,1,104,2,7,0,10,0,0,19,39,55,51,17,51,21,33,55,51,17,81,1,106,68,105,254,233,1,105,1,103,81,78,254,55,61,61,1,122,0,1,0,50,0,0,1,134,2,17,0,31, - 0,0,19,39,62,2,51,50,30,2,21,20,6,15,1,33,21,33,53,52,55,54,55,62,1,53,52,38,35,34,6,7,55,1,8,29,81,37,48,72,36,17,44,59,147,1,1,254,173,13,1,165,37,40,58,45,26,75,24,1,159,65,5,16, - 27,30,48,46,21,40,78,58,146,61,46,14,12,1,165,38,80,33,33,47,27,13,0,0,0,1,0,45,255,246,1,139,2,16,0,41,0,0,1,22,21,20,6,35,34,38,47,1,53,30,2,51,50,54,53,52,38,43,1,53,51,50,54,53, - 52,38,35,34,6,15,1,53,54,51,50,22,21,20,6,1,26,112,107,85,34,78,22,23,7,25,80,41,57,65,65,49,64,64,46,56,55,45,33,72,20,20,74,68,78,98,51,1,22,30,109,65,84,13,7,6,69,4,12,19,51,49, - 46,52,58,45,38,37,43,14,7,7,64,23,74,59,50,55,0,0,0,2,0,22,0,0,1,162,2,7,0,2,0,13,0,0,37,17,3,59,1,21,35,21,35,53,35,53,19,51,1,16,179,237,88,88,67,241,208,100,181,1,18,254,238,58, - 123,123,73,1,66,0,0,1,0,49,255,246,1,135,2,7,0,40,0,0,19,17,33,21,35,21,54,51,50,30,3,21,20,14,2,35,34,38,47,1,53,30,2,51,50,62,2,53,52,46,2,35,34,6,7,72,1,33,221,24,41,25,48,51,38, - 24,35,61,67,38,43,70,14,14,7,24,76,38,21,39,39,23,23,40,44,25,28,56,14,1,2,1,4,59,127,11,10,25,38,63,40,49,72,38,18,11,6,5,71,4,11,19,11,25,48,33,33,48,25,12,13,7,0,2,0,41,255,248, - 1,143,2,8,0,9,0,37,0,0,55,50,53,52,35,34,6,21,20,22,19,50,30,2,21,20,6,35,34,38,53,52,62,2,51,50,22,31,1,21,38,35,34,6,21,54,224,101,101,41,59,59,51,31,56,49,29,91,82,87,98,36,63,79, - 48,24,46,11,10,31,59,69,89,36,48,119,121,57,64,63,56,1,39,20,40,68,43,90,89,114,136,73,110,63,31,8,4,3,66,25,95,98,72,0,0,0,0,1,0,46,0,0,1,138,2,7,0,6,0,0,19,53,33,21,3,35,19,46,1, - 91,197,78,190,1,203,59,29,254,23,1,202,0,0,3,0,39,255,246,1,145,2,17,0,15,0,31,0,52,0,0,54,50,62,2,52,46,2,34,14,2,20,30,1,18,34,14,2,20,30,2,50,62,2,52,46,1,23,30,1,21,20,6,35,34, - 38,53,52,55,38,53,52,54,51,50,22,21,20,199,42,32,32,18,18,33,32,40,32,33,18,18,32,72,37,29,29,16,17,29,28,36,28,30,16,16,29,33,48,52,104,76,77,104,99,84,95,71,70,96,45,7,20,42,63,42, - 19,7,7,19,42,63,42,20,1,166,6,17,37,53,37,16,6,6,16,37,53,37,17,191,16,72,52,69,78,77,70,107,33,30,91,62,69,70,61,90,0,2,0,41,0,0,1,143,2,16,0,9,0,37,0,0,19,34,21,20,51,50,54,53,52, - 38,3,34,46,2,53,52,54,51,50,22,21,20,14,2,35,34,38,47,1,53,22,51,50,54,53,6,215,100,100,42,59,60,51,30,57,48,29,91,82,86,99,36,64,79,47,24,46,11,11,32,59,68,89,35,1,216,120,120,56, - 64,64,56,254,217,20,39,68,44,89,90,114,136,73,110,63,31,8,3,4,65,24,95,98,72,0,0,0,2,0,166,0,81,1,18,1,171,0,7,0,15,0,0,18,34,38,52,54,50,22,20,6,50,22,20,6,34,38,52,242,44,32,32,44, - 32,76,44,32,32,44,32,1,65,31,44,31,31,44,165,31,44,31,31,44,0,0,0,0,2,0,143,255,209,1,18,1,171,0,7,0,24,0,0,18,34,38,52,54,50,22,20,6,50,22,21,20,14,2,15,1,39,54,55,46,1,53,52,243, - 45,31,31,45,31,76,44,32,22,30,31,11,10,27,55,10,17,25,1,65,31,44,31,31,44,165,32,22,33,60,41,31,7,7,37,48,41,1,31,21,22,0,0,0,1,0,24,0,84,1,160,1,176,0,6,0,0,19,37,21,13,1,21,37,24, - 1,135,254,200,1,56,254,121,1,30,145,62,111,112,62,145,0,0,0,2,0,24,0,152,1,159,1,114,0,3,0,7,0,0,37,33,53,33,53,33,53,33,1,159,254,121,1,135,254,121,1,135,153,59,99,59,0,0,0,1,0,24, - 0,84,1,160,1,176,0,6,0,0,19,5,21,5,53,45,1,24,1,135,254,121,1,56,254,200,1,176,145,57,145,62,111,112,0,0,0,2,0,48,0,0,1,135,2,31,0,34,0,42,0,0,19,50,22,21,20,14,3,29,1,35,53,52,62, - 4,53,52,38,35,34,14,2,15,1,39,62,4,16,50,22,20,6,34,38,52,226,83,82,29,42,42,29,70,21,33,38,33,22,52,43,25,45,29,22,4,5,52,2,10,34,38,61,45,31,31,45,31,2,31,68,52,28,47,33,30,33,17, - 41,41,22,39,28,29,23,31,16,30,33,16,23,23,8,8,34,4,14,35,26,22,254,75,31,44,31,31,44,0,0,0,0,2,255,225,255,233,1,215,2,32,0,7,0,64,0,0,54,50,54,52,38,34,6,20,5,23,14,4,35,34,46,3,53, - 52,54,51,50,22,21,20,14,2,7,21,35,53,6,35,34,38,52,54,51,50,22,31,1,50,53,52,38,35,34,6,21,20,30,2,51,50,62,3,214,60,43,43,60,43,1,5,38,2,11,38,43,71,37,63,103,67,46,20,141,105,105, - 128,15,24,21,10,55,36,43,55,79,80,55,28,49,10,11,45,84,70,81,118,39,61,75,39,35,64,40,30,14,168,56,79,57,57,79,120,46,4,11,27,21,17,33,55,74,79,42,120,163,78,67,24,35,17,7,1,198,19, - 31,93,131,94,26,13,13,28,34,57,124,104,53,87,55,30,13,20,20,13,0,0,0,2,0,5,0,0,1,178,2,7,0,2,0,10,0,0,55,51,3,55,19,35,39,35,7,35,19,141,158,79,45,169,77,41,193,40,77,169,192,1,9,61, - 253,250,136,136,2,6,0,3,0,38,0,0,1,146,2,7,0,8,0,17,0,39,0,0,55,50,54,53,52,38,43,1,21,17,21,22,55,54,53,52,38,35,23,30,4,21,20,14,2,43,1,17,51,50,30,2,21,20,6,220,65,52,62,45,121, - 71,39,84,49,42,77,12,23,34,25,18,30,50,57,31,194,177,43,62,32,15,49,58,47,52,47,43,189,1,147,156,1,2,4,76,42,33,183,3,7,20,27,48,31,38,57,32,14,2,5,25,43,46,24,42,55,0,0,1,0,47,255, - 248,1,137,2,18,0,26,0,0,37,21,6,35,34,46,2,53,52,54,51,50,23,21,38,35,34,14,2,21,20,30,1,51,50,1,136,49,79,56,86,50,24,112,104,77,51,51,77,38,57,32,15,26,66,50,77,93,73,28,42,74,95, - 58,117,151,32,71,45,33,59,74,46,62,91,59,0,2,0,39,0,0,1,144,2,7,0,6,0,13,0,0,55,50,53,52,43,1,17,19,50,17,16,35,7,17,199,125,125,84,84,201,200,160,58,202,201,254,109,1,204,254,253, - 254,254,1,2,6,0,1,0,52,0,0,1,131,2,7,0,11,0,0,19,33,21,33,23,51,21,35,21,33,21,33,53,1,77,254,253,1,227,228,1,4,254,178,2,6,59,153,59,188,59,0,0,0,0,1,0,58,0,0,1,126,2,7,0,9,0,0,19, - 33,21,35,31,1,21,35,21,35,58,1,67,249,1,181,182,74,2,6,59,158,1,59,241,0,0,1,0,35,255,248,1,148,2,18,0,36,0,0,37,39,35,53,51,21,14,4,35,34,46,2,53,52,54,51,50,23,21,38,35,34,14,2,21, - 20,30,1,51,50,62,1,1,78,1,99,170,2,7,27,32,54,30,56,85,51,24,112,104,78,50,51,77,38,57,32,14,25,66,50,27,42,11,67,141,58,223,2,7,18,13,11,42,74,95,58,117,151,32,71,45,33,59,74,46,62, - 91,59,11,7,0,1,0,42,0,0,1,141,2,7,0,11,0,0,51,17,51,21,51,53,51,17,35,53,35,21,43,75,204,75,75,204,2,6,212,212,253,250,247,246,0,1,0,66,0,0,1,117,2,7,0,11,0,0,19,53,33,21,35,17,51, - 21,5,53,55,17,67,1,50,116,116,254,206,115,1,203,59,59,254,112,58,1,57,1,1,145,0,0,0,1,0,65,255,249,1,118,2,7,0,13,0,0,19,51,17,20,6,35,7,53,51,50,54,53,17,35,158,216,66,78,164,147, - 48,37,140,2,6,254,158,80,90,1,57,48,58,1,47,0,0,0,0,1,0,19,0,0,1,165,2,7,0,11,0,0,51,17,51,21,55,51,7,19,35,3,7,21,19,75,233,85,212,221,90,180,57,2,6,230,230,212,254,206,1,4,57,202, - 0,0,0,1,0,49,0,0,1,135,2,7,0,5,0,0,55,17,51,17,33,21,49,75,1,10,1,2,5,254,53,58,0,0,0,1,0,19,0,0,1,164,2,7,0,12,0,0,51,17,51,23,55,51,17,7,17,3,35,3,17,20,100,99,101,100,65,107,57, - 106,2,6,254,254,253,251,1,1,197,254,239,1,19,254,58,0,0,1,0,41,0,0,1,142,2,7,0,9,0,0,51,3,51,19,17,51,17,35,3,17,45,3,98,186,72,95,186,2,6,254,90,1,166,253,250,1,166,254,90,0,0,2,0, - 35,255,250,1,149,2,18,0,5,0,25,0,0,19,50,16,35,34,16,18,50,62,3,52,46,3,34,14,3,20,30,2,220,184,184,184,167,34,27,30,20,13,13,20,30,27,34,27,30,20,14,14,20,30,2,17,253,234,2,22,254, - 37,8,26,43,78,106,78,44,26,8,8,26,44,78,106,78,43,26,0,0,0,2,0,44,255,255,1,139,2,7,0,12,0,30,0,0,19,50,62,2,53,52,46,2,43,1,21,55,50,22,21,20,6,43,1,28,1,30,1,28,1,49,35,17,50,206, - 32,46,22,10,10,21,42,30,93,99,85,91,85,84,108,1,1,75,174,1,10,19,31,31,17,17,31,31,18,195,252,80,70,71,89,5,21,55,48,50,29,2,6,0,0,0,0,2,0,13,255,184,1,171,2,15,0,12,0,32,0,0,19,50, - 17,20,7,23,21,35,39,6,35,34,16,18,50,62,3,52,46,3,34,14,3,20,30,2,198,184,40,84,48,82,40,58,184,167,34,27,30,20,13,13,20,30,27,34,27,30,20,14,14,20,30,2,14,254,245,123,67,97,44,91, - 27,2,22,254,37,8,26,43,78,106,78,44,26,8,8,26,44,78,106,78,43,26,0,2,0,38,0,0,1,145,2,7,0,9,0,24,0,0,19,35,21,22,55,62,1,53,52,38,15,1,35,17,51,50,22,21,20,6,7,23,35,39,38,213,99,68, - 39,34,51,53,139,3,72,179,79,83,57,44,122,79,111,97,1,205,184,1,2,2,46,45,43,47,242,218,2,5,89,69,45,69,16,229,217,1,0,0,0,1,0,42,255,246,1,141,2,17,0,54,0,0,1,21,46,2,35,34,6,21,20, - 30,7,23,30,3,21,20,6,35,34,38,47,1,53,30,2,51,50,54,53,52,38,39,46,3,53,52,54,51,50,30,2,23,1,109,6,21,67,35,62,61,6,14,11,25,12,31,9,33,1,23,42,48,29,101,89,43,78,18,18,7,27,86,45, - 45,66,61,69,34,48,47,24,103,87,18,40,32,27,8,1,245,71,4,13,21,41,48,11,18,15,11,10,5,7,3,5,1,4,17,33,58,39,78,74,16,9,8,73,5,16,27,46,45,46,37,14,6,17,31,50,34,72,82,5,8,9,2,0,0,0, - 1,0,9,0,0,1,175,2,7,0,7,0,0,19,53,33,21,35,17,7,17,10,1,164,172,75,1,203,59,59,254,54,1,1,203,0,1,0,37,255,246,1,147,2,7,0,24,0,0,55,17,51,17,20,30,2,51,50,54,53,17,51,17,20,14,3,34, - 46,3,37,76,6,19,43,32,67,48,75,6,22,38,68,95,70,38,22,7,166,1,96,254,153,26,35,34,18,54,67,1,95,254,173,33,48,53,33,22,21,32,50,44,0,1,0,13,0,0,1,171,2,7,0,6,0,0,51,3,51,27,1,51,3, - 174,161,73,134,134,72,161,2,6,254,58,1,198,253,250,0,1,255,249,0,0,1,190,2,7,0,12,0,0,51,3,51,27,1,51,27,1,51,3,35,11,1,75,81,63,58,63,83,64,57,64,81,73,72,73,2,6,254,99,1,157,254, - 98,1,158,253,250,1,184,254,72,0,1,255,255,0,0,1,185,2,7,0,11,0,0,19,39,51,23,55,51,7,19,35,39,7,35,184,160,80,121,123,81,165,177,80,141,141,80,1,19,243,195,195,243,254,237,218,218, - 0,1,0,5,0,0,1,178,2,7,0,8,0,0,55,3,51,23,55,51,3,21,35,182,176,79,135,134,80,177,75,234,1,28,228,228,254,227,233,0,0,1,0,33,0,0,1,151,2,7,0,9,0,0,19,53,33,21,1,33,21,5,53,1,41,1,102, - 254,224,1,40,254,138,1,24,1,203,59,53,254,106,58,1,56,1,147,0,0,0,1,0,104,255,189,1,80,2,73,0,7,0,0,1,39,17,51,21,35,17,51,1,79,162,162,231,231,2,18,1,253,226,56,2,140,0,1,0,39,255, - 222,1,144,2,39,0,3,0,0,19,1,35,1,109,1,35,70,254,222,2,39,253,184,2,72,0,0,0,1,0,104,255,189,1,80,2,73,0,7,0,0,19,51,17,35,53,51,17,7,104,231,231,163,163,2,73,253,116,56,2,30,1,0,0, - 1,0,37,1,63,1,147,2,7,0,6,0,0,19,23,35,39,7,35,55,252,150,82,100,101,82,150,2,6,198,141,141,198,0,0,0,1,255,241,255,190,1,199,255,247,0,3,0,0,5,33,53,33,1,198,254,44,1,212,66,56,0, - 0,0,1,0,124,1,160,1,60,2,57,0,3,0,0,19,23,35,39,207,108,82,109,2,57,153,153,0,0,0,2,0,48,255,246,1,136,1,143,0,17,0,54,0,0,55,50,62,3,53,34,35,38,14,4,21,20,22,39,52,62,3,23,48,60, - 1,46,6,35,7,53,50,54,51,21,50,30,2,21,7,35,54,39,6,35,34,38,204,32,48,23,13,2,10,21,24,45,39,32,22,13,51,118,28,50,69,81,45,2,3,7,9,15,18,26,16,122,18,58,34,38,58,52,29,1,61,2,2,38, - 99,64,79,44,26,33,49,27,17,1,2,3,10,18,28,20,37,35,72,36,51,28,16,1,1,14,7,17,10,16,10,12,7,5,2,54,2,1,12,33,65,47,241,25,27,61,63,0,0,2,0,50,255,247,1,134,2,49,0,9,0,30,0,0,54,50, - 54,53,52,38,34,6,21,20,39,62,4,51,50,22,21,20,6,35,34,38,47,1,7,35,17,51,172,112,50,51,110,52,3,1,5,18,23,42,25,71,87,88,59,32,62,16,15,7,61,68,45,82,68,67,83,83,67,68,212,3,8,20,16, - 12,102,101,98,106,29,15,15,49,2,47,0,1,0,59,255,247,1,125,1,143,0,20,0,0,1,34,6,21,20,22,51,50,55,21,6,35,34,38,52,54,51,50,23,21,38,1,13,65,72,72,65,62,49,47,78,85,110,110,85,78,47, - 49,1,89,74,76,76,74,43,65,32,106,196,106,32,65,43,0,0,2,0,50,255,247,1,134,2,49,0,7,0,30,0,0,54,50,53,52,38,34,6,21,19,51,17,35,39,14,4,35,34,38,53,52,54,51,50,30,2,31,1,122,200,48, - 104,48,200,68,62,6,3,8,26,27,41,20,59,88,87,70,25,42,24,17,3,4,45,150,67,83,83,67,1,109,253,209,49,3,7,21,15,13,106,98,101,102,12,17,17,6,7,0,0,0,0,2,0,37,255,247,1,147,1,143,0,5,0, - 26,0,0,19,34,6,21,51,52,7,20,22,51,50,54,55,21,6,35,34,38,53,52,54,51,50,22,29,1,32,227,47,69,224,227,62,67,42,62,46,70,82,89,109,105,79,91,90,254,218,1,89,68,48,116,165,56,79,18,21, - 64,29,109,95,93,110,97,73,48,0,0,0,1,0,40,0,3,1,144,2,36,0,19,0,0,1,34,6,29,1,51,21,35,17,35,17,35,53,51,53,52,54,59,1,21,1,40,35,31,125,125,68,122,122,65,64,108,1,237,25,37,75,57, - 254,217,1,39,57,52,78,62,55,0,0,0,0,2,0,50,255,70,1,134,1,143,0,9,0,39,0,0,55,50,53,52,35,34,6,21,20,22,19,51,17,20,6,43,1,53,51,50,62,2,61,1,14,4,35,34,38,53,52,54,51,50,22,23,222, - 99,99,53,51,51,159,61,90,81,130,136,28,42,23,10,1,5,18,24,42,25,71,91,91,60,48,52,28,53,142,150,82,68,65,77,1,80,254,110,86,86,58,22,36,37,18,59,2,6,16,12,10,101,100,98,101,20,29,0, - 0,1,0,62,0,1,1,122,2,49,0,18,0,0,19,50,22,21,17,35,53,52,38,35,34,6,29,1,35,17,51,21,54,253,53,72,68,40,37,47,56,68,68,37,1,146,78,67,255,0,250,45,48,61,59,223,2,47,218,60,0,2,0,139, - 0,1,1,45,2,30,0,11,0,17,0,0,1,35,34,61,1,52,59,1,50,29,1,20,7,53,51,17,35,17,1,35,56,10,10,56,9,161,161,68,1,202,10,64,9,9,64,10,127,59,254,123,1,74,0,0,0,2,0,100,255,70,1,84,2,30, - 0,12,0,24,0,0,19,53,51,17,20,43,1,53,51,50,54,53,17,55,35,34,61,1,52,59,1,50,29,1,20,165,174,127,112,105,29,37,59,56,10,10,56,9,1,76,58,254,98,161,59,52,50,1,100,126,10,64,9,9,64,10, - 0,1,0,41,0,2,1,142,2,30,0,11,0,0,55,23,35,39,7,21,35,17,51,17,55,51,210,188,81,154,51,70,70,181,80,245,243,201,45,156,2,27,254,201,161,0,0,0,0,1,0,133,0,1,1,51,2,8,0,5,0,0,19,51,17, - 35,17,35,133,173,69,104,2,7,253,250,1,202,0,0,0,1,0,20,255,254,1,164,1,143,0,30,0,0,1,50,22,21,17,35,17,52,35,34,6,7,17,35,17,52,35,34,6,7,17,35,17,51,21,54,51,50,23,62,1,1,68,43,52, - 61,52,26,26,3,61,52,26,26,3,62,62,31,42,52,26,13,48,1,143,69,53,254,234,1,5,84,34,37,254,238,1,5,84,33,36,254,236,1,133,18,29,49,22,27,0,0,0,1,0,62,0,1,1,122,1,147,0,18,0,0,19,50,22, - 21,17,35,53,52,38,35,34,6,29,1,35,17,51,23,54,253,53,72,68,40,37,47,56,68,64,4,37,1,146,78,67,255,0,250,45,48,61,59,223,1,133,48,60,0,0,0,0,2,0,42,255,247,1,141,1,144,0,9,0,17,0,0, - 54,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53,52,174,92,58,59,90,59,21,166,94,254,158,44,72,80,80,70,70,80,80,1,28,102,102,205,205,102,0,2,0,50,255,78,1,134,1,136,0,7,0,30,0,0, - 54,50,54,53,52,34,21,20,19,50,22,21,20,6,35,34,46,2,47,1,21,35,17,51,23,62,4,176,103,48,199,107,66,89,87,71,25,41,24,18,3,3,68,61,7,1,6,20,25,41,38,82,67,148,148,67,1,16,105,99,101, - 103,12,18,17,6,6,221,2,48,49,2,8,20,16,13,0,2,0,50,255,78,1,134,1,136,0,7,0,30,0,0,54,50,54,53,52,34,21,20,19,51,17,35,53,14,4,35,34,38,53,52,54,51,50,30,2,31,1,160,104,48,200,216, - 62,68,1,5,18,24,42,25,70,87,89,66,23,41,26,19,4,4,38,82,67,148,148,67,1,6,253,208,221,2,8,21,15,13,103,101,99,105,12,18,17,6,6,0,0,1,0,69,0,0,1,115,1,142,0,19,0,0,1,50,22,31,1,21,46, - 2,35,34,6,29,1,35,17,51,7,62,1,1,12,29,52,11,11,4,16,56,31,56,71,68,68,2,17,69,1,142,15,7,8,65,5,12,20,60,35,245,1,133,53,27,35,0,0,1,0,69,255,254,1,115,1,151,0,38,0,0,55,30,1,54,53, - 52,39,46,1,53,52,62,2,51,50,22,31,1,21,46,2,35,34,21,20,22,23,30,1,21,20,6,35,34,38,47,1,69,53,109,71,91,83,57,14,32,65,44,33,62,14,15,6,19,63,33,90,36,57,70,69,88,73,31,70,20,20,88, - 27,14,32,35,49,15,15,53,44,22,38,36,20,11,6,6,62,4,11,17,57,25,29,8,11,46,55,57,66,12,6,6,0,0,0,1,0,87,0,6,1,97,2,4,0,17,0,0,55,51,21,35,34,46,3,53,17,51,21,51,21,35,21,20,216,136, - 125,25,33,41,24,16,68,162,162,65,58,3,15,26,50,34,1,124,118,58,204,70,0,0,0,1,0,54,255,246,1,130,1,133,0,21,0,0,55,53,51,21,20,51,50,54,53,55,51,19,35,53,14,4,35,34,38,54,68,86,44, - 62,3,68,1,64,1,3,17,23,45,27,79,73,145,244,241,102,53,39,251,254,124,42,2,7,19,13,12,74,0,0,0,1,0,29,0,0,1,155,1,133,0,6,0,0,1,51,3,35,3,51,19,1,84,70,148,86,147,71,120,1,133,254,123, - 1,133,254,186,0,0,0,0,1,255,248,255,255,1,192,1,133,0,12,0,0,1,51,3,35,39,7,35,3,51,19,55,51,23,1,124,67,97,63,68,65,65,97,68,68,53,76,60,1,133,254,123,215,215,1,133,254,208,192,192, - 0,0,0,0,1,0,20,255,255,1,163,1,133,0,11,0,0,37,23,35,39,7,35,55,39,51,23,55,51,1,1,162,78,122,120,78,162,149,76,110,109,76,203,203,155,155,204,185,141,141,0,0,1,0,47,255,68,1,137,1, - 134,0,31,0,0,1,18,21,20,14,2,43,1,53,51,50,62,4,53,52,53,35,34,38,53,19,51,21,20,22,51,23,3,1,134,3,12,24,47,32,195,176,16,23,13,8,3,1,133,71,72,1,68,29,41,137,1,1,133,254,135,48,17, - 47,52,36,59,12,24,22,34,17,14,4,2,78,49,1,6,229,49,50,1,1,73,0,0,0,1,0,64,255,255,1,119,1,134,0,14,0,0,55,51,23,33,53,62,3,39,35,53,33,21,2,137,237,1,254,202,15,50,105,69,1,229,1,45, - 238,52,52,59,17,58,122,82,1,50,60,254,235,0,0,0,0,1,0,63,255,178,1,120,2,84,0,41,0,0,1,21,20,7,22,29,1,20,22,59,1,21,34,35,34,46,3,61,1,52,38,43,1,53,51,50,54,61,1,52,62,3,59,1,21, - 35,34,6,1,11,72,72,38,42,29,31,13,38,54,27,14,3,38,43,51,51,43,38,3,14,27,54,38,44,29,42,38,1,215,100,95,17,17,96,99,34,29,62,20,26,44,30,23,86,43,32,66,32,42,87,23,30,44,26,19,62, - 29,0,0,1,0,188,255,200,0,252,2,63,0,3,0,0,23,35,17,51,252,64,64,55,2,117,0,1,0,63,255,178,1,120,2,84,0,41,0,0,19,53,52,38,43,1,53,50,51,50,30,3,29,1,20,22,59,1,21,35,34,6,29,1,20,14, - 3,43,1,53,51,50,54,61,1,52,55,38,172,37,42,29,30,14,37,54,27,15,2,38,44,51,51,44,38,2,15,27,54,37,44,29,42,37,72,72,1,115,100,33,29,62,19,26,44,30,23,87,42,32,66,32,43,86,24,29,44, - 26,20,62,29,33,100,96,17,16,0,0,0,1,0,22,0,177,1,161,1,93,0,33,0,0,1,23,14,4,35,34,46,3,7,14,1,15,1,39,62,4,51,50,30,3,55,62,1,55,1,103,58,5,5,17,21,40,25,25,43,30,28,31,16,20,25,3, - 3,58,5,5,17,21,40,25,25,43,30,28,31,16,20,25,3,1,66,13,21,21,45,24,20,26,35,36,21,2,3,45,21,21,13,21,22,44,24,21,26,36,35,22,3,3,45,20,0,3,0,21,0,0,1,163,0,106,0,15,0,31,0,47,0,0,55, - 50,22,29,1,20,6,43,1,34,38,61,1,52,54,59,1,50,22,29,1,20,6,43,1,34,38,61,1,52,54,59,1,50,22,29,1,20,6,43,1,34,38,61,1,52,54,51,104,5,7,7,5,71,4,8,8,4,222,5,7,7,5,70,5,7,7,5,221,5,7, - 7,5,70,5,7,7,5,105,7,5,81,5,7,7,5,81,5,7,7,5,81,5,7,7,5,81,5,7,7,5,81,5,7,7,5,81,5,7,0,0,2,0,159,255,235,1,25,2,9,0,7,0,13,0,0,18,34,38,52,54,50,22,20,7,51,23,7,35,53,245,50,35,35, - 50,35,84,46,29,1,101,1,145,35,49,35,35,49,105,196,155,155,0,2,0,63,255,147,1,121,1,242,0,5,0,28,0,0,55,17,14,1,21,20,19,17,54,55,21,6,7,21,35,53,46,1,53,52,54,55,53,51,21,22,23,21, - 38,243,50,58,146,57,39,45,51,38,78,102,100,80,38,61,35,40,49,1,38,6,73,67,134,1,25,254,215,2,25,59,21,3,100,101,6,107,92,95,104,4,97,98,5,20,60,25,0,1,0,40,255,255,1,144,2,16,0,27, - 0,0,55,51,21,33,53,51,53,35,53,51,53,52,54,51,50,22,31,1,21,38,35,34,6,29,1,51,21,35,202,197,254,153,87,73,73,82,79,33,52,9,10,48,42,50,50,136,136,59,59,59,161,50,82,88,88,10,5,5,64, - 30,53,63,88,50,0,0,0,2,0,55,0,63,1,128,1,125,0,7,0,31,0,0,54,50,54,52,38,34,6,20,54,20,7,23,7,39,6,34,39,7,39,55,38,52,55,39,55,23,54,50,23,55,23,7,187,65,46,46,65,46,204,22,60,34, - 62,31,73,31,62,34,60,22,22,60,34,62,31,73,31,62,34,60,148,44,61,43,43,61,67,73,30,57,35,60,19,19,60,35,57,30,73,30,57,35,60,19,19,60,35,57,0,1,0,5,0,0,1,178,2,7,0,24,0,0,1,7,51,21, - 35,7,21,51,21,35,21,35,53,35,53,51,53,39,35,53,51,39,51,23,55,1,178,120,91,115,33,148,148,75,148,148,33,115,91,119,79,135,134,2,6,194,39,53,11,39,182,182,39,11,53,39,194,228,228,0, - 0,0,0,2,0,188,255,206,0,252,2,57,0,3,0,7,0,0,23,35,17,51,53,35,17,51,252,64,64,64,64,50,1,8,92,1,7,0,0,2,0,64,255,188,1,119,2,16,0,15,0,75,0,0,37,62,1,53,52,38,39,38,39,14,1,21,20, - 22,23,22,23,30,1,21,20,6,35,34,38,47,1,53,22,51,50,54,53,52,38,39,38,39,46,4,53,52,54,55,46,1,53,52,54,51,50,22,31,1,21,38,35,34,6,21,20,22,23,22,23,30,4,21,20,6,1,10,21,28,48,46,25, - 22,22,27,48,45,25,61,25,21,69,72,25,57,16,16,58,51,36,42,37,47,8,3,28,25,39,17,14,38,33,25,21,68,74,24,54,14,14,51,51,37,40,36,47,8,3,29,24,39,17,14,38,142,12,35,15,26,44,25,14,13, - 12,36,15,26,44,25,14,37,18,34,23,44,66,10,5,5,57,26,32,25,20,30,26,4,2,16,14,28,23,34,19,28,50,16,18,34,24,43,59,10,5,5,57,27,26,25,20,30,26,4,2,15,15,28,23,33,20,28,50,0,0,0,0,2,0, - 109,1,212,1,75,2,27,0,11,0,23,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,1,66,58,9,9,58,9,155,58,9,9,58,8,1,213,9,52,9,9,52,9,9,52,9,9,52,9,0,0,3,255,248,0, - 40,1,192,1,218,0,7,0,15,0,36,0,0,54,50,54,52,38,34,6,20,18,50,22,20,6,34,38,52,22,52,54,51,50,23,21,38,35,34,6,21,20,22,51,50,55,21,6,35,34,142,156,111,111,156,111,95,188,133,133,188, - 134,92,78,62,57,30,43,34,47,52,52,47,46,31,36,51,61,79,105,147,105,105,147,1,34,127,179,127,127,179,152,126,66,15,38,21,48,49,49,47,18,36,17,0,0,0,0,3,0,92,0,162,1,91,2,18,0,3,0,18, - 0,53,0,0,37,35,53,51,39,34,35,34,14,4,21,20,22,51,50,54,7,52,62,2,23,60,1,46,2,35,34,6,15,1,53,62,6,51,50,22,29,1,35,39,6,35,34,38,1,91,247,247,55,5,8,25,24,37,19,20,8,36,22,49,41, - 201,37,58,70,33,8,15,32,22,26,50,11,12,2,18,7,17,12,17,18,9,57,73,45,8,39,54,47,59,163,43,178,1,3,6,11,18,13,24,24,61,16,33,43,14,7,4,8,10,22,14,11,11,6,6,44,1,6,2,6,2,3,1,57,64,159, - 38,45,44,0,2,0,50,0,49,1,134,1,112,0,6,0,13,0,0,1,21,7,23,21,39,53,55,7,23,21,39,53,55,1,134,112,112,174,7,111,111,173,173,1,112,67,93,93,66,145,28,79,93,93,66,145,28,146,0,0,4,255, - 248,0,40,1,192,1,218,0,9,0,27,0,35,0,43,0,0,19,22,62,2,53,52,38,43,1,23,30,1,23,35,38,39,38,43,1,21,35,53,51,50,21,20,14,1,50,54,52,38,34,6,20,18,50,22,20,6,34,38,52,175,21,36,27,15, - 29,21,49,86,14,25,46,52,30,17,21,24,27,47,92,103,34,147,156,111,111,156,111,95,188,133,133,188,134,1,13,1,2,6,18,15,19,20,102,5,33,72,44,26,33,103,242,74,21,32,172,105,147,105,105, - 147,1,34,127,179,127,127,179,0,0,1,0,109,1,183,1,75,1,235,0,3,0,0,1,35,53,51,1,74,220,220,1,183,51,0,0,0,0,2,0,101,1,50,1,82,2,16,0,7,0,15,0,0,18,50,54,52,38,34,6,20,54,50,22,20,6, - 34,38,52,190,59,42,42,59,41,22,98,69,69,98,69,1,94,39,55,39,39,55,138,65,91,65,65,91,0,0,0,0,2,0,24,255,255,1,159,1,151,0,11,0,15,0,0,19,51,21,35,21,35,53,35,53,51,53,51,19,33,53,33, - 251,164,164,62,165,165,62,164,254,121,1,135,1,36,59,115,115,59,114,254,105,59,0,0,0,1,0,115,1,133,1,69,2,173,0,24,0,0,1,20,14,1,7,51,21,35,53,54,55,54,53,52,38,35,34,6,15,1,53,54,51, - 50,22,1,66,17,62,70,152,210,77,32,42,37,28,17,42,12,13,39,51,57,58,2,94,20,33,64,61,39,38,72,29,40,36,18,25,11,6,6,41,20,51,0,0,1,0,109,1,130,1,75,2,176,0,39,0,0,1,20,6,35,34,38,47, - 1,53,22,51,50,54,53,52,38,43,1,53,51,50,54,53,52,38,35,34,6,15,1,53,54,51,50,22,21,20,6,7,22,1,75,68,55,21,49,15,14,50,42,26,48,43,31,31,31,29,36,30,27,21,44,12,12,47,44,49,63,33,30, - 71,1,214,37,47,7,4,4,42,18,26,25,25,27,38,22,21,18,22,8,4,4,42,13,42,33,28,29,7,13,0,0,0,1,0,131,1,181,1,53,2,57,0,3,0,0,19,51,7,35,235,73,120,56,2,57,131,0,0,0,0,1,0,37,255,107,1, - 146,1,132,0,36,0,0,37,50,54,63,1,21,6,35,34,38,47,1,14,4,35,34,38,39,21,35,17,51,21,20,22,51,50,54,53,55,51,16,21,20,1,120,7,12,4,3,27,29,19,26,4,3,1,4,16,22,42,27,26,47,11,60,64,45, - 37,43,59,3,65,49,4,2,2,52,15,26,13,13,2,7,18,14,11,28,26,192,2,24,241,48,53,53,38,251,254,226,24,29,0,0,0,1,0,48,255,185,1,136,2,7,0,16,0,0,19,51,17,35,17,35,16,21,6,34,47,1,17,34, - 38,52,54,216,175,52,70,1,26,13,13,69,99,99,2,6,253,182,2,32,253,229,5,2,1,1,1,39,85,121,85,0,0,1,0,159,0,198,1,25,1,63,0,7,0,0,18,50,22,20,6,34,38,52,195,50,35,35,50,35,1,63,35,50, - 35,35,50,0,0,1,0,143,255,119,1,41,0,1,0,16,0,0,33,22,21,20,35,34,38,47,1,53,22,51,50,39,48,58,1,1,0,40,91,14,31,8,8,24,27,91,73,21,22,41,37,59,4,2,2,46,11,94,0,0,0,1,0,114,1,132,1, - 70,2,167,0,10,0,0,19,51,21,35,53,51,53,7,53,55,51,250,75,204,76,83,85,51,1,171,38,38,212,14,40,13,0,3,0,83,0,162,1,101,2,16,0,3,0,13,0,21,0,0,37,35,53,51,2,34,6,21,20,22,50,54,53,52, - 22,32,53,52,54,50,22,21,1,86,249,249,88,69,46,45,71,45,56,254,239,73,127,73,163,43,1,25,47,54,54,49,49,54,54,197,143,71,71,71,71,0,0,0,0,2,0,50,0,49,1,134,1,112,0,6,0,13,0,0,55,21, - 7,53,55,39,53,51,23,21,7,53,55,39,223,173,111,111,166,174,174,112,112,222,28,145,66,93,93,67,146,28,145,66,93,93,0,4,0,19,255,162,1,165,2,64,0,3,0,6,0,17,0,28,0,0,1,23,5,39,23,51,53, - 55,21,51,21,35,21,35,53,35,53,55,3,7,53,55,51,21,51,21,35,53,51,1,155,9,254,120,9,198,102,51,43,43,50,144,134,187,82,87,48,75,203,75,1,47,37,91,37,203,144,43,188,37,65,65,42,183,1, - 86,14,39,13,252,39,39,0,3,0,19,255,162,1,165,2,64,0,3,0,28,0,39,0,0,1,23,5,39,5,7,51,21,35,53,54,55,54,53,52,38,35,34,6,15,1,39,54,51,50,22,21,20,6,1,7,53,55,51,21,51,21,35,53,51,1, - 155,9,254,120,9,1,73,86,152,210,77,32,42,37,28,17,41,13,12,1,39,51,57,59,28,254,252,82,87,48,75,203,75,1,47,37,91,37,190,77,39,39,71,30,39,36,19,25,12,6,6,42,19,51,27,23,45,1,226,14, - 39,13,252,39,39,0,4,0,18,255,162,1,165,2,70,0,3,0,6,0,17,0,56,0,0,1,23,5,39,23,51,39,55,21,51,21,35,21,35,53,35,53,55,39,20,6,35,34,38,47,1,53,22,51,50,54,52,38,43,1,53,51,50,54,53, - 52,38,35,34,6,15,1,53,54,51,50,22,21,20,6,7,22,1,155,9,254,120,9,202,102,1,51,43,43,49,145,134,45,72,55,21,48,13,13,41,46,36,42,38,34,33,30,31,37,33,25,24,45,10,10,46,44,50,62,33,30, - 72,1,47,37,91,37,203,144,43,188,37,65,65,42,183,168,36,47,7,4,4,41,18,29,47,28,37,23,21,20,20,8,4,4,42,12,41,32,29,29,8,14,0,0,2,0,73,255,247,1,111,2,27,0,30,0,38,0,0,55,50,54,63,1, - 21,14,2,35,34,38,53,52,62,4,61,1,51,21,20,14,3,21,20,22,18,34,38,52,54,50,22,20,235,29,66,18,19,7,24,69,34,82,78,19,29,34,29,19,71,26,37,38,26,47,71,44,32,32,44,32,48,24,11,12,65,5, - 12,21,65,54,24,43,30,30,24,31,17,69,61,30,48,34,31,39,21,31,36,1,129,31,44,31,31,44,0,0,3,0,5,0,0,1,179,2,131,0,3,0,6,0,14,0,0,1,35,39,51,3,51,3,55,19,35,39,35,7,35,19,1,9,56,84,68, - 52,158,79,45,169,77,41,193,40,77,169,2,38,92,254,61,1,10,61,253,250,135,135,2,6,0,0,3,0,5,0,0,1,179,2,131,0,3,0,6,0,14,0,0,1,7,35,55,3,51,3,55,19,35,39,35,7,35,19,1,59,84,56,72,106, - 158,79,45,169,77,40,193,41,77,169,2,130,92,92,254,61,1,10,61,253,250,135,135,2,6,0,3,0,5,255,255,1,179,2,131,0,6,0,9,0,17,0,0,19,7,35,55,51,23,35,3,51,3,55,19,35,39,35,7,35,19,220, - 61,51,78,69,78,51,141,158,79,45,169,77,40,193,41,77,169,2,101,62,92,92,254,151,1,10,61,253,250,135,135,2,6,0,0,0,3,0,5,255,254,1,179,2,123,0,20,0,23,0,31,0,0,19,34,6,21,35,52,54,51, - 50,22,51,50,54,53,55,51,20,6,35,34,38,3,51,3,55,19,35,39,35,7,35,19,169,12,12,47,36,34,26,62,15,11,13,1,46,34,36,28,58,45,158,79,45,169,77,40,193,41,77,169,2,81,19,16,33,43,34,17,9, - 8,25,51,35,254,109,1,10,61,253,250,135,135,2,6,0,0,0,4,0,5,255,255,1,179,2,131,0,2,0,10,0,22,0,34,0,0,55,51,3,55,19,35,39,35,7,35,19,55,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52, - 59,1,50,29,1,20,141,158,79,45,169,77,40,193,41,77,169,147,58,9,9,58,9,155,58,9,9,58,9,190,1,10,61,253,250,135,135,2,6,56,9,52,9,9,52,9,9,52,9,9,52,9,0,0,0,0,3,0,5,255,254,1,179,2,149, - 0,2,0,14,0,30,0,0,55,51,3,39,20,22,23,51,62,1,53,52,38,34,6,23,19,35,39,35,7,35,19,38,53,52,54,50,22,21,20,141,158,79,56,18,16,44,16,19,33,47,34,112,159,77,40,193,41,77,159,47,60,84, - 60,190,1,10,110,17,26,6,6,26,17,21,31,31,101,254,25,135,135,1,231,28,51,40,55,55,40,51,0,2,0,2,255,255,1,182,2,7,0,3,0,19,0,0,55,17,35,3,55,21,51,21,35,53,35,7,35,19,37,7,35,23,55, - 7,235,37,75,186,128,202,127,37,68,150,1,23,1,122,1,111,1,190,1,13,254,244,55,188,59,134,133,2,5,2,61,153,1,60,0,0,0,1,0,47,255,119,1,137,2,16,0,40,0,0,1,34,14,2,21,20,30,1,51,50,55, - 21,6,7,22,21,20,6,35,34,39,53,22,51,50,53,52,39,46,3,53,52,54,51,50,23,21,38,1,8,38,57,32,14,25,66,50,77,51,37,56,33,45,38,45,25,24,31,46,26,54,81,48,23,112,104,77,51,51,1,213,32,60, - 74,46,62,91,59,46,73,21,5,36,32,31,30,9,45,11,31,22,32,3,42,74,93,56,117,151,32,71,45,0,2,0,52,0,3,1,132,2,135,0,11,0,15,0,0,55,33,21,33,17,33,21,35,31,1,21,35,19,35,39,51,127,1,4, - 254,178,1,71,253,1,241,242,142,57,84,68,63,59,2,6,59,153,1,59,1,48,93,0,0,0,2,0,52,0,4,1,132,2,135,0,11,0,15,0,0,55,33,21,33,17,33,21,35,31,1,21,35,19,7,35,55,127,1,4,254,178,1,71, - 253,1,241,242,173,84,56,72,64,59,2,6,59,153,1,59,1,140,93,93,0,0,2,0,52,0,4,1,132,2,136,0,11,0,18,0,0,55,33,21,33,17,33,21,35,31,1,21,35,19,7,35,55,51,23,35,127,1,4,254,178,1,71,253, - 1,241,242,86,61,52,78,70,78,52,64,59,2,6,59,153,1,59,1,110,62,93,93,0,0,0,3,0,52,0,0,1,132,2,133,0,11,0,23,0,35,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20, - 3,33,21,33,17,33,21,35,23,51,21,35,1,66,58,9,9,58,9,155,58,9,9,58,9,58,1,4,254,178,1,71,253,1,241,242,2,63,8,52,9,9,52,8,8,52,9,9,52,8,253,252,59,2,6,59,153,59,0,2,0,66,255,254,1,118, - 2,131,0,11,0,15,0,0,1,35,17,23,21,33,53,51,17,35,53,33,39,35,39,51,1,117,115,115,254,206,116,116,1,50,106,56,84,68,1,202,254,111,1,57,59,1,144,59,33,92,0,0,0,2,0,66,0,3,1,118,2,135, - 0,11,0,15,0,0,1,35,17,51,21,33,53,51,17,39,53,33,39,7,35,55,1,117,116,116,254,206,115,115,1,50,60,84,56,72,1,207,254,112,59,57,1,145,1,59,125,93,93,0,0,2,0,66,0,3,1,118,2,136,0,11, - 0,18,0,0,1,35,17,51,21,33,53,51,17,39,53,33,39,7,35,55,51,23,35,1,117,116,116,254,206,115,115,1,50,148,61,52,78,70,78,52,1,207,254,112,59,57,1,145,1,59,95,62,93,93,0,0,0,3,0,66,255, - 254,1,118,2,131,0,11,0,23,0,35,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,23,35,17,51,21,33,53,55,17,35,53,33,1,66,58,9,9,58,9,155,58,9,9,58,9,188,116,116, - 254,206,115,115,1,50,2,61,9,52,9,9,52,9,9,52,9,9,52,9,115,254,112,59,57,1,1,145,59,0,0,2,0,17,0,4,1,167,2,11,0,18,0,37,0,0,55,50,62,3,52,46,3,43,1,21,51,21,35,21,50,19,50,30,3,20,14, - 3,43,1,53,35,53,51,53,50,200,19,36,42,30,20,20,30,42,36,19,62,99,99,62,1,31,56,61,45,29,29,45,61,56,30,139,46,46,138,62,9,27,42,75,98,75,42,27,8,162,53,188,1,205,12,35,55,95,125,96, - 54,35,11,245,53,220,0,0,2,0,42,0,0,1,142,2,130,0,20,0,30,0,0,19,34,6,21,35,52,54,51,50,22,51,50,54,53,55,51,20,6,35,34,38,23,51,17,35,3,17,35,3,51,19,169,12,12,47,36,34,26,62,15,11, - 13,1,46,34,36,28,58,140,72,95,186,71,4,98,186,2,88,19,16,33,43,34,17,9,8,25,51,35,82,253,250,1,166,254,90,2,6,254,90,0,3,0,35,255,250,1,149,2,135,0,5,0,9,0,29,0,0,19,50,16,35,34,16, - 55,35,39,51,18,50,62,3,52,46,3,34,14,3,20,30,2,220,184,184,184,238,57,84,68,3,33,27,30,20,13,13,20,29,28,34,27,30,20,13,13,20,31,2,17,253,234,2,22,25,93,253,175,8,26,43,78,106,78,44, - 26,8,8,26,44,78,106,78,43,26,0,0,0,3,0,35,255,250,1,149,2,136,0,5,0,12,0,32,0,0,19,50,16,35,34,16,55,7,35,55,51,23,35,2,50,62,3,52,46,3,34,14,3,20,30,2,220,184,184,184,184,61,52,78, - 70,78,52,77,33,27,30,20,13,13,20,29,28,34,27,30,20,13,13,20,31,2,17,253,234,2,22,88,62,93,93,254,11,8,26,43,78,106,78,44,26,8,8,26,44,78,106,78,43,26,0,0,0,3,0,35,255,251,1,149,2,129, - 0,20,0,26,0,46,0,0,19,34,6,21,35,52,54,51,50,22,51,50,54,55,53,51,20,6,35,34,38,23,50,16,35,34,16,18,50,62,3,52,46,3,34,14,3,20,30,2,169,11,13,47,36,35,25,62,15,11,13,1,46,34,35,29, - 58,34,184,184,184,168,33,27,30,20,13,13,20,29,28,34,27,30,20,13,13,20,31,2,87,19,16,33,43,34,17,9,8,25,51,35,70,253,234,2,22,254,37,8,26,44,78,105,78,44,27,7,7,27,44,78,105,78,44,26, - 0,0,0,4,0,35,255,250,1,149,2,136,0,5,0,17,0,29,0,49,0,0,19,50,16,35,34,16,37,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,18,50,62,3,52,46,3,34,14,3,20,30,2,220,184, - 184,184,1,30,58,9,9,58,9,155,58,9,9,58,9,19,33,27,30,20,13,13,20,29,28,34,27,30,20,13,13,20,31,2,17,253,234,2,22,49,9,52,9,9,52,9,9,52,9,9,52,9,253,244,8,26,43,78,106,78,44,26,8,8, - 26,44,78,106,78,43,26,0,1,0,46,0,65,1,137,1,137,0,11,0,0,1,7,23,7,39,7,39,55,39,55,23,55,1,137,129,129,45,128,129,45,129,129,45,129,128,1,94,121,121,42,121,121,42,121,121,42,121,121, - 0,3,0,1,255,234,1,183,2,34,0,10,0,21,0,39,0,0,55,50,62,3,53,52,39,7,22,39,20,23,55,38,35,34,14,3,37,7,22,21,16,35,34,39,7,39,55,38,53,16,51,50,23,55,220,17,27,30,20,13,7,184,26,49, - 7,185,26,59,17,27,30,20,13,1,70,65,30,184,83,46,54,36,65,30,184,83,46,54,54,8,26,43,78,53,56,42,248,58,208,56,42,249,58,8,26,44,78,205,88,65,105,254,245,56,72,25,88,65,105,1,11,56, - 72,0,0,2,0,46,255,246,1,138,2,131,0,17,0,21,0,0,1,51,17,20,35,34,53,17,51,17,20,22,51,50,62,2,53,3,35,39,51,1,62,75,170,176,75,39,61,30,40,19,7,43,57,84,69,2,6,254,160,176,189,1,83, - 254,160,67,52,18,33,36,25,1,135,92,0,2,0,46,255,246,1,138,2,131,0,17,0,21,0,0,1,51,17,20,35,34,53,17,51,17,20,22,51,50,62,2,53,3,7,35,55,1,62,75,170,176,75,39,61,30,40,19,7,12,84,57, - 72,2,6,254,160,176,189,1,83,254,160,67,52,18,33,36,25,1,227,92,92,0,0,0,0,2,0,46,255,246,1,138,2,131,0,17,0,24,0,0,1,51,17,20,35,34,53,17,51,17,20,22,51,50,62,2,53,3,7,35,55,51,23, - 35,1,62,75,170,176,75,39,61,30,40,19,7,98,61,52,78,70,78,52,2,6,254,160,176,189,1,83,254,160,67,52,17,34,36,25,1,198,62,92,92,0,3,0,47,255,246,1,138,2,131,0,17,0,29,0,41,0,0,1,51,17, - 20,35,34,53,17,51,17,20,22,51,50,62,2,53,19,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,1,62,76,171,176,75,40,61,30,39,19,7,5,58,9,9,58,9,155,58,9,9,58,9,2,6,254, - 160,176,189,1,83,254,160,67,52,17,34,36,25,1,158,9,52,9,9,52,9,9,52,9,9,52,9,0,0,0,0,2,0,5,255,255,1,179,2,130,0,8,0,12,0,0,1,51,3,21,35,55,3,51,23,19,7,35,55,1,98,80,177,75,1,177, - 79,135,90,84,57,73,2,6,254,227,233,234,1,28,229,1,97,92,92,0,0,2,0,42,255,255,1,142,2,6,0,8,0,21,0,0,55,50,54,53,52,38,43,1,21,55,50,22,21,20,43,1,21,35,17,51,21,50,210,49,61,63,47, - 93,103,83,95,178,103,75,75,103,186,43,48,47,42,180,240,75,74,150,127,2,6,92,0,0,0,1,0,42,255,242,1,142,2,28,0,48,0,0,19,20,30,3,21,20,14,1,38,39,53,22,51,50,54,53,52,46,3,53,52,62, - 2,63,1,38,54,46,2,35,34,6,21,17,35,17,52,54,51,50,21,34,6,234,34,48,48,33,51,78,88,38,49,51,41,45,33,47,47,33,24,35,34,12,12,1,3,10,14,38,27,46,41,68,73,82,155,47,72,1,50,20,33,27, - 32,53,35,43,57,20,5,16,56,21,36,29,24,37,25,27,45,30,28,44,24,15,2,2,1,15,23,22,16,48,50,254,123,1,133,77,74,152,44,0,0,0,0,3,0,38,255,245,1,146,2,69,0,3,0,18,0,61,0,0,1,35,39,51,19, - 50,62,2,39,48,42,1,35,14,1,21,20,22,55,21,20,22,31,1,35,38,39,14,1,35,34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62,6,51,50,1,12,57,118,72,24,36,52,26,10,1,36,47,11,60,52,51,225, - 10,5,5,68,9,7,21,76,38,65,80,91,91,92,2,6,8,15,20,30,18,38,71,16,17,3,25,11,24,17,24,26,13,168,1,194,131,253,230,29,47,50,26,2,32,44,38,36,183,116,25,55,15,15,22,37,32,37,64,60,62, - 70,1,15,9,18,13,16,11,10,5,18,10,9,63,1,9,3,8,3,4,2,0,0,0,0,3,0,38,255,245,1,146,2,69,0,3,0,18,0,61,0,0,1,7,35,55,3,50,62,2,39,42,2,35,14,1,21,20,22,55,21,20,22,31,1,35,38,39,14,1, - 35,34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62,6,51,50,1,84,118,57,103,80,37,52,26,10,1,1,35,47,11,60,52,51,225,10,5,5,68,9,7,21,76,38,65,80,91,91,92,2,6,8,15,20,30,18,38,71,16, - 17,3,25,11,24,17,24,26,13,168,2,69,131,131,253,230,29,47,50,26,2,32,44,38,36,183,116,25,55,15,15,22,37,32,37,64,60,62,70,1,15,9,18,13,16,11,10,5,18,10,9,63,1,9,3,8,3,4,2,0,0,0,3,0, - 38,255,245,1,146,2,69,0,6,0,21,0,64,0,0,19,7,35,55,51,23,35,3,50,62,2,39,48,42,1,35,14,1,21,20,22,55,21,20,22,31,1,35,38,39,14,1,35,34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62, - 6,51,50,220,66,52,90,56,90,52,97,36,52,26,10,1,36,47,11,60,52,51,225,10,5,5,68,9,7,21,76,38,65,80,91,91,92,2,6,8,15,20,30,18,38,71,16,17,3,25,11,24,17,24,26,13,168,2,26,88,131,131, - 254,105,29,47,50,26,2,32,44,38,36,183,116,25,55,15,15,22,37,32,37,64,60,63,69,1,15,9,18,13,16,11,10,5,18,10,9,63,1,9,3,8,3,4,2,0,3,0,38,255,245,1,146,2,51,0,24,0,39,0,82,0,0,1,34,46, - 2,35,34,21,35,52,54,51,50,30,1,51,50,54,61,1,51,20,14,2,3,50,62,2,39,48,42,1,35,14,1,21,20,22,55,21,20,22,31,1,35,38,39,14,1,35,34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62,6,51, - 50,1,13,21,31,16,23,11,26,45,36,37,21,34,30,13,12,13,46,5,13,30,101,36,52,26,10,1,36,47,11,60,52,51,225,10,5,5,68,9,7,21,76,38,65,80,91,91,92,2,6,8,15,20,30,18,38,71,16,17,3,25,11, - 24,17,24,26,13,168,1,209,17,20,17,54,43,55,27,26,26,13,14,15,29,33,21,254,90,29,47,50,26,2,32,44,38,36,183,116,25,55,15,15,22,37,32,37,64,60,62,70,1,15,9,18,13,16,11,10,5,18,10,9,63, - 1,9,3,8,3,4,2,0,0,0,4,0,38,255,245,1,146,2,29,0,11,0,23,0,38,0,81,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,19,50,62,2,39,42,2,35,14,1,21,20,22,55,21,20,22, - 31,1,35,38,39,14,1,35,34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62,6,51,50,1,63,58,9,9,58,9,155,58,9,9,58,9,6,37,52,26,10,1,1,35,47,11,60,52,51,225,10,5,5,68,9,7,21,76,38,65,80, - 91,91,92,2,6,8,15,20,30,18,38,71,16,17,3,25,11,24,17,24,26,13,168,1,214,9,52,9,9,52,9,9,52,9,9,52,9,254,85,29,47,50,26,2,32,44,38,36,183,116,25,55,15,15,22,37,32,37,64,60,62,70,1,15, - 9,18,13,16,11,10,5,18,10,9,63,1,9,3,8,3,4,2,0,0,0,4,0,38,255,245,1,146,2,114,0,7,0,15,0,58,0,73,0,0,18,34,6,20,22,50,54,52,6,34,38,52,54,50,22,20,19,21,20,22,31,1,35,38,39,14,1,35, - 34,38,53,52,54,59,1,60,2,46,5,35,34,6,15,1,53,62,6,51,50,3,50,62,2,39,42,2,35,14,1,21,20,22,240,46,33,33,46,33,14,84,60,60,84,60,63,10,5,5,68,9,7,21,76,38,65,80,91,91,92,2,6,8,15,20, - 30,18,38,71,16,17,3,25,11,24,17,24,26,13,168,194,37,52,26,10,1,1,35,47,11,60,52,51,2,70,31,44,31,31,44,118,56,80,56,56,80,254,249,116,25,55,15,15,22,37,32,37,64,60,62,70,1,15,9,18, - 13,16,11,10,5,18,10,9,63,1,9,3,8,3,4,2,254,155,29,47,50,26,2,32,44,38,36,0,0,0,0,3,0,5,255,245,1,179,1,143,0,8,0,19,0,89,0,0,1,34,6,23,51,54,39,46,1,3,50,62,1,39,35,34,6,21,20,22,37, - 21,35,28,2,30,5,51,22,54,63,1,21,14,2,35,34,46,2,47,1,14,4,35,34,38,53,52,54,59,1,53,52,38,35,34,6,15,1,53,54,51,50,30,2,31,1,62,4,51,50,22,23,30,1,21,1,56,31,31,3,121,1,2,3,27,217, - 26,26,14,1,28,53,44,37,1,75,182,2,4,6,10,14,21,12,34,52,9,10,5,15,48,25,25,42,22,16,2,3,1,4,16,21,36,22,57,60,70,68,50,42,30,19,46,13,14,44,65,19,30,18,12,2,2,1,3,14,19,36,22,58,48, - 8,2,1,1,90,54,64,23,22,35,38,254,209,18,59,59,32,38,35,31,136,1,1,28,10,28,13,23,11,14,6,1,17,9,10,60,3,10,16,11,17,16,6,5,2,7,19,15,12,60,56,57,65,28,50,39,14,8,7,58,24,9,13,13,4, - 5,2,6,15,11,10,59,76,18,42,12,0,0,0,1,0,59,255,119,1,125,1,142,0,37,0,0,1,34,6,21,20,22,51,50,55,21,14,1,15,1,22,21,20,6,35,34,39,53,22,51,50,53,52,39,46,1,53,52,54,51,50,23,21,38, - 1,13,65,72,72,65,62,49,14,43,15,15,33,45,38,45,25,24,31,46,26,82,106,110,85,78,47,49,1,88,74,76,76,74,43,65,11,15,2,2,36,32,31,30,8,46,12,32,22,31,3,105,96,98,106,32,65,43,0,0,0,3, - 0,37,255,247,1,147,2,69,0,3,0,9,0,30,0,0,1,35,39,51,23,34,6,21,51,52,7,20,22,51,50,54,55,21,6,35,34,38,53,52,54,51,50,22,21,23,32,1,19,57,118,72,55,46,70,224,227,62,67,42,62,46,70, - 82,89,109,105,79,92,89,1,254,217,1,194,131,236,68,48,116,165,56,79,18,21,64,29,109,95,93,110,97,73,48,0,3,0,37,255,247,1,147,2,69,0,3,0,9,0,30,0,0,1,7,35,55,7,34,6,21,51,52,7,20,22, - 51,50,54,55,21,6,35,34,38,53,52,54,51,50,22,21,23,32,1,93,119,56,102,49,46,70,224,227,62,67,42,62,46,70,82,89,109,105,79,92,89,1,254,217,2,69,131,131,236,68,48,116,165,56,79,18,21, - 64,29,109,95,93,110,97,73,48,0,0,0,0,3,0,37,255,247,1,147,2,69,0,6,0,12,0,33,0,0,19,7,35,55,51,23,35,7,34,6,21,51,52,7,20,22,51,50,54,55,21,6,35,34,38,53,52,54,51,50,22,21,23,32,225, - 67,52,90,57,90,52,64,46,70,224,227,62,67,42,62,46,70,82,89,109,105,79,92,89,1,254,217,2,26,88,131,131,105,68,48,116,165,56,79,18,21,64,29,109,95,93,110,97,73,48,0,0,4,0,37,255,247, - 1,147,2,29,0,11,0,23,0,29,0,50,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,23,34,6,21,51,52,7,20,22,51,50,54,55,21,6,35,34,38,53,52,54,51,50,22,21,23,32,1,69, - 57,9,9,57,9,155,58,9,9,58,9,39,46,70,224,227,62,67,42,62,46,70,82,89,109,105,79,92,89,1,254,217,1,214,9,52,9,9,52,9,9,52,9,9,52,9,125,68,48,116,165,56,79,18,21,64,29,109,95,93,110, - 97,73,48,0,0,0,0,2,0,51,255,252,1,117,2,59,0,13,0,17,0,0,37,51,21,34,35,34,38,61,1,35,53,51,21,20,17,35,39,51,1,37,80,24,71,54,65,90,158,57,119,73,51,54,78,63,201,50,251,86,1,132,131, - 0,0,0,0,2,0,68,255,252,1,116,2,59,0,13,0,17,0,0,37,51,21,34,35,34,38,61,1,35,53,51,21,20,19,7,35,55,1,37,79,23,72,53,66,90,158,106,119,57,103,51,54,78,63,201,50,251,86,2,7,131,131, - 0,0,2,0,68,255,252,1,116,2,69,0,6,0,20,0,0,19,7,35,55,51,23,35,19,51,21,34,35,34,38,61,1,35,53,51,21,20,186,66,52,90,56,90,51,40,79,23,72,53,66,90,158,2,26,88,131,131,254,113,54,78, - 63,201,50,251,86,0,0,0,3,0,68,255,252,1,116,2,26,0,11,0,23,0,37,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,19,51,21,34,35,34,38,61,1,35,53,51,21,20,1,44,57, - 9,9,57,9,155,57,9,9,57,9,130,79,23,72,53,66,90,158,1,212,9,52,9,9,52,9,9,52,9,9,52,9,254,95,54,78,63,201,50,251,86,0,2,0,42,255,244,1,142,2,27,0,14,0,47,0,0,55,50,54,53,52,38,47,1, - 38,35,34,6,21,20,22,19,20,30,6,21,20,6,35,34,38,53,52,54,23,46,1,47,1,7,39,55,39,51,23,55,23,7,22,220,45,60,20,10,10,18,50,43,59,60,145,20,6,19,8,13,6,5,89,88,88,89,107,100,5,27,10, - 11,103,12,88,67,81,47,106,13,93,36,42,70,71,38,67,15,14,9,69,73,73,69,1,89,1,27,10,29,19,33,29,38,19,86,107,107,94,93,102,8,8,31,12,11,31,34,27,69,49,32,34,28,34,0,0,0,0,2,0,62,0,0, - 1,122,2,32,0,18,0,43,0,0,19,50,22,21,17,35,53,52,38,35,34,6,29,1,35,17,51,23,54,55,34,21,35,52,54,51,50,30,1,51,50,54,61,1,51,20,14,2,35,34,46,2,253,53,72,68,39,38,47,56,68,64,4,37, - 3,26,45,36,37,20,35,30,13,12,13,46,5,14,29,21,21,31,17,22,1,145,78,67,255,0,250,45,48,61,59,223,1,132,47,60,99,54,44,54,27,26,26,14,13,15,29,33,21,17,20,17,0,0,0,3,0,43,255,244,1,141, - 2,69,0,3,0,13,0,21,0,0,1,35,39,51,18,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53,52,1,15,56,119,73,5,92,58,59,90,59,21,166,94,254,158,1,194,131,253,229,71,80,80,70,70,80,80,1,28, - 102,102,204,204,102,0,0,3,0,43,255,244,1,141,2,69,0,3,0,13,0,21,0,0,1,7,35,55,2,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53,52,1,86,118,57,103,96,92,58,59,90,59,21,166,94,254,158, - 2,69,131,131,253,229,71,80,80,70,70,80,80,1,28,102,102,204,204,102,0,3,0,43,255,244,1,141,2,69,0,6,0,16,0,24,0,0,19,7,35,55,51,23,35,2,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53, - 52,220,66,52,90,56,90,52,112,92,58,59,90,59,21,166,94,254,158,2,26,88,131,131,254,104,71,80,80,70,70,80,80,1,28,102,102,204,204,102,0,0,0,3,0,43,255,244,1,141,2,32,0,24,0,34,0,42,0, - 0,1,34,46,2,35,34,21,35,52,54,51,50,30,1,51,50,54,61,1,51,20,14,2,2,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53,52,1,15,20,32,16,22,12,25,46,36,38,20,35,29,14,12,13,46,5,14,30,118, - 92,58,59,90,59,21,166,94,254,158,1,190,17,20,17,54,44,54,27,26,26,14,13,15,29,33,21,254,108,71,80,80,70,70,80,80,1,28,102,102,204,204,102,0,4,0,43,255,244,1,141,2,26,0,11,0,23,0,33, - 0,41,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,2,50,54,53,52,38,34,6,21,20,18,50,22,21,20,32,53,52,1,66,58,9,9,58,9,155,58,9,9,58,9,11,92,58,59,90,59,21,166, - 94,254,158,1,212,9,52,9,9,52,9,9,52,9,9,52,9,254,86,71,80,80,70,70,80,80,1,28,102,102,204,204,102,0,3,0,24,0,49,1,159,1,136,0,3,0,19,0,35,0,0,37,33,53,33,39,35,34,38,61,1,52,54,59, - 1,50,22,29,1,20,6,3,35,34,38,61,1,52,54,59,1,50,22,29,1,20,6,1,159,254,121,1,135,161,70,4,7,7,4,70,5,6,6,5,70,4,7,7,4,70,5,6,6,192,59,56,6,5,63,5,6,6,5,63,5,6,254,255,6,5,63,4,7,7, - 4,63,5,6,0,0,0,0,3,0,12,255,222,1,172,1,166,0,7,0,15,0,35,0,0,55,50,54,53,52,39,7,22,39,20,23,55,38,35,34,6,37,7,22,21,20,35,34,39,7,39,55,38,53,52,54,51,50,23,55,22,222,47,57,10,169, - 27,56,9,168,27,46,45,59,1,54,61,33,178,75,44,57,34,62,29,94,83,71,46,55,34,43,72,80,42,32,189,37,152,42,31,189,33,70,121,68,52,81,204,40,63,26,70,50,81,102,102,39,63,27,0,0,0,0,2,0, - 61,255,246,1,123,2,59,0,3,0,26,0,0,1,35,39,51,23,51,17,35,39,14,4,35,34,38,61,1,51,21,20,22,51,50,54,53,1,13,57,119,73,144,68,63,6,2,5,20,23,38,21,77,61,67,38,43,44,53,1,184,131,182, - 254,124,57,2,10,23,18,14,72,82,244,240,52,52,59,50,0,0,0,2,0,61,255,246,1,123,2,59,0,3,0,26,0,0,1,7,35,55,23,51,17,35,39,14,4,35,34,38,61,1,51,21,20,22,51,50,54,53,1,83,119,56,102, - 44,68,63,6,2,5,20,23,38,21,77,61,67,38,43,44,53,2,59,131,131,182,254,124,57,2,10,23,18,14,72,82,244,240,52,52,59,50,0,0,2,0,61,255,246,1,123,2,69,0,6,0,29,0,0,19,7,35,55,51,23,35,23, - 17,35,39,14,4,35,34,38,61,1,51,21,20,22,51,50,54,53,55,220,66,52,90,56,90,52,92,63,6,2,5,20,23,38,21,77,61,67,38,42,45,53,2,2,26,88,131,131,61,254,124,57,2,10,23,18,14,72,82,244,240, - 52,52,59,50,235,0,0,0,3,0,61,255,246,1,123,2,27,0,11,0,23,0,46,0,0,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,23,51,17,35,39,14,4,35,34,38,61,1,51,21,20,22,51, - 50,54,53,1,63,58,8,8,58,9,155,58,9,9,58,9,128,68,63,6,2,5,20,23,38,21,77,61,67,38,42,45,53,1,213,9,52,9,9,52,9,9,52,9,9,52,9,80,254,124,57,2,10,23,18,14,72,82,244,240,52,52,59,50,0, - 0,2,0,26,255,107,1,158,2,59,0,17,0,21,0,0,1,51,2,7,14,3,43,1,53,51,50,54,55,3,51,27,1,7,35,55,1,86,72,140,39,14,32,36,25,18,54,46,30,32,22,160,72,123,105,119,56,102,1,133,254,175,98, - 35,44,18,5,54,46,54,1,127,254,208,1,230,131,131,0,0,0,2,0,50,255,107,1,134,2,32,0,9,0,23,0,0,54,50,54,53,52,38,34,6,21,20,19,50,22,21,20,35,34,39,21,35,17,51,21,54,174,89,55,57,86, - 56,99,80,91,171,67,32,68,68,31,42,71,80,80,70,70,80,80,1,28,102,102,204,65,202,2,180,208,61,0,0,0,3,0,26,255,107,1,158,2,17,0,17,0,29,0,41,0,0,1,51,2,7,14,3,43,1,53,51,50,54,55,3,51, - 27,1,35,34,61,1,52,59,1,50,29,1,20,43,1,34,61,1,52,59,1,50,29,1,20,1,86,72,140,39,14,32,36,25,18,54,46,30,32,22,160,72,123,100,57,9,9,57,9,155,58,9,9,58,9,1,133,254,175,98,35,44,18, - 5,54,46,54,1,127,254,208,1,118,9,52,9,9,52,9,9,52,9,9,52,9,0,0,0,1,0,30,255,249,1,153,2,20,0,43,0,0,1,34,7,51,7,35,6,21,20,21,51,7,35,30,3,51,50,54,55,21,6,35,34,38,39,35,55,51,38, - 52,55,35,55,51,62,1,51,50,23,21,46,1,1,44,110,20,178,18,163,1,132,17,111,6,27,38,37,23,20,61,27,47,61,88,103,14,65,18,44,2,2,62,18,47,14,103,83,65,48,28,61,1,220,144,36,30,4,17,15, - 37,44,60,29,10,19,24,71,28,104,95,37,29,9,28,36,95,105,29,72,24,21,0,0,0,0,0,0,14,0,174,0,1,0,0,0,0,0,0,0,1,0,4,0,1,0,0,0,0,0,1,0,1,0,10,0,1,0,0,0,0,0,2,0,1,0,16,0,1,0,0,0,0,0,3,0, - 29,0,78,0,1,0,0,0,0,0,4,0,1,0,112,0,1,0,0,0,0,0,5,0,9,0,134,0,1,0,0,0,0,0,6,0,1,0,148,0,3,0,1,4,9,0,0,0,2,0,0,0,3,0,1,4,9,0,1,0,2,0,6,0,3,0,1,4,9,0,2,0,2,0,12,0,3,0,1,4,9,0,3,0,58, - 0,18,0,3,0,1,4,9,0,4,0,2,0,108,0,3,0,1,4,9,0,5,0,18,0,114,0,3,0,1,4,9,0,6,0,2,0,144,0,46,0,0,46,0,0,46,0,0,46,0,0,46,0,0,46,0,0,70,0,111,0,110,0,116,0,70,0,111,0,114,0,103,0,101,0, - 32,0,50,0,46,0,48,0,32,0,58,0,32,0,46,0,32,0,58,0,32,0,49,0,49,0,45,0,50,0,45,0,50,0,48,0,50,0,54,0,0,70,111,110,116,70,111,114,103,101,32,50,46,48,32,58,32,46,32,58,32,49,49,45,50, - 45,50,48,50,54,0,0,46,0,0,46,0,0,86,0,101,0,114,0,115,0,105,0,111,0,110,0,32,0,46,0,0,86,101,114,115,105,111,110,32,46,0,0,46,0,0,46,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,192,0,0,0,1,0,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0,11,0,12,0,13,0,14,0,15,0,16,0,17,0,18,0,19,0,20,0,21,0,22,0,23,0,24,0,25,0,26,0,27,0,28,0,29,0,30,0,31,0,32,0, - 33,0,34,0,35,0,36,0,37,0,38,0,39,0,40,0,41,0,42,0,43,0,44,0,45,0,46,0,47,0,48,0,49,0,50,0,51,0,52,0,53,0,54,0,55,0,56,0,57,0,58,0,59,0,60,0,61,0,62,0,63,0,64,0,65,0,66,0,67,0,68,0, - 69,0,70,0,71,0,72,0,73,0,74,0,75,0,76,0,77,0,78,0,79,0,80,0,81,0,82,0,83,0,84,0,85,0,86,0,87,0,88,0,89,0,90,0,91,0,92,0,93,0,94,1,2,0,96,0,97,1,3,0,163,0,132,0,133,0,189,0,150,0,232, - 0,134,0,142,0,139,0,157,0,169,0,138,1,4,0,131,0,147,0,242,0,243,0,141,0,151,0,136,0,195,0,222,0,241,0,158,0,170,0,245,0,244,0,246,0,162,0,173,0,201,0,199,0,174,0,98,0,99,0,144,0,100, - 0,203,0,101,0,200,0,202,0,207,0,204,0,205,0,206,0,233,0,102,0,211,0,209,0,175,0,103,0,240,0,145,0,214,0,212,0,213,0,104,0,235,0,237,0,137,0,106,0,105,0,107,0,109,0,108,0,110,0,160, - 0,111,0,113,0,112,0,114,0,115,0,117,0,116,0,118,0,119,0,234,0,120,0,122,0,121,0,123,0,125,0,124,0,184,0,161,0,127,0,126,0,128,0,129,0,236,0,238,0,186,1,5,11,118,101,114,116,105,99, - 97,108,98,97,114,7,117,110,105,48,48,56,53,9,111,118,101,114,115,99,111,114,101,4,69,117,114,111,0,0,0,0,0,0,1,255,255,0,2,0,1,0,0,0,12,0,0,0,22,0,0,0,2,0,1,0,98,0,98,0,1,0,4,0,0,0, - 2,0,0,0,0,0,0,0,1,0,0,0,0,229,13,183,147,0,0,0,0,229,175,187,66,0,0,0,0,229,178,59,232, -}; -// clang-format on - -const unsigned char* GetFontBytes( int* outSize ) -{ - if ( outSize != NULL ) - { - *outSize = (int)ProggyForeverMinimal_size; - } - - return ProggyForeverMinimal_data; -} - -const char* GetFontName( void ) -{ - return "Proggy Forever"; -} diff --git a/samples/gfx/fonts.h b/samples/gfx/fonts.h deleted file mode 100644 index 15c812e..0000000 --- a/samples/gfx/fonts.h +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#ifdef __cplusplus -extern "C" -{ -#endif - -// TTF bytes, valid for the life of the program. Covers printable ASCII, which -// is all the samples emit. Anything outside that draws as '?'. -const unsigned char* GetFontBytes( int* outSize ); - -// Short name for the ImGui atlas and logs. -const char* GetFontName( void ); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/samples/gfx/geometry_registry.c b/samples/gfx/geometry_registry.c index f63c156..b0833a4 100644 --- a/samples/gfx/geometry_registry.c +++ b/samples/gfx/geometry_registry.c @@ -16,7 +16,7 @@ typedef struct Entry { - uint64_t hash; + uint32_t hash; int refCount; // 0 means free sg_buffer vbo; sg_buffer ibo; @@ -164,7 +164,7 @@ void DestroyMeshRegistry( void ) sg_destroy_buffer( s_geom.instBuf ); } -MeshHandle FindMesh( uint64_t hash ) +MeshHandle FindMesh( uint32_t hash ) { if ( hash == 0u ) { @@ -200,10 +200,10 @@ static int FindFreeSlot( void ) return s_geom.entryCount++; } -MeshHandle RegisterMesh( uint64_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, +MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, int indexCount, const char* debugLabel ) { - assert( hash != 0 ); + assert( hash != 0u ); assert( vertexCount > 0 ); assert( indexCount > 0 ); @@ -428,7 +428,7 @@ void ReleaseMeshReference( MeshHandle h ) sg_destroy_view( e->edgeStorageView ); sg_destroy_buffer( e->edgeBuf ); } - e->hash = 0; + e->hash = 0u; e->indexCount = 0; e->edgeBuf.id = SG_INVALID_ID; e->edgeStorageView.id = SG_INVALID_ID; diff --git a/samples/gfx/geometry_registry.h b/samples/gfx/geometry_registry.h index eff0630..5bbedbd 100644 --- a/samples/gfx/geometry_registry.h +++ b/samples/gfx/geometry_registry.h @@ -3,7 +3,7 @@ // Ref-counted GPU buffer store for triangle geometries (convex hulls, // triangle meshes, heightfields). Owned by the renderer -// Keyed by uint64_t content hash for Box3D shapes we +// Keyed by uint32_t content hash for Box3D shapes we // pass through b3HullData.hash / b3MeshData.hash / b3HeightFieldData.hash // // Lifecycle: @@ -52,12 +52,12 @@ extern "C" typedef struct MeshHandle { int index; // -1 means invalid - uint64_t hash; // for cheap validation against index reuse + uint32_t hash; // for cheap validation against index reuse } MeshHandle; static inline MeshHandle InvalidMeshHandle( void ) { - MeshHandle h = { -1, 0ull }; + MeshHandle h = { -1, 0u }; return h; } @@ -142,9 +142,9 @@ typedef struct MeshXpInstance void CreateMeshRegistry( void ); void DestroyMeshRegistry( void ); -MeshHandle FindMesh( uint64_t hash ); +MeshHandle FindMesh( uint32_t hash ); -MeshHandle RegisterMesh( uint64_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, +MeshHandle RegisterMesh( uint32_t hash, const MeshVertex* vertices, int vertexCount, const uint32_t* indices, int indexCount, const char* debugLabel ); // Optional: register an edge list for a geometry already registered via diff --git a/samples/gfx/keycodes.h b/samples/gfx/keycodes.h index 48c81d0..f883438 100644 --- a/samples/gfx/keycodes.h +++ b/samples/gfx/keycodes.h @@ -15,8 +15,6 @@ enum KEY_B = SAPP_KEYCODE_B, KEY_D = SAPP_KEYCODE_D, KEY_F = SAPP_KEYCODE_F, - KEY_G = SAPP_KEYCODE_G, - KEY_K = SAPP_KEYCODE_K, KEY_L = SAPP_KEYCODE_L, KEY_M = SAPP_KEYCODE_M, KEY_O = SAPP_KEYCODE_O, @@ -28,17 +26,11 @@ enum KEY_V = SAPP_KEYCODE_V, KEY_W = SAPP_KEYCODE_W, KEY_SPACE = SAPP_KEYCODE_SPACE, - KEY_COMMA = SAPP_KEYCODE_COMMA, - KEY_PERIOD = SAPP_KEYCODE_PERIOD, KEY_ESCAPE = SAPP_KEYCODE_ESCAPE, KEY_TAB = SAPP_KEYCODE_TAB, KEY_LEFT_SHIFT = SAPP_KEYCODE_LEFT_SHIFT, - KEY_RIGHT_SHIFT = SAPP_KEYCODE_RIGHT_SHIFT, - KEY_LEFT_CONTROL = SAPP_KEYCODE_LEFT_CONTROL, - KEY_RIGHT_CONTROL = SAPP_KEYCODE_RIGHT_CONTROL, KEY_LEFT_BRACKET = SAPP_KEYCODE_LEFT_BRACKET, KEY_RIGHT_BRACKET = SAPP_KEYCODE_RIGHT_BRACKET, - KEY_PAUSE = SAPP_KEYCODE_PAUSE, MOD_SHIFT = SAPP_MODIFIER_SHIFT, MOD_CTRL = SAPP_MODIFIER_CTRL, diff --git a/samples/gfx/renderer.c b/samples/gfx/renderer.c index d45459c..2fb8aa5 100644 --- a/samples/gfx/renderer.c +++ b/samples/gfx/renderer.c @@ -25,7 +25,6 @@ #include "gfx/sky.h" #include "gfx/text.h" #include "gfx/tone_map.h" -#include "gfx/world_text.h" #include "shadow_caster_capsule.glsl.h" #include "shadow_caster_cube.glsl.h" #include "shadow_caster_geom.glsl.h" @@ -88,12 +87,24 @@ static struct sg_pipeline shadowGeomPipeline; sg_pipeline shadowGeomPipelineMirror; - // Shadow caster pipelines (sphere, capsule). Both rasterize the same - // bounding proxy the lit impostor uses and ray-cast the exact surface, - // so they borrow the cube's vbuf/ibuf and share the lit pipeline's - // instance buffers. + // Shadow caster pipeline (sphere). The lit sphere pipeline is an + // analytic impostor, too expensive for the shadow pass, so the + // caster rasterizes a low-poly icosphere proxy generated at InitRenderer. + // The icosphere vbo/ibo live here, the sphere instance buffer is + // shared with the lit pipeline. + sg_buffer icosphereVbuf; + sg_buffer icosphereIbuf; + int icosphereIndexCount; sg_shader shadowSphereShader; sg_pipeline shadowSpherePipeline; + + // Shadow caster pipeline (capsule). Cylinder-plus-caps proxy mesh + // built once at InitRenderer, the capsule instance buffer is shared with + // the lit pipeline. Per-vertex format is two vec3s: in_axis (scaled + // by halfLength) + in_radial (scaled by radius). + sg_buffer capsuleProxyVbuf; + sg_buffer capsuleProxyIbuf; + int capsuleProxyIndexCount; sg_shader shadowCapsuleShader; sg_pipeline shadowCapsulePipeline; @@ -242,6 +253,320 @@ static const uint16_t CUBE_INDICES[36] = { 4, 5, 7, 4, 7, 6, // +Z }; +// Ico-sphere shadow proxy +// N-level subdivided ico-sphere built from a 12-vert icosahedron: each +// subdivision step splits every face into 4 by inserting edge midpoints, +// then renormalizes every new vertex to the unit sphere. After L levels: +// verts = 10 * 4^L + 2, tris = 20 * 4^L. Built once at InitRenderer and uploaded +// to dedicated vbuf/ibuf for the shadow_caster_sphere pipeline. +// +// We use L=2 (162 verts, 320 tris), subdiv-1 gave visibly polygonal +// shadow silhouettes when the sun grazed a sphere, subdiv-2 reads as +// round at any zoom we're likely to use. Subdiv-3 (1280 tris) is overkill. +// +// The icosahedron's golden-ratio coordinates produce a remarkably even +// vertex distribution, better silhouette quality than a UV sphere +// comparable triangle count. +#define ICO_SPHERE_SUBDIV_LEVEL 2 +#define ICO_SPHERE_VERTICES 162 // 10 * 4^L + 2 for L=2 +#define ICO_SPHERE_INDICES ( 320 * 3 ) // 20 * 4^L for L=2 + +static void BuildIcosphere( float ( *outVerts )[3], uint32_t* outIndices ) +{ + const float phi = ( 1.0f + sqrtf( 5.0f ) ) * 0.5f; + const float invLen = 1.0f / sqrtf( 1.0f + phi * phi ); + + // 12 icosahedron vertices, normalized to the unit sphere. + const float baseVerts[12][3] = { + { -1.0f, phi, 0.0f }, { 1.0f, phi, 0.0f }, { -1.0f, -phi, 0.0f }, { 1.0f, -phi, 0.0f }, + { 0.0f, -1.0f, phi }, { 0.0f, 1.0f, phi }, { 0.0f, -1.0f, -phi }, { 0.0f, 1.0f, -phi }, + { phi, 0.0f, -1.0f }, { phi, 0.0f, 1.0f }, { -phi, 0.0f, -1.0f }, { -phi, 0.0f, 1.0f }, + }; + for ( int i = 0; i < 12; ++i ) + { + outVerts[i][0] = baseVerts[i][0] * invLen; + outVerts[i][1] = baseVerts[i][1] * invLen; + outVerts[i][2] = baseVerts[i][2] * invLen; + } + + // 20 base faces, CCW from outside. + static const uint32_t baseTris[20 * 3] = { + 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, + 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1, + }; + + // Ping-pong tri buffers. Each level reads `cur` and writes `nxt`, then + // swaps. Static so the ~7.5 KB doesn't pressure the call-site stack. + static uint32_t triA[ICO_SPHERE_INDICES]; + static uint32_t triB[ICO_SPHERE_INDICES]; + uint32_t* cur = triA; + uint32_t* nxt = triB; + int triCount = 20; + for ( int i = 0; i < 20 * 3; ++i ) + cur[i] = baseTris[i]; + + int vertCount = 12; + + // Edge midpoint cache, sized for the final vertex count. Each edge + // the *current* tri set pairs exactly two faces, so a midpoint computed + // for one face is reused by exactly one other. Cleared per level so + // midpoint indices from earlier levels don't leak in. ~104 KB static. + static int midCache[ICO_SPHERE_VERTICES][ICO_SPHERE_VERTICES]; + + for ( int L = 0; L < ICO_SPHERE_SUBDIV_LEVEL; ++L ) + { + for ( int i = 0; i < ICO_SPHERE_VERTICES; ++i ) + { + for ( int j = 0; j < ICO_SPHERE_VERTICES; ++j ) + { + midCache[i][j] = -1; + } + } + + int nxtCount = 0; + for ( int t = 0; t < triCount; ++t ) + { + const uint32_t v[3] = { cur[t * 3 + 0], cur[t * 3 + 1], cur[t * 3 + 2] }; + + uint32_t mid[3]; + for ( int e = 0; e < 3; ++e ) + { + uint32_t a = v[e]; + uint32_t b = v[( e + 1 ) % 3]; + if ( a > b ) + { + uint32_t tmp = a; + a = b; + b = tmp; + } + if ( midCache[a][b] < 0 ) + { + const int index = vertCount++; + float mx = 0.5f * ( outVerts[a][0] + outVerts[b][0] ); + float my = 0.5f * ( outVerts[a][1] + outVerts[b][1] ); + float mz = 0.5f * ( outVerts[a][2] + outVerts[b][2] ); + const float len = sqrtf( mx * mx + my * my + mz * mz ); + if ( len > 0.0f ) + { + mx /= len; + my /= len; + mz /= len; + } + outVerts[index][0] = mx; + outVerts[index][1] = my; + outVerts[index][2] = mz; + midCache[a][b] = index; + } + mid[e] = (uint32_t)midCache[a][b]; + } + + // Subdivide one tri (v0,v1,v2) into four: + // (v0, m01, m20), (v1, m12, m01), (v2, m20, m12), (m01, m12, m20). + // mid[0] = m01, mid[1] = m12, mid[2] = m20. + nxt[nxtCount++] = v[0]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = mid[2]; + nxt[nxtCount++] = v[1]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = v[2]; + nxt[nxtCount++] = mid[2]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[0]; + nxt[nxtCount++] = mid[1]; + nxt[nxtCount++] = mid[2]; + } + triCount = nxtCount / 3; + uint32_t* tmp = cur; + cur = nxt; + nxt = tmp; + } + + for ( int i = 0; i < triCount * 3; ++i ) + outIndices[i] = cur[i]; +} + +// Capsule proxy for shadows +// 12-slice cylinder + two hemispherical caps with 2 latitude rings each +// (alpha at pi/6 and pi/3, plus a single pole). Verts are encoded with two +// vec3s, in_axis (scaled by halfLength) and in_radial (scaled by radius), +// so the same proxy mesh works for any (halfLength, radius) pair. +// +// Layout (74 vertices, 144 tris): +// 0..11 body ring -X in_axis=(-1,0,0), in_radial=(0, cos beta, sin beta) +// 12..23 body ring +X in_axis=(+1,0,0), in_radial=(0, cos beta, sin beta) +// 24..35 +X cap ring alpha=pi/6 in_axis=(+1,0,0), in_radial=(sin alpha, cos alpha cos beta, cos alpha sin beta) +// 36..47 +X cap ring alpha=pi/3 ditto with alpha=pi/3 +// 48 +X pole in_axis=(+1,0,0), in_radial=(1, 0, 0) +// 49..60 -X cap ring alpha=pi/6 in_axis=(-1,0,0), in_radial=(-sin alpha, cos alpha cos beta, cos alpha sin beta) +// 61..72 -X cap ring alpha=pi/3 ditto +// 73 -X pole in_axis=(-1,0,0), in_radial=(-1, 0, 0) +// +// Caps share their equator ring with the body's end ring (the body ring +// at +X is the +X cap's alpha=0 equator, etc.), saves 24 verts and avoids +// any seam in the depth render. +#define CAPSULE_SLICES 12 +#define CAPSULE_VERTICES 74 +#define CAPSULE_INDICES ( 144 * 3 ) + +typedef struct CapsuleVertex +{ + float axis[3]; + float radial[3]; +} CapsuleVertex; + +// Helper macro: emit two triangles for a quad with corners +// bl, br, tr, tl (CCW outside-front). +#define CAPSULE_QUAD( bl, br, tr, tl ) \ + do \ + { \ + outIndices[index++] = (uint32_t)( bl ); \ + outIndices[index++] = (uint32_t)( br ); \ + outIndices[index++] = (uint32_t)( tr ); \ + outIndices[index++] = (uint32_t)( bl ); \ + outIndices[index++] = (uint32_t)( tr ); \ + outIndices[index++] = (uint32_t)( tl ); \ + } \ + while ( 0 ) + +static void BuildCapsuleProxy( CapsuleVertex* outVerts, uint32_t* outIndices ) +{ + const float TWO_PI = 6.28318530717958647692f; + const float ALPHA1 = TWO_PI / 12.0f; // pi/6 + const float ALPHA2 = 2.0f * TWO_PI / 12.0f; // pi/3 + + // Vertices + int v = 0; + // 0..11: body ring -X + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = 0.0f; + outVerts[v].radial[1] = cosf( beta ); + outVerts[v].radial[2] = sinf( beta ); + } + // 12..23: body ring +X + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = 0.0f; + outVerts[v].radial[1] = cosf( beta ); + outVerts[v].radial[2] = sinf( beta ); + } + // 24..35: +X cap ring alpha=pi/6 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = sinf( ALPHA1 ); + outVerts[v].radial[1] = cosf( ALPHA1 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA1 ) * sinf( beta ); + } + // 36..47: +X cap ring alpha=pi/3 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = sinf( ALPHA2 ); + outVerts[v].radial[1] = cosf( ALPHA2 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA2 ) * sinf( beta ); + } + // 48: +X pole + outVerts[v].axis[0] = +1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = +1.0f; + outVerts[v].radial[1] = 0.0f; + outVerts[v].radial[2] = 0.0f; + ++v; + // 49..60: -X cap ring alpha=pi/6 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -sinf( ALPHA1 ); + outVerts[v].radial[1] = cosf( ALPHA1 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA1 ) * sinf( beta ); + } + // 61..72: -X cap ring alpha=pi/3 + for ( int i = 0; i < CAPSULE_SLICES; ++i, ++v ) + { + const float beta = TWO_PI * (float)i / (float)CAPSULE_SLICES; + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -sinf( ALPHA2 ); + outVerts[v].radial[1] = cosf( ALPHA2 ) * cosf( beta ); + outVerts[v].radial[2] = cosf( ALPHA2 ) * sinf( beta ); + } + // 73: -X pole + outVerts[v].axis[0] = -1.0f; + outVerts[v].axis[1] = 0.0f; + outVerts[v].axis[2] = 0.0f; + outVerts[v].radial[0] = -1.0f; + outVerts[v].radial[1] = 0.0f; + outVerts[v].radial[2] = 0.0f; + ++v; + + // Indices + int index = 0; + + // Body: ring -X (verts 0..11) to ring +X (verts 12..23). For slice i + // and i+1, the outward face winds from -X[i] up the slice direction + // (beta increasing) to -X[i+1], across to +X[i+1], down to +X[i]. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + const int mxi = i; // ring -X + const int mxn = next; + const int pxi = 12 + i; // ring +X + const int pxn = 12 + next; + CAPSULE_QUAD( mxi, mxn, pxn, pxi ); + } + + // +X cap: equator (ring +X, 12..23) -> alpha=pi/6 ring (24..35) -> alpha=pi/3 (36..47) -> pole (48). + // Going outward, alpha increases. For slice i to i+1, the outward face + // winds equator[i] -> equator[i+1] -> ring1[i+1] -> ring1[i]. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + CAPSULE_QUAD( 12 + i, 12 + next, 24 + next, 24 + i ); + CAPSULE_QUAD( 24 + i, 24 + next, 36 + next, 36 + i ); + // Fan to pole: tri (ring2[i], ring2[i+1], pole). + outIndices[index++] = (uint32_t)( 36 + i ); + outIndices[index++] = (uint32_t)( 36 + next ); + outIndices[index++] = (uint32_t)48; + } + + // -X cap: equator (ring -X, 0..11) -> alpha=pi/6 ring (49..60) -> alpha=pi/3 (61..72) -> pole (73). + // Winding flipped relative to +X cap because the outward normal points + // toward -X, the "outside-front" side of each quad swaps slice order. + for ( int i = 0; i < CAPSULE_SLICES; ++i ) + { + const int next = ( i + 1 ) % CAPSULE_SLICES; + CAPSULE_QUAD( 0 + next, 0 + i, 49 + i, 49 + next ); + CAPSULE_QUAD( 49 + next, 49 + i, 61 + i, 61 + next ); + // Fan to pole: tri (ring2[i+1], ring2[i], pole), opposite winding to +X. + outIndices[index++] = (uint32_t)( 61 + next ); + outIndices[index++] = (uint32_t)( 61 + i ); + outIndices[index++] = (uint32_t)73; + } +} + +#undef CAPSULE_QUAD + // On the GL backend, set clip-space Z to [0,1] so the rasterizer's // gl_FragCoord.z matches what the impostor shaders write into gl_FragDepth // (hit_clip.z / hit_clip.w). Default GL clip space is [-1,1], remapped by @@ -575,10 +900,30 @@ void InitRenderer( const sg_environment* env ) s_gfx.shadowGeomPipelineMirror = sg_make_pipeline( &shadowGeomMirrorPdesc ); // Shadow caster pipeline: spheres - // Rasterizes the bounding cube the lit impostor uses, so it borrows the - // cube's buffers and vertex format. Culling stays on back faces: the - // shader's conservative-depth promise only holds while the rasterized - // surface is the light-facing one. + // Build the ico-sphere proxy once and upload to a + // dedicated vbo/ibo. Position-only vertex layout (no normals, the + // caster shader never reads them). + { + float icoVerts[ICO_SPHERE_VERTICES][3]; + uint32_t icoIndices[ICO_SPHERE_INDICES]; + BuildIcosphere( icoVerts, icoIndices ); + s_gfx.icosphereIndexCount = ICO_SPHERE_INDICES; + + sg_buffer_desc ivdesc = { 0 }; + ivdesc.usage.vertex_buffer = true; + ivdesc.data.ptr = icoVerts; + ivdesc.data.size = sizeof( icoVerts ); + ivdesc.label = "icosphere_verts"; + s_gfx.icosphereVbuf = sg_make_buffer( &ivdesc ); + + sg_buffer_desc iidesc = { 0 }; + iidesc.usage.index_buffer = true; + iidesc.data.ptr = icoIndices; + iidesc.data.size = sizeof( icoIndices ); + iidesc.label = "icosphere_indices"; + s_gfx.icosphereIbuf = sg_make_buffer( &iidesc ); + } + s_gfx.shadowSphereShader = sg_make_shader( shadow_sphere_caster_shader_desc( sg_query_backend() ) ); sg_pipeline_desc shadowSpherePdesc = { 0 }; @@ -586,7 +931,7 @@ void InitRenderer( const sg_environment* env ) shadowSpherePdesc.layout.buffers[0].stride = sizeof( float ) * 3; shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3; shadowSpherePdesc.layout.attrs[ATTR_shadow_sphere_caster_in_pos].buffer_index = 0; - shadowSpherePdesc.index_type = SG_INDEXTYPE_UINT16; + shadowSpherePdesc.index_type = SG_INDEXTYPE_UINT32; shadowSpherePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; shadowSpherePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; shadowSpherePdesc.depth.compare = SG_COMPAREFUNC_LESS; @@ -597,16 +942,40 @@ void InitRenderer( const sg_environment* env ) shadowSpherePdesc.label = "shadow_sphere_pipeline"; s_gfx.shadowSpherePipeline = sg_make_pipeline( &shadowSpherePdesc ); - // Shadow caster pipeline: capsules, see the sphere caster above. The - // OBB comes from the same cube buffers. + // Shadow caster pipeline: capsules + { + CapsuleVertex capsVerts[CAPSULE_VERTICES]; + uint32_t capsIndices[CAPSULE_INDICES]; + BuildCapsuleProxy( capsVerts, capsIndices ); + s_gfx.capsuleProxyIndexCount = CAPSULE_INDICES; + + sg_buffer_desc cvdesc = { 0 }; + cvdesc.usage.vertex_buffer = true; + cvdesc.data.ptr = capsVerts; + cvdesc.data.size = sizeof( capsVerts ); + cvdesc.label = "capsule_proxy_verts"; + s_gfx.capsuleProxyVbuf = sg_make_buffer( &cvdesc ); + + sg_buffer_desc cidesc = { 0 }; + cidesc.usage.index_buffer = true; + cidesc.data.ptr = capsIndices; + cidesc.data.size = sizeof( capsIndices ); + cidesc.label = "capsule_proxy_indices"; + s_gfx.capsuleProxyIbuf = sg_make_buffer( &cidesc ); + } + s_gfx.shadowCapsuleShader = sg_make_shader( shadow_capsule_caster_shader_desc( sg_query_backend() ) ); sg_pipeline_desc shadowCapsulePdesc = { 0 }; shadowCapsulePdesc.shader = s_gfx.shadowCapsuleShader; - shadowCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 3; - shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_pos].format = SG_VERTEXFORMAT_FLOAT3; - shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_pos].buffer_index = 0; - shadowCapsulePdesc.index_type = SG_INDEXTYPE_UINT16; + shadowCapsulePdesc.layout.buffers[0].stride = sizeof( float ) * 6; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].format = SG_VERTEXFORMAT_FLOAT3; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].buffer_index = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_axis].offset = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].format = SG_VERTEXFORMAT_FLOAT3; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].buffer_index = 0; + shadowCapsulePdesc.layout.attrs[ATTR_shadow_capsule_caster_in_radial].offset = sizeof( float ) * 3; + shadowCapsulePdesc.index_type = SG_INDEXTYPE_UINT32; shadowCapsulePdesc.colors[0].pixel_format = SG_PIXELFORMAT_NONE; shadowCapsulePdesc.depth.pixel_format = SG_PIXELFORMAT_DEPTH; shadowCapsulePdesc.depth.compare = SG_COMPAREFUNC_LESS; @@ -858,7 +1227,6 @@ void InitRenderer( const sg_environment* env ) HighlightMaskInit(); InitHighlightOutline(); OverlayInit(); - WorldTextInit(); s_gfx.swapchainColorFormat = env->defaults.color_format; s_gfx.sun.dirToSun = b3Normalize( (b3Vec3){ 0.5f, 0.8f, 0.4f } ); @@ -934,35 +1302,6 @@ static b3Vec3 TransformDir( Mat4 m, b3Vec3 v ) return (b3Vec3){ r.x, r.y, r.z }; } -// The lit shaders carry their own SHADOW_CASCADE_COUNT, and nothing links it -// to the one here. Check the generated layout instead, so a half-finished -// change is a build error rather than a cascade that silently never receives -// its matrix, or a fill loop that runs off the end of the array into the -// uniforms behind it. Every shader that takes cascades needs its own check, -// since they are generated one at a time. Tripping this means regenerating -// the shaders. -_Static_assert( sizeof( ( (ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT, - "cube shader cascade count differs from SHADOW_CASCADE_COUNT" ); -_Static_assert( sizeof( ( (sphere_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT, - "sphere shader cascade count differs from SHADOW_CASCADE_COUNT" ); -_Static_assert( sizeof( ( (capsule_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT, - "capsule shader cascade count differs from SHADOW_CASCADE_COUNT" ); -_Static_assert( sizeof( ( (geom_ub_pass_t*)0 )->cascade_matrices ) / sizeof( Mat4 ) == SHADOW_CASCADE_COUNT, - "geom shader cascade count differs from SHADOW_CASCADE_COUNT" ); - -// One vec4 lane per cascade, which is what caps the count at four. Lanes past -// the count stay zero, so a shader built for more would read unlit rather than -// garbage. -static Vec4 PackCascades( float ( *get )( int cascade ) ) -{ - float lanes[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) - { - lanes[i] = get( i ); - } - return MakeVec4( lanes[0], lanes[1], lanes[2], lanes[3] ); -} - static sg_pass_action MakeSceneClear( void ) { sg_pass_action a = { 0 }; @@ -1038,17 +1377,6 @@ static void DrawShadowCascade( int cascade ) const Mat4 lightVP = GetCascadeMatrix( cascade ); bool viewportApplied = false; - // Impostor casters march along the light from the proxy face they - // rasterized, then turn the hit into clip depth themselves. Both - // quantities come out of the projection's depth row, which under an - // orthographic light varies only along the light axis: its gradient - // is the direction light travels, and it is the row that maps a - // world position to depth. Reading the direction back off the matrix - // rather than off the sun keeps the two from drifting apart. - const Vec4 lightDepthRow = MakeVec4( lightVP.cx.z, lightVP.cy.z, lightVP.cz.z, lightVP.cw.z ); - const b3Vec3 lightDir = b3Normalize( ( b3Vec3 ){ lightDepthRow.x, lightDepthRow.y, lightDepthRow.z } ); - const Vec4 lightDirPacked = MakeVec4( lightDir.x, lightDir.y, lightDir.z, 0.0f ); - // Cubes if ( s_gfx.cubeCount > 0 ) { @@ -1075,7 +1403,7 @@ static void DrawShadowCascade( int cascade ) sg_pop_debug_group(); } - // Spheres + // Spheres (low-poly icosphere proxy) if ( s_gfx.sphereCount > 0 ) { sg_push_debug_group( "caster_sphere" ); @@ -1086,26 +1414,22 @@ static void DrawShadowCascade( int cascade ) } sg_apply_pipeline( s_gfx.shadowSpherePipeline ); sg_bindings bindings = { 0 }; - bindings.vertex_buffers[0] = s_gfx.vbuf; - bindings.index_buffer = s_gfx.ibuf; + bindings.vertex_buffers[0] = s_gfx.icosphereVbuf; + bindings.index_buffer = s_gfx.icosphereIbuf; bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstView; sg_apply_bindings( &bindings ); shadow_sphere_ub_frame_t sub = { 0 }; sub.light_view_proj = lightVP; sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) ); - shadow_sphere_ub_pass_t supass = { 0 }; - supass.light_dir = lightDirPacked; - supass.depth_row = lightDepthRow; - sg_apply_uniforms( UB_shadow_sphere_ub_pass, &SG_RANGE( supass ) ); shadow_sphere_ub_draw_t sudraw = { 0 }; sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) ); - sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.sphereCount ); + sg_draw( 0, s_gfx.icosphereIndexCount, (int)s_gfx.sphereCount ); sg_pop_debug_group(); } - // Capsules + // Capsules (cylinder + caps proxy) if ( s_gfx.capsuleCount > 0 ) { sg_push_debug_group( "caster_capsule" ); @@ -1116,22 +1440,18 @@ static void DrawShadowCascade( int cascade ) } sg_apply_pipeline( s_gfx.shadowCapsulePipeline ); sg_bindings bindings = { 0 }; - bindings.vertex_buffers[0] = s_gfx.vbuf; - bindings.index_buffer = s_gfx.ibuf; + bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf; + bindings.index_buffer = s_gfx.capsuleProxyIbuf; bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstView; sg_apply_bindings( &bindings ); shadow_capsule_ub_frame_t cub = { 0 }; cub.light_view_proj = lightVP; sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) ); - shadow_capsule_ub_pass_t cupass = { 0 }; - cupass.light_dir = lightDirPacked; - cupass.depth_row = lightDepthRow; - sg_apply_uniforms( UB_shadow_capsule_ub_pass, &SG_RANGE( cupass ) ); shadow_capsule_ub_draw_t cudraw = { 0 }; sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) ); - sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), (int)s_gfx.capsuleCount ); + sg_draw( 0, s_gfx.capsuleProxyIndexCount, (int)s_gfx.capsuleCount ); sg_pop_debug_group(); } @@ -1230,18 +1550,14 @@ static void DrawShadowCascade( int cascade ) } sg_apply_pipeline( s_gfx.shadowSpherePipeline ); sg_bindings bindings = { 0 }; - bindings.vertex_buffers[0] = s_gfx.vbuf; - bindings.index_buffer = s_gfx.ibuf; + bindings.vertex_buffers[0] = s_gfx.icosphereVbuf; + bindings.index_buffer = s_gfx.icosphereIbuf; bindings.views[VIEW_shadow_sphere_instances] = s_gfx.sphereInstViewXp; sg_apply_bindings( &bindings ); shadow_sphere_ub_frame_t sub = { 0 }; sub.light_view_proj = lightVP; sg_apply_uniforms( UB_shadow_sphere_ub_frame, &SG_RANGE( sub ) ); - shadow_sphere_ub_pass_t supass = { 0 }; - supass.light_dir = lightDirPacked; - supass.depth_row = lightDepthRow; - sg_apply_uniforms( UB_shadow_sphere_ub_pass, &SG_RANGE( supass ) ); for ( size_t i = 0; i < s_gfx.sphereCountXp; ++i ) { @@ -1250,7 +1566,7 @@ static void DrawShadowCascade( int cascade ) shadow_sphere_ub_draw_t sudraw = { 0 }; sudraw.inst_base[0] = (int)i; sg_apply_uniforms( UB_shadow_sphere_ub_draw, &SG_RANGE( sudraw ) ); - sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + sg_draw( 0, s_gfx.icosphereIndexCount, 1 ); } sg_pop_debug_group(); } @@ -1265,18 +1581,14 @@ static void DrawShadowCascade( int cascade ) } sg_apply_pipeline( s_gfx.shadowCapsulePipeline ); sg_bindings bindings = { 0 }; - bindings.vertex_buffers[0] = s_gfx.vbuf; - bindings.index_buffer = s_gfx.ibuf; + bindings.vertex_buffers[0] = s_gfx.capsuleProxyVbuf; + bindings.index_buffer = s_gfx.capsuleProxyIbuf; bindings.views[VIEW_shadow_capsule_instances] = s_gfx.capsuleInstViewXp; sg_apply_bindings( &bindings ); shadow_capsule_ub_frame_t cub = { 0 }; cub.light_view_proj = lightVP; sg_apply_uniforms( UB_shadow_capsule_ub_frame, &SG_RANGE( cub ) ); - shadow_capsule_ub_pass_t cupass = { 0 }; - cupass.light_dir = lightDirPacked; - cupass.depth_row = lightDepthRow; - sg_apply_uniforms( UB_shadow_capsule_ub_pass, &SG_RANGE( cupass ) ); for ( size_t i = 0; i < s_gfx.capsuleCountXp; ++i ) { @@ -1285,7 +1597,7 @@ static void DrawShadowCascade( int cascade ) shadow_capsule_ub_draw_t cudraw = { 0 }; cudraw.inst_base[0] = (int)i; sg_apply_uniforms( UB_shadow_capsule_ub_draw, &SG_RANGE( cudraw ) ); - sg_draw( 0, (int)( sizeof( CUBE_INDICES ) / sizeof( CUBE_INDICES[0] ) ), 1 ); + sg_draw( 0, s_gfx.capsuleProxyIndexCount, 1 ); } sg_pop_debug_group(); } @@ -1368,12 +1680,9 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram // flip). The shader multiplies NDC.y by this before mapping to UV.y. const sg_backend backend = sg_query_backend(); const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; - const Vec4 shadowParams = MakeVec4( uvYSign, GetShadowTexelSize(), 0.0f, 0.0f ); - const Vec4 cascadeFarViewZ = PackCascades( GetCascadeFarViewZ ); - const Vec4 cascadeTexelWorld = PackCascades( GetCascadeTexelWorld ); - const Vec4 cascadeDepthBias = PackCascades( GetCascadeDepthBias ); - Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT]; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign ); + Mat4 cascadeMatrices[3]; + for ( int i = 0; i < 3; ++i ) { cascadeMatrices[i] = GetCascadeMatrix( i ); } @@ -1417,10 +1726,7 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram up.sun_color = sunColor; up.flags[0] = frame->debugMode; up.cascade_far_view_z = cascadeFarViewZ; - up.cascade_texel_world = cascadeTexelWorld; - up.cascade_depth_bias = cascadeDepthBias; - up.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) up.cascade_matrices[i] = cascadeMatrices[i]; up.view = frame->view; up.camera_pos_world = MakeVec4( frame->cameraPosition.x, frame->cameraPosition.y, frame->cameraPosition.z, 0.0f ); @@ -1468,10 +1774,7 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram sup.view_proj = viewProj; sup.view = frame->view; sup.cascade_far_view_z = cascadeFarViewZ; - sup.cascade_texel_world = cascadeTexelWorld; - sup.cascade_depth_bias = cascadeDepthBias; - sup.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) sup.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) { @@ -1514,10 +1817,7 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram cup.view_proj = viewProj; cup.view = frame->view; cup.cascade_far_view_z = cascadeFarViewZ; - cup.cascade_texel_world = cascadeTexelWorld; - cup.cascade_depth_bias = cascadeDepthBias; - cup.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) cup.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) { @@ -1569,10 +1869,7 @@ static void DrawScene( int targetWidth, int targetHeight, const FrameInput* fram gup.grid_offset = MakeVec4( frame->gridWrap.x, frame->gridWrap.y, frame->drawOrigin.x, frame->drawOrigin.z ); gup.view = frame->view; gup.cascade_far_view_z = cascadeFarViewZ; - gup.cascade_texel_world = cascadeTexelWorld; - gup.cascade_depth_bias = cascadeDepthBias; - gup.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) gup.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) { @@ -1981,12 +2278,9 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput* const sg_backend backend = sg_query_backend(); const float uvYSign = ( backend == SG_BACKEND_GLCORE || backend == SG_BACKEND_GLES3 ) ? 1.0f : -1.0f; - const Vec4 shadowParams = MakeVec4( uvYSign, GetShadowTexelSize(), 0.0f, 0.0f ); - const Vec4 cascadeFarViewZ = PackCascades( GetCascadeFarViewZ ); - const Vec4 cascadeTexelWorld = PackCascades( GetCascadeTexelWorld ); - const Vec4 cascadeDepthBias = PackCascades( GetCascadeDepthBias ); - Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT]; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + const Vec4 cascadeFarViewZ = MakeVec4( GetCascadeFarViewZ( 0 ), GetCascadeFarViewZ( 1 ), GetCascadeFarViewZ( 2 ), uvYSign ); + Mat4 cascadeMatrices[3]; + for ( int i = 0; i < 3; ++i ) { cascadeMatrices[i] = GetCascadeMatrix( i ); } @@ -2019,10 +2313,7 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput* cubePass.sun_color = sunColor; cubePass.flags[0] = frame->debugMode; cubePass.cascade_far_view_z = cascadeFarViewZ; - cubePass.cascade_texel_world = cascadeTexelWorld; - cubePass.cascade_depth_bias = cascadeDepthBias; - cubePass.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) { cubePass.cascade_matrices[i] = cascadeMatrices[i]; } @@ -2044,10 +2335,7 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput* spherePass.view_proj = view_proj; spherePass.view = frame->view; spherePass.cascade_far_view_z = cascadeFarViewZ; - spherePass.cascade_texel_world = cascadeTexelWorld; - spherePass.cascade_depth_bias = cascadeDepthBias; - spherePass.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) spherePass.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) spherePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); @@ -2063,10 +2351,7 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput* capsulePass.view_proj = view_proj; capsulePass.view = frame->view; capsulePass.cascade_far_view_z = cascadeFarViewZ; - capsulePass.cascade_texel_world = cascadeTexelWorld; - capsulePass.cascade_depth_bias = cascadeDepthBias; - capsulePass.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) capsulePass.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) capsulePass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); @@ -2083,10 +2368,7 @@ static void DrawTransparentIntoResolve( int width, int height, const FrameInput* geomPass.grid_offset = MakeVec4( frame->gridWrap.x, frame->gridWrap.y, frame->drawOrigin.x, frame->drawOrigin.z ); geomPass.view = frame->view; geomPass.cascade_far_view_z = cascadeFarViewZ; - geomPass.cascade_texel_world = cascadeTexelWorld; - geomPass.cascade_depth_bias = cascadeDepthBias; - geomPass.shadow_params = shadowParams; - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) + for ( int i = 0; i < 3; ++i ) geomPass.cascade_matrices[i] = cascadeMatrices[i]; for ( int i = 0; i < 9; ++i ) geomPass.sh[i] = MakeVec4( iblSh[i].x, iblSh[i].y, iblSh[i].z, 0.0f ); @@ -2383,12 +2665,6 @@ void RenderFrame( const sg_swapchain* swapChain, const FrameInput* frame ) frame->cameraPosition, frame->time, GetLinearDepthSampleView(), GetAOLinearSampler(), swapChain->color_format, swapChain->depth_format ); sg_pop_debug_group(); - // World labels ride the same pass as the overlays, after them so a label - // reads on top of the primitive it names. - sg_push_debug_group( "world_text" ); - WorldTextSubmit( swapChain->width, swapChain->height, &frame->view, &frame->viewInv, &frame->proj, &frame->projInv, - frame->cameraPosition, frame->time, swapChain->color_format, swapChain->depth_format ); - sg_pop_debug_group(); sg_end_pass(); sg_pop_debug_group(); @@ -2451,10 +2727,6 @@ void RenderFrameOffscreen( const sg_attachments* attachments, sg_pixel_format ou OverlaySubmit( width, height, &frame->view, &frame->viewInv, &frame->proj, &frame->projInv, frame->cameraPosition, frame->time, GetLinearDepthSampleView(), GetAOLinearSampler(), outputFormat, SG_PIXELFORMAT_NONE ); sg_pop_debug_group(); - sg_push_debug_group( "world_text" ); - WorldTextSubmit( width, height, &frame->view, &frame->viewInv, &frame->proj, &frame->projInv, frame->cameraPosition, - frame->time, outputFormat, SG_PIXELFORMAT_NONE ); - sg_pop_debug_group(); sg_end_pass(); sg_pop_debug_group(); @@ -2568,7 +2840,6 @@ int GetCubeProxyIndexCount( void ) void ShutdownRenderer( void ) { OverlayShutdown(); - WorldTextShutdown(); ShutdownHighlightOutline(); HighlightMaskShutdown(); ShutdownHighlightTarget(); @@ -2589,8 +2860,12 @@ void ShutdownRenderer( void ) ShutdownSky(); sg_destroy_pipeline( s_gfx.shadowCapsulePipeline ); sg_destroy_shader( s_gfx.shadowCapsuleShader ); + sg_destroy_buffer( s_gfx.capsuleProxyIbuf ); + sg_destroy_buffer( s_gfx.capsuleProxyVbuf ); sg_destroy_pipeline( s_gfx.shadowSpherePipeline ); sg_destroy_shader( s_gfx.shadowSphereShader ); + sg_destroy_buffer( s_gfx.icosphereIbuf ); + sg_destroy_buffer( s_gfx.icosphereVbuf ); sg_destroy_pipeline( s_gfx.shadowGeomPipelineMirror ); sg_destroy_pipeline( s_gfx.shadowGeomPipeline ); sg_destroy_shader( s_gfx.shadowGeomShader ); diff --git a/samples/gfx/shadow.c b/samples/gfx/shadow.c index 5f55f35..3e2b161 100644 --- a/samples/gfx/shadow.c +++ b/samples/gfx/shadow.c @@ -3,52 +3,43 @@ #include "gfx/shadow.h" -#include "gfx/draw.h" - #include #include #include -// Cascade fitting parameters. The split range defaults (SHADOW_SPLIT_NEAR / -// SHADOW_SPLIT_FAR, in shadow.h) are *view-space* distances from the camera +// Cascade fitting parameters. SHADOW_SPLIT_NEAR and the default far +// (SHADOW_SPLIT_FAR, in shadow.h) are *view-space* distances from the camera // (positive). CSM quality at distance falls off fast, so cascades focus on // near content. // // PSSM_LAMBDA blends the uniform split scheme (each cascade covers an // equal slice of view-space distance) and the logarithmic scheme (each // cascade covers an equal multiplicative range). 0 = pure uniform, -// 1 = pure log, 0.5 is the standard sweet spot. Raising it tightens the -// near cascades but drags the boundaries inward, so the last cascade -// takes over closer to the camera where its coarser texels show. This is -// the starting value, SetShadowSplitLambda overrides it. +// 1 = pure log. 0.5 is the sweet spot at the default range. The blend is +// pushed toward log up to PSSM_LAMBDA_MAX as the range widens, otherwise a +// large far would balloon the near cascade and coarsen close-up shadows. // // CASTER_MARGIN_M expands the orthographic light frustum's near edge // toward the sun so casters above the camera frustum slice (e.g. the // building roof at y=3 when the slice itself only reaches y=1) still cast // onto receivers inside the slice. -// DEPTH_BIAS_TEXELS is what remains of the comparison bias once the lit -// shaders offset the lookup along the surface normal. It only has to -// cover depth quantization, so it is measured in texels of the cascade -// that owns it rather than in a fixed world size that would be wrong at -// one end or the other of a wide split range. +#define SHADOW_SPLIT_NEAR 0.1f #define PSSM_LAMBDA 0.5f +#define PSSM_LAMBDA_MAX 0.9f #define CASTER_MARGIN_M 50.0f -#define DEPTH_BIAS_TEXELS 0.5f static struct { b3Vec3 sunDir; // world-space dir TO sun, normalized float splitNear; // PSSM split range near (positive view-Z) float splitFar; // PSSM split range far (positive view-Z) - float splitLambda; // uniform/log blend for the split scheme + float splitLambda; // uniform/log split blend, widens with range sg_image depthArray; // D32F, cascade layers sg_view cascadeAttachmentViews[SHADOW_CASCADE_COUNT]; // depth-stencil view per cascade sg_view sampleView; // full-array texture-sample view sg_sampler sampler; // comparison sampler (LESS_EQUAL, linear PCF) Mat4 cascadeMatrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade float cascadeFarViewZ[SHADOW_CASCADE_COUNT]; // far end (positive view-Z) per cascade - float cascadeTexelWorld[SHADOW_CASCADE_COUNT]; // one shadow texel in world length units - float cascadeDepthBias[SHADOW_CASCADE_COUNT]; // residual bias in shadow clip-Z units bool inPass; // safety against unbalanced begin/end } s_shadow; @@ -60,24 +51,16 @@ static inline float ComputeSplitDistance( int i, int cascadeCount, float nearZ, const float fi = (float)i / (float)cascadeCount; const float u = nearZ + ( farZ - nearZ ) * fi; const float l = nearZ * powf( farZ / nearZ, fi ); - const float lambda = s_shadow.splitLambda; - return lambda * l + ( 1.0f - lambda ) * u; + return s_shadow.splitLambda * l + ( 1.0f - s_shadow.splitLambda ) * u; } -// MakePerspectiveAndInverse puts proj[1][1] = 1/tan(fovY/2) and -// proj[0][0] = proj[1][1] / aspect. The analytic inverse stores both -// quantities directly, so callers holding either matrix can recover the -// frustum shape. -static inline void PerspectiveShape( const Mat4* proj, float* tanHalfFovY, float* aspect ) +// Push the uniform/log blend toward log as the split range widens, so the near +// cascade stays tight when far is large. Anchored at the default range so the +// reference scenes keep the 0.5 sweet spot. +static inline float SplitLambdaForRange( float nearZ, float farZ ) { - *tanHalfFovY = ( proj->cy.y != 0.0f ) ? ( 1.0f / proj->cy.y ) : 1.0f; - *aspect = ( proj->cx.x != 0.0f ) ? ( proj->cy.y / proj->cx.x ) : 1.0f; -} - -static inline void PerspectiveShapeFromInverse( const Mat4* projInv, float* tanHalfFovY, float* aspect ) -{ - *tanHalfFovY = projInv->cy.y; - *aspect = ( projInv->cy.y != 0.0f ) ? ( projInv->cx.x / projInv->cy.y ) : 1.0f; + float decades = log10f( ( farZ / nearZ ) / ( SHADOW_SPLIT_FAR / SHADOW_SPLIT_NEAR ) ); + return b3ClampFloat( PSSM_LAMBDA + 0.4f * decades, PSSM_LAMBDA, PSSM_LAMBDA_MAX ); } // Fill cornersOut with the 8 world-space corners of the camera frustum @@ -87,14 +70,18 @@ static inline void PerspectiveShapeFromInverse( const Mat4* projInv, float* tanH // Camera basis comes straight from `viewInv` (the camera's world matrix // produced by mat4ViewAndInverse): column 0 is right, column 1 is up, // column 2 is back (i.e., -forward), column 3 is eye, no inversion. -static void FrustumSliceCornersWorld( const Mat4* viewInv, float tanHalfFovY, float aspect, float nearZ, float farZ, - b3Vec3 cornersOut[8] ) +// FovY and aspect are read from the projection matrix: mat4Perspective +// puts proj[1][1] = 1/tan(fovY/2) and proj[0][0] = proj[1][1] / aspect. +static void FrustumSliceCornersWorld( const Mat4* viewInv, const Mat4* proj, float nearZ, float farZ, b3Vec3 cornersOut[8] ) { const b3Vec3 eye = { viewInv->cw.x, viewInv->cw.y, viewInv->cw.z }; const b3Vec3 right = { viewInv->cx.x, viewInv->cx.y, viewInv->cx.z }; const b3Vec3 up = { viewInv->cy.x, viewInv->cy.y, viewInv->cy.z }; const b3Vec3 forward = { -viewInv->cz.x, -viewInv->cz.y, -viewInv->cz.z }; + const float tanHalfFovY = ( proj->cy.y != 0.0f ) ? ( 1.0f / proj->cy.y ) : 1.0f; + const float aspect = ( proj->cx.x != 0.0f ) ? ( proj->cy.y / proj->cx.x ) : 1.0f; + const float distances[2] = { nearZ, farZ }; for ( int s = 0; s < 2; ++s ) { @@ -113,16 +100,29 @@ static void FrustumSliceCornersWorld( const Mat4* viewInv, float tanHalfFovY, fl } } -// Bound a frustum slice by a world-space sphere: centroid of the 8 -// corners, plus the max distance from it to any of them. The sphere is -// rotation-invariant. Rotating the camera around its eye doesn't change -// the radius, which is the key property that lets the texel-snap -// stabilization avoid swimming edges. -static void SliceBoundingSphere( const Mat4* viewInv, float tanHalfFovY, float aspect, float nearZ, float farZ, - b3Vec3* centerOut, float* radiusOut ) +// Fit one cascade's light-space view-projection matrix to the camera +// frustum slice [nearZ, farZ] for the configured sun direction. +// +// The slice is bounded by a *world-space sphere* (centroid + max radius +// from centroid to any slice corner). The sphere is rotation-invariant. +// Rotating the camera around its eye doesn't move it, which is the key +// property that lets the texel-snap stabilization avoid swimming edges. +// +// Light view: orthonormal frame whose -Z axis points toward the sun. +// Light proj: orthographic, sized to enclose the sphere. The near plane +// is pushed back along +sun by CASTER_MARGIN_M so casters between the +// slice and the sun are not clipped. +// +// Texel-snap: after the unsnapped lightVP is built, transform the slice +// center through it to clip space, round the resulting clip-space xy to +// the nearest texel grid step, and apply the rounding delta as a +// post-translation. This pins the cascade to a fixed grid in light +// space, small camera motions no longer cause the shadow texels to +// drift relative to the casters. +static Mat4 FitCascade( const Mat4* viewInv, const Mat4* proj, b3Vec3 dirToSun, float nearZ, float farZ ) { b3Vec3 corners[8]; - FrustumSliceCornersWorld( viewInv, tanHalfFovY, aspect, nearZ, farZ, corners ); + FrustumSliceCornersWorld( viewInv, proj, nearZ, farZ, corners ); b3Vec3 center = b3Vec3_zero; for ( int i = 0; i < 8; ++i ) @@ -146,34 +146,6 @@ static void SliceBoundingSphere( const Mat4* viewInv, float tanHalfFovY, float a radius = 0.01f; } - *centerOut = center; - *radiusOut = radius; -} - -// Fit one cascade's light-space view-projection matrix to the camera -// frustum slice [nearZ, farZ] for the configured sun direction. -// -// Light view: orthonormal frame whose -Z axis points toward the sun. -// Light proj: orthographic, sized to enclose the sphere. The near plane -// is pushed back along +sun by CASTER_MARGIN_M so casters between the -// slice and the sun are not clipped. -// -// Texel-snap: quantize the sphere center onto a world-anchored lattice -// aligned with the light's own axes, one texel of world per step, then -// build the light matrices around the snapped center. Camera motion now -// slides the cascade in whole texels, so shadow edges step instead of -// crawling. -// -// It has to happen here, on the center, and not by projecting the center -// through the finished lightVP: the center is the look-at target, so it -// lands on clip (0, 0) by construction and rounding it is a no-op. -static Mat4 FitCascade( const Mat4* viewInv, float tanHalfFovY, float aspect, b3Vec3 dirToSun, float nearZ, float farZ, - float* radiusOut ) -{ - b3Vec3 center; - float radius; - SliceBoundingSphere( viewInv, tanHalfFovY, aspect, nearZ, farZ, ¢er, &radius ); - // Avoid a degenerate up vector when the sun is straight up/down. b3Vec3 up = b3Vec3_axisY; if ( fabsf( dirToSun.y ) > 0.999f ) @@ -181,47 +153,28 @@ static Mat4 FitCascade( const Mat4* viewInv, float tanHalfFovY, float aspect, b3 up = b3Vec3_axisZ; } - // Light axes, matching the basis MakeLookAt derives below. The eye sits - // along +sun from the target, so the light looks along -sun. These - // depend only on the sun and the up choice, never on the camera, which - // is what makes the lattice hold still. - const b3Vec3 forward = { -dirToSun.x, -dirToSun.y, -dirToSun.z }; - const b3Vec3 lightRight = b3Normalize( b3Cross( forward, up ) ); - const b3Vec3 lightUp = b3Cross( lightRight, forward ); - - // Radius is fixed for a given split, field of view and aspect, so the - // lattice step is fixed too and the same world points keep landing on - // the same texels frame to frame. - const float texelWorld = 2.0f * radius / (float)SHADOW_RESOLUTION; - - // Geometry reaches the GPU shifted against the draw origin, which - // tracks the camera, so the eye sits at this frame's origin and the - // frame slides whenever the camera does. Anchoring the lattice here - // would drag it along and quantize against a moving reference, which - // is the crawl the snap exists to remove. Fold the draw origin back in - // and snap the absolute coordinate, in double so the fractional part - // within a texel survives far from the origin. - const b3Pos drawOrigin = GetDrawOrigin(); - const double ox = (double)lightRight.x * (double)drawOrigin.x + (double)lightRight.y * (double)drawOrigin.y + - (double)lightRight.z * (double)drawOrigin.z; - const double oy = (double)lightUp.x * (double)drawOrigin.x + (double)lightUp.y * (double)drawOrigin.y + - (double)lightUp.z * (double)drawOrigin.z; - - const double step = (double)texelWorld; - const double ax = ox + (double)b3Dot( lightRight, center ); - const double ay = oy + (double)b3Dot( lightUp, center ); - center = b3MulAdd( center, (float)( round( ax / step ) * step - ax ), lightRight ); - center = b3MulAdd( center, (float)( round( ay / step ) * step - ay ), lightUp ); - // Place the light eye behind the sphere along +sun. Far clip extends // past the sphere's back face. Near clip pulls forward by // CASTER_MARGIN_M to admit casters above the slice. const b3Vec3 eyeWorld = b3MulAdd( center, radius + CASTER_MARGIN_M, dirToSun ); const Mat4 lightView = MakeLookAt( eyeWorld, center, up ); const Mat4 lightProj = MakeOrthographic( -radius, radius, -radius, radius, 0.0f, 2.0f * radius + CASTER_MARGIN_M ); + Mat4 lightVP = MulMM4( lightProj, lightView ); - *radiusOut = radius; - return MulMM4( lightProj, lightView ); + // Texel-snap stabilization. Transform the sphere center through the + // unsnapped lightVP. Project to texel coords, round, convert the + // delta back to clip space, and add as a post-translation. + const Vec4 centerClip = MulMV4( lightVP, MakeVec4( center.x, center.y, center.z, 1.0f ) ); + const float halfRes = (float)SHADOW_RESOLUTION * 0.5f; + const float texX = centerClip.x * halfRes; + const float texY = centerClip.y * halfRes; + const float dx = ( roundf( texX ) - texX ) / halfRes; + const float dy = ( roundf( texY ) - texY ) / halfRes; + + Mat4 snapMat = MakeIdentity(); + snapMat.cw.x = dx; + snapMat.cw.y = dy; + return MulMM4( snapMat, lightVP ); } void InitShadows( void ) @@ -229,16 +182,7 @@ void InitShadows( void ) s_shadow.sunDir = b3Normalize( (b3Vec3){ 0.5f, 0.8f, 0.4f } ); s_shadow.splitNear = SHADOW_SPLIT_NEAR; s_shadow.splitFar = SHADOW_SPLIT_FAR; - s_shadow.splitLambda = PSSM_LAMBDA; - - // The lit shaders divide by the texel size to scale the filter against - // cascade zero, so leaving these zero until the first FitShadows would - // render a frame of NaN. This is what a unit cascade radius works out to, - // which makes every ratio one. - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) - { - s_shadow.cascadeTexelWorld[i] = 2.0f / (float)SHADOW_RESOLUTION; - } + s_shadow.splitLambda = SplitLambdaForRange( s_shadow.splitNear, s_shadow.splitFar ); sg_image_desc desc = { 0 }; desc.type = SG_IMAGETYPE_ARRAY; @@ -276,22 +220,13 @@ void InitShadows( void ) // the receiver's reference depth is <= the stored depth, i.e., the // receiver is the closest surface to the light. Linear PCF: each // texture call returns a 2x2 weighted compare-result mix. - // - // White border means taps past a cascade edge compare against the far - // plane and come back lit, which dissolves the boundary across the - // filter kernel. That is what lets the lit shaders drop their hard - // bounds test, and the hard test is what used to flip whole pixels - // between sampled and lit as the texel snap stepped the map. Clamping - // to edge instead would smear the border texel outward and streak - // shadows across everything past the cascade. sg_sampler_desc sdesc = { 0 }; sdesc.min_filter = SG_FILTER_LINEAR; sdesc.mag_filter = SG_FILTER_LINEAR; sdesc.mipmap_filter = SG_FILTER_NEAREST; - sdesc.wrap_u = SG_WRAP_CLAMP_TO_BORDER; - sdesc.wrap_v = SG_WRAP_CLAMP_TO_BORDER; + sdesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; + sdesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; sdesc.wrap_w = SG_WRAP_CLAMP_TO_EDGE; - sdesc.border_color = SG_BORDERCOLOR_OPAQUE_WHITE; sdesc.compare = SG_COMPAREFUNC_LESS_EQUAL; sdesc.label = "shadow_compare_sampler"; s_shadow.sampler = sg_make_sampler( &sdesc ); @@ -321,6 +256,7 @@ void SetShadowSplits( float nearViewZ, float farViewZ ) s_shadow.splitNear = nearViewZ; s_shadow.splitFar = farViewZ; + s_shadow.splitLambda = SplitLambdaForRange( nearViewZ, farViewZ ); } void SetShadowSplitFar( float farViewZ ) @@ -328,26 +264,6 @@ void SetShadowSplitFar( float farViewZ ) SetShadowSplits( s_shadow.splitNear, farViewZ ); } -float GetShadowSplitNear( void ) -{ - return s_shadow.splitNear; -} - -float GetShadowSplitFar( void ) -{ - return s_shadow.splitFar; -} - -void SetShadowSplitLambda( float lambda ) -{ - s_shadow.splitLambda = b3ClampFloat( lambda, 0.0f, 1.0f ); -} - -float GetShadowSplitLambda( void ) -{ - return s_shadow.splitLambda; -} - void SetShadowSunDir( b3Vec3 dirToSun ) { const float lenSq = dirToSun.x * dirToSun.x + dirToSun.y * dirToSun.y + dirToSun.z * dirToSun.z; @@ -367,65 +283,13 @@ void FitShadows( const Mat4* viewInv, const Mat4* proj ) splits[i] = ComputeSplitDistance( i, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar ); } - float tanHalfFovY, aspect; - PerspectiveShape( proj, &tanHalfFovY, &aspect ); - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) { - float radius = 0.0f; - s_shadow.cascadeMatrices[i] = - FitCascade( viewInv, tanHalfFovY, aspect, s_shadow.sunDir, splits[i], splits[i + 1], &radius ); + s_shadow.cascadeMatrices[i] = FitCascade( viewInv, proj, s_shadow.sunDir, splits[i], splits[i + 1] ); s_shadow.cascadeFarViewZ[i] = splits[i + 1]; - - // The ortho half-extent is the sphere radius, so the map covers - // 2 * radius of world across its resolution. - const float texelWorld = 2.0f * radius / (float)SHADOW_RESOLUTION; - s_shadow.cascadeTexelWorld[i] = texelWorld; - - // Shadow clip-Z spans the whole orthographic depth range, and the - // caster margin inflates that range without covering any more - // receiver. Sizing the bias in world units here decouples it, so - // the margin costs caster headroom and nothing else. - const float depthRange = 2.0f * radius + CASTER_MARGIN_M; - s_shadow.cascadeDepthBias[i] = ( DEPTH_BIAS_TEXELS * texelWorld ) / depthRange; } } -void GetShadowCasterBounds( const Mat4* viewInv, const Mat4* projInv, b3Vec3* loOut, b3Vec3* hiOut ) -{ - float tanHalfFovY, aspect; - PerspectiveShapeFromInverse( projInv, &tanHalfFovY, &aspect ); - - b3Vec3 lo = { FLT_MAX, FLT_MAX, FLT_MAX }; - b3Vec3 hi = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; - - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) - { - const float nearZ = ComputeSplitDistance( i, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar ); - const float farZ = ComputeSplitDistance( i + 1, SHADOW_CASCADE_COUNT, s_shadow.splitNear, s_shadow.splitFar ); - - b3Vec3 center; - float radius; - SliceBoundingSphere( viewInv, tanHalfFovY, aspect, nearZ, farZ, ¢er, &radius ); - - // A caster can only darken a receiver in this sphere if it sits - // between the two, so sweep the sphere toward the sun rather than - // growing it in every direction. Sweeping by the caster margin - // lands the front face exactly on the cascade's near plane. - const b3Vec3 swept = b3MulAdd( center, CASTER_MARGIN_M, s_shadow.sunDir ); - - lo.x = b3MinFloat( lo.x, b3MinFloat( center.x, swept.x ) - radius ); - lo.y = b3MinFloat( lo.y, b3MinFloat( center.y, swept.y ) - radius ); - lo.z = b3MinFloat( lo.z, b3MinFloat( center.z, swept.z ) - radius ); - hi.x = b3MaxFloat( hi.x, b3MaxFloat( center.x, swept.x ) + radius ); - hi.y = b3MaxFloat( hi.y, b3MaxFloat( center.y, swept.y ) + radius ); - hi.z = b3MaxFloat( hi.z, b3MaxFloat( center.z, swept.z ) + radius ); - } - - *loOut = lo; - *hiOut = hi; -} - void BeginShadowPass( int cascade ) { if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) @@ -470,24 +334,6 @@ float GetCascadeFarViewZ( int cascade ) return s_shadow.cascadeFarViewZ[cascade]; } -float GetCascadeTexelWorld( int cascade ) -{ - if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) - { - return 0.0f; - } - return s_shadow.cascadeTexelWorld[cascade]; -} - -float GetCascadeDepthBias( int cascade ) -{ - if ( cascade < 0 || cascade >= SHADOW_CASCADE_COUNT ) - { - return 0.0f; - } - return s_shadow.cascadeDepthBias[cascade]; -} - sg_view GetShadowSampleView( void ) { return s_shadow.sampleView; diff --git a/samples/gfx/shadow.h b/samples/gfx/shadow.h index 409c078..829cbe3 100644 --- a/samples/gfx/shadow.h +++ b/samples/gfx/shadow.h @@ -42,41 +42,13 @@ extern "C" { #endif -// Must match SHADOW_CASCADE_COUNT in shaders/common/shadow_cascade.glsl, -// which the renderer static asserts against the generated uniform layout. -// Changing it needs a shader regen (BOX3D_BUILD_SHADERS=ON) to reach the -// committed headers. Four is the ceiling: per-cascade values ride in vec4 -// lanes and a fifth would need a second vec4 for each of them. -// -// More cascades cannot sharpen the last one. It always has to reach the far -// split, so its texel is pinned near 2 * k * far / resolution with k set by -// the field of view. What they buy is a finer near cascade and a smaller -// step at each boundary, both at the cost of another shadow pass. -#define SHADOW_CASCADE_COUNT 4 -#define SHADOW_RESOLUTION 4096 +#define SHADOW_CASCADE_COUNT 3 +#define SHADOW_RESOLUTION 2048 -// Default cascade split range, view-space distance from the camera. Scenes -// smaller than the far end keep the default range, larger ones widen it. -// -// The near end sits nowhere near the camera near plane on purpose. It says -// where the split distribution starts, not where shadows start: the first -// cascade's bounding sphere reaches back past the eye whatever this is, so -// close content is covered either way. Starting out at working distance is -// what puts the whole volume being looked at inside the first cascade, -// rather than spending it on the metre in front of the lens and leaving two -// boundaries sitting in the middle of the scene. The cost is a first cascade -// stretched to reach that far, so it trades sharpness for uniformity. -#define SHADOW_SPLIT_NEAR 10.0f +// Default cascade far split, view-space distance from the camera. Scenes +// smaller than this keep the default range, larger ones widen it. #define SHADOW_SPLIT_FAR 50.0f -// Ceiling on that widening. The last cascade always has to reach the far -// split, so its texel size is set by this number alone and nothing else -// in the fit affects it. Letting a scene push it out coarsens the far -// cascade until its shadows read as blocks, and widens the step from the -// cascade before it. A scene that genuinely needs more reach should ask -// for it rather than have it inferred from how big its ground is. -#define SHADOW_SPLIT_FAR_MAX 80.0f - void InitShadows( void ); void ShutdownShadows( void ); @@ -84,26 +56,15 @@ void ShutdownShadows( void ); void SetShadowSunDir( b3Vec3 dirToSun ); // Override the view-space distance range PSSM splits over. Defaults to -// (SHADOW_SPLIT_NEAR, SHADOW_SPLIT_FAR), sufficient for the reference scenes -// but wrong for a scene watched from far off, where the near end wastes whole -// cascades on the empty space in front of the camera. Pass (0, 0) to restore -// defaults. +// (0.1, SHADOW_SPLIT_FAR), sufficient for the reference scenes but too short +// for larger ones. The split blend is derived from the range, so a wider far +// keeps the near cascade tight. Pass (0, 0) to restore defaults. void SetShadowSplits( float nearViewZ, float farViewZ ); // Fit the cascade far split to a scene of this view-space depth, keeping the -// current near. +// current near and recomputing the split blend. void SetShadowSplitFar( float farViewZ ); -float GetShadowSplitNear( void ); -float GetShadowSplitFar( void ); - -// Blend between the two PSSM split schemes. 0 puts every boundary at an -// equal slice of distance, 1 at an equal multiplicative step. Raising it -// tightens the near cascades at the cost of dragging every boundary toward -// the camera, so the coarse far cascade takes over sooner. -void SetShadowSplitLambda( float lambda ); -float GetShadowSplitLambda( void ); - // Recompute per-cascade light-space matrices and split distances for the // camera frustum described by viewInv + proj. viewInv (the camera's world // matrix) supplies eye + basis directly, so the slice-corner walk does no @@ -112,18 +73,6 @@ float GetShadowSplitLambda( void ); // boundaries to avoid swimming edges as the camera moves. void FitShadows( const Mat4* viewInv, const Mat4* proj ); -// World-space AABB enclosing every shape that can cast into the cascades: -// each slice's bounding sphere swept toward the sun by the caster margin. -// It reaches well outside the camera frustum, which is the point. A host -// culling its draw submission to the visible volume drops casters that -// belong in the shadow map, and their shadows vanish. -// -// Derived from the camera alone, so it can be queried before FitShadows -// runs for the frame. Takes projInv because that is what the draw path -// already carries. Bounds come back in the same frame viewInv maps into, -// so a caller working against a shifted draw origin must offset them. -void GetShadowCasterBounds( const Mat4* viewInv, const Mat4* projInv, b3Vec3* loOut, b3Vec3* hiOut ); - // Begin / end the depth-only render pass for a cascade. Bind this as // the surrounding pass before issuing caster draws into the cascade. void BeginShadowPass( int cascade ); @@ -138,28 +87,14 @@ Mat4 GetCascadeMatrix( int cascade ); // these to pick which cascade to sample. float GetCascadeFarViewZ( int cascade ); -// One shadow texel measured in world length units for a cascade. Lit -// shaders scale the normal offset by this so every cascade biases by the -// same visual amount regardless of how much world it covers. The ratio -// against cascade 0 also shrinks the PCF kernel in the coarser cascades, -// which keeps the penumbra a constant world width instead of jumping at -// every cascade boundary. -float GetCascadeTexelWorld( int cascade ); - -// Residual comparison bias for a cascade, in shadow clip-Z units. The -// normal offset carries the slope term, this only has to cover depth -// quantization. Sized on the CPU because shadow clip-Z spans the whole -// orthographic range, which differs per cascade. -float GetCascadeDepthBias( int cascade ); - // Bound by lit pipelines once for sampling across all cascades. The view // is the depth array's full-array sampling view. Per-cascade selection // happens inside the shader by passing `cascade` as the layer index. sg_view GetShadowSampleView( void ); sg_sampler GetShadowSampler( void ); -// One-texel size in shadow UV space (1 / SHADOW_RESOLUTION). Lit shaders -// use this to size PCF taps and the cascade-edge reject. +// One-texel size in shadow space (1 / SHADOW_RESOLUTION). Lit shaders +// use this to size PCF taps and slope-scale bias. float GetShadowTexelSize( void ); #ifdef __cplusplus diff --git a/samples/gfx/text.c b/samples/gfx/text.c index 8417a9c..3bf0a9d 100644 --- a/samples/gfx/text.c +++ b/samples/gfx/text.c @@ -1,10 +1,6 @@ // SPDX-FileCopyrightText: 2026 Erin Catto // SPDX-License-Identifier: MIT -#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS ) -#define _CRT_SECURE_NO_WARNINGS -#endif - #include "gfx/text.h" #include diff --git a/samples/gfx/text.h b/samples/gfx/text.h index d127c89..636541d 100644 --- a/samples/gfx/text.h +++ b/samples/gfx/text.h @@ -52,8 +52,6 @@ void DrawString( b3Vec3 worldPos, Vec4 color, const char* text ); // Submit a UTF-8 string at a screen-pixel position (origin top-left, Y down, // framebuffer pixels). Same copy/truncation/overflow rules as DrawString. void DrawScreenString( int x, int y, Vec4 color, const char* text ); - -B3_PRINTF_FORMAT( 4, 5 ) void DrawScreenStringFormat( int x, int y, Vec4 color, const char* fmt, ... ); // Iteration surface for the GUI shell. Pointers/strings are valid until diff --git a/samples/gfx/world_text.c b/samples/gfx/world_text.c deleted file mode 100644 index 13c3f4d..0000000 --- a/samples/gfx/world_text.c +++ /dev/null @@ -1,523 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#if defined( _MSC_VER ) && !defined( _CRT_SECURE_NO_WARNINGS ) -#define _CRT_SECURE_NO_WARNINGS -#endif - -#include "gfx/world_text.h" - -#include "gfx/fonts.h" -#include "gfx/text.h" -#include "world_text.glsl.h" - -#define STB_TRUETYPE_IMPLEMENTATION -#include "stb_truetype.h" - -#include -#include -#include -#include -#include - -// Printable ASCII. Labels are numbers, ids and short type names, so this -// range covers everything the samples emit. Anything outside draws as '?'. -#define FIRST_CHAR 32 -#define CHAR_COUNT 95 - -// Distance range carried around each outline, in pixels. The halo fades inside -// it, so this bounds how far the fade can reach. -#define SDF_PADDING 4 -#define SDF_ONEDGE 128 - -// One transparent column and row between packed glyphs so a bilinear tap at -// a glyph edge cannot reach its neighbour. -#define GLYPH_GAP 1 - -#define ATLAS_DIM 512 - -// 1024 labels of 32 characters, matching text.c's label cap. Overflow drops -// glyphs rather than growing. -#define MAX_GLYPHS 32768 - -// The swap chain (color + depth) and the color-only offscreen test target. -// Mirrors overlay.c's cache. -#define TEXT_MAX_PIPELINES 2 - -// Pen-relative glyph box and atlas window. The box is in pixels and whole, so a -// quad placed at a whole pixel covers its atlas cell one texel to one pixel. The -// advance stays fractional: rounding every advance instead of every origin would -// drift the whole word. -typedef struct Glyph -{ - float x0, y0, x1, y1; // origin at the top left of the line box, Y down - float u0, v0, u1, v1; - float advance; -} Glyph; - -static struct -{ - Glyph glyphs[CHAR_COUNT]; - - // Built from scratch inside each submit rather than accumulated across the - // frame, so a flat array beats the arena the overlay needs. - world_text_glyph_instance_t* instances; - int glyphCount; - - sg_shader shader; - sg_image atlas; - sg_view atlasView; - sg_sampler atlasSampler; - - sg_buffer instBuf; - sg_view instView; - - struct - { - sg_pixel_format colorFormat; - sg_pixel_format depthFormat; - sg_pipeline pipeline; - } pipelines[TEXT_MAX_PIPELINES]; - int pipelineCount; - - float pixelHeight; - float haloPixels; - - bool ready; -} s_text; - -// Rasterize printable ASCII into one RG8 atlas and fill the glyph table. R is a -// coverage bitmap, G a distance field, both from the same outlines at the same -// scale so they agree on where the edge is. -// -// The bake tracks the size labels draw at, which is what buys the glyph body its -// crispness: a coverage bitmap sampled one texel to one pixel is exactly what a -// UI font renderer puts on screen, and no distance field reproduces that at 14 -// pixels because it cannot grid fit. The halo has no such constraint, so it -// keeps the field, which is smooth at any size and gives a fade for free. -// -// Packing is a shelf: glyphs from a single bake size have near-uniform heights, -// so rows waste little and this stands in for a real rect packer. -static bool BakeAtlas( void ) -{ - int fontSize = 0; - const unsigned char* fontData = GetFontBytes( &fontSize ); - - stbtt_fontinfo font; - if ( stbtt_InitFont( &font, fontData, stbtt_GetFontOffsetForIndex( fontData, 0 ) ) == 0 ) - { - fprintf( stderr, "[world_text] stbtt_InitFont failed on %d embedded bytes of %s\n", fontSize, GetFontName() ); - return false; - } - - // ScaleForPixelHeight makes ascent-to-descent exactly the label height. - const float scale = stbtt_ScaleForPixelHeight( &font, s_text.pixelHeight ); - int ascent, descent, lineGap; - stbtt_GetFontVMetrics( &font, &ascent, &descent, &lineGap ); - - // Whole pixels, so a glyph box stays whole and lands on the pixel grid. A - // fractional baseline would put every horizontal stroke between two rows. - const float ascentPixels = floorf( (float)ascent * scale + 0.5f ); - - unsigned char* atlas = (unsigned char*)calloc( (size_t)ATLAS_DIM * ATLAS_DIM * 2, 1 ); - if ( atlas == NULL ) - { - return false; - } - - const float invDim = 1.0f / (float)ATLAS_DIM; - const float distanceScale = (float)SDF_ONEDGE / (float)SDF_PADDING; - - int penX = 0; - int penY = 0; - int shelfHeight = 0; - bool ok = true; - - for ( int i = 0; i < CHAR_COUNT; ++i ) - { - const int codepoint = FIRST_CHAR + i; - Glyph* glyph = &s_text.glyphs[i]; - memset( glyph, 0, sizeof( *glyph ) ); - - int advance, leftBearing; - stbtt_GetCodepointHMetrics( &font, codepoint, &advance, &leftBearing ); - glyph->advance = (float)advance * scale; - - int w = 0, h = 0, xoff = 0, yoff = 0; - unsigned char* sdf = - stbtt_GetCodepointSDF( &font, scale, codepoint, SDF_PADDING, SDF_ONEDGE, distanceScale, &w, &h, &xoff, &yoff ); - if ( sdf == NULL ) - { - // Space and friends carry an advance but no outline. - continue; - } - - if ( penX + w > ATLAS_DIM ) - { - penX = 0; - penY += shelfHeight; - shelfHeight = 0; - } - if ( penY + h > ATLAS_DIM ) - { - fprintf( stderr, "[world_text] atlas full at codepoint %d, raise ATLAS_DIM or lower the label size\n", codepoint ); - stbtt_FreeSDF( sdf, NULL ); - ok = false; - break; - } - - for ( int row = 0; row < h; ++row ) - { - unsigned char* dst = atlas + ( (size_t)( penY + row ) * ATLAS_DIM + penX ) * 2; - const unsigned char* src = sdf + (size_t)row * w; - for ( int col = 0; col < w; ++col ) - { - dst[col * 2 + 1] = src[col]; - } - } - - // The coverage bitmap shares the cell. stb derives both boxes from the - // same glyph box and only the field pads it, so the offsets differ by - // exactly the padding, but take it from the reported corners anyway. - int bw = 0, bh = 0, bxoff = 0, byoff = 0; - unsigned char* bitmap = stbtt_GetCodepointBitmap( &font, scale, scale, codepoint, &bw, &bh, &bxoff, &byoff ); - if ( bitmap != NULL ) - { - const int insetX = bxoff - xoff; - const int insetY = byoff - yoff; - for ( int row = 0; row < bh; ++row ) - { - const int y = insetY + row; - if ( y < 0 || y >= h ) - { - continue; - } - unsigned char* dst = atlas + ( (size_t)( penY + y ) * ATLAS_DIM + penX ) * 2; - const unsigned char* src = bitmap + (size_t)row * bw; - for ( int col = 0; col < bw; ++col ) - { - const int x = insetX + col; - if ( x >= 0 && x < w ) - { - dst[x * 2] = src[col]; - } - } - } - stbtt_FreeBitmap( bitmap, NULL ); - } - - // stb reports the box against the baseline with Y down. Shift it to - // the top of the line box so an anchor lands where ImGui put it, and - // existing call sites that pad with leading spaces still read right. - glyph->x0 = (float)xoff; - glyph->y0 = (float)yoff + ascentPixels; - glyph->x1 = (float)( xoff + w ); - glyph->y1 = (float)yoff + ascentPixels + (float)h; - - glyph->u0 = (float)penX * invDim; - glyph->v0 = (float)penY * invDim; - glyph->u1 = (float)( penX + w ) * invDim; - glyph->v1 = (float)( penY + h ) * invDim; - - penX += w + GLYPH_GAP; - if ( h + GLYPH_GAP > shelfHeight ) - { - shelfHeight = h + GLYPH_GAP; - } - - stbtt_FreeSDF( sdf, NULL ); - } - - if ( ok ) - { - // A resize rebakes, so drop whatever the last size produced. - if ( s_text.atlasView.id != 0 ) - { - sg_destroy_view( s_text.atlasView ); - s_text.atlasView.id = 0; - } - if ( s_text.atlas.id != 0 ) - { - sg_destroy_image( s_text.atlas ); - s_text.atlas.id = 0; - } - - sg_image_desc imgDesc = { 0 }; - imgDesc.width = ATLAS_DIM; - imgDesc.height = ATLAS_DIM; - imgDesc.num_mipmaps = 1; - imgDesc.pixel_format = SG_PIXELFORMAT_RG8; - imgDesc.data.mip_levels[0].ptr = atlas; - imgDesc.data.mip_levels[0].size = (size_t)ATLAS_DIM * ATLAS_DIM * 2; - imgDesc.label = "world_text_atlas"; - s_text.atlas = sg_make_image( &imgDesc ); - - sg_view_desc viewDesc = { 0 }; - viewDesc.texture.image = s_text.atlas; - viewDesc.label = "world_text_atlas_view"; - s_text.atlasView = sg_make_view( &viewDesc ); - - if ( s_text.atlasSampler.id == 0 ) - { - // Nearest would do for the body, which is sampled one texel to one - // pixel, but the field wants filtering at the cell edges. - sg_sampler_desc sampDesc = { 0 }; - sampDesc.min_filter = SG_FILTER_LINEAR; - sampDesc.mag_filter = SG_FILTER_LINEAR; - sampDesc.wrap_u = SG_WRAP_CLAMP_TO_EDGE; - sampDesc.wrap_v = SG_WRAP_CLAMP_TO_EDGE; - sampDesc.label = "world_text_atlas_sampler"; - s_text.atlasSampler = sg_make_sampler( &sampDesc ); - } - } - - free( atlas ); - return ok; -} - -// Lazily create (and cache) the pipeline for one output format pair, same -// scheme and same blend state as overlay.c. Depth compare is ALWAYS with -// writes off: a label is meant to be read, so it draws over whatever the -// scene put in front of it. -static bool EnsurePipeline( sg_pixel_format colorFormat, sg_pixel_format depthFormat, sg_pipeline* outPipeline ) -{ - for ( int i = 0; i < s_text.pipelineCount; ++i ) - { - if ( s_text.pipelines[i].colorFormat == colorFormat && s_text.pipelines[i].depthFormat == depthFormat ) - { - *outPipeline = s_text.pipelines[i].pipeline; - return true; - } - } - if ( s_text.pipelineCount >= TEXT_MAX_PIPELINES ) - { - fprintf( stderr, "[world_text] pipeline cache exhausted (max %d format pairs)\n", TEXT_MAX_PIPELINES ); - return false; - } - - sg_pipeline_desc pdesc = { 0 }; - pdesc.shader = s_text.shader; - // No VBO / no IBO, the VS expands six vertices per instance. - pdesc.index_type = SG_INDEXTYPE_NONE; - pdesc.cull_mode = SG_CULLMODE_NONE; - pdesc.colors[0].pixel_format = colorFormat; - pdesc.color_count = 1; - // Premultiplied-alpha blend. The FS emits premultiplied color, which is - // also what makes the halo work: alpha without color resolves to black. - pdesc.colors[0].blend.enabled = true; - pdesc.colors[0].blend.src_factor_rgb = SG_BLENDFACTOR_ONE; - pdesc.colors[0].blend.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; - pdesc.colors[0].blend.op_rgb = SG_BLENDOP_ADD; - pdesc.colors[0].blend.src_factor_alpha = SG_BLENDFACTOR_ONE; - pdesc.colors[0].blend.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; - pdesc.colors[0].blend.op_alpha = SG_BLENDOP_ADD; - pdesc.depth.pixel_format = depthFormat; - pdesc.depth.compare = SG_COMPAREFUNC_ALWAYS; - pdesc.depth.write_enabled = false; - pdesc.sample_count = 1; - pdesc.label = "world_text_pipeline"; - const sg_pipeline pipeline = sg_make_pipeline( &pdesc ); - - s_text.pipelines[s_text.pipelineCount].colorFormat = colorFormat; - s_text.pipelines[s_text.pipelineCount].depthFormat = depthFormat; - s_text.pipelines[s_text.pipelineCount].pipeline = pipeline; - ++s_text.pipelineCount; - - *outPipeline = pipeline; - return true; -} - -void WorldTextInit( void ) -{ - if ( s_text.ready ) - { - return; - } - - s_text.pixelHeight = floorf( 13.0f * sapp_dpi_scale() ); - s_text.haloPixels = 2.0f; - - if ( BakeAtlas() == false ) - { - return; - } - - s_text.instances = (world_text_glyph_instance_t*)malloc( (size_t)MAX_GLYPHS * sizeof( world_text_glyph_instance_t ) ); - if ( s_text.instances == NULL ) - { - fprintf( stderr, "[world_text] failed to allocate glyph instances\n" ); - - // Clean up - sg_destroy_sampler( s_text.atlasSampler ); - s_text.atlasSampler.id = 0; - sg_destroy_view( s_text.atlasView ); - s_text.atlasView.id = 0; - sg_destroy_image( s_text.atlas ); - s_text.atlas.id = 0; - - return; - } - - sg_buffer_desc bufDesc = { 0 }; - bufDesc.usage.storage_buffer = true; - bufDesc.usage.stream_update = true; - bufDesc.size = (size_t)MAX_GLYPHS * sizeof( world_text_glyph_instance_t ); - bufDesc.label = "world_text_glyph_instances"; - s_text.instBuf = sg_make_buffer( &bufDesc ); - - sg_view_desc instViewDesc = { 0 }; - instViewDesc.storage_buffer.buffer = s_text.instBuf; - instViewDesc.label = "world_text_glyph_instances_view"; - s_text.instView = sg_make_view( &instViewDesc ); - - s_text.shader = sg_make_shader( world_text_prog_shader_desc( sg_query_backend() ) ); - - s_text.ready = true; -} - -void WorldTextShutdown( void ) -{ - if ( !s_text.ready ) - { - return; - } - for ( int i = 0; i < s_text.pipelineCount; ++i ) - { - sg_destroy_pipeline( s_text.pipelines[i].pipeline ); - s_text.pipelines[i].pipeline.id = 0; - s_text.pipelines[i].colorFormat = SG_PIXELFORMAT_NONE; - s_text.pipelines[i].depthFormat = SG_PIXELFORMAT_NONE; - } - s_text.pipelineCount = 0; - sg_destroy_shader( s_text.shader ); - s_text.shader.id = 0; - sg_destroy_view( s_text.instView ); - s_text.instView.id = 0; - sg_destroy_buffer( s_text.instBuf ); - s_text.instBuf.id = 0; - sg_destroy_sampler( s_text.atlasSampler ); - s_text.atlasSampler.id = 0; - sg_destroy_view( s_text.atlasView ); - s_text.atlasView.id = 0; - sg_destroy_image( s_text.atlas ); - s_text.atlas.id = 0; - free( s_text.instances ); - s_text.instances = NULL; - s_text.glyphCount = 0; - s_text.ready = false; -} - -// Walk this frame's labels and lay each one out into glyph quads. Advances -// accumulate along the pen, so a label's characters share an anchor and differ -// only in their pen offset, which keeps the whole string bill-boarding as one. -// The pen accumulates fractionally and each origin rounds off it, so spacing -// stays true across a word while every glyph still starts on a whole pixel. -static void BuildGlyphs( void ) -{ - s_text.glyphCount = 0; - - const int count = GetTextCount(); - - for ( int i = 0; i < count; ++i ) - { - const TextEntry* entry = GetTextAt( i ); - if ( entry->space != TEXT_SPACE_WORLD ) - { - continue; - } - - const Vec4 color = entry->color; - float pen = 0.0f; - - for ( const char* p = entry->text; *p != '\0'; ++p ) - { - int index = (unsigned char)*p - FIRST_CHAR; - if ( index < 0 || index >= CHAR_COUNT ) - { - index = '?' - FIRST_CHAR; - } - const Glyph* glyph = &s_text.glyphs[index]; - - // Space has an advance but no box, and nothing else should reach - // the rasterizer with zero area either. - if ( glyph->x1 > glyph->x0 && glyph->y1 > glyph->y0 ) - { - if ( s_text.glyphCount >= MAX_GLYPHS ) - { - return; - } - const float originX = floorf( pen + 0.5f ); - - world_text_glyph_instance_t* inst = &s_text.instances[s_text.glyphCount]; - inst->anchor = MakeVec4( entry->worldPos.x, entry->worldPos.y, entry->worldPos.z, 0.0f ); - inst->rect = MakeVec4( originX + glyph->x0, glyph->y0, glyph->x1 - glyph->x0, glyph->y1 - glyph->y0 ); - inst->uv = MakeVec4( glyph->u0, glyph->v0, glyph->u1, glyph->v1 ); - inst->color = color; - s_text.glyphCount++; - } - - pen += glyph->advance; - } - } -} - -void WorldTextSubmit( int width, int height, const Mat4* view, const Mat4* viewInv, const Mat4* proj, const Mat4* projInv, - b3Vec3 cameraPos, float time, sg_pixel_format colorFormat, sg_pixel_format depthFormat ) -{ - if ( !s_text.ready ) - { - return; - } - - BuildGlyphs(); - if ( s_text.glyphCount == 0 ) - { - return; - } - - sg_pipeline pipeline = { 0 }; - if ( !EnsurePipeline( colorFormat, depthFormat, &pipeline ) ) - { - return; - } - - const Mat4 view_proj = MulMM4( *proj, *view ); - // inv(P*V) = inv(V)*inv(P), see overlay.c for why both inverses arrive - // prebuilt rather than being inverted here. - const Mat4 inv_view_proj = MulMM4( *viewInv, *projInv ); - const float w = (float)width; - const float h = (float)height; - - world_text_ub_frame_t ub = { 0 }; - ub.view = *view; - ub.proj = *proj; - ub.view_proj = view_proj; - ub.inv_view_proj = inv_view_proj; - ub.camera_pos = MakeVec4( cameraPos.x, cameraPos.y, cameraPos.z, time ); - ub.viewport = MakeVec4( w, h, w > 0.0f ? 1.0f / w : 0.0f, h > 0.0f ? 1.0f / h : 0.0f ); - - // Halo width in pixels plus the distance one pixel spans, which the bake fixes - // since the field is rasterized at the size it draws at. The field saturates - // SDF_PADDING pixels out, so that is the ceiling on the fade. - world_text_ub_text_style_t styleUb = { 0 }; - const float distancePerPixel = ( (float)SDF_ONEDGE / (float)SDF_PADDING ) / 255.0f; - styleUb.style_params = MakeVec4( s_text.haloPixels, (float)SDF_ONEDGE / 255.0f, distancePerPixel, 0.0f ); - - // .w is strength at the glyph edge - styleUb.halo_params = MakeVec4( 0.2f, 0.2f, 0.2f, 0.2f ); - - sg_range instanceRange; - instanceRange.ptr = s_text.instances; - instanceRange.size = (size_t)s_text.glyphCount * sizeof( world_text_glyph_instance_t ); - sg_update_buffer( s_text.instBuf, &instanceRange ); - - sg_apply_pipeline( pipeline ); - sg_bindings bindings = { 0 }; - bindings.views[VIEW_world_text_glyph_instances] = s_text.instView; - bindings.views[VIEW_world_text_tex_sdf] = s_text.atlasView; - bindings.samplers[SMP_world_text_smp_sdf] = s_text.atlasSampler; - sg_apply_bindings( &bindings ); - sg_apply_uniforms( UB_world_text_ub_frame, &SG_RANGE( ub ) ); - sg_apply_uniforms( UB_world_text_ub_text_style, &SG_RANGE( styleUb ) ); - sg_draw( 0, 6, s_text.glyphCount ); -} diff --git a/samples/gfx/world_text.h b/samples/gfx/world_text.h deleted file mode 100644 index 0d04fee..0000000 --- a/samples/gfx/world_text.h +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// World-space text: rasterized glyphs over a distance field halo. -// -// Owns the glyph atlas, one pipeline, and a per-frame glyph instance arena. -// Labels themselves are not submitted here: text.c already collects them via -// DrawString, and this module drains the world-space ones at submit time and -// turns each character into a quad. Screen-space labels stay with ImGui, -// which is the right tool for something genuinely 2D. -// -// A label anchors at a world point but holds a fixed pixel height and ignores -// scene depth, matching the ImGui labels it replaced. What this buys over those -// is the halo and one draw call for the whole frame. -// -// The atlas bakes at init from the embedded TTF, two channels from one pass of -// stb_truetype: coverage for the glyph body, a distance field for the halo. It -// bakes at the size labels draw at, and the quads land on whole pixels, so the -// body samples one texel to one pixel and reads as crisply as a UI font. A -// distance field alone cannot manage that at 14 pixels, since resolving -// coverage from it means a smoothstep across a good part of a stem and there is -// no grid fitting to fall back on. Scale independence is no loss here: labels -// are one fixed size, and a size change just rebakes. -// -// Pass placement matches overlay.c exactly: the renderer calls WorldTextSubmit -// in the post-tone map pass, after tone map and the highlight outline. - -#pragma once - -#include "gfx/utility.h" -#include "sokol_gfx.h" - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Bakes the glyph atlas from the embedded font, so labels do not depend on the -// working directory. Logs and stays inert if the bake fails rather than taking -// the whole app with it. -void WorldTextInit( void ); -void WorldTextShutdown( void ); - -// Encode world label draws into the currently-open render pass. Called once -// per frame from the post-tone map pass, after tone map + highlight outline. -// No-op when no world labels were submitted this frame. -// -// Arguments match OverlaySubmit minus the depth pre-pass views, which labels -// have no use for, see overlay.h for what each one carries. -void WorldTextSubmit( int width, int height, const Mat4* view, const Mat4* viewInv, const Mat4* proj, const Mat4* projInv, - b3Vec3 cameraPos, float time, sg_pixel_format colorFormat, sg_pixel_format depthFormat ); - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/samples/host/camera.cpp b/samples/host/camera.cpp index acafcb6..fdb32f2 100644 --- a/samples/host/camera.cpp +++ b/samples/host/camera.cpp @@ -12,6 +12,7 @@ static constexpr float ORBIT_SENS = 0.005f; // radians per pixel static constexpr float FLY_LOOK_SENS = 0.005f; // radians per pixel static constexpr float PAN_SENS = 0.005f; // meters per pixel per meter of radius static constexpr float RADIAL_ZOOM_SENS = 0.02f; // meters per pixel (alt+right-drag) +static constexpr float FLY_SPEED_STEP = 1.0f; // m/s per scroll tick static constexpr float ZOOM_STEP = 0.9f; // multiplier per scroll tick static constexpr float MIN_DIST = 0.1f; static constexpr float MIN_SPEED = 0.06f; // matches box3d's 0.001*60 @@ -77,7 +78,6 @@ Camera::Camera() , m_fov( 60.0f * DEG_TO_RAD ) , m_near( 0.1f ) , m_far( kViewDistance ) - , m_drawDistance( kViewDistance ) , m_speed( 10.0f ) , m_width( 0 ) , m_height( 0 ) @@ -191,27 +191,6 @@ void Camera::SetOrbit( float yawRadians, float pitchRadians, float radius ) RebuildBasisAndView( *this ); } -void Camera::SetTarget( b3Pos target ) -{ - // The sim->display map is a uniform scale plus an optional quarter turn, so apply it directly - // rather than through the float matrix. In large world mode that keeps the range the pivot is - // double for; a matrix multiply would round it away. - const double s = 1.0 / m_lengthUnitsPerMeter; - m_pivot.x = s * target.x; - if ( m_zUp ) - { - m_pivot.y = s * target.z; - m_pivot.z = -s * target.y; - } - else - { - m_pivot.y = s * target.y; - m_pivot.z = s * target.z; - } - - RebuildBasisAndView( *this ); -} - void Camera::SetView( float yawDegrees, float pitchDegrees, float radius, b3Pos pivot ) { SetPivot( pivot ); @@ -342,12 +321,6 @@ void Camera::OnEvent( const sapp_event* e ) case SAPP_KEYCODE_D: m_dDown = true; break; - case SAPP_KEYCODE_Q: - m_qDown = true; - break; - case SAPP_KEYCODE_E: - m_eDown = true; - break; case SAPP_KEYCODE_LEFT_ALT: case SAPP_KEYCODE_RIGHT_ALT: m_altDown = true; @@ -371,12 +344,6 @@ void Camera::OnEvent( const sapp_event* e ) case SAPP_KEYCODE_D: m_dDown = false; break; - case SAPP_KEYCODE_Q: - m_qDown = false; - break; - case SAPP_KEYCODE_E: - m_eDown = false; - break; case SAPP_KEYCODE_LEFT_ALT: case SAPP_KEYCODE_RIGHT_ALT: m_altDown = false; @@ -395,8 +362,6 @@ void Camera::OnEvent( const sapp_event* e ) m_aDown = false; m_sDown = false; m_dDown = false; - m_qDown = false; - m_eDown = false; m_altDown = false; break; default: @@ -459,7 +424,6 @@ void Camera::Update( float dt, int width, int height ) float wasdF = 0.0f; // +forward = backwards, since forward = pivot->eye float wasdR = 0.0f; - float wasdU = 0.0f; // Q/E rise and fall, along world up rather than the view basis if ( m_wDown ) wasdF -= 1.0f; if ( m_sDown ) @@ -468,13 +432,9 @@ void Camera::Update( float dt, int width, int height ) wasdR += 1.0f; if ( m_aDown ) wasdR -= 1.0f; - if ( m_eDown ) - wasdU += 1.0f; - if ( m_qDown ) - wasdU -= 1.0f; b3Pos eye = eyeBefore; - if ( wasdF != 0.0f || wasdR != 0.0f || wasdU != 0.0f ) + if ( wasdF != 0.0f || wasdR != 0.0f ) { // Right = normalize(worldUp x forward), matching Box3D's // UpdateTransform. worldUp = (0,1,0). @@ -488,9 +448,9 @@ void Camera::Update( float dt, int width, int height ) right.z /= rlen; } const float step = m_speed * dt; - eye.x += forward.x * wasdF * step + right.x * wasdR * step + worldUp.x * wasdU * step; - eye.y += forward.y * wasdF * step + right.y * wasdR * step + worldUp.y * wasdU * step; - eye.z += forward.z * wasdF * step + right.z * wasdR * step + worldUp.z * wasdU * step; + eye.x += forward.x * wasdF * step + right.x * wasdR * step; + eye.y += forward.y * wasdF * step + right.y * wasdR * step; + eye.z += forward.z * wasdF * step + right.z * wasdR * step; } // Back-derive the pivot so Position() stays consistent and a return @@ -501,7 +461,7 @@ void Camera::Update( float dt, int width, int height ) if ( m_speedScrollAccum != 0.0f ) { - m_speed *= powf( 1.1f, m_speedScrollAccum ); + m_speed += m_speedScrollAccum * FLY_SPEED_STEP; m_speed = b3ClampFloat( m_speed, MIN_SPEED, MAX_SPEED ); } } diff --git a/samples/host/camera.h b/samples/host/camera.h index f2f1f49..4ece431 100644 --- a/samples/host/camera.h +++ b/samples/host/camera.h @@ -11,7 +11,6 @@ // FLY (right mouse held, no Alt) // right-drag : FPS look (yaw/pitch the view direction) // WASD : translate eye along view forward/right at m_speed -// QE : translate eye along world down/up at m_speed // scroll : tune m_speed // // Always @@ -113,12 +112,11 @@ public: { m_pivot = pivot; } - - // Aim at a point given in simulation space: length units and the simulation up axis, mapped - // into the display frame the pivot lives in, then the transform refreshed. Follow cams read - // positions straight from the world, so they land here. Counterpart to DrawOrigin, which maps - // the eye back the other way. SetPivot takes a point already in display space. - void SetTarget( b3Pos target ); + + void SetTarget( b3Pos target ) + { + m_pivot = target; + } // Frame an AABB: keep current yaw/pitch, move pivot to the AABB center, // and refit radius so the AABB fits in view at the current FOV+aspect. @@ -135,12 +133,6 @@ public: m_far = far; } - // Draw/cull box half extent around the eye, in meters. Drives DrawBounds. - void SetDrawDistance( float meters ) - { - m_drawDistance = meters; - } - // Recomputes the projection. Call after any SetFov / SetClip change, or // when the target framebuffer aspect changes outside Update(). void RebuildProj( float aspect ); @@ -172,11 +164,11 @@ public: } // Cull box for b3World_Draw, in simulation space (length units): a cube of the - // draw distance centered on the simulation eye. The broad phase is queried in - // length units, hence the scale. + // view distance centered on the simulation eye, so the draw set matches the far + // plane reach. The broad phase is queried in length units, hence the scale. b3AABB DrawBounds() const { - float h = m_drawDistance * m_lengthUnitsPerMeter; + float h = kViewDistance * m_lengthUnitsPerMeter; b3Vec3 r = { h, h, h }; return b3OffsetAABB( { b3Neg( r ), r }, DrawOrigin() ); } @@ -190,10 +182,6 @@ public: float m_near; float m_far; - // Half extent of the draw/cull box around the eye (meters). Independent of the - // far plane, so it shrinks the draw set without touching the projection. - float m_drawDistance; - // Fly-mode translation speed, m/s. Scroll-tunable while right-mouse held. float m_speed; @@ -219,8 +207,9 @@ public: b3Vec3 m_up; b3Vec3 m_forward; - // All four matrices are produced together: view / viewInv from the basis, - // proj / projInv from fov/aspect/near/far. + // All four matrices are produced together — view / viewInv from the basis, + // proj / projInv from fov/aspect/near/far — so the renderer never inverts + // at runtime. Mat4 m_view; Mat4 m_viewInv; Mat4 m_proj; @@ -254,6 +243,4 @@ public: bool m_aDown = false; bool m_sDown = false; bool m_dDown = false; - bool m_qDown = false; - bool m_eDown = false; }; diff --git a/samples/host/gui.cpp b/samples/host/gui.cpp index 619a27d..006cae2 100644 --- a/samples/host/gui.cpp +++ b/samples/host/gui.cpp @@ -13,11 +13,9 @@ #include "gui.h" #include "gfx/draw.h" -#include "gfx/fonts.h" #include "gfx/projection.h" #include "gfx/renderer.h" #include "gfx/text.h" -#include "gfx/world_text.h" #include "imgui.h" #include "implot.h" #include "sokol_app.h" @@ -137,6 +135,7 @@ void InitUI( const sg_environment* env, DrawUiFcn* drawGuiFcn ) desc.sample_count = env->defaults.sample_count; desc.ini_filename = "imgui.ini"; desc.logger.func = slog_func; + // Skip ImGui's auto-pick so we always get the vector font we add below. desc.no_default_font = true; simgui_setup( &desc ); @@ -169,9 +168,9 @@ void InitUI( const sg_environment* env, DrawUiFcn* drawGuiFcn ) style.ScaleAllSizes( s_uiScale ); } - // 13px base, scaled to a whole physical pixel. Rasterizer density is 1.0 - // (DisplayFramebufferScale 1.0), so the atlas bakes at exactly this - - // floorf keeps it on a whole-pixel size. + // 13px base for the proportional UI font, scaled to a whole physical + // pixel. Rasterizer density is 1.0 (DisplayFramebufferScale 1.0), so the + // atlas bakes at exactly this - floorf keeps it on a whole-pixel size. style.FontSizeBase = floorf( 13.0f * s_uiScale ); s_uiInitialized = true; @@ -289,11 +288,12 @@ void EndPanel( void ) } // Text overlay. Drain the per-frame label arena (filled by DrawString / -// DrawScreenString and the Box3D adapter's DrawString callback). Screen -// entries pass through their pixel position into ImGui's background draw -// list, so labels sit on the scene but under any ImGui windows. World -// entries belong to the SDF pass. The drain runs in StartUIFrame because the calling -// app guarantees RenderFrame already ran this frame, so GetCameraState +// DrawScreenString and the Box3D adapter's DrawString callback). World +// entries project to screen pixels with the last rendered camera, screen +// entries pass through their pixel position, and both emit into ImGui's +// background draw list - labels sit on the scene but under any ImGui +// windows. The drain runs in StartUIFrame because the calling app +// guarantees RenderFrame already ran this frame, so GetCameraState // returns the matrices the scene was actually rasterized with. static void RenderText() { @@ -321,11 +321,6 @@ static void RenderText() for ( int i = 0; i < n; ++i ) { const TextEntry* e = GetTextAt( i ); - if ( e->space == TEXT_SPACE_WORLD ) - { - continue; - } - float sx, sy; if ( !ResolveTextScreenPos( e, cam.view, cam.proj, vpW, vpH, &sx, &sy ) ) { @@ -341,12 +336,8 @@ static void RenderText() v = 1.0f; return (uint32_t)( v * 255.0f + 0.5f ); }; - const uint32_t alpha = byte( e->color.w ); - const uint32_t col = IM_COL32( byte( e->color.x ), byte( e->color.y ), byte( e->color.z ), alpha ); - - const float x = origin.x + sx; - const float y = origin.y + sy; - dl->AddText( nullptr, 0.0f, ImVec2( x, y ), col, e->text ); + const uint32_t col = IM_COL32( byte( e->color.x ), byte( e->color.y ), byte( e->color.z ), byte( e->color.w ) ); + dl->AddText( nullptr, 0.0f, ImVec2( origin.x + sx, origin.y + sy ), col, e->text ); } } diff --git a/samples/host/sokol_app_impl.c b/samples/host/sokol_app_impl.c index 398e2d3..3113529 100644 --- a/samples/host/sokol_app_impl.c +++ b/samples/host/sokol_app_impl.c @@ -8,10 +8,9 @@ // `sokol` INTERFACE target. On Apple this file is compiled as Objective-C // with ARC (see src/app/CMakeLists.txt) so sokol_app's Cocoa backend builds. // -// SOKOL_NO_ENTRY: samples/main.cpp supplies its own main() so it can install -// MSVC CRT leak reporting and dump after sapp_run returns, past sokol's own -// teardown. Our main is console-subsystem, which also keeps stderr flowing to -// ctest for the smoke test. +// SOKOL_WIN32_FORCE_MAIN: sokol_app defaults to WinMain (subsystem:windows) +// on Windows. Our binaries are console-subsystem so the smoke test can +// surface stderr to ctest, so force the int main variant. // // _POSIX_C_SOURCE: glibc gates clock_gettime / CLOCK_MONOTONIC behind a // POSIX feature-test macro under -std=c17. Define before any system headers. @@ -22,7 +21,7 @@ #define SOKOL_APP_IMPL #define SOKOL_GLUE_IMPL #define SOKOL_LOG_IMPL -#define SOKOL_NO_ENTRY +#define SOKOL_WIN32_FORCE_MAIN #include "sokol_gfx.h" #include "sokol_app.h" diff --git a/samples/main.cpp b/samples/main.cpp index 0fe8a6b..2f86d8d 100644 --- a/samples/main.cpp +++ b/samples/main.cpp @@ -1,20 +1,9 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#if defined( _MSC_VER ) -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS -#endif -#define _CRTDBG_MAP_ALLOC -// stdlib before crtdbg so the malloc->_malloc_dbg remap lands after the real prototype -#include -#include -#endif - #include "gfx/debug_adapter.h" #include "gfx/keycodes.h" #include "gfx/renderer.h" -#include "gfx/text.h" #include "host/gui.h" #include "sample.h" #include "sokol_app.h" @@ -29,12 +18,6 @@ #include #include -#ifdef TRACY_ENABLE -#include -#else -#define FrameMark -#endif - #if defined( _WIN32 ) #define WIN32_LEAN_AND_MEAN #define NOMINMAX @@ -49,8 +32,6 @@ static SampleContext s_context; static int s_frame = 0; static int s_frameLimit = -1; static int s_sampleOverride = -1; -static bool s_openReplay = false; -static int s_exitCode = 0; static int CompareSamples( const void* a, const void* b ) { @@ -94,13 +75,10 @@ static void OnDrawUI( void ) static void OnInit( void ) { -#ifdef TRACY_ENABLE - tracy::StartupProfiler(); -#endif - #if defined( _WIN32 ) timeBeginPeriod( 1 ); #endif + const sg_environment env = sglue_environment(); InitRenderer( &env ); InitUI( &env, OnDrawUI ); @@ -136,12 +114,6 @@ static void OnInit( void ) index = s_sampleOverride; } - // Resolved here rather than at parse time because sorting moves the slot. - if ( s_openReplay && g_replayIndex >= 0 ) - { - index = g_replayIndex; - } - SelectSample( &s_context, index, false ); } @@ -168,17 +140,6 @@ static void OnEvent( const sapp_event* e ) s_context.camera.OnEvent( e ); } - // Releases go to the key table even when the UI captures them. Otherwise Ctrl let go - // while the Ctrl+O picker is open stays down in the next sample. - if ( e->type == SAPP_EVENTTYPE_KEY_UP ) - { - SetKeyDown( e->key_code, false ); - } - else if ( e->type == SAPP_EVENTTYPE_UNFOCUSED ) - { - ClearKeysDown(); - } - if ( uiCaptured ) { return; @@ -199,22 +160,11 @@ static void OnEvent( const sapp_event* e ) { switch ( e->key_code ) { - case SAPP_KEYCODE_TAB: - if ( mods & SAPP_MODIFIER_SHIFT ) - { - bool hide = s_context.showUI || s_context.showText; - s_context.showUI = !hide; - s_context.showText = !hide; - } - else - { - // Plain Tab also restores text so it always leads back to the full view - s_context.showUI = !s_context.showUI; - s_context.showText = true; - } + case KEY_TAB: + s_context.showUI = !s_context.showUI; break; - case SAPP_KEYCODE_ESCAPE: + case KEY_ESCAPE: // Layered cancel. An open picker is an ImGui popup that // already swallowed this. So peel the controls window, then // the selection. Quit lives on Ctrl+Q now. @@ -224,15 +174,12 @@ static void OnEvent( const sapp_event* e ) } else { - // The replay viewer redraws the highlight from its own selection every - // frame, so it has to clear that too ClearSelection(); - s_context.sample->Keyboard( e->key_code, ACTION_PRESS, mods ); } break; case KEY_Q: - if ( mods & SAPP_MODIFIER_CTRL ) + if ( mods & MOD_CTRL ) { sapp_request_quit(); break; @@ -241,54 +188,69 @@ static void OnEvent( const sapp_event* e ) break; case KEY_O: - if ( mods & SAPP_MODIFIER_CTRL ) + if ( mods & MOD_CTRL ) { // Ctrl+O opens the fuzzy picker. Force the UI visible so it shows. s_context.showUI = true; s_context.openSamplePicker = true; - break; } - s_context.sample->Keyboard( e->key_code, ACTION_PRESS, mods ); + else + { + s_context.singleStep += ( mods & MOD_SHIFT ) ? 5 : 1; + } break; - // Step forward. Backward is , and only a sample that can rewind - // handles it, so that key falls through to the sample. - case KEY_PERIOD: - s_context.singleStep += ( mods & SAPP_MODIFIER_SHIFT ) ? 5 : 1; - break; - - case SAPP_KEYCODE_P: - case SAPP_KEYCODE_PAUSE: + case KEY_P: + // Pause stays on P. Space is not bound here on purpose. Global + // keys are dispatched before the sample sees them, so claiming + // Space would steal jump from the Mover sample. s_context.pause = !s_context.pause; break; - case SAPP_KEYCODE_M: + case KEY_M: s_context.showMetrics = !s_context.showMetrics; break; - case SAPP_KEYCODE_I: - s_context.showProfile = !s_context.showProfile; - break; - - case SAPP_KEYCODE_R: + case KEY_R: SelectSample( &s_context, s_context.sampleIndex, true ); break; - case SAPP_KEYCODE_LEFT_BRACKET: - SelectSample( &s_context, ( s_context.sampleIndex + g_sampleCount - 1 ) % g_sampleCount, false ); + case KEY_LEFT_BRACKET: + SelectSample( &s_context, b3MaxInt( 0, s_context.sampleIndex - 1 ), false ); break; - case SAPP_KEYCODE_RIGHT_BRACKET: - SelectSample( &s_context, ( s_context.sampleIndex + 1 ) % g_sampleCount, false ); + case KEY_RIGHT_BRACKET: + SelectSample( &s_context, b3MinInt( g_sampleCount - 1, s_context.sampleIndex + 1 ), false ); break; - case SAPP_KEYCODE_F: - FrameSelection( &s_context ); - break; - - case SAPP_KEYCODE_HOME: - s_context.sample->FocusHome(); - break; + case KEY_F: + { + // Frame the selection, or let the sample frame its whole scene when nothing is + // selected. A non-body selection such as a recorded query supplies its own bounds and + // takes priority over the hovered body. The replay viewer's scene lives in a + // player-owned world, not the base world, so the whole-scene case routes through + // FocusHome. + Camera& cam = s_context.camera; + float aspect = cam.m_height > 0 ? (float)cam.m_width / (float)cam.m_height : 1.0f; + b3AABB bounds; + if ( s_context.sample->FocusBounds( &bounds ) ) + { + cam.Frame( bounds, aspect, 1.5f ); + } + else + { + b3BodyId bodyId = s_context.sample->FocusBody(); + if ( B3_IS_NON_NULL( bodyId ) ) + { + cam.Frame( b3Body_ComputeAABB( bodyId ), aspect, 1.5f ); + } + else + { + s_context.sample->FocusHome(); + } + } + } + break; default: s_context.sample->Keyboard( e->key_code, ACTION_PRESS, mods ); @@ -297,6 +259,10 @@ static void OnEvent( const sapp_event* e ) } break; + case SAPP_EVENTTYPE_KEY_UP: + SetKeyDown( e->key_code, false ); + break; + case SAPP_EVENTTYPE_CHAR: // ? toggles the controls window. Read the typed character so it works // on any layout and a text field can still type a literal ?, since the @@ -343,17 +309,12 @@ static void OnEvent( const sapp_event* e ) } } -// This limits the render rate to the simulation rate. Physics debugging -// ergonomics require render frames and simulation frames to be one to one. -// I don't recommend this setup for games, where a decoupled render -// and simulation rate is desirable. +// Pace the loop to 60 Hz so the fixed 1/60 physics step plays at real time on any +// display. Sleep the bulk of the idle time, then spin the last bit since sleep wakes +// are only accurate to about a millisecond. static void LimitFrameRate( uint64_t frameStart ) { - // By limiting to the simulation hertz, this allows me to run the simulation - // at 240Hz and render at that rate when using a 240Hz monitor. It also allows - // me to run a 10Hz simulation in at the wall clock rate. - float hertz = b3ClampFloat(s_context.hertz, 5.0f, 1000.0f); - const float targetMs = 1000.0f / hertz; + const float targetMs = 1000.0f / 60.0f; const float spinMs = 2.0f; int sleepMs = (int)( targetMs - spinMs - b3GetMilliseconds( frameStart ) ); @@ -412,7 +373,6 @@ static void OnFrame( void ) // frame tracks load/unload without extra wiring. Live samples sit at 1 unit per // meter, leaving the transform identity. camera.SetRenderTransform( b3GetLengthUnitsPerMeter(), s_context.viewZUp ); - camera.SetDrawDistance( s_context.drawDistance ); // Sync the draw origin to the camera eye once per frame, before any drawing. This must hold even // for samples that drive their own Step without calling Sample::Step. Render re-syncs after Step @@ -426,18 +386,11 @@ static void OnFrame( void ) // queues the HUD text; Render fills the instance and overlay arenas via the // b3DebugDraw adapter and the sample's own Draw* calls. SetTransparentDynamic( s_context.transparentDynamic ); - SetTransparentKinematic( s_context.transparentKinematic ); s_context.sample->ResetText(); s_context.sample->Step(); s_context.sample->Render(); - // Before RenderFrame so world labels drop too - if ( s_context.showText == false ) - { - ResetTextArena(); - } - FrameInput fi{}; fi.view = camera.View(); fi.viewInv = camera.ViewInverse(); @@ -472,9 +425,6 @@ static void OnFrame( void ) sg_commit(); ++s_frame; - // For the Tracy profiler - FrameMark; - if ( s_frameLimit < 0 ) { LimitFrameRate( frameStart ); @@ -498,35 +448,10 @@ static void OnCleanup( void ) timeEndPeriod( 1 ); #endif - #ifdef TRACY_ENABLE - tracy::ShutdownProfiler(); -#endif - - // Return instead of exit so sokol frees its own window and context. main - // dumps CRT leaks once sapp_run returns, past that teardown. - s_exitCode = errors == 0 ? 0 : 1; + exit( errors == 0 ? 0 : 1 ); } -static void OnAppLog( const char* tag, uint32_t logLevel, uint32_t logItemId, const char* message, uint32_t lineNumber, - const char* filename, void* userData ) -{ - (void)tag; - (void)logItemId; - (void)filename; - (void)userData; - (void)lineNumber; - - const char* level = ( logLevel == 0 ) ? "panic" : ( logLevel == 1 ) ? "error" : ( logLevel == 2 ) ? "warn" : "info"; - fprintf( stderr, "sokol(level %s) %s\n", level, message ? message : "(no message)" ); - - if ( logLevel == 0 ) - { - fprintf( stderr, "Ensure you have OpenGL 4.5 if on Linux" ); - exit( 1 ); - } -} - -static sapp_desc BuildAppDesc( int argc, char** argv ) +sapp_desc sokol_main( int argc, char** argv ) { for ( int i = 1; i < argc; ++i ) { @@ -538,17 +463,6 @@ static sapp_desc BuildAppDesc( int argc, char** argv ) { s_sampleOverride = atoi( argv[++i] ); } - else if ( strcmp( argv[i], "--replay" ) == 0 && i + 1 < argc ) - { - const char* path = argv[++i]; - - snprintf( s_context.replayFile, sizeof( s_context.replayFile ), "%s", path ); - s_openReplay = true; - } - else if ( strcmp( argv[i], "--zup" ) == 0 ) - { - s_context.viewZUp = true; - } } sapp_desc desc{}; @@ -556,7 +470,6 @@ static sapp_desc BuildAppDesc( int argc, char** argv ) desc.frame_cb = OnFrame; desc.event_cb = OnEvent; desc.cleanup_cb = OnCleanup; - desc.logger.func = OnAppLog; // GL 4.5 for glClipControl (reverse-Z). Ignored on D3D11 / Metal. desc.gl.major_version = 4; @@ -582,19 +495,3 @@ static sapp_desc BuildAppDesc( int argc, char** argv ) return desc; } - -// The leak dump runs at CRT exit, after static destructors. Libraries such as ImGuizmo keep -// heap backed containers at file scope, and a dump right after sapp_run reports them. -int main( int argc, char** argv ) -{ -#if defined( _MSC_VER ) - _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT ); - _CrtSetDbgFlag( _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ) | _CRTDBG_LEAK_CHECK_DF ); -#endif - - sapp_desc desc = BuildAppDesc( argc, argv ); - sapp_run( &desc ); - - return s_exitCode; -} diff --git a/samples/mesh_loader.cpp b/samples/mesh_loader.cpp index bfbb13a..d31d307 100644 --- a/samples/mesh_loader.cpp +++ b/samples/mesh_loader.cpp @@ -10,52 +10,40 @@ #define TINYOBJLOADER_USE_MAPBOX_EARCUT #include "tiny_obj_loader.h" -#include +#include -// A missing obj is refused rather than fatal, so the samples still run from a -// directory with no data beside them. -static bool ParseObjFile( tinyobj::ObjReader& reader, const char* path ) +// Load a wavefront obj file using tiny obj loader and earcut for triangulation. +void LoadTempMesh( const char* path, TempMesh* tempMesh, float scale, bool zUp ) { + std::string inputFile = path; tinyobj::ObjReaderConfig readerConfig; readerConfig.triangulate = true; readerConfig.mtl_search_path = "./"; // Path to material files - if ( reader.ParseFromFile( path, readerConfig ) == false ) - { - fprintf( stderr, "Failed to load mesh '%s'", path ); - if ( reader.Error().empty() == false ) - { - fprintf( stderr, ": %s", reader.Error().c_str() ); - } - fprintf( stderr, "\n" ); - return false; - } - - if ( reader.Warning().empty() == false ) - { - fprintf( stderr, "TinyObjReader: %s\n", reader.Warning().c_str() ); - } - - return true; -} - -// Load a wavefront obj file using tiny obj loader and earcut for triangulation. -bool LoadTempMesh( const char* path, TempMesh* tempMesh, float scale, bool zUp ) -{ - tempMesh->vertices.clear(); - tempMesh->indices.clear(); - tempMesh->materialIndices.clear(); - tinyobj::ObjReader reader; - if ( ParseObjFile( reader, path ) == false ) + + if ( !reader.ParseFromFile( inputFile, readerConfig ) ) { - return false; + if ( !reader.Error().empty() ) + { + std::cerr << "TinyObjReader: " << reader.Error(); + } + exit( 1 ); + } + + if ( !reader.Warning().empty() ) + { + std::cout << "TinyObjReader: " << reader.Warning(); } const tinyobj::attrib_t& attrib = reader.GetAttrib(); const std::vector& shapes = reader.GetShapes(); // const std::vector& objMaterials = reader.GetMaterials(); + tempMesh->vertices.clear(); + tempMesh->indices.clear(); + tempMesh->materialIndices.clear(); + int vertexCount = int( attrib.vertices.size() / 3 ); for ( int i = 0; i < vertexCount; i++ ) { @@ -96,16 +84,29 @@ bool LoadTempMesh( const char* path, TempMesh* tempMesh, float scale, bool zUp ) baseIndex += faceVertexCount; } } - - return true; } b3MeshData* CreateMeshData( const char* path, float scale, bool zUp, bool useMedianSplit, bool identifyConvexEdges, bool weldVertices ) { + std::string inputFile = path; + tinyobj::ObjReaderConfig readerConfig; + readerConfig.triangulate = true; + readerConfig.mtl_search_path = "./"; // Path to material files + tinyobj::ObjReader reader; - if ( ParseObjFile( reader, path ) == false ) + + if ( !reader.ParseFromFile( inputFile, readerConfig ) ) { - return nullptr; + if ( !reader.Error().empty() ) + { + std::cerr << "TinyObjReader: " << reader.Error(); + } + exit( 1 ); + } + + if ( !reader.Warning().empty() ) + { + std::cout << "TinyObjReader: " << reader.Warning(); } const tinyobj::attrib_t& attrib = reader.GetAttrib(); @@ -167,18 +168,5 @@ b3MeshData* CreateMeshData( const char* path, float scale, bool zUp, bool useMed def.weldTolerance = 0.002f; b3MeshData* meshData = b3CreateMesh( &def, nullptr, 0 ); - if ( meshData == nullptr ) - { - fprintf( stderr, "Mesh '%s' has no usable triangles\n", path ); - } - return meshData; } - -void DestroyMeshData( b3MeshData* meshData ) -{ - if ( meshData != nullptr ) - { - b3DestroyMesh( meshData ); - } -} diff --git a/samples/mesh_loader.h b/samples/mesh_loader.h index 960395d..d91dad6 100644 --- a/samples/mesh_loader.h +++ b/samples/mesh_loader.h @@ -8,14 +8,9 @@ #include struct b3MeshData; - -// Returns null if the mesh cannot be created. b3MeshData* CreateMeshData( const char* path, float scale, bool zUp, bool useMedianSplit, bool identifyConvexEdges, bool weldVertices ); -// Null tolerant. -void DestroyMeshData( b3MeshData* meshData ); - struct TempMesh { std::vector vertices; @@ -23,4 +18,4 @@ struct TempMesh std::vector materialIndices; }; -bool LoadTempMesh( const char* path, TempMesh* tempMesh, float scale, bool zUp ); +void LoadTempMesh( const char* path, TempMesh* tempMesh, float scale, bool zUp ); diff --git a/samples/sample.cpp b/samples/sample.cpp index 8d26b97..bd2f815 100644 --- a/samples/sample.cpp +++ b/samples/sample.cpp @@ -15,7 +15,6 @@ #include "gfx/renderer.h" #include "gfx/shadow.h" #include "gfx/text.h" -#include "host/gui.h" #include "human.h" #include "imgui.h" #include "implot.h" @@ -45,34 +44,18 @@ static char* ReadFile( int& size, const char* filename ) } fseek( file, 0, SEEK_END ); - long length = ftell( file ); + size = static_cast( ftell( file ) ); fseek( file, 0, SEEK_SET ); - if ( length <= 0 ) + if ( size == 0 ) { fclose( file ); return nullptr; } - size = static_cast( length ); - char* data = (char*)malloc( size + 1 ); - if ( data == nullptr ) - { - fclose( file ); - return nullptr; - } - - // Short read means a truncated or racing file, so treat it as no file at all - size_t read = fread( data, 1, size, file ); + fread( data, size, 1, file ); fclose( file ); - - if ( read != (size_t)size ) - { - free( data ); - return nullptr; - } - data[size] = 0; return data; @@ -97,11 +80,6 @@ void SetKeyDown( int key, bool down ) } } -void ClearKeysDown() -{ - memset( s_keyDown, 0, sizeof( s_keyDown ) ); -} - void SampleContext::Save() { const b3DebugDraw* gd = GetGuiDraw(); @@ -115,20 +93,17 @@ void SampleContext::Save() fprintf( file, "{\n" ); fprintf( file, " \"sampleIndex\": %d,\n", sampleIndex ); fprintf( file, " \"drawShapes\": %s,\n", gd->drawShapes ? "true" : "false" ); + fprintf( file, " \"drawJoints\": %s,\n", gd->drawJoints ? "true" : "false" ); + fprintf( file, " \"drawContacts\": %s,\n", gd->drawContacts ? "true" : "false" ); fprintf( file, " \"enableShadows\": %s,\n", enableShadows ? "true" : "false" ); fprintf( file, " \"enableGtao\": %s,\n", enableGtao ? "true" : "false" ); fprintf( file, " \"gtaoQuality\": %d,\n", gtaoQuality ); fprintf( file, " \"enableIbl\": %s,\n", GetIblEnabled() ? "true" : "false" ); fprintf( file, " \"exposure\": %g,\n", GetExposure() ); fprintf( file, " \"sunStrength\": %g,\n", GetSun().strength ); - fprintf( file, " \"shadowSplitLambda\": %g,\n", GetShadowSplitLambda() ); fprintf( file, " \"debugView\": %d,\n", debugView ); - fprintf( file, " \"drawDistance\": %g,\n", drawDistance ); fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" ); fprintf( file, " \"showEdgeConvexity\": %s,\n", GetEdgeOverlayParams().showEdgeConvexity ? "true" : "false" ); - fprintf( file, " \"edgeAlpha\": %g,\n", GetEdgeOverlayParams().alphaScale ); - fprintf( file, " \"showMetrics\": %s,\n", showMetrics ? "true" : "false" ); - fprintf( file, " \"showProfile\": %s,\n", showProfile ? "true" : "false" ); fprintf( file, " \"replayKeyframeBudgetMB\": %d,\n", replayKeyframeBudgetMB ); fprintf( file, " \"replayKeyframeMinInterval\": %d\n", replayKeyframeMinInterval ); fprintf( file, "}\n" ); @@ -147,34 +122,6 @@ static int jsoneq( const char* json, jsmntok_t* tok, const char* s ) return -1; } -// Tokens are not terminated, so copy before handing one to strtof or strtol. -// The settings file is hand editable, so truncate a long token rather than -// trusting it to fit. -static void CopyToken( char* buffer, int capacity, const char* json, const jsmntok_t& tok ) -{ - int count = tok.end - tok.start; - if ( count > capacity - 1 ) - { - count = capacity - 1; - } - memcpy( buffer, json + tok.start, count ); - buffer[count] = 0; -} - -static float ParseFloat( const char* json, const jsmntok_t& tok ) -{ - char buffer[32]; - CopyToken( buffer, (int)sizeof( buffer ), json, tok ); - return strtof( buffer, nullptr ); -} - -static int ParseInt( const char* json, const jsmntok_t& tok ) -{ - char buffer[32]; - CopyToken( buffer, (int)sizeof( buffer ), json, tok ); - return (int)strtol( buffer, nullptr, 10 ); -} - void SampleContext::Load() { recycleDistance = B3_CONTACT_RECYCLE_DISTANCE; @@ -195,12 +142,19 @@ void SampleContext::Load() jsmn_init( &parser ); int tokenCount = jsmn_parse( &parser, data, size, tokens, MAX_TOKENS ); + char buffer[32]; for ( int i = 0; i < tokenCount; ++i ) { if ( jsoneq( data, &tokens[i], "sampleIndex" ) == 0 ) { - sampleIndex = ParseInt( data, tokens[i + 1] ); + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + char* dummy; + sampleIndex = (int)strtol( buffer, &dummy, 10 ); if ( sampleIndex < 0 ) { @@ -216,6 +170,16 @@ void SampleContext::Load() const char* s = data + tokens[i + 1].start; GetGuiDraw()->drawShapes = strncmp( s, "true", 4 ) == 0; } + else if ( jsoneq( data, &tokens[i], "drawJoints" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + GetGuiDraw()->drawJoints = strncmp( s, "true", 4 ) == 0; + } + else if ( jsoneq( data, &tokens[i], "drawContacts" ) == 0 ) + { + const char* s = data + tokens[i + 1].start; + GetGuiDraw()->drawContacts = strncmp( s, "true", 4 ) == 0; + } else if ( jsoneq( data, &tokens[i], "enableShadows" ) == 0 ) { const char* s = data + tokens[i + 1].start; @@ -228,7 +192,12 @@ void SampleContext::Load() } else if ( jsoneq( data, &tokens[i], "gtaoQuality" ) == 0 ) { - int quality = b3ClampInt( ParseInt( data, tokens[i + 1] ), 0, 2 ); + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + int quality = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 2 ); GtaoTraceParams p = GetGtaoTraceParams(); p.quality = (AmbientOcclusionQuality)quality; @@ -241,25 +210,32 @@ void SampleContext::Load() } else if ( jsoneq( data, &tokens[i], "exposure" ) == 0 ) { - SetExposure( ParseFloat( data, tokens[i + 1] ) ); + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + SetExposure( strtof( buffer, nullptr ) ); } else if ( jsoneq( data, &tokens[i], "sunStrength" ) == 0 ) { + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; Sun sun = GetSun(); - sun.strength = ParseFloat( data, tokens[i + 1] ); + sun.strength = strtof( buffer, nullptr ); SetSun( sun ); } - else if ( jsoneq( data, &tokens[i], "shadowSplitLambda" ) == 0 ) - { - SetShadowSplitLambda( ParseFloat( data, tokens[i + 1] ) ); - } else if ( jsoneq( data, &tokens[i], "debugView" ) == 0 ) { - debugView = b3ClampInt( ParseInt( data, tokens[i + 1] ), 0, 4 ); - } - else if ( jsoneq( data, &tokens[i], "drawDistance" ) == 0 ) - { - drawDistance = b3ClampFloat( ParseFloat( data, tokens[i + 1] ), 1.0f, Camera::kViewDistance ); + int count = tokens[i + 1].end - tokens[i + 1].start; + assert( count < 32 ); + const char* s = data + tokens[i + 1].start; + strncpy( buffer, s, count ); + buffer[count] = 0; + debugView = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 4 ); } else if ( jsoneq( data, &tokens[i], "showHullEdges" ) == 0 ) { @@ -275,29 +251,29 @@ void SampleContext::Load() p.showEdgeConvexity = strncmp( s, "true", 4 ) == 0; SetEdgeOverlayParams( &p ); } - else if ( jsoneq( data, &tokens[i], "edgeAlpha" ) == 0 ) - { - EdgeOverlayParams p = GetEdgeOverlayParams(); - p.alphaScale = b3ClampFloat( ParseFloat( data, tokens[i + 1] ), 0.0f, 4.0f ); - SetEdgeOverlayParams( &p ); - } - else if ( jsoneq( data, &tokens[i], "showMetrics" ) == 0 ) - { - const char* s = data + tokens[i + 1].start; - showMetrics = strncmp( s, "true", 4 ) == 0; - } - else if ( jsoneq( data, &tokens[i], "showProfile" ) == 0 ) - { - const char* s = data + tokens[i + 1].start; - showProfile = strncmp( s, "true", 4 ) == 0; - } else if ( jsoneq( data, &tokens[i], "replayKeyframeBudgetMB" ) == 0 ) { - replayKeyframeBudgetMB = b3ClampInt( ParseInt( data, tokens[i + 1] ), 64, 4096 ); + int count = tokens[i + 1].end - tokens[i + 1].start; + if ( count > (int)sizeof( buffer ) - 1 ) + { + count = (int)sizeof( buffer ) - 1; + } + const char* s = data + tokens[i + 1].start; + memcpy( buffer, s, count ); + buffer[count] = 0; + replayKeyframeBudgetMB = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 64, 4096 ); } else if ( jsoneq( data, &tokens[i], "replayKeyframeMinInterval" ) == 0 ) { - replayKeyframeMinInterval = b3ClampInt( ParseInt( data, tokens[i + 1] ), 1, 1024 ); + int count = tokens[i + 1].end - tokens[i + 1].start; + if ( count > (int)sizeof( buffer ) - 1 ) + { + count = (int)sizeof( buffer ) - 1; + } + const char* s = data + tokens[i + 1].start; + memcpy( buffer, s, count ); + buffer[count] = 0; + replayKeyframeMinInterval = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 1, 1024 ); } } @@ -325,7 +301,6 @@ Sample::Sample( SampleContext* context ) m_mouseFraction = 0.0f; m_mouseForceScale = 100.0f; - m_textX = 5; m_textLine = 0; m_textIncrement = 22; m_stepCount = 0; @@ -344,9 +319,6 @@ Sample::Sample( SampleContext* context ) m_mouseDelta = { 0.0f, 0.0f }; m_launchSpeedScale = 5.0f; - m_shadowSplitNear = 0.0f; - m_shadowSplitFar = 0.0f; - g_randomSeed = RAND_SEED; b3Capacity capacity = {}; @@ -385,17 +357,7 @@ void Sample::FinishRecording() } b3World_StopRecording( m_worldId ); - - // The buffer is freed either way, so a failed write has to be said out loud - if ( b3SaveRecordingToFile( m_recording, m_context->recordingFile ) ) - { - snprintf( m_context->savedRecordingFile, sizeof( m_context->savedRecordingFile ), "%s", m_context->recordingFile ); - } - else - { - fprintf( stderr, "Failed to write recording '%s'\n", m_context->recordingFile ); - } - + b3SaveRecordingToFile( m_recording, m_context->recordingFile ); b3DestroyRecording( m_recording ); m_recording = nullptr; } @@ -438,12 +400,6 @@ void Sample::ResetText() { m_textLine = (int)( 3.0f * fontSize ); } - - m_textX = 5; - if ( IsProfileVisible() ) - { - m_textX += (int)( GetProfilePanelWidth() + 0.5f * fontSize ); - } } void Sample::Step() @@ -477,9 +433,6 @@ void Sample::Step() b3World_EnableSleeping( m_worldId, m_context->enableSleep ); b3World_EnableWarmStarting( m_worldId, m_context->enableWarmStarting ); b3World_EnableContinuous( m_worldId, m_context->enableContinuous ); - b3World_SetRestitutionIterations( m_worldId, m_context->restitutionIterations ); - b3World_EnableRestitutionPropagation( m_worldId, m_context->enableRestitutionPropagation ); - b3World_EnableSSE2Fallback( m_worldId, m_context->enableSSE2Fallback ); if ( timeStep > 0.0f || m_stepWhilePaused ) { @@ -536,23 +489,7 @@ void Sample::Step() // Box3D uses this to decide which shapes enter the draw set and lazily fire // createDebugShape. The camera derives it from the view distance, in length units // around the simulation eye, matching the broad-phase tree and the far plane. - const b3AABB drawBox = m_camera->DrawBounds(); - - // A caster between the view and the sun is off screen but still darkens what - // is on screen, so the draw set has to reach past the view box. Bounds come - // back in the eye-relative frame the view inverse maps into, hence the offset. - b3Vec3 casterLo, casterHi; - const Mat4 viewInv = m_camera->ViewInverse(); - const Mat4 projInv = m_camera->ProjInverse(); - GetShadowCasterBounds( &viewInv, &projInv, &casterLo, &casterHi ); - const b3AABB casterBox = b3OffsetAABB( { casterLo, casterHi }, m_camera->DrawOrigin() ); - - debugDraw.drawingBounds.lowerBound = b3Min( drawBox.lowerBound, casterBox.lowerBound ); - debugDraw.drawingBounds.upperBound = b3Max( drawBox.upperBound, casterBox.upperBound ); - - // Compound child culling keeps the tighter view box. Widening it there would - // cull nothing. - SetViewBounds( drawBox ); + debugDraw.drawingBounds = m_camera->DrawBounds(); ApplyGuiFlags( &debugDraw ); @@ -576,39 +513,13 @@ b3BodyId Sample::FocusBody() const void Sample::FocusHome() { - m_camera->m_pivot = m_context->homePivot; - m_camera->SetOrbit( m_context->homeYaw, m_context->homePitch, m_context->homeRadius ); -} - -void FrameSelection( SampleContext* context ) -{ - // A non-body selection such as a recorded query supplies its own bounds and takes priority over - // the hovered body. With nothing selected the sample decides what home is. The replay viewer fits - // its recording, which lives in a player-owned world rather than the base world. - Sample* sample = context->sample; - Camera& cam = context->camera; - float aspect = cam.m_height > 0 ? (float)cam.m_width / (float)cam.m_height : 1.0f; - b3AABB bounds; - if ( sample->FocusBounds( &bounds ) ) - { - cam.Frame( bounds, aspect, 1.5f ); - return; - } - - b3BodyId bodyId = sample->FocusBody(); - if ( B3_IS_NON_NULL( bodyId ) ) - { - cam.Frame( b3Body_ComputeAABB( bodyId ), aspect, 1.5f ); - return; - } - - sample->FocusHome(); + b3AABB aabb = b3World_GetBounds( m_worldId ); + float aspect = m_camera->m_height > 0 ? (float)m_camera->m_width / (float)m_camera->m_height : 1.0f; + m_camera->Frame( aabb, aspect, 0.75f ); } void Sample::ResetProfile() { - // Keeps the elapsed recording length intact across a profile reset - m_recordStartStep -= m_stepCount; m_stepCount = 0; memset( m_profiles, 0, sizeof( m_profiles ) ); m_currentProfileIndex = 0; @@ -652,314 +563,9 @@ float AddSegment( ImDrawList* dl, float availWidth, float t, float stepNow, ImU3 return x; } -#define PROFILE_SECTION_WIDTH 8.0f -#define PROFILE_INDENT_WIDTH 0.75f -#define PROFILE_VALUE_WIDTH 3.0f -#define PROFILE_BAR_WIDTH 4.0f -#define PROFILE_COLUMN_COUNT 5 - -// Shared by the profile panel and the frame time plot so the two views read alike -static const ImU32 s_colorStep = IM_COL32( 230, 230, 230, 255 ); -static const ImU32 s_colorPairs = IM_COL32( 102, 153, 255, 255 ); -static const ImU32 s_colorCollide = IM_COL32( 255, 140, 51, 255 ); -static const ImU32 s_colorSolve = IM_COL32( 102, 204, 102, 255 ); -static const ImU32 s_colorSolveChild = IM_COL32( 150, 190, 150, 255 ); -static const ImU32 s_colorConstraintChild = IM_COL32( 110, 200, 190, 255 ); -static const ImU32 s_colorSensors = IM_COL32( 200, 120, 220, 255 ); -static const ImU32 s_colorOther = IM_COL32( 140, 140, 140, 255 ); - -// Well apart from both row background shades so the track reads the same on every row -static const ImU32 s_colorTrack = IM_COL32( 70, 70, 74, 255 ); - -bool Sample::IsProfileVisible() const -{ - return m_context->showUI && m_context->showProfile && HasProfile(); -} - -float Sample::GetProfilePanelWidth() const -{ - if ( IsProfileVisible() == false ) - { - return 0.0f; - } - - const ImGuiStyle& style = ImGui::GetStyle(); - float fontSize = ImGui::GetFontSize(); - float width = PROFILE_SECTION_WIDTH + 3.0f * PROFILE_VALUE_WIDTH + PROFILE_BAR_WIDTH; - return width * fontSize + 2.0f * PROFILE_COLUMN_COUNT * style.CellPadding.x + 2.0f * style.WindowPadding.x; -} - -// Left profile panel (I). Full height under the menu bar, clear of the right info panel. -void Sample::DrawProfile() -{ - if ( IsProfileVisible() == false ) - { - return; - } - - float fontSize = ImGui::GetFontSize(); - float menuBarHeight = ImGui::GetFrameHeight(); - float panelWidth = GetProfilePanelWidth(); - - ImGui::SetNextWindowPos( { 0.5f * fontSize, menuBarHeight + 0.5f * fontSize } ); - ImGui::SetNextWindowSize( { panelWidth, m_camera->m_height - menuBarHeight - fontSize } ); - - ImGui::Begin( "Profile", nullptr, - ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | - ImGuiWindowFlags_NoTitleBar ); - - int count = m_profileWriteIndex - m_profileReadIndex; - - // Unroll ring buffer into per-field histories. - constexpr int kRowCount = 22; - float histories[kRowCount][m_profileCapacity]; - float totals[kRowCount] = {}; - for ( int i = 0; i < count; ++i ) - { - int idx = ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ); - const b3Profile& p = m_profiles[idx]; - histories[0][i] = p.step; - histories[1][i] = p.pairs; - histories[2][i] = p.collide; - histories[3][i] = p.solve; - histories[4][i] = p.solverSetup; - histories[5][i] = p.constraints; - histories[6][i] = p.prepareConstraints; - histories[7][i] = p.integrateVelocities; - histories[8][i] = p.warmStart; - histories[9][i] = p.solveImpulses; - histories[10][i] = p.integratePositions; - histories[11][i] = p.relaxImpulses; - histories[12][i] = p.restitution; - histories[13][i] = p.storeImpulses; - histories[14][i] = p.splitIslands; - histories[15][i] = p.transforms; - histories[16][i] = p.jointEvents; - histories[17][i] = p.hitEvents; - histories[18][i] = p.refit; - histories[19][i] = p.sleepIslands; - histories[20][i] = p.bullets; - histories[21][i] = p.sensors; - for ( int j = 0; j < kRowCount; ++j ) - { - totals[j] += histories[j][i]; - } - } - - // Smoothed over the last few frames so bars don't jitter visibly. - constexpr int kNowWindow = 10; - float now[kRowCount] = {}; - { - int n = count < kNowWindow ? count : kNowWindow; - if ( n > 0 ) - { - float inv = 1.0f / n; - for ( int r = 0; r < kRowCount; ++r ) - { - float sum = 0.0f; - for ( int i = count - n; i < count; ++i ) - { - sum += histories[r][i]; - } - now[r] = sum * inv; - } - } - } - - float avg[kRowCount] = {}; - if ( count > 0 ) - { - float scale = 1.0f / count; - for ( int i = 0; i < kRowCount; ++i ) - { - avg[i] = scale * totals[i]; - } - } - - float rowMax[kRowCount] = {}; - for ( int r = 0; r < kRowCount; ++r ) - { - for ( int i = 0; i < count; ++i ) - { - if ( histories[r][i] > rowMax[r] ) - { - rowMax[r] = histories[r][i]; - } - } - } - - const RowDef rows[kRowCount] = { - { "step", 0, s_colorStep }, - { "pairs", 0, s_colorPairs }, - { "collide", 0, s_colorCollide }, - { "solve", 0, s_colorSolve }, - { "setup", 1, s_colorSolveChild }, - { "constraints", 1, s_colorSolveChild }, - { "prepare", 2, s_colorConstraintChild }, - { "velocities", 2, s_colorConstraintChild }, - { "warm start", 2, s_colorConstraintChild }, - { "bias", 2, s_colorConstraintChild }, - { "positions", 2, s_colorConstraintChild }, - { "relax", 2, s_colorConstraintChild }, - { "restitution", 2, s_colorConstraintChild }, - { "store", 2, s_colorConstraintChild }, - { "split", 2, s_colorConstraintChild }, - { "transforms", 1, s_colorSolveChild }, - { "joint events", 1, s_colorSolveChild }, - { "hit events", 1, s_colorSolveChild }, - { "refit BVH", 1, s_colorSolveChild }, - { "sleep", 1, s_colorSolveChild }, - { "bullets", 1, s_colorSolveChild }, - { "sensors", 0, s_colorSensors }, - }; - - float stepNow = b3MaxFloat( now[0], 0.001f ); - - if ( ImGui::Button( "Reset" ) ) - { - ResetProfile(); - } - ImGui::SameLine(); - ImGui::Text( " step %.2f ms", now[0] ); - - // Flame strip: step subdivided by top-level children. - { - float pairsT = now[1]; - float collideT = now[2]; - float solveT = now[3]; - float sensorsT = now[21]; - float otherT = b3MaxFloat( stepNow - pairsT - collideT - solveT - sensorsT, 0.0f ); - - float availWidth = ImGui::GetContentRegionAvail().x; - float barHeight = 1.5f * fontSize; - ImDrawList* dl = ImGui::GetWindowDrawList(); - ImVec2 cursor = ImGui::GetCursorScreenPos(); - float x = cursor.x; - - x = AddSegment( dl, availWidth, pairsT, stepNow, s_colorPairs, x, cursor, barHeight ); - x = AddSegment( dl, availWidth, collideT, stepNow, s_colorCollide, x, cursor, barHeight ); - x = AddSegment( dl, availWidth, solveT, stepNow, s_colorSolve, x, cursor, barHeight ); - x = AddSegment( dl, availWidth, sensorsT, stepNow, s_colorSensors, x, cursor, barHeight ); - x = AddSegment( dl, availWidth, otherT, stepNow, s_colorOther, x, cursor, barHeight ); - - ImGui::Dummy( ImVec2( availWidth, barHeight ) ); - } - - const ImGuiTableFlags tableFlags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit; - - if ( ImGui::BeginTable( "profile", PROFILE_COLUMN_COUNT, tableFlags ) ) - { - ImGui::TableSetupColumn( "section", ImGuiTableColumnFlags_WidthFixed, PROFILE_SECTION_WIDTH * fontSize ); - ImGui::TableSetupColumn( "now", ImGuiTableColumnFlags_WidthFixed, PROFILE_VALUE_WIDTH * fontSize ); - ImGui::TableSetupColumn( "avg", ImGuiTableColumnFlags_WidthFixed, PROFILE_VALUE_WIDTH * fontSize ); - ImGui::TableSetupColumn( "max", ImGuiTableColumnFlags_WidthFixed, PROFILE_VALUE_WIDTH * fontSize ); - ImGui::TableSetupColumn( "%", ImGuiTableColumnFlags_WidthFixed, PROFILE_BAR_WIDTH * fontSize ); - ImGui::TableHeadersRow(); - - for ( int r = 0; r < kRowCount; ++r ) - { - const RowDef& d = rows[r]; - - ImGui::TableNextRow(); - - ImGui::TableNextColumn(); - float indent = d.indent * PROFILE_INDENT_WIDTH * fontSize; - ImGui::SetCursorPosX( ImGui::GetCursorPosX() + indent ); - ImGui::PushStyleColor( ImGuiCol_Text, d.color ); - ImGui::TextUnformatted( d.name ); - ImGui::PopStyleColor(); - - // Dim rows that would print as zero so the costly sections stand out - bool idle = avg[r] < 0.005f; - if ( idle ) - { - ImGui::PushStyleColor( ImGuiCol_Text, ImGui::GetStyleColorVec4( ImGuiCol_TextDisabled ) ); - } - ImGui::TableNextColumn(); - ImGui::Text( "%6.2f", now[r] ); - ImGui::TableNextColumn(); - ImGui::Text( "%6.2f", avg[r] ); - ImGui::TableNextColumn(); - ImGui::Text( "%6.2f", rowMax[r] ); - if ( idle ) - { - ImGui::PopStyleColor(); - } - - ImGui::TableNextColumn(); - - // The step itself is measured against the frame budget to show headroom - bool isBudget = r == 0 && m_context->hertz > 0.0f; - float reference = isBudget ? 1000.0f / m_context->hertz : stepNow; - float frac = b3ClampFloat( now[r] / reference, 0.0f, 1.0f ); - - // Text line height instead of a framed progress bar keeps the rows tight - float barWidth = ImGui::GetContentRegionAvail().x; - float barHeight = ImGui::GetTextLineHeight(); - ImVec2 p = ImGui::GetCursorScreenPos(); - ImDrawList* drawList = ImGui::GetWindowDrawList(); - drawList->AddRectFilled( p, ImVec2( p.x + barWidth, p.y + barHeight ), s_colorTrack ); - drawList->AddRectFilled( p, ImVec2( p.x + frac * barWidth, p.y + barHeight ), d.color ); - ImGui::Dummy( ImVec2( barWidth, barHeight ) ); - if ( isBudget ) - { - ImGui::SetItemTooltip( "%.0f%% of %.1f ms frame", 100.0f * now[r] / reference, reference ); - } - else - { - ImGui::SetItemTooltip( "%.0f%% of step", 100.0f * now[r] / reference ); - } - } - ImGui::EndTable(); - } - - ImGui::End(); -} - -// Vertical bars scaled to a shared maximum, one per value. Stands in for a table that would not -// fit the drawer, so the caller reports each bar's count from the returned hover index. -static int DrawBarChart( const char* id, const int* values, const ImU32* colors, int count, int scaleMax, ImVec2 size ) -{ - ImVec2 origin = ImGui::GetCursorScreenPos(); - ImGui::InvisibleButton( id, size ); - bool hovered = ImGui::IsItemHovered(); - float mouseX = ImGui::GetIO().MousePos.x; - - ImDrawList* drawList = ImGui::GetWindowDrawList(); - float slot = size.x / count; - float gap = b3MinFloat( 2.0f, 0.25f * slot ); - float invMax = scaleMax > 0 ? 1.0f / scaleMax : 0.0f; - float bottom = origin.y + size.y; - - int hoveredIndex = -1; - for ( int i = 0; i < count; ++i ) - { - float x0 = origin.x + i * slot; - float x1 = x0 + slot - gap; - - // Empty slots still show, so a gap in the sequence reads as a gap - drawList->AddRectFilled( ImVec2( x0, origin.y ), ImVec2( x1, bottom ), s_colorTrack ); - - float height = b3ClampFloat( values[i] * invMax, 0.0f, 1.0f ) * size.y; - if ( values[i] > 0 ) - { - // A tiny count keeps a visible sliver - height = b3MaxFloat( height, 1.0f ); - drawList->AddRectFilled( ImVec2( x0, bottom - height ), ImVec2( x1, bottom ), colors[i] ); - } - - if ( hovered && x0 <= mouseX && mouseX < x0 + slot ) - { - hoveredIndex = i; - drawList->AddRect( ImVec2( x0, origin.y ), ImVec2( x1, bottom ), IM_COL32( 255, 255, 255, 200 ) ); - } - } - - return hoveredIndex; -} - -// Bottom metrics drawer (M). Tabs: the ImPlot frame time chart, Counters, and Renderer. -// Anchored along the window bottom, between the profile panel and the right info panel. +// Bottom diagnostics drawer (M). Tabs: Profile, Counters, Renderer, and the +// optional ImPlot frame-time chart. Anchored along the window bottom, clear +// of the right info panel. void Sample::DrawMetrics() { if ( m_context->showMetrics == false ) @@ -970,14 +576,9 @@ void Sample::DrawMetrics() float fontSize = ImGui::GetFontSize(); float menuWidth = InfoPanelWidthEm() * fontSize; float drawerHeight = 16.0f * fontSize; - float drawerX = 0.5f * fontSize; - if ( IsProfileVisible() ) - { - drawerX += GetProfilePanelWidth() + 0.5f * fontSize; - } - float drawerWidth = m_camera->m_width - menuWidth - fontSize - drawerX; + float drawerWidth = m_camera->m_width - menuWidth - 1.5f * fontSize; - ImGui::SetNextWindowPos( { drawerX, m_camera->m_height - drawerHeight - 0.5f * fontSize } ); + ImGui::SetNextWindowPos( { 0.5f * fontSize, m_camera->m_height - drawerHeight - 0.5f * fontSize } ); ImGui::SetNextWindowSize( { drawerWidth, drawerHeight } ); ImGui::Begin( "Metrics", nullptr, @@ -990,178 +591,445 @@ void Sample::DrawMetrics() return; } - if ( HasProfile() && ImGui::BeginTabItem( "Frame Time" ) ) + if ( ImGui::BeginTabItem( "Profile" ) ) { - float maxValue = 0.0f; - float times[m_profileCapacity]; - float stepTimes[m_profileCapacity]; - float pairsTimes[m_profileCapacity]; - float collideTimes[m_profileCapacity]; - float solveTimes[m_profileCapacity]; - float sensorsTimes[m_profileCapacity]; int count = m_profileWriteIndex - m_profileReadIndex; + + // Unroll ring buffer into per-field histories. + constexpr int kRowCount = 22; + float histories[kRowCount][m_profileCapacity]; + float totals[kRowCount] = {}; for ( int i = 0; i < count; ++i ) { - int index = ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ); - times[i] = i / 60.0f; - stepTimes[i] = m_profiles[index].step; - pairsTimes[i] = m_profiles[index].pairs; - collideTimes[i] = m_profiles[index].collide; - solveTimes[i] = m_profiles[index].solve; - sensorsTimes[i] = m_profiles[index].sensors; - maxValue = b3MaxFloat( stepTimes[i], maxValue ); + int idx = ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ); + const b3Profile& p = m_profiles[idx]; + histories[0][i] = p.step; + histories[1][i] = p.pairs; + histories[2][i] = p.collide; + histories[3][i] = p.solve; + histories[4][i] = p.solverSetup; + histories[5][i] = p.constraints; + histories[6][i] = p.prepareConstraints; + histories[7][i] = p.integrateVelocities; + histories[8][i] = p.warmStart; + histories[9][i] = p.solveImpulses; + histories[10][i] = p.integratePositions; + histories[11][i] = p.relaxImpulses; + histories[12][i] = p.applyRestitution; + histories[13][i] = p.storeImpulses; + histories[14][i] = p.splitIslands; + histories[15][i] = p.transforms; + histories[16][i] = p.jointEvents; + histories[17][i] = p.hitEvents; + histories[18][i] = p.refit; + histories[19][i] = p.sleepIslands; + histories[20][i] = p.bullets; + histories[21][i] = p.sensors; + + totals[0] += p.step; + totals[1] += p.pairs; + totals[2] += p.collide; + totals[3] += p.solve; + totals[4] += p.solverSetup; + totals[5] += p.constraints; + totals[6] += p.prepareConstraints; + totals[7] += p.integrateVelocities; + totals[8] += p.warmStart; + totals[9] += p.solveImpulses; + totals[10] += p.integratePositions; + totals[11] += p.relaxImpulses; + totals[12] += p.applyRestitution; + totals[13] += p.storeImpulses; + totals[14] += p.splitIslands; + totals[15] += p.transforms; + totals[16] += p.jointEvents; + totals[17] += p.hitEvents; + totals[18] += p.refit; + totals[19] += p.sleepIslands; + totals[20] += p.bullets; + totals[21] += p.sensors; } - // ImPlot picks a 5 second major interval at this width, leaving one bright line among the half seconds - ImPlot::PushStyleVar( ImPlotStyleVar_MinorAlpha, 1.0f ); - ImPlot::PushStyleColor( ImPlotCol_AxisGrid, IM_COL32( 255, 255, 255, 15 ) ); - - ImVec2 plotSize = ImGui::GetContentRegionAvail(); - if ( ImPlot::BeginPlot( "Profile", plotSize, ImPlotFlags_NoTitle ) ) + // Smoothed over the last few frames so bars don't jitter visibly. + constexpr int kNowWindow = 10; + float now[kRowCount] = {}; { - ImPlot::SetupAxes( nullptr, "ms" ); - ImPlot::SetupAxisLimits( ImAxis_X1, 0.0, m_profileCapacity / 60.0 ); - ImPlot::SetupAxisLimits( ImAxis_Y1, 0.0, b3MaxFloat( maxValue, 1.0f ) * 1.05, ImPlotCond_Always ); - ImPlot::SetNextLineStyle( ImGui::ColorConvertU32ToFloat4( s_colorStep ) ); - ImPlot::PlotLine( "step", times, stepTimes, count ); - ImPlot::SetNextLineStyle( ImGui::ColorConvertU32ToFloat4( s_colorPairs ) ); - ImPlot::PlotLine( "pairs", times, pairsTimes, count ); - ImPlot::SetNextLineStyle( ImGui::ColorConvertU32ToFloat4( s_colorCollide ) ); - ImPlot::PlotLine( "collide", times, collideTimes, count ); - ImPlot::SetNextLineStyle( ImGui::ColorConvertU32ToFloat4( s_colorSolve ) ); - ImPlot::PlotLine( "solve", times, solveTimes, count ); - ImPlot::SetNextLineStyle( ImGui::ColorConvertU32ToFloat4( s_colorSensors ) ); - ImPlot::PlotLine( "sensors", times, sensorsTimes, count ); - ImPlot::EndPlot(); + int n = count < kNowWindow ? count : kNowWindow; + if ( n > 0 ) + { + float inv = 1.0f / n; + for ( int r = 0; r < kRowCount; ++r ) + { + float sum = 0.0f; + for ( int i = count - n; i < count; ++i ) + { + sum += histories[r][i]; + } + now[r] = sum * inv; + } + } } - ImPlot::PopStyleColor(); - ImPlot::PopStyleVar(); + // Rolling average + float avg[kRowCount] = {}; + if ( count > 0 ) + { + float scale = 1.0f / count; + for ( int i = 0; i < kRowCount; ++i ) + { + avg[i] = scale * totals[i]; + } + } + + float rowMax[kRowCount] = {}; + for ( int r = 0; r < kRowCount; ++r ) + { + for ( int i = 0; i < count; ++i ) + { + if ( histories[r][i] > rowMax[r] ) + { + rowMax[r] = histories[r][i]; + } + } + } + + // Match Frame Time chart's first three colors so rows read with the line plot. + const ImU32 colorStep = IM_COL32( 102, 153, 255, 255 ); + const ImU32 colorPairs = IM_COL32( 220, 220, 220, 255 ); + const ImU32 colorCollide = IM_COL32( 255, 140, 51, 255 ); + const ImU32 colorSolve = IM_COL32( 102, 204, 102, 255 ); + const ImU32 colorSensors = IM_COL32( 200, 120, 220, 255 ); + const ImU32 colorOther = IM_COL32( 90, 90, 90, 255 ); + const ImU32 colorDefault = IM_COL32( 220, 220, 220, 255 ); + + const RowDef rows[kRowCount] = { + { "step", 0, colorStep }, { "pairs", 0, colorPairs }, { "collide", 0, colorCollide }, + { "solve", 0, colorSolve }, { "setup", 1, colorDefault }, { "constraints", 1, colorDefault }, + { "prepare", 2, colorDefault }, { "velocities", 2, colorDefault }, { "warm start", 2, colorDefault }, + { "bias", 2, colorDefault }, { "positions", 2, colorDefault }, { "relax", 2, colorDefault }, + { "restitution", 2, colorDefault }, { "store", 2, colorDefault }, { "split islands", 2, colorDefault }, + { "transforms", 1, colorDefault }, { "joint events", 1, colorDefault }, { "hit events", 1, colorDefault }, + { "refit BVH", 1, colorDefault }, { "sleep", 1, colorDefault }, { "bullets", 1, colorDefault }, + { "sensors", 0, colorSensors }, + }; + + // Derive parent/child links from the indent levels so we can collapse subtrees. + int parents[kRowCount]; + bool hasChildren[kRowCount] = {}; + { + int stack[8]; + int stackSize = 0; + for ( int i = 0; i < kRowCount; ++i ) + { + while ( stackSize > 0 && rows[stack[stackSize - 1]].indent >= rows[i].indent ) + { + --stackSize; + } + parents[i] = stackSize > 0 ? stack[stackSize - 1] : -1; + stack[stackSize++] = i; + if ( parents[i] >= 0 ) + { + hasChildren[parents[i]] = true; + } + } + } + + static bool s_rowOpen[kRowCount]; + static bool s_showPlots = false; + + // Bars are drawn relative to the step row so the proportions are visually consistent. + const float stepNow = b3MaxFloat( now[0], 0.001f ); + + if ( ImGui::Button( "Reset" ) ) + { + ResetProfile(); + } + ImGui::SameLine(); + ImGui::Checkbox( "Show plots", &s_showPlots ); + ImGui::SameLine(); + ImGui::Text( " step %.2f ms", now[0] ); + + // Flame strip: step subdivided by top-level children. + { + float pairsT = now[1]; + float collideT = now[2]; + float solveT = now[3]; + float sensorsT = now[21]; + float otherT = b3MaxFloat( stepNow - pairsT - collideT - solveT - sensorsT, 0.0f ); + + float availWidth = ImGui::GetContentRegionAvail().x; + float barHeight = 1.5f * fontSize; + ImDrawList* dl = ImGui::GetWindowDrawList(); + ImVec2 cursor = ImGui::GetCursorScreenPos(); + float x = cursor.x; + + x = AddSegment( dl, availWidth, pairsT, stepNow, colorPairs, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, collideT, stepNow, colorCollide, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, solveT, stepNow, colorSolve, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, sensorsT, stepNow, colorSensors, x, cursor, barHeight ); + x = AddSegment( dl, availWidth, otherT, stepNow, colorOther, x, cursor, barHeight ); + + ImGui::Dummy( ImVec2( availWidth, barHeight ) ); + } + + const ImGuiTableFlags tableFlags = + ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_ScrollY; + + const int colCount = s_showPlots ? 6 : 5; + ImVec2 tableSize = ImGui::GetContentRegionAvail(); + if ( ImGui::BeginTable( "profile", colCount, tableFlags, tableSize ) ) + { + ImGui::TableSetupColumn( "section", ImGuiTableColumnFlags_WidthFixed, 8.0f * fontSize ); + ImGui::TableSetupColumn( "now", ImGuiTableColumnFlags_WidthFixed, 3.0f * fontSize ); + ImGui::TableSetupColumn( "avg", ImGuiTableColumnFlags_WidthFixed, 3.0f * fontSize ); + ImGui::TableSetupColumn( "max", ImGuiTableColumnFlags_WidthFixed, 3.0f * fontSize ); + ImGui::TableSetupColumn( "% step", ImGuiTableColumnFlags_WidthFixed, 8.0f * fontSize ); + if ( s_showPlots ) + { + ImGui::TableSetupColumn( "history", ImGuiTableColumnFlags_WidthFixed, 16.0f * fontSize ); + } + ImGui::TableHeadersRow(); + + const float rowHeight = 1.5f * fontSize; + + for ( int r = 0; r < kRowCount; ++r ) + { + bool visible = true; + for ( int p = parents[r]; p >= 0; p = parents[p] ) + { + if ( !s_rowOpen[p] ) + { + visible = false; + break; + } + } + if ( !visible ) + { + continue; + } + + // Hide leaf rows that are entirely zero. Parents stay so structure reads. + if ( !hasChildren[r] && now[r] == 0.0f && avg[r] == 0.0f && rowMax[r] == 0.0f ) + { + continue; + } + + const RowDef& d = rows[r]; + const float* hist = histories[r]; + + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + if ( d.indent > 0 ) + { + ImGui::Indent( d.indent * fontSize ); + } + if ( hasChildren[r] ) + { + ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_OpenOnDoubleClick | + ImGuiTreeNodeFlags_NoTreePushOnOpen; + ImGui::PushStyleColor( ImGuiCol_Text, d.color ); + s_rowOpen[r] = ImGui::TreeNodeEx( d.name, flags ); + ImGui::PopStyleColor(); + } + else + { + float leafIndent = ImGui::GetTreeNodeToLabelSpacing(); + ImGui::Indent( leafIndent ); + ImGui::PushStyleColor( ImGuiCol_Text, d.color ); + ImGui::TextUnformatted( d.name ); + ImGui::PopStyleColor(); + ImGui::Unindent( leafIndent ); + } + if ( d.indent > 0 ) + { + ImGui::Unindent( d.indent * fontSize ); + } + + ImGui::TableNextColumn(); + ImGui::Text( "%6.2f", now[r] ); + ImGui::TableNextColumn(); + ImGui::Text( "%6.2f", avg[r] ); + ImGui::TableNextColumn(); + ImGui::Text( "%6.2f", rowMax[r] ); + + ImGui::TableNextColumn(); + float frac = b3ClampFloat( now[r] / stepNow, 0.0f, 1.0f ); + ImGui::PushStyleColor( ImGuiCol_PlotHistogram, d.color ); + ImGui::ProgressBar( frac, ImVec2( -FLT_MIN, 0.0f ), "" ); + ImGui::PopStyleColor(); + + if ( s_showPlots ) + { + ImGui::TableNextColumn(); + if ( count > 1 ) + { + char id[16]; + snprintf( id, sizeof( id ), "##h%d", r ); + ImGui::PushStyleColor( ImGuiCol_PlotLines, d.color ); + ImGui::PlotLines( id, hist, count, 0, nullptr, 0.0f, rowMax[r] * 1.05f + 0.001f, + ImVec2( -FLT_MIN, rowHeight ) ); + ImGui::PopStyleColor(); + } + } + } + ImGui::EndTable(); + } ImGui::EndTabItem(); } if ( ImGui::BeginTabItem( "Counters" ) ) { - b3WorldId worldId = GetMetricsWorldId(); - b3Counters s = b3World_GetCounters( worldId ); - b3Capacity c = b3World_GetMaxCapacity( worldId ); - + ImGui::BeginChild( "##counters_scroll" ); + b3Counters s = b3World_GetCounters( m_worldId ); constexpr int colorCount = sizeof( s.colorCounts ) / sizeof( s.colorCounts[0] ); - constexpr int overflowIndex = colorCount - 1; + const int overflowIndex = colorCount - 1; constexpr int manifoldBucketCount = sizeof( s.manifoldCounts ) / sizeof( s.manifoldCounts[0] ); - // Four fixed columns side by side so the whole tab fits the drawer without scrolling - const ImGuiTableFlags tableFlags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_SizingFixedFit; - if ( ImGui::BeginTable( "counters_layout", 4, tableFlags ) ) + // Bars are scaled to the largest non-overflow color so the distribution shape reads clearly; + // overflow gets its own bar against the same scale, with a red tint to flag coupling problems. + int totalCount = 0; + int maxCount = 1; + for ( int i = 0; i < colorCount; ++i ) { - ImGui::TableSetupColumn( "world", ImGuiTableColumnFlags_WidthFixed, 11.0f * fontSize ); - ImGui::TableSetupColumn( "memory", ImGuiTableColumnFlags_WidthFixed, 9.0f * fontSize ); - ImGui::TableSetupColumn( "collision", ImGuiTableColumnFlags_WidthFixed, 11.0f * fontSize ); - ImGui::TableSetupColumn( "solver", ImGuiTableColumnFlags_WidthStretch ); + totalCount += s.colorCounts[i]; + if ( i != overflowIndex && s.colorCounts[i] > maxCount ) + { + maxCount = s.colorCounts[i]; + } + } + + int totalManifolds = 0; + int maxManifolds = 1; + for ( int i = 0; i < manifoldBucketCount; ++i ) + { + totalManifolds += s.manifoldCounts[i]; + if ( s.manifoldCounts[i] > maxManifolds ) + { + maxManifolds = s.manifoldCounts[i]; + } + } + + ImGui::Text( "bodies/shapes/contacts/joints = %d/%d/%d/%d", s.bodyCount, s.shapeCount, s.contactCount, s.jointCount ); + { + float frac = s.awakeContactCount > 0 + ? b3ClampFloat( (float)s.recycledContactCount / (float)s.awakeContactCount, 0.0f, 1.0f ) + : 0.0f; + + char overlay[32]; + snprintf( overlay, sizeof( overlay ), "%d / %d", s.recycledContactCount, s.awakeContactCount ); + + ImGui::TextUnformatted( "recycled contacts" ); + ImGui::SameLine(); + ImGui::ProgressBar( frac, ImVec2( -FLT_MIN, 0.0f ), overlay ); + } + ImGui::Text( "islands/tasks = %d/%d", s.islandCount, s.taskCount ); + ImGui::Text( "tree height static/movable = %d/%d", s.staticTreeHeight, s.treeHeight ); + ImGui::Text( "sat call/hit = %d/%d", s.satCallCount, s.satCacheHitCount ); + ImGui::Text( "toi d/p/r = %d/%d/%d", s.distanceIterations, s.pushBackIterations, s.rootIterations ); + ImGui::Text( "stack allocator size = %d K", s.stackUsed / 1024 ); + ImGui::Text( "arena capacity = %d K", s.arenaCapacity / 1024 ); + ImGui::Text( "total allocation = %d K", s.byteCount / 1024 ); + + ImGui::Separator(); + b3Capacity c = b3World_GetMaxCapacity( m_worldId ); + ImGui::Text( "max capacities" ); + ImGui::BulletText( "static shapes/bodies = %d/%d", c.staticShapeCount, c.staticBodyCount ); + ImGui::BulletText( "dynamic shapes/bodies = %d/%d", c.dynamicShapeCount, c.dynamicBodyCount ); + ImGui::BulletText( "contacts = %d", c.contactCount ); + + ImGui::Separator(); + ImGui::Text( "%d constraints across %d colors", totalCount, colorCount ); + + const ImGuiTableFlags tableFlags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit; + if ( ImGui::BeginTable( "graphColors", 3, tableFlags ) ) + { + ImGui::TableSetupColumn( "color", ImGuiTableColumnFlags_WidthFixed, 3.5f * fontSize ); + ImGui::TableSetupColumn( "count", ImGuiTableColumnFlags_WidthFixed, 5.0f * fontSize ); + ImGui::TableSetupColumn( "share", ImGuiTableColumnFlags_WidthFixed, 16.0f * fontSize ); ImGui::TableHeadersRow(); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::Text( "bodies %d / %d", s.bodyCount, c.staticBodyCount + c.dynamicBodyCount ); - ImGui::SetItemTooltip( "max static %d, dynamic %d", c.staticBodyCount, c.dynamicBodyCount ); - ImGui::Text( "shapes %d / %d", s.shapeCount, c.staticShapeCount + c.dynamicShapeCount ); - ImGui::SetItemTooltip( "max static %d, dynamic %d", c.staticShapeCount, c.dynamicShapeCount ); - ImGui::Text( "contacts %d / %d", s.contactCount, c.contactCount ); - ImGui::SetItemTooltip( "current / max" ); - ImGui::Text( "joints %d", s.jointCount ); - ImGui::Text( "islands %d", s.islandCount ); - ImGui::Text( "tasks %d / %d", s.enqueueCount, s.taskCount ); + const float invMax = 1.0f / static_cast( maxCount ); - ImGui::TableNextColumn(); - ImGui::Text( "static tree %d", s.staticTreeHeight ); - ImGui::SetItemTooltip( "tree height" ); - ImGui::Text( "movable tree %d", s.treeHeight ); - ImGui::SetItemTooltip( "tree height" ); - ImGui::Text( "world %lld K", (long long)( s.byteCount / 1024 ) ); - ImGui::Text( "stack %d K", s.stackUsed / 1024 ); - ImGui::Text( "arena %d K", s.arenaCapacity / 1024 ); - - ImGui::TableNextColumn(); - ImGui::Text( "sat %d / %d", s.satCallCount, s.satCacheHitCount ); - ImGui::SetItemTooltip( "SAT calls / cache hits" ); - ImGui::Text( "toi %d / %d / %d", s.distanceIterations, s.pushBackIterations, s.rootIterations ); - ImGui::SetItemTooltip( "TOI distance / push back / root iterations" ); - - // One bucket per manifold count, up to the cap - constexpr int manifoldBarCount = manifoldBucketCount; - int totalManifolds = 0; - int maxManifolds = 0; - ImU32 manifoldColors[manifoldBarCount]; - for ( int i = 0; i < manifoldBarCount; ++i ) - { - totalManifolds += s.manifoldCounts[i]; - maxManifolds = b3MaxInt( maxManifolds, s.manifoldCounts[i] ); - manifoldColors[i] = s_colorPairs; - } - - ImGui::TextDisabled( "manifolds per pair" ); - ImVec2 manifoldSize = { ImGui::GetContentRegionAvail().x, 4.0f * fontSize }; - int hoveredBucket = - DrawBarChart( "##manifolds", s.manifoldCounts, manifoldColors, manifoldBarCount, maxManifolds, manifoldSize ); - if ( hoveredBucket >= 0 ) - { - ImGui::SetTooltip( "%d manifolds: %d of %d pairs", hoveredBucket + 1, s.manifoldCounts[hoveredBucket], - totalManifolds ); - } - - ImGui::TableNextColumn(); - - // Bars are scaled to the largest normal color so the distribution shape reads clearly. Overflow - // gets a share bar of its own below to flag coupling problems. - int totalCount = 0; - int maxCount = 0; - ImU32 colors[overflowIndex]; for ( int i = 0; i < colorCount; ++i ) { - totalCount += s.colorCounts[i]; - if ( i != overflowIndex ) + int count = s.colorCounts[i]; + bool isOverflow = ( i == overflowIndex ); + + // Skip empty slots, but always show overflow — a non-zero overflow row is the signal we care about. + if ( count == 0 && !isOverflow ) { - maxCount = b3MaxInt( maxCount, s.colorCounts[i] ); - uint32_t hex = static_cast( b3GetGraphColor( i ) ); - colors[i] = IM_COL32( ( hex >> 16 ) & 0xFF, ( hex >> 8 ) & 0xFF, hex & 0xFF, 255 ); + continue; } + + uint32_t hex = static_cast( b3GetGraphColor( i ) ); + ImU32 swatch = IM_COL32( ( hex >> 16 ) & 0xFF, ( hex >> 8 ) & 0xFF, hex & 0xFF, 255 ); + ImU32 barColor = isOverflow ? IM_COL32( 220, 60, 60, 255 ) : swatch; + + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + if ( isOverflow ) + { + ImGui::PushStyleColor( ImGuiCol_Text, IM_COL32( 220, 60, 60, 255 ) ); + ImGui::TextUnformatted( "over" ); + ImGui::PopStyleColor(); + } + else + { + ImGui::PushStyleColor( ImGuiCol_Text, swatch ); + ImGui::Text( "%d", i ); + ImGui::PopStyleColor(); + } + + ImGui::TableNextColumn(); + ImGui::Text( "%d", count ); + + ImGui::TableNextColumn(); + float frac = b3ClampFloat( count * invMax, 0.0f, 1.0f ); + ImGui::PushStyleColor( ImGuiCol_PlotHistogram, barColor ); + ImGui::ProgressBar( frac, ImVec2( -FLT_MIN, 0.0f ), "" ); + ImGui::PopStyleColor(); } - int overflowCount = s.colorCounts[overflowIndex]; - - ImGui::Text( "%d constraints across %d colors", totalCount, overflowIndex ); - - ImVec2 colorSize = { ImGui::GetContentRegionAvail().x, 5.0f * fontSize }; - int hoveredColor = DrawBarChart( "##colors", s.colorCounts, colors, overflowIndex, maxCount, colorSize ); - if ( hoveredColor >= 0 ) - { - ImGui::SetTooltip( "color %d: %d", hoveredColor, s.colorCounts[hoveredColor] ); - } - - // Overflow and recycling share a line to keep the column within the drawer height - float halfWidth = 0.5f * ( ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x ); - - float overflowFrac = totalCount > 0 ? (float)overflowCount / (float)totalCount : 0.0f; - char overflowOverlay[32]; - snprintf( overflowOverlay, sizeof( overflowOverlay ), "overflow %d", overflowCount ); - ImGui::PushStyleColor( ImGuiCol_PlotHistogram, IM_COL32( 220, 60, 60, 255 ) ); - ImGui::ProgressBar( overflowFrac, ImVec2( halfWidth, 0.0f ), overflowOverlay ); - ImGui::PopStyleColor(); - ImGui::SetItemTooltip( "Constraints in the overflow color, solved serially" ); - ImGui::SameLine(); - - float recycledFrac = s.awakeContactCount > 0 - ? b3ClampFloat( (float)s.recycledContactCount / (float)s.awakeContactCount, 0.0f, 1.0f ) - : 0.0f; - char recycledOverlay[48]; - snprintf( recycledOverlay, sizeof( recycledOverlay ), "recycled %d / %d", s.recycledContactCount, - s.awakeContactCount ); - ImGui::ProgressBar( recycledFrac, ImVec2( -FLT_MIN, 0.0f ), recycledOverlay ); - ImGui::SetItemTooltip( "Awake contacts that reused last step's manifold" ); - ImGui::EndTable(); } + ImGui::Separator(); + ImGui::Text( "%d manifolds across %d buckets", totalManifolds, manifoldBucketCount ); + if ( ImGui::BeginTable( "manifolds", 3, tableFlags ) ) + { + ImGui::TableSetupColumn( "manifolds", ImGuiTableColumnFlags_WidthFixed, 3.5f * fontSize ); + ImGui::TableSetupColumn( "count", ImGuiTableColumnFlags_WidthFixed, 5.0f * fontSize ); + ImGui::TableSetupColumn( "share", ImGuiTableColumnFlags_WidthFixed, 16.0f * fontSize ); + ImGui::TableHeadersRow(); + + const float invMax = 1.0f / static_cast( maxManifolds ); + + for ( int i = 0; i < manifoldBucketCount; ++i ) + { + int count = s.manifoldCounts[i]; + if ( count == 0 ) + { + continue; + } + + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + ImGui::Text( "%d", i + 1 ); + + ImGui::TableNextColumn(); + ImGui::Text( "%d", count ); + + ImGui::TableNextColumn(); + float frac = b3ClampFloat( count * invMax, 0.0f, 1.0f ); + ImGui::ProgressBar( frac, ImVec2( -FLT_MIN, 0.0f ), "" ); + } + ImGui::EndTable(); + } + + ImGui::EndChild(); ImGui::EndTabItem(); } @@ -1212,6 +1080,39 @@ void Sample::DrawMetrics() ImGui::EndTabItem(); } + if ( ImGui::BeginTabItem( "Frame Time" ) ) + { + float maxValue = 0.0f; + float times[m_profileCapacity]; + float stepTimes[m_profileCapacity]; + float collideTimes[m_profileCapacity]; + float solveTimes[m_profileCapacity]; + int count = m_profileWriteIndex - m_profileReadIndex; + for ( int i = 0; i < count; ++i ) + { + int index = ( m_profileReadIndex + i ) & ( m_profileCapacity - 1 ); + times[i] = i / 60.0f; + stepTimes[i] = m_profiles[index].step; + collideTimes[i] = m_profiles[index].collide; + solveTimes[i] = m_profiles[index].solve; + maxValue = b3MaxFloat( stepTimes[i], maxValue ); + } + + ImVec2 plotSize = ImGui::GetContentRegionAvail(); + if ( ImPlot::BeginPlot( "Profile", plotSize, ImPlotFlags_NoTitle ) ) + { + ImPlot::SetupAxes( "t", "ms" ); + ImPlot::SetupAxisLimits( ImAxis_X1, 0.0, m_profileCapacity / 60.0 ); + ImPlot::SetupAxisLimits( ImAxis_Y1, 0.0, b3MaxFloat( maxValue, 1.0f ) * 1.05, ImPlotCond_Always ); + ImPlot::PlotLine( "step", times, stepTimes, count ); + ImPlot::PlotLine( "collide", times, collideTimes, count ); + ImPlot::PlotLine( "solve", times, solveTimes, count ); + ImPlot::EndPlot(); + } + + ImGui::EndTabItem(); + } + // Sample-specific tabs (the Replay viewer adds Timeline here). DrawMetricsTab(); @@ -1382,52 +1283,8 @@ void Sample::DrawTextLine( const char* text, ... ) char buffer[512]; vsnprintf( buffer, sizeof( buffer ), text, args ); va_end( args ); - - // The text arena keeps 63 characters per string, so wrap long lines at spaces and indent the rest - constexpr int capacity = 63; - constexpr int indent = 2; - const char* start = buffer; - bool first = true; - while ( true ) - { - int width = first ? capacity : capacity - indent; - int length = (int)strlen( start ); - int cut = length; - if ( length > width ) - { - cut = width; - while ( cut > 0 && start[cut] != ' ' ) - { - cut -= 1; - } - - if ( cut == 0 ) - { - cut = width; - } - } - - char line[capacity + 1]; - int offset = first ? 0 : indent; - memset( line, ' ', offset ); - memcpy( line + offset, start, cut ); - line[offset + cut] = '\0'; - DrawScreenString( m_textX, m_textLine, MakeColor( b3_colorWhite ), line ); - m_textLine += m_textIncrement; - - start += cut; - while ( *start == ' ' ) - { - start += 1; - } - - if ( *start == '\0' ) - { - break; - } - - first = false; - } + DrawScreenString( 5, m_textLine, MakeColor( b3_colorWhite ), buffer ); + m_textLine += m_textIncrement; } SampleEntry g_sampleEntries[MAX_SAMPLES]; @@ -1466,14 +1323,6 @@ void SelectSample( SampleContext* context, int selection, bool restart ) return; } - if ( restart == false ) - { - context->pause = false; - } - - // Steps queued in a sample that never consumes them must not play out in the next one - context->singleStep = 0; - // delete tolerates the first selection, before any sample exists. delete context->sample; context->sample = nullptr; @@ -1482,34 +1331,10 @@ void SelectSample( SampleContext* context, int selection, bool restart ) context->restart = restart; context->sample = g_sampleEntries[selection].CreateFcn( context ); - // A restart keeps the camera where it was, so the original starting view stays home - if ( restart == false ) - { - context->homePivot = context->camera.m_pivot; - context->homeYaw = context->camera.m_yaw; - context->homePitch = context->camera.m_pitch; - context->homeRadius = context->camera.m_radius; - } - - // A sample that knows where its content sits relative to its camera says - // so, and is taken at its word. The ceiling below guards a guess, not a - // measurement, so capping an explicit request would only hide it. - if ( context->sample->m_shadowSplitFar > 0.0f ) - { - // A sample wanting only more reach leaves the near end at zero. - float splitNear = context->sample->m_shadowSplitNear; - SetShadowSplits( splitNear > 0.0f ? splitNear : SHADOW_SPLIT_NEAR, context->sample->m_shadowSplitFar ); - } - else - { - // Otherwise fit the range to the world bounds. The bounds are a poor - // proxy for how far shadows need to reach: a ground plate stretches - // the diagonal well past anything worth shadowing, so the ceiling - // matters more than the estimate. - b3AABB bounds = b3World_GetBounds( context->sample->m_worldId ); - float diagonal = b3Distance( bounds.lowerBound, bounds.upperBound ); - SetShadowSplits( SHADOW_SPLIT_NEAR, b3ClampFloat( diagonal, SHADOW_SPLIT_FAR, SHADOW_SPLIT_FAR_MAX ) ); - } + // Fit the shadow cascade range to the world bounds. + b3AABB bounds = b3World_GetBounds( context->sample->m_worldId ); + float diagonal = b3Distance( bounds.lowerBound, bounds.upperBound ); + SetShadowSplitFar( b3ClampFloat( diagonal, SHADOW_SPLIT_FAR, 200.0f ) ); // Samples read restart only while constructing, to keep the camera across a // restart. Clear it so a later switch starts fresh. @@ -1523,20 +1348,13 @@ void OpenReplayFileDialog( SampleContext* context ) return; } - if ( NFD_Init() != NFD_OKAY ) - { - return; - } - + NFD_Init(); nfdu8char_t* outPath = nullptr; nfdu8filteritem_t filter[1] = { { "Box3D recording", "b3rec" } }; - // Start in the working directory, where recordings are saved by default. A - // deleted or unreadable working directory just means no starting point. - std::error_code ec; - std::u8string cwd = std::filesystem::current_path( ec ).u8string(); - const nfdu8char_t* defaultPath = ec ? nullptr : reinterpret_cast( cwd.c_str() ); - + // Start in the working directory, where recordings are saved by default. + std::u8string cwd = std::filesystem::current_path().u8string(); + const nfdu8char_t* defaultPath = reinterpret_cast( cwd.c_str() ); if ( NFD_OpenDialogU8( &outPath, filter, 1, defaultPath ) == NFD_OKAY ) { snprintf( context->replayFile, sizeof( context->replayFile ), "%s", outPath ); @@ -1673,61 +1491,6 @@ static void DrawRenderMenu( SampleContext& ctx ) { ImGui::MenuItem( "Shadows", nullptr, &ctx.enableShadows ); - if ( ImGui::BeginMenu( "Cascades" ) ) - { - ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() ); - - // Where the split distribution starts, not where shadows start. Raising - // it hands the whole working volume to the first cascade and coarsens - // it to suit. The c0 row below is what to steer by: it says how far the - // sharp cascade reaches and what one of its texels costs. - float splitNear = GetShadowSplitNear(); - if ( ImGui::SliderFloat( "Start", &splitNear, 0.1f, 30.0f, "%.1f m" ) ) - { - SetShadowSplits( splitNear, GetShadowSplitFar() ); - } - - // Selecting a sample refits the range to the world, so a value dialed - // in here survives only until the next sample switch. - float splitFar = GetShadowSplitFar(); - if ( ImGui::SliderFloat( "Range", &splitFar, 10.0f, 200.0f, "%.0f m" ) ) - { - SetShadowSplitFar( splitFar ); - } - - float lambda = GetShadowSplitLambda(); - if ( ImGui::SliderFloat( "Distribution", &lambda, 0.0f, 1.0f, "%.2f" ) ) - { - SetShadowSplitLambda( lambda ); - } - - ImGui::PopItemWidth(); - - // Where each cascade ends and how much world one of its texels covers. - // A quality cliff at a boundary is the step between two neighboring - // texel sizes, which is easier to read here than off the image. - if ( ImGui::BeginTable( "cascades", 3, ImGuiTableFlags_SizingFixedFit ) ) - { - ImGui::TableSetupColumn( "csm" ); - ImGui::TableSetupColumn( "far" ); - ImGui::TableSetupColumn( "texel" ); - ImGui::TableHeadersRow(); - for ( int i = 0; i < SHADOW_CASCADE_COUNT; ++i ) - { - ImGui::TableNextRow(); - ImGui::TableSetColumnIndex( 0 ); - ImGui::Text( "%d", i ); - ImGui::TableSetColumnIndex( 1 ); - ImGui::Text( "%.1f m", GetCascadeFarViewZ( i ) ); - ImGui::TableSetColumnIndex( 2 ); - ImGui::Text( "%.0f mm", 1000.0f * GetCascadeTexelWorld( i ) ); - } - ImGui::EndTable(); - } - - ImGui::EndMenu(); - } - if ( ImGui::BeginMenu( "GTAO" ) ) { ImGui::MenuItem( "Enable", nullptr, &ctx.enableGtao ); @@ -1762,11 +1525,6 @@ static void DrawRenderMenu( SampleContext& ctx ) ImGui::Separator(); ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() ); - if ( ImGui::SliderFloat( "Edge Alpha", &edgeParams.alphaScale, 0.0f, 4.0f, "%.2f" ) ) - { - SetEdgeOverlayParams( &edgeParams ); - } - float ev = GetExposure(); if ( ImGui::SliderFloat( "Exposure", &ev, -8.0f, 4.0f, "%.2f" ) ) { @@ -1809,7 +1567,7 @@ static void DrawMenuBar( SampleContext* context ) if ( ImGui::BeginMenu( "Sim" ) ) { ImGui::MenuItem( "Pause", "P", &context->pause ); - if ( ImGui::MenuItem( "Single Step", "." ) ) + if ( ImGui::MenuItem( "Single Step", "O" ) ) { context->singleStep += 1; } @@ -1820,11 +1578,11 @@ static void DrawMenuBar( SampleContext* context ) ImGui::Separator(); if ( ImGui::MenuItem( "Previous Sample", "[" ) ) { - SelectSample( context, ( context->sampleIndex + g_sampleCount - 1 ) % g_sampleCount, false ); + SelectSample( context, b3MaxInt( 0, context->sampleIndex - 1 ), false ); } if ( ImGui::MenuItem( "Next Sample", "]" ) ) { - SelectSample( context, ( context->sampleIndex + 1 ) % g_sampleCount, false ); + SelectSample( context, b3MinInt( g_sampleCount - 1, context->sampleIndex + 1 ), false ); } ImGui::Separator(); if ( ImGui::MenuItem( "Reset Profile" ) ) @@ -1836,7 +1594,7 @@ static void DrawMenuBar( SampleContext* context ) b3World_DumpMemoryStats( context->sample->m_worldId ); } ImGui::Separator(); - if ( ImGui::MenuItem( "Quit", "Ctrl+Q" ) ) + if ( ImGui::MenuItem( "Quit", "Esc" ) ) { sapp_request_quit(); } @@ -1849,31 +1607,19 @@ static void DrawMenuBar( SampleContext* context ) { context->showUI = false; } - if ( ImGui::MenuItem( "Hide UI and Text", "Shift+Tab" ) ) + if ( ImGui::MenuItem( "Frame Camera" ) ) { - context->showUI = false; - context->showText = false; - } - if ( ImGui::MenuItem( "Frame Selection", "F" ) ) - { - FrameSelection( context ); - } - if ( ImGui::MenuItem( "Reset Camera", "Home" ) ) - { - context->sample->FocusHome(); + b3AABB aabb = b3World_GetBounds( context->sample->m_worldId ); + Camera& cam = context->camera; + float aspect = cam.m_height > 0 ? (float)cam.m_width / (float)cam.m_height : 1.0f; + cam.Frame( aabb, aspect, 0.75f ); } ImGui::MenuItem( "Shapes", nullptr, &gd->drawShapes ); - if ( ImGui::BeginMenu( "Transparency" ) ) - { - ImGui::MenuItem( "Dynamic", nullptr, &context->transparentDynamic ); - ImGui::MenuItem( "Kinematic", nullptr, &context->transparentKinematic ); - ImGui::EndMenu(); - } + ImGui::MenuItem( "Transparent", nullptr, &context->transparentDynamic ); ImGui::MenuItem( "Joints", nullptr, &gd->drawJoints ); ImGui::MenuItem( "Joint Extras", nullptr, &gd->drawJointExtras ); ImGui::MenuItem( "Bounds", nullptr, &gd->drawBounds ); ImGui::MenuItem( "Mass", nullptr, &gd->drawMass ); - ImGui::MenuItem( "Sleep", nullptr, &gd->drawSleep ); ImGui::MenuItem( "Body Names", nullptr, &gd->drawBodyNames ); ImGui::MenuItem( "Graph Colors", nullptr, &gd->drawGraphColors ); ImGui::MenuItem( "Islands", nullptr, &gd->drawIslands ); @@ -1882,24 +1628,21 @@ static void DrawMenuBar( SampleContext* context ) ImGui::MenuItem( "Contact Normals", nullptr, &gd->drawContactNormals ); ImGui::MenuItem( "Contact Features", nullptr, &gd->drawContactFeatures ); ImGui::MenuItem( "Contact Forces", nullptr, &gd->drawContactForces ); + ImGui::MenuItem( "Friction Forces", nullptr, &gd->drawFrictionForces ); if ( ImGui::BeginMenu( "Anchor" ) ) { - if ( ImGui::MenuItem( "Anchor A", nullptr, gd->drawAnchorA == true ) ) + if ( ImGui::MenuItem( "Anchor A", nullptr, gd->drawAnchorA != 0 ) ) { - gd->drawAnchorA = true; + gd->drawAnchorA = 1; } - if ( ImGui::MenuItem( "Anchor B", nullptr, gd->drawAnchorA == false ) ) + if ( ImGui::MenuItem( "Anchor B", nullptr, gd->drawAnchorA == 0 ) ) { - gd->drawAnchorA = false; + gd->drawAnchorA = 0; } ImGui::EndMenu(); } ImGui::Separator(); - ImGui::MenuItem( "Metrics", "M", &context->showMetrics ); - ImGui::MenuItem( "Profile", "I", &context->showProfile, context->sample->HasProfile() ); - ImGui::PushItemWidth( 8.0f * fontSize ); - ImGui::SliderFloat( "Draw Distance", &context->drawDistance, 10.0f, Camera::kViewDistance, "%.0f m" ); - ImGui::PopItemWidth(); + ImGui::MenuItem( "Diagnostics", "M", &context->showMetrics ); ImGui::Separator(); if ( ImGui::BeginMenu( "Scale" ) ) { @@ -1986,17 +1729,13 @@ static void DrawMenuBar( SampleContext* context ) if ( ImGui::BeginTable( "keys", 2, ImGuiTableFlags_SizingFixedFit ) ) { DrawRow( "Tab", "Show / hide UI" ); - DrawRow( "Shift+Tab", "Show / hide UI and text" ); - DrawRow( "M", "Show / hide metrics" ); - DrawRow( "I", "Show / hide profile" ); + DrawRow( "M", "Show / hide diagnostics" ); DrawRow( "P", "Pause / resume" ); - DrawRow( ".", "Single step (Shift: 5)" ); - DrawRow( ",", "Step back, replay only (Shift: 5)" ); + DrawRow( "O", "Single step (Shift: 5)" ); DrawRow( "R", "Restart sample" ); DrawRow( "[ ]", "Previous / next sample" ); DrawRow( "Ctrl+O", "Open sample picker" ); - DrawRow( "F", "Frame selection" ); - DrawRow( "Home", "Reset camera" ); + DrawRow( "F", "Frame selection / world" ); DrawRow( "?", "Show / hide controls" ); DrawRow( "Esc", "Cancel / close" ); DrawRow( "Ctrl+Q", "Quit" ); @@ -2011,7 +1750,7 @@ static void DrawMenuBar( SampleContext* context ) DrawRow( "Alt + left drag", "Orbit camera" ); DrawRow( "Alt + middle drag", "Pan camera" ); DrawRow( "Alt + right drag", "Zoom (dolly)" ); - DrawRow( "Right drag", "Fly look (WASD, Q / E to move)" ); + DrawRow( "Right drag", "Fly look (WASD to move)" ); DrawRow( "Scroll", "Zoom" ); DrawRow( "Shift + left", "Shoot (Ctrl spin, Alt ragdoll)" ); ImGui::EndTable(); @@ -2143,22 +1882,6 @@ static void DrawSamplePicker( SampleContext* context ) } } -// A dot after the widget that reveals help on hover. Unlike a tooltip on the widget itself, -// it never covers the value being edited, and it is quieter than a "(?)" on every row. -static void HelpMarker( const char* text ) -{ - ImGui::SameLine( 0.0f, ImGui::GetStyle().ItemInnerSpacing.x ); - float width = ImGui::GetFontSize(); - float height = ImGui::GetFrameHeight(); - ImVec2 pos = ImGui::GetCursorScreenPos(); - ImGui::Dummy( { width, height } ); - bool hovered = ImGui::IsItemHovered(); - ImU32 color = ImGui::GetColorU32( ImGuiCol_CheckMark, hovered ? 1.0f : 0.6f ); - ImVec2 center = { pos.x + 0.5f * width, pos.y + 0.5f * height }; - ImGui::GetWindowDrawList()->AddCircleFilled( center, 0.2f * width, color ); - ImGui::SetItemTooltip( "%s", text ); -} - static void DrawInfoPanel( SampleContext* context ) { const SampleEntry& entry = g_sampleEntries[context->sampleIndex]; @@ -2187,7 +1910,7 @@ static void DrawInfoPanel( SampleContext* context ) } const float frameMs = (float)( sapp_frame_duration() * 1000.0 ); - ImGui::TextColored( HexColor( b3_colorSeaGreen ), "frame %.1f ms", frameMs ); + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "%.1f ms", frameMs ); ImGui::TextColored( HexColor( b3_colorSeaGreen ), "step %d", context->sample->m_stepCount ); ImGui::Separator(); @@ -2214,20 +1937,13 @@ static void DrawInfoPanel( SampleContext* context ) { ImGui::PushItemWidth( 6.0f * fontSize ); ImGui::SliderInt( "Sub-steps##Solver", &context->subStepCount, 1, 50 ); - HelpMarker( "The solver breaks the full step into several sub-steps.\nMore sub-steps usually lead to more accurate results." ); - - ImGui::SliderInt( "Bounce Iters##Solver", &context->restitutionIterations, 0, 8 ); - HelpMarker( "Iterations for the restitution solver." ); - - ImGui::SliderFloat( "Hertz##Solver", &context->hertz, 5.0f, 240.0f, "%.0f Hz" ); - HelpMarker( "The number of world steps per second." ); + ImGui::SliderFloat( "Hertz##Solver", &context->hertz, 5.0f, 240.0f, "%.0f hz" ); if ( ImGui::SliderInt( "Workers##Solver", &context->workerCount, 1, B3_MAX_WORKERS ) ) { context->workerCount = b3ClampInt( context->workerCount, 1, B3_MAX_WORKERS ); SelectSample( context, context->sampleIndex, true ); } - HelpMarker( "The number worker threads used by the world step." ); float recyclingCentimeters = 100.0f * context->recycleDistance; if ( ImGui::SliderFloat( "Recycle##Solver", &recyclingCentimeters, 0.0f, 10.0f, "%.1f cm" ) ) @@ -2235,27 +1951,11 @@ static void DrawInfoPanel( SampleContext* context ) context->recycleDistance = 0.01f * recyclingCentimeters; b3World_SetContactRecycleDistance( context->sample->m_worldId, context->recycleDistance ); } - HelpMarker( "The contact recycling distance tolerance.\nSet to zero to disable recycling." ); ImGui::PopItemWidth(); ImGui::Checkbox( "Sleep##Solver", &context->enableSleep ); - HelpMarker( "Allow bodies to sleep, reducing simulation CPU cost." ); - ImGui::Checkbox( "Warm Starting##Solver", &context->enableWarmStarting ); - HelpMarker( "Enable solver warm starting which usually improves stacking stability." ); - ImGui::Checkbox( "Continuous##Solver", &context->enableContinuous ); - HelpMarker( "Enable continuous collision detection." ); - - ImGui::Checkbox( "Bounce Propagation##Solver", &context->enableRestitutionPropagation ); - HelpMarker( "Enable restitution solver propagation across all touching contacts points" ); - - static bool avx2Available = b3IsAVX2Available(); - if ( avx2Available ) - { - ImGui::Checkbox( "SSE2 Fallback##Solver", &context->enableSSE2Fallback ); - HelpMarker( "Use the 4 wide SSE2 path instead of the 8 wide AVX2 path.\nThe simulation is bitwise identical either way." ); - } if ( ImGui::Shortcut( ImGuiKey_R ) || ImGui::Button( "Restart" ) ) { @@ -2283,16 +1983,6 @@ static void DrawInfoPanel( SampleContext* context ) { context->sample->StartRecording(); } - - if ( g_replayIndex >= 0 && context->savedRecordingFile[0] != 0 ) - { - if ( ImGui::Button( "Play##Recording" ) ) - { - snprintf( context->replayFile, sizeof( context->replayFile ), "%s", context->savedRecordingFile ); - SelectSample( context, g_replayIndex, false ); - } - ImGui::SetItemTooltip( "Open %s in the replay viewer", context->savedRecordingFile ); - } } else { @@ -2300,20 +1990,7 @@ static void DrawInfoPanel( SampleContext* context ) { context->sample->FinishRecording(); } - } - - if ( context->sample->m_recording != nullptr ) - { - float kilobytes = b3Recording_GetSize( context->sample->m_recording ) / 1024.0f; - int steps = context->sample->m_stepCount - context->sample->m_recordStartStep; - if ( kilobytes < 1024.0f ) - { - ImGui::TextColored( HexColor( b3_colorRed ), "recording %d steps, %.0f KB", steps, kilobytes ); - } - else - { - ImGui::TextColored( HexColor( b3_colorRed ), "recording %d steps, %.1f MB", steps, kilobytes / 1024.0f ); - } + ImGui::TextColored( HexColor( b3_colorSeaGreen ), "recording (from step %d)", context->sample->m_recordStartStep ); } } @@ -2327,7 +2004,7 @@ static void DrawHud( SampleContext* context ) const SampleEntry& entry = g_sampleEntries[context->sampleIndex]; float fontSize = ImGui::GetFontSize(); - DrawScreenStringFormat( 5, (int)( 0.5f * fontSize ), MakeColor( b3_colorYellow ), "%s : %s", entry.Category, entry.Name ); + DrawScreenStringFormat( 5, (int)( 1.5f * fontSize ), MakeColor( b3_colorYellow ), "%s : %s", entry.Category, entry.Name ); if ( context->pause ) { @@ -2343,10 +2020,7 @@ void DrawUI( SampleContext* context ) // Hidden shows only the minimal in-world HUD. if ( context->showUI == false ) { - if ( context->showText ) - { - DrawHud( context ); - } + DrawHud( context ); return; } @@ -2357,8 +2031,7 @@ void DrawUI( SampleContext* context ) // Extra top-level windows (the Replay viewer adds the Outline panel). context->sample->DrawSampleWindows(); - // Sample controls live in the info panel. - context->sample->DrawProfile(); + // Bottom diagnostics drawer. Sample controls live in the info panel. context->sample->DrawMetrics(); } @@ -2377,46 +2050,6 @@ void Sample::ToggleThirdPerson() } } -MoverInput Sample::GetMoverInput() const -{ - MoverInput input = {}; - input.forward = -m_camera->GetForward(); - input.right = m_camera->GetRight(); - - input.forward.y = 0.0f; - input.forward = b3Normalize( input.forward ); - - if ( m_camera->m_thirdPerson == false ) - { - return input; - } - - if ( IsKeyDown( KEY_W ) ) - { - input.throttle.x += 1.0f; - } - - if ( IsKeyDown( KEY_S ) ) - { - input.throttle.x -= 1.0f; - } - - if ( IsKeyDown( KEY_A ) ) - { - input.throttle.y -= 1.0f; - } - - if ( IsKeyDown( KEY_D ) ) - { - input.throttle.y += 1.0f; - } - - input.jump = IsKeyDown( KEY_SPACE ); - input.sprint = IsKeyDown( KEY_LEFT_SHIFT ) || IsKeyDown( KEY_RIGHT_SHIFT ); - input.walk = IsKeyDown( KEY_LEFT_CONTROL ) || IsKeyDown( KEY_RIGHT_CONTROL ); - return input; -} - float CastClosestCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t materialId, int triangleIndex, int childIndex, void* context ) { @@ -2432,23 +2065,329 @@ float CastClosestCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float return fraction; } -MechanicalEnergy MeasureEnergy( b3WorldId worldId, const b3BodyId* bodyIds, int count ) +static bool MoverFilterCallback( b3ShapeId shapeId, void* context ) { - b3Vec3 gravity = b3World_GetGravity( worldId ); - - MechanicalEnergy energy = {}; - for ( int i = 0; i < count; ++i ) + CharacterMover* self = (CharacterMover*)context; + for ( int i = 0; i < self->m_ignoreCount; ++i ) { - b3MassData massData = b3Body_GetMassData( bodyIds[i] ); - b3Vec3 v = b3Body_GetLinearVelocity( bodyIds[i] ); - - // The inertia tensor is in the body frame, so bring the angular velocity back to it - b3Vec3 w = b3InvRotateVector( b3Body_GetRotation( bodyIds[i] ), b3Body_GetAngularVelocity( bodyIds[i] ) ); - - energy.linear += 0.5f * massData.mass * b3Dot( v, v ); - energy.angular += 0.5f * b3Dot( w, b3MulMV( massData.inertia, w ) ); - energy.potential -= massData.mass * b3Dot( gravity, b3ToVec3( b3Body_GetWorldCenter( bodyIds[i] ) ) ); + if ( B3_ID_EQUALS( shapeId, self->m_ignoreShapeIds[i] ) ) + { + return false; + } } - return energy; + return true; +} + +void CharacterMover::Initialize( Sample* sample, b3Pos position ) +{ + m_sample = sample; + m_transform.p = position; + m_transform.q = b3Quat_identity; + m_velocity = { 0.0f, 0.0f, 0.0f }; + m_capsule = { { 0.0f, -0.5f, 0.0f }, { 0.0f, 0.5f, 0.0f }, 0.3f }; + + m_planeCount = 0; + m_totalIterations = 0; + m_pogoVelocity = 0.0f; + m_onGround = false; + m_sprint = false; + + m_ignoreShapeIds = nullptr; + m_ignoreCount = 0; +} + +static bool PlaneResultFcn( b3ShapeId shapeId, const b3PlaneResult* planeResults, int planeCount, void* context ) +{ + if ( MoverFilterCallback( shapeId, context ) == false ) + { + // ignore these planes but continue looking for more + return true; + } + + CharacterMover* self = static_cast( context ); + float maxPush = FLT_MAX; + bool clipVelocity = true; + MoverShapeUserData* userData = static_cast( (void*)b3Shape_GetUserData( shapeId ) ); + if ( userData != nullptr ) + { + maxPush = userData->maxPush; + clipVelocity = userData->clipVelocity; + } + + for ( int i = 0; i < planeCount && self->m_planeCount < CharacterMover::m_planeCapacity; ++i ) + { + assert( b3IsValidPlane( planeResults[i].plane ) ); + self->m_planes[self->m_planeCount] = { + .plane = planeResults[i].plane, + .pushLimit = maxPush, + .push = 0.0f, + .clipVelocity = clipVelocity, + }; + self->m_planeExtras[self->m_planeCount] = { + .point = b3OffsetPos( self->m_transform.p, planeResults[i].point ), + .shapeId = shapeId, + }; + self->m_planeCount += 1; + } + + return true; +} + +void CharacterMover::SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, bool clipVelocity ) +{ + // Friction + float speed = b3Length( m_velocity ); + if ( speed < m_minSpeed ) + { + m_velocity.x = 0.0f; + m_velocity.y = 0.0f; + } + else + { + // Linear damping above stopSpeed and fixed reduction below stopSpeed + float control = speed < m_stopSpeed ? m_stopSpeed : speed; + + // friction has units of 1/time + float drop = control * m_friction * timeStep; + float newSpeed = b3MaxFloat( 0.0f, speed - drop ); + m_velocity *= newSpeed / speed; + } + + float maxSpeed = m_sprint ? 1.5f * m_maxSpeed : m_maxSpeed; + + b3Vec3 desiredVelocity = maxSpeed * throttle.x * forward + maxSpeed * throttle.y * right; + float desiredSpeed; + b3Vec3 desiredDirection = b3GetLengthAndNormalize( &desiredSpeed, desiredVelocity ); + + if ( desiredSpeed > maxSpeed ) + { + desiredVelocity *= maxSpeed / desiredSpeed; + desiredSpeed = maxSpeed; + } + + if ( m_onGround ) + { + m_velocity.y = 0.0f; + } + + // Accelerate + float currentSpeed = b3Dot( m_velocity, desiredDirection ); + float addSpeed = desiredSpeed - currentSpeed; + if ( addSpeed > 0.0f ) + { + float accelSpeed = m_accelerate * maxSpeed * timeStep; + if ( accelSpeed > addSpeed ) + { + accelSpeed = addSpeed; + } + + m_velocity += accelSpeed * desiredDirection; + } + + m_velocity.y -= m_gravity * timeStep; + + b3WorldId worldId = m_sample->m_worldId; + + float pogoRestLength = 3.0f * m_capsule.radius; + float rayLength = pogoRestLength + m_capsule.radius; + b3Pos rayOrigin = b3TransformWorldPoint( m_transform, m_capsule.center1 ); + b3Vec3 rayTranslation = -rayLength * b3Vec3_axisY; + b3QueryFilter skipTeamFilter = { 1, ~2u }; + skipTeamFilter.name = "pogo"; + b3RayResult rayResult = b3World_CastRayClosest( worldId, rayOrigin, rayTranslation, skipTeamFilter ); + + if ( rayResult.hit == false ) + { + m_onGround = false; + m_pogoVelocity = 0.0f; + + DrawLine( rayOrigin, b3OffsetPos( rayOrigin, rayTranslation ), MakeColor( b3_colorGray ) ); + } + else + { + m_onGround = true; + float pogoCurrentLength = rayResult.fraction * rayLength; + + float zeta = 0.7f; + float hertz = 4.0f; + float omega = 2.0f * B3_PI * hertz; + float omegaH = omega * timeStep; + + m_pogoVelocity = ( m_pogoVelocity - omega * omegaH * ( pogoCurrentLength - pogoRestLength ) ) / + ( 1.0f + 2.0f * zeta * omegaH + omegaH * omegaH ); + DrawLine( rayOrigin, rayResult.point, MakeColor( b3_colorGreen ) ); + } + + b3Pos startPosition = m_transform.p; + b3Pos target = m_transform.p + timeStep * m_velocity + timeStep * m_pogoVelocity * b3Vec3_axisY; + + // Want the mover to collide with allies + b3QueryFilter moverFilter = { .categoryBits = 1, .maskBits = ~0u, .id = 1, .name = "mover_collide" }; + + // The cast should ignore allies + b3QueryFilter castFilter = { .categoryBits = 1, .maskBits = ~2u, .id = 1, .name = "mover_cast" }; + + m_totalIterations = 0; + float tolerance = 0.01f; + + for ( int iteration = 0; iteration < 5; ++iteration ) + { + m_planeCount = 0; + + b3Capsule mover; + mover.center1 = m_capsule.center1; + mover.center2 = m_capsule.center2; + mover.radius = m_capsule.radius; + + b3World_CollideMover( worldId, m_transform.p, &mover, moverFilter, PlaneResultFcn, this ); + + b3Vec3 targetDelta = target - m_transform.p; + b3PlaneSolverResult result = b3SolvePlanes( targetDelta, m_planes, m_planeCount ); + + m_totalIterations += result.iterationCount; + + b3Vec3 delta = result.delta; + + float fraction = b3World_CastMover( worldId, m_transform.p, &mover, delta, castFilter, MoverFilterCallback, this ); + + delta *= fraction; + m_transform.p = m_transform.p + delta; + + if ( b3LengthSquared( delta ) < tolerance * tolerance ) + { + break; + } + } + + for ( int i = 0; i < m_planeCount; ++i ) + { + b3BodyId bodyId = b3Shape_GetBody( m_planeExtras[i].shapeId ); + b3BodyType bodyType = b3Body_GetType( bodyId ); + if ( bodyType != b3_dynamicBody ) + { + continue; + } + + b3Pos point = m_planeExtras[i].point; + b3Vec3 normal = b3Neg( m_planes[i].plane.normal ); + + float invMassA = 0.0f; + float invMassB = b3Body_GetInverseMass( bodyId ); + b3Matrix3 invIB = b3Body_GetWorldInverseRotationalInertia( bodyId ); + + b3Pos pB = b3Body_GetWorldCenterOfMass( bodyId ); + b3Vec3 rB = b3SubPos( point, pB ); + + b3Vec3 rnB = b3Cross( rB, normal ); + float kNormal = invMassA + invMassB + b3Dot( rnB, b3MulMV( invIB, rnB ) ); + float normalMass = kNormal > 0.0f ? 1.0f / kNormal : 0.0f; + + b3Vec3 vB = b3Body_GetLinearVelocity( bodyId ); + b3Vec3 omegaB = b3Body_GetAngularVelocity( bodyId ); + b3Vec3 vrB = b3Add( vB, b3Cross( omegaB, rB ) ); + float vn = b3Dot( b3Sub( vrB, m_velocity ), normal ); + float impulse = b3MaxFloat( -normalMass * vn, 0.0f ); + + b3Vec3 P = b3MulSV( impulse, normal ); + m_velocity = b3MulSub( m_velocity, invMassA, P ); + + b3Body_ApplyLinearImpulse( bodyId, P, point, true ); + } + + if ( clipVelocity ) + { + // Using the velocity clipper can avoid picking up velocity from depenetration. + // This allows the mover to avoid velocity from soft collision depenetration. + m_velocity = b3ClipVector( m_velocity, m_planes, m_planeCount ); + } + else if ( timeStep > 0.0f ) + { + // Using the position delta is more holistic and intuitive in some cases. + m_velocity = ( 1.0f / timeStep ) * ( m_transform.p - startPosition ); + } +} + +void CharacterMover::Step( b3ShapeId* ignoreShapes, int ignoreCount, bool clipVelocity ) +{ + m_ignoreShapeIds = ignoreShapes; + m_ignoreCount = ignoreCount; + + b3Vec2 throttle = { 0.0f, 0.0f }; + b3Vec3 forward = -m_sample->m_camera->GetForward(); + b3Vec3 right = m_sample->m_camera->GetRight(); + forward.y = 0.0f; + + if ( m_sample->m_camera->m_thirdPerson ) + { + if ( IsKeyDown( KEY_W ) ) + { + throttle.x += 1.0f; + } + + if ( IsKeyDown( KEY_S ) ) + { + throttle.x -= 1.0f; + } + + if ( IsKeyDown( KEY_A ) ) + { + throttle.y -= 1.0f; + } + + if ( IsKeyDown( KEY_D ) ) + { + throttle.y += 1.0f; + } + + if ( IsKeyDown( KEY_SPACE ) && m_onGround == true ) + { + m_velocity.y = m_jumpSpeed; + m_onGround = false; + } + + if ( m_onGround == true ) + { + m_sprint = IsKeyDown( KEY_LEFT_SHIFT ); + } + else + { + m_sprint = false; + } + } + + float hertz = m_sample->m_context->hertz; + float timeStep = hertz > 0.0f ? 1.0f / hertz : 0.0f; + + // throttle = { 0.0f, 0.0f, -1.0f }; + + SolveMove( timeStep, forward, right, throttle, clipVelocity ); + + b3Pos position = m_transform.p; + + // Follow the mover and latch the draw origin before drawing, so the overlays below demote + // against the same eye the view renders from. + if ( m_sample->m_camera->m_thirdPerson ) + { + m_sample->m_camera->m_pivot = position; + m_sample->m_camera->UpdateTransform(); + } + + SetDrawOrigin( m_sample->m_camera->DrawOrigin() ); + + int count = m_planeCount; + for ( int i = 0; i < count; ++i ) + { + b3Plane plane = m_planes[i].plane; + b3Pos p1 = position + ( plane.offset - m_capsule.radius ) * plane.normal; + b3Pos p2 = p1 + 0.1f * plane.normal; + DrawPoint( p1, 5.0f, MakeColor( b3_colorYellow ) ); + DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); + } + + DrawSolidCapsule( m_transform, m_capsule, MakeColor( b3_colorBlue ) ); + DrawLine( position, position + m_velocity, MakeColor( b3_colorPurple ) ); + + m_ignoreShapeIds = nullptr; + m_ignoreCount = 0; } diff --git a/samples/sample.h b/samples/sample.h index 5e8ff18..3281fd3 100644 --- a/samples/sample.h +++ b/samples/sample.h @@ -11,7 +11,6 @@ // Fed from the host event loop; read with the KEY_* aliases in gfx/keycodes.h. bool IsKeyDown( int key ); void SetKeyDown( int key, bool down ); -void ClearKeysDown(); // Key action passed to Keyboard, matching the old GLFW press/release values so // sample code reads naturally without leaking sokol_app event types. @@ -21,17 +20,6 @@ enum ACTION_PRESS = 1, }; -// Character input relative to the camera. Throttle x is forward and y is right. -struct MoverInput -{ - b3Vec3 forward; - b3Vec3 right; - b3Vec2 throttle; - bool jump; - bool sprint; - bool walk; -}; - struct SampleContext { void Save(); @@ -62,33 +50,18 @@ struct SampleContext char recordingFile[256] = "recording.b3rec"; char replayFile[256] = ""; - // Last recording saved this session, empty until a save succeeds. The default record path - // may name a stale file from an earlier run, so Play only trusts this one. - char savedRecordingFile[256] = ""; - // Keyframe ring policy the Replay viewer applies on open, persisted across sessions. int replayKeyframeBudgetMB = 512; int replayKeyframeMinInterval = 16; float hertz = 60.0f; float recycleDistance = 0.05f; - float drawDistance = 100.0f; // meters, view/cull box half extent, persisted - - // Camera the sample set up on creation. Home returns to it. Fitting the world bounds instead - // can put a scene with a large ground plate beyond the draw distance. - b3Pos homePivot = {}; - float homeYaw = 0.0f; - float homePitch = 0.0f; - float homeRadius = 0.0f; int subStepCount = 4; - int restitutionIterations = 2; int workerCount = 1; bool transparentDynamic = false; - bool transparentKinematic = false; + bool transparent = false; bool enableWarmStarting = true; bool enableContinuous = true; - bool enableRestitutionPropagation = false; - bool enableSSE2Fallback = false; bool enableSleep = true; bool pause = false; int singleStep = 0; @@ -97,16 +70,10 @@ struct SampleContext // UI visibility (Tab / View > Hide UI). When hidden only the minimal HUD shows. bool showUI = true; - // Viewport text: HUD, sample text lines and world labels. - bool showText = true; - - // Bottom metrics drawer (M), set by Ctrl+O for the fuzzy picker. + // Bottom diagnostics drawer (M), set by Ctrl+O for the fuzzy picker. bool showMetrics = false; bool openSamplePicker = false; - // Left profile panel (I) - bool showProfile = false; - // Controls help window (Help > Controls, toggled with ?). Promoted to the // context so the key handler can reach it. Seeded from newUser after Load. bool showControls = false; @@ -151,9 +118,7 @@ public: // Update and render are split to support pausing the simulation virtual void Step(); - virtual void Render() - { - } + virtual void Render() {} // Draw sample controls into the shared info panel. Return true if any widget // was drawn so the panel can add a separator. @@ -168,12 +133,6 @@ public: return true; } - // Allow a sample without a world step to hide the profile panel. - virtual bool HasProfile() const - { - return true; - } - // Width of the right info panel in em. The bottom drawer clears to the same width. A sample that // hosts heavier content there, such as the replay viewer's detail pane, can widen it. virtual float InfoPanelWidthEm() const; @@ -188,9 +147,9 @@ public: // framing works regardless of where the cursor sits. virtual b3BodyId FocusBody() const; - // Home, and the frame shortcut with nothing selected. Defaults to the camera the sample set up on - // creation. The replay viewer overrides this to fit the recording, whose world is player-owned and - // separate from the empty base world. + // Frame shortcut with nothing selected: fit the whole scene. Defaults to the live world bounds. + // The replay viewer overrides this to fit the recording, whose world is player-owned and separate + // from the empty base world. virtual void FocusHome(); // Arm recording on the live world, snapshotting it as the seed so capture can begin at any @@ -198,20 +157,10 @@ public: void StartRecording(); void FinishRecording(); - // Left profile panel, a table of the step sections readable at a glance. - bool IsProfileVisible() const; - float GetProfilePanelWidth() const; - void DrawProfile(); - - // Bottom metrics drawer (Frame Time / Counters / Renderer). + // Bottom diagnostics drawer (Profile / Counters / Renderer / Frame Time). void DrawMetrics(); - virtual b3WorldId GetMetricsWorldId() const - { - return m_worldId; - } - - // Append extra tabs to the metrics drawer's tab bar (the Replay viewer adds Timeline). + // Append extra tabs to the diagnostics drawer's tab bar (the Replay viewer adds Timeline). virtual void DrawMetricsTab() { } @@ -230,11 +179,6 @@ public: virtual void MouseMove( b3Vec2 p ); void ToggleThirdPerson(); - - // WASD, space, shift and ctrl, active only in third person so the free camera keeps its keys. - MoverInput GetMoverInput() const; - - B3_PRINTF_FORMAT( 2, 3 ) void DrawTextLine( const char* text, ... ); void ResetProfile(); @@ -263,7 +207,6 @@ public: float m_mouseForceScale; float m_launchSpeedScale; int m_stepCount; - int m_textX; int m_textLine; int m_textIncrement; int m_triangleIndex; @@ -278,18 +221,6 @@ public: int m_profileReadIndex; int m_profileWriteIndex; - // View-space distance range the shadow cascades split over, set during - // construction. Left at zero the range is guessed from the world bounds, - // which only works when the camera sits close to the content. A scene - // viewed from far off wants an explicit range: the guess spends every - // cascade on the empty space in front of the camera and the shadows stop - // partway into the scene. - // - // Authored against the sample's opening camera, so flying well away from - // it can still outrun the far end. - float m_shadowSplitNear; - float m_shadowSplitFar; - b3Vec2 m_mouseLast; b3Vec2 m_mouseDelta; bool m_didStep; @@ -323,16 +254,13 @@ int RegisterReplay( const char* category, const char* name, SampleCreateFcn* fcn // by leaving the restart flag set while the new sample constructs. void SelectSample( SampleContext* context, int selection, bool restart ); -// Frame the selection, or go home when nothing is selected -void FrameSelection( SampleContext* context ); - // Run the native "open replay" file picker and, on success, hand the chosen // file to the Replay viewer. Must be called outside the frame (the dialog spins // a blocking nested run loop), driven by SampleContext::openReplayPicker. void OpenReplayFileDialog( SampleContext* context ); -// The single host UI callback: menu bar, sample picker, info panel, profile panel, -// and the bottom metrics drawer. +// The single host UI callback: menu bar, sample picker, info panel, and the +// bottom diagnostics drawer. void DrawUI( SampleContext* context ); struct CastClosestContext @@ -350,18 +278,46 @@ struct CastClosestContext float CastClosestCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t materialId, int triangleIndex, int childIndex, void* context ); -struct MechanicalEnergy +struct MoverShapeUserData { - float Total() const - { - return linear + angular + potential; - } - - float linear; - float angular; - float potential; + float maxPush; + bool clipVelocity; }; -// Kinetic and gravitational potential energy summed over the bodies. Restitution samples -// use the total as the invariant that may only decrease. -MechanicalEnergy MeasureEnergy( b3WorldId worldId, const b3BodyId* bodyIds, int count ); +struct PlaneExtra +{ + b3Pos point; + b3ShapeId shapeId; +}; + +struct CharacterMover +{ + static constexpr int m_planeCapacity = 8; + static constexpr float m_jumpSpeed = 5.0f; + static constexpr float m_maxSpeed = 6.0f; + static constexpr float m_minSpeed = 0.01f; + static constexpr float m_stopSpeed = 1.0f; + static constexpr float m_accelerate = 30.0f; + static constexpr float m_friction = 4.0f; + static constexpr float m_gravity = 15.0f; + + void Initialize( Sample* sample, b3Pos position ); + void SolveMove( float timeStep, b3Vec3 forward, b3Vec3 right, b3Vec2 throttle, bool clipVelocity ); + void Step( b3ShapeId* ignoreShapes, int ignoreCount, bool clipVelocity ); + + Sample* m_sample; + b3WorldTransform m_transform; + b3Vec3 m_velocity; + b3Capsule m_capsule; + b3CollisionPlane m_planes[m_planeCapacity] = {}; + PlaneExtra m_planeExtras[m_planeCapacity] = {}; + int m_planeCount; + int m_totalIterations; + float m_pogoVelocity; + bool m_onGround; + bool m_sprint; + + // Transient + b3ShapeId* m_ignoreShapeIds; + int m_ignoreCount; +}; diff --git a/samples/sample_benchmark.cpp b/samples/sample_benchmark.cpp index 5482088..37cc719 100644 --- a/samples/sample_benchmark.cpp +++ b/samples/sample_benchmark.cpp @@ -12,10 +12,6 @@ #include -#ifdef BOX3D_INTERNAL_BENCHMARKS -#include "sat_benchmark.h" -#endif - inline bool operator<( b3BodyId a, b3BodyId b ) { uint64_t ua = b3StoreBodyId( a ); @@ -34,8 +30,6 @@ public: m_camera->SetView( 40.0f, -10.0f, 110.0f, { 0.0f, 40.0f, 0.0f } ); } - m_shadowSplitFar = 180.0f; - CreateLargePyramid( m_worldId ); SetGroundShape( GetGroundShapeId() ); @@ -638,13 +632,13 @@ public: } float milliseconds = b3GetMilliseconds( startTick ); - int tickCount = (int)(b3GetTicks() - startTick); + uint64_t tickCount = b3GetTicks() - startTick; float aveIterations = float( iterationCount ) / float( castCount ); float aveInner = float( innerIterationCount ) / float( castCount ); float aveCastTime = 1000.0f * milliseconds / float( castCount ); - DrawTextLine( "count = %d, hit count = %d, iterations = %d, inner = %d, ticks = %d", castCount, hitCount, iterationCount, + DrawTextLine( "count = %d, hit count = %d, iterations = %d, inner = %d, ticks = %ld", castCount, hitCount, iterationCount, innerIterationCount, tickCount ); DrawTextLine( "ave iterations = %.1f, ave inner = %.1f, ave cast us %.3f", aveIterations, aveInner, aveCastTime ); @@ -693,25 +687,20 @@ public: if ( m_gridSize == 100 ) { - m_useHeightField ? CreateTrees100HeightField( m_worldId ) : CreateTrees100( m_worldId ); + CreateTrees100( m_worldId ); } else if ( m_gridSize == 50 ) { - m_useHeightField ? CreateTrees50HeightField( m_worldId ) : CreateTrees50( m_worldId ); + CreateTrees50( m_worldId ); } else { - m_useHeightField ? CreateTrees25HeightField( m_worldId ) : CreateTrees25( m_worldId ); + CreateTrees25( m_worldId ); } } bool DrawControls() override { - if ( ImGui::Checkbox( "Height Field", &m_useHeightField ) ) - { - Generate(); - } - if ( ImGui::RadioButton( "100cm", &m_gridSize, 100 ) ) { Generate(); @@ -736,126 +725,10 @@ public: } int m_gridSize; - bool m_useHeightField = false; }; static int sampleFallingTrees = RegisterSample( "Benchmark", "Falling Trees", BenchmarkFallingTrees::Create ); -class BenchmarkMeshDrop : public Sample -{ -public: - explicit BenchmarkMeshDrop( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 30.0f, 140.0f, b3Pos_zero ); - GetGuiDraw()->forceScale = 0.1f; - } - - CreateMeshDropBenchmark( m_worldId ); - } - - ~BenchmarkMeshDrop() override - { - DestroyMeshDropBenchmark(); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkMeshDrop( context ); - } -}; - -static int sampleMeshDropBenchmark = RegisterSample( "Benchmark", "Mesh Drop", BenchmarkMeshDrop::Create ); - -class BenchmarkVillage : public Sample -{ -public: - explicit BenchmarkVillage( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 45.0f, 30.0f, 300.0f, b3Pos_zero ); - } - - b3Capacity capacity = {}; - GetVillageCapacity( &capacity ); - CreateWorld( &capacity ); - - CreateVillage( m_worldId ); - } - - ~BenchmarkVillage() override - { - DestroyVillage(); - } - - void Step() override - { - StepVillage( m_worldId, m_stepCount ); - Sample::Step(); - } - - bool DrawControls() override - { - ImGui::Checkbox( "Draw Casts", &m_drawCasts ); - ImGui::Checkbox( "Draw Spheres", &m_drawSpheres ); - return true; - } - - void Render() override - { - Sample::Render(); - - VillageCurtain curtain = GetVillageCurtain(); - - int hitCount = 0; - for ( int i = 0; i < curtain.castCount; ++i ) - { - const VillageCast& cast = curtain.casts[i]; - hitCount += cast.hit ? 1 : 0; - - if ( m_drawCasts == false ) - { - continue; - } - - b3Pos end = cast.origin + cast.fraction * curtain.translation; - DrawLine( cast.origin, end, MakeColor( cast.hit ? b3_colorYellow : b3_colorGray ) ); - - if ( cast.hit == false ) - { - continue; - } - - DrawPoint( cast.point, 4.0f, MakeColor( b3_colorGreen ) ); - DrawLine( cast.point, cast.point + 0.5f * cast.normal, MakeColor( b3_colorGreen ) ); - - if ( m_drawSpheres ) - { - b3WorldTransform transform = b3WorldTransform_identity; - transform.p = end; - DrawSphereEx( transform, curtain.radius, MakeColorAlpha( b3_colorPurple, 0.5f ), 0.0f, 0.5f, - TRANSPARENT_SHADOW_NONE ); - } - } - - DrawTextLine( "casts = %d, hits = %d", curtain.castCount, hitCount ); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkVillage( context ); - } - - bool m_drawCasts = true; - bool m_drawSpheres = true; -}; - -static int sampleVillageBenchmark = RegisterSample( "Benchmark", "Village", BenchmarkVillage::Create ); - struct ShapeUserData { int row; @@ -1161,12 +1034,13 @@ public: g_randomSeed = 42; - for ( int i = 0; i < m_capacity; ++i ) + m_count = 64; + for ( int i = 0; i < m_count; ++i ) { m_points[i] = RandomVec3( { -1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, 1.0f } ); } - m_hull = b3CreateHull( m_points, m_capacity, m_count ); + m_hull = b3CreateHull( m_points, m_count, m_count ); m_scale = { -1.0f, 1.0f, 1.0f }; m_transformedHull = b3CloneAndTransformHull( m_hull, b3Transform_identity, m_scale ); } @@ -1196,7 +1070,7 @@ public: for ( int i = 0; i < trials; ++i ) { - b3HullData* hull = b3CreateHull( m_points, m_capacity, m_count ); + b3HullData* hull = b3CreateHull( m_points, m_count, m_count ); area += hull->surfaceArea; b3DestroyHull( hull ); } @@ -1225,12 +1099,12 @@ public: return new BenchmarkHull( sampleContext ); } - static constexpr int m_capacity = 100; - static constexpr int m_count = 16; + static constexpr int m_capacity = 64; b3HullData* m_hull; b3HullData* m_transformedHull; b3Vec3 m_scale; b3Vec3 m_points[m_capacity]; + int m_count; }; static int sampleBenchmarkHull = RegisterSample( "Benchmark", "Hull", BenchmarkHull::Create ); @@ -1553,10 +1427,6 @@ public: GetGuiDraw()->drawJoints = false; } - b3Capacity capacity = {}; - GetJunkyardCapacity( &capacity ); - CreateWorld( &capacity ); - CreateJunkyard( m_worldId ); SetGroundShape( GetGroundShapeId() ); @@ -1564,7 +1434,7 @@ public: void Step() override { - if ( m_context->pause == false || m_context->singleStep > 0 ) + if ( m_context->pause == false || m_context->singleStep == 0 ) { StepJunkyard( m_worldId, m_stepCount ); } @@ -1579,252 +1449,3 @@ public: }; static int sampleJunkyard = RegisterSample( "Benchmark", "Junkyard", BenchmarkJunkyard::Create ); - -class BenchmarkConvexPile : public Sample -{ -public: - explicit BenchmarkConvexPile( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 45.0f, 20.0f, 150.0f, { 0.0f, 15.0f, 0.0f } ); - } - - // Watched from 150 m out, so the settled pile sits between 100 and 180 m - // of view depth and the guessed range stops less than halfway into it. - m_shadowSplitFar = 180.0f; - - b3Capacity capacity = {}; - GetConvexPileCapacity( &capacity ); - CreateWorld( &capacity ); - - CreateConvexPile( m_worldId ); - - SetGroundShape( GetGroundShapeId() ); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkConvexPile( context ); - } -}; - -static int sampleConvexPile = RegisterSample( "Benchmark", "Convex Pile", BenchmarkConvexPile::Create ); - -class BenchmarkSpinner : public Sample -{ -public: - explicit BenchmarkSpinner( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 0.0f, 12.0f, 45.0f, { 0.0f, 12.0f, 0.0f } ); - } - - b3Capacity capacity = {}; - GetSpinnerCapacity( &capacity ); - CreateWorld( &capacity ); - - CreateSpinner( m_worldId ); - } - - ~BenchmarkSpinner() override - { - DestroySpinner(); - } - - void Step() override - { - Sample::Step(); - - DrawTextLine( "spinner angle = %.2f", GetSpinnerAngle() ); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkSpinner( context ); - } -}; - -static int benchmarkSpinner = RegisterSample( "Benchmark", "Spinner", BenchmarkSpinner::Create ); - -class BenchmarkSleep : public Sample -{ -public: - explicit BenchmarkSleep( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( -10.0f, 25.0f, 100.0f, { 0.0f, 3.0f, 0.0f } ); - } - - b3Capacity capacity = {}; - GetSleepCapacity( &capacity ); - CreateWorld( &capacity ); - - CreateSleep( m_worldId ); - SetGroundShape( GetGroundShapeId() ); - } - - void Step() override - { - if ( m_context->pause == false || m_context->singleStep > 0 ) - { - StepSleep( m_worldId, m_stepCount ); - } - - Sample::Step(); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkSleep( context ); - } -}; - -static int benchmarkSleep = RegisterSample( "Benchmark", "Sleep", BenchmarkSleep::Create ); - -#ifdef BOX3D_INTERNAL_BENCHMARKS - -// GJK versus SAT on hull pairs held inside the speculative margin. Times are per query and smoothed over frames. -class BenchmarkSeparatingAxis : public Sample -{ -public: - explicit BenchmarkSeparatingAxis( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 0.0f, 15.0f, 4.0f, b3Pos_zero ); - } - - m_data = CreateSatBenchmark( (SatHullType)m_typeA, (SatHullType)m_typeB ); - } - - ~BenchmarkSeparatingAxis() override - { - DestroySatBenchmark( m_data ); - } - - bool HasSolverControls() const override - { - return false; - } - - bool HasProfile() const override - { - return false; - } - - bool DrawControls() override - { - const char* hullNames[] = { "Complex", "Rock", "Cylinder" }; - static_assert( IM_ARRAYSIZE( hullNames ) == satHull_count ); - - ImGui::PushItemWidth( 8.0f * ImGui::GetFontSize() ); - - bool changed = ImGui::Combo( "Hull A", &m_typeA, hullNames, IM_ARRAYSIZE( hullNames ) ); - changed = ImGui::Combo( "Hull B", &m_typeB, hullNames, IM_ARRAYSIZE( hullNames ) ) || changed; - if ( changed ) - { - DestroySatBenchmark( m_data ); - m_data = CreateSatBenchmark( (SatHullType)m_typeA, (SatHullType)m_typeB ); - m_resetAverage = true; - } - - m_resetAverage = ImGui::Checkbox( "Inscribed Sphere", &m_inscribedSphere ) || m_resetAverage; - m_resetAverage = ImGui::Checkbox( "Warm Start GJK", &m_warmStart ) || m_resetAverage; - ImGui::SliderInt( "Pair", &m_pairIndex, 0, SAT_PAIR_COUNT - 1 ); - - ImGui::PopItemWidth(); - return true; - } - - void Render() override - { - b3Transform transformB = m_data->transforms[m_pairIndex]; - b3WorldTransform worldA = b3MakeWorldTransform( b3Transform_identity ); - b3WorldTransform worldB = b3MakeWorldTransform( transformB ); - - DrawHull( worldA, m_data->hullA, MakeColor( b3_colorGreen ) ); - DrawHull( worldB, m_data->hullB, MakeColor( b3_colorCyan ) ); - - b3DistanceInput input = {}; - input.proxyA = { b3GetHullPoints( m_data->hullA ), m_data->hullA->vertexCount, 0.0f }; - input.proxyB = { b3GetHullPoints( m_data->hullB ), m_data->hullB->vertexCount, 0.0f }; - input.transform = transformB; - input.useRadii = false; - - b3SimplexCache cache = {}; - b3DistanceOutput output = b3ShapeDistance( &input, &cache, nullptr, 0 ); - - b3Pos pA = b3TransformWorldPoint( worldA, output.pointA ); - b3Pos pB = b3TransformWorldPoint( worldA, output.pointB ); - DrawPoint( pA, 8.0f, MakeColor( b3_colorRed ) ); - DrawPoint( pB, 8.0f, MakeColor( b3_colorYellow ) ); - DrawLine( pA, pB, MakeColor( b3_colorWhite ) ); - - Sample::Render(); - } - - void Step() override - { - EnableSatInscribedSphere( m_data, m_inscribedSphere ); - - int repeatCount = m_isDebug ? 1 : 10; - SatBenchmarkResult result = RunSatBenchmark( m_data, repeatCount, m_warmStart ); - - float scale = 1000.0f / result.queryCount; - float distanceTime = scale * result.distanceMs; - float satTime = scale * result.satMs; - - if ( m_resetAverage ) - { - m_distanceTime = distanceTime; - m_satTime = satTime; - m_resetAverage = false; - } - else - { - float alpha = 0.05f; - m_distanceTime = b3LerpFloat( m_distanceTime, distanceTime, alpha ); - m_satTime = b3LerpFloat( m_satTime, satTime, alpha ); - } - - DrawTextLine( "pairs = %d, queries per frame = %d", SAT_PAIR_COUNT, result.queryCount ); - DrawTextLine( "GJK (us) = %.3f, iterations = %.2f", m_distanceTime, result.averageIterations ); - DrawTextLine( "SAT (us) = %.3f", m_satTime ); - DrawTextLine( "SAT / GJK = %.2f", m_satTime / m_distanceTime ); - DrawTextLine( "target dist = %.4f, avg dist = %.4f, avg sep = %.4f", m_data->targetDistance, - result.averageDistance, result.averageSeparation ); - - if ( result.earlyReturnCount > 0 ) - { - DrawTextLine( "SAT early returns = %d", result.earlyReturnCount ); - } - - Sample::Step(); - } - - static Sample* Create( SampleContext* context ) - { - return new BenchmarkSeparatingAxis( context ); - } - - SatBenchmarkData* m_data; - int m_typeA = satHull_complex; - int m_typeB = satHull_complex; - int m_pairIndex = 0; - bool m_inscribedSphere = true; - bool m_warmStart = false; - bool m_resetAverage = true; - float m_distanceTime = 0.0f; - float m_satTime = 0.0f; -}; - -static int sampleSeparatingAxis = RegisterSample( "Benchmark", "SAT vs GJK", BenchmarkSeparatingAxis::Create ); - -#endif diff --git a/samples/sample_bodies.cpp b/samples/sample_bodies.cpp index cc58786..115fa49 100644 --- a/samples/sample_bodies.cpp +++ b/samples/sample_bodies.cpp @@ -334,356 +334,27 @@ public: bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 2.0f, 0.0f }; bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, -0.5f * B3_PI ); + bodyDef.angularVelocity = { 0.01f, 0.01f, 10.0f }; bodyDef.gravityScale = 0.0f; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.updateBodyMass = false; b3HullData* cylinder = b3CreateCylinder( 0.6f, 0.15f, 0.0f, 32 ); b3BoxHull box = b3MakeBoxHull( 1.0f, 0.05f, 0.1f ); - b3CreateHullShape( m_bodyId, &shapeDef, cylinder ); - b3CreateHullShape( m_bodyId, &shapeDef, &box.base ); - b3Body_ApplyMassFromShapes( m_bodyId ); - - // Set the angular velocity after creating the shapes and the local center of mass is fixed. - b3Body_SetAngularVelocity( m_bodyId, { 0.01f, 0.01f, 10.0f } ); + b3CreateHullShape( bodyId, &shapeDef, cylinder ); + b3CreateHullShape( bodyId, &shapeDef, &box.base ); b3DestroyHull( cylinder ); } - void Step() override - { - Sample::Step(); - - b3Pos c = b3Body_GetWorldCenter( m_bodyId ); - DrawTextLine( "center %.3g %.3g %.3g", c.x, c.y, c.z ); - } - static Sample* Create( SampleContext* sampleContext ) { return new GyroscopicTorque( sampleContext ); } - - b3BodyId m_bodyId; }; static int sampleGyroscopicTorque = RegisterSample( "Bodies", "Gyroscopic Torque", GyroscopicTorque::Create ); -// Spinning tops. Ported from PEEL. -// Each top is tilted and spun about its symmetry axis. Gravity torque about the tip is what makes -// them precess instead of toppling. The first top carries a diagnostic that compares the measured -// precession rate against the classical heavy top solution. -class GyroscopicPrecession : public Sample -{ -public: - explicit GyroscopicPrecession( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 40.0f, 30.0f, 75.0f, { 0.0f, 2.0f, 0.0f } ); - } - - AddGroundBox( 40.0f ); - - // Top shape: a wide n-gon rim up top and a point at the origin, so it balances on its tip. - constexpr int numSegs = 7; - constexpr float r = 2.0f; - constexpr float h = 2.0f; - b3Vec3 hullPoints[numSegs + 1]; - const float dphi = 2.0f * B3_PI / numSegs; - for ( int i = 0; i < numSegs; ++i ) - { - hullPoints[i] = { r * cosf( i * dphi ), h, r * sinf( i * dphi ) }; - } - hullPoints[numSegs] = b3Vec3_zero; - b3HullData* hull = b3CreateHull( hullPoints, numSegs + 1, numSegs + 1 ); - - // Capsule for testing alternate shapes. Keep this. - //b3Capsule capsule = {{0.0f, -0.6f, 0.0f}, {0.0f, 0.6f, 0.0f }, 0.4f}; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = 0.1f; - - // Tilt the top, then spin it about its own symmetry axis. Gravity does the rest. - b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 15.0f * B3_PI / 180.0f ); - b3Vec3 angularVelocity = b3RotateVector( rotation, { 0.0f, 75.0f, 0.0f } ); - - constexpr int count = 8; - constexpr float separation = 6.0f; - for ( int x = 0; x < count; ++x ) - { - for ( int z = 0; z < count; ++z ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { ( x - count / 2 ) * separation, h, ( z - count / 2 ) * separation }; - bodyDef.rotation = rotation; - - // The spin rate exceeds the default cap, so bypass it as the test intends. - bodyDef.allowFastRotation = true; - - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, hull ); - - //b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - - b3Body_SetAngularVelocity( bodyId, angularVelocity ); - - if ( x == 0 && z == 0 ) - { - m_topId = bodyId; - } - } - } - - b3DestroyHull( hull ); - - // Mass properties of the measured top. The tip sits at the body origin, so the pivot distance is - // just the height of the center of mass, and the symmetry axis is the local up axis. - b3MassData massData = b3Body_GetMassData( m_topId ); - m_mass = massData.mass; - m_pivotDistance = massData.center.y; - m_spinInertia = massData.inertia.cy.y; - - // Transverse inertia belongs about the pivot, not the center of mass - float transverse = 0.5f * ( massData.inertia.cx.x + massData.inertia.cz.z ); - m_transverseInertia = transverse + m_mass * m_pivotDistance * m_pivotDistance; - - m_gravity = b3Length( b3World_GetGravity( m_worldId ) ); - - m_azimuth = 0.0f; - m_actualAngle = 0.0f; - m_expectedAngle = 0.0f; - m_elapsed = 0.0f; - m_groundTime = 0.0f; - m_rate = 0.0f; - m_measuring = false; - } - - // Steady precession rate of a heavy symmetric top about the vertical. The slow root of - // I1 * W^2 * cos(tilt) - I3 * spin * W + M * g * d = 0. Goldstein 5.7. - // Collapses to torque over spin momentum for a fast top. - float ExpectedRate( float spin, float cosTilt ) const - { - float momentum = m_spinInertia * spin; - float torque = m_mass * m_gravity * m_pivotDistance; - if ( momentum <= FLT_EPSILON ) - { - return 0.0f; - } - - float a = m_transverseInertia * cosTilt; - float discriminant = momentum * momentum - 4.0f * a * torque; - if ( a <= FLT_EPSILON || discriminant < 0.0f ) - { - // Axis at or past horizontal, or spinning too slowly to precess steadily - return torque / momentum; - } - - return ( momentum - sqrtf( discriminant ) ) / ( 2.0f * a ); - } - - void Step() override - { - Sample::Step(); - - bool isAwake = b3Body_IsAwake( m_topId ); - if ( isAwake == false ) - { - DrawTextLine( "top is sleeping" ); - return; - } - - b3Pos tip = b3Body_GetPosition( m_topId ); - b3Quat quat = b3Body_GetRotation( m_topId ); - b3Vec3 axis = b3RotateVector( quat, b3Vec3_axisY ); - b3Vec3 omega = b3Body_GetAngularVelocity( m_topId ); - float spin = b3Dot( omega, axis ); - float cosTilt = b3ClampFloat( axis.y, -1.0f, 1.0f ); - float expected = ExpectedRate( spin, cosTilt ); - - if ( m_didStep ) - { - float timeStep = 1.0f / m_context->hertz; - - // Gravity exerts no torque about the center of mass while the top is airborne, so the pivot - // solution only applies once the tip lands. Give the landing impulse time to wash out too, - // otherwise it biases the average for the rest of the run. - if ( tip.y < 0.05f ) - { - m_groundTime += timeStep; - } - - if ( m_measuring == false ) - { - if ( m_groundTime > 0.5f ) - { - m_measuring = true; - m_azimuth = b3Atan2( -axis.z, axis.x ); - } - } - else - { - // Right handed angle of the symmetry axis about the world up axis - float azimuth = b3Atan2( -axis.z, axis.x ); - float delta = b3UnwindAngle( azimuth - m_azimuth ); - m_azimuth = azimuth; - - m_actualAngle += delta; - m_expectedAngle += expected * timeStep; - m_elapsed += timeStep; - - // Nutation swings the instantaneous rate between zero and twice the mean, so filter it - // with a one second time constant. - float alpha = timeStep / ( timeStep + 1.0f ); - m_rate += alpha * ( delta / timeStep - m_rate ); - } - } - - DrawLine( tip, b3OffsetPos( tip, 5.0f * axis ), MakeColor( b3_colorYellow ) ); - - DrawTextLine( "spin %.1f rad/s, tilt %.1f deg", spin, ( 180.0f / B3_PI ) * acosf( cosTilt ) ); - DrawTextLine( "precession: expected %.4f rad/s, actual %.4f rad/s", expected, m_rate ); - - if ( m_elapsed > 0.0f ) - { - // Average both sides over the same window. The spin decays, so the expected rate drifts with it. - float expectedAverage = m_expectedAngle / m_elapsed; - float actualAverage = m_actualAngle / m_elapsed; - float error = expectedAverage != 0.0f ? 100.0f * ( actualAverage - expectedAverage ) / expectedAverage : 0.0f; - DrawTextLine( "%.1f s average: expected %.4f, actual %.4f, error %+.1f%%", m_elapsed, expectedAverage, actualAverage, - error ); - } - else - { - DrawTextLine( "waiting for the tip to land" ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new GyroscopicPrecession( context ); - } - - b3BodyId m_topId; - float m_mass; - float m_gravity; - float m_pivotDistance; - float m_spinInertia; - float m_transverseInertia; - float m_azimuth; - float m_actualAngle; - float m_expectedAngle; - float m_elapsed; - float m_groundTime; - float m_rate; - bool m_measuring; -}; - -static int sampleGyroscopicPrecession = RegisterSample( "Bodies", "Gyroscopic Precession", GyroscopicPrecession::Create ); - -// This show that gyroscopic torque is necessary for plausible behavior on long skinny objects. -class SpinningCapsule : public Sample -{ -public: - explicit SpinningCapsule( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 30.0f, 25.0f, 15.0f, { 0.0f, 1.0f, 0.0f } ); - } - - m_length = 4.0f; - m_tolerance = b3World_GetIsotropicInertiaTolerance( m_worldId ); - CreateScene(); - } - - void CreateScene() - { - // The tolerance only applies to bodies created after it is set - b3Capacity capacity = {}; - CreateWorld( &capacity ); - b3World_SetIsotropicInertiaTolerance( m_worldId, m_tolerance ); - - AddGroundBox( 20.0f ); - - float radius = 0.2f; - float halfLength = 0.5f * m_length; - b3Capsule capsule = { { 0.0f, -halfLength, 0.0f }, { 0.0f, halfLength, 0.0f }, radius }; - - // Stand on the lower cap, tilted about it - b3Quat rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 15.0f * B3_PI / 180.0f ); - b3Vec3 axis = b3RotateVector( rotation, b3Vec3_axisY ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = b3OffsetPos( { 0.0f, radius, 0.0f }, halfLength * axis ); - bodyDef.rotation = rotation; - bodyDef.angularVelocity = 20.0f * axis; - m_capsuleId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateCapsuleShape( m_capsuleId, &shapeDef, &capsule ); - } - - bool DrawControls() override - { - bool changed = false; - - ImGui::PushItemWidth( 10.0f * ImGui::GetFontSize() ); - changed |= ImGui::SliderFloat( "Length", &m_length, 0.0f, 8.0f, "%.1f" ); - changed |= ImGui::SliderFloat( "Tolerance", &m_tolerance, 0.0f, 1.0f, "%.3f" ); - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Reset" ) || changed ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - // Same measure the world uses to skip the gyroscopic solve: the deviatoric part of the inertia - // relative to its mean. - b3Matrix3 inertia = b3Body_GetLocalRotationalInertia( m_capsuleId ); - float mean = ( inertia.cx.x + inertia.cy.y + inertia.cz.z ) / 3.0f; - float dx = inertia.cx.x - mean; - float dy = inertia.cy.y - mean; - float dz = inertia.cz.z - mean; - float offDiagonal = inertia.cy.x * inertia.cy.x + inertia.cz.x * inertia.cz.x + inertia.cz.y * inertia.cz.y; - float deviation = dx * dx + dy * dy + dz * dz + 2.0f * offDiagonal; - float anisotropy = mean > 0.0f ? sqrtf( 2.0f * deviation / 3.0f ) / mean : 0.0f; - bool isGyroscopic = anisotropy > m_tolerance; - - b3Pos center = b3Body_GetWorldCenter( m_capsuleId ); - b3Vec3 axis = b3RotateVector( b3Body_GetRotation( m_capsuleId ), b3Vec3_axisY ); - b3Vec3 omega = b3Body_GetAngularVelocity( m_capsuleId ); - float tilt = acosf( b3ClampFloat( b3AbsFloat( axis.y ), 0.0f, 1.0f ) ); - - DrawLine( center, b3OffsetPos( center, 0.2f * omega ), MakeColor( b3_colorYellow ) ); - - DrawTextLine( "anisotropy %.2f, gyroscopic torque %s", anisotropy, isGyroscopic ? "on" : "off" ); - DrawTextLine( "tilt %.0f deg, spin %.1f rad/s", ( 180.0f / B3_PI ) * tilt, b3Dot( omega, axis ) ); - } - - static Sample* Create( SampleContext* context ) - { - return new SpinningCapsule( context ); - } - - b3BodyId m_capsuleId; - float m_length; - float m_tolerance; -}; - -static int sampleSpinningCapsule = RegisterSample( "Bodies", "Spinning Capsule", SpinningCapsule::Create ); - class Weeble : public Sample { public: @@ -960,7 +631,7 @@ public: { PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); b3Pos origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); - m_transform.p = m_baseTranslation + b3SubPos( origin, m_origin ); + m_transform.p = m_baseTranslation + b3SubPos(origin, m_origin); } } @@ -1287,150 +958,3 @@ public: }; static int sampleFixedRotation = RegisterSample( "Bodies", "Fixed Rotation", FixedRotation::Create ); - -// A spinning class ring flips its heavy gem from bottom to top, like this video: -// https://www.youtube.com/watch?v=_up0BiLCliA -// This is a fiddley test and requires careful tuning. -class ClassRing : public Sample -{ -public: - explicit ClassRing( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 40.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); - } - - AddGroundBox( 100.0f ); - - constexpr int n = 24; - constexpr float r = 1.0f; - constexpr float tubeRadius = 0.1f * r; - constexpr float axisRadius = r - tubeRadius; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, r, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 13.0f * B3_PI / 180.0f ); - bodyDef.allowFastRotation = true; - bodyDef.enableContactRecycling = false; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - - // Band built from a loop of capsules. - b3Vec3 vertices[n]; - float deltaAngle = 2.0f * B3_PI / n; - b3CosSin cs = b3ComputeCosSin( deltaAngle ); - float x = axisRadius, y = 0.0f; - for ( int i = 0; i < n; ++i ) - { - vertices[i] = { x, y, 0.0f }; - float x2 = cs.cosine * x - cs.sine * y; - float y2 = cs.sine * x + cs.cosine * y; - x = x2; - y = y2; - } - - for ( int i = 0; i < n; ++i ) - { - b3Capsule capsule = { vertices[i], vertices[( i + 1 ) % n], tubeRadius }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - - // Heavy gem provides the mass asymmetry that drives the inversion - shapeDef.density = 2.0f; - b3Sphere sphere = { .center = { 0.0f, -0.65f * r, 0.0f }, .radius = 0.3f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - b3Vec3 angularVelocity = b3RotateVector( bodyDef.rotation, { 0.0f, 100.0f, 0.0f } ); - b3Body_SetAngularVelocity( bodyId, angularVelocity ); - - m_ringId = bodyId; - } - - void Step() override - { - // This needs a high simulation rate so that contact points keep up with the high speed rotation. - float hertz = m_context->hertz; - int subStepCount = m_context->subStepCount; - - // 960Hz simulation - int multiplier = 16; - m_context->hertz = multiplier * 60.0f; - m_context->subStepCount = 8; - - // Multiple hidden steps to keep the render real-time. - for ( int i = 0; i < multiplier - 1; ++i ) - { - b3World_Step( m_worldId, 1.0f / m_context->hertz, m_context->subStepCount ); - } - - Sample::Step(); - - m_context->hertz = hertz; - m_context->subStepCount = subStepCount; - } - - static Sample* Create( SampleContext* context ) - { - return new ClassRing( context ); - } - - b3BodyId m_ringId; -}; - -static int sampleClassRing = RegisterSample( "Bodies", "Class Ring", ClassRing::Create ); - -/* -mandude — 9:34 AM -I've run into a minor, and admittedly pretty niche, issue with kinematic bodies. Because box3d will skip mass computations on -kinematic bodies, the center of mass is never set. This means if the origin of a shape attached to the body isn't in the center of -the shape, and you add an angular velocity, the shape will rotate about whatever the shape's origin is. For a simple example, if -you have a cube as a mesh, with opposing corners at (0, 0, 0) and (1, 1, 1), rotation will happen about the corner of the cube. -It's possible to work around this by calling setMassData with zero mass, a custom center of mass, and an identity matrix for the -inertia tensor. That function tries to preserve momentum, so it can have unexpected effects on the velocity if the body is already -moving, so perhaps it would be useful to have a more direct way to specify a custom offset for the origin of a kinematic body? - */ -class OffsetKinematic : public Sample -{ -public: - explicit OffsetKinematic( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 0.0f, 30.0f, 10.0f, { 0.0f, 1.5f, 0.0f } ); - } - - AddGroundBox( 20.0f ); - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "kinematic"; - bodyDef.type = b3_kinematicBody; - bodyDef.position.y = 3.0; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3Vec3 offset = { 0.5f, 0.5f, 1.0f }; - b3BoxHull box = b3MakeTransformedBoxHull( 0.5f, 0.5f, 1.0f, { .p = offset, .q = b3Quat_identity} ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3MassData massData = b3Body_GetMassData( bodyId ); - massData.center = offset; - b3Body_SetMassData( bodyId, massData ); - - b3Vec3 angularVelocity = {1.0f, -1.0f, 2.0f}; - b3Body_SetAngularVelocity( bodyId, angularVelocity ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new OffsetKinematic( context ); - } -}; - -static int sampleOffsetKinematic = RegisterSample( "Bodies", "Offset Kinematic", OffsetKinematic::Create ); diff --git a/samples/sample_character.cpp b/samples/sample_character.cpp index 3790835..0aa5477 100644 --- a/samples/sample_character.cpp +++ b/samples/sample_character.cpp @@ -1,10 +1,6 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "dynamic_mover.h" -#include "geometric_mover.h" -#include "gfx/debug_adapter.h" -#include "gfx/debug_shapes.h" #include "gfx/draw.h" #include "gfx/keycodes.h" #include "mesh_loader.h" @@ -14,8 +10,6 @@ #include -#include - class CapsulePlane : public Sample { public: @@ -62,12 +56,9 @@ public: Sample::Render(); DrawGroundGrid( 10 ); - DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisX ), - MakeColor( b3_colorRed ) ); - DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisY ), - MakeColor( b3_colorGreen ) ); - DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisZ ), - MakeColor( b3_colorBlue ) ); + DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisX ), MakeColor( b3_colorRed ) ); + DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisY ), MakeColor( b3_colorGreen ) ); + DrawLine( b3Pos_zero, b3OffsetPos( b3Pos_zero, 2.0f * b3Vec3_axisZ ), MakeColor( b3_colorBlue ) ); } bool DrawControls() override @@ -80,8 +71,7 @@ public: return true; } - static bool PlaneResultFcn( b3ShapeId shape, const b3PlaneResult* results, int planeCount, - void* context ) + static bool PlaneResultFcn( b3ShapeId shape, const b3PlaneResult* results, int planeCount, void* context ) { CapsulePlane* self = static_cast( context ); for ( int i = 0; i < planeCount && self->m_planeCount < 3; ++i ) @@ -221,8 +211,7 @@ public: DrawGroundGrid( 12 ); } - static bool PlaneResultFcn( b3ShapeId /*shape*/, const b3PlaneResult* results, int planeCount, - void* context ) + static bool PlaneResultFcn( b3ShapeId /*shape*/, const b3PlaneResult* results, int planeCount, void* context ) { MoverOverlap* self = static_cast( context ); for ( int i = 0; i < planeCount && self->m_planeCount < m_planeCapacity; ++i ) @@ -322,19 +311,10 @@ public: static int sampleMoverOverlap = RegisterSample( "Character", "MoverOverlap", MoverOverlap::Create ); -// What the mover was last struck with. Stays on screen until the next hit. -struct MoverImpact -{ - b3Pos point; - b3Vec3 normal; - float speed; - bool valid; -}; - -class GeometricMoverSample : public Sample +class BasicMover : public Sample { public: - explicit GeometricMoverSample( SampleContext* context ) + explicit BasicMover( SampleContext* context ) : Sample( context ) { b3Pos moverPosition = { 7.5f, 0.75f, 9.0f }; @@ -344,29 +324,26 @@ public: m_camera->SetView( 120.0f, 30.0f, 5.0f, moverPosition ); } - GeometricMoverDef moverDef; - moverDef.position = moverPosition; - m_mover.Create( m_worldId, &moverDef ); - m_mover.m_ignoreShapeIds = &m_ignoreShapeId; - m_mover.m_ignoreCount = 1; + m_mover.Initialize( this, moverPosition ); { - m_levelMesh = - CreateMeshData( "data/meshes/test_map01.obj", 1.0f, false, false, true, true ); + m_levelMesh = CreateMeshData( "data/meshes/test_map01.obj", 1.0f, false, false, true, true ); b3BodyDef bodyDef = b3DefaultBodyDef(); b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3SurfaceMaterial materials[3]; + materials[0] = { 0.6f, 0.0f, 0 }; + materials[1] = { 0.6f, 1.0f, 1 }; + materials[2] = { 0.1f, 0.0f, 2 }; + shapeDef.materials = materials; + shapeDef.materialCount = 3; - if ( m_levelMesh != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_levelMesh, b3Vec3_one ); - } + b3CreateMeshShape( body, &shapeDef, m_levelMesh, b3Vec3_one ); - // b3Transform transform = { { 0.0f, 1.0f, 14.0f }, b3MakeQuatFromAxisAngle( - // b3Vec3_axisY, 0.75f * B3_PI ) }; b3BoxHull box = - // b3MakeTransformedBoxHull( 5.0f, 1.0f, 0.5f, transform ); b3CreateHullShape( body, - // &shapeDef, &box.base ); + // b3Transform transform = { { 0.0f, 1.0f, 14.0f }, b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.75f * B3_PI ) }; + // b3BoxHull box = b3MakeTransformedBoxHull( 5.0f, 1.0f, 0.5f, transform ); + // b3CreateHullShape( body, &shapeDef, &box.base ); { b3Transform transform = { { 4.0f, 1.0f, 14.0f }, b3Quat_identity }; @@ -379,8 +356,7 @@ public: b3CreateHullShape( body, &shapeDef, &box.base ); } { - b3Transform transform = { { 5.8f, 1.0f, 13.7f }, - b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.1f * B3_PI ) }; + b3Transform transform = { { 5.8f, 1.0f, 13.7f }, b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.1f * B3_PI ) }; b3BoxHull box = b3MakeTransformedBoxHull( 1.0f, 1.0f, 1.0f, transform ); b3CreateHullShape( body, &shapeDef, &box.base ); } @@ -394,10 +370,7 @@ public: b3ShapeDef shapeDef = b3DefaultShapeDef(); b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); - if ( m_stairs != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_stairs, { 0.75f, 0.75f, -1.5f } ); - } + b3CreateMeshShape( body, &shapeDef, m_stairs, { 0.75f, 0.75f, -1.5f } ); } { @@ -419,20 +392,14 @@ public: m_heightField = b3CreateWave( 50.0f, 50.0f, b3Vec3_one, 0.02f, 0.04f, true ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHeightFieldShape( body, &shapeDef, m_heightField ); - } + b3SurfaceMaterial materials[3]; + materials[0] = { 0.6f, 0.0f, 0 }; + materials[1] = { 0.6f, 1.0f, 1 }; + materials[2] = { 0.1f, 0.0f, 2 }; + shapeDef.materials = materials; + shapeDef.materialCount = 3; - // The tree is longer than the height field is wide, so topple it along the diagonal. - { - b3Vec3 axis = { 1.0f, 0.0f, -1.0f }; - m_treeSpin = 0.5f * b3Normalize( axis ); - m_treeSpawn = { 22.0f, 1.5f, 2.0f }; - m_treeTimer = 0.0f; - m_treeShapeUserData.maxPush = 10.0f; - m_treeShapeUserData.clipVelocity = true; - m_treeShapeUserData.canMoverPush = false; - m_treeImpact = {}; - CreateFallingTree(); + b3CreateHeightFieldShape( body, &shapeDef, m_heightField ); } { @@ -442,7 +409,6 @@ public: b3ShapeDef shapeDef = b3DefaultShapeDef(); m_enemyShape.maxPush = 1.0f; m_enemyShape.clipVelocity = true; - m_enemyShape.canMoverPush = false; b3Capsule capsule = { { 0.0f, -0.5f, 0.0f }, @@ -464,7 +430,6 @@ public: b3ShapeDef shapeDef = b3DefaultShapeDef(); m_friendlyShape.maxPush = 0.01f; m_friendlyShape.clipVelocity = false; - m_friendlyShape.canMoverPush = false; b3Capsule capsule = { { 0.0f, -0.5f, 0.0f }, @@ -490,29 +455,6 @@ public: b3CreateSphereShape( body, &shapeDef, &sphere ); } - // Falls through the mover start position on a loop to feed the mover time of impact. - { - m_fallingExtent = { 1.0f, 0.1, 1.0f }; - m_fallingSpawn = { 10.5f, 30.0f, 0.0f }; - m_fallingSpin = { 0.0f, 0.0f, 0.0f }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = m_fallingSpawn; - bodyDef.angularVelocity = m_fallingSpin; - m_fallingBoxId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorGold; - b3BoxHull box = - b3MakeBoxHull( m_fallingExtent.x, m_fallingExtent.y, m_fallingExtent.z ); - b3CreateHullShape( m_fallingBoxId, &shapeDef, &box.base ); - - m_respawnTimer = 0.0f; - m_impactTransform = { b3Pos_zero, b3Quat_identity }; - m_boxImpact = {}; - } - { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 7.0f, 2.0f, -3.0f }; @@ -575,6 +517,7 @@ public: //} m_camera->m_thirdPerson = false; + m_clipVelocity = true; // sapp_lock_mouse( true ); // m_haveMouseLast = false; @@ -582,13 +525,13 @@ public: // m_mouseDelta = { 0.0f, 0.0f }; } - ~GeometricMoverSample() override + ~BasicMover() override { m_camera->m_thirdPerson = false; sapp_lock_mouse( false ); - DestroyMeshData( m_levelMesh ); - DestroyMeshData( m_stairs ); - DestroyMeshData( m_torus ); + b3DestroyMesh( m_levelMesh ); + b3DestroyMesh( m_stairs ); + b3DestroyMesh( m_torus ); b3DestroyHeightField( m_heightField ); } @@ -606,7 +549,7 @@ public: ToggleThirdPerson(); } - ImGui::Checkbox( "Clip Velocity", &m_mover.m_clipVelocity ); + ImGui::Checkbox( "Clip Velocity", &m_clipVelocity ); return true; } @@ -619,1261 +562,32 @@ public: } } - void CreateFallingTree() - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = m_treeSpawn; - bodyDef.sleepThreshold = 0.2f; - m_treeId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.9f; - shapeDef.baseMaterial.rollingResistance = 0.05f; - shapeDef.updateBodyMass = false; - shapeDef.userData = &m_treeShapeUserData; - - float y = 1.0f; - float r = 0.75f; - float l = 1.5f; - for ( int i = 0; i < 22; ++i ) - { - b3HullData* hull = b3CreateCylinder( l + 2.0f * r, r, y - r, 6 ); - b3CreateHullShape( m_treeId, &shapeDef, hull ); - b3DestroyHull( hull ); - - y += l + 2.0f * r; - r = 0.95f * r; - } - - b3Body_ApplyMassFromShapes( m_treeId ); - - b3Pos center = b3Body_GetWorldCenter( m_treeId ); - b3Body_SetAngularVelocity( m_treeId, m_treeSpin ); - b3Body_SetLinearVelocity( m_treeId, - b3Cross( m_treeSpin, b3SubPos( center, m_treeSpawn ) ) ); - } - - // Spin about the base so the trunk sweeps down through anything standing in the fall line. - void ResetFallingTree() - { - b3DestroyBody( m_treeId ); - CreateFallingTree(); - } - - // The normal points from the body to the mover, so approach gives a positive speed. - MoverImpact MakeImpact( b3BodyId bodyId, const b3BodyTOIResult* toi ) - { - b3Vec3 pointVelocity = b3Body_GetWorldPointVelocity( bodyId, toi->point ); - float speed = b3Dot( toi->normal, b3Sub( pointVelocity, m_mover.m_velocity ) ); - - return { toi->point, toi->normal, speed, true }; - } - - void DrawImpact( const MoverImpact* impact, b3HexColor hexColor ) - { - if ( impact->valid == false ) - { - return; - } - - Vec4 color = MakeColor( hexColor ); - b3Pos tip = impact->point + 0.5f * impact->normal; - - DrawPoint( impact->point, 6.0f, color ); - DrawArrow( impact->point, tip, color ); - DrawString3D( tip, color, " %.1f m/s", impact->speed ); - } - - // True once the body has held still for a second. - bool SettledForOneSecond( b3BodyId bodyId, float* timer ) - { - if ( b3Body_IsAwake( bodyId ) ) - { - *timer = 0.0f; - return false; - } - - *timer += m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - if ( *timer < 1.0f ) - { - return false; - } - - *timer = 0.0f; - return true; - } - - // Same sweep as the box, but the tree reports what the character was struck with. - void UpdateFallingTree( b3Pos moverStart, b3WorldTransform treeStart ) - { - b3WorldTransform treeEnd = b3Body_GetTransform( m_treeId ); - b3Vec3 moverTranslation = b3SubPos( m_mover.m_position, moverStart ); - - b3BodyTOIResult toi = - b3Body_TimeOfImpactMover( m_treeId, moverStart, &m_mover.m_capsule, moverTranslation, - b3DefaultQueryFilter(), treeStart, treeEnd ); - - if ( toi.fraction > 0.0f ) - { - m_treeImpact = MakeImpact( m_treeId, &toi ); - } - - if ( SettledForOneSecond( m_treeId, &m_treeTimer ) ) - { - ResetFallingTree(); - } - } - - // Sweep the mover capsule against the box motion from this step and keep the box pose at first - // touch. Both sweeps cover the same interval, so the mover translation comes from this step - // too. - void UpdateFallingBox( b3Pos moverStart, b3WorldTransform boxStart ) - { - b3WorldTransform boxEnd = b3Body_GetTransform( m_fallingBoxId ); - b3Vec3 moverTranslation = b3SubPos( m_mover.m_position, moverStart ); - - b3BodyTOIResult toi = - b3Body_TimeOfImpactMover( m_fallingBoxId, moverStart, &m_mover.m_capsule, - moverTranslation, b3DefaultQueryFilter(), boxStart, boxEnd ); - - // A zero fraction means the box was already resting against the mover, so keep the pose - // from the step that first reached it. - if ( toi.fraction > 0.0f ) - { - m_impactTransform.p = boxStart.p + toi.fraction * b3SubPos( boxEnd.p, boxStart.p ); - m_impactTransform.q = b3NLerp( boxStart.q, boxEnd.q, toi.fraction ); - m_boxImpact = MakeImpact( m_fallingBoxId, &toi ); - } - - if ( SettledForOneSecond( m_fallingBoxId, &m_respawnTimer ) ) - { - RespawnFallingBox(); - } - } - - void RespawnFallingBox() - { - b3Body_SetTransform( m_fallingBoxId, m_fallingSpawn, b3Quat_identity ); - b3Body_SetLinearVelocity( m_fallingBoxId, b3Vec3_zero ); - b3Body_SetAngularVelocity( m_fallingBoxId, m_fallingSpin ); - b3Body_SetAwake( m_fallingBoxId, true ); - } - void Step() override { - b3Pos moverStart = m_mover.m_position; - b3WorldTransform boxStart = b3Body_GetTransform( m_fallingBoxId ); - b3WorldTransform treeStart = b3Body_GetTransform( m_treeId ); - - MoverInput input = GetMoverInput(); - if ( input.jump ) - { - m_mover.Jump(); - } - - float speedScale = 1.0f; - if ( input.walk ) - { - speedScale = 0.25f; - } - else if ( m_mover.m_onGround && input.sprint ) - { - speedScale = 1.5f; - } - float timeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - m_mover.Update( timeStep, input.forward, input.right, input.throttle, speedScale ); - - if ( m_camera->m_thirdPerson ) - { - m_camera->m_pivot = m_mover.m_position; - m_camera->UpdateTransform(); - } - - SetDrawOrigin( m_camera->DrawOrigin() ); - m_mover.Draw(); - + m_mover.Step( &m_ignoreShapeId, 1, m_clipVelocity ); DrawTextLine( "third person (T) = %d", m_camera->m_thirdPerson ); DrawTextLine( "deltaX = %g, deltaY = %g", m_mouseDelta.x, m_mouseDelta.y ); Sample::Step(); - - if ( m_didStep ) - { - UpdateFallingBox( moverStart, boxStart ); - UpdateFallingTree( moverStart, treeStart ); - } - - if ( m_boxImpact.valid ) - { - DrawCube( m_impactTransform, 2.0f * m_fallingExtent, - MakeColorAlpha( b3_colorYellow, 0.4f ) ); - } - - DrawImpact( &m_boxImpact, b3_colorYellow ); - DrawImpact( &m_treeImpact, b3_colorCyan ); } static Sample* Create( SampleContext* context ) { - return new GeometricMoverSample( context ); + return new BasicMover( context ); } - GeometricMover m_mover; + CharacterMover m_mover; MoverShapeUserData m_enemyShape; MoverShapeUserData m_friendlyShape; - MoverShapeUserData m_treeShapeUserData; b3MeshData* m_levelMesh; b3MeshData* m_stairs; b3MeshData* m_torus; b3HeightFieldData* m_heightField; b3ShapeId m_ignoreShapeId; - b3BodyId m_fallingBoxId; - b3BodyId m_treeId; - b3WorldTransform m_impactTransform; - MoverImpact m_boxImpact; - MoverImpact m_treeImpact; - b3Pos m_treeSpawn; - b3Vec3 m_treeSpin; - float m_treeTimer; - b3Pos m_fallingSpawn; - b3Vec3 m_fallingExtent; - b3Vec3 m_fallingSpin; - float m_respawnTimer; + bool m_clipVelocity; }; -static int sampleMover = - RegisterSample( "Character", "Geometric Mover", GeometricMoverSample::Create ); - -class DynamicMoverSample : public Sample -{ -public: - explicit DynamicMoverSample( SampleContext* context ) - : Sample( context ) - { - b3Pos startPosition = { 0.0f, 1.5f, 0.0f }; - - if ( m_context->restart == false ) - { - m_camera->SetView( 180.0f, 20.0f, 6.0f, startPosition ); - } - - b3BodyId groundId = AddGroundBox( 80.0f ); - - { - DynamicMoverDef def; - def.position = startPosition; - def.filter = { MoverBit, AllBits & ~DebrisBit, 0 }; - def.platformMaterialId = m_platformMaterial; - def.enableSensorEvents = true; - m_mover.Create( m_worldId, &def ); - } - - // Stairs up to the bridge - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId stairsId = b3CreateBody( m_worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorOliveDrab; - - for ( int i = 0; i < 10; ++i ) - { - float halfHeight = 0.1f * ( i + 1 ); - b3Transform transform = { { -6.0f, halfHeight, 3.3f + 0.6f * i }, b3Quat_identity }; - b3BoxHull box = b3MakeTransformedBoxHull( 1.5f, halfHeight, 0.3f, transform ); - b3CreateHullShape( stairsId, &shapeDef, &box.base ); - } - } - - // Platforms next to the bridge - b3BodyId towerIds[2]; - for ( int i = 0; i < 2; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { i == 0 ? -6.0f : 6.0f, 1.0f, 11.0f }; - towerIds[i] = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorSlateGray; - b3BoxHull box = b3MakeBoxHull( 1.5f, 1.0f, 2.0f ); - b3CreateHullShape( towerIds[i], &shapeDef, &box.base ); - } - - // Suspension bridge - { - int plankCount = 18; - float plankLength = 9.0f / plankCount; - float xBase = -4.5f; - float y = 1.95f; - float z = 11.0f; - - b3ShapeDef plankShapeDef = b3DefaultShapeDef(); - plankShapeDef.density = 300.0f; - plankShapeDef.baseMaterial.customColor = b3_colorBurlywood; - b3BoxHull plank = b3MakeBoxHull( 0.5f * plankLength - 0.01f, 0.05f, 0.75f ); - - // The hinge is the local z-axis, across the bridge - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.enableMotor = true; - jointDef.maxMotorTorque = 50.0f; - - b3BodyId prevId = towerIds[0]; - for ( int i = 0; i < plankCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { xBase + plankLength * ( i + 0.5f ), y, z }; - bodyDef.angularDamping = 0.5f; - b3BodyId plankId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( plankId, &plankShapeDef, &plank.base ); - - b3Pos pivot = { xBase + plankLength * i, y, z }; - jointDef.base.bodyIdA = prevId; - jointDef.base.bodyIdB = plankId; - jointDef.base.localFrameA.p = b3Body_GetLocalPoint( prevId, pivot ); - jointDef.base.localFrameB.p = b3Body_GetLocalPoint( plankId, pivot ); - b3CreateRevoluteJoint( m_worldId, &jointDef ); - - prevId = plankId; - } - - b3Pos pivot = { xBase + plankLength * plankCount, y, z }; - jointDef.base.bodyIdA = prevId; - jointDef.base.bodyIdB = towerIds[1]; - jointDef.base.localFrameA.p = b3Body_GetLocalPoint( prevId, pivot ); - jointDef.base.localFrameB.p = b3Body_GetLocalPoint( towerIds[1], pivot ); - b3CreateRevoluteJoint( m_worldId, &jointDef ); - } - - // Ramp to bridge. - AddRamp( { 6.0f, 2.0f, 9.0f }, { 6.0f, 0.0f, 3.5f }, 1.5f, b3_colorOliveDrab ); - - // Wall - AddRamp( { 20.0f, 3.0f, -40.0f }, { 20.0f, -0.5f, -40.0f }, 5.0f, b3_colorLightSteelBlue ); - - // Ramp - AddRamp( { 35.0f, 3.0f, -46.0f }, { 35.0f, -0.5f, -39.5f }, 5.0f, b3_colorLightSteelBlue ); - - // Steep - AddRamp( { 50.0f, 3.0f, -42.5f }, { 50.0f, -0.5f, -39.5f }, 5.0f, b3_colorLightSteelBlue ); - - // Curb - AddRamp( { 65.0f, 0.25f, -40.0f }, { 65.0f, -0.5f, -40.0f }, 5.0f, b3_colorLightSteelBlue ); - - // Ledges - for ( int i = 0; i < 2; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { i == 0 ? 18.0f : 32.0f, 2.0f, 0.0f }; - b3BodyId ledgeId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorDarkSlateGray; - b3BoxHull box = b3MakeBoxHull( 2.0f, 2.0f, 2.0f ); - b3CreateHullShape( ledgeId, &shapeDef, &box.base ); - } - - // Moving platforms - for ( int i = 0; i < m_platformCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_kinematicBody; - bodyDef.position = GetPlatformPosition( i, 0.0f ); - m_platformIds[i] = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef platformShapeDef = b3DefaultShapeDef(); - platformShapeDef.filter.categoryBits = DynamicBit; - platformShapeDef.baseMaterial.userMaterialId = m_platformMaterial; - platformShapeDef.baseMaterial.customColor = b3_colorGoldenRod; - b3BoxHull box = b3MakeBoxHull( 1.5f, 0.1f, 1.5f ); - b3CreateHullShape( m_platformIds[i], &platformShapeDef, &box.base ); - } - - // Seesaw - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { -14.0f, 0.4f, 0.0f }; - b3BodyId fulcrumId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorSlateGray; - b3BoxHull fulcrum = b3MakeBoxHull( 0.25f, 0.4f, 0.75f ); - b3CreateHullShape( fulcrumId, &shapeDef, &fulcrum.base ); - - bodyDef.type = b3_dynamicBody; - bodyDef.position = { -14.0f, 0.9f, 0.0f }; - b3BodyId plankId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef plankShapeDef = b3DefaultShapeDef(); - plankShapeDef.filter.categoryBits = DynamicBit; - plankShapeDef.density = 200.0f; - plankShapeDef.baseMaterial.customColor = b3_colorBurlywood; - b3BoxHull plank = b3MakeBoxHull( 3.5f, 0.1f, 0.8f ); - b3CreateHullShape( plankId, &plankShapeDef, &plank.base ); - - b3Pos pivot = { -14.0f, 0.8f, 0.0f }; - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = fulcrumId; - jointDef.base.bodyIdB = plankId; - jointDef.base.localFrameA.p = b3Body_GetLocalPoint( fulcrumId, pivot ); - jointDef.base.localFrameB.p = b3Body_GetLocalPoint( plankId, pivot ); - jointDef.enableLimit = true; - jointDef.lowerAngle = -0.3f; - jointDef.upperAngle = 0.3f; - b3CreateRevoluteJoint( m_worldId, &jointDef ); - } - - // Large pyramid past the seesaw, standing in the yz plane - { - int baseCount = m_isDebug ? 20 : 100; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef boxShapeDef = b3DefaultShapeDef(); - boxShapeDef.filter.categoryBits = DynamicBit; - boxShapeDef.density = 50.0f; - - float h = 0.25f; - b3BoxHull box = b3MakeCubeHull( h ); - - for ( int i = 0; i < baseCount; ++i ) - { - float y = ( 2.0f * i + 1.0f ) * h; - - for ( int j = i; j < baseCount; ++j ) - { - float z = ( i + 1.0f ) * h + 2.0f * ( j - i ) * h - h * baseCount; - - bodyDef.position = { -50.0f, y, z }; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId, &boxShapeDef, &box.base ); - } - } - } - - // Door - { - b3Pos doorPosition = { -10.0f, 1.6f, -8.0f }; - float doorHalfWidth = 0.75f; - float doorHalfHeight = 1.5f; - - // The door fits the frame tightly. The joint keeps the two from colliding. - b3BodyDef frameDef = b3DefaultBodyDef(); - frameDef.position = doorPosition; - b3BodyId frameId = b3CreateBody( m_worldId, &frameDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorSlateGray; - - float frameHalfWidth = 0.3f; - float postBottom = -doorPosition.y; - float postHalfHeight = 0.5f * ( doorHalfHeight - postBottom ); - float postOffset = doorHalfWidth + frameHalfWidth; - - for ( float side : { -1.0f, 1.0f } ) - { - b3Transform transform = { { side * postOffset, postBottom + postHalfHeight, 0.0f }, - b3Quat_identity }; - b3BoxHull post = - b3MakeTransformedBoxHull( frameHalfWidth, postHalfHeight, 0.2f, transform ); - b3CreateHullShape( frameId, &shapeDef, &post.base ); - } - - b3Transform transform = { { 0.0f, doorHalfHeight + frameHalfWidth, 0.0f }, - b3Quat_identity }; - b3BoxHull lintel = b3MakeTransformedBoxHull( postOffset + frameHalfWidth, - frameHalfWidth, 0.2f, transform ); - b3CreateHullShape( frameId, &shapeDef, &lintel.base ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = doorPosition; - bodyDef.gravityScale = 2.0f; - b3BodyId doorId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef doorShapeDef = b3DefaultShapeDef(); - doorShapeDef.filter.categoryBits = DynamicBit; - doorShapeDef.density = 100.0f; - doorShapeDef.baseMaterial.customColor = b3_colorPeru; - b3BoxHull box = b3MakeBoxHull( doorHalfWidth, doorHalfHeight, 0.1f ); - b3CreateHullShape( doorId, &doorShapeDef, &box.base ); - - b3Quat axisQuat = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisZ, b3Vec3_axisY ); - b3Vec3 offset = { -doorHalfWidth, 0.0f, 0.0f }; - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = frameId; - jointDef.base.bodyIdB = doorId; - jointDef.base.localFrameA = { offset, axisQuat }; - jointDef.base.localFrameB = { offset, axisQuat }; - jointDef.enableLimit = true; - jointDef.lowerAngle = B3_DEG_TO_RAD * -90.0f; - jointDef.upperAngle = B3_DEG_TO_RAD * 90.0f; - jointDef.enableSpring = true; - jointDef.hertz = 1.0f; - jointDef.dampingRatio = 0.5f; - jointDef.base.drawScale = 2.0f; - b3CreateRevoluteJoint( m_worldId, &jointDef ); - } - - // Ball pit - { - b3ShapeDef sphereShapeDef = b3DefaultShapeDef(); - sphereShapeDef.density = 100.0f; - sphereShapeDef.baseMaterial.friction = 0.2f; - sphereShapeDef.baseMaterial.customColor = b3_colorLightSeaGreen; - sphereShapeDef.filter.categoryBits = DynamicBit; - b3Sphere sphere = { b3Vec3_zero, 0.35f }; - - b3WeldJointDef jointDef = b3DefaultWeldJointDef(); - jointDef.linearHertz = 0.5f; - jointDef.linearDampingRatio = 0.2f; - jointDef.base.bodyIdA = groundId; - jointDef.base.collideConnected = true; - - int gridCount = 20; - for ( int i = 0; i < gridCount; ++i ) - { - for ( int j = 0; j < gridCount; ++j ) - { - b3Pos position = { -9.5f + 1.0f * i, 1.3f, 17.0f + 1.0f * j }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = position; - bodyDef.gravityScale = 0.0f; - b3BodyId sphereId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateSphereShape( sphereId, &sphereShapeDef, &sphere ); - - jointDef.base.bodyIdB = sphereId; - jointDef.base.localFrameA.p = b3Body_GetLocalPoint( groundId, position ); - jointDef.base.localFrameB.p = b3Vec3_zero; - b3CreateWeldJoint( m_worldId, &jointDef ); - } - } - } - - // Pressure plate - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = m_plateCenter; - b3BodyId plateId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef plateShapeDef = b3DefaultShapeDef(); - plateShapeDef.density = 20.0f; - plateShapeDef.baseMaterial.customColor = b3_colorFireBrick; - // Only allow the mover to press this. - plateShapeDef.filter = { DynamicBit, MoverBit, 0 }; - plateShapeDef.explosionScale = 0.0f; - - b3BoxHull plate = b3MakeBoxHull( 1.5f, 0.1f, 1.5f ); - b3CreateHullShape( plateId, &plateShapeDef, &plate.base ); - - // The motor force works like a preloaded spring. The plate holds its own weight but - // sinks under the mover. - float gravity = b3Length( b3World_GetGravity( m_worldId ) ); - float plateWeight = gravity * b3Body_GetMass( plateId ); - float moverWeight = - m_mover.m_gravityScale * gravity * b3Body_GetMass( m_mover.GetBodyId() ); - - // The prismatic axis is the local x-axis, so turn it upright - b3Quat upright = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ); - - b3PrismaticJointDef jointDef = b3DefaultPrismaticJointDef(); - jointDef.base.bodyIdA = groundId; - jointDef.base.bodyIdB = plateId; - jointDef.base.localFrameA = { b3Body_GetLocalPoint( groundId, m_plateCenter ), - upright }; - jointDef.base.localFrameB = { b3Vec3_zero, upright }; - jointDef.enableLimit = true; - jointDef.lowerTranslation = -m_plateTravel; - jointDef.upperTranslation = 0.0f; - jointDef.enableMotor = true; - jointDef.motorSpeed = 0.5f; - jointDef.maxMotorForce = plateWeight + 0.5f * moverWeight; - m_plateJointId = b3CreatePrismaticJoint( m_worldId, &jointDef ); - m_plateArmed = true; - } - - // Skittles - if constexpr ( m_isDebug == false ) - { - b3ShapeDef boxShapeDef = b3DefaultShapeDef(); - - // Debris doesn't collide with the mover or other debris. - boxShapeDef.filter.categoryBits = DebrisBit; - boxShapeDef.filter.maskBits = DebrisBit | ProjectileBit | DynamicBit | StaticBit; - boxShapeDef.density = 100.0f; - boxShapeDef.explosionScale = 0.05f; - - b3HexColor colors[5] = { b3_colorCrimson, b3_colorDarkOrange, b3_colorGold, - b3_colorLimeGreen, b3_colorRebeccaPurple }; - - constexpr int sides = 6; - float radius = 0.1f; - float halfHeight = 0.05f; - float bulge = 1.3f; - b3Vec3 points[3 * sides]; - for ( int i = 0; i < sides; ++i ) - { - b3CosSin cs = b3ComputeCosSin( 2.0f * B3_PI * i / sides ); - b3Vec3 rim = { radius * cs.cosine, 0.0f, radius * cs.sine }; - points[3 * i + 0] = { rim.x, -halfHeight, rim.z }; - points[3 * i + 1] = { bulge * rim.x, 0.0f, bulge * rim.z }; - points[3 * i + 2] = { rim.x, halfHeight, rim.z }; - } - - b3HullData* skittle = b3CreateHull( points, 3 * sides, 3 * sides ); - - int gridCount = 32; - int layerCount = 3; - float spacing = 0.5f; - float offset = -0.5f * spacing * ( gridCount - 1 ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.isAwake = false; - - for ( int layer = 0; layer < layerCount; ++layer ) - { - for ( int i = 0; i < gridCount; ++i ) - { - for ( int j = 0; j < gridCount; ++j ) - { - bodyDef.position = { m_plateCenter.x + offset + spacing * i, - 8.0f + spacing * layer, - m_plateCenter.z + offset + spacing * j }; - b3BodyId boxId = b3CreateBody( m_worldId, &bodyDef ); - boxShapeDef.baseMaterial.customColor = colors[( i + 3 * j ) % 5]; - b3CreateHullShape( boxId, &boxShapeDef, skittle ); - } - } - } - - b3DestroyHull( skittle ); - } - - // Big sphere - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 6.0f, 1.0f, -6.0f }; - b3BodyId ballId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef ballShapeDef = b3DefaultShapeDef(); - ballShapeDef.filter.categoryBits = DynamicBit; - ballShapeDef.density = 30.0f; - ballShapeDef.baseMaterial.rollingResistance = 0.05f; - ballShapeDef.baseMaterial.customColor = b3_colorTomato; - b3Sphere sphere = { b3Vec3_zero, 1.0f }; - b3CreateSphereShape( ballId, &ballShapeDef, &sphere ); - } - - // Sweeper - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = m_sweeperCenter; - b3BodyId sweeperId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.filter.categoryBits = DynamicBit; - shapeDef.baseMaterial.customColor = b3_colorCrimson; - - b3BoxHull post = b3MakeTransformedBoxHull( 0.3f, 0.6f, 0.3f, - { { 0.0f, 0.6f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( sweeperId, &shapeDef, &post.base ); - - b3BoxHull armX = b3MakeTransformedBoxHull( 5.0f, 0.25f, 0.1f, - { { 0.0f, 1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( sweeperId, &shapeDef, &armX.base ); - - b3BoxHull armZ = b3MakeTransformedBoxHull( 0.1f, 0.25f, 5.0f, - { { 0.0f, 1.0f, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( sweeperId, &shapeDef, &armZ.base ); - - b3Quat upright = b3MakeQuatFromAxisAngle( b3Vec3_axisX, -0.5f * B3_PI ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = groundId; - jointDef.base.bodyIdB = sweeperId; - jointDef.base.localFrameA = { b3Body_GetLocalPoint( groundId, m_sweeperCenter ), - upright }; - jointDef.base.localFrameB = { b3Vec3_zero, upright }; - jointDef.enableMotor = true; - jointDef.motorSpeed = 1.0f; - jointDef.maxMotorTorque = 3000.0f; - - b3CreateRevoluteJoint( m_worldId, &jointDef ); - } - - // Jump puzzle - for ( int i = 0; i < m_pillarCount; ++i ) - { - b3Pos top = GetPillarTop( i ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { top.x, 0.0f, top.z }; - b3BodyId pillarId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = b3_colorMediumPurple; - b3HullData* pillar = b3CreateCylinder( (float)top.y, 0.75f, 0.0f, 12 ); - b3CreateHullShape( pillarId, &shapeDef, pillar ); - b3DestroyHull( pillar ); - } - - SpawnGems(); - - m_camera->m_thirdPerson = true; - sapp_lock_mouse( true ); - - m_jumpReleased = true; - m_drawProbes = true; - m_useBox = false; - - for ( b3BodyId& id : m_ballIds ) - { - id = b3_nullBodyId; - } - - m_ballIndex = 0; - m_ballSpeed = 50.0f; - m_aiming = false; - m_aimBlend = 0.0f; - m_shootRequested = false; - - // Flat ended so the muzzle sits at the front face - float launcherLength = m_launcherBack + m_launcherFront + m_launcherRadius; - m_launcherHull = b3CreateCylinder( launcherLength, m_launcherRadius, -m_launcherBack, 5 ); - m_launcherMesh = FindOrAddHull( m_launcherHull ); - m_time = 0.0f; - } - - ~DynamicMoverSample() override - { - ReleaseMeshReference( m_launcherMesh ); - b3DestroyHull( m_launcherHull ); - - m_camera->m_thirdPerson = false; - sapp_lock_mouse( false ); - } - - void AddRamp( b3Vec3 high, b3Vec3 low, float halfWidth, b3HexColor color ) - { - b3Vec3 axis = b3Sub( high, low ); - float length = b3Length( axis ); - axis = b3MulSV( 1.0f / length, axis ); - - b3Quat rotation = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisZ, axis ); - b3Vec3 normal = b3RotateVector( rotation, b3Vec3_axisY ); - - float halfThickness = 0.1f; - b3Vec3 center = b3MulAdd( b3Lerp( low, high, 0.5f ), -halfThickness, normal ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId rampId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.customColor = color; - b3BoxHull box = b3MakeTransformedBoxHull( halfWidth, halfThickness, 0.5f * length, - { center, rotation } ); - b3CreateHullShape( rampId, &shapeDef, &box.base ); - } - - b3Pos GetPlatformPosition( int index, float time ) const - { - if ( index == 0 ) - { - // Vertical - float y = 1.95f - 1.95f * cosf( 0.6f * time ); - return { 14.0f, y, 0.0f }; - } - - // Horizontal - float x = 25.0f - 3.5f * cosf( 0.5f * time ); - return { x, 3.9f, 0.0f }; - } - - b3Pos GetPillarTop( int index ) const - { - return { -20.0f, 0.5f + 0.6f * index, -3.0f - 5.0f * index }; - } - - void SpawnGems() - { - b3Pos positions[m_gemCount] = { - { 0.0f, 1.2f, 5.0f }, { -6.0f, 2.2f, 6.0f }, { -6.0f, 3.2f, 11.0f }, - { 0.0f, 3.2f, 11.0f }, { 6.0f, 3.2f, 11.0f }, { 6.0f, 2.2f, 6.0f }, - { 18.0f, 5.2f, 0.0f }, { 25.0f, 5.2f, 0.0f }, { 32.0f, 5.2f, 0.0f }, - { -17.0f, 2.2f, 0.0f }, { -10.0f, 4.4f, -8.0f }, { 6.0f, 1.2f, -9.5f }, - { 3.0f, 1.2f, -16.0f }, { -3.0f, 1.2f, -16.0f }, { 0.0f, 1.2f, -19.0f }, - { 0.0f, 1.2f, -13.0f }, { -20.0f, 0.0f, 0.0f }, - }; - - positions[m_gemCount - 1] = GetPillarTop( m_pillarCount - 1 ); - positions[m_gemCount - 1].y += 1.2f; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.isSensor = true; - shapeDef.enableSensorEvents = true; - shapeDef.filter = { GemBit, MoverBit, 0 }; - shapeDef.baseMaterial.customColor = b3_colorGold; - - b3Quat tilt = b3MakeQuatFromAxisAngle( b3Normalize( { 1.0f, 0.0f, -1.0f } ), 0.9553f ); - b3BoxHull gem = b3MakeTransformedBoxHull( 0.2f, 0.2f, 0.2f, { b3Vec3_zero, tilt } ); - - for ( int i = 0; i < m_gemCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_kinematicBody; - bodyDef.position = positions[i]; - bodyDef.angularVelocity = { 0.0f, 2.0f, 0.0f }; - m_gemIds[i] = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( m_gemIds[i], &shapeDef, &gem.base ); - } - } - - void UpdatePressurePlate() - { - float translation = b3PrismaticJoint_GetTranslation( m_plateJointId ); - - if ( m_plateArmed && translation < -m_plateTravel + 0.01f ) - { - b3ExplosionDef def = b3DefaultExplosionDef(); - def.position = b3OffsetPos( m_plateCenter, b3Vec3{ 0.0f, -0.1f, 0.0f } ); - def.radius = 10.0f; - def.falloff = 10.0f; - def.impulsePerArea = 3000.0f; - b3World_Explode( m_worldId, &def ); - - m_mover.Launch(); - m_plateArmed = false; - } - else if ( m_plateArmed == false && translation > -0.01f ) - { - m_plateArmed = true; - } - } - - void CollectGems() - { - b3SensorEvents events = b3World_GetSensorEvents( m_worldId ); - for ( int i = 0; i < events.beginCount; ++i ) - { - b3SensorBeginTouchEvent* event = events.beginEvents + i; - if ( b3Shape_IsValid( event->visitorShapeId ) == false || - b3Shape_IsValid( event->sensorShapeId ) == false ) - { - continue; - } - - b3BodyId visitorId = b3Shape_GetBody( event->visitorShapeId ); - if ( B3_ID_EQUALS( visitorId, m_mover.GetBodyId() ) == false ) - { - continue; - } - - b3BodyId gemId = b3Shape_GetBody( event->sensorShapeId ); - for ( b3BodyId& id : m_gemIds ) - { - if ( B3_ID_EQUALS( id, gemId ) ) - { - b3DestroyBody( id ); - id = b3_nullBodyId; - break; - } - } - } - } - - void SwapMoverShape() - { - b3BodyId bodyId = m_mover.GetBodyId(); - - b3ShapeId shapeId; - b3Body_GetShapes( bodyId, &shapeId, 1 ); - float density = b3Shape_GetDensity( shapeId ); - b3DestroyShape( shapeId, false ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - shapeDef.filter = { MoverBit, AllBits, 0 }; - shapeDef.enableSensorEvents = true; - - b3Capsule capsule = m_mover.m_capsule; - if ( m_useBox ) - { - float r = capsule.radius; - float hy = 0.5f * b3Length( capsule.center2 - capsule.center1 ) + r; - b3Vec3 c = b3Lerp( capsule.center1, capsule.center2, 0.5f ); - b3BoxHull box = b3MakeOffsetBoxHull( r, hy, r, c ); - shapeDef.density = density; - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - else - { - shapeDef.density = density; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - } - - struct Aim - { - b3Pos shoulder; - b3Pos muzzle; - b3Vec3 direction; - b3Vec3 right; - b3Vec3 velocity; - }; - - Aim ComputeAim() const - { - const b3Capsule& capsule = m_mover.m_capsule; - - b3Vec3 right = m_camera->GetRight(); - right.y = 0.0f; - right = b3Normalize( right ); - - Aim aim = {}; - aim.right = right; - - b3Vec3 shoulderOffset = capsule.center2 + ( capsule.radius + m_launcherRadius ) * right; - aim.shoulder = b3Body_GetPosition( m_mover.GetBodyId() ) + shoulderOffset; - aim.direction = -m_camera->GetForward(); - aim.muzzle = aim.shoulder + ( m_launcherFront + m_launcherRadius ) * aim.direction; - aim.velocity = m_ballSpeed * aim.direction; - - return aim; - } - - void ShootBall( const Aim& aim, float leadTime ) - { - b3BodyId& ballId = m_ballIds[m_ballIndex]; - if ( b3Body_IsValid( ballId ) ) - { - b3DestroyBody( ballId ); - } - - // Back up the spawn point so we see it drawn at the muzzle. - float backDistance = - b3MinFloat( m_ballSpeed * leadTime, m_launcherFront + m_launcherRadius ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = aim.muzzle - backDistance * aim.direction; - bodyDef.linearVelocity = aim.velocity; - - // This is good use case for the bullet setting because this is a fast projectile. - bodyDef.isBullet = true; - bodyDef.name = "ball"; - ballId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 4000.0f; - shapeDef.baseMaterial.friction = 0.2f; - shapeDef.baseMaterial.restitution = 0.5f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - shapeDef.baseMaterial.customColor = b3_colorOrangeRed; - shapeDef.filter = { ProjectileBit, AllBits & ~MoverBit, 0 }; - b3Sphere sphere = { b3Vec3_zero, m_ballRadius }; - b3CreateSphereShape( ballId, &shapeDef, &sphere ); - - m_ballIndex = ( m_ballIndex + 1 ) % m_ballCapacity; - } - - void DrawWeapon( const Aim& aim ) const - { - // The cylinder axis is local y. Roll with the camera to keep it steady. - b3Matrix3 basis = { aim.right, aim.direction, b3Cross( aim.right, aim.direction ) }; - b3WorldTransform launcherTransform = { aim.shoulder, b3MakeQuatFromMatrix( &basis ) }; - b3Transform relative = b3ToRelativeTransform( launcherTransform, GetDrawOrigin() ); - AppendMesh( m_launcherMesh, relative, b3Vec3_one, MakeColor( b3_colorDimGray ), 0.6f, 0.35f, - MESH_MATERIAL_MODE_SOLID, 0.0f, TRANSPARENT_SHADOW_FULL ); - } - - void MouseDown( b3Vec2 p, int button, int modifiers ) override - { - if ( m_camera->m_thirdPerson ) - { - if ( button == 1 ) - { - m_aiming = true; - } - else if ( button == 0 && m_aiming ) - { - m_shootRequested = true; - } - - return; - } - - Sample::MouseDown( p, button, modifiers ); - } - - void MouseUp( b3Vec2 p, int button ) override - { - if ( button == 1 ) - { - m_aiming = false; - } - - Sample::MouseUp( p, button ); - } - - // Pull the boom in when the view to the mover is blocked - void FollowMover( b3Pos position ) - { - if ( m_camera->m_thirdPerson == false ) - { - m_aiming = false; - m_aimBlend = 0.0f; - SetBodyAlpha( b3_nullBodyId, 1.0f ); - return; - } - - // Frame time so the blend still runs while paused - float blendTime = 0.2f; - float blendStep = ImGui::GetIO().DeltaTime / blendTime; - m_aimBlend = b3ClampFloat( m_aimBlend + ( m_aiming ? blendStep : -blendStep ), 0.0f, 1.0f ); - float blend = m_aimBlend * m_aimBlend * ( 3.0f - 2.0f * m_aimBlend ); - - // The zoomed camera sits right behind the mover, so fade it to see past - SetBodyAlpha( m_mover.GetBodyId(), 1.0f - 0.7f * blend ); - - // The wheel zoom stays in the camera radius, aiming only overrides it for this frame - float savedRadius = m_camera->m_radius; - float aimRadius = b3MinFloat( savedRadius, 0.8f ); - m_camera->m_radius = savedRadius + blend * ( aimRadius - savedRadius ); - - m_camera->m_pivot = position; - m_camera->UpdateTransform(); - - // Over the shoulder so the mover and launcher sit low and left of the crosshair - if ( blend > 0.0f ) - { - b3Vec3 shoulder = 0.75f * b3Vec3_axisY + 0.6f * m_camera->GetRight(); - m_camera->m_pivot = position + blend * shoulder; - m_camera->UpdateTransform(); - } - - b3Vec3 translation = b3SubPos( m_camera->m_worldEye, position ); - float distance = b3Length( translation ); - if ( distance > 0.01f ) - { - b3QueryFilter filter = { StaticBit, StaticBit, 0, "camera" }; - b3RayResult result = b3World_CastRayClosest( m_worldId, position, translation, filter ); - if ( result.hit ) - { - m_camera->m_radius = b3MaxFloat( 0.1f, result.fraction * distance - 0.15f ); - m_camera->UpdateTransform(); - } - } - - m_camera->m_radius = savedRadius; - } - - void Keyboard( int key, int action, int mods ) override - { - if ( key == KEY_T && action == ACTION_PRESS ) - { - ToggleThirdPerson(); - } - - // Align movement for video - if ( key == KEY_K && action == ACTION_PRESS ) - { - float quarterTurn = 0.5f * B3_PI; - m_camera->m_yaw = quarterTurn * roundf( m_camera->m_yaw / quarterTurn ); - m_camera->m_pitch = 15.0f * B3_DEG_TO_RAD; - - b3BodyId bodyId = m_mover.GetBodyId(); - b3Pos position = b3Body_GetPosition( bodyId ); - position.x = roundf( position.x ); - position.z = roundf( position.z ); - b3Body_SetTransform( bodyId, position, b3Body_GetRotation( bodyId ) ); - b3Body_SetLinearVelocity( bodyId, b3Vec3_zero ); - } - } - - bool DrawControls() override - { - bool thirdPerson = m_camera->m_thirdPerson; - if ( ImGui::Checkbox( "Third Person (T)", &thirdPerson ) ) - { - ToggleThirdPerson(); - } - - ImGui::Checkbox( "Skirt Pogo", &m_mover.m_enableSkirtPogo ); - ImGui::Checkbox( "Draw Probes", &m_drawProbes ); - - if ( ImGui::Checkbox( "Box Mover", &m_useBox ) ) - { - SwapMoverShape(); - } - - ImGui::Separator(); - - ImGui::SliderFloat( "Jump Speed", &m_mover.m_jumpSpeed, 0.0f, 20.0f, "%.1f" ); - ImGui::SliderFloat( "Max Speed", &m_mover.m_maxSpeed, 0.0f, 20.0f, "%.0f" ); - ImGui::SliderFloat( "Accelerate", &m_mover.m_accelerate, 0.0f, 100.0f, "%.0f" ); - ImGui::SliderFloat( "Friction", &m_mover.m_friction, 0.0f, 20.0f, "%.1f" ); - ImGui::SliderFloat( "Air Steer", &m_mover.m_airSteer, 0.0f, 1.0f, "%.2f" ); - - float gravityScale = m_mover.m_gravityScale; - if ( ImGui::SliderFloat( "Gravity Scale", &gravityScale, 0.0f, 4.0f, "%.1f" ) ) - { - m_mover.SetGravityScale( gravityScale ); - } - - ImGui::SliderFloat( "Pogo Hertz", &m_mover.m_pogoHertz, 0.0f, 30.0f, "%.0f" ); - ImGui::SliderFloat( "Pogo Damping", &m_mover.m_pogoDampingRatio, 0.0f, 4.0f, "%.1f" ); - ImGui::SliderFloat( "Ground Force", &m_mover.m_maxGroundForce, 0.0f, 20000.0f, "%.0f" ); - - ImGui::Separator(); - - ImGui::SliderFloat( "Ball Speed", &m_ballSpeed, 10.0f, 200.0f, "%.0f" ); - - return true; - } - - void Step() override - { - bool pause = m_context->pause && m_context->singleStep == 0; - float timeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - - if ( pause == false && timeStep > 0.0f ) - { - m_time += timeStep; - - for ( int i = 0; i < m_platformCount; ++i ) - { - b3WorldTransform target = { GetPlatformPosition( i, m_time ), b3Quat_identity }; - b3Body_SetTargetTransform( m_platformIds[i], target, timeStep, true ); - } - - MoverInput input = GetMoverInput(); - - // Jumping again needs a fresh press - if ( input.jump ) - { - if ( m_jumpReleased && m_mover.Jump() ) - { - m_jumpReleased = false; - } - } - else - { - m_jumpReleased = true; - } - - float speedScale = 1.0f; - if ( input.walk || m_aiming ) - { - speedScale = 0.25f; - } - else if ( input.sprint ) - { - speedScale = 1.5f; - } - m_mover.Update( timeStep, input.forward, input.right, input.throttle, speedScale ); - } - - // The base step draws the world, so the camera has to be placed before it. Otherwise the - // world renders from the previous eye and the overlay from the new one. - FollowMover( b3Body_GetPosition( m_mover.GetBodyId() ) ); - - // Shoot before the step so the ball is in the world when it is drawn - if ( m_aiming && m_shootRequested ) - { - float leadTime = pause == false ? timeStep : 0.0f; - ShootBall( ComputeAim(), leadTime ); - } - - m_shootRequested = false; - - Sample::Step(); - - if ( m_didStep ) - { - CollectGems(); - UpdatePressurePlate(); - } - - if ( m_drawProbes ) - { - m_mover.Draw(); - } - - if ( m_aiming ) - { - Aim aim = ComputeAim(); - DrawWeapon( aim ); - } - - DrawTextLine( "WASD = move, Space = jump, Shift = sprint, Ctrl = walk" ); - DrawTextLine( "T = camera, RMB = aim, LMB = shoot" ); - - float normalY = m_mover.m_castResult.hit ? m_mover.m_castResult.normal.y : 0.0f; - DrawTextLine( "on ground %d, walkable %d, normal y %.2f", (int)m_mover.m_onGround, - (int)m_mover.m_walkable, normalY ); - DrawTextLine( "pogo length %.2f / %.2f", m_mover.m_pogoLength, m_mover.m_pogoRestLength ); - - DrawTextLine( "time sliding %.2f", m_mover.m_timeSliding ); - } - - static Sample* Create( SampleContext* context ) - { - return new DynamicMoverSample( context ); - } - - static constexpr uint64_t StaticBit = 0x1; - static constexpr uint64_t MoverBit = 0x2; - static constexpr uint64_t GemBit = 0x4; - static constexpr uint64_t DynamicBit = 0x10; - static constexpr uint64_t ProjectileBit = 0x20; - static constexpr uint64_t DebrisBit = 0x40; - static constexpr uint64_t AllBits = ~0ull; - - static constexpr int m_ballCapacity = 50; - - static constexpr float m_launcherRadius = 0.03f; - static constexpr float m_launcherBack = 0.05f; - static constexpr float m_launcherFront = 0.55f; - static constexpr float m_ballRadius = 0.1f; - - static constexpr uint64_t m_platformMaterial = 7; - static constexpr int m_platformCount = 2; - static constexpr int m_pillarCount = 6; - static constexpr int m_gemCount = 17; - static constexpr b3Pos m_sweeperCenter = { 0.0f, 0.0f, -16.0f }; - static constexpr b3Pos m_plateCenter = { 0.0f, 0.05f, 26.5f }; - static constexpr float m_plateTravel = 0.1f; - - DynamicMover m_mover; - b3JointId m_plateJointId; - bool m_plateArmed; - b3BodyId m_platformIds[m_platformCount]; - b3BodyId m_gemIds[m_gemCount]; - float m_time; - bool m_jumpReleased; - bool m_drawProbes; - bool m_useBox; - - b3BodyId m_ballIds[m_ballCapacity]; - int m_ballIndex; - float m_ballSpeed; - bool m_aiming; - float m_aimBlend; - bool m_shootRequested; - b3HullData* m_launcherHull; - MeshHandle m_launcherMesh; -}; - -static int sampleDynamicMover = - RegisterSample( "Character", "Dynamic Mover", DynamicMoverSample::Create ); +static int sampleMover = RegisterSample( "Character", "Mover", BasicMover::Create ); struct ClosestShapeCastContext { @@ -1887,9 +601,8 @@ struct ClosestShapeCastContext bool startedSolid; }; -static float ClosestShapeCastCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, - float fraction, uint64_t userMaterialId, int triangleIndex, - int childIndex, void* context ) +static float ClosestShapeCastCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, + int triangleIndex, int childIndex, void* context ) { auto* ctx = static_cast( context ); @@ -2029,10 +742,8 @@ struct RigidbodyCharacter float feetVolume = 8.0f * halfExtX * halfExtY * halfExtZ; shapeDef.density = ( m_characterMass * 0.4f ) / feetVolume; - b3Transform feetTransform = { { 0.0f, -m_totalHeight * 0.5f + halfExtY, 0.0f }, - b3Quat_identity }; - b3BoxHull feetBox = - b3MakeTransformedBoxHull( halfExtX, halfExtY, halfExtZ, feetTransform ); + b3Transform feetTransform = { { 0.0f, -m_totalHeight * 0.5f + halfExtY, 0.0f }, b3Quat_identity }; + b3BoxHull feetBox = b3MakeTransformedBoxHull( halfExtX, halfExtY, halfExtZ, feetTransform ); m_feetBoxId = b3CreateHullShape( m_bodyId, &shapeDef, &feetBox.base ); } @@ -2072,8 +783,7 @@ struct RigidbodyCharacter // --- TraceBody: box shape cast matching s&box's TraceBody --- // Casts a box from `from` to `to` with given radius and height scale. - TraceResult TraceBody( b3Pos from, b3Pos to, float radiusScale = 1.0f, - float heightScale = 1.0f ) const + TraceResult TraceBody( b3Pos from, b3Pos to, float radiusScale = 1.0f, float heightScale = 1.0f ) const { TraceResult result = {}; result.endPosition = to; @@ -2128,8 +838,7 @@ struct RigidbodyCharacter ctx.closestShape = b3_nullShapeId; b3QueryFilter filter = b3DefaultQueryFilter(); - b3World_CastShape( m_sample->m_worldId, from, &proxy, translation, filter, - ClosestShapeCastCallback, &ctx ); + b3World_CastShape( m_sample->m_worldId, from, &proxy, translation, filter, ClosestShapeCastCallback, &ctx ); result.startedSolid = ctx.startedSolid; if ( ctx.hit ) @@ -2182,8 +891,7 @@ struct RigidbodyCharacter tr = TraceBody( from, to, radiusScale, 0.5f ); } - if ( !tr.startedSolid && tr.hit && IsStandableSurface( tr.normal ) && - m_jumpCooldown <= 0.0f ) + if ( !tr.startedSolid && tr.hit && IsStandableSurface( tr.normal ) && m_jumpCooldown <= 0.0f ) { UpdateGround( true, tr.normal ); DrawLine( from, tr.hitPoint, MakeColor( b3_colorGreen ) ); @@ -2276,8 +984,7 @@ struct RigidbodyCharacter // Phase 1 — FORWARD: trace body forward in velocity direction // Start slightly behind (offset by skin) - float forwardDist = - hSpeed * ( 1.0f / 60.0f ) + m_bodyRadius; // one frame of movement + radius + float forwardDist = hSpeed * ( 1.0f / 60.0f ) + m_bodyRadius; // one frame of movement + radius b3Pos forwardFrom = pos - m_skin * moveDir; b3Pos forwardTo = pos + forwardDist * moveDir; @@ -2371,8 +1078,7 @@ struct RigidbodyCharacter DrawPoint( trDown.endPosition, 8.0f, MakeColor( b3_colorYellow ) ); // Teleport body to step position - b3Pos stepPos = { trDown.endPosition.x, trDown.endPosition.y + 0.01f, - trDown.endPosition.z }; + b3Pos stepPos = { trDown.endPosition.x, trDown.endPosition.y + 0.01f, trDown.endPosition.z }; b3Quat rot = b3Body_GetRotation( m_bodyId ); b3Body_SetTransform( m_bodyId, stepPos, rot ); @@ -2466,8 +1172,7 @@ struct RigidbodyCharacter b3Body_SetGravityScale( m_bodyId, wantsGravity ? ( m_characterGravity / 10.0f ) : 0.0f ); // Linear damping — s&box: brakes when wish < 1 unit/s && groundVel < 1 unit/s - bool wantsDamping = - m_onGround && wishLen < ( 1.0f * SRC ) && b3Length( m_groundVelocity ) < ( 1.0f * SRC ); + bool wantsDamping = m_onGround && wishLen < ( 1.0f * SRC ) && b3Length( m_groundVelocity ) < ( 1.0f * SRC ); b3Body_SetLinearDamping( m_bodyId, wantsDamping ? 10.0f * m_brakePower : m_airFriction ); } @@ -2544,7 +1249,7 @@ struct RigidbodyCharacter // 3. TryStep — 4-phase step-up m_didStep = TryStep( m_stepUpHeight ); - m_massCenterWorld = b3Body_GetWorldCenter( m_bodyId ); + m_massCenterWorld = b3Body_GetWorldCenterOfMass( m_bodyId ); } // --- PostStep: RestoreStep + Reground + CategorizeGround --- @@ -2600,8 +1305,7 @@ struct RigidbodyCharacter if ( m_onGround ) { b3Pos bottom = { pos.x, pos.y - m_totalHeight * 0.5f, pos.z }; - DrawLine( bottom, b3OffsetPos( bottom, 0.3f * m_groundNormal ), - MakeColor( b3_colorGreen ) ); + DrawLine( bottom, b3OffsetPos( bottom, 0.3f * m_groundNormal ), MakeColor( b3_colorGreen ) ); } } }; @@ -2623,17 +1327,19 @@ public: // --- Main level mesh (test_map01) --- { - m_levelMesh = - CreateMeshData( "data/meshes/test_map01.obj", 1.0f, false, false, true, true ); + m_levelMesh = CreateMeshData( "data/meshes/test_map01.obj", 1.0f, false, false, true, true ); b3BodyDef bodyDef = b3DefaultBodyDef(); b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3SurfaceMaterial materials[3]; + materials[0] = { 0.6f, 0.0f, 0 }; + materials[1] = { 0.6f, 1.0f, 1 }; + materials[2] = { 0.1f, 0.0f, 2 }; + shapeDef.materials = materials; + shapeDef.materialCount = 3; - if ( m_levelMesh != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_levelMesh, b3Vec3_one ); - } + b3CreateMeshShape( body, &shapeDef, m_levelMesh, b3Vec3_one ); } // --- Stairs mesh --- @@ -2644,53 +1350,38 @@ public: b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( m_stairs != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_stairs, { 0.75f, 0.75f, -1.5f } ); - } + b3CreateMeshShape( body, &shapeDef, m_stairs, { 0.75f, 0.75f, -1.5f } ); } // --- High-poly building mesh --- { - m_building = - CreateMeshData( "data/meshes/building.obj", 1.0f, false, false, true, true ); + m_building = CreateMeshData( "data/meshes/building.obj", 1.0f, false, false, true, true ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { -5.0f, 0.0f, -10.0f }; b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( m_building != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_building, b3Vec3_one ); - } + b3CreateMeshShape( body, &shapeDef, m_building, b3Vec3_one ); } // --- Voxel meshes (dense tri terrain) --- { - m_voxel01 = - CreateMeshData( "data/meshes/voxel_mesh_01.obj", 1.0f, false, false, true, true ); + m_voxel01 = CreateMeshData( "data/meshes/voxel_mesh_01.obj", 1.0f, false, false, true, true ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 10.0f, 0.0f, -10.0f }; b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( m_voxel01 != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_voxel01, b3Vec3_one ); - } + b3CreateMeshShape( body, &shapeDef, m_voxel01, b3Vec3_one ); } { - m_voxel02 = - CreateMeshData( "data/meshes/voxel_mesh_02.obj", 1.0f, false, false, true, true ); + m_voxel02 = CreateMeshData( "data/meshes/voxel_mesh_02.obj", 1.0f, false, false, true, true ); b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 10.0f, 0.0f, 10.0f }; b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( m_voxel02 != nullptr ) - { - b3CreateMeshShape( body, &shapeDef, m_voxel02, b3Vec3_one ); - } + b3CreateMeshShape( body, &shapeDef, m_voxel02, b3Vec3_one ); } // --- Height field terrain --- @@ -2701,6 +1392,13 @@ public: m_heightField = b3CreateWave( 50.0f, 50.0f, b3Vec3_one, 0.02f, 0.04f, true ); b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3SurfaceMaterial materials[3]; + materials[0] = { 0.6f, 0.0f, 0 }; + materials[1] = { 0.6f, 1.0f, 1 }; + materials[2] = { 0.1f, 0.0f, 2 }; + shapeDef.materials = materials; + shapeDef.materialCount = 3; + b3CreateHeightFieldShape( body, &shapeDef, m_heightField ); } @@ -2795,11 +1493,11 @@ public: { m_camera->m_thirdPerson = false; sapp_lock_mouse( false ); - DestroyMeshData( m_levelMesh ); - DestroyMeshData( m_stairs ); - DestroyMeshData( m_building ); - DestroyMeshData( m_voxel01 ); - DestroyMeshData( m_voxel02 ); + b3DestroyMesh( m_levelMesh ); + b3DestroyMesh( m_stairs ); + b3DestroyMesh( m_building ); + b3DestroyMesh( m_voxel01 ); + b3DestroyMesh( m_voxel02 ); b3DestroyHeightField( m_heightField ); } @@ -2888,8 +1586,7 @@ public: if ( desiredDist > 0.01f ) { b3QueryFilter filter = b3DefaultQueryFilter(); - b3RayResult rayResult = - b3World_CastRayClosest( m_worldId, charPos, translation, filter ); + b3RayResult rayResult = b3World_CastRayClosest( m_worldId, charPos, translation, filter ); if ( rayResult.hit ) { @@ -2921,8 +1618,7 @@ public: DrawTextLine( "Rigid Body Character (s&box-style)" ); DrawTextLine( "position: %.2f %.2f %.2f", pos.x, pos.y, pos.z ); DrawTextLine( "velocity: %.2f %.2f %.2f (horizontal: %.2f)", vel.x, vel.y, vel.z, speed ); - DrawTextLine( "on ground: %s | sprint: %s", m_character.m_onGround ? "yes" : "no", - m_character.m_sprint ? "yes" : "no" ); + DrawTextLine( "on ground: %s | sprint: %s", m_character.m_onGround ? "yes" : "no", m_character.m_sprint ? "yes" : "no" ); DrawTextLine( "WASD=move Space=jump Shift=sprint T=camera V=debug" ); } @@ -2972,5 +1668,4 @@ public: bool m_showDebug; }; -static int sampleRBCharacter = - RegisterSample( "Character", "Rigid Body", RigidBodyCharacter::Create ); +static int sampleRBCharacter = RegisterSample( "Character", "Rigid Body", RigidBodyCharacter::Create ); diff --git a/samples/sample_collision.cpp b/samples/sample_collision.cpp index 6251cd2..34f1390 100644 --- a/samples/sample_collision.cpp +++ b/samples/sample_collision.cpp @@ -735,7 +735,7 @@ public: for ( int i = 0; i < m_castContext.count; ++i ) { - DrawTextLine( "material = %d, triangle = %d", (int)m_castContext.materialIds[i], m_castContext.triangleIndices[i] ); + DrawTextLine( "material = %d, triangle = %d", m_castContext.materialIds[i], m_castContext.triangleIndices[i] ); } DrawGroundGrid( 10 ); @@ -1790,99 +1790,6 @@ public: static int sampleShapeCastDebug = RegisterSample( "Collision", "Shape Cast Debug", ShapeCastDebug::Create ); -// Box resting a few millimeters above a ground box, inside the cast target distance. -// With encroach enabled the box can be cast away from the surface. Without it the -// cast reports an initial overlap and the box is stuck. -class EncroachCast : public Sample -{ -public: - explicit EncroachCast( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 120.0f, 25.0f, 8.0f, { 0.0f, 0.5f, 0.0f } ); - } - - m_ground = b3MakeTransformedBoxHull( 3.0f, 0.25f, 3.0f, { { 0.0f, -0.25f, 0.0f }, b3Quat_identity } ); - m_box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - m_gap = 4.0f; - m_angle = 0.5f; - m_distance = 2.0f; - m_canEncroach = true; - } - - bool HasSolverControls() const override - { - return false; - } - - bool DrawControls() override - { - ImGui::Checkbox( "Can Encroach", &m_canEncroach ); - ImGui::PushItemWidth( 12.0f * ImGui::GetFontSize() ); - ImGui::SliderFloat( "Gap (mm)", &m_gap, 0.0f, 20.0f, "%.1f" ); - ImGui::SliderFloat( "Angle", &m_angle, -5.0f, 5.0f, "%.1f deg" ); - ImGui::SliderFloat( "Distance", &m_distance, 0.0f, 4.0f, "%.1f" ); - ImGui::PopItemWidth(); - return true; - } - - void Render() override - { - Sample::Render(); - - DrawGroundGrid( 20 ); - - b3Transform transform = { { 0.0f, 0.5f + 0.001f * m_gap, 0.0f }, b3Quat_identity }; - float radians = m_angle * B3_DEG_TO_RAD; - b3Vec3 translation = m_distance * b3Vec3{ cosf( radians ), sinf( radians ), 0.0f }; - - b3ShapeCastPairInput input = {}; - input.proxyA = { m_ground.boxPoints, m_ground.base.vertexCount, 0.0f }; - input.proxyB = { m_box.boxPoints, m_box.base.vertexCount, 0.0f }; - input.transform = transform; - input.translationB = translation; - input.maxFraction = 1.0f; - input.canEncroach = m_canEncroach; - - b3CastOutput output = b3ShapeCast( &input ); - - DrawHull( b3WorldTransform_identity, &m_ground.base, MakeColor( b3_colorSteelBlue ) ); - DrawHull( b3MakeWorldTransform( transform ), &m_box.base, MakeColor( b3_colorGreen ) ); - - float fraction = output.hit ? output.fraction : 1.0f; - b3Transform end = { transform.p + fraction * translation, transform.q }; - DrawHull( b3MakeWorldTransform( end ), &m_box.base, MakeColor( output.hit ? b3_colorRed : b3_colorGray ) ); - DrawLine( b3ToPos( transform.p ), b3ToPos( transform.p + translation ), MakeColor( b3_colorWhite ) ); - - if ( output.hit ) - { - b3Pos p = b3ToPos( output.point ); - DrawPoint( p, 8.0f, MakeColor( b3_colorRed ) ); - DrawLine( p, b3OffsetPos( p, 0.5f * output.normal ), MakeColor( b3_colorYellow ) ); - } - - DrawTextLine( "hit = %s, fraction = %.3f, iterations = %d", output.hit ? "true" : "false", output.fraction, - output.iterations ); - DrawTextLine( "Encroach applies to gaps up to %.2f mm", 1250.0f * B3_LINEAR_SLOP ); - } - - static Sample* Create( SampleContext* context ) - { - return new EncroachCast( context ); - } - - b3BoxHull m_ground; - b3BoxHull m_box; - float m_gap; - float m_angle; - float m_distance; - bool m_canEncroach; -}; - -static int sampleEncroachCast = RegisterSample( "Collision", "Encroach Cast", EncroachCast::Create ); - class DistanceDebug : public Sample { public: @@ -2460,9 +2367,9 @@ public: float length = b3Length( d ); assert( b3AbsFloat( length - output.distance ) < 10.0f * FLT_EPSILON ); b3Vec3 n = b3Normalize( d ); - assert( b3AbsFloat( n.x - output.normal.x ) < 0.0001f ); - assert( b3AbsFloat( n.y - output.normal.y ) < 0.0001f ); - assert( b3AbsFloat( n.z - output.normal.z ) < 0.0001f ); + assert( b3AbsFloat( n.x - output.normal.x ) < 100.0f * FLT_EPSILON ); + assert( b3AbsFloat( n.y - output.normal.y ) < 100.0f * FLT_EPSILON ); + assert( b3AbsFloat( n.z - output.normal.z ) < 100.0f * FLT_EPSILON ); } m_simplexCount = output.simplexCount; @@ -2889,247 +2796,3 @@ public: }; static int sampleCapsuleCastRay = RegisterSample( "Collision", "Capsule Cast Ray", CapsuleCastRay::Create ); - -// The 2D manifold point reduction that runs when B3_MAX_MANIFOLD_POINTS is more than 4. -// Cyan is the convex hull and yellow the simplified version. -class Hull2D : public Sample -{ -public: - enum SourceMode - { - e_random = 0, - e_circle = 1, - e_sliver = 2, - e_grid = 3, - }; - - static Sample* Create( SampleContext* context ) - { - return new Hull2D( context ); - } - - explicit Hull2D( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 0.0f, 20.0f, b3Pos_zero ); - } - - m_sourceMode = e_random; - m_inputCount = 0; - m_hullCount = 0; - m_simplifiedCount = 0; - m_targetCount = 6; - m_pointCount = 20; - m_drawScale = 1.0f; - m_drawLabels = true; - m_hullFlags = 0; - - Generate(); - } - - void Generate() - { - if ( m_sourceMode == e_random ) - { - m_drawScale = 1.0f; - m_inputCount = m_pointCount; - - for ( int i = 0; i < m_inputCount; ++i ) - { - m_inputPoints[i].p = { RandomFloatRange( -5.0f, 5.0f ), RandomFloatRange( -5.0f, 5.0f ) }; - m_inputPoints[i].separation = 0.0f; - m_inputPoints[i].originalIndex = i; - } - } - else if ( m_sourceMode == e_circle ) - { - // Every vertex of a regular polygon contributes the same area, so this is the case - // where the simplification has nothing but its pecking order to break ties with. - // libm rather than b3ComputeCosSin, whose rational approximation is coarse enough - // to make the areas unequal and hide that. - m_drawScale = 1.0f; - m_inputCount = m_pointCount; - - float radius = 5.0f; - float delta = 2.0f * B3_PI / (float)m_inputCount; - - for ( int i = 0; i < m_inputCount; ++i ) - { - float angle = delta * (float)i; - m_inputPoints[i].p = { radius * cosf( angle ), radius * sinf( angle ) }; - m_inputPoints[i].separation = 0.0f; - m_inputPoints[i].originalIndex = i; - } - } - else if ( m_sourceMode == e_grid ) - { - // Every border point is collinear with its neighbors, so the hull keeps them only with - // the collinear flag - m_drawScale = 1.0f; - m_inputCount = 36; - - for ( int i = 0; i < m_inputCount; ++i ) - { - m_inputPoints[i].p = { -5.0f + 2.0f * (float)( i % 6 ), -5.0f + 2.0f * (float)( i / 6 ) }; - m_inputPoints[i].separation = 0.0f; - m_inputPoints[i].originalIndex = i; - } - } - else - { - // A near degenerate sliver with a duplicate pair. Welding and collinear removal have - // to survive this without producing a zero area hull. - b3Vec2 points[] = { - { 0.0f, 0.0f }, - { -0.00305632968f, 0.0000554900616f }, - { -0.00305632968f, 0.0246563386f }, - { -0.00305632968f, 0.0246562902f }, - { -0.00305632968f, 0.0800221488f }, - }; - - m_drawScale = 50.0f; - m_inputCount = int( sizeof( points ) / sizeof( points[0] ) ); - - for ( int i = 0; i < m_inputCount; ++i ) - { - m_inputPoints[i].p = points[i]; - m_inputPoints[i].separation = 0.0f; - m_inputPoints[i].originalIndex = i; - } - } - - m_targetCount = b3ClampInt( m_targetCount, 3, m_inputCount ); - } - - void Step() override - { - m_targetCount = b3ClampInt( m_targetCount, 3, m_inputCount ); - - // b3Hull2D sorts and welds in place, so it needs a scratch copy of the input - b3Point2D scratch[m_pointCapacity]; - for ( int i = 0; i < m_inputCount; ++i ) - { - scratch[i] = m_inputPoints[i]; - } - - m_hullCount = b3Hull2D( scratch, m_inputCount, m_hullPoints, m_hullFlags ); - - for ( int i = 0; i < m_hullCount; ++i ) - { - m_simplifiedPoints[i] = m_hullPoints[i]; - } - - m_simplifiedCount = b3SimplifyHull2D( m_simplifiedPoints, m_hullCount, m_targetCount ); - } - - bool DrawControls() override - { - const char* modes[] = { "Random", "Circle", "Sliver", "Grid" }; - if ( ImGui::Combo( "Source", &m_sourceMode, modes, IM_ARRAYSIZE( modes ) ) ) - { - Generate(); - } - - if ( m_sourceMode == e_random || m_sourceMode == e_circle ) - { - if ( ImGui::SliderInt( "Point Count", &m_pointCount, 4, m_pointCapacity ) ) - { - Generate(); - } - } - - if ( m_sourceMode == e_random ) - { - if ( ImGui::Button( "Regenerate" ) ) - { - Generate(); - } - } - - ImGui::SliderInt( "Target Count", &m_targetCount, 3, m_inputCount ); - ImGui::CheckboxFlags( "Keep Collinear", &m_hullFlags, b3_hull2DKeepCollinear ); - ImGui::CheckboxFlags( "Exact Merge", &m_hullFlags, b3_hull2DExactMerge ); - ImGui::Checkbox( "Draw Labels", &m_drawLabels ); - - return true; - } - - void Render() override - { - Sample::Render(); - - DrawTextLine( "input = %d, hull = %d, simplified = %d", m_inputCount, m_hullCount, m_simplifiedCount ); - - DrawAxes( b3WorldTransform_identity, 0.4f ); - - bool onHull[m_pointCapacity] = {}; - for ( int i = 0; i < m_hullCount; ++i ) - { - onHull[m_hullPoints[i].originalIndex] = true; - } - - for ( int i = 0; i < m_inputCount; ++i ) - { - if ( onHull[i] ) - { - continue; - } - - b3Pos p = ToWorld( m_inputPoints[i].p, 0.0f ); - DrawPoint( p, 4.0f, MakeColor( b3_colorGray ) ); - - if ( m_drawLabels ) - { - DrawString3D( p, MakeColor( b3_colorGray ), " %d", i ); - } - } - - for ( int i = 0; i < m_hullCount; ++i ) - { - int next = ( i + 1 ) % m_hullCount; - b3Pos p1 = ToWorld( m_hullPoints[i].p, 0.0f ); - b3Pos p2 = ToWorld( m_hullPoints[next].p, 0.0f ); - DrawLine( p1, p2, MakeColor( b3_colorCyan ) ); - DrawPoint( p1, 6.0f, MakeColor( b3_colorCyan ) ); - - if ( m_drawLabels ) - { - DrawString3D( p1, MakeColor( b3_colorCyan ), " %d", m_hullPoints[i].originalIndex ); - } - } - - // Lifted so the survivors read on top of the hull they came from - for ( int i = 0; i < m_simplifiedCount; ++i ) - { - int next = ( i + 1 ) % m_simplifiedCount; - b3Pos p1 = ToWorld( m_simplifiedPoints[i].p, 0.01f ); - b3Pos p2 = ToWorld( m_simplifiedPoints[next].p, 0.01f ); - DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); - DrawPoint( p1, 10.0f, MakeColor( b3_colorYellow ) ); - } - } - - b3Pos ToWorld( b3Vec2 p, float z ) const - { - return b3Pos{ m_drawScale * p.x, m_drawScale * p.y, z }; - } - - static constexpr int m_pointCapacity = 64; - - b3Point2D m_inputPoints[m_pointCapacity]; - b3Point2D m_hullPoints[2 * m_pointCapacity]; - b3Point2D m_simplifiedPoints[2 * m_pointCapacity]; - float m_drawScale; - int m_sourceMode; - int m_inputCount; - int m_hullCount; - int m_simplifiedCount; - int m_targetCount; - int m_pointCount; - int m_hullFlags; - bool m_drawLabels; -}; - -static int sampleHull2D = RegisterSample( "Collision", "Hull 2D", Hull2D::Create ); diff --git a/samples/sample_compound.cpp b/samples/sample_compound.cpp index 0faeee0..126c3d1 100644 --- a/samples/sample_compound.cpp +++ b/samples/sample_compound.cpp @@ -1,8 +1,6 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "geometric_mover.h" -#include "gfx/debug_adapter.h" #include "gfx/draw.h" #include "human.h" #include "mesh_loader.h" @@ -13,8 +11,6 @@ #include -#include - class SimpleCompound : public Sample { public: @@ -54,7 +50,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); } b3World_SetContactRecycleDistance( m_worldId, 0.0f ); @@ -95,7 +91,7 @@ public: b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; DrawAxes( b3MakeWorldTransform( transform ), 1.0f ); - int height = m_compound->treeHeight; + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); } @@ -141,7 +137,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); } ~CompoundSpheres() override @@ -155,7 +151,7 @@ public: b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; DrawAxes( b3MakeWorldTransform( transform ), 1.0f ); - int height = m_compound->treeHeight; + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); } @@ -215,7 +211,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); } ~CompoundHulls() override @@ -229,7 +225,7 @@ public: b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; DrawAxes( b3MakeWorldTransform( transform ), 1.0f ); - int height = m_compound->treeHeight; + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree height = %d", height ); } @@ -300,7 +296,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); delete[] hulls; hulls = nullptr; @@ -347,8 +343,8 @@ public: DrawTextLine( "compound hull count = %d, mesh count = %d", m_compound->hullCount, m_compound->meshCount ); DrawTextLine( "compound byte count = %d", m_compound->byteCount ); - int treeBytes = m_compound->nodeCount * (int)sizeof( b3TreeNode ); - int height = m_compound->treeHeight; + int treeBytes = b3DynamicTree_GetByteCount( &m_compound->tree ); + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree byte count = %d, height = %d", treeBytes, height ); } @@ -423,7 +419,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); } #if 0 @@ -463,8 +459,8 @@ public: DrawTextLine( "compound instance count = %d, byte count = %d", m_compound->meshCount, m_compound->byteCount ); - int treeBytes = m_compound->nodeCount * (int)sizeof( b3TreeNode ); - int height = m_compound->treeHeight; + int treeBytes = b3DynamicTree_GetByteCount( &m_compound->tree ); + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree byte count = %d, height = %d", treeBytes, height ); } @@ -486,39 +482,6 @@ static bool OverlapResultFcn( b3ShapeId shapeId, void* context ) return false; } -struct VillageBoxQuery -{ - b3AABB aabb; - int shapeCount; - int childCount; -}; - -static bool CountCompoundChildFcn( const b3CompoundData* compound, int childIndex, void* context ) -{ - (void)compound; - (void)childIndex; - int* count = (int*)context; - *count += 1; - return true; -} - -// The world query only reaches the compound as a whole, so descend into its children like a game would -static bool VillageBoxQueryFcn( b3ShapeId shapeId, void* context ) -{ - VillageBoxQuery* query = (VillageBoxQuery*)context; - query->shapeCount += 1; - - if ( b3Shape_GetType( shapeId ) == b3_compoundShape ) - { - b3WorldTransform bodyTransform = b3Body_GetTransform( b3Shape_GetBody( shapeId ) ); - b3Transform worldToLocal = b3InvMulWorldTransforms( bodyTransform, b3WorldTransform_identity ); - b3AABB localBox = b3AABB_Transform( worldToLocal, query->aabb ); - b3QueryCompound( b3Shape_GetCompound( shapeId ), localBox, CountCompoundChildFcn, &query->childCount ); - } - - return true; -} - class Village : public Sample { public: @@ -536,9 +499,7 @@ public: } m_launchSpeedScale = 2.0f; - GeometricMoverDef moverDef; - moverDef.position = position; - m_mover.Create( m_worldId, &moverDef ); + m_mover.Initialize( this, position ); { constexpr int capsuleCapacity = gridCount * gridCount / 8 + 1; @@ -582,7 +543,6 @@ public: assert( capsuleIndex < capsuleCapacity ); capsules[capsuleIndex].capsule = { p1, p2, radius }; capsules[capsuleIndex].material = material; - capsules[capsuleIndex].material.userMaterialId = 1; capsuleIndex += 1; } else @@ -590,7 +550,6 @@ public: assert( sphereIndex < capsuleCapacity ); spheres[sphereIndex].sphere = { p1, radius }; spheres[sphereIndex].material = material; - spheres[sphereIndex].material.userMaterialId = 2; sphereIndex += 1; } } @@ -598,7 +557,6 @@ public: hulls[hullIndex].hull = &box.base; hulls[hullIndex].transform = transform; hulls[hullIndex].material = material; - hulls[hullIndex].material.userMaterialId = 3; hullIndex += 1; } @@ -614,11 +572,9 @@ public: constexpr int materialCapacity = 5; b3SurfaceMaterial meshMaterials[materialCapacity]; - - // Without the building mesh the village still stands, just with no buildings b3MeshData* buildingMesh = CreateMeshData( "data/meshes/building.obj", 1.0f, false, false, true, true ); - int materialCount = buildingMesh != nullptr ? buildingMesh->materialCount : 0; + int materialCount = buildingMesh->materialCount; assert( materialCount <= materialCapacity ); for ( int i = 0; i < materialCount; ++i ) @@ -635,11 +591,11 @@ public: meshMaterials[i].userMaterialId = i + 42; } - b3CompoundMeshDef* meshes = buildingMesh != nullptr ? new b3CompoundMeshDef[meshCount] : nullptr; + b3CompoundMeshDef* meshes = new b3CompoundMeshDef[meshCount]; transform = b3Transform_identity; int meshIndex = 0; - for ( int i = 0; meshes != nullptr && i < meshGridCount; ++i ) + for ( int i = 0; i < meshGridCount; ++i ) { transform.p.x = ( 2.0f * i - meshGridCount ) * b + 0.5f * b; @@ -672,7 +628,7 @@ public: } } - assert( meshes == nullptr || meshIndex == meshCount ); + assert( meshIndex == meshCount ); b3CompoundDef def = {}; def.capsules = capsules; @@ -681,7 +637,7 @@ public: def.hulls = hulls; def.hullCount = hullCount; def.meshes = meshes; - def.meshCount = meshIndex; + def.meshCount = meshCount; def.spheres = spheres; def.sphereCount = sphereIndex; @@ -693,7 +649,7 @@ public: b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - (void)b3CreateBakedCompoundShape( groundId, &shapeDef, m_compound ); + (void)b3CreateCompoundShape( groundId, &shapeDef, m_compound ); delete[] capsules; capsules = nullptr; @@ -707,7 +663,7 @@ public: delete[] spheres; spheres = nullptr; - DestroyMeshData( buildingMesh ); + b3DestroyMesh( buildingMesh ); } m_rayOrigin = { -0.45f * m_worldWidth, 20.0f, -0.45f * m_worldWidth }; @@ -726,136 +682,27 @@ public: } } - // Fixed seed so timings compare across runs and builds - void CreateStressQueries() - { - uint32_t savedSeed = g_randomSeed; - g_randomSeed = 271828; - - float h = 0.45f * m_worldWidth; - - m_stressRays.resize( m_stressRayCount ); - for ( StressRay& ray : m_stressRays ) - { - ray.origin = { RandomFloatRange( -h, h ), 20.0f, RandomFloatRange( -h, h ) }; - ray.translation = { RandomFloatRange( -10.0f, 10.0f ), -40.0f, RandomFloatRange( -10.0f, 10.0f ) }; - } - - m_stressBoxes.resize( m_stressBoxCount ); - for ( b3AABB& box : m_stressBoxes ) - { - b3Vec3 center = { RandomFloatRange( -h, h ), RandomFloatRange( 0.0f, 8.0f ), RandomFloatRange( -h, h ) }; - b3Vec3 extents = RandomVec3( { 0.5f, 0.5f, 0.5f }, { 4.0f, 4.0f, 4.0f } ); - box = { center - extents, center + extents }; - } - - g_randomSeed = savedSeed; - } - - void RunStressQueries() - { - b3QueryFilter filter = b3DefaultQueryFilter(); - - uint64_t ticks = b3GetTicks(); - - int rayHitCount = 0; - for ( const StressRay& ray : m_stressRays ) - { - CastClosestContext context = {}; - (void)b3World_CastRay( m_worldId, ray.origin, ray.translation, filter, CastClosestCallback, &context ); - rayHitCount += context.hit ? 1 : 0; - } - - float rayTime = b3GetMillisecondsAndReset( &ticks ); - - VillageBoxQuery query = {}; - for ( b3AABB box : m_stressBoxes ) - { - query.aabb = box; - (void)b3World_OverlapAABB( m_worldId, box, filter, VillageBoxQueryFcn, &query ); - } - - float boxTime = b3GetMilliseconds( ticks ); - - int rayCount = (int)m_stressRays.size(); - int boxCount = (int)m_stressBoxes.size(); - - DrawTextLine( "rays = %d, hits = %d", rayCount, rayHitCount ); - DrawTextLine( "ray time = %.3f ms, ave = %.3f us", rayTime, 1000.0f * rayTime / rayCount ); - DrawTextLine( "aabb queries = %d, shapes = %d, children = %d", boxCount, query.shapeCount, query.childCount ); - DrawTextLine( "aabb time = %.3f ms, ave = %.3f us", boxTime, 1000.0f * boxTime / boxCount ); - } - - bool DrawControls() override - { - bool changed = ImGui::Checkbox( "Query Stress", &m_stressQueries ); - changed = ImGui::SliderInt( "Rays", &m_stressRayCount, 1, 100000 ) || changed; - changed = ImGui::SliderInt( "AABB Queries", &m_stressBoxCount, 1, 100000 ) || changed; - - if ( changed && m_stressQueries ) - { - CreateStressQueries(); - } - - return true; - } - void Render() override { Sample::Render(); b3Transform transform = { { 0.0f, 0.01f, 0.0f }, b3Quat_identity }; DrawAxes( b3MakeWorldTransform( transform ), 4.0f ); - DrawTextLine( "surface type = %d", (int)m_userMaterialId ); + DrawTextLine( "surface type = %d", m_userMaterialId ); DrawTextLine( "compound capsules/hulls/meshes/sphere = %d / %d / %d / %d", m_compound->capsuleCount, m_compound->hullCount, m_compound->meshCount, m_compound->sphereCount ); DrawTextLine( "compound byte count = %d", m_compound->byteCount ); - int treeBytes = m_compound->nodeCount * (int)sizeof( b3TreeNode ); - int height = m_compound->treeHeight; + int treeBytes = b3DynamicTree_GetByteCount( &m_compound->tree ); + int height = b3DynamicTree_GetHeight( &m_compound->tree ); DrawTextLine( "compound tree byte count = %d, height = %d", treeBytes, height ); - - int total = 0; - int drawn = GetLastCompoundDrawStats( &total ); - DrawTextLine( "compound children drawn = %d / %d", drawn, total ); } void Step() override { - MoverInput input = GetMoverInput(); - if ( input.jump ) - { - m_mover.Jump(); - } - - float speedScale = 1.0f; - if ( input.walk ) - { - speedScale = 0.25f; - } - else if ( m_mover.m_onGround && input.sprint ) - { - speedScale = 1.5f; - } - float moverTimeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - m_mover.Update( moverTimeStep, input.forward, input.right, input.throttle, speedScale ); - - if ( m_camera->m_thirdPerson ) - { - m_camera->m_pivot = m_mover.m_position; - m_camera->UpdateTransform(); - } - - SetDrawOrigin( m_camera->DrawOrigin() ); - m_mover.Draw(); - + m_mover.Step( nullptr, 0, true ); DrawTextLine( "third person (T) = %d", m_camera->m_thirdPerson ); - if ( m_stressQueries ) - { - RunStressQueries(); - } - b3Vec3 translation = { 10.0f, -40.0f, -5.0f }; b3QueryFilter filter = b3DefaultQueryFilter(); @@ -871,7 +718,7 @@ public: DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); DrawPoint( p1, 8.0f, MakeColor( b3_colorLightCoral ) ); DrawTextLine( "ray hit triangle/child/material = %d / %d / %d", context.triangleIndex, context.childIndex, - (int)context.materialId ); + context.materialId ); } else { @@ -896,7 +743,7 @@ public: b3Sphere sphere = { b3Vec3_zero, 0.25f }; DrawSolidSphere( { position, b3Quat_identity }, sphere, MakeColor( b3_colorOrchid ) ); DrawTextLine( "shape hit triangle/child/material = %d / %d / %d", context.triangleIndex, context.childIndex, - (int)context.materialId ); + context.materialId ); } else { @@ -942,22 +789,10 @@ public: return new Village( context ); } - struct StressRay - { - b3Pos origin; - b3Vec3 translation; - }; - b3CompoundData* m_compound; - GeometricMover m_mover; + CharacterMover m_mover; float m_worldWidth; b3Pos m_rayOrigin; - - std::vector m_stressRays; - std::vector m_stressBoxes; - int m_stressRayCount = 1000; - int m_stressBoxCount = 1000; - bool m_stressQueries = false; }; static int sampleVillage = RegisterSample( "Compound", "Village", Village::Create ); diff --git a/samples/sample_continuous.cpp b/samples/sample_continuous.cpp index 770e6f2..9592877 100644 --- a/samples/sample_continuous.cpp +++ b/samples/sample_continuous.cpp @@ -1,13 +1,14 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "gfx/debug_adapter.h" -#include "gfx/draw.h" #include "imgui.h" -#include "mesh_drop.h" #include "sample.h" +#include "gfx/draw.h" +#include "stability.h" #include "utils.h" +#include "gfx/debug_adapter.h" + #include "box3d/box3d.h" #include @@ -388,37 +389,61 @@ public: static int sampleNeedleMesh = RegisterSample( "Continuous", "Needle Mesh", NeedleMesh::Create ); -// The rough wave has bumps smaller than the bodies, so a mesh contact reaches the manifold cap. Registered -// a second time as Rough Mesh Drop with that wave on. +struct IndexPair +{ + int index1; + int index2; +}; + +static inline IndexPair ConvertToPair( void* userData ) +{ + static_assert( sizeof( intptr_t ) >= 8 && sizeof( int ) == 4 ); + intptr_t value = (intptr_t)userData; + int index1 = (int)value; + int index2 = (int)( value >> 32 ); + return { index1, index2 }; +} + +static inline void* ConvertToUserData( IndexPair pair ) +{ + intptr_t value = (intptr_t)pair.index2 << 32 | (intptr_t)pair.index1; + return (void*)value; +} + class MeshDrop : public Sample { public: - MeshDrop( SampleContext* context, bool rough ) + enum ShapeType + { + e_box, + e_capsule, + e_cylinder, + e_sphere, + }; + + explicit MeshDrop( SampleContext* context ) : Sample( context ) { if ( context->restart == false ) { - m_camera->SetView( 0.0f, 30.0f, rough ? 12.0f : 20.0f, b3Pos_zero ); + m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Pos_zero ); GetGuiDraw()->forceScale = 0.1f; } - m_settings = GetDefaultMeshDropSettings(); - m_settings.rough = rough; - m_settings.amplitude = GetMeshDropDefaultAmplitude( rough ); m_groundId = b3_nullBodyId; m_groundMesh = nullptr; + m_groundAmplitude = 0.5f; CreateGround(); - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) - { - m_bodies[i] = b3_nullBodyId; - } + m_bodies = new b3BodyId[m_bodyCount]; + memset( m_bodies, 0, m_bodyCount * sizeof( b3BodyId ) ); - m_cylinder = CreateMeshDropCylinder(); - m_seed = 0; + m_cylinder = b3CreateCylinder( 0.4f, 0.05f, 0.0f, 6 ); + m_shapeType = e_box; m_runCount = 0; m_failure = false; m_autoGenerate = false; + m_stepWhilePaused = true; Generate(); @@ -426,6 +451,7 @@ public: ~MeshDrop() override { + delete[] m_bodies; b3DestroyHull( m_cylinder ); b3DestroyMesh( m_groundMesh ); } @@ -444,13 +470,58 @@ public: m_groundMesh = nullptr; } - m_groundMesh = CreateMeshDropMesh( m_settings ); - m_groundId = CreateMeshDropGround( m_worldId, m_groundMesh, m_settings ); + b3BodyDef bodyDef = b3DefaultBodyDef(); + m_groundId = b3CreateBody( m_worldId, &bodyDef ); + + int gridCount = 40; + float cellWidth = 1.0f; + float rowHz = 0.1f; + float columnHz = 0.2f; + + m_groundMesh = b3CreateWaveMesh( gridCount, gridCount, cellWidth, m_groundAmplitude, rowHz, columnHz ); + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.filter.categoryBits = 1; + b3CreateMeshShape( m_groundId, &shapeDef, m_groundMesh, b3Vec3_one ); + + float extent = 0.5f * gridCount * cellWidth; + float halfHeight = 1.0f; + + { + b3Transform transform; + transform.p = { 0.0f, halfHeight, -extent }; + transform.q = b3Quat_identity; + b3BoxHull wallBox = b3MakeTransformedBoxHull( extent, halfHeight, 0.1f, transform ); + b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base ); + } + + { + b3Transform transform; + transform.p = { 0.0f, halfHeight, extent }; + transform.q = b3Quat_identity; + b3BoxHull wallBox = b3MakeTransformedBoxHull( extent, halfHeight, 0.1f, transform ); + b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base ); + } + + { + b3Transform transform; + transform.p = { -extent, halfHeight, 0.0f }; + transform.q = b3Quat_identity; + b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, halfHeight, extent, transform ); + b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base ); + } + + { + b3Transform transform; + transform.p = { extent, halfHeight, 0.0f }; + transform.q = b3Quat_identity; + b3BoxHull wallBox = b3MakeTransformedBoxHull( 0.1f, halfHeight, extent, transform ); + b3CreateHullShape( m_groundId, &shapeDef, &wallBox.base ); + } } void Generate() { - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) + for ( int i = 0; i < m_bodyCount; ++i ) { if ( B3_IS_NULL( m_bodies[i] ) ) { @@ -461,63 +532,99 @@ public: m_bodies[i] = b3_nullBodyId; } - // A non-zero seed replays a generation reported by the mesh_soak tool - m_seed = m_replaySeed != 0 ? m_replaySeed : (uint32_t)b3GetTicks(); + // The soft contact solver cannot always resolve this small shape at 4 sub-steps. + // Also this small shape has trouble moving advancing in the time of impact code + // because the size is very close to the tolerances used. + // b3BoxHull box = b3MakeBoxHull( 0.01f, 0.1f, 0.02f ); + b3BoxHull box = b3MakeBoxHull( 0.02f, 0.2f, 0.04f ); + b3Capsule capsule = { { 0.0f, -0.2f, 0.0f }, { 0.0f, 0.2f, 0.0f }, 0.05f }; + b3Sphere sphere = { b3Vec3_zero, 0.05f }; + + int bodyIndex = 0; + + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; + + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.baseMaterial.rollingResistance = m_shapeType == e_capsule ? 0.4f : 0.1f; + + // Don't allow shapes to collide with each other. This + // makes isolating failures easier. + shapeDef.filter.categoryBits = 2; + shapeDef.filter.maskBits = 1; + + g_randomSeed = (uint32_t)b3GetTicks(); + + bool simulateAll = true; + // g_randomSeed = 3963634789; m_runCount += 1; m_stepCount = 0; - printf( "run %d seed %u\n", m_runCount, m_seed ); + printf( "run %d seed %u\n", m_runCount, g_randomSeed ); - MeshDropSettings settings = m_settings; - if ( m_solo[0] >= 0 && m_solo[1] >= 0 ) + for ( int i = 0; i < m_gridCount; ++i ) { - settings.soloIndex = MESH_DROP_GRID_COUNT * m_solo[0] + m_solo[1]; + for ( int j = 0; j < m_gridCount; ++j ) + { + b3Vec3 linearVelocity = RandomVec3Uniform( -1.0f, 1.0f ); + b3Vec3 angularVelocity = RandomVec3Uniform( -5.0f, 5.0f ); + + if ( simulateAll || ( i == 5 && j == 4 ) ) + { + bodyDef.position = { 0.5f * ( i - 0.5f * m_gridCount ), 5.0f, 0.5f * ( j - 0.5f * m_gridCount ) }; + bodyDef.linearVelocity = linearVelocity; + bodyDef.angularVelocity = angularVelocity; + // bodyDef.angularDamping = 0.1f; + bodyDef.userData = ConvertToUserData( { i, j } ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + + if ( m_shapeType == e_box ) + { + b3CreateHullShape( bodyId, &shapeDef, &box.base ); + } + else if ( m_shapeType == e_capsule ) + { + b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); + } + else if ( m_shapeType == e_cylinder ) + { + b3CreateHullShape( bodyId, &shapeDef, m_cylinder ); + } + else + { + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + } + + m_bodies[bodyIndex] = bodyId; + } + else + { + m_bodies[bodyIndex] = b3_nullBodyId; + } + bodyIndex += 1; + } } - CreateMeshDropBodies( m_worldId, settings, m_seed, m_cylinder, m_bodies ); - ResetMeshDropDepth( &m_depth, settings, m_cylinder ); + assert( bodyIndex == m_bodyCount ); } bool DrawControls() override { - int shapeType = (int)m_settings.shape; - if ( ImGui::Combo( "Type", &shapeType, g_meshDropShapeNames, e_meshDropShapeCount ) ) + const char* shapeTypes[] = { "box", "capsule", "cylinder", "sphere" }; + int shapeType = (int)m_shapeType; + if ( ImGui::Combo( "Type", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ) ) { m_stepCount = 0; - m_settings.shape = MeshDropShape( shapeType ); + m_shapeType = ShapeType( shapeType ); Generate(); } - if ( ImGui::Checkbox( "Rough", &m_settings.rough ) ) - { - m_settings.amplitude = GetMeshDropDefaultAmplitude( m_settings.rough ); - CreateGround(); - Generate(); - } - - // The rough mesh is slow to build, so wait for the slider to settle - float maxAmplitude = m_settings.rough ? 0.05f : 1.0f; - bool amplitudeChanged = ImGui::SliderFloat( "Amplitude", &m_settings.amplitude, 0.0f, maxAmplitude, "%.3f" ); - if ( m_settings.rough ? ImGui::IsItemDeactivatedAfterEdit() : amplitudeChanged ) + if ( ImGui::SliderFloat( "Amplitude", &m_groundAmplitude, 0.0f, 1.0f ) ) { CreateGround(); Generate(); } - if ( ImGui::Checkbox( "Collide", &m_settings.collide ) ) - { - Generate(); - } - - ImGui::InputScalar( "Seed", ImGuiDataType_U32, &m_replaySeed ); - - // Drop only the body at these indices, -1 for all - if ( ImGui::InputInt2( "Solo", m_solo ) ) - { - m_solo[0] = b3ClampInt( m_solo[0], -1, MESH_DROP_GRID_COUNT - 1 ); - m_solo[1] = b3ClampInt( m_solo[1], -1, MESH_DROP_GRID_COUNT - 1 ); - } - if ( ImGui::Button( "Generate" ) ) { Generate(); @@ -534,14 +641,8 @@ public: void Step() override { - int stepCount = m_stepCount; Sample::Step(); - if ( m_stepCount != stepCount ) - { - UpdateMeshDropDepth( m_worldId, &m_depth ); - } - { PickRay pickRay = m_camera->BuildPickRay( m_context->mouseX, m_context->mouseY ); @@ -551,35 +652,13 @@ public: if ( result.hit ) { b3BodyId bodyId = b3Shape_GetBody( result.shapeId ); - int index = GetMeshDropBodyIndex( b3Body_GetUserData( bodyId ) ); - if ( index >= 0 ) - { - DrawTextLine( "indices: (%d, %d)", index / MESH_DROP_GRID_COUNT, index % MESH_DROP_GRID_COUNT ); - } + void* userData = b3Body_GetUserData( bodyId ); + IndexPair pair = ConvertToPair( userData ); + DrawTextLine( "indices: (%d, %d)\n", pair.index1, pair.index2 ); } } - DrawTextLine( "seed %u", m_seed ); - - // The last bucket is the cap, so it holds every contact that was reduced - b3Counters counters = b3World_GetCounters( m_worldId ); - int contactCount = 0; - for ( int i = 0; i < B3_MAX_MANIFOLDS; ++i ) - { - contactCount += counters.manifoldCounts[i]; - } - DrawTextLine( "contacts at the manifold cap: %d of %d", counters.manifoldCounts[B3_MAX_MANIFOLDS - 1], - contactCount ); - - if ( m_depth.maxIndex >= 0 ) - { - int index = m_depth.maxIndex; - DrawTextLine( "deepest: (%d, %d) %.1f slop at step %d", index / MESH_DROP_GRID_COUNT, - index % MESH_DROP_GRID_COUNT, m_depth.maxDepth / B3_LINEAR_SLOP, m_depth.maxStep ); - } - - float tunnelHeight = GetMeshDropTunnelHeight(); - for ( int i = 0; i < MESH_DROP_BODY_COUNT && m_failure == false; i += 1 ) + for ( int i = 0; i < m_bodyCount && m_failure == false; i += 1 ) { b3BodyId bodyId = m_bodies[i]; if ( B3_IS_NULL( bodyId ) ) @@ -587,15 +666,20 @@ public: continue; } - b3Pos massCenter = b3Body_GetWorldCenter( bodyId ); - if ( massCenter.y < tunnelHeight ) + b3Pos massCenter = b3Body_GetWorldCenterOfMass( bodyId ); + if ( massCenter.y < -2.0f ) { - printf( "index1: %d - index2: %d\n", i / MESH_DROP_GRID_COUNT, i % MESH_DROP_GRID_COUNT ); + IndexPair pair = ConvertToPair( b3Body_GetUserData( bodyId ) ); + printf( "index1: %d - index2: %d\n", pair.index1, pair.index2 ); printf( "(%6.2f, %6.2f, %6.2f)\n", massCenter.x, massCenter.y, massCenter.z ); m_context->pause = true; m_failure = true; m_autoGenerate = false; } + + // This is for debugging the fallback inner sphere + // b3Sphere sphere = {massCenter, 0.015f}; + // DrawSphere( m_scene, b3Transform_identity, sphere, b3_colorLightGray ); } if ( m_autoGenerate ) @@ -620,13 +704,13 @@ public: for ( int i = 0; i < n; ++i ) { b3World_Step( m_worldId, timeStep, m_context->subStepCount ); - UpdateMeshDropDepth( m_worldId, &m_depth ); } m_stepCount += n; } - if ( m_stepCount > GetMeshDropStepLimit( m_settings.shape ) ) + int maxSteps = m_shapeType == e_capsule ? 3000 : 1000; + if ( m_stepCount > maxSteps ) { m_context->pause = true; m_failure = true; @@ -637,30 +721,79 @@ public: static Sample* Create( SampleContext* context ) { - return new MeshDrop( context, false ); + return new MeshDrop( context ); } - static Sample* CreateRough( SampleContext* context ) - { - return new MeshDrop( context, true ); - } + static constexpr int m_gridCount = 32; + // static constexpr int m_gridCount = 3; + static constexpr int m_bodyCount = m_gridCount * m_gridCount; - MeshDropSettings m_settings; - MeshDropDepth m_depth; b3MeshData* m_groundMesh; + float m_groundAmplitude; b3BodyId m_groundId; b3HullData* m_cylinder; - b3BodyId m_bodies[MESH_DROP_BODY_COUNT]; - uint32_t m_seed; + b3BodyId* m_bodies; + ShapeType m_shapeType; int m_runCount; bool m_failure; bool m_autoGenerate; - uint32_t m_replaySeed = 0; - int m_solo[2] = { -1, -1 }; }; static int sampleMeshDrop = RegisterSample( "Continuous", "Mesh Drop", MeshDrop::Create ); -static int sampleRoughMeshDrop = RegisterSample( "Continuous", "Rough Mesh Drop", MeshDrop::CreateRough ); + +class MeshDropUnitTest : public Sample +{ +public: + explicit MeshDropUnitTest( SampleContext* context ) + : Sample( context ) + { + if ( context->restart == false ) + { + m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Pos_zero ); + GetGuiDraw()->forceScale = 0.1f; + } + + m_data = CreateMeshDrop( m_worldId, b3Pos_zero ); + m_failed = false; + } + + ~MeshDropUnitTest() override + { + DestroyMeshDrop( &m_data ); + } + + void Step() override + { + Sample::Step(); + + if ( m_failed == false ) + { + if ( m_stepCount >= 300 ) + { + b3BodyEvents bodyEvents = b3World_GetBodyEvents( m_worldId ); + if ( bodyEvents.moveCount > 0 ) + { + m_failed = true; + } + } + } + + if ( m_failed == true ) + { + DrawTextLine( "failed!" ); + } + } + + static Sample* Create( SampleContext* context ) + { + return new MeshDropUnitTest( context ); + } + + MeshDropData m_data; + bool m_failed; +}; + +static int sampleMeshDropUnitTest = RegisterSample( "Continuous", "Mesh Drop Unit Test", MeshDropUnitTest::Create ); // This sample shows that clustering based on the manifold normal can lead to clipping and/or tunneling. class HumpMesh : public Sample @@ -784,12 +917,13 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 15.0f, 0.0f } ); + } AddGroundBox( 40.0f ); b3BoxHull box = b3MakeBoxHull( 0.5f, 10.0f, 0.5f ); - b3Capsule capsule = { { 0.0f, -9.5f, 0.0f }, { 0.0f, 9.5f, 0.0f }, 0.5f }; + b3Capsule capsule = {{0.0f, -9.5f, 0.0f}, {0.0f, 9.5f, 0.0f}, 0.5f}; bool useCapsule = false; @@ -802,7 +936,7 @@ public: b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( useCapsule ) + if (useCapsule) { b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); } @@ -884,6 +1018,11 @@ public: b3CreateMeshShape( bodyId, &shapeDef, m_mesh, b3Vec3_one ); } + m_savedThreshold = b3GetStallThreshold(); + + // Log any CCD that takes longer than 1 ms. + b3SetStallThreshold( 0.001f ); + Launch(); } @@ -923,6 +1062,7 @@ public: ~Stall() override { b3DestroyMesh( m_mesh ); + b3SetStallThreshold( m_savedThreshold ); } static Sample* Create( SampleContext* context ) @@ -932,121 +1072,7 @@ public: b3MeshData* m_mesh = nullptr; b3BodyId m_bulletId = b3_nullBodyId; + float m_savedThreshold; }; static int sampleStall = RegisterSample( "Continuous", "Stall", Stall::Create ); - -// This shows how adjusting the CCD safety factor can engage continuous collision at -// lower speeds to avoid the slight overlap that happens with discrete collision detection. -// The best way to run this sample is: -// 1. press pause (P) -// 2. restart (R) or press the Drop button -// 3. then single step (.) -// Then look at the metrics and overlap. The shape is drawn orange while it is using -// continuous collision detection. -class SafetyFactor : public Sample -{ -public: - explicit SafetyFactor( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 3.0f, 8.0f, { 0.0f, 1.0f, 0.0f } ); - } - - AddGroundBox( 20.0f ); - - m_bodyId = b3_nullBodyId; - m_extent = 0.5f; - m_height = 0.3f; - m_safetyFactor = 0.1f; - m_overlap = 0.0f; - - Launch(); - } - - void Launch() - { - if ( B3_IS_NON_NULL( m_bodyId ) ) - { - b3DestroyBody( m_bodyId ); - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, m_height + m_extent, 0.0f }; - bodyDef.safetyFactor = m_safetyFactor; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( m_extent, m_extent, m_extent ); - b3CreateHullShape( m_bodyId, &shapeDef, &box.base ); - - m_overlap = 0.0f; - } - - void Step() override - { - Sample::Step(); - - if ( m_didStep ) - { - // Contacts are computed at the beginning of the step, so the manifold holds the initial separation. - b3ContactData data; - int count = b3Body_GetContactData( m_bodyId, &data, 1 ); - if ( count == 1 ) - { - for ( int i = 0; i < data.manifoldCount; ++i ) - { - const b3Manifold* manifold = data.manifolds + i; - for ( int j = 0; j < manifold->pointCount; ++j ) - { - m_overlap = b3MaxFloat( m_overlap, -manifold->points[j].separation ); - } - } - } - } - - // The overlap line sits below the ground surface, so dash it where the ground hides it - DrawLineEx( { -3.0f, -m_overlap, 0.0f }, { 3.0f, -m_overlap, 0.0f }, MakeColor( b3_colorRed ), - DEFAULT_LINE_THICKNESS_PX, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DASHED ); - - float timeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - float motion = timeStep * b3Length( b3Body_GetLinearVelocity( m_bodyId ) ); - - DrawTextLine( "actual movement = %.3f m", motion ); - DrawTextLine( "fast movement = %.3f m", m_safetyFactor * m_extent ); - DrawTextLine( "overlap = %.4f m", m_overlap ); - } - - bool DrawControls() override - { - bool changed = false; - - ImGui::PushItemWidth( 10.0f * ImGui::GetFontSize() ); - changed |= ImGui::SliderFloat( "Height", &m_height, 0.0f, 2.0f, "%.2f" ); - changed |= ImGui::SliderFloat( "Safety", &m_safetyFactor, 0.0f, 1.0f, "%.2f" ); - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Drop" ) || changed ) - { - Launch(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new SafetyFactor( context ); - } - - b3BodyId m_bodyId; - float m_extent; - float m_height; - float m_safetyFactor; - float m_overlap; -}; - -static int sampleSafetyFactor = RegisterSample( "Continuous", "Safety Factor", SafetyFactor::Create ); diff --git a/samples/sample_determinism.cpp b/samples/sample_determinism.cpp index 6370e86..98a850c 100644 --- a/samples/sample_determinism.cpp +++ b/samples/sample_determinism.cpp @@ -2,10 +2,7 @@ // SPDX-License-Identifier: MIT #include "determinism.h" -#include "gfx/debug_adapter.h" -#include "gfx/draw.h" #include "sample.h" -#include "stability.h" #include "box3d/box3d.h" @@ -35,7 +32,7 @@ public: { Sample::Step( ); - if ( m_done == false && (m_context->pause == false || m_context->singleStep > 0) ) + if ( m_done == false ) { m_done = UpdateFallingRagdolls( m_worldId, &m_data ); if (m_done) @@ -60,207 +57,3 @@ public: }; static int sampleFallingRagdolls = RegisterSample( "Determinism", "Falling Ragdolls", FallingRagdolls::Create ); - -class WavePile : public Sample -{ -public: - explicit WavePile( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 45.0f, 25.0f, 25.0f, b3Pos_zero ); - } - - m_data = CreateWavePile( m_worldId ); - m_done = false; - } - - ~WavePile() override - { - DestroyWavePile( &m_data ); - } - - void Step() override - { - Sample::Step(); - - if ( m_done == false ) - { - // Only advance the scenario on real steps, else pausing would skew the step count - if ( m_didStep ) - { - m_done = UpdateWavePile( m_worldId, &m_data ); - if ( m_done ) - { - printf( "sleep step = %d, hash = 0x%08X\n", m_data.sleepStep, m_data.hash ); - } - } - } - else - { - DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new WavePile( context ); - } - - WavePileData m_data; - bool m_done; -}; - -static int sampleWavePile = RegisterSample( "Determinism", "Wave Pile", WavePile::Create ); - -class QuerySpawn : public Sample -{ -public: - explicit QuerySpawn( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 45.0f, 25.0f, 30.0f, b3Pos_zero ); - } - - m_data = CreateQuerySpawn( m_worldId ); - m_frameCount = 0; - m_done = false; - } - - ~QuerySpawn() override - { - DestroyQuerySpawn( &m_data ); - } - - void Step() override - { - Sample::Step(); - - if ( m_done == false ) - { - // Advance every 10th step so each query lingers on screen. This diverges from - // the unit test cadence, so the hashes differ from the pinned constants. - if ( m_didStep ) - { - m_frameCount += 1; - if ( m_frameCount % 10 == 1 ) - { - m_done = UpdateQuerySpawn( m_worldId, &m_data ); - if ( m_done ) - { - printf( "sleep step = %d, hash = 0x%08X, hits = %d, query hash = 0x%08X\n", m_data.sleepStep, - m_data.hash, m_data.queryHitCount, m_data.queryHash ); - } - } - } - - DrawTextLine( "spawned = %d of %d, query hits = %d", m_data.spawnCount, QUERY_SPAWN_COUNT, m_data.queryHitCount ); - DrawTextLine( "ray = yellow, overlap box = magenta, sphere cast = cyan, spawn = white" ); - } - else - { - DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash ); - DrawTextLine( "query hits = %d, query hash = 0x%08X", m_data.queryHitCount, m_data.queryHash ); - } - } - - void Render() override - { - Sample::Render(); - - if ( m_data.spawnCount == 0 ) - { - return; - } - - // Ray with hit point and normal, red end point on a miss - DrawLine( m_data.rayOrigin, m_data.rayPoint, MakeColor( b3_colorYellow ) ); - DrawPoint( m_data.rayOrigin, 5.0f, MakeColor( b3_colorYellow ) ); - if ( m_data.rayDidHit ) - { - DrawPoint( m_data.rayPoint, 8.0f, MakeColor( b3_colorGreen ) ); - DrawLine( m_data.rayPoint, b3OffsetPos( m_data.rayPoint, m_data.rayNormal ), MakeColor( b3_colorGreen ) ); - } - else - { - DrawPoint( m_data.rayPoint, 5.0f, MakeColor( b3_colorRed ) ); - } - - DrawBounds( m_data.overlapBounds, 0.0f, MakeColor( b3_colorMagenta ) ); - - // Swept sphere stopped at its cast fraction, gray when it reached full length - b3Pos castCenter = b3OffsetPos( m_data.rayOrigin, b3MulSV( m_data.castFraction, m_data.rayTranslation ) ); - b3Sphere castSphere = { b3Vec3_zero, QUERY_SPAWN_CAST_RADIUS }; - Vec4 castColor = m_data.castFraction < 1.0f ? MakeColor( b3_colorCyan ) : MakeColor( b3_colorGray ); - DrawWireSphere( { castCenter, b3Quat_identity }, &castSphere, 24, castColor ); - - DrawCross( m_data.lastSpawnPosition, 0.5f, MakeColor( b3_colorWhite ) ); - } - - static Sample* Create( SampleContext* context ) - { - return new QuerySpawn( context ); - } - - QuerySpawnData m_data; - int m_frameCount; - bool m_done; -}; - -static int sampleQuerySpawn = RegisterSample( "Determinism", "Query Spawn", QuerySpawn::Create ); - -class MeshDropDeterminism : public Sample -{ -public: - explicit MeshDropDeterminism( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 30.0f, 20.0f, b3Pos_zero ); - GetGuiDraw()->forceScale = 0.1f; - } - - m_data = CreateMeshDrop( m_worldId, b3Pos_zero ); - m_done = false; - } - - ~MeshDropDeterminism() override - { - DestroyMeshDrop( &m_data ); - } - - void Step() override - { - Sample::Step(); - - if ( m_done == false ) - { - if ( m_didStep ) - { - m_done = UpdateMeshDrop( m_worldId, &m_data ); - if ( m_done ) - { - printf( "sleep step = %d, hash = 0x%08X\n", m_data.sleepStep, m_data.hash ); - } - } - } - else - { - DrawTextLine( "sleep step = %d, hash = 0x%08X", m_data.sleepStep, m_data.hash ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new MeshDropDeterminism( context ); - } - - MeshDropData m_data; - bool m_done; -}; - -static int sampleMeshDropDeterminism = RegisterSample( "Determinism", "Mesh Drop", MeshDropDeterminism::Create ); diff --git a/samples/sample_events.cpp b/samples/sample_events.cpp index db08b42..85b4cd2 100644 --- a/samples/sample_events.cpp +++ b/samples/sample_events.cpp @@ -1,12 +1,13 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "gfx/draw.h" -#include "gfx/keycodes.h" #include "imgui.h" #include "sample.h" +#include "gfx/draw.h" #include "utils.h" +#include "gfx/keycodes.h" + #include "box3d/box3d.h" #include @@ -159,7 +160,7 @@ public: { b3Body_ApplyMassFromShapes( bodyId ); - b3Pos center = b3Body_GetWorldCenter( bodyId ); + b3Pos center = b3Body_GetWorldCenterOfMass( bodyId ); b3Vec3 omega = { 0.0f, 0.0f, -1.0f * velocityScale }; b3Vec3 v = b3Cross( omega, b3SubPos( center, b3OffsetPos( b3Pos_zero, origin ) ) ); b3Body_SetAngularVelocity( bodyId, omega ); @@ -217,8 +218,7 @@ public: DrawPoint( p1, 10.0f, MakeColor( b3_colorYellow ) ); DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); - DrawString3D( p1, MakeColor( b3_colorWhite ), "%.1f, %d", m_events[i].approachSpeed, - (int)m_events[i].userMaterialIdA ); + DrawString3D( p1, MakeColor( b3_colorWhite ), "%.1f, %d", m_events[i].approachSpeed, m_events[i].userMaterialIdA ); } DrawTextLine( "event count = %d", m_eventCount ); @@ -253,6 +253,7 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); + } AddGroundBox( 40.0f ); @@ -271,7 +272,7 @@ public: b3BoxHull dynamicBox = b3MakeTransformedBoxHull( 0.5f, 10.0f, 0.5f, { { 0.0f, 10.0f, 0.0f }, b3Quat_identity } ); b3CreateHullShape( m_bodyId, &shapeDef, &dynamicBox.base ); - b3Pos center = b3Body_GetWorldCenter( m_bodyId ); + b3Pos center = b3Body_GetWorldCenterOfMass( m_bodyId ); b3Vec3 r = b3SubPos( pivot, center ); float rr = b3LengthSquared( r ); @@ -341,6 +342,7 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); + } AddGroundBox( 20.0f ); @@ -568,384 +570,6 @@ public: static int sampleJointEvent = RegisterSample( "Events", "Joint", JointEvent::Create ); -struct BodyUserData -{ - int index; -}; - -// This shows how to use contact events to transfer shapes from one body to another. -class ContactEvent : public Sample -{ -public: - enum - { - e_count = 200 - }; - - explicit ContactEvent( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 0.0f, 35.0f, 60.0f, b3Pos_zero ); - } - - m_groundExtent = 80.0f; - b3BodyId groundId = AddGroundBox( m_groundExtent ); - - // The walls live on their own body so a contact can be told apart from the floor. The player - // rides on the floor at all times, so treating every non-debris body as a wall would strip - // each pickup the moment it dragged along the ground. - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "walls"; - m_wallsId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - float extent = m_groundExtent + 0.5f; - float height = 5.0f; - float thickness = 0.5f; - - b3BoxHull wall = b3MakeTransformedBoxHull( thickness, height, extent, { { extent, height, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( m_wallsId, &shapeDef, &wall.base ); - - wall = b3MakeTransformedBoxHull( thickness, height, extent, { { -extent, height, 0.0f }, b3Quat_identity } ); - b3CreateHullShape( m_wallsId, &shapeDef, &wall.base ); - - wall = b3MakeTransformedBoxHull( extent, height, thickness, { { 0.0f, height, extent }, b3Quat_identity } ); - b3CreateHullShape( m_wallsId, &shapeDef, &wall.base ); - - wall = b3MakeTransformedBoxHull( extent, height, thickness, { { 0.0f, height, -extent }, b3Quat_identity } ); - b3CreateHullShape( m_wallsId, &shapeDef, &wall.base ); - } - - // Player - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.name = "player"; - bodyDef.position = { 0.0f, 1.0f, 0.0f }; - bodyDef.angularDamping = 0.1f; - bodyDef.enableSleep = false; - m_playerId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - // Contact events fire when either shape enables them, so opting in the player alone - // still reports every collision it has while debris hitting debris stays silent. - shapeDef.enableContactEvents = true; - - // Friction is what turns the drive torque into motion - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - shapeDef.baseMaterial.customColor = b3MakeDebugColor( b3_colorPlum, b3_debugMaterialMetallic ); - - b3Sphere sphere = { b3Vec3_zero, 1.0f }; - m_coreShapeId = b3CreateSphereShape( m_playerId, &shapeDef, &sphere ); - - m_torque = 30000.0f; - - b3MotorJointDef jointDef = b3DefaultMotorJointDef(); - jointDef.base.bodyIdA = groundId; - jointDef.base.bodyIdB = m_playerId; - jointDef.base.collideConnected = true; - jointDef.maxVelocityTorque = m_torque; - m_motorId = b3CreateMotorJoint( m_worldId, &jointDef ); - } - - for ( int i = 0; i < e_count; ++i ) - { - m_debrisIds[i] = b3_nullBodyId; - m_bodyUserData[i].index = i; - } - - b3AABB bounds = b3Body_ComputeAABB( m_playerId ); - b3Vec3 extents = b3AABB_Extents( bounds ); - float mass = b3Body_GetMass( m_playerId ); - m_massExtent = ( mass / 3.0f ) * ( extents.x + extents.y + extents.z ); - m_wait = 0.5f; - } - - void SpawnDebris() - { - int index = -1; - for ( int i = 0; i < e_count; ++i ) - { - if ( B3_IS_NULL( m_debrisIds[i] ) ) - { - index = i; - break; - } - } - - if ( index == -1 ) - { - return; - } - - float a = m_groundExtent - 2.0f; - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = RandomPos( { -a, 1.0f, -a }, { a, 6.0f, a } ); - bodyDef.rotation = RandomQuat(); - bodyDef.linearVelocity = RandomVec3Uniform( -2.0f, 2.0f ); - bodyDef.angularVelocity = RandomVec3Uniform( -1.0f, 1.0f ); - bodyDef.userData = m_bodyUserData + index; - m_debrisIds[index] = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.restitution = 0.3f; - - if ( ( index + 1 ) % 3 == 0 ) - { - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - b3CreateSphereShape( m_debrisIds[index], &shapeDef, &sphere ); - } - else if ( ( index + 1 ) % 2 == 0 ) - { - b3Capsule capsule = { { 0.0f, -0.25f, 0.0f }, { 0.0f, 0.25f, 0.0f }, 0.25f }; - b3CreateCapsuleShape( m_debrisIds[index], &shapeDef, &capsule ); - } - else - { - b3BoxHull box = b3MakeBoxHull( 0.4f, 0.6f, 0.5f ); - b3CreateHullShape( m_debrisIds[index], &shapeDef, &box.base ); - } - } - - // Rebuild a debris shape in the player frame and destroy the body it came from - void AttachDebris( int index ) - { - b3BodyId debrisId = m_debrisIds[index]; - if ( B3_IS_NULL( debrisId ) ) - { - return; - } - - b3WorldTransform playerTransform = b3Body_GetTransform( m_playerId ); - b3WorldTransform debrisTransform = b3Body_GetTransform( debrisId ); - b3Transform relativeTransform = b3InvMulWorldTransforms( playerTransform, debrisTransform ); - - b3ShapeId shapeId; - if ( b3Body_GetShapes( debrisId, &shapeId, 1 ) == 0 ) - { - return; - } - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.enableContactEvents = true; - shapeDef.baseMaterial.customColor = b3_colorGold; - - // Several shapes may land in one step, so take the mass update once at the end - shapeDef.updateBodyMass = false; - - switch ( b3Shape_GetType( shapeId ) ) - { - case b3_sphereShape: - { - b3Sphere sphere = b3Shape_GetSphere( shapeId ); - sphere.center = b3TransformPoint( relativeTransform, sphere.center ); - - b3CreateSphereShape( m_playerId, &shapeDef, &sphere ); - } - break; - - case b3_capsuleShape: - { - b3Capsule capsule = b3Shape_GetCapsule( shapeId ); - capsule.center1 = b3TransformPoint( relativeTransform, capsule.center1 ); - capsule.center2 = b3TransformPoint( relativeTransform, capsule.center2 ); - - b3CreateCapsuleShape( m_playerId, &shapeDef, &capsule ); - } - break; - - case b3_hullShape: - { - // The hull is cloned and baked, so the source body can go away right after - const b3HullData* hull = b3Shape_GetHull( shapeId ); - b3CreateTransformedHullShape( m_playerId, &shapeDef, hull, relativeTransform, b3Vec3_one ); - } - break; - - default: - assert( false ); - } - - b3DestroyBody( debrisId ); - m_debrisIds[index] = b3_nullBodyId; - } - - bool DrawControls() override - { - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - ImGui::SliderFloat( "torque", &m_torque, 0.0f, 60000.0f, "%.0f" ); - ImGui::PopItemWidth(); - - return true; - } - - void Step() override - { - // Drive relative to the camera so the controls hold up as the view orbits - b3Vec2 throttle = { 0.0f, 0.0f }; - - if ( IsKeyDown( KEY_W ) ) - { - throttle.x += 1.0f; - } - - if ( IsKeyDown( KEY_S ) ) - { - throttle.x -= 1.0f; - } - - if ( IsKeyDown( KEY_A ) ) - { - throttle.y -= 1.0f; - } - - if ( IsKeyDown( KEY_D ) ) - { - throttle.y += 1.0f; - } - - b3Vec3 forward = -m_camera->GetForward(); - forward.y = 0.0f; - forward = b3Normalize( forward ); - - b3Vec3 right = m_camera->GetRight(); - right.y = 0.0f; - right = b3Normalize( right ); - - b3Vec3 direction = throttle.x * forward + throttle.y * right; - if ( b3LengthSquared( direction ) > 0.0f ) - { - b3AABB bounds = b3Body_ComputeAABB( m_playerId ); - b3Vec3 extents = b3AABB_Extents( bounds ); - float mass = b3Body_GetMass( m_playerId ); - float massExtent = ( mass / 3.0f ) * ( extents.x + extents.y + extents.z ); - float scale = massExtent / m_massExtent; - - // Rolling without slipping spins about up cross velocity - b3Vec3 axis = b3Cross( b3Vec3_axisY, b3Normalize( direction ) ); - float speed = 5.0f; - b3MotorJoint_SetMaxVelocityTorque( m_motorId, scale * m_torque ); - b3MotorJoint_SetAngularVelocity( m_motorId, speed * axis ); - } - else - { - b3MotorJoint_SetAngularVelocity( m_motorId, b3Vec3_zero ); - - } - - Sample::Step(); - - int debrisToAttach[e_count] = {}; - b3ShapeId shapesToDestroy[e_count] = {}; - int attachCount = 0; - int destroyCount = 0; - - b3ContactEvents contactEvents = b3World_GetContactEvents( m_worldId ); - for ( int i = 0; i < contactEvents.beginCount; ++i ) - { - b3ContactBeginTouchEvent event = contactEvents.beginEvents[i]; - - b3ShapeId playerShapeId = event.shapeIdA; - b3ShapeId otherShapeId = event.shapeIdB; - if ( B3_ID_EQUALS( b3Shape_GetBody( playerShapeId ), m_playerId ) == false ) - { - playerShapeId = event.shapeIdB; - otherShapeId = event.shapeIdA; - } - - // Only the player enables contact events, so one side is always the player - assert( B3_ID_EQUALS( b3Shape_GetBody( playerShapeId ), m_playerId ) ); - - b3BodyId otherBodyId = b3Shape_GetBody( otherShapeId ); - BodyUserData* userData = static_cast( b3Body_GetUserData( otherBodyId ) ); - - if ( userData != nullptr ) - { - if ( attachCount < e_count ) - { - debrisToAttach[attachCount] = userData->index; - attachCount += 1; - } - } - else if ( B3_ID_EQUALS( otherBodyId, m_wallsId ) && B3_ID_EQUALS( playerShapeId, m_coreShapeId ) == false ) - { - // An accreted shape scraped a wall. The core is exempt or the player would dissolve. - bool found = false; - for ( int j = 0; j < destroyCount; ++j ) - { - if ( B3_ID_EQUALS( playerShapeId, shapesToDestroy[j] ) ) - { - found = true; - break; - } - } - - // Avoid double deletion - if ( found == false && destroyCount < e_count ) - { - shapesToDestroy[destroyCount] = playerShapeId; - destroyCount += 1; - } - } - } - - for ( int i = 0; i < attachCount; ++i ) - { - AttachDebris( debrisToAttach[i] ); - } - - for ( int i = 0; i < destroyCount; ++i ) - { - bool updateMass = false; - b3DestroyShape( shapesToDestroy[i], updateMass ); - } - - if ( attachCount > 0 || destroyCount > 0 ) - { - b3Body_ApplyMassFromShapes( m_playerId ); - } - - if ( m_context->hertz > 0.0f && m_context->pause == false ) - { - m_wait -= 1.0f / m_context->hertz; - if ( m_wait < 0.0f ) - { - SpawnDebris(); - m_wait += 0.5f; - } - } - - DrawTextLine( "move using WASD" ); - DrawTextLine( "player shape count = %d", b3Body_GetShapeCount( m_playerId ) ); - } - - static Sample* Create( SampleContext* context ) - { - return new ContactEvent( context ); - } - - static constexpr int m_capacity = 200; - b3BodyId m_playerId; - b3JointId m_motorId; - b3BodyId m_wallsId; - b3ShapeId m_coreShapeId; - b3BodyId m_debrisIds[m_capacity]; - BodyUserData m_bodyUserData[m_capacity]; - float m_groundExtent; - float m_massExtent; - float m_torque; - float m_wait; -}; - -static int sampleContactEvent = RegisterSample( "Events", "Contact", ContactEvent::Create ); - class PersistentContact : public Sample { public: @@ -1011,7 +635,7 @@ public: if ( B3_IS_NON_NULL( m_contactId ) && b3Contact_IsValid( m_contactId ) ) { b3ContactData data = b3Contact_GetData( m_contactId ); - b3Pos centerOfMass = b3Body_GetWorldCenter( b3Shape_GetBody( data.shapeIdA ) ); + b3Pos centerOfMass = b3Body_GetWorldCenterOfMass( b3Shape_GetBody( data.shapeIdA ) ); for ( int i = 0; i < data.manifoldCount; ++i ) { @@ -1055,6 +679,7 @@ public: if ( m_context->restart == false ) { m_camera->SetView( 0.0f, 30.0f, 40.0f, { 0.0f, 5.0f, 0.0f } ); + } AddGroundBox( 10.0f ); @@ -1197,7 +822,7 @@ public: { b3BodyId sensorBodyId = b3Shape_GetBody( sensorShapeId ); b3WorldTransform t = b3Body_GetTransform( sensorBodyId ); - t.p = b3Body_GetWorldCenter( sensorBodyId ); + t.p = b3Body_GetWorldCenterOfMass( sensorBodyId ); m_transforms[m_transformCount] = t; m_transformCount += 1; } diff --git a/samples/sample_ghost.cpp b/samples/sample_ghost.cpp deleted file mode 100644 index e2c9ee6..0000000 --- a/samples/sample_ghost.cpp +++ /dev/null @@ -1,3762 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "ghost_collisions.h" -#include "sample.h" -#include "utils.h" - -#include "gfx/draw.h" - -#include "box3d/box3d.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Scenes for comparing ghost collision handling across physics engines. Each one isolates a mechanism -// where engines differ: crest angles around the active edge cutoffs, high valence vertex fans, saddle -// vertices, long runs through grid vertices, and large bodies on fine meshes. Energy, vertical velocity -// and drift only need body state, so the same scenes can be measured in any engine. The ghost count -// also needs contact normals and the triangle feature behind each point. - -enum ProbeShape -{ - e_probeBox, - e_probeCylinder, - e_probeSphere, - e_probeCapsule, - e_probeShapeCount -}; - -static const char* s_probeShapeNames[e_probeShapeCount] = { "Box", "Cylinder", "Sphere", "Capsule" }; - -// Box and cylinder slide without friction. Sphere and capsule roll. -static bool IsRoller( int shape ) -{ - return shape == e_probeSphere || shape == e_probeCapsule; -} - -static float GetProbeRadius( int shape ) -{ - return shape == e_probeSphere ? 0.25f : 0.2f; -} - -enum DiagonalMode -{ - e_diagonalForward, - e_diagonalBackward, - e_diagonalAlternate, - e_diagonalModeCount -}; - -static const char* s_diagonalNames[e_diagonalModeCount] = { "Along +x+z", "Along +x-z", "Alternate" }; - -static std::vector MakeSamples( float lower, float upper, int count ) -{ - std::vector samples( count + 1 ); - for ( int i = 0; i <= count; ++i ) - { - samples[i] = lower + ( upper - lower ) * (float)i / (float)count; - } - return samples; -} - -// Rows run along x. Triangles wind counter clockwise seen from above. -static void AddGrid( std::vector& vertices, std::vector& indices, const std::vector& xs, - const std::vector& zs, const std::function& height, int mode ) -{ - int base = (int)vertices.size(); - int stride = (int)zs.size(); - for ( int i = 0; i < (int)xs.size(); ++i ) - { - for ( int j = 0; j < stride; ++j ) - { - vertices.push_back( { xs[i], height( i, j ), zs[j] } ); - } - } - - int xCount = (int)xs.size() - 1; - int zCount = stride - 1; - for ( int i = 0; i < xCount; ++i ) - { - for ( int j = 0; j < zCount; ++j ) - { - int a = base + i * stride + j; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - - bool forward = mode == e_diagonalForward || ( mode == e_diagonalAlternate && ( ( i + j ) & 1 ) == 0 ); - if ( forward ) - { - int32_t corners[6] = { a, b, c, c, d, a }; - indices.insert( indices.end(), corners, corners + 6 ); - } - else - { - int32_t corners[6] = { a, b, d, b, c, d }; - indices.insert( indices.end(), corners, corners + 6 ); - } - } - } -} - -static void AddUpTriangle( const std::vector& vertices, std::vector& indices, int a, int b, int c ) -{ - b3Vec3 normal = b3Cross( vertices[b] - vertices[a], vertices[c] - vertices[a] ); - if ( normal.y < 0.0f ) - { - std::swap( b, c ); - } - - indices.push_back( a ); - indices.push_back( b ); - indices.push_back( c ); -} - -// Linear and rotational kinetic energy per unit mass -static float GetSpecificKinetic( b3BodyId bodyId ) -{ - b3Vec3 v = b3Body_GetLinearVelocity( bodyId ); - b3Vec3 w = b3InvRotateVector( b3Body_GetRotation( bodyId ), b3Body_GetAngularVelocity( bodyId ) ); - b3Matrix3 inertia = b3Body_GetLocalRotationalInertia( bodyId ); - return 0.5f * b3Dot( v, v ) + 0.5f * b3Dot( w, b3MulMV( inertia, w ) ) / b3Body_GetMass( bodyId ); -} - -static float GetSpecificEnergy( b3BodyId bodyId, b3Vec3 gravity ) -{ - b3Vec3 center = b3ToVec3( b3Body_GetWorldCenter( bodyId ) ); - return GetSpecificKinetic( bodyId ) - b3Dot( gravity, center ); -} - -static float NextUnit( uint32_t& state ) -{ - state = 1664525u * state + 1013904223u; - return (float)( state >> 8 ) / 16777216.0f; -} - -// Owns the ground mesh and counts ghost manifolds on it. A pushing manifold is a ghost when its normal -// matches no nearby triangle and does not lie in the normal cone of the edge or vertex that produced it. -class GhostSample : public Sample -{ -public: - static constexpr int m_markerCapacity = 256; - static constexpr int m_historyCapacity = 600; - - enum GhostClass - { - e_faceGhost, - e_edgeGhost, - e_vertexGhost, - e_otherGhost, - e_ghostClassCount - }; - - explicit GhostSample( SampleContext* context ) - : Sample( context ) - { - m_mesh = nullptr; - m_groundId = b3_nullBodyId; - m_followId = b3_nullBodyId; - m_cylinder = b3CreateCylinder( 0.4f, 0.4f, -0.2f, 16 ); - m_toleranceDegrees = 5.0f; - m_cosTolerance = 1.0f; - m_sinTolerance = 0.0f; - m_drawGhosts = true; - m_follow = true; - m_showHistory = true; - m_plotScale = 1.0f; - m_lastHeight = 0.0f; - ResetGhostCounts(); - ClearHistory(); - } - - ~GhostSample() override - { - b3DestroyHull( m_cylinder ); - if ( m_mesh != nullptr ) - { - b3DestroyMesh( m_mesh ); - } - } - -protected: - void CreateGround( std::vector& vertices, std::vector& indices ) - { - if ( B3_IS_NON_NULL( m_groundId ) ) - { - b3DestroyBody( m_groundId ); - m_groundId = b3_nullBodyId; - } - - if ( m_mesh != nullptr ) - { - b3DestroyMesh( m_mesh ); - m_mesh = nullptr; - } - - b3MeshDef def = {}; - def.vertices = vertices.data(); - def.vertexCount = (int)vertices.size(); - def.indices = indices.data(); - def.triangleCount = (int)indices.size() / 3; - def.useMedianSplit = true; - def.identifyEdges = true; - m_mesh = b3CreateMesh( &def, nullptr, 0 ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "ground"; - m_groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( m_groundId, &shapeDef, m_mesh, b3Vec3_one ); - - BuildAdjacency(); - ResetGhostCounts(); - } - - // The direction is horizontal. Rollers start with the spin that matches their speed. The yaw turns a - // box or cylinder about the vertical axis relative to the direction of travel. - b3BodyId CreateProbe( int shape, b3Pos position, b3Vec3 direction, float yawDegrees, float speed ) - { - b3Quat heading = b3MakeQuatFromAxisAngle( b3Vec3_axisY, atan2f( -direction.z, direction.x ) ); - b3Quat yaw = b3MakeQuatFromAxisAngle( b3Vec3_axisY, yawDegrees * B3_DEG_TO_RAD ); - bool roller = IsRoller( shape ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = position; - bodyDef.rotation = roller ? heading : b3MulQuat( heading, yaw ); - bodyDef.linearVelocity = speed * direction; - if ( roller ) - { - bodyDef.angularVelocity = ( speed / GetProbeRadius( shape ) ) * b3Cross( b3Vec3_axisY, direction ); - } - - // Recycling reuses a manifold while the body barely moves, which hides the collision under test - bodyDef.enableContactRecycling = false; - bodyDef.enableSleep = false; - bodyDef.name = "probe"; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = roller ? 0.6f : 0.0f; - - switch ( shape ) - { - case e_probeBox: - { - b3BoxHull box = b3MakeBoxHull( 0.4f, 0.2f, 0.4f ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - break; - - case e_probeCylinder: - b3CreateHullShape( bodyId, &shapeDef, m_cylinder ); - break; - - case e_probeSphere: - { - b3Sphere sphere = { b3Vec3_zero, GetProbeRadius( shape ) }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - break; - - default: - { - // Axis across the direction of travel so it rolls - b3Capsule capsule = { { 0.0f, 0.0f, -0.4f }, { 0.0f, 0.0f, 0.4f }, GetProbeRadius( shape ) }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - break; - } - - return bodyId; - } - - void BuildAdjacency() - { - int triangleCount = m_mesh->triangleCount; - int vertexCount = m_mesh->vertexCount; - const b3MeshTriangle* triangles = b3GetMeshTriangles( m_mesh ); - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - - m_triangleNormals.resize( triangleCount ); - m_edgeNeighbors.assign( 3 * triangleCount, B3_NULL_INDEX ); - m_vertexRings.assign( vertexCount, {} ); - m_vertexTriangles.assign( vertexCount, {} ); - - // Sorting by vertex pair puts the two sides of a shared edge next to each other - std::vector> edges; - edges.reserve( 3 * triangleCount ); - - for ( int t = 0; t < triangleCount; ++t ) - { - int v[3] = { triangles[t].index1, triangles[t].index2, triangles[t].index3 }; - m_triangleNormals[t] = b3Normalize( b3Cross( vertices[v[1]] - vertices[v[0]], vertices[v[2]] - vertices[v[0]] ) ); - - for ( int e = 0; e < 3; ++e ) - { - int a = v[e]; - int b = v[e < 2 ? e + 1 : 0]; - uint64_t key = ( (uint64_t)b3MinInt( a, b ) << 32 ) | (uint64_t)b3MaxInt( a, b ); - edges.push_back( { key, 3 * t + e } ); - m_vertexRings[a].push_back( b ); - m_vertexRings[b].push_back( a ); - m_vertexTriangles[a].push_back( t ); - } - } - - std::sort( edges.begin(), edges.end() ); - for ( size_t i = 0; i + 1 < edges.size(); ++i ) - { - // A non-manifold edge leaves every side without a neighbor - uint64_t key = edges[i].first; - bool pair = edges[i + 1].first == key; - bool single = ( i + 2 >= edges.size() || edges[i + 2].first != key ) && ( i == 0 || edges[i - 1].first != key ); - if ( pair && single ) - { - m_edgeNeighbors[edges[i].second] = edges[i + 1].second / 3; - m_edgeNeighbors[edges[i + 1].second] = edges[i].second / 3; - } - } - - for ( std::vector& ring : m_vertexRings ) - { - std::sort( ring.begin(), ring.end() ); - ring.erase( std::unique( ring.begin(), ring.end() ), ring.end() ); - } - } - - bool MatchesFace( b3Vec3 normal, int triangleIndex ) const - { - return b3Dot( normal, m_triangleNormals[triangleIndex] ) >= m_cosTolerance; - } - - // Direction in the face plane pointing away from the edge into the face - static b3Vec3 GetInwardDirection( b3Vec3 edgeStart, b3Vec3 axis, b3Vec3 opposite ) - { - b3Vec3 d = opposite - edgeStart; - return b3Normalize( d - b3Dot( d, axis ) * axis ); - } - - // The normal cone of a convex edge is the arc between its two face normals. Neither face may rise - // above the edge along the normal, so a concave edge only admits its face normals. - bool AdmitsEdge( b3Vec3 normal, int triangleIndex, int edgeIndex ) const - { - int neighbor = m_edgeNeighbors[3 * triangleIndex + edgeIndex]; - if ( MatchesFace( normal, triangleIndex ) || ( neighbor != B3_NULL_INDEX && MatchesFace( normal, neighbor ) ) ) - { - return true; - } - - const b3MeshTriangle* triangles = b3GetMeshTriangles( m_mesh ); - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - int v[3] = { triangles[triangleIndex].index1, triangles[triangleIndex].index2, triangles[triangleIndex].index3 }; - int ia = v[edgeIndex]; - int ib = v[edgeIndex < 2 ? edgeIndex + 1 : 0]; - int ic = v[edgeIndex > 0 ? edgeIndex - 1 : 2]; - - b3Vec3 a = vertices[ia]; - b3Vec3 axis = b3Normalize( vertices[ib] - a ); - if ( b3AbsFloat( b3Dot( normal, axis ) ) > m_sinTolerance ) - { - return false; - } - - if ( b3Dot( normal, GetInwardDirection( a, axis, vertices[ic] ) ) > m_sinTolerance ) - { - return false; - } - - if ( neighbor != B3_NULL_INDEX ) - { - int w[3] = { triangles[neighbor].index1, triangles[neighbor].index2, triangles[neighbor].index3 }; - for ( int k = 0; k < 3; ++k ) - { - if ( w[k] != ia && w[k] != ib && b3Dot( normal, GetInwardDirection( a, axis, vertices[w[k]] ) ) > m_sinTolerance ) - { - return false; - } - } - } - - return true; - } - - // A vertex normal is valid when the vertex is a local support point in that direction - bool AdmitsVertex( b3Vec3 normal, int vertexIndex ) const - { - for ( int t : m_vertexTriangles[vertexIndex] ) - { - if ( MatchesFace( normal, t ) ) - { - return true; - } - } - - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - b3Vec3 vertex = vertices[vertexIndex]; - for ( int other : m_vertexRings[vertexIndex] ) - { - if ( b3Dot( normal, b3Normalize( vertices[other] - vertex ) ) > m_sinTolerance ) - { - return false; - } - } - - return true; - } - - bool AdmitsPoint( b3Vec3 normal, const b3ManifoldPoint& point ) const - { - const b3MeshTriangle& triangle = b3GetMeshTriangles( m_mesh )[point.triangleIndex]; - int v[3] = { triangle.index1, triangle.index2, triangle.index3 }; - - switch ( point.triangleFeature ) - { - case b3_featureTriangleFace: - return MatchesFace( normal, point.triangleIndex ); - - case b3_featureEdge1: - case b3_featureEdge2: - case b3_featureEdge3: - return AdmitsEdge( normal, point.triangleIndex, point.triangleFeature - b3_featureEdge1 ); - - case b3_featureVertex1: - case b3_featureVertex2: - case b3_featureVertex3: - return AdmitsVertex( normal, v[point.triangleFeature - b3_featureVertex1] ); - - default: - // No feature was resolved, so any feature of the triangle may own the normal - if ( MatchesFace( normal, point.triangleIndex ) ) - { - return true; - } - - for ( int k = 0; k < 3; ++k ) - { - if ( AdmitsEdge( normal, point.triangleIndex, k ) || AdmitsVertex( normal, v[k] ) ) - { - return true; - } - } - - return false; - } - } - - static GhostClass Classify( const b3ManifoldPoint& point ) - { - switch ( point.triangleFeature ) - { - case b3_featureTriangleFace: - return e_faceGhost; - - case b3_featureEdge1: - case b3_featureEdge2: - case b3_featureEdge3: - return e_edgeGhost; - - case b3_featureVertex1: - case b3_featureVertex2: - case b3_featureVertex3: - return e_vertexGhost; - - default: - return e_otherGhost; - } - } - - // The center is the body center at the start of the step, where the anchors were computed - int CountGhosts( b3BodyId bodyId, b3Pos center ) - { - // Clustering merges manifolds whose normals agree within its threshold and hands them one normal, - // so a point may carry a normal that far from its own feature - float angle = m_toleranceDegrees * B3_DEG_TO_RAD + acosf( 0.996f ); - m_cosTolerance = cosf( angle ); - m_sinTolerance = sinf( angle ); - - memset( m_stepClassCounts, 0, sizeof( m_stepClassCounts ) ); - int ghostCount = 0; - - // A pile box touches many neighbors besides the ground - m_contacts.resize( b3MaxInt( 1, b3Body_GetContactCapacity( bodyId ) ) ); - b3ContactData* contacts = m_contacts.data(); - int contactCount = b3Body_GetContactData( bodyId, contacts, (int)m_contacts.size() ); - for ( int i = 0; i < contactCount; ++i ) - { - bool bodyIsA = B3_ID_EQUALS( b3Shape_GetBody( contacts[i].shapeIdA ), bodyId ); - b3ShapeId otherId = bodyIsA ? contacts[i].shapeIdB : contacts[i].shapeIdA; - if ( b3Shape_GetType( otherId ) != b3_meshShape ) - { - continue; - } - - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - const b3Manifold* manifold = contacts[i].manifolds + j; - b3Vec3 normal = bodyIsA ? -manifold->normal : manifold->normal; - - // Speculative points that never pushed are harmless. Clustering hands every point the normal - // of one member, so the manifold is sound if any pushing point owns that normal. - int pushCount = 0; - int firstPush = 0; - bool admitted = false; - for ( int k = 0; k < manifold->pointCount && admitted == false; ++k ) - { - const b3ManifoldPoint& point = manifold->points[k]; - if ( point.totalNormalImpulse <= 0.0f ) - { - continue; - } - - firstPush = pushCount == 0 ? k : firstPush; - pushCount += 1; - admitted = AdmitsPoint( normal, point ); - } - - if ( pushCount == 0 ) - { - continue; - } - - m_manifoldCount += 1; - - if ( admitted ) - { - continue; - } - - const b3ManifoldPoint& point = manifold->points[firstPush]; - GhostClass ghostClass = Classify( point ); - m_classCounts[ghostClass] += 1; - m_stepClassCounts[ghostClass] += 1; - m_ghostCount += 1; - ghostCount += 1; - - b3Vec3 anchor = bodyIsA ? point.anchorA : point.anchorB; - m_markers[m_markerIndex] = { b3OffsetPos( center, anchor ), normal }; - m_markerIndex = ( m_markerIndex + 1 ) % m_markerCapacity; - m_markerCount = b3MinInt( m_markerCount + 1, m_markerCapacity ); - } - } - - return ghostCount; - } - - void ResetGhostCounts() - { - memset( m_classCounts, 0, sizeof( m_classCounts ) ); - memset( m_stepClassCounts, 0, sizeof( m_stepClassCounts ) ); - m_ghostCount = 0; - m_manifoldCount = 0; - m_markerCount = 0; - m_markerIndex = 0; - } - - virtual void ResetCounters() - { - ResetGhostCounts(); - } - - void ClearHistory() - { - m_historyCount = 0; - m_historyIndex = 0; - } - - // From the height change over the step, so push out counts and every engine is measured the same way. - // A fast rolling body can report a steady downward velocity that never moves it. - float GetVerticalSpeed( float height ) - { - float speed = ( height - m_lastHeight ) * m_context->hertz; - m_lastHeight = height; - return speed; - } - - void PushHistory( float value ) - { - m_history[m_historyIndex] = value; - m_historyIndex = ( m_historyIndex + 1 ) % m_historyCapacity; - m_historyCount = b3MinInt( m_historyCount + 1, m_historyCapacity ); - } - - void DrawGhosts() - { - if ( m_drawGhosts ) - { - for ( int i = 0; i < m_markerCount; ++i ) - { - b3Pos p = m_markers[i].point; - DrawPoint( p, 8.0f, MakeColor( b3_colorRed ) ); - DrawLine( p, p + 0.5f * m_markers[i].normal, MakeColor( b3_colorRed ) ); - } - } - - if ( m_follow && B3_IS_NON_NULL( m_followId ) ) - { - m_camera->SetPivot( b3Body_GetPosition( m_followId ) ); - } - } - - void DrawGhostSummary() - { - DrawTextLine( "ghost manifolds: %d of %d pushing, face %d, edge %d, vertex %d, unresolved %d", m_ghostCount, - m_manifoldCount, m_classCounts[e_faceGhost], m_classCounts[e_edgeGhost], m_classCounts[e_vertexGhost], - m_classCounts[e_otherGhost] ); - DrawTextLine( "triangles: %d, mesh bytes: %d", m_mesh->triangleCount, m_mesh->byteCount ); - } - - void DrawGhostControls() - { - ImGui::Separator(); - ImGui::SliderFloat( "Ghost Tolerance", &m_toleranceDegrees, 1.0f, 20.0f, "%.0f deg" ); - ImGui::Checkbox( "Draw Ghosts", &m_drawGhosts ); - ImGui::Checkbox( "Follow", &m_follow ); - if ( ImGui::Button( "Reset Counters" ) ) - { - ResetCounters(); - } - - if ( m_showHistory ) - { - ImGui::SliderFloat( "Plot Scale", &m_plotScale, 0.1f, 5.0f, "%.1f m/s" ); - int offset = m_historyCount < m_historyCapacity ? 0 : m_historyIndex; - ImGui::PlotLines( "##vy", m_history, m_historyCount, offset, "vertical velocity", -m_plotScale, m_plotScale, - ImVec2( 0.0f, 80.0f ) ); - } - } - - struct Marker - { - b3Pos point; - b3Vec3 normal; - }; - - b3MeshData* m_mesh; - b3BodyId m_groundId; - b3BodyId m_followId; - b3HullData* m_cylinder; - - std::vector m_triangleNormals; - std::vector m_edgeNeighbors; - std::vector> m_vertexRings; - std::vector> m_vertexTriangles; - std::vector m_contacts; - - float m_toleranceDegrees; - float m_cosTolerance; - float m_sinTolerance; - int m_classCounts[e_ghostClassCount]; - int m_stepClassCounts[e_ghostClassCount]; - int m_ghostCount; - int m_manifoldCount; - - Marker m_markers[m_markerCapacity]; - int m_markerCount; - int m_markerIndex; - - float m_history[m_historyCapacity]; - int m_historyCount; - int m_historyIndex; - float m_plotScale; - float m_lastHeight; - - bool m_drawGhosts; - bool m_follow; - bool m_showHistory; -}; - -// Roof ridges with crest angles from 1 to 20 degrees, separated by flat runs. The angles straddle the -// cutoffs of engines that keep one convex bit per edge, about 5 degrees in Jolt and PhysX, while Box3D -// stores the angle in 1.4 degree steps. Each crest reports, from its foot to the next foot, the energy -// lost and the peak vertical velocity. The slope alone lifts the body at its speed times the sine of -// half the crest angle. -class CrestLadder : public GhostSample -{ -public: - static constexpr int m_crestCount = 9; - static constexpr float m_slopeRun = 1.5f; - static constexpr float m_gap = 2.5f; - static constexpr float m_leadIn = 5.0f; - static constexpr float m_runOut = 5.0f; - static constexpr float m_halfWidth = 2.0f; - - struct CrestStats - { - float startEnergy; - float startKinetic; - float slopeVelocity; - float peakVelocity; - float loss; - int ghosts; - bool valid; - }; - - explicit CrestLadder( SampleContext* context ) - : GhostSample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 60.0f, 20.0f, 12.0f, { 2.0f, 0.5f, 0.0f } ); - } - - m_probe = e_probeBox; - m_speed = 4.0f; - m_yaw = 0.0f; - m_cellSize = 0.25f; - m_diagonal = e_diagonalAlternate; - m_probeId = b3_nullBodyId; - - BuildGround(); - ResetCounters(); - Launch(); - } - - void ResetCounters() override - { - GhostSample::ResetCounters(); - memset( m_current, 0, sizeof( m_current ) ); - memset( m_last, 0, sizeof( m_last ) ); - memset( m_crestGhosts, 0, sizeof( m_crestGhosts ) ); - m_runCount = 0; - } - - void BuildGround() - { - std::vector corners; - corners.push_back( { 0.0f, 0.0f } ); - - float x = m_leadIn; - for ( int i = 0; i < m_crestCount; ++i ) - { - float rise = m_slopeRun * tanf( 0.5f * m_angles[i] * B3_DEG_TO_RAD ); - m_windowStart[i] = x; - m_crestPoints[i] = { x + m_slopeRun, rise }; - corners.push_back( { x, 0.0f } ); - corners.push_back( { x + m_slopeRun, rise } ); - corners.push_back( { x + 2.0f * m_slopeRun, 0.0f } ); - x += 2.0f * m_slopeRun + m_gap; - } - - m_windowEnd = x; - m_length = x + m_runOut; - corners.push_back( { m_length, 0.0f } ); - - // Every corner lands on a vertex row - std::vector xs; - std::vector ys; - for ( size_t k = 0; k + 1 < corners.size(); ++k ) - { - b3Vec2 a = corners[k]; - b3Vec2 b = corners[k + 1]; - int count = b3MaxInt( 1, (int)ceilf( ( b.x - a.x ) / m_cellSize - 0.001f ) ); - for ( int s = 0; s < count; ++s ) - { - float t = (float)s / (float)count; - xs.push_back( a.x + t * ( b.x - a.x ) ); - ys.push_back( a.y + t * ( b.y - a.y ) ); - } - } - xs.push_back( corners.back().x ); - ys.push_back( corners.back().y ); - - int zCount = b3MaxInt( 1, (int)ceilf( 2.0f * m_halfWidth / m_cellSize - 0.001f ) ); - std::vector zs = MakeSamples( -m_halfWidth, m_halfWidth, zCount ); - - std::vector vertices; - std::vector indices; - AddGrid( vertices, indices, xs, zs, [&]( int i, int ) { return ys[i]; }, m_diagonal ); - CreateGround( vertices, indices ); - } - - void Launch() - { - if ( B3_IS_NON_NULL( m_probeId ) ) - { - b3DestroyBody( m_probeId ); - } - - b3Pos position = { 2.0f, GetProbeRadius( m_probe ) + 0.01f, 0.0f }; - m_probeId = CreateProbe( m_probe, position, b3Vec3_axisX, m_yaw, m_speed ); - m_followId = m_probeId; - m_lastHeight = (float)position.y; - m_window = -1; - m_runSteps = 0; - memset( m_current, 0, sizeof( m_current ) ); - ClearHistory(); - } - - int FindWindow( float x ) const - { - for ( int i = 0; i < m_crestCount; ++i ) - { - float end = i + 1 < m_crestCount ? m_windowStart[i + 1] : m_windowEnd; - if ( m_windowStart[i] <= x && x < end ) - { - return i; - } - } - - return -1; - } - - void OpenWindow( int index ) - { - b3Vec3 gravity = b3World_GetGravity( m_worldId ); - float speed = b3Length( b3Body_GetLinearVelocity( m_probeId ) ); - CrestStats& stats = m_current[index]; - stats = {}; - stats.startEnergy = GetSpecificEnergy( m_probeId, gravity ); - stats.startKinetic = GetSpecificKinetic( m_probeId ); - stats.slopeVelocity = speed * sinf( 0.5f * m_angles[index] * B3_DEG_TO_RAD ); - stats.peakVelocity = -FLT_MAX; - } - - void CloseWindow( int index ) - { - b3Vec3 gravity = b3World_GetGravity( m_worldId ); - CrestStats& stats = m_current[index]; - float lost = stats.startEnergy - GetSpecificEnergy( m_probeId, gravity ); - stats.loss = stats.startKinetic > 0.0f ? 100.0f * lost / stats.startKinetic : 0.0f; - stats.valid = true; - } - - void Step() override - { - b3Pos center = b3Body_GetWorldCenter( m_probeId ); - - Sample::Step(); - - if ( m_didStep ) - { - int ghostCount = CountGhosts( m_probeId, center ); - - b3Pos position = b3Body_GetWorldCenter( m_probeId ); - float verticalSpeed = GetVerticalSpeed( (float)position.y ); - PushHistory( verticalSpeed ); - - int window = FindWindow( (float)position.x ); - if ( window != m_window ) - { - if ( m_window >= 0 ) - { - CloseWindow( m_window ); - } - - if ( window >= 0 ) - { - OpenWindow( window ); - } - - m_window = window; - } - - if ( m_window >= 0 ) - { - CrestStats& stats = m_current[m_window]; - stats.ghosts += ghostCount; - stats.peakVelocity = b3MaxFloat( stats.peakVelocity, verticalSpeed ); - m_crestGhosts[m_window] += ghostCount; - } - - m_runSteps += 1; - bool done = (float)position.x > m_length - 3.0f || (float)position.y < -2.0f || m_runSteps > 1800; - if ( done ) - { - if ( m_window >= 0 ) - { - CloseWindow( m_window ); - } - - memcpy( m_last, m_current, sizeof( m_last ) ); - m_runCount += 1; - Launch(); - } - } - - DrawGhosts(); - - for ( int i = 0; i < m_crestCount; ++i ) - { - b3Pos p = { m_crestPoints[i].x, m_crestPoints[i].y + 0.6f, m_halfWidth }; - DrawString3D( p, MakeColor( b3_colorWhite ), "%.0f deg", m_angles[i] ); - } - - DrawTextLine( "completed runs: %d, crest values from the last run, ghosts over all runs", m_runCount ); - DrawGhostSummary(); - - const CrestStats* stats = m_runCount > 0 ? m_last : m_current; - for ( int i = 0; i < m_crestCount; ++i ) - { - if ( stats[i].valid ) - { - DrawTextLine( "crest %2.0f deg: ghosts %d, energy loss %5.1f%%, peak vy %.2f m/s, slope vy %.2f m/s", m_angles[i], - m_crestGhosts[i], stats[i].loss, stats[i].peakVelocity, stats[i].slopeVelocity ); - } - else - { - DrawTextLine( "crest %2.0f deg: ghosts %d", m_angles[i], m_crestGhosts[i] ); - } - } - } - - bool DrawControls() override - { - bool rebuild = false; - bool relaunch = false; - - relaunch |= ImGui::Combo( "Probe", &m_probe, s_probeShapeNames, e_probeShapeCount ); - relaunch |= ImGui::SliderFloat( "Speed", &m_speed, 0.5f, 15.0f, "%.1f m/s" ); - relaunch |= ImGui::SliderFloat( "Yaw", &m_yaw, 0.0f, 45.0f, "%.0f deg" ); - rebuild |= ImGui::SliderFloat( "Cell Size", &m_cellSize, 0.1f, 1.0f, "%.2f m" ); - rebuild |= ImGui::Combo( "Diagonals", &m_diagonal, s_diagonalNames, e_diagonalModeCount ); - relaunch |= ImGui::Button( "Launch" ); - - DrawGhostControls(); - - if ( rebuild ) - { - BuildGround(); - ResetCounters(); - } - - if ( rebuild || relaunch ) - { - Launch(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new CrestLadder( context ); - } - - static constexpr float m_angles[m_crestCount] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 8.0f, 12.0f, 20.0f }; - - b3BodyId m_probeId; - int m_probe; - float m_speed; - float m_yaw; - float m_cellSize; - int m_diagonal; - - float m_windowStart[m_crestCount]; - b3Vec2 m_crestPoints[m_crestCount]; - float m_windowEnd; - float m_length; - - CrestStats m_current[m_crestCount]; - CrestStats m_last[m_crestCount]; - int m_crestGhosts[m_crestCount]; - int m_window; - int m_runSteps; - int m_runCount; -}; - -static int sampleCrestLadder = RegisterSample( "Ghost", "Crest Ladder", CrestLadder::Create ); - -// A cone apex shared by 6 to 48 triangles with uneven spacing, so some triangles near the apex are -// slivers. Every spoke is a crest whose dihedral angle shrinks as the fan grows, so each engine's edge -// cutoff falls somewhere in the range. Vertex handling is where engines differ most. The probe crosses -// the apex along eight headings in turn. -class HubPeak : public GhostSample -{ -public: - static constexpr int m_headingCount = 8; - static constexpr int m_ringCount = 10; - static constexpr float m_ringSpacing = 1.0f; - static constexpr float m_coneRadius = 3.0f; - static constexpr float m_launchDistance = 6.5f; - - enum HubShape - { - e_hubPeak, - e_hubPit, - e_hubSaddle, - e_hubShapeCount - }; - - struct RunStats - { - float startEnergy; - float startKinetic; - float peakVelocity; - float loss; - int ghosts; - int vertexGhosts; - bool valid; - }; - - explicit HubPeak( SampleContext* context ) - : GhostSample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 45.0f, 30.0f, 16.0f, { 0.0f, 0.5f, 0.0f } ); - } - - m_follow = false; - m_hubShape = e_hubPeak; - m_fanIndex = 1; - m_slopeDegrees = 10.0f; - m_jitter = 0.3f; - m_probe = e_probeBox; - m_speed = 5.0f; - m_yaw = 0.0f; - m_offset = 0.0f; - m_heading = 0; - m_probeId = b3_nullBodyId; - - BuildGround(); - ResetCounters(); - Launch(); - } - - void ResetCounters() override - { - GhostSample::ResetCounters(); - memset( m_last, 0, sizeof( m_last ) ); - m_runCount = 0; - } - - float GetHeight( float radius, float angle ) const - { - if ( radius >= m_coneRadius ) - { - return 0.0f; - } - - float slope = tanf( m_slopeDegrees * B3_DEG_TO_RAD ); - switch ( m_hubShape ) - { - case e_hubPeak: - return slope * ( m_coneRadius - radius ); - - case e_hubPit: - return -slope * ( m_coneRadius - radius ); - - default: - // Three ridges and three valleys meet at the center, the slope there is set by the angle - return slope * radius * ( 1.0f - radius / m_coneRadius ) * cosf( 3.0f * angle ); - } - } - - void BuildGround() - { - int fanCount = m_fanCounts[m_fanIndex]; - - // Fixed seed so a fan count always gets the same slivers - uint32_t state = 12345; - std::vector angles( fanCount ); - for ( int i = 0; i < fanCount; ++i ) - { - float u = NextUnit( state ) - 0.5f; - angles[i] = 2.0f * B3_PI * ( (float)i + m_jitter * u ) / (float)fanCount; - } - - std::vector vertices; - std::vector indices; - vertices.push_back( { 0.0f, GetHeight( 0.0f, 0.0f ), 0.0f } ); - for ( int k = 1; k <= m_ringCount; ++k ) - { - float radius = m_ringSpacing * (float)k; - for ( int i = 0; i < fanCount; ++i ) - { - float angle = angles[i]; - vertices.push_back( { radius * cosf( angle ), GetHeight( radius, angle ), radius * sinf( angle ) } ); - } - } - - for ( int i = 0; i < fanCount; ++i ) - { - AddUpTriangle( vertices, indices, 0, 1 + i, 1 + ( i + 1 ) % fanCount ); - } - - // Dihedral angles between neighboring apex triangles - m_minDihedral = FLT_MAX; - m_maxDihedral = 0.0f; - for ( int i = 0; i < fanCount; ++i ) - { - const int32_t* t1 = indices.data() + 3 * i; - const int32_t* t2 = indices.data() + 3 * ( ( i + 1 ) % fanCount ); - b3Vec3 n1 = b3Normalize( b3Cross( vertices[t1[1]] - vertices[t1[0]], vertices[t1[2]] - vertices[t1[0]] ) ); - b3Vec3 n2 = b3Normalize( b3Cross( vertices[t2[1]] - vertices[t2[0]], vertices[t2[2]] - vertices[t2[0]] ) ); - float dihedral = acosf( b3ClampFloat( b3Dot( n1, n2 ), -1.0f, 1.0f ) ) / B3_DEG_TO_RAD; - m_minDihedral = b3MinFloat( m_minDihedral, dihedral ); - m_maxDihedral = b3MaxFloat( m_maxDihedral, dihedral ); - } - - for ( int k = 1; k < m_ringCount; ++k ) - { - int inner = 1 + ( k - 1 ) * fanCount; - int outer = inner + fanCount; - for ( int i = 0; i < fanCount; ++i ) - { - int next = ( i + 1 ) % fanCount; - int a = inner + i; - int b = inner + next; - int c = outer + next; - int d = outer + i; - - if ( ( i + k ) & 1 ) - { - AddUpTriangle( vertices, indices, a, b, c ); - AddUpTriangle( vertices, indices, a, c, d ); - } - else - { - AddUpTriangle( vertices, indices, a, b, d ); - AddUpTriangle( vertices, indices, b, c, d ); - } - } - } - - CreateGround( vertices, indices ); - } - - b3Vec3 GetDirection() const - { - float angle = (float)m_heading * 2.0f * B3_PI / (float)m_headingCount; - return { cosf( angle ), 0.0f, sinf( angle ) }; - } - - void Launch() - { - if ( B3_IS_NON_NULL( m_probeId ) ) - { - b3DestroyBody( m_probeId ); - } - - b3Vec3 d = GetDirection(); - b3Vec3 perp = { -d.z, 0.0f, d.x }; - b3Vec3 start = -m_launchDistance * d + m_offset * perp; - start.y = GetProbeRadius( m_probe ) + 0.01f; - m_start = start; - - m_probeId = CreateProbe( m_probe, b3ToPos( start ), d, m_yaw, m_speed ); - m_followId = m_probeId; - m_lastHeight = start.y; - m_runSteps = 0; - - m_current = {}; - m_current.startEnergy = GetSpecificEnergy( m_probeId, b3World_GetGravity( m_worldId ) ); - m_current.startKinetic = GetSpecificKinetic( m_probeId ); - m_current.peakVelocity = -FLT_MAX; - ClearHistory(); - } - - void Step() override - { - b3Pos center = b3Body_GetWorldCenter( m_probeId ); - - Sample::Step(); - - if ( m_didStep ) - { - int ghostCount = CountGhosts( m_probeId, center ); - m_current.ghosts += ghostCount; - m_current.vertexGhosts += m_stepClassCounts[e_vertexGhost]; - - b3Vec3 position = b3ToVec3( b3Body_GetWorldCenter( m_probeId ) ); - float verticalSpeed = GetVerticalSpeed( position.y ); - m_current.peakVelocity = b3MaxFloat( m_current.peakVelocity, verticalSpeed ); - PushHistory( verticalSpeed ); - - b3Vec3 d = GetDirection(); - float along = b3Dot( position - m_start, d ); - float radius = sqrtf( position.x * position.x + position.z * position.z ); - - m_runSteps += 1; - bool done = along > 2.0f * m_launchDistance || position.y < -4.0f || radius > 9.0f || m_runSteps > 900; - if ( done ) - { - float lost = m_current.startEnergy - GetSpecificEnergy( m_probeId, b3World_GetGravity( m_worldId ) ); - m_current.loss = m_current.startKinetic > 0.0f ? 100.0f * lost / m_current.startKinetic : 0.0f; - m_current.valid = true; - m_last[m_heading] = m_current; - m_runCount += 1; - m_heading = ( m_heading + 1 ) % m_headingCount; - Launch(); - } - } - - DrawGhosts(); - - b3Vec3 d = GetDirection(); - b3Vec3 tail = m_start + 0.5f * b3Vec3_axisY; - DrawArrow( b3ToPos( tail ), b3ToPos( tail + 1.5f * d ), MakeColor( b3_colorYellow ) ); - - DrawTextLine( "fan %d, apex dihedral angles %.1f to %.1f deg, completed runs %d", m_fanCounts[m_fanIndex], m_minDihedral, - m_maxDihedral, m_runCount ); - DrawGhostSummary(); - - for ( int i = 0; i < m_headingCount; ++i ) - { - int degrees = i * 360 / m_headingCount; - const RunStats& stats = m_last[i]; - if ( stats.valid ) - { - DrawTextLine( "heading %3d deg: ghosts %d (vertex %d), energy loss %5.1f%%, peak vy %.2f m/s", degrees, stats.ghosts, - stats.vertexGhosts, stats.loss, stats.peakVelocity ); - } - else - { - DrawTextLine( "heading %3d deg: pending", degrees ); - } - } - } - - bool DrawControls() override - { - bool rebuild = false; - bool relaunch = false; - - const char* shapeNames[e_hubShapeCount] = { "Peak", "Pit", "Saddle" }; - const char* fanNames[] = { "6", "12", "24", "48" }; - rebuild |= ImGui::Combo( "Hub", &m_hubShape, shapeNames, e_hubShapeCount ); - rebuild |= ImGui::Combo( "Fan", &m_fanIndex, fanNames, IM_ARRAYSIZE( fanNames ) ); - rebuild |= ImGui::SliderFloat( "Slope", &m_slopeDegrees, 1.0f, 20.0f, "%.0f deg" ); - rebuild |= ImGui::SliderFloat( "Jitter", &m_jitter, 0.0f, 0.45f, "%.2f" ); - relaunch |= ImGui::Combo( "Probe", &m_probe, s_probeShapeNames, e_probeShapeCount ); - relaunch |= ImGui::SliderFloat( "Speed", &m_speed, 0.5f, 15.0f, "%.1f m/s" ); - relaunch |= ImGui::SliderFloat( "Yaw", &m_yaw, 0.0f, 45.0f, "%.0f deg" ); - relaunch |= ImGui::SliderFloat( "Offset", &m_offset, 0.0f, 0.5f, "%.2f m" ); - relaunch |= ImGui::Button( "Launch" ); - - DrawGhostControls(); - - if ( rebuild ) - { - BuildGround(); - } - - if ( rebuild || relaunch ) - { - ResetCounters(); - m_heading = 0; - Launch(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new HubPeak( context ); - } - - static constexpr int m_fanCounts[4] = { 6, 12, 24, 48 }; - - b3BodyId m_probeId; - int m_hubShape; - int m_fanIndex; - float m_slopeDegrees; - float m_jitter; - int m_probe; - float m_speed; - float m_yaw; - float m_offset; - float m_minDihedral; - float m_maxDihedral; - - b3Vec3 m_start; - int m_heading; - int m_runSteps; - int m_runCount; - RunStats m_current; - RunStats m_last[m_headingCount]; -}; - -static int sampleHubPeak = RegisterSample( "Ghost", "Hub Peak", HubPeak::Create ); - -// A single fan whose spokes alternate between ridges and gullies. Each gully is a concave edge, so the -// mesh flags the hub concave, yet every spoke runs downhill and the hub is the closest point for a body -// dropped on it. Every fan triangle has a gully edge, so the edge tests of whichever triangle reports -// the vertex reject a near vertical normal. The contact survives only because the normal is also tested -// against the whole fan. Gullies steeper than the slope lift the ridges above the hub and make a true -// saddle with no normal cone. -class SaddleVertex : public GhostSample -{ -public: - static constexpr float m_fanRadius = 1.5f; - static constexpr int m_maxSpokes = 12; - static constexpr int m_directionCount = 3000; - static constexpr int m_holdSteps = 240; - - // The neighbor tolerance of the mesh collider, about 1 degree - static constexpr float m_edgeTolerance = 0.0175f; - - // Matches the speculative distance of the contact solver - static constexpr float m_reach = 0.02f; - - enum SpokeKind - { - e_convexSpoke, - e_concaveSpoke, - e_flatSpoke - }; - - enum Outcome - { - e_held, - e_fellThrough, - e_rolledOff, - e_outcomeCount - }; - - struct RunStats - { - int outcome; - int reachSteps; - int unsupportedSteps; - float deepest; - bool valid; - }; - - explicit SaddleVertex( SampleContext* context ) - : GhostSample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 45.0f, 30.0f, 6.0f, { 0.0f, 0.6f, 0.0f } ); - } - - m_spokeIndex = 1; - m_slopeDegrees = 20.0f; - m_gullyDegrees = 12.0f; - m_jitter = 0.0f; - m_probe = e_probeSphere; - m_upright = false; - m_dropHeight = 1.0f; - m_offset = 0.0f; - m_yaw = 0.0f; - m_showCone = true; - m_probeId = b3_nullBodyId; - - BuildGround(); - ResetStats(); - Launch(); - } - - void ResetStats() - { - m_last = {}; - memset( m_outcomeCounts, 0, sizeof( m_outcomeCounts ) ); - } - - static b3Vec3 GetUpNormal( b3Vec3 a, b3Vec3 b, b3Vec3 c ) - { - b3Vec3 normal = b3Normalize( b3Cross( b - a, c - a ) ); - return normal.y < 0.0f ? -normal : normal; - } - - void BuildGround() - { - int spokeCount = m_spokeCounts[m_spokeIndex]; - - // Fixed seed so a spoke count always gets the same slivers - uint32_t state = 12345; - - // Even spokes are ridges and odd spokes gullies. The lowest gully end sits at zero. - float hubHeight = m_fanRadius * tanf( ( m_slopeDegrees + m_gullyDegrees ) * B3_DEG_TO_RAD ); - std::vector vertices; - std::vector indices; - vertices.push_back( { 0.0f, hubHeight, 0.0f } ); - for ( int i = 0; i < spokeCount; ++i ) - { - float u = NextUnit( state ) - 0.5f; - float angle = 2.0f * B3_PI * ( (float)i + m_jitter * u ) / (float)spokeCount; - float elevation = ( i & 1 ) ? -( m_slopeDegrees + m_gullyDegrees ) : m_gullyDegrees - m_slopeDegrees; - float height = hubHeight + m_fanRadius * tanf( elevation * B3_DEG_TO_RAD ); - vertices.push_back( { m_fanRadius * cosf( angle ), height, m_fanRadius * sinf( angle ) } ); - } - - for ( int i = 0; i < spokeCount; ++i ) - { - AddUpTriangle( vertices, indices, 0, 1 + i, 1 + ( i + 1 ) % spokeCount ); - } - - CreateGround( vertices, indices ); - - m_spokeCount = spokeCount; - m_hub = vertices[0]; - for ( int i = 0; i < spokeCount; ++i ) - { - m_ring[i] = vertices[1 + i]; - } - - m_minHeight = FLT_MAX; - for ( b3Vec3 v : vertices ) - { - m_minHeight = b3MinFloat( m_minHeight, v.y ); - } - - // A spoke is convex when the next fan triangle bends below the plane of the previous one. The mesh - // stores edge angles in steps of about 1.4 degrees, so a smaller fold counts as flat. - m_convexCount = 0; - m_concaveCount = 0; - m_flatCount = 0; - for ( int i = 0; i < spokeCount; ++i ) - { - b3Vec3 previous = m_ring[( i + spokeCount - 1 ) % spokeCount]; - b3Vec3 next = m_ring[( i + 1 ) % spokeCount]; - b3Vec3 normal1 = GetUpNormal( m_hub, previous, m_ring[i] ); - b3Vec3 normal2 = GetUpNormal( m_hub, m_ring[i], next ); - float dihedral = acosf( b3ClampFloat( b3Dot( normal1, normal2 ), -1.0f, 1.0f ) ) / B3_DEG_TO_RAD; - float lift = b3Dot( normal1, next - m_hub ); - - if ( dihedral < 0.7f ) - { - m_spokeKinds[i] = e_flatSpoke; - m_flatCount += 1; - } - else if ( lift < 0.0f ) - { - m_spokeKinds[i] = e_convexSpoke; - m_convexCount += 1; - } - else - { - m_spokeKinds[i] = e_concaveSpoke; - m_concaveCount += 1; - } - } - - // Spread directions over the sphere and keep the ones the whole fan admits - m_coneDirections.clear(); - float golden = B3_PI * ( 3.0f - sqrtf( 5.0f ) ); - for ( int i = 0; i < m_directionCount; ++i ) - { - float y = 1.0f - 2.0f * ( (float)i + 0.5f ) / (float)m_directionCount; - float r = sqrtf( b3MaxFloat( 0.0f, 1.0f - y * y ) ); - float phi = golden * (float)i; - b3Vec3 direction = { r * cosf( phi ), y, r * sinf( phi ) }; - if ( FanAdmits( direction ) ) - { - m_coneDirections.push_back( direction ); - } - } - } - - // The hub is the closest point for a normal that no spoke leans along - bool FanAdmits( b3Vec3 normal ) const - { - for ( int i = 0; i < m_spokeCount; ++i ) - { - if ( b3Dot( normal, b3Normalize( m_ring[i] - m_hub ) ) > m_edgeTolerance ) - { - return false; - } - } - - return true; - } - - // The two edge tests the collider applies first, against the neighbors across the fan triangle's - // spokes. A normal that leans over either neighbor fails. - bool EdgesAdmit( b3Vec3 normal, int triangle ) const - { - int n = m_spokeCount; - int spokes[2] = { triangle, ( triangle + 1 ) % n }; - int opposites[2] = { ( triangle + n - 1 ) % n, ( triangle + 2 ) % n }; - for ( int j = 0; j < 2; ++j ) - { - b3Vec3 axis = b3Normalize( m_ring[spokes[j]] - m_hub ); - b3Vec3 inward = GetInwardDirection( m_hub, axis, m_ring[opposites[j]] ); - if ( b3Dot( normal, inward ) > m_edgeTolerance ) - { - return false; - } - } - - return true; - } - - // The core radius that the closest point query leaves out - float GetCoreRadius() const - { - return IsRoller( m_probe ) ? GetProbeRadius( m_probe ) : 0.0f; - } - - bool HasGroundSupport() - { - m_contacts.resize( b3MaxInt( 1, b3Body_GetContactCapacity( m_probeId ) ) ); - int contactCount = b3Body_GetContactData( m_probeId, m_contacts.data(), (int)m_contacts.size() ); - for ( int i = 0; i < contactCount; ++i ) - { - const b3ContactData& contact = m_contacts[i]; - for ( int j = 0; j < contact.manifoldCount; ++j ) - { - for ( int k = 0; k < contact.manifolds[j].pointCount; ++k ) - { - if ( contact.manifolds[j].points[k].totalNormalImpulse > 0.0f ) - { - return true; - } - } - } - } - - return false; - } - - void Launch() - { - if ( B3_IS_NON_NULL( m_probeId ) ) - { - b3DestroyBody( m_probeId ); - } - - b3Vec3 start = m_hub + b3Vec3{ m_offset, 0.5f + m_dropHeight, 0.0f }; - m_probeId = CreateProbe( m_probe, b3ToPos( start ), b3Vec3_axisX, m_yaw, 0.0f ); - - // Stands a capsule on its end and a box or cylinder on its side - if ( m_upright ) - { - b3Quat tilt = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 0.5f * B3_PI ); - b3Body_SetTransform( m_probeId, b3ToPos( start ), b3MulQuat( tilt, b3Body_GetRotation( m_probeId ) ) ); - } - - m_runSteps = 0; - m_current = {}; - } - - void Step() override - { - Sample::Step(); - - if ( m_didStep ) - { - b3Vec3 position = b3ToVec3( b3Body_GetWorldCenter( m_probeId ) ); - - b3Vec3 closest; - float distance = b3Body_GetClosestPoint( m_probeId, &closest, m_hub ); - float gap = distance - GetCoreRadius(); - if ( gap <= m_reach ) - { - m_current.reachSteps += 1; - if ( HasGroundSupport() == false ) - { - m_current.unsupportedSteps += 1; - } - - // Inside a hull the query reports zero and the depth is unknown - if ( distance > 0.0f ) - { - m_current.deepest = b3MaxFloat( m_current.deepest, -gap ); - } - } - - m_runSteps += 1; - float radius = sqrtf( position.x * position.x + position.z * position.z ); - bool done = true; - if ( radius < 0.4f * m_fanRadius && position.y < m_hub.y - 0.5f ) - { - m_current.outcome = e_fellThrough; - } - else if ( radius > m_fanRadius + 0.3f || position.y < m_minHeight - 1.0f ) - { - m_current.outcome = e_rolledOff; - } - else if ( m_runSteps >= m_holdSteps ) - { - m_current.outcome = e_held; - } - else - { - done = false; - } - - if ( done ) - { - m_current.valid = true; - m_last = m_current; - m_outcomeCounts[m_current.outcome] += 1; - Launch(); - } - } - - // Direction from the hub to the nearest point of the probe core, straight up once the hub is inside - b3Vec3 closest; - float distance = b3Body_GetClosestPoint( m_probeId, &closest, m_hub ); - b3Vec3 direction = distance > 0.0f ? b3Normalize( closest - m_hub ) : b3Vec3_axisY; - bool fanAdmits = FanAdmits( direction ); - int edgeAdmitCount = 0; - for ( int k = 0; k < m_spokeCount; ++k ) - { - edgeAdmitCount += EdgesAdmit( direction, k ) ? 1 : 0; - } - - if ( m_showCone ) - { - for ( b3Vec3 d : m_coneDirections ) - { - DrawPoint( b3ToPos( m_hub + 0.75f * d ), 4.0f, MakeColor( b3_colorLimeGreen ) ); - } - - b3Vec3 lift = { 0.0f, 0.01f, 0.0f }; - for ( int i = 0; i < m_spokeCount; ++i ) - { - b3HexColor color = m_spokeKinds[i] == e_convexSpoke - ? b3_colorRed - : ( m_spokeKinds[i] == e_concaveSpoke ? b3_colorDodgerBlue : b3_colorGray ); - DrawLine( b3ToPos( m_hub + lift ), b3ToPos( m_ring[i] + lift ), MakeColor( color ) ); - } - - for ( int k = 0; k < m_spokeCount; ++k ) - { - b3Vec3 centroid = ( 1.0f / 3.0f ) * ( m_hub + m_ring[k] + m_ring[( k + 1 ) % m_spokeCount] ) + 2.0f * lift; - b3HexColor color = EdgesAdmit( direction, k ) ? b3_colorLimeGreen : b3_colorRed; - DrawPoint( b3ToPos( centroid ), 10.0f, MakeColor( color ) ); - } - - DrawArrow( b3ToPos( m_hub ), b3ToPos( m_hub + 0.75f * direction ), MakeColor( b3_colorYellow ) ); - } - - DrawTextLine( "hub: %d spokes, %d convex, %d concave, %d flat, the mesh flags it %s", m_spokeCount, m_convexCount, - m_concaveCount, m_flatCount, - m_concaveCount > 0 ? "concave" : ( m_convexCount > 0 ? "convex" : "flat" ) ); - DrawTextLine( "vertex normal cone: %.1f%% of directions, %s", 100.0f * (float)m_coneDirections.size() / (float)m_directionCount, - FanAdmits( b3Vec3_axisY ) ? "contains up" : "does not contain up" ); - DrawTextLine( "probe direction from the hub: the fan %s it, the edge tests admit it on %d of %d fan triangles", - fanAdmits ? "admits" : "rejects", edgeAdmitCount, m_spokeCount ); - DrawTextLine( "green dots: the fan's normal cone, triangle dots: green when the triangle's edge tests admit the arrow" ); - DrawTextLine( "spokes: red convex, blue concave, gray flat" ); - DrawTextLine( "drops: held %d, fell through %d, rolled off %d", m_outcomeCounts[e_held], m_outcomeCounts[e_fellThrough], - m_outcomeCounts[e_rolledOff] ); - - if ( m_last.valid ) - { - const char* outcomeNames[e_outcomeCount] = { "held", "FELL THROUGH", "rolled off" }; - DrawTextLine( "last drop: %s, hub in reach %d steps, %d with no ground contact, deepest %.3f m", - outcomeNames[m_last.outcome], m_last.reachSteps, m_last.unsupportedSteps, m_last.deepest ); - } - else - { - DrawTextLine( "last drop: pending" ); - } - } - - bool DrawControls() override - { - bool rebuild = false; - bool relaunch = false; - - const char* spokeNames[] = { "4", "6", "8", "12" }; - rebuild |= ImGui::Combo( "Spokes", &m_spokeIndex, spokeNames, IM_ARRAYSIZE( spokeNames ) ); - rebuild |= ImGui::SliderFloat( "Slope", &m_slopeDegrees, 5.0f, 30.0f, "%.0f deg" ); - rebuild |= ImGui::SliderFloat( "Gully", &m_gullyDegrees, 0.0f, 40.0f, "%.0f deg" ); - rebuild |= ImGui::SliderFloat( "Jitter", &m_jitter, 0.0f, 0.45f, "%.2f" ); - relaunch |= ImGui::Combo( "Probe", &m_probe, s_probeShapeNames, e_probeShapeCount ); - relaunch |= ImGui::Checkbox( "Upright", &m_upright ); - relaunch |= ImGui::SliderFloat( "Drop Height", &m_dropHeight, 0.0f, 2.0f, "%.2f m" ); - relaunch |= ImGui::SliderFloat( "Offset", &m_offset, 0.0f, 0.5f, "%.2f m" ); - relaunch |= ImGui::SliderFloat( "Yaw", &m_yaw, 0.0f, 45.0f, "%.0f deg" ); - ImGui::Checkbox( "Show Cone", &m_showCone ); - relaunch |= ImGui::Button( "Launch" ); - - if ( rebuild ) - { - BuildGround(); - } - - if ( rebuild || relaunch ) - { - ResetStats(); - Launch(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new SaddleVertex( context ); - } - - static constexpr int m_spokeCounts[4] = { 4, 6, 8, 12 }; - - b3BodyId m_probeId; - int m_spokeIndex; - float m_slopeDegrees; - float m_gullyDegrees; - float m_jitter; - int m_probe; - bool m_upright; - float m_dropHeight; - float m_offset; - float m_yaw; - bool m_showCone; - - int m_spokeCount; - b3Vec3 m_hub; - b3Vec3 m_ring[m_maxSpokes]; - int m_spokeKinds[m_maxSpokes]; - int m_convexCount; - int m_concaveCount; - int m_flatCount; - float m_minHeight; - std::vector m_coneDirections; - - int m_runSteps; - RunStats m_current; - RunStats m_last; - int m_outcomeCounts[e_outcomeCount]; -}; - -static int sampleSaddleVertex = RegisterSample( "Ghost", "Saddle Vertex", SaddleVertex::Create ); - -// A long run through grid vertices. At the 45 degree heading the path meets a vertex in every cell, so -// rare vertex misses add up instead of hiding in one crossing. The wave crests and the default diagonals -// both cross that heading, so the path is a mirror line of the mesh and a clean run keeps its line and -// heading. Diagonals along the path fold the wave cells under it into ridges the body rolls off. -class DiagonalRoll : public GhostSample -{ -public: - static constexpr float m_halfExtent = 20.0f; - static constexpr float m_runLength = 50.0f; - static constexpr int m_settleSteps = 10; - - struct RunStats - { - float startEnergy; - float startKinetic; - float sumSquaredVelocity; - float distance; - float loss; - float lateral; - float drift; - int steps; - int ghosts; - bool valid; - }; - - explicit DiagonalRoll( SampleContext* context ) - : GhostSample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 20.0f, 25.0f, 8.0f, { -17.0f, 0.0f, -17.0f } ); - } - - // Gentle enough that a sphere at 5 m/s keeps contact over the crests - m_wave = true; - m_amplitude = 0.1f; - m_wavelength = 6.0f; - m_cellSize = 0.25f; - m_diagonal = e_diagonalBackward; - m_probe = e_probeSphere; - m_speed = 5.0f; - m_headingDegrees = 45.0f; - m_offset = 0.0f; - m_probeId = b3_nullBodyId; - - BuildGround(); - ResetCounters(); - Launch(); - } - - void ResetCounters() override - { - GhostSample::ResetCounters(); - m_last = {}; - m_runCount = 0; - } - - // Crests run along x + z = constant - float GetHeight( float x, float z ) const - { - if ( m_wave == false ) - { - return 0.0f; - } - - return m_amplitude * sinf( 2.0f * B3_PI * ( x + z ) / ( sqrtf( 2.0f ) * m_wavelength ) ); - } - - void BuildGround() - { - // An even count keeps a vertex at the origin, so the heading line through it meets the vertices - int halfCount = b3MaxInt( 1, (int)( m_halfExtent / m_cellSize + 0.5f ) ); - m_actualCellSize = m_halfExtent / (float)halfCount; - std::vector samples = MakeSamples( -m_halfExtent, m_halfExtent, 2 * halfCount ); - - std::vector vertices; - std::vector indices; - AddGrid( vertices, indices, samples, samples, [&]( int i, int j ) { return GetHeight( samples[i], samples[j] ); }, - m_diagonal ); - CreateGround( vertices, indices ); - } - - b3Vec3 GetDirection() const - { - float angle = m_headingDegrees * B3_DEG_TO_RAD; - return { cosf( angle ), 0.0f, sinf( angle ) }; - } - - void Launch() - { - if ( B3_IS_NON_NULL( m_probeId ) ) - { - b3DestroyBody( m_probeId ); - } - - b3Vec3 d = GetDirection(); - b3Vec3 perp = { -d.z, 0.0f, d.x }; - b3Vec3 start = -0.5f * m_runLength * d + m_offset * perp; - start.y = GetHeight( start.x, start.z ) + GetProbeRadius( m_probe ) + 0.01f; - m_start = start; - - m_probeId = CreateProbe( m_probe, b3ToPos( start ), d, 0.0f, m_speed ); - m_followId = m_probeId; - m_lastHeight = start.y; - - m_current = {}; - m_current.startEnergy = GetSpecificEnergy( m_probeId, b3World_GetGravity( m_worldId ) ); - m_current.startKinetic = GetSpecificKinetic( m_probeId ); - ClearHistory(); - } - - void Finish( RunStats& stats ) const - { - b3Vec3 d = GetDirection(); - b3Vec3 perp = { -d.z, 0.0f, d.x }; - b3Vec3 position = b3ToVec3( b3Body_GetWorldCenter( m_probeId ) ); - b3Vec3 velocity = b3Body_GetLinearVelocity( m_probeId ); - - float lost = stats.startEnergy - GetSpecificEnergy( m_probeId, b3World_GetGravity( m_worldId ) ); - stats.loss = stats.startKinetic > 0.0f ? 100.0f * lost / stats.startKinetic : 0.0f; - stats.lateral = b3Dot( position - m_start, perp ); - stats.drift = atan2f( b3Dot( velocity, perp ), b3Dot( velocity, d ) ) / B3_DEG_TO_RAD; - } - - void Step() override - { - b3Pos center = b3Body_GetWorldCenter( m_probeId ); - - Sample::Step(); - - if ( m_didStep ) - { - m_current.ghosts += CountGhosts( m_probeId, center ); - - b3Vec3 position = b3ToVec3( b3Body_GetWorldCenter( m_probeId ) ); - float verticalSpeed = GetVerticalSpeed( position.y ); - m_current.steps += 1; - - // Skip the drop onto the ground - if ( m_current.steps > m_settleSteps ) - { - m_current.sumSquaredVelocity += verticalSpeed * verticalSpeed; - } - m_current.distance = b3Dot( position - m_start, GetDirection() ); - PushHistory( verticalSpeed ); - - float edge = m_halfExtent - 0.5f; - bool done = m_current.distance > m_runLength || b3AbsFloat( position.x ) > edge || b3AbsFloat( position.z ) > edge || - position.y < -3.0f || m_current.steps > 1800; - if ( done ) - { - Finish( m_current ); - m_current.valid = true; - m_last = m_current; - m_runCount += 1; - Launch(); - } - } - - DrawGhosts(); - - b3Vec3 d = GetDirection(); - b3Vec3 lift = { 0.0f, m_wave ? m_amplitude + 0.02f : 0.02f, 0.0f }; - DrawLine( b3ToPos( m_start + lift ), b3ToPos( m_start + m_runLength * d + lift ), MakeColor( b3_colorYellow ) ); - - DrawTextLine( "cell %.3f m, completed runs %d", m_actualCellSize, m_runCount ); - DrawGhostSummary(); - - RunStats current = m_current; - Finish( current ); - DrawRun( "current", current ); - if ( m_last.valid ) - { - DrawRun( "last", m_last ); - } - } - - void DrawRun( const char* label, const RunStats& stats ) - { - int sampleCount = stats.steps - m_settleSteps; - float rms = sampleCount > 0 ? sqrtf( stats.sumSquaredVelocity / (float)sampleCount ) : 0.0f; - float perMeter = stats.distance > 0.0f ? (float)stats.ghosts / stats.distance : 0.0f; - DrawTextLine( "%s: %.1f m, ghosts %d (%.2f per m), energy loss %.1f%%, rms vy %.3f m/s, lateral %.3f m, drift %.2f deg", - label, stats.distance, stats.ghosts, perMeter, stats.loss, rms, stats.lateral, stats.drift ); - } - - bool DrawControls() override - { - bool rebuild = false; - bool relaunch = false; - - rebuild |= ImGui::Checkbox( "Wave", &m_wave ); - rebuild |= ImGui::SliderFloat( "Amplitude", &m_amplitude, 0.0f, 0.5f, "%.2f m" ); - rebuild |= ImGui::SliderFloat( "Wavelength", &m_wavelength, 1.0f, 10.0f, "%.1f m" ); - rebuild |= ImGui::SliderFloat( "Cell Size", &m_cellSize, 0.2f, 1.0f, "%.2f m" ); - rebuild |= ImGui::Combo( "Diagonals", &m_diagonal, s_diagonalNames, e_diagonalModeCount ); - relaunch |= ImGui::Combo( "Probe", &m_probe, s_probeShapeNames, e_probeShapeCount ); - relaunch |= ImGui::SliderFloat( "Speed", &m_speed, 0.5f, 15.0f, "%.1f m/s" ); - relaunch |= ImGui::SliderFloat( "Heading", &m_headingDegrees, 0.0f, 45.0f, "%.0f deg" ); - relaunch |= ImGui::SliderFloat( "Offset", &m_offset, 0.0f, 0.5f, "%.2f m" ); - relaunch |= ImGui::Button( "Launch" ); - - DrawGhostControls(); - - if ( rebuild ) - { - BuildGround(); - } - - if ( rebuild || relaunch ) - { - ResetCounters(); - Launch(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new DiagonalRoll( context ); - } - - b3BodyId m_probeId; - bool m_wave; - float m_amplitude; - float m_wavelength; - float m_cellSize; - float m_actualCellSize; - int m_diagonal; - int m_probe; - float m_speed; - float m_headingDegrees; - float m_offset; - - b3Vec3 m_start; - RunStats m_current; - RunStats m_last; - int m_runCount; -}; - -static int sampleDiagonalRoll = RegisterSample( "Ghost", "Diagonal Roll", DiagonalRoll::Create ); - -// Large bodies over thousands of triangles of a fine mesh, and a pile of small boxes for the everyday -// cost. Engines that cap the triangles or features they consider per pair can let ghosts back in where -// the cost is highest. Step time comes from the world profile, so the ghost count is not in it. -class FineMeshLoad : public GhostSample -{ -public: - static constexpr int m_timeCapacity = 60; - static constexpr int m_pileCount = 64; - - enum LoadMode - { - e_largeBodies, - e_pile, - e_loadModeCount - }; - - struct LargeStats - { - int manifolds; - int points; - int ghosts; - float peakSpeed; - }; - - explicit FineMeshLoad( SampleContext* context ) - : GhostSample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 30.0f, 30.0f, 30.0f, { 0.0f, 0.0f, 0.0f } ); - } - - m_follow = false; - m_showHistory = false; - m_mode = e_largeBodies; - m_cellIndex = 0; - m_speed = 3.0f; - m_countGhosts = true; - m_wallsId = b3_nullBodyId; - - Build(); - } - - void ResetCounters() override - { - GhostSample::ResetCounters(); - m_timeCount = 0; - m_timeIndex = 0; - m_maxStepTime = 0.0f; - m_stepGhosts = 0; - memset( m_largeStats, 0, sizeof( m_largeStats ) ); - } - - void DestroyBodies() - { - for ( b3BodyId bodyId : m_bodyIds ) - { - b3DestroyBody( bodyId ); - } - m_bodyIds.clear(); - - if ( B3_IS_NON_NULL( m_wallsId ) ) - { - b3DestroyBody( m_wallsId ); - m_wallsId = b3_nullBodyId; - } - } - - void Build() - { - DestroyBodies(); - - std::vector vertices; - std::vector indices; - - if ( m_mode == e_largeBodies ) - { - float cellSize = m_cellSizes[m_cellIndex]; - int xCount = (int)( 32.0f / cellSize + 0.5f ); - int zCount = (int)( 20.0f / cellSize + 0.5f ); - std::vector xs = MakeSamples( -16.0f, 16.0f, xCount ); - std::vector zs = MakeSamples( -10.0f, 10.0f, zCount ); - AddGrid( vertices, indices, xs, zs, []( int, int ) { return 0.0f; }, e_diagonalAlternate ); - CreateGround( vertices, indices ); - LaunchLarge(); - } - else - { - std::vector samples = MakeSamples( -10.0f, 10.0f, 80 ); - auto height = [&]( int i, int j ) { - float k = 2.0f * B3_PI / 4.0f; - return 0.3f * sinf( k * samples[i] ) * sinf( k * samples[j] ); - }; - AddGrid( vertices, indices, samples, samples, height, e_diagonalAlternate ); - CreateGround( vertices, indices ); - CreatePile(); - } - - ResetCounters(); - } - - void LaunchLarge() - { - DestroyBodies(); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.linearVelocity = { m_speed, 0.0f, 0.0f }; - bodyDef.enableSleep = false; - - // Recycling would skip the collision under test on some steps and make the step time bimodal - bodyDef.enableContactRecycling = false; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - - // A 4 m box over about 3200 triangles at the finest cells - bodyDef.position = { -13.0f, 0.5f, -5.0f }; - bodyDef.name = "big box"; - b3BodyId boxId = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull box = b3MakeBoxHull( 2.0f, 0.5f, 2.0f ); - b3CreateHullShape( boxId, &shapeDef, &box.base ); - m_bodyIds.push_back( boxId ); - - // A 6 m capsule lying across the direction of travel - bodyDef.position = { -13.0f, 0.5f, 5.0f }; - bodyDef.name = "long capsule"; - b3BodyId capsuleId = b3CreateBody( m_worldId, &bodyDef ); - b3Capsule capsule = { { 0.0f, 0.0f, -2.5f }, { 0.0f, 0.0f, 2.5f }, 0.5f }; - b3CreateCapsuleShape( capsuleId, &shapeDef, &capsule ); - m_bodyIds.push_back( capsuleId ); - - // Ghosts accumulate over passes, the peak is per pass - m_largeStats[0].peakSpeed = 0.0f; - m_largeStats[1].peakSpeed = 0.0f; - m_passSteps = 0; - } - - void CreatePile() - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "walls"; - m_wallsId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull walls[4] = { - b3MakeOffsetBoxHull( 10.5f, 1.5f, 0.5f, { 0.0f, 1.0f, -10.5f } ), - b3MakeOffsetBoxHull( 10.5f, 1.5f, 0.5f, { 0.0f, 1.0f, 10.5f } ), - b3MakeOffsetBoxHull( 0.5f, 1.5f, 10.5f, { -10.5f, 1.0f, 0.0f } ), - b3MakeOffsetBoxHull( 0.5f, 1.5f, 10.5f, { 10.5f, 1.0f, 0.0f } ), - }; - for ( b3BoxHull& wall : walls ) - { - b3CreateHullShape( m_wallsId, &shapeDef, &wall.base ); - } - - b3BoxHull box = b3MakeBoxHull( 0.1f, 0.1f, 0.1f ); - bodyDef.type = b3_dynamicBody; - bodyDef.name = "pile box"; - float spacing = 0.3f; - float start = -0.5f * spacing * ( m_pileCount - 1 ); - for ( int i = 0; i < m_pileCount; ++i ) - { - for ( int j = 0; j < m_pileCount; ++j ) - { - int index = m_pileCount * i + j; - bodyDef.position = { start + spacing * i, 1.5f, start + spacing * j }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Normalize( { 1.0f, 2.0f, 3.0f } ), 0.37f * (float)index ); - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - m_bodyIds.push_back( bodyId ); - } - } - } - - void Step() override - { - int bodyCount = (int)m_bodyIds.size(); - m_centers.resize( bodyCount ); - for ( int i = 0; i < bodyCount; ++i ) - { - m_centers[i] = b3Body_GetWorldCenter( m_bodyIds[i] ); - } - - Sample::Step(); - - if ( m_didStep ) - { - b3Profile profile = b3World_GetProfile( m_worldId ); - m_stepTimes[m_timeIndex] = profile.step; - m_collideTimes[m_timeIndex] = profile.collide; - m_timeIndex = ( m_timeIndex + 1 ) % m_timeCapacity; - m_timeCount = b3MinInt( m_timeCount + 1, m_timeCapacity ); - m_maxStepTime = b3MaxFloat( m_maxStepTime, profile.step ); - - m_stepGhosts = 0; - if ( m_countGhosts ) - { - for ( int i = 0; i < bodyCount; ++i ) - { - int ghostCount = CountGhosts( m_bodyIds[i], m_centers[i] ); - m_stepGhosts += ghostCount; - if ( m_mode == e_largeBodies ) - { - m_largeStats[i].ghosts += ghostCount; - } - } - } - - if ( m_mode == e_largeBodies ) - { - UpdateLarge(); - } - } - - DrawGhosts(); - - float stepTime = 0.0f; - float collideTime = 0.0f; - for ( int i = 0; i < m_timeCount; ++i ) - { - stepTime += m_stepTimes[i]; - collideTime += m_collideTimes[i]; - } - float scale = m_timeCount > 0 ? 1.0f / (float)m_timeCount : 0.0f; - - DrawTextLine( "step %.2f ms, collide %.2f ms, averaged over %d steps, max step %.2f ms", scale * stepTime, - scale * collideTime, m_timeCount, m_maxStepTime ); - DrawGhostSummary(); - - if ( m_mode == e_largeBodies ) - { - float cellSize = m_cellSizes[m_cellIndex]; - int under = (int)( 16.0f / ( 0.5f * cellSize * cellSize ) ); - DrawTextLine( "triangles under the box: about %d", under ); - const char* names[2] = { "box", "capsule" }; - for ( int i = 0; i < 2; ++i ) - { - const LargeStats& stats = m_largeStats[i]; - DrawTextLine( "%s: manifolds %d, points %d, ghosts %d, peak off plane speed %.3f m/s", names[i], stats.manifolds, - stats.points, stats.ghosts, stats.peakSpeed ); - } - } - else - { - b3Counters counters = b3World_GetCounters( m_worldId ); - DrawTextLine( "bodies %d, awake %d, contacts %d, ghosts this step %d", (int)m_bodyIds.size(), - b3World_GetAwakeBodyCount( m_worldId ), counters.contactCount, m_stepGhosts ); - } - } - - // Off plane speed includes spin, since a ghost on flat ground tips or lifts the body. The first steps - // settle the bodies onto the grid. - void UpdateLarge() - { - m_passSteps += 1; - bool settled = m_passSteps > 10; - bool done = true; - for ( int i = 0; i < 2; ++i ) - { - b3BodyId bodyId = m_bodyIds[i]; - LargeStats& stats = m_largeStats[i]; - - b3ContactData contacts[4]; - int contactCount = b3Body_GetContactData( bodyId, contacts, 4 ); - stats.manifolds = 0; - stats.points = 0; - for ( int j = 0; j < contactCount; ++j ) - { - stats.manifolds += contacts[j].manifoldCount; - for ( int k = 0; k < contacts[j].manifoldCount; ++k ) - { - stats.points += contacts[j].manifolds[k].pointCount; - } - } - - b3Vec3 v = b3Body_GetLinearVelocity( bodyId ); - b3Vec3 w = b3Body_GetAngularVelocity( bodyId ); - float offPlane = b3AbsFloat( v.y ) + b3Length( w ); - stats.peakSpeed = settled ? b3MaxFloat( stats.peakSpeed, offPlane ) : 0.0f; - - done = done && (float)b3Body_GetPosition( bodyId ).x > 13.0f; - } - - if ( done ) - { - LaunchLarge(); - } - } - - bool DrawControls() override - { - bool rebuild = false; - - const char* modeNames[e_loadModeCount] = { "Large Bodies", "Pile" }; - const char* cellNames[] = { "0.1 m", "0.25 m", "0.5 m" }; - rebuild |= ImGui::Combo( "Mode", &m_mode, modeNames, e_loadModeCount ); - if ( m_mode == e_largeBodies ) - { - rebuild |= ImGui::Combo( "Cell Size", &m_cellIndex, cellNames, IM_ARRAYSIZE( cellNames ) ); - if ( ImGui::SliderFloat( "Speed", &m_speed, 0.0f, 10.0f, "%.1f m/s" ) ) - { - LaunchLarge(); - } - } - - rebuild |= ImGui::Button( "Restart" ); - ImGui::Checkbox( "Count Ghosts", &m_countGhosts ); - - DrawGhostControls(); - - if ( rebuild ) - { - Build(); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new FineMeshLoad( context ); - } - - static constexpr float m_cellSizes[3] = { 0.1f, 0.25f, 0.5f }; - - int m_mode; - int m_cellIndex; - float m_speed; - bool m_countGhosts; - - std::vector m_bodyIds; - std::vector m_centers; - b3BodyId m_wallsId; - - LargeStats m_largeStats[2]; - int m_passSteps; - float m_stepTimes[m_timeCapacity]; - float m_collideTimes[m_timeCapacity]; - int m_timeCount; - int m_timeIndex; - float m_maxStepTime; - int m_stepGhosts; -}; - -static int sampleFineMeshLoad = RegisterSample( "Ghost", "Fine Mesh Load", FineMeshLoad::Create ); - -// Ghost collision scenes. The scenes, launch and ghost test live in shared/ghost_collisions.c so the -// headless ghost scan measures the same thing. -class GhostCollisions : public Sample -{ -public: - static constexpr int m_markerCapacity = 256; - - explicit GhostCollisions( SampleContext* context ) - : Sample( context ) - , m_markers{} - { - if ( m_context->restart == false ) - { - m_camera->SetView( 90.0f, 20.0f, 30.0f, { 0.0f, 1.0f, 0.0f } ); - } - - m_data = CreateGhostCollisions( m_worldId, GetDefaultGhostSettings() ); - } - - ~GhostCollisions() override - { - DestroyGhostCollisions( &m_data ); - } - - void Step() override - { - Sample::Step(); - - if ( m_didStep ) - { - GhostReport reports[16]; - int ghostCount = UpdateGhostCollisions( m_worldId, &m_data, reports, IM_ARRAYSIZE( reports ) ); - ghostCount = b3MinInt( ghostCount, IM_ARRAYSIZE( reports ) ); - for ( int i = 0; i < ghostCount; ++i ) - { - m_markers[m_markerIndex] = { reports[i].point, reports[i].normal }; - m_markerIndex = ( m_markerIndex + 1 ) % m_markerCapacity; - m_markerCount = b3MinInt( m_markerCount + 1, m_markerCapacity ); - } - } - - for ( int i = 0; i < m_markerCount; ++i ) - { - b3Pos p = m_markers[i].point; - DrawPoint( p, 8.0f, MakeColor( b3_colorRed ) ); - DrawLine( p, p + 0.5f * m_markers[i].normal, MakeColor( b3_colorRed ) ); - } - - b3Vec3 velocity = b3Body_GetLinearVelocity( m_data.bodyId ); - DrawTextLine( "ghost manifolds: %d this run, %d total over %d runs", m_data.runGhostCount, m_data.ghostCount, - m_data.runCount + 1 ); - DrawTextLine( "speed: %.2f m/s, vertical velocity: %.2f m/s", b3Length( velocity ), velocity.y ); - } - - bool DrawControls() override - { - GhostSettings& settings = m_data.settings; - bool rebuild = false; - bool relaunch = false; - - int scene = (int)settings.scene; - if ( ImGui::Combo( "Scene", &scene, g_ghostSceneNames, e_ghostSceneCount ) ) - { - settings.scene = (GhostScene)scene; - rebuild = true; - - // The chamfer ghost needs the s&box character, a fixed rotation hull without speculative contact - if ( settings.scene == e_ghostChamfer ) - { - settings.fixedRotation = true; - settings.speculative = false; - if ( settings.body != e_ghostBox && settings.body != e_ghostCylinder ) - { - settings.body = e_ghostBox; - } - relaunch = true; - } - - // The beams ghost needs the s&box character hovering on speculative contacts - if ( settings.scene == e_ghostBeams ) - { - settings.fixedRotation = true; - settings.speculative = true; - settings.speed = GHOST_BEAM_SPEED; - if ( settings.body != e_ghostBox && settings.body != e_ghostCylinder ) - { - settings.body = e_ghostBox; - } - relaunch = true; - } - - if ( settings.scene == e_ghostInternal ) - { - m_camera->SetView( 60.0f, 20.0f, 160.0f, { 0.0f, 30.0f, 0.0f } ); - } - else - { - m_camera->SetView( 90.0f, 20.0f, 30.0f, { 0.0f, 1.0f, 0.0f } ); - } - } - - if ( settings.scene == e_ghostInternal ) - { - rebuild |= ImGui::Combo( "Preset", &settings.peelPreset, g_ghostPeelPresetNames, GHOST_PEEL_PRESET_COUNT ); - } - - int body = (int)settings.body; - if ( ImGui::Combo( "Body", &body, g_ghostBodyNames, e_ghostBodyCount ) ) - { - settings.body = (GhostBody)body; - relaunch = true; - } - - rebuild |= ImGui::Checkbox( "Mirror", &settings.mirror ); - rebuild |= ImGui::Checkbox( "Height Field", &settings.heightField ); - rebuild |= ImGui::SliderFloat( "Cell Size", &settings.cellSize, 0.1f, 1.0f, "%.2f m" ); - relaunch |= ImGui::SliderFloat( "Speed", &settings.speed, 0.0f, 15.0f, "%.1f m/s" ); - relaunch |= ImGui::SliderFloat( "Yaw", &settings.yaw, 0.0f, 45.0f, "%.0f deg" ); - relaunch |= ImGui::SliderFloat( "Friction", &settings.friction, 0.0f, 1.0f, "%.2f" ); - relaunch |= ImGui::Checkbox( "Fixed Rotation", &settings.fixedRotation ); - relaunch |= ImGui::Checkbox( "Speculative", &settings.speculative ); - relaunch |= ImGui::Button( "Launch" ); - - if ( ImGui::Button( "Reset Counters" ) ) - { - m_data.ghostCount = 0; - m_data.runGhostCount = 0; - m_data.runCount = 0; - m_markerCount = 0; - m_markerIndex = 0; - } - - if ( rebuild ) - { - CreateGhostGround( m_worldId, &m_data ); - m_markerCount = 0; - m_markerIndex = 0; - } - - if ( rebuild || relaunch ) - { - LaunchGhostBody( m_worldId, &m_data ); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new GhostCollisions( context ); - } - - struct Marker - { - b3Pos point; - b3Vec3 normal; - }; - - GhostCollisionsData m_data; - Marker m_markers[m_markerCapacity]; - int m_markerCount = 0; - int m_markerIndex = 0; -}; - -static int sampleGhostScenarios= RegisterSample( "Ghost", "Scenarios", GhostCollisions::Create ); - -// A closed conveyor circuit swept from a cross section and finely tessellated, so every body slides over -// thousands of internal edges. Belts carry bodies over a washboard, up a spiral lift and a bumpy escalator, -// then off a sharp drop where gravity takes them down a banked trough spiral back to the start. -// A pushing manifold is counted as a ghost when its normal matches no nearby triangle and does not lie -// on the arc between two triangles that meet at a convex crease. -class ConveyorCircuit : public Sample -{ -public: - enum BodyType - { - e_mixedBody, - e_boxBody, - e_capsuleBody, - e_sphereBody, - e_cylinderBody, - e_bodyTypeCount - }; - - static constexpr int m_maxBodies = 300; - static constexpr int m_markerCapacity = 256; - - // Material 0 is the rails and skirts, then the slide, then the belt directions - static constexpr int m_slideMaterial = 1; - static constexpr int m_firstBeltMaterial = 2; - static constexpr int m_yawBinCount = 128; - static constexpr int m_materialCount = m_firstBeltMaterial + m_yawBinCount; - - static constexpr int m_segmentCount = 4; - static constexpr int m_slideSegment = 3; - - // Skirt, lip, inner wall, floor, inner wall, lip, skirt - static constexpr int m_profileSegmentCount = 7; - static constexpr int m_floorSegment = 3; - - // Half turns, so each spiral reverses the heading and the loop closes - static constexpr float m_liftTurns = 2.5f; - static constexpr float m_slideTurns = 1.5f; - - static constexpr float m_radius = 4.5f; - static constexpr float m_straightLength = 16.0f; - static constexpr float m_halfWidth = 1.0f; - static constexpr float m_railHeight = 0.35f; - static constexpr float m_railThickness = 0.08f; - static constexpr float m_skirtDepth = 0.4f; - static constexpr float m_baseHeight = 1.0f; - static constexpr float m_liftHeight = 5.0f; - static constexpr float m_bumpStart = 5.0f; - static constexpr float m_bumpEnd = 11.0f; - static constexpr float m_bumpLength = 1.0f; - static constexpr float m_bumpHeight = 0.06f; - static constexpr float m_escalatorRise = 1.5f; - static constexpr float m_stepLength = 1.5f; - static constexpr float m_stepHeight = 0.15f; - static constexpr float m_dropLength = 2.5f; - static constexpr float m_troughBlendLength = 2.0f; - static constexpr float m_floorArcAngle = 55.0f * B3_DEG_TO_RAD; - static constexpr float m_bankAngle = 20.0f * B3_DEG_TO_RAD; - static constexpr float m_bankRampFraction = 0.2f; - static constexpr float m_spawnDistance = 3.0f; - static constexpr float m_heatBinLength = 1.0f; - static constexpr int m_trackWindow = 6; - - struct Segment - { - float length; - float curvature; - const char* name; - }; - - enum GhostClass - { - e_faceGhost, - e_edgeGhost, - e_vertexGhost, - e_otherGhost, - e_ghostClassCount - }; - - struct Marker - { - b3Pos point; - b3Vec3 normal; - }; - - explicit ConveyorCircuit( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( -135.0f, 35.0f, 27.5f, { 0.0f, -1.0f, 2.0f } ); - } - - AddGroundBox( 30.0f ); - - m_segments[0] = { m_straightLength, 0.0f, "bottom straight" }; - m_segments[1] = { 2.0f * B3_PI * m_radius * m_liftTurns, 1.0f / m_radius, "spiral lift" }; - m_segments[2] = { m_straightLength, 0.0f, "escalator" }; - m_segments[m_slideSegment] = { 2.0f * B3_PI * m_radius * m_slideTurns, 1.0f / m_radius, "slide" }; - - m_totalLength = 0.0f; - for ( int i = 0; i < m_segmentCount; ++i ) - { - m_segmentStart[i] = m_totalLength; - m_totalLength += m_segments[i].length; - } - - m_cylinderHull = b3CreateCylinder( 0.4f, 0.25f, -0.2f, 16 ); - - m_cellSize = 0.4f; - m_beltSpeed = 5.0f; - m_slideFriction = 0.01f; - m_targetCount = 120; - m_spawnInterval = 15; - m_bodyType = e_mixedBody; - m_toleranceDegrees = 10.0f; - m_contactRecycling = true; - m_drawFlow = true; - m_drawGhosts = false; - m_drawHeat = false; - - m_groundId = b3_nullBodyId; - m_bodyCount = 0; - m_spawnIndex = 0; - m_spawnTimer = 0; - - ResetCounters(); - CreateCircuit(); - } - - ~ConveyorCircuit() override - { - DestroyCircuit(); - b3DestroyHull( m_cylinderHull ); - } - - static float SmoothStep( float x ) - { - x = b3ClampFloat( x, 0.0f, 1.0f ); - return x * x * ( 3.0f - 2.0f * x ); - } - - float GetSlideStart() const - { - return m_segmentStart[m_slideSegment]; - } - - float EvaluateHeight( float s ) const - { - float lift0 = m_segmentStart[1]; - float lift1 = m_segmentStart[2]; - float slide0 = GetSlideStart(); - - if ( s < lift0 ) - { - if ( m_bumpStart <= s && s <= m_bumpEnd ) - { - float phase = 2.0f * B3_PI * ( s - m_bumpStart ) / m_bumpLength; - return 0.5f * m_bumpHeight * ( 1.0f - cosf( phase ) ); - } - - return 0.0f; - } - - if ( s < lift1 ) - { - return m_liftHeight * SmoothStep( ( s - lift0 ) / ( lift1 - lift0 ) ); - } - - // Constant grade between parabolic blends, so every step sits on the same slope. The top blend - // levels out at the lip so belt speed bodies fly off the edge instead of following the drop, and - // it shares its length with the trough blend so the steps stay on the flat channel floor. - if ( s < slide0 ) - { - float t = s - lift1; - float length = slide0 - lift1; - float blend = m_troughBlendLength; - float grade = m_escalatorRise / ( length - blend ); - - float height = m_liftHeight; - if ( t < blend ) - { - height += 0.5f * grade * t * t / blend; - } - else if ( t < length - blend ) - { - height += grade * ( t - 0.5f * blend ); - } - else - { - float r = length - t; - height += m_escalatorRise - 0.5f * grade * r * r / blend; - } - - int stepCount = (int)( ( length - 2.0f * blend ) / m_stepLength ); - float stepStart = 0.5f * ( length - stepCount * m_stepLength ); - if ( stepStart <= t && t <= stepStart + stepCount * m_stepLength ) - { - float phase = 2.0f * B3_PI * ( t - stepStart ) / m_stepLength; - height += 0.5f * m_stepHeight * ( 1.0f - cosf( phase ) ); - } - - return height; - } - - // Steepest at the top so slow bodies leaving the belt keep moving, level at the bottom. The drop - // sheds the escalator rise and flattens out where the base curve takes over. - float u = ( s - slide0 ) / m_segments[m_slideSegment].length; - float height = m_liftHeight * ( 1.0f - 1.5f * u + 0.5f * u * u * u ); - - float x = ( s - slide0 ) / m_dropLength; - if ( x < 1.0f ) - { - height += m_escalatorRise * ( 1.0f - sinf( 0.5f * B3_PI * x ) ); - } - - return height; - } - - // Zero for the belt channel and one for the slide trough, blended on the straights at either end - float EvaluateTrough( float s ) const - { - float slide0 = GetSlideStart(); - if ( s >= slide0 ) - { - return 1.0f; - } - - float entry = ( s - ( slide0 - m_troughBlendLength ) ) / m_troughBlendLength; - float exit = 1.0f - s / m_troughBlendLength; - return SmoothStep( b3MaxFloat( entry, exit ) ); - } - - // The slide only turns left, so a positive bank always lowers the inside of the turn - float EvaluateBank( float s ) const - { - float slide0 = GetSlideStart(); - if ( s < slide0 ) - { - return 0.0f; - } - - float u = ( s - slide0 ) / m_segments[m_slideSegment].length; - return m_bankAngle * SmoothStep( b3MinFloat( u, 1.0f - u ) / m_bankRampFraction ); - } - - // Cross section in lateral and up coordinates, traversed with air on the left. The trough bends the - // inner walls and floor onto one circular arc, so channel and trough share a grid and blend smoothly. - b3Vec2 EvaluateProfile( int segment, float alpha, float trough ) const - { - float inner = m_halfWidth; - float outer = m_halfWidth + m_railThickness; - - b3Vec2 channel[m_profileSegmentCount + 1] = { - { -outer, -m_skirtDepth }, { -outer, m_railHeight }, { -inner, m_railHeight }, { -inner, 0.0f }, - { inner, 0.0f }, { inner, m_railHeight }, { outer, m_railHeight }, { outer, -m_skirtDepth }, - }; - - // The lips sit at the top of the arc - b3Vec2 troughCorners[m_profileSegmentCount + 1] = { - { -outer, -m_skirtDepth }, { -outer, inner }, { -inner, inner }, {}, {}, { inner, inner }, { outer, inner }, - { outer, -m_skirtDepth }, - }; - - b3Vec2 a = channel[segment]; - b3Vec2 b = channel[segment + 1]; - b3Vec2 p = { a.x + alpha * ( b.x - a.x ), a.y + alpha * ( b.y - a.y ) }; - - b3Vec2 q; - if ( m_floorSegment - 1 <= segment && segment <= m_floorSegment + 1 ) - { - float angles[4] = { -0.5f * B3_PI, -m_floorArcAngle, m_floorArcAngle, 0.5f * B3_PI }; - int i = segment - ( m_floorSegment - 1 ); - float angle = angles[i] + alpha * ( angles[i + 1] - angles[i] ); - q = { inner * sinf( angle ), inner * ( 1.0f - cosf( angle ) ) }; - } - else - { - b3Vec2 ta = troughCorners[segment]; - b3Vec2 tb = troughCorners[segment + 1]; - q = { ta.x + alpha * ( tb.x - ta.x ), ta.y + alpha * ( tb.y - ta.y ) }; - } - - return { p.x + trough * ( q.x - p.x ), p.y + trough * ( q.y - p.y ) }; - } - - float GetProfileLength( int segment, float trough ) const - { - int sampleCount = 8; - float length = 0.0f; - b3Vec2 a = EvaluateProfile( segment, 0.0f, trough ); - for ( int i = 1; i <= sampleCount; ++i ) - { - b3Vec2 b = EvaluateProfile( segment, (float)i / (float)sampleCount, trough ); - length += sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) ); - a = b; - } - - return length; - } - - b3Vec3 EvaluateCenter( float s ) const - { - float x = -0.5f * m_straightLength; - float z = -m_radius; - float yaw = 0.0f; - float remaining = s; - - for ( int i = 0; i < m_segmentCount && remaining > 0.0f; ++i ) - { - float ds = b3MinFloat( remaining, m_segments[i].length ); - float k = m_segments[i].curvature; - if ( k == 0.0f ) - { - x += ds * cosf( yaw ); - z += ds * sinf( yaw ); - } - else - { - float yaw1 = yaw + k * ds; - x += ( sinf( yaw1 ) - sinf( yaw ) ) / k; - z -= ( cosf( yaw1 ) - cosf( yaw ) ) / k; - yaw = yaw1; - } - - remaining -= ds; - } - - return { x, m_baseHeight + EvaluateHeight( s ), z }; - } - - void BuildStations() - { - int count = b3MaxInt( 32, (int)ceilf( m_totalLength / m_cellSize ) ); - m_stations.resize( count ); - m_stationDistances.resize( count ); - m_tangents.resize( count ); - m_laterals.resize( count ); - m_ups.resize( count ); - m_troughs.resize( count ); - - for ( int k = 0; k < count; ++k ) - { - float s = m_totalLength * (float)k / (float)count; - m_stationDistances[k] = s; - m_stations[k] = EvaluateCenter( s ); - m_troughs[k] = EvaluateTrough( s ); - } - - // The chord across each station bisects a crease, so the rails stay square to the belt - for ( int k = 0; k < count; ++k ) - { - b3Vec3 next = m_stations[( k + 1 ) % count]; - b3Vec3 prev = m_stations[( k + count - 1 ) % count]; - b3Vec3 t = b3Normalize( next - prev ); - b3Vec3 l = b3Normalize( b3Cross( t, b3Vec3_axisY ) ); - b3Vec3 u = b3Cross( l, t ); - - float bank = EvaluateBank( m_stationDistances[k] ); - float c = cosf( bank ); - float s = sinf( bank ); - m_tangents[k] = t; - m_laterals[k] = c * l - s * u; - m_ups[k] = c * u + s * l; - } - } - - b3SurfaceMaterial MakeMaterial( int index ) const - { - b3SurfaceMaterial material = b3DefaultSurfaceMaterial(); - if ( index == 0 ) - { - material.friction = 0.2f; - material.customColor = b3_colorCadetBlue; - return material; - } - - if ( index == m_slideMaterial ) - { - material.friction = m_slideFriction; - material.customColor = b3_colorSilver; - return material; - } - - // Horizontal is enough, the solver projects tangent velocity onto the contact plane - float yaw = -B3_PI + 2.0f * B3_PI * (float)( index - m_firstBeltMaterial ) / (float)m_yawBinCount; - material.friction = 0.8f; - material.tangentVelocity = { m_beltSpeed * cosf( yaw ), 0.0f, m_beltSpeed * sinf( yaw ) }; - material.customColor = b3_colorLightSteelBlue; - return material; - } - - int GetStationMaterial( int station, int profileSegment ) const - { - bool slide = m_stationDistances[station] >= GetSlideStart(); - if ( slide && m_floorSegment - 1 <= profileSegment && profileSegment <= m_floorSegment + 1 ) - { - return m_slideMaterial; - } - - if ( slide == false && profileSegment == m_floorSegment ) - { - int stationCount = (int)m_stations.size(); - b3Vec3 direction = m_stations[( station + 1 ) % stationCount] - m_stations[station]; - float yaw = atan2f( direction.z, direction.x ); - int bin = (int)floorf( ( yaw + B3_PI ) / ( 2.0f * B3_PI ) * m_yawBinCount + 0.5f ); - return m_firstBeltMaterial + bin % m_yawBinCount; - } - - return 0; - } - - void CreateCircuit() - { - BuildStations(); - - // The last row repeats the first station and welds to it, closing the loop - int stationCount = (int)m_stations.size(); - - // Every station shares one column layout, sized for the longer of the two sections - int columnCounts[m_profileSegmentCount]; - int columnTotal = 0; - for ( int j = 0; j < m_profileSegmentCount; ++j ) - { - float length = b3MaxFloat( GetProfileLength( j, 0.0f ), GetProfileLength( j, 1.0f ) ); - columnCounts[j] = b3MaxInt( 1, (int)ceilf( length / m_cellSize - 0.01f ) ); - columnTotal += columnCounts[j]; - } - - int stride = columnTotal + 1; - - std::vector vertices; - std::vector indices; - std::vector materialIndices; - vertices.reserve( ( stationCount + 1 ) * stride ); - - m_lipPoints.resize( stationCount ); - for ( int k = 0; k <= stationCount; ++k ) - { - int station = k % stationCount; - b3Vec3 center = m_stations[station]; - b3Vec3 lateral = m_laterals[station]; - b3Vec3 up = m_ups[station]; - float trough = m_troughs[station]; - - b3Vec2 p = EvaluateProfile( 0, 0.0f, trough ); - vertices.push_back( center + p.x * lateral + p.y * up ); - - for ( int j = 0; j < m_profileSegmentCount; ++j ) - { - for ( int i = 1; i <= columnCounts[j]; ++i ) - { - p = EvaluateProfile( j, (float)i / (float)columnCounts[j], trough ); - vertices.push_back( center + p.x * lateral + p.y * up ); - } - } - - if ( k < stationCount ) - { - p = EvaluateProfile( 1, 0.0f, trough ); - m_lipPoints[k] = center + p.x * lateral + p.y * up; - } - } - - for ( int k = 0; k < stationCount; ++k ) - { - int column = 0; - for ( int j = 0; j < m_profileSegmentCount; ++j ) - { - int material = GetStationMaterial( k, j ); - - for ( int i = 0; i < columnCounts[j]; ++i, ++column ) - { - int a = k * stride + column; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - - // Air is on the left of the profile direction - b3Vec3 expected = b3Cross( vertices[b] - vertices[a], m_tangents[k] ); - - int corners[6] = { a, b, c, c, d, a }; - if ( ( k + column ) & 1 ) - { - int flipped[6] = { a, b, d, b, c, d }; - memcpy( corners, flipped, sizeof( corners ) ); - } - - for ( int n = 0; n < 6; n += 3 ) - { - b3Vec3 v1 = vertices[corners[n]]; - b3Vec3 v2 = vertices[corners[n + 1]]; - b3Vec3 v3 = vertices[corners[n + 2]]; - bool reversed = b3Dot( b3Cross( v2 - v1, v3 - v1 ), expected ) < 0.0f; - - indices.push_back( corners[n] ); - indices.push_back( reversed ? corners[n + 2] : corners[n + 1] ); - indices.push_back( reversed ? corners[n + 1] : corners[n + 2] ); - materialIndices.push_back( (uint8_t)material ); - } - } - } - } - - b3MeshDef meshDef = {}; - meshDef.vertices = vertices.data(); - meshDef.indices = indices.data(); - meshDef.materialIndices = materialIndices.data(); - meshDef.vertexCount = (int)vertices.size(); - meshDef.triangleCount = (int)( indices.size() / 3 ); - meshDef.weldVertices = true; - meshDef.weldTolerance = 0.001f; - meshDef.identifyEdges = true; - - m_mesh = b3CreateMesh( &meshDef, nullptr, 0 ); - - b3SurfaceMaterial materials[m_materialCount]; - for ( int i = 0; i < m_materialCount; ++i ) - { - materials[i] = MakeMaterial( i ); - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "circuit"; - m_groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.materials = materials; - shapeDef.materialCount = m_materialCount; - m_shapeId = b3CreateMeshShape( m_groundId, &shapeDef, m_mesh, b3Vec3_one ); - - BuildAdjacency(); - - m_heatBinCount = b3MaxInt( 1, (int)( m_totalLength / m_heatBinLength + 0.5f ) ); - m_binGhosts.assign( m_heatBinCount, 0 ); - m_binManifolds.assign( m_heatBinCount, 0 ); - - // Station indices changed, so every body needs a fresh search - for ( int i = 0; i < m_bodyCount; ++i ) - { - m_bodyStations[i] = B3_NULL_INDEX; - } - - m_markerCount = 0; - m_markerIndex = 0; - } - - // The body holding the mesh shapes must go before the mesh data - void DestroyCircuit() - { - if ( B3_IS_NON_NULL( m_groundId ) ) - { - b3DestroyBody( m_groundId ); - m_groundId = b3_nullBodyId; - } - - if ( m_mesh != nullptr ) - { - b3DestroyMesh( m_mesh ); - m_mesh = nullptr; - } - } - - void UpdateMaterials() - { - for ( int i = 1; i < m_materialCount; ++i ) - { - b3Shape_SetMeshMaterial( m_shapeId, MakeMaterial( i ), i ); - } - } - - b3Pos GetSpawnPosition() const - { - b3Vec3 center = EvaluateCenter( m_spawnDistance ); - float lateral = RandomFloatRange( -0.6f, 0.6f ); - return b3ToPos( { center.x, center.y + 1.2f, center.z + lateral } ); - } - - void SpawnBody() - { - int type = m_bodyType == e_mixedBody ? 1 + m_spawnIndex % ( e_bodyTypeCount - 1 ) : m_bodyType; - m_spawnIndex += 1; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = GetSpawnPosition(); - bodyDef.rotation = RandomQuat(); - - // A jammed body would fall asleep on a moving belt - bodyDef.enableSleep = false; - bodyDef.enableContactRecycling = m_contactRecycling; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.6f; - - // Round bodies would roll back down the helix without it - shapeDef.baseMaterial.rollingResistance = 0.3f; - - switch ( type ) - { - case e_boxBody: - { - float halfLength = ( m_spawnIndex & 1 ) ? 0.4f : 0.25f; - b3BoxHull box = b3MakeBoxHull( halfLength, 0.15f, 0.25f ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - break; - - case e_capsuleBody: - { - b3Capsule capsule = { { -0.3f, 0.0f, 0.0f }, { 0.3f, 0.0f, 0.0f }, 0.15f }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - break; - - case e_sphereBody: - { - b3Sphere sphere = { b3Vec3_zero, 0.25f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - break; - - default: - b3CreateHullShape( bodyId, &shapeDef, m_cylinderHull ); - break; - } - - m_bodyIds[m_bodyCount] = bodyId; - m_bodyStations[m_bodyCount] = B3_NULL_INDEX; - m_bodyCount += 1; - } - - void DestroyBodies() - { - for ( int i = 0; i < m_bodyCount; ++i ) - { - b3DestroyBody( m_bodyIds[i] ); - } - - m_bodyCount = 0; - m_spawnIndex = 0; - m_spawnTimer = 0; - } - - void ResetCounters() - { - memset( m_classCounts, 0, sizeof( m_classCounts ) ); - memset( m_flagCounts, 0, sizeof( m_flagCounts ) ); - m_ghostCount = 0; - m_manifoldCount = 0; - m_stepGhostCount = 0; - m_recycleCount = 0; - m_markerCount = 0; - m_markerIndex = 0; - std::fill( m_binGhosts.begin(), m_binGhosts.end(), 0 ); - std::fill( m_binManifolds.begin(), m_binManifolds.end(), 0 ); - } - - // Bodies move far less than a station per step, so a local search follows a body along the track and - // keeps it from snapping to a spiral layer above or below. A body that fell off gets a full search. - int FindStation( b3Vec3 point, int hint ) const - { - int count = (int)m_stations.size(); - int best = 0; - float bestDistanceSquared = FLT_MAX; - - if ( hint != B3_NULL_INDEX ) - { - for ( int offset = -m_trackWindow; offset <= m_trackWindow; ++offset ) - { - int k = ( hint + offset + count ) % count; - float distanceSquared = b3LengthSquared( point - m_stations[k] ); - if ( distanceSquared < bestDistanceSquared ) - { - bestDistanceSquared = distanceSquared; - best = k; - } - } - - if ( bestDistanceSquared < 4.0f ) - { - return best; - } - } - - for ( int k = 0; k < count; ++k ) - { - float distanceSquared = b3LengthSquared( point - m_stations[k] ); - if ( distanceSquared < bestDistanceSquared ) - { - bestDistanceSquared = distanceSquared; - best = k; - } - } - - return best; - } - - int GetHeatBin( int station ) const - { - return (int)( (int64_t)station * m_heatBinCount / (int64_t)m_stations.size() ); - } - - const char* GetSegmentName( float s ) const - { - int segment = 0; - while ( segment + 1 < m_segmentCount && s >= m_segmentStart[segment + 1] ) - { - segment += 1; - } - - return m_segments[segment].name; - } - - void BuildAdjacency() - { - int triangleCount = m_mesh->triangleCount; - int vertexCount = m_mesh->vertexCount; - const b3MeshTriangle* triangles = b3GetMeshTriangles( m_mesh ); - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - - m_triangleNormals.resize( triangleCount ); - m_edgeNeighbors.assign( 3 * triangleCount, B3_NULL_INDEX ); - m_vertexRings.assign( vertexCount, {} ); - m_vertexTriangles.assign( vertexCount, {} ); - - // Sorting by vertex pair puts the two sides of a shared edge next to each other - std::vector> edges; - edges.reserve( 3 * triangleCount ); - - for ( int t = 0; t < triangleCount; ++t ) - { - int v[3] = { triangles[t].index1, triangles[t].index2, triangles[t].index3 }; - m_triangleNormals[t] = - b3Normalize( b3Cross( vertices[v[1]] - vertices[v[0]], vertices[v[2]] - vertices[v[0]] ) ); - - for ( int e = 0; e < 3; ++e ) - { - int a = v[e]; - int b = v[e < 2 ? e + 1 : 0]; - uint64_t key = ( (uint64_t)b3MinInt( a, b ) << 32 ) | (uint64_t)b3MaxInt( a, b ); - edges.push_back( { key, 3 * t + e } ); - m_vertexRings[a].push_back( b ); - m_vertexRings[b].push_back( a ); - m_vertexTriangles[a].push_back( t ); - } - } - - std::sort( edges.begin(), edges.end() ); - for ( size_t i = 0; i + 1 < edges.size(); ++i ) - { - // A non-manifold edge leaves every side without a neighbor - uint64_t key = edges[i].first; - bool pair = edges[i + 1].first == key; - bool single = - ( i + 2 >= edges.size() || edges[i + 2].first != key ) && ( i == 0 || edges[i - 1].first != key ); - if ( pair && single ) - { - m_edgeNeighbors[edges[i].second] = edges[i + 1].second / 3; - m_edgeNeighbors[edges[i + 1].second] = edges[i].second / 3; - } - } - - for ( std::vector& ring : m_vertexRings ) - { - std::sort( ring.begin(), ring.end() ); - ring.erase( std::unique( ring.begin(), ring.end() ), ring.end() ); - } - } - - bool MatchesFace( b3Vec3 normal, int triangleIndex ) const - { - return b3Dot( normal, m_triangleNormals[triangleIndex] ) >= m_cosTolerance; - } - - // Direction in the face plane pointing away from the edge into the face - static b3Vec3 GetInwardDirection( b3Vec3 edgeStart, b3Vec3 axis, b3Vec3 opposite ) - { - b3Vec3 d = opposite - edgeStart; - return b3Normalize( d - b3Dot( d, axis ) * axis ); - } - - // The normal cone of a convex edge is the arc between its two face normals. Neither face may rise - // above the edge along the normal, so a concave edge only admits its face normals. - bool AdmitsEdge( b3Vec3 normal, int triangleIndex, int edgeIndex ) const - { - int neighbor = m_edgeNeighbors[3 * triangleIndex + edgeIndex]; - if ( MatchesFace( normal, triangleIndex ) || ( neighbor != B3_NULL_INDEX && MatchesFace( normal, neighbor ) ) ) - { - return true; - } - - const b3MeshTriangle* triangles = b3GetMeshTriangles( m_mesh ); - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - int v[3] = { triangles[triangleIndex].index1, triangles[triangleIndex].index2, - triangles[triangleIndex].index3 }; - int ia = v[edgeIndex]; - int ib = v[edgeIndex < 2 ? edgeIndex + 1 : 0]; - int ic = v[edgeIndex > 0 ? edgeIndex - 1 : 2]; - - b3Vec3 a = vertices[ia]; - b3Vec3 axis = b3Normalize( vertices[ib] - a ); - if ( b3AbsFloat( b3Dot( normal, axis ) ) > m_sinTolerance ) - { - return false; - } - - if ( b3Dot( normal, GetInwardDirection( a, axis, vertices[ic] ) ) > m_sinTolerance ) - { - return false; - } - - if ( neighbor != B3_NULL_INDEX ) - { - int w[3] = { triangles[neighbor].index1, triangles[neighbor].index2, triangles[neighbor].index3 }; - for ( int k = 0; k < 3; ++k ) - { - if ( w[k] != ia && w[k] != ib && - b3Dot( normal, GetInwardDirection( a, axis, vertices[w[k]] ) ) > m_sinTolerance ) - { - return false; - } - } - } - - return true; - } - - // A vertex normal is valid when the vertex is a local support point in that direction - bool AdmitsVertex( b3Vec3 normal, int vertexIndex ) const - { - for ( int t : m_vertexTriangles[vertexIndex] ) - { - if ( MatchesFace( normal, t ) ) - { - return true; - } - } - - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - b3Vec3 vertex = vertices[vertexIndex]; - for ( int other : m_vertexRings[vertexIndex] ) - { - if ( b3Dot( normal, b3Normalize( vertices[other] - vertex ) ) > m_sinTolerance ) - { - return false; - } - } - - return true; - } - - bool AdmitsPoint( b3Vec3 normal, const b3ManifoldPoint& point ) const - { - const b3MeshTriangle& triangle = b3GetMeshTriangles( m_mesh )[point.triangleIndex]; - int v[3] = { triangle.index1, triangle.index2, triangle.index3 }; - - switch ( point.triangleFeature ) - { - case b3_featureTriangleFace: - return MatchesFace( normal, point.triangleIndex ); - - case b3_featureEdge1: - case b3_featureEdge2: - case b3_featureEdge3: - return AdmitsEdge( normal, point.triangleIndex, point.triangleFeature - b3_featureEdge1 ); - - case b3_featureVertex1: - case b3_featureVertex2: - case b3_featureVertex3: - return AdmitsVertex( normal, v[point.triangleFeature - b3_featureVertex1] ); - - default: - // No feature was resolved, so any feature of the triangle may own the normal - if ( MatchesFace( normal, point.triangleIndex ) ) - { - return true; - } - - for ( int k = 0; k < 3; ++k ) - { - if ( AdmitsEdge( normal, point.triangleIndex, k ) || AdmitsVertex( normal, v[k] ) ) - { - return true; - } - } - - return false; - } - } - - static GhostClass Classify( const b3ManifoldPoint& point ) - { - switch ( point.triangleFeature ) - { - case b3_featureTriangleFace: - return e_faceGhost; - - case b3_featureEdge1: - case b3_featureEdge2: - case b3_featureEdge3: - return e_edgeGhost; - - case b3_featureVertex1: - case b3_featureVertex2: - case b3_featureVertex3: - return e_vertexGhost; - - default: - return e_otherGhost; - } - } - - void CountGhosts( b3BodyId bodyId, b3Pos center, int heatBin ) - { - // Clustering merges manifolds whose normals agree within its threshold and hands them one normal, - // so a point may carry a normal that far from its own feature - float angle = m_toleranceDegrees * B3_DEG_TO_RAD + acosf( 0.996f ); - m_cosTolerance = cosf( angle ); - m_sinTolerance = sinf( angle ); - - b3ContactData contacts[16]; - int contactCount = b3Body_GetContactData( bodyId, contacts, 16 ); - - for ( int i = 0; i < contactCount; ++i ) - { - bool bodyIsA = B3_ID_EQUALS( b3Shape_GetBody( contacts[i].shapeIdA ), bodyId ); - b3ShapeId otherId = bodyIsA ? contacts[i].shapeIdB : contacts[i].shapeIdA; - if ( b3Shape_GetType( otherId ) != b3_meshShape ) - { - continue; - } - - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - const b3Manifold* manifold = contacts[i].manifolds + j; - b3Vec3 normal = bodyIsA ? b3Neg( manifold->normal ) : manifold->normal; - - // Speculative points that never pushed are harmless. Clustering hands every point the normal - // of one member, so the manifold is sound if any pushing point owns that normal. - int pushCount = 0; - int firstPush = 0; - bool admitted = false; - for ( int k = 0; k < manifold->pointCount && admitted == false; ++k ) - { - const b3ManifoldPoint& point = manifold->points[k]; - if ( point.totalNormalImpulse <= 0.0f ) - { - continue; - } - - firstPush = pushCount == 0 ? k : firstPush; - pushCount += 1; - admitted = AdmitsPoint( normal, point ); - } - - if ( pushCount == 0 ) - { - continue; - } - - m_manifoldCount += 1; - m_binManifolds[heatBin] += 1; - - if ( admitted ) - { - continue; - } - - const b3ManifoldPoint& point = manifold->points[firstPush]; - m_ghostCount += 1; - m_binGhosts[heatBin] += 1; - m_stepGhostCount += 1; - m_classCounts[Classify( point )] += 1; - for ( int bit = 0; bit < m_flagCount; ++bit ) - { - m_flagCounts[bit] += ( point.meshFlags >> bit ) & 1; - } - - b3Vec3 anchor = bodyIsA ? point.anchorA : point.anchorB; - m_markers[m_markerIndex] = { b3OffsetPos( center, anchor ), normal }; - m_markerIndex = ( m_markerIndex + 1 ) % m_markerCapacity; - m_markerCount = b3MinInt( m_markerCount + 1, m_markerCapacity ); - } - } - } - - void Step() override - { - // Contacts are computed at the start of the step and anchors stay relative to that body position. - // A fast body moves past the margin within a step, so the end position would query the wrong triangles. - for ( int i = 0; i < m_bodyCount; ++i ) - { - m_contactCenters[i] = b3Body_GetWorldCenter( m_bodyIds[i] ); - } - - Sample::Step(); - - if ( m_didStep ) - { - m_stepGhostCount = 0; - - for ( int i = 0; i < m_bodyCount; ++i ) - { - b3BodyId bodyId = m_bodyIds[i]; - b3Pos position = b3Body_GetPosition( bodyId ); - - // Off the belt and on the ground, so drop it back in at the start - if ( position.y < m_baseHeight - 0.5f ) - { - b3Body_SetTransform( bodyId, GetSpawnPosition(), RandomQuat() ); - b3Body_SetLinearVelocity( bodyId, b3Vec3_zero ); - b3Body_SetAngularVelocity( bodyId, b3Vec3_zero ); - m_bodyStations[i] = B3_NULL_INDEX; - m_recycleCount += 1; - continue; - } - - m_bodyStations[i] = FindStation( b3ToVec3( m_contactCenters[i] ), m_bodyStations[i] ); - CountGhosts( bodyId, m_contactCenters[i], GetHeatBin( m_bodyStations[i] ) ); - } - - m_spawnTimer += 1; - if ( m_bodyCount < m_targetCount && m_spawnTimer >= m_spawnInterval ) - { - SpawnBody(); - m_spawnTimer = 0; - } - } - -#if 0 - float rate = m_manifoldCount > 0 ? 1.0e6f * (float)m_ghostCount / (float)m_manifoldCount : 0.0f; - DrawTextLine( "ghost manifolds: %d this step, %d of %d pushing (%.0f ppm)", m_stepGhostCount, m_ghostCount, - m_manifoldCount, rate ); - DrawTextLine( "ghost feature: face %d, edge %d, vertex %d, unresolved %d", m_classCounts[e_faceGhost], - m_classCounts[e_edgeGhost], m_classCounts[e_vertexGhost], m_classCounts[e_otherGhost] ); - DrawTextLine( "ghost origin: hull face %d, snapped %d, deep %d", m_flagCounts[0], m_flagCounts[1], - m_flagCounts[2] ); - int worstBin = 0; - for ( int i = 1; i < m_heatBinCount; ++i ) - { - worstBin = m_binGhosts[i] > m_binGhosts[worstBin] ? i : worstBin; - } - - if ( m_binGhosts[worstBin] > 0 ) - { - float s = ( (float)worstBin + 0.5f ) * m_totalLength / (float)m_heatBinCount; - float binRate = 1.0e6f * (float)m_binGhosts[worstBin] / (float)m_binManifolds[worstBin]; - DrawTextLine( "worst metre: %.0f m along the %s, %d ghosts (%.0f ppm)", s, GetSegmentName( s ), - m_binGhosts[worstBin], binRate ); - } - else - { - DrawTextLine( "worst metre: none" ); - } - - DrawTextLine( "bodies: %d, recycled: %d", m_bodyCount, m_recycleCount ); - DrawTextLine( "triangles: %d, stations: %d, length: %.0f m", m_mesh->triangleCount, (int)m_stations.size(), - m_totalLength ); -#endif - } - - void Render() override - { - Sample::Render(); - - int stationCount = (int)m_stations.size(); - - if ( m_drawFlow ) - { - int stride = b3MaxInt( 1, stationCount / 96 ); - float slide0 = GetSlideStart(); - for ( int k = 0; k < stationCount; k += stride ) - { - if ( m_stationDistances[k] >= slide0 ) - { - continue; - } - - b3Vec3 p = m_stations[k] + 0.05f * m_ups[k]; - b3Vec3 t = m_tangents[k]; - DrawArrow( b3ToPos( p ), b3ToPos( p + 0.25f * m_beltSpeed * t ), MakeColor( b3_colorGold ) ); - } - } - - if ( m_drawHeat ) - { - DrawHeat(); - } - - if ( m_drawGhosts ) - { - for ( int i = 0; i < m_markerCount; ++i ) - { - b3Pos p = m_markers[i].point; - DrawPoint( p, 8.0f, MakeColor( b3_colorRed ) ); - DrawLine( p, p + 0.5f * m_markers[i].normal, MakeColor( b3_colorRed ) ); - } - } - } - - // The strip runs along the outer lip. Each metre of track is a tick, gray before any traffic and green - // while clean. Ghosts raise a bar whose height follows the count and whose color runs from gold to red - // with the rate. - void DrawHeat() - { - int stationCount = (int)m_stations.size(); - - int maxGhosts = 1; - float maxRate = 0.0f; - for ( int i = 0; i < m_heatBinCount; ++i ) - { - maxGhosts = b3MaxInt( maxGhosts, m_binGhosts[i] ); - if ( m_binManifolds[i] > 0 ) - { - maxRate = b3MaxFloat( maxRate, (float)m_binGhosts[i] / (float)m_binManifolds[i] ); - } - } - - Vec4 idle = MakeColor( b3_colorDimGray ); - Vec4 clean = MakeColor( b3_colorLimeGreen ); - Vec4 low = MakeColor( b3_colorGold ); - Vec4 high = MakeColor( b3_colorRed ); - - for ( int i = 0; i < m_heatBinCount; ++i ) - { - int first = (int)( (int64_t)i * stationCount / m_heatBinCount ); - int last = (int)( (int64_t)( i + 1 ) * stationCount / m_heatBinCount ); - b3Vec3 a = m_lipPoints[first] + 0.05f * b3Vec3_axisY; - b3Vec3 b = m_lipPoints[last % stationCount] + 0.05f * b3Vec3_axisY; - - Vec4 color = m_binManifolds[i] > 0 ? clean : idle; - DrawLineEx( b3ToPos( a ), b3ToPos( b ), color, 0.04f, OVERLAY_THICKNESS_WORLD, OVERLAY_OCCLUSION_DIM ); - - if ( m_binGhosts[i] == 0 ) - { - continue; - } - - float rate = (float)m_binGhosts[i] / (float)m_binManifolds[i]; - float t = maxRate > 0.0f ? rate / maxRate : 1.0f; - Vec4 barColor = MakeVec4( low.x + t * ( high.x - low.x ), low.y + t * ( high.y - low.y ), - low.z + t * ( high.z - low.z ), 1.0f ); - - float height = 0.2f + 1.8f * (float)m_binGhosts[i] / (float)maxGhosts; - b3Vec3 base = m_lipPoints[( first + last ) / 2 % stationCount]; - DrawLineEx( b3ToPos( base ), b3ToPos( base + height * b3Vec3_axisY ), barColor, 0.08f, - OVERLAY_THICKNESS_WORLD, OVERLAY_OCCLUSION_DIM ); - } - } - - bool DrawControls() override - { - bool rebuild = false; - bool respawn = false; - - ImGui::SliderFloat( "Cell Size", &m_cellSize, 0.1f, 0.5f, "%.2f m" ); - rebuild |= ImGui::IsItemDeactivatedAfterEdit(); - - if ( ImGui::SliderFloat( "Belt Speed", &m_beltSpeed, 0.0f, 6.0f, "%.1f m/s" ) ) - { - UpdateMaterials(); - } - - if ( ImGui::SliderFloat( "Slide Friction", &m_slideFriction, 0.0f, 0.2f, "%.3f" ) ) - { - UpdateMaterials(); - } - - ImGui::SliderInt( "Body Count", &m_targetCount, 1, m_maxBodies ); - ImGui::SliderInt( "Spawn Interval", &m_spawnInterval, 1, 60 ); - - const char* bodyNames[e_bodyTypeCount] = { "Mixed", "Box", "Capsule", "Sphere", "Cylinder" }; - int bodyType = m_bodyType; - if ( ImGui::Combo( "Bodies", &bodyType, bodyNames, e_bodyTypeCount ) ) - { - m_bodyType = (BodyType)bodyType; - respawn = true; - } - - if ( ImGui::Checkbox( "Contact Recycling", &m_contactRecycling ) ) - { - for ( int i = 0; i < m_bodyCount; ++i ) - { - b3Body_EnableContactRecycling( m_bodyIds[i], m_contactRecycling ); - } - } - - ImGui::SliderFloat( "Ghost Tolerance", &m_toleranceDegrees, 1.0f, 20.0f, "%.0f deg" ); - ImGui::Checkbox( "Draw Flow", &m_drawFlow ); - ImGui::Checkbox( "Draw Ghosts", &m_drawGhosts ); - ImGui::Checkbox( "Draw Heat", &m_drawHeat ); - - respawn |= ImGui::Button( "Respawn" ); - if ( ImGui::Button( "Reset Counters" ) ) - { - ResetCounters(); - } - - if ( rebuild ) - { - DestroyCircuit(); - CreateCircuit(); - ResetCounters(); - } - - if ( respawn ) - { - DestroyBodies(); - ResetCounters(); - } - - // Shrinking the count drops the newest bodies - while ( m_bodyCount > m_targetCount ) - { - m_bodyCount -= 1; - b3DestroyBody( m_bodyIds[m_bodyCount] ); - } - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new ConveyorCircuit( context ); - } - - Segment m_segments[m_segmentCount]; - float m_segmentStart[m_segmentCount]; - float m_totalLength; - - std::vector m_stations; - std::vector m_stationDistances; - std::vector m_tangents; - std::vector m_laterals; - std::vector m_ups; - std::vector m_troughs; - std::vector m_lipPoints; - - int m_heatBinCount = 1; - std::vector m_binGhosts; - std::vector m_binManifolds; - - std::vector m_triangleNormals; - std::vector m_edgeNeighbors; - std::vector> m_vertexRings; - std::vector> m_vertexTriangles; - - b3BodyId m_groundId; - b3MeshData* m_mesh = nullptr; - b3ShapeId m_shapeId = {}; - b3HullData* m_cylinderHull; - - b3BodyId m_bodyIds[m_maxBodies]; - b3Pos m_contactCenters[m_maxBodies]; - int m_bodyStations[m_maxBodies]; - int m_bodyCount; - int m_spawnIndex; - int m_spawnTimer; - - float m_cellSize; - float m_beltSpeed; - float m_slideFriction; - int m_targetCount; - int m_spawnInterval; - BodyType m_bodyType; - float m_toleranceDegrees; - float m_cosTolerance = 1.0f; - float m_sinTolerance = 0.0f; - bool m_contactRecycling; - bool m_drawFlow; - bool m_drawGhosts; - bool m_drawHeat; - - static constexpr int m_flagCount = 3; - int m_classCounts[e_ghostClassCount]; - int m_flagCounts[m_flagCount]; - int m_ghostCount; - int m_manifoldCount; - int m_stepGhostCount; - int m_recycleCount; - Marker m_markers[m_markerCapacity]; - int m_markerCount; - int m_markerIndex; -}; - -static int sampleConveyorCircuit = RegisterSample( "Ghost", "Conveyor Circuit", ConveyorCircuit::Create ); diff --git a/samples/sample_issues.cpp b/samples/sample_issues.cpp index 3bc4c5c..d05b353 100644 --- a/samples/sample_issues.cpp +++ b/samples/sample_issues.cpp @@ -1,22 +1,54 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "gfx/draw.h" -#include "gfx/keycodes.h" #include "imgui.h" #include "mesh_loader.h" -#include "meshoptimizer.h" #include "sample.h" +#include "gfx/draw.h" #include "box3d/box3d.h" -#include -#include -#include -#include -#include #include +class DumpLoader : public Sample +{ +public: + explicit DumpLoader( SampleContext* context ) + : Sample( context ) + { + if ( context->restart == false ) + { + m_camera->SetView( 45.0f, 30.0f, 15.0f, { 0.0f, 2.0f, 0.0f } ); + // m_camera->SetView( 45.0f, 30.0f, 300.0f, { 3910.62109f, 9862.50293f, 875.395081f } ); + } + + b3SetLengthUnitsPerMeter( 1.0f ); + + const char* dumpPrefix = "data/dumps/single_box/"; + +#include "dumps/single_box/box3d_dump.inl" + } + + ~DumpLoader() override + { + for ( b3MeshData* md : m_meshes ) + { + b3DestroyMesh( md ); + } + + b3SetLengthUnitsPerMeter( 1.0f ); + } + + static Sample* Create( SampleContext* context ) + { + return new DumpLoader( context ); + } + + std::vector m_meshes; +}; + +static int sampleDumpLoader = RegisterSample( "Issues", "Dump Loader", DumpLoader::Create ); + class Crash : public Sample { public: @@ -137,149 +169,7 @@ public: } }; -static int sampleMultiplePrismatic = - RegisterSample( "Issues", "Multiple Prismatic", MultiplePrismatic::Create ); - -// bad hull SM_Waterfall_MED_Wide_01 -static const b3Vec3 waterfallPoints[] = { - { 0.100183107, -498.925385, -1275.39966 }, { 0.100183107, -498.925415, 0.125000000 }, - { 0.100183107, 486.343750, 0.125000000 }, { 0.100183107, 486.343719, -1275.39966 }, - { -395.117462, 486.343781, -1462.43750 }, { -395.117462, 486.343750, -96.7426758 }, - { -395.117462, -498.925415, -96.7424469 }, { -395.117462, -498.925446, -1462.52612 }, - { -186.979691, 486.294891, -1462.47949 }, { -298.250000, 486.294891, 0.125000000 }, - { -395.121216, 486.294891, -1462.52612 }, { -186.984360, -498.913361, -1462.48413 }, - { -298.250000, -498.913361, 0.125000000 }, -}; - -static const b3Vec3 quadPoints[] = { - { 100.000000, -142.292389, 130.826111 }, { 99.5354385, -71.3011093, 130.826111 }, - { 99.5930862, -80.1112213, -100.000000 }, { 100.000000, -142.292389, -100.000000 }, - { 99.5930862, -80.1112213, 130.826111 }, -}; - -static const b3Vec3 thinBoxPoints[] = { - { -11.3861933, -24.2451687, -12.0037909 }, { -11.3889809, -24.2466526, -11.9013014 }, - { -11.3804407, -24.3151531, -12.0046492 }, { -11.3832273, -24.3166409, -11.9021587 }, - { -14.4396200, -24.3636723, -12.1324549 }, { -14.4432650, -24.3655701, -12.0299988 }, - { -14.4356947, -24.4337788, -12.1336164 }, { -14.4393377, -24.4356804, -12.0311594 }, -}; - -// Inline point sets are scaled from centimeters. A null point array is a file in data/hulls. -struct HullSource -{ - const char* name; - const b3Vec3* points; - int count; - float scale; -}; - -static const HullSource hullSources[] = { - { "waterfall", waterfallPoints, (int)std::size( waterfallPoints ), 0.01f }, - { "quad", quadPoints, (int)std::size( quadPoints ), 0.01f }, - { "thin box", thinBoxPoints, (int)std::size( thinBoxPoints ), 0.01f }, - { "axe.txt", nullptr, 0, 1.0f }, -}; - -static constexpr int hullSourceCount = (int)std::size( hullSources ); - -// Reads x, y, z triples separated by commas or whitespace. A C source repro is -// also accepted: only the first initializer list is parsed, so counts and other -// numbers in the surrounding code are ignored. -static bool LoadHullPoints( const char* path, std::vector* points ) -{ - points->clear(); - - FILE* file = fopen( path, "rb" ); - if ( file == nullptr ) - { - fprintf( stderr, "Failed to open '%s'\n", path ); - return false; - } - - fseek( file, 0, SEEK_END ); - long size = ftell( file ); - fseek( file, 0, SEEK_SET ); - if ( size < 0 ) - { - fprintf( stderr, "Failed to read '%s'\n", path ); - fclose( file ); - return false; - } - - std::vector text( size + 1 ); - size_t readCount = fread( text.data(), 1, size, file ); - fclose( file ); - text[readCount] = '\0'; - - char* begin = text.data(); - char* end = begin + readCount; - for ( char* c = begin; *c != '\0'; ++c ) - { - if ( *c != '{' ) - { - continue; - } - - char* prev = c - 1; - while ( prev >= begin && isspace( (unsigned char)*prev ) ) - { - --prev; - } - - if ( prev < begin || *prev != '=' ) - { - continue; - } - - begin = c + 1; - int depth = 1; - for ( end = begin; *end != '\0'; ++end ) - { - if ( *end == '{' ) - { - depth += 1; - } - else if ( *end == '}' && --depth == 0 ) - { - break; - } - } - - break; - } - - *end = '\0'; - - std::vector values; - char* cursor = begin; - while ( *cursor != '\0' ) - { - char* stop; - float value = strtof( cursor, &stop ); - if ( stop == cursor ) - { - cursor += 1; - continue; - } - - values.push_back( value ); - cursor = stop; - } - - if ( values.size() % 3 != 0 ) - { - fprintf( stderr, "'%s' has %d values, not a multiple of 3\n", path, (int)values.size() ); - } - - int count = (int)values.size() / 3; - points->resize( count ); - for ( int i = 0; i < count; ++i ) - { - ( *points )[i] = { values[3 * i], values[3 * i + 1], values[3 * i + 2] }; - } - - return count > 0; -} +static int sampleMultiplePrismatic = RegisterSample( "Issues", "Multiple Prismatic", MultiplePrismatic::Create ); class HullCrash : public Sample { @@ -287,17 +177,59 @@ public: explicit HullCrash( SampleContext* context ) : Sample( context ) { - m_hull = nullptr; - m_sourceIndex = 3; - m_maxVertexCount = B3_MAX_HULL_VERTICES; - - LoadPoints(); - CreateHull(); - if ( m_context->restart == false ) { - FrameView(); + m_camera->SetView( 0.0f, 15.0f, 5.0f, b3Pos_zero ); } + + m_hull = nullptr; + +#if 0 + // bad hull SM_Waterfall_MED_Wide_01 + b3Vec3 points[] = { + { 0.100183107, -498.925385, -1275.39966 }, { 0.100183107, -498.925415, 0.125000000 }, + { 0.100183107, 486.343750, 0.125000000 }, { 0.100183107, 486.343719, -1275.39966 }, + { -395.117462, 486.343781, -1462.43750 }, { -395.117462, 486.343750, -96.7426758 }, + { -395.117462, -498.925415, -96.7424469 }, { -395.117462, -498.925446, -1462.52612 }, + { -186.979691, 486.294891, -1462.47949 }, { -298.250000, 486.294891, 0.125000000 }, + { -395.121216, 486.294891, -1462.52612 }, { -186.984360, -498.913361, -1462.48413 }, + { -298.250000, -498.913361, 0.125000000 }, + }; + +#elif 1 + b3Vec3 points[] = { + { 100.000000, -142.292389, 130.826111 }, { 99.5354385, -71.3011093, 130.826111 }, + { 99.5930862, -80.1112213, -100.000000 }, { 100.000000, -142.292389, -100.000000 }, + { 99.5930862, -80.1112213, 130.826111 }, + }; +#else + b3Vec3 points[] = { + { -11.3861933, -24.2451687, -12.0037909 }, { -11.3889809, -24.2466526, -11.9013014 }, + { -11.3804407, -24.3151531, -12.0046492 }, { -11.3832273, -24.3166409, -11.9021587 }, + { -14.4396200, -24.3636723, -12.1324549 }, { -14.4432650, -24.3655701, -12.0299988 }, + { -14.4356947, -24.4337788, -12.1336164 }, { -14.4393377, -24.4356804, -12.0311594 }, + }; +#endif + + static_assert( sizeof( points ) / sizeof( points[0] ) < m_capacity, "bad" ); + + m_count = sizeof( points ) / sizeof( points[0] ); + for ( int i = 0; i < m_count; ++i ) + { + m_points[i] = 0.01f * points[i]; + } + + // This shift shouldn't be necessary but I'm doing it so the hull + // appears on the screen. + // for ( int i = 0; i < m_count; ++i ) + //{ + // m_points[i] -= m_points[0]; + // m_points[i] *= 0.01f; + //} + + m_hull = b3CreateHull( m_points, m_count, m_count ); + + (void)m_hull; } ~HullCrash() override @@ -308,95 +240,6 @@ public: } } - void LoadPoints() - { - const HullSource& source = hullSources[m_sourceIndex]; - if ( source.points != nullptr ) - { - m_points.assign( source.points, source.points + source.count ); - } - else - { - char path[64]; - snprintf( path, sizeof( path ), "data/hulls/%s", source.name ); - LoadHullPoints( path, &m_points ); - } - - for ( b3Vec3& point : m_points ) - { - point = source.scale * point; - } - - // The reported failure used the point count as the limit - m_maxVertexCount = b3ClampInt( (int)m_points.size(), 4, B3_MAX_HULL_VERTICES ); - } - - void CreateHull() - { - if ( m_hull != nullptr ) - { - b3DestroyHull( m_hull ); - m_hull = nullptr; - } - - int count = (int)m_points.size(); - if ( count >= 4 ) - { - m_hull = b3CreateHull( m_points.data(), count, m_maxVertexCount ); - } - } - - void FrameView() - { - if ( m_points.empty() ) - { - return; - } - - b3AABB bounds = b3MakeAABB( m_points.data(), (int)m_points.size(), 0.0f ); - float radius = b3Length( b3AABB_Extents( bounds ) ); - m_camera->SetView( 0.0f, 15.0f, b3MaxFloat( 3.0f * radius, 1.0f ), - b3ToPos( b3AABB_Center( bounds ) ) ); - } - - bool DrawControls() override - { - DrawTextLine( "points = %d", (int)m_points.size() ); - - if ( m_hull != nullptr ) - { - DrawTextLine( "hull: vertices = %d, edges = %d, faces = %d", m_hull->vertexCount, - m_hull->edgeCount / 2, m_hull->faceCount ); - } - else - { - DrawTextLine( "hull creation failed" ); - } - - if ( ImGui::BeginCombo( "Source", hullSources[m_sourceIndex].name ) ) - { - for ( int i = 0; i < hullSourceCount; ++i ) - { - if ( ImGui::Selectable( hullSources[i].name, i == m_sourceIndex ) ) - { - m_sourceIndex = i; - LoadPoints(); - CreateHull(); - FrameView(); - } - } - - ImGui::EndCombo(); - } - - if ( ImGui::SliderInt( "Max Vertices", &m_maxVertexCount, 4, B3_MAX_HULL_VERTICES ) ) - { - CreateHull(); - } - - return true; - } - void Render() override { if ( m_hull != nullptr ) @@ -405,9 +248,9 @@ public: } else { - for ( const b3Vec3& point : m_points ) + for ( int i = 0; i < m_count; ++i ) { - DrawPoint( b3ToPos( point ), 5.0f, MakeColor( b3_colorWhite ) ); + DrawPoint( b3ToPos( m_points[i] ), 5.0f, MakeColor( b3_colorWhite ) ); } } @@ -421,10 +264,10 @@ public: return new HullCrash( sampleContext ); } - std::vector m_points; + static constexpr int m_capacity = 64; b3HullData* m_hull; - int m_sourceIndex; - int m_maxVertexCount; + b3Vec3 m_points[m_capacity]; + int m_count; }; static int sampleHullCrash = RegisterSample( "Issues", "Hull Crash", HullCrash::Create ); @@ -438,6 +281,7 @@ public: if ( context->restart == false ) { m_camera->SetView( 0.0f, 15.0f, 10.0f, { 0.0f, 2.0f, 0.0f } ); + } AddGroundBox( 10.0f ); @@ -556,11 +400,11 @@ public: b3ShapeDef shapeDef = b3DefaultShapeDef(); m_heightField = b3CreateGrid( 40, 40, { 0.5f, 1.0f, 0.5f }, false ); - // m_heightField = b3CreateWave( 40, 40, {1.0f, 2.0f, 1.0f}, 0.02f, 0.04f, false ); + //m_heightField = b3CreateWave( 40, 40, {1.0f, 2.0f, 1.0f}, 0.02f, 0.04f, false ); b3CreateHeightFieldShape( groundId, &shapeDef, m_heightField ); m_gridMesh = b3CreateGridMesh( 40, 40, 0.5f, 1, true ); - // b3CreateMeshShape( groundId, &shapeDef, m_gridMesh, b3Vec3_one ); + //b3CreateMeshShape( groundId, &shapeDef, m_gridMesh, b3Vec3_one ); } { @@ -639,7 +483,6 @@ public: // --- Building mesh on top of ground --- m_building = CreateMeshData( "data/meshes/building.obj", 1.0f, false, false, true, true ); - if ( m_building != nullptr ) { b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.position = { 0.0f, 0.1f, 0.0f }; @@ -687,2409 +530,3 @@ public: }; static int sampleIndex = RegisterSample( "Issues", "Capsule Mesh", CapsuleMeshBug::Create ); - -// Reproduces s&box rigid body character ghost collisions on a FLAT floor. -// -// The s&box player is a fixed rotation dynamic body (zero radius box hull) moved by setting -// velocity. The floor here is modeled on an s&box map area that ghosts badly: concrete slabs -// and a run of parallel chamfered beams over deep pits. Every walkable vertex is at exactly -// y = 0 - there is nothing to climb and nothing to trip on. The only mesh features are AT or -// BELOW the walkable plane: chamfer facets sloping down from beam tops, pit walls and floors, -// T-junction seams between tiles tessellated at different resolutions, and a chunk seam where -// two mesh shapes meet (separate contact pairs, like s&box world chunks). -// -// Walking back and forth still launches the body upward (60-190 inch/s at run speed). No shape -// casts, no step up, no ground snapping - any upward velocity spike is a ghost collision from -// speculative hull vs triangle contacts against below-plane geometry. -class SBoxGhostCollisions : public Sample -{ -public: - // s&box works in inches: 1 unit = 0.0254 m (40 units per meter) - static constexpr float SRC = 0.0254f; - - // Floor layout (s&box inches) - static constexpr int m_halfLengthU = 256; // strip half length along x - static constexpr int m_halfWidthU = 64; // strip half width along z - static constexpr int m_tileSizeU = 32; // slab tile stride - - // Beam section: beams run along z, the character walks along x across them. - // Tops are 12 wide with 1.5 chamfers, pits between are 10 wide and 24 deep. - // The 16 wide hull always spans the 13 gap between flat tops. - static constexpr float m_beamPitchU = 22.0f; - static constexpr float m_beamWidthU = 12.0f; - static constexpr float m_chamferWidthU = 1.5f; - static constexpr float m_chamferDropU = 1.0f; - static constexpr float m_pitDepthU = 24.0f; - static constexpr int m_beamCount = 9; - static constexpr float m_beamRegion0 = -94.0f; // first beam start - static constexpr float m_beamRegion1 = 94.0f; // last beam end - - // Character (s&box player: 16 wide zero radius box hull, 72 tall, mass 500) - static constexpr float m_bodyHalfWidth = 16.0f * SRC; - static constexpr float m_bodyHalfHeight = 36.0f * SRC; - static constexpr float m_characterMass = 500.0f; - - explicit SBoxGhostCollisions( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 90.0f, 25.0f, 10.0f, { 0.0f, 1.0f, 0.0f } ); - } - - m_fixWinding = true; - m_combineChunks = true; - m_remesh = true; - m_simplifyErrorMillimeters = 10.0f; - m_repeatSimplify = true; - CreateFloor(); - - // Character - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { -m_walkRangeX, m_bodyHalfHeight + 0.1f, 0.0f }; - bodyDef.motionLocks.angularX = true; - bodyDef.motionLocks.angularY = true; - bodyDef.motionLocks.angularZ = true; - bodyDef.enableSleep = false; - - // With current ghost mitigation this seems unnecessary - //bodyDef.enableContactRecycling = false; - - bodyDef.gravityScale = 2.03f; // s&box gravity: 800 inch/s^2 - bodyDef.name = "character"; - bodyDef.safetyFactor = 0.05f; - m_characterId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - // shapeDef.baseMaterial.customColor = b3_colorLimeGreen; - - float volume = 8.0f * m_bodyHalfWidth * m_bodyHalfHeight * m_bodyHalfWidth; - shapeDef.density = m_characterMass / volume; - - // With current ghost mitigation this seems unnecessary - //shapeDef.enableSpeculativeContact = false; - - b3BoxHull box = b3MakeBoxHull( m_bodyHalfWidth, m_bodyHalfHeight, m_bodyHalfWidth ); - b3CreateHullShape( m_characterId, &shapeDef, &box.base ); - } - - m_walkDirectionX = 1.0f; - m_walkDirectionZ = 1.0f; - m_walkSpeedX = 350.0f * SRC; // s&box run speed - m_walkSpeedZ = 20.0f * SRC; - m_launchCount = 0; - m_maxLaunchSpeed = 0.0f; - m_launchMarkerCount = 0; - m_wasLaunched = false; - - m_stepWhilePaused = true; - } - - ~SBoxGhostCollisions() override - { - for ( int i = 0; i < 2; ++i ) - { - if ( m_chunkMesh[i] != nullptr ) - { - b3DestroyMesh( m_chunkMesh[i] ); - } - } - } - - void CreateFloor() - { - m_chunkTriangleCount[1] = 0; - m_simplifyPassCount[1] = 0; - - if ( m_combineChunks ) - { - CreateFloorChunk( 0, -(float)m_halfLengthU, (float)m_halfLengthU ); - return; - } - - // Two chunks meeting at x = 0, each its own body and mesh shape, so seam contacts live - // in separate contact pairs like s&box world mesh chunks. A beam top straddles the seam. - CreateFloorChunk( 0, -(float)m_halfLengthU, 0.0f ); - CreateFloorChunk( 1, 0.0f, (float)m_halfLengthU ); - } - - void DestroyFloor() - { - for ( int i = 0; i < 2; ++i ) - { - if ( B3_IS_NON_NULL( m_chunkBodyIds[i] ) ) - { - b3DestroyBody( m_chunkBodyIds[i] ); - b3DestroyMesh( m_chunkMesh[i] ); - } - - m_chunkBodyIds[i] = b3_nullBodyId; - m_chunkMesh[i] = nullptr; - } - } - - // Deterministic integer hash for tile tessellation selection - static uint32_t Hash( uint32_t x ) - { - x ^= x >> 16; - x *= 0x7feb352du; - x ^= x >> 15; - x *= 0x846ca68bu; - x ^= x >> 16; - return x; - } - - static void EmitTriangle( std::vector& vertices, std::vector& indices, - b3Vec3 a, b3Vec3 b, b3Vec3 c ) - { - int32_t base = (int32_t)vertices.size(); - vertices.push_back( a ); - vertices.push_back( b ); - vertices.push_back( c ); - indices.push_back( base ); - indices.push_back( base + 1 ); - indices.push_back( base + 2 ); - } - - // Horizontal patch at height y spanning [x0,x1]x[z0,z1] (inches), normal +y - static void EmitPatch( std::vector& vertices, std::vector& indices, float x0, - float x1, float z0, float z1, float y, float cell ) - { - if ( x1 - x0 < 0.01f ) - { - return; - } - - int countX = (int)( ( x1 - x0 ) / cell + 0.99f ); - int countZ = (int)( ( z1 - z0 ) / cell + 0.99f ); - - for ( int ix = 0; ix < countX; ++ix ) - { - for ( int iz = 0; iz < countZ; ++iz ) - { - float cx0 = x0 + ( x1 - x0 ) * (float)ix / (float)countX; - float cx1 = x0 + ( x1 - x0 ) * (float)( ix + 1 ) / (float)countX; - float cz0 = z0 + ( z1 - z0 ) * (float)iz / (float)countZ; - float cz1 = z0 + ( z1 - z0 ) * (float)( iz + 1 ) / (float)countZ; - - b3Vec3 a = { SRC * cx0, SRC * y, SRC * cz0 }; - b3Vec3 b = { SRC * cx1, SRC * y, SRC * cz0 }; - b3Vec3 c = { SRC * cx1, SRC * y, SRC * cz1 }; - b3Vec3 d = { SRC * cx0, SRC * y, SRC * cz1 }; - - // Alternate the split diagonal like typical cooked map data - if ( ( ix + iz ) & 1 ) - { - EmitTriangle( vertices, indices, a, d, c ); - EmitTriangle( vertices, indices, a, c, b ); - } - else - { - EmitTriangle( vertices, indices, a, d, b ); - EmitTriangle( vertices, indices, b, d, c ); - } - } - } - } - - // Sloped strip from edge (xLow, yLow) to edge (xHigh, yHigh) spanning the full z width - static void EmitSlope( std::vector& vertices, std::vector& indices, float xLow, - float yLow, float xHigh, float yHigh, float zCell, bool fixWinding ) - { - // The original winding only faces out for a slope rising toward +x - bool flip = fixWinding && xHigh < xLow; - - int countZ = (int)( 2.0f * (float)m_halfWidthU / zCell + 0.99f ); - for ( int iz = 0; iz < countZ; ++iz ) - { - float z0 = - -(float)m_halfWidthU + 2.0f * (float)m_halfWidthU * (float)iz / (float)countZ; - float z1 = -(float)m_halfWidthU + - 2.0f * (float)m_halfWidthU * (float)( iz + 1 ) / (float)countZ; - - b3Vec3 l0 = { SRC * xLow, SRC * yLow, SRC * z0 }; - b3Vec3 l1 = { SRC * xLow, SRC * yLow, SRC * z1 }; - b3Vec3 h0 = { SRC * xHigh, SRC * yHigh, SRC * z0 }; - b3Vec3 h1 = { SRC * xHigh, SRC * yHigh, SRC * z1 }; - - if ( flip ) - { - EmitTriangle( vertices, indices, l0, h1, l1 ); - EmitTriangle( vertices, indices, l0, h0, h1 ); - } - else - { - EmitTriangle( vertices, indices, l0, l1, h1 ); - EmitTriangle( vertices, indices, l0, h1, h0 ); - } - } - } - - // Vertical wall at x from y0 (bottom) to y1 (top). facing = +1 faces +x, -1 faces -x - static void EmitWall( std::vector& vertices, std::vector& indices, float x, - float y0, float y1, int facing, float zCell, bool fixWinding ) - { - // The original winding faced every wall into the solid - bool faceNegativeX = fixWinding ? facing < 0 : facing > 0; - - int countZ = (int)( 2.0f * (float)m_halfWidthU / zCell + 0.99f ); - for ( int iz = 0; iz < countZ; ++iz ) - { - float z0 = - -(float)m_halfWidthU + 2.0f * (float)m_halfWidthU * (float)iz / (float)countZ; - float z1 = -(float)m_halfWidthU + - 2.0f * (float)m_halfWidthU * (float)( iz + 1 ) / (float)countZ; - - b3Vec3 b0 = { SRC * x, SRC * y0, SRC * z0 }; - b3Vec3 b1 = { SRC * x, SRC * y0, SRC * z1 }; - b3Vec3 t0 = { SRC * x, SRC * y1, SRC * z0 }; - b3Vec3 t1 = { SRC * x, SRC * y1, SRC * z1 }; - - if ( faceNegativeX ) - { - EmitTriangle( vertices, indices, b0, b1, t1 ); - EmitTriangle( vertices, indices, b0, t1, t0 ); - } - else - { - EmitTriangle( vertices, indices, b0, t0, t1 ); - EmitTriangle( vertices, indices, b0, t1, b1 ); - } - } - } - - // Clip [a0,a1] to [c0,c1] - static bool ClipSpan( float a0, float a1, float c0, float c1, float* o0, float* o1 ) - { - *o0 = a0 > c0 ? a0 : c0; - *o1 = a1 < c1 ? a1 : c1; - return *o1 - *o0 > 0.01f; - } - - // Weld exact duplicates, then let meshoptimizer collapse every edge that leaves the surface in - // place. A t-junction vertex sits on an open border, so it can slide along that border onto a - // corner, which closes the seam. Flat collapses still cost a little from the simplifier's - // vertex regularization, so the error limit has to clear that while staying far below the inch - // scale cost of collapsing a real crease. Regularize options raise that cost. Vertex kinds are - // fixed per call, so a corner locked by a t-junction stays locked after its seam closes. - // Repeating reclassifies, but the error limit applies per pass, so deviation can accumulate. - // Winding is not repaired. Returns the number of passes. - static int Remesh( std::vector& vertices, std::vector& indices, - float errorLimit, unsigned int options, bool repeat ) - { - size_t indexCount = indices.size(); - const unsigned int* sourceIndices = reinterpret_cast( indices.data() ); - - std::vector remap( vertices.size() ); - size_t vertexCount = - meshopt_generateVertexRemap( remap.data(), sourceIndices, indexCount, vertices.data(), - vertices.size(), sizeof( b3Vec3 ) ); - - std::vector welded( indexCount ); - meshopt_remapIndexBuffer( welded.data(), sourceIndices, indexCount, remap.data() ); - - std::vector positions( vertexCount ); - meshopt_remapVertexBuffer( positions.data(), vertices.data(), vertices.size(), - sizeof( b3Vec3 ), remap.data() ); - - std::vector simplified( indexCount ); - int passCount = 0; - for ( ;; ) - { - size_t simplifiedCount = meshopt_simplify( - simplified.data(), welded.data(), welded.size(), &positions[0].x, vertexCount, - sizeof( b3Vec3 ), 0, errorLimit, meshopt_SimplifyErrorAbsolute | options, nullptr ); - passCount += 1; - - bool reduced = simplifiedCount < welded.size(); - welded.assign( simplified.begin(), simplified.begin() + simplifiedCount ); - - if ( repeat == false || reduced == false ) - { - break; - } - } - - size_t usedCount = - meshopt_optimizeVertexFetch( positions.data(), welded.data(), welded.size(), - positions.data(), vertexCount, sizeof( b3Vec3 ) ); - positions.resize( usedCount ); - - vertices = positions; - indices.assign( welded.begin(), welded.end() ); - return passCount; - } - - void CreateFloorChunk( int chunk, float x0U, float x1U ) - { - std::vector vertices; - std::vector indices; - - float s0, s1; - - // --- Concrete slabs at y = 0 outside the beam region --- - // Tiles tessellate at a hash-picked resolution so neighbors meet with T-junctions, - // like cooked s&box map collision. - float slabSpans[2][2] = { { -(float)m_halfLengthU, m_beamRegion0 }, - { m_beamRegion1, (float)m_halfLengthU } }; - for ( int i = 0; i < 2; ++i ) - { - if ( ClipSpan( slabSpans[i][0], slabSpans[i][1], x0U, x1U, &s0, &s1 ) == false ) - { - continue; - } - - for ( float tx = s0; tx < s1; tx += (float)m_tileSizeU ) - { - float tx1 = b3MinFloat( tx + (float)m_tileSizeU, s1 ); - for ( int tz = -m_halfWidthU; tz < m_halfWidthU; tz += m_tileSizeU ) - { - // Seeded by side rather than chunk so combined and split floors tessellate the - // same - uint32_t side = tx < 0.0f ? 0u : 1u; - uint32_t h = - Hash( (uint32_t)( (int)tx * 73856093 ) ^ (uint32_t)( tz * 19349663 ) ^ - (uint32_t)( side * 2654435761u ) ); - float cells[3] = { 4.0f, 8.0f, 16.0f }; - EmitPatch( vertices, indices, tx, tx1, (float)tz, (float)( tz + m_tileSizeU ), - 0.0f, cells[h % 3] ); - } - } - } - - // --- Beam section: flat tops at y = 0, chamfers dropping to pits --- - float pitTop = -m_chamferDropU; - float pitBottom = -m_pitDepthU; - - // Coarse walls and pit floors leave t-junctions against the 8 inch chamfer cells - float wellCell = 16.0f; - - for ( int k = 0; k < m_beamCount; ++k ) - { - float bx = m_beamRegion0 + m_beamPitchU * (float)k; - bool pitLeft = k > 0; - bool pitRight = k < m_beamCount - 1; - - // Flat top (flush with the slab on outer sides) - float top0 = pitLeft ? bx + m_chamferWidthU : bx; - float top1 = pitRight ? bx + m_beamWidthU - m_chamferWidthU : bx + m_beamWidthU; - if ( ClipSpan( top0, top1, x0U, x1U, &s0, &s1 ) ) - { - EmitPatch( vertices, indices, s0, s1, -(float)m_halfWidthU, (float)m_halfWidthU, - 0.0f, 8.0f ); - } - - // Chamfers sloping below the walkable plane - if ( pitLeft && bx >= x0U && bx < x1U ) - { - EmitSlope( vertices, indices, bx, pitTop, bx + m_chamferWidthU, 0.0f, 8.0f, - m_fixWinding ); - } - if ( pitRight && bx + m_beamWidthU > x0U && bx + m_beamWidthU <= x1U ) - { - EmitSlope( vertices, indices, bx + m_beamWidthU, pitTop, - bx + m_beamWidthU - m_chamferWidthU, 0.0f, 8.0f, m_fixWinding ); - } - - // Pit to the right of this beam - if ( pitRight ) - { - float pitL = bx + m_beamWidthU; - float pitR = bx + m_beamPitchU; - if ( pitL >= x0U && pitL < x1U ) - { - EmitWall( vertices, indices, pitL, pitBottom, pitTop, +1, wellCell, - m_fixWinding ); - } - if ( pitR > x0U && pitR <= x1U ) - { - EmitWall( vertices, indices, pitR, pitBottom, pitTop, -1, wellCell, - m_fixWinding ); - } - if ( ClipSpan( pitL, pitR, x0U, x1U, &s0, &s1 ) ) - { - EmitPatch( vertices, indices, s0, s1, -(float)m_halfWidthU, (float)m_halfWidthU, - pitBottom, wellCell ); - } - } - } - - if ( m_remesh ) - { - m_simplifyPassCount[chunk] = Remesh( - vertices, indices, 0.001f * m_simplifyErrorMillimeters, 0, m_repeatSimplify ); - } - - m_chunkTriangleCount[chunk] = (int)( indices.size() / 3 ); - - b3MeshDef meshDef = {}; - meshDef.vertices = vertices.data(); - meshDef.indices = indices.data(); - meshDef.vertexCount = (int)vertices.size(); - meshDef.triangleCount = (int)( indices.size() / 3 ); - meshDef.weldVertices = true; - meshDef.weldTolerance = 0.005f; // == B3_LINEAR_SLOP, same as s&box - meshDef.identifyEdges = true; - - m_chunkMesh[chunk] = b3CreateMesh( &meshDef, nullptr, 0 ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - m_chunkBodyIds[chunk] = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( m_chunkBodyIds[chunk], &shapeDef, m_chunkMesh[chunk], b3Vec3_one ); - } - - void Step() override - { - // Drive the character with pure velocity control: keep the solver's vertical velocity, - // set the horizontal velocity. This is how the s&box player controller moves. - b3Pos position = b3Body_GetPosition( m_characterId ); - if ( position.x > m_walkRangeX ) - { - m_walkDirectionX = -1.0f; - } - else if ( position.x < -m_walkRangeX ) - { - m_walkDirectionX = 1.0f; - } - - if ( position.z > m_walkRangeZ ) - { - m_walkDirectionZ = -1.0f; - } - else if ( position.z < -m_walkRangeZ ) - { - m_walkDirectionZ = 1.0f; - } - - b3Vec3 velocity = b3Body_GetLinearVelocity( m_characterId ); - velocity.x = m_walkDirectionX * m_walkSpeedX; - velocity.z = m_walkDirectionZ * m_walkSpeedZ; - b3Body_SetLinearVelocity( m_characterId, velocity ); - - Sample::Step(); - - if ( m_didStep ) - { - // The walkable plane is exactly y = 0, so the grounded body center never rises above - // rest height. Any upward velocity spike while grounded is a ghost collision: there - // is nothing to climb and nothing to bounce off. - position = b3Body_GetPosition( m_characterId ); - velocity = b3Body_GetLinearVelocity( m_characterId ); - - bool grounded = position.y < m_bodyHalfHeight + 0.01f + 4.0f * SRC; - bool launched = velocity.y > m_launchThreshold; - - if ( grounded && launched && m_wasLaunched == false ) - { - m_launchCount += 1; - m_maxLaunchSpeed = b3MaxFloat( m_maxLaunchSpeed, velocity.y ); - - if ( m_launchMarkerCount < m_markerCapacity ) - { - m_launchMarkers[m_launchMarkerCount] = position; - m_launchMarkerCount += 1; - } - } - - m_wasLaunched = launched; - } - - for ( int i = 0; i < m_launchMarkerCount; ++i ) - { - DrawPoint( m_launchMarkers[i], 8.0f, MakeColor( b3_colorRed ) ); - } - - b3Vec3 currentVelocity = b3Body_GetLinearVelocity( m_characterId ); - DrawTextLine( "ghost launches: %d, worst: %.2f m/s (%.0f inch/s)", m_launchCount, - m_maxLaunchSpeed, m_maxLaunchSpeed / SRC ); - DrawTextLine( "vertical velocity: %.2f m/s", currentVelocity.y ); - if ( m_combineChunks ) - { - DrawTextLine( "floor triangles: %d", m_chunkTriangleCount[0] ); - } - else - { - DrawTextLine( "floor triangles: %d (chunks %d + %d)", - m_chunkTriangleCount[0] + m_chunkTriangleCount[1], - m_chunkTriangleCount[0], m_chunkTriangleCount[1] ); - } - - if ( m_remesh ) - { - DrawTextLine( m_combineChunks ? "simplify passes: %d" : "simplify passes: %d + %d", - m_simplifyPassCount[0], m_simplifyPassCount[1] ); - } - } - - bool DrawControls() override - { - float speedUX = m_walkSpeedX / SRC; - if ( ImGui::SliderFloat( "Walk Speed X (inch/s)", &speedUX, 100.0f, 400.0f, "%.0f" ) ) - { - m_walkSpeedX = speedUX * SRC; - } - - float speedUZ = m_walkSpeedZ / SRC; - if ( ImGui::SliderFloat( "Walk Speed Z (inch/s)", &speedUZ, 10.0f, 100.0f, "%.0f" ) ) - { - m_walkSpeedZ = speedUZ * SRC; - } - - bool rebuild = ImGui::Checkbox( "Fix Winding", &m_fixWinding ); - rebuild = ImGui::Checkbox( "Combine Chunks", &m_combineChunks ) || rebuild; - rebuild = ImGui::Checkbox( "Remesh (meshoptimizer)", &m_remesh ) || rebuild; - - ImGui::SliderFloat( "Simplify Error (mm)", &m_simplifyErrorMillimeters, 0.1f, 50.0f, "%.1f", - ImGuiSliderFlags_Logarithmic ); - rebuild = ( ImGui::IsItemDeactivatedAfterEdit() && m_remesh ) || rebuild; - - rebuild = - ( ImGui::Checkbox( "Repeat Simplify", &m_repeatSimplify ) && m_remesh ) || rebuild; - - if ( rebuild ) - { - DestroyFloor(); - CreateFloor(); - } - - if ( ImGui::Button( "Reset Counters" ) || rebuild ) - { - m_launchCount = 0; - m_maxLaunchSpeed = 0.0f; - m_launchMarkerCount = 0; - } - - ImGui::Text( "Launches: %d", m_launchCount ); - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new SBoxGhostCollisions( context ); - } - - static constexpr float m_walkRangeX = 3.5f; // turn around beyond +/- this x (meters) - static constexpr float m_walkRangeZ = 0.5f; // turn around beyond +/- this x (meters) - static constexpr float m_launchThreshold = - 0.5f; // upward m/s counted as a ghost launch (~20 inch/s) - static constexpr int m_markerCapacity = 64; - - b3MeshData* m_chunkMesh[2] = {}; - b3BodyId m_chunkBodyIds[2] = { b3_nullBodyId, b3_nullBodyId }; - bool m_fixWinding; - bool m_combineChunks; - bool m_remesh; - float m_simplifyErrorMillimeters; - bool m_repeatSimplify; - int m_simplifyPassCount[2] = {}; - int m_chunkTriangleCount[2] = {}; - b3BodyId m_characterId; - float m_walkDirectionX; - float m_walkDirectionZ; - float m_walkSpeedX; - float m_walkSpeedZ; - int m_launchCount; - float m_maxLaunchSpeed; - bool m_wasLaunched; - b3Pos m_launchMarkers[m_markerCapacity]; - int m_launchMarkerCount; -}; - -static int sampleSBoxGhostCollisions = - RegisterSample( "Issues", "s&box Ghost Collisions", SBoxGhostCollisions::Create ); - -static const b3Vec3 s_metalWheel1Verts[317] = { - { 0.010279f, 0.086341f, 0.051768f }, { -0.010314f, -0.084708f, 0.051804f }, - { 0.010279f, -0.084708f, 0.051768f }, { -0.010314f, 0.086341f, 0.051804f }, - { 0.029138f, -0.084708f, -0.043911f }, { 0.043724f, -0.084708f, -0.029376f }, - { 0.010098f, -0.084708f, -0.051759f }, { -0.010494f, -0.084708f, -0.051723f }, - { 0.051638f, -0.084708f, -0.010364f }, { 0.051674f, -0.084708f, 0.010229f }, - { 0.043827f, -0.084708f, 0.029268f }, { 0.029291f, -0.084708f, 0.043855f }, - { -0.029353f, -0.084708f, 0.043957f }, { -0.051889f, -0.084708f, -0.010183f }, - { -0.051853f, -0.084708f, 0.010409f }, { -0.043939f, -0.084708f, 0.029421f }, - { -0.029506f, -0.084708f, -0.043809f }, { -0.044042f, -0.084708f, -0.029222f }, - { -0.029353f, 0.086341f, 0.043957f }, { 0.043724f, 0.086341f, -0.029376f }, - { 0.029138f, 0.086341f, -0.043911f }, { 0.010098f, 0.086341f, -0.051759f }, - { 0.051638f, 0.086341f, -0.010364f }, { 0.051674f, 0.086341f, 0.010229f }, - { -0.044042f, 0.086341f, -0.029222f }, { 0.043827f, 0.086341f, 0.029268f }, - { -0.051889f, 0.086341f, -0.010183f }, { -0.043939f, 0.086341f, 0.029421f }, - { -0.029506f, 0.086341f, -0.043809f }, { 0.035354f, 0.070897f, 0.035658f }, - { 0.035354f, -0.069397f, 0.035658f }, { -0.035498f, 0.070897f, 0.035658f }, - { -0.035498f, -0.069397f, 0.035658f }, { 0.035354f, -0.069397f, 0.365503f }, - { 0.035354f, 0.070897f, 0.365503f }, { -0.035498f, 0.070897f, 0.365503f }, - { -0.035498f, -0.069397f, 0.365503f }, { 0.035354f, 0.070897f, -0.365033f }, - { 0.035354f, -0.069397f, -0.365033f }, { -0.035498f, 0.070897f, -0.365033f }, - { -0.035498f, -0.069397f, -0.365033f }, { 0.035354f, -0.069397f, -0.035187f }, - { 0.035354f, 0.070897f, -0.035187f }, { -0.035498f, 0.070897f, -0.035187f }, - { -0.035498f, -0.069397f, -0.035187f }, { -0.035494f, -0.069397f, -0.035191f }, - { -0.365340f, -0.069397f, -0.035191f }, { -0.035494f, 0.070897f, -0.035191f }, - { -0.365340f, 0.070897f, -0.035191f }, { -0.365340f, -0.069397f, 0.035661f }, - { -0.035494f, -0.069397f, 0.035661f }, { -0.035494f, 0.070897f, 0.035661f }, - { -0.365340f, 0.070897f, 0.035661f }, { 0.035350f, 0.070897f, -0.035191f }, - { 0.365196f, 0.070897f, -0.035191f }, { 0.035350f, -0.069397f, -0.035191f }, - { 0.365196f, -0.069397f, -0.035191f }, { 0.365196f, 0.070897f, 0.035661f }, - { 0.035350f, 0.070897f, 0.035661f }, { 0.035350f, -0.069397f, 0.035661f }, - { 0.365196f, -0.069397f, 0.035661f }, { -0.070802f, 0.086337f, 0.355420f }, - { -0.070802f, -0.084705f, 0.355420f }, { -0.097081f, 0.086335f, 0.487537f }, - { -0.097081f, -0.084704f, 0.487537f }, { -0.000108f, 0.086337f, 0.362383f }, - { -0.000108f, 0.086335f, 0.497088f }, { -0.000108f, -0.084704f, 0.497088f }, - { -0.000108f, -0.084705f, 0.362383f }, { -0.138787f, -0.084705f, 0.334799f }, - { -0.138787f, 0.086337f, 0.334799f }, { -0.070810f, -0.084705f, 0.355419f }, - { -0.070810f, 0.086337f, 0.355419f }, { -0.097090f, 0.086335f, 0.487536f }, - { -0.190336f, 0.086335f, 0.459250f }, { -0.190336f, -0.084704f, 0.459250f }, - { -0.097090f, -0.084704f, 0.487536f }, { -0.138795f, 0.086337f, 0.334796f }, - { -0.138795f, -0.084705f, 0.334796f }, { -0.201442f, 0.086337f, 0.301310f }, - { -0.201442f, -0.084705f, 0.301310f }, { -0.276280f, -0.084704f, 0.413313f }, - { -0.276280f, 0.086335f, 0.413313f }, { -0.190344f, 0.086335f, 0.459247f }, - { -0.190344f, -0.084704f, 0.459247f }, { -0.201450f, -0.084705f, 0.301306f }, - { -0.256361f, -0.084705f, 0.256241f }, { -0.201450f, 0.086337f, 0.301306f }, - { -0.256361f, 0.086337f, 0.256241f }, { -0.351612f, 0.086335f, 0.351492f }, - { -0.351612f, -0.084704f, 0.351492f }, { -0.276288f, 0.086335f, 0.413309f }, - { -0.276288f, -0.084704f, 0.413309f }, { -0.301431f, -0.084705f, 0.201325f }, - { -0.413435f, -0.084704f, 0.276163f }, { -0.413435f, 0.086335f, 0.276163f }, - { -0.301431f, 0.086337f, 0.201325f }, { -0.256367f, -0.084705f, 0.256236f }, - { -0.256367f, 0.086337f, 0.256236f }, { -0.351618f, 0.086335f, 0.351487f }, - { -0.351618f, -0.084704f, 0.351487f }, { -0.334922f, -0.084705f, 0.138670f }, - { -0.459374f, -0.084704f, 0.190220f }, { -0.459374f, 0.086335f, 0.190220f }, - { -0.334922f, 0.086337f, 0.138670f }, { -0.301436f, 0.086337f, 0.201318f }, - { -0.301436f, -0.084705f, 0.201318f }, { -0.413440f, 0.086335f, 0.276156f }, - { -0.413440f, -0.084704f, 0.276156f }, { -0.487663f, -0.084704f, 0.096966f }, - { -0.355546f, -0.084705f, 0.070686f }, { -0.459377f, -0.084704f, 0.190212f }, - { -0.334926f, -0.084705f, 0.138663f }, { -0.355546f, 0.086337f, 0.070686f }, - { -0.334926f, 0.086337f, 0.138663f }, { -0.487663f, 0.086335f, 0.096966f }, - { -0.459377f, 0.086335f, 0.190212f }, { -0.362511f, -0.084705f, -0.000016f }, - { -0.355549f, -0.084705f, 0.070678f }, { -0.497217f, -0.084704f, -0.000016f }, - { -0.487665f, -0.084704f, 0.096957f }, { -0.497217f, 0.086335f, -0.000016f }, - { -0.362511f, 0.086337f, -0.000016f }, { -0.355549f, 0.086337f, 0.070678f }, - { -0.487665f, 0.086335f, 0.096957f }, { -0.362512f, 0.086337f, -0.000024f }, - { -0.362512f, -0.084705f, -0.000024f }, { -0.355549f, 0.086337f, -0.070717f }, - { -0.355549f, -0.084705f, -0.070717f }, { -0.497217f, -0.084704f, -0.000024f }, - { -0.487666f, -0.084704f, -0.096997f }, { -0.497217f, 0.086335f, -0.000024f }, - { -0.487666f, 0.086335f, -0.096997f }, { -0.334927f, -0.084705f, -0.138702f }, - { -0.355548f, 0.086337f, -0.070726f }, { -0.355548f, -0.084705f, -0.070726f }, - { -0.334927f, 0.086337f, -0.138702f }, { -0.487665f, -0.084704f, -0.097005f }, - { -0.459379f, -0.084704f, -0.190252f }, { -0.487665f, 0.086335f, -0.097005f }, - { -0.459379f, 0.086335f, -0.190252f }, { -0.413442f, -0.084704f, -0.276196f }, - { -0.301439f, -0.084705f, -0.201358f }, { -0.334925f, -0.084705f, -0.138710f }, - { -0.459376f, -0.084704f, -0.190260f }, { -0.334925f, 0.086337f, -0.138710f }, - { -0.301439f, 0.086337f, -0.201358f }, { -0.459376f, 0.086335f, -0.190260f }, - { -0.413442f, 0.086335f, -0.276196f }, { -0.256370f, -0.084705f, -0.256276f }, - { -0.301434f, 0.086337f, -0.201365f }, { -0.301434f, -0.084705f, -0.201365f }, - { -0.256370f, 0.086337f, -0.256276f }, { -0.413438f, 0.086335f, -0.276203f }, - { -0.351621f, 0.086335f, -0.351527f }, { -0.413438f, -0.084704f, -0.276203f }, - { -0.351621f, -0.084704f, -0.351527f }, { -0.256364f, -0.084705f, -0.256283f }, - { -0.201453f, 0.086337f, -0.301347f }, { -0.256364f, 0.086337f, -0.256283f }, - { -0.201453f, -0.084705f, -0.301347f }, { -0.276292f, -0.084704f, -0.413350f }, - { -0.351615f, -0.084704f, -0.351534f }, { -0.351615f, 0.086335f, -0.351534f }, - { -0.276292f, 0.086335f, -0.413350f }, { -0.201447f, -0.084705f, -0.301352f }, - { -0.276285f, -0.084704f, -0.413355f }, { -0.138799f, -0.084705f, -0.334838f }, - { -0.190349f, -0.084704f, -0.459289f }, { -0.276285f, 0.086335f, -0.413355f }, - { -0.201447f, 0.086337f, -0.301352f }, { -0.190349f, 0.086335f, -0.459289f }, - { -0.138799f, 0.086337f, -0.334838f }, { -0.190341f, 0.086335f, -0.459293f }, - { -0.190341f, -0.084704f, -0.459293f }, { -0.138791f, -0.084705f, -0.334842f }, - { -0.138791f, 0.086337f, -0.334842f }, { -0.070815f, 0.086337f, -0.355462f }, - { -0.070815f, -0.084705f, -0.355462f }, { -0.097095f, 0.086335f, -0.487579f }, - { -0.097095f, -0.084704f, -0.487579f }, { -0.070807f, 0.086337f, -0.355464f }, - { -0.097086f, 0.086335f, -0.487581f }, { -0.097086f, -0.084704f, -0.487581f }, - { -0.070807f, -0.084705f, -0.355464f }, { -0.000113f, -0.084705f, -0.362427f }, - { -0.000113f, 0.086337f, -0.362427f }, { -0.000113f, 0.086335f, -0.497132f }, - { -0.000113f, -0.084704f, -0.497132f }, { 0.070588f, 0.086337f, -0.355465f }, - { 0.096868f, -0.084704f, -0.487582f }, { 0.096868f, 0.086335f, -0.487582f }, - { 0.070588f, -0.084705f, -0.355465f }, { -0.000105f, 0.086337f, -0.362427f }, - { -0.000105f, 0.086335f, -0.497133f }, { -0.000105f, -0.084704f, -0.497133f }, - { -0.000105f, -0.084705f, -0.362427f }, { 0.190123f, -0.084704f, -0.459294f }, - { 0.190123f, 0.086335f, -0.459294f }, { 0.138573f, -0.084705f, -0.334843f }, - { 0.138573f, 0.086337f, -0.334843f }, { 0.070597f, 0.086337f, -0.355463f }, - { 0.070597f, -0.084705f, -0.355463f }, { 0.096876f, -0.084704f, -0.487580f }, - { 0.096876f, 0.086335f, -0.487580f }, { 0.201229f, -0.084705f, -0.301354f }, - { 0.276067f, -0.084704f, -0.413358f }, { 0.201229f, 0.086337f, -0.301354f }, - { 0.138581f, -0.084705f, -0.334840f }, { 0.138581f, 0.086337f, -0.334840f }, - { 0.190131f, 0.086335f, -0.459292f }, { 0.276067f, 0.086335f, -0.413358f }, - { 0.190131f, -0.084704f, -0.459292f }, { 0.201236f, 0.086337f, -0.301350f }, - { 0.256147f, -0.084705f, -0.256286f }, { 0.256147f, 0.086337f, -0.256286f }, - { 0.201236f, -0.084705f, -0.301350f }, { 0.351398f, -0.084704f, -0.351537f }, - { 0.351398f, 0.086335f, -0.351537f }, { 0.276074f, -0.084704f, -0.413353f }, - { 0.276074f, 0.086335f, -0.413353f }, { 0.301218f, -0.084705f, -0.201369f }, - { 0.301218f, 0.086337f, -0.201369f }, { 0.256154f, -0.084705f, -0.256280f }, - { 0.256154f, 0.086337f, -0.256280f }, { 0.413221f, 0.086335f, -0.276207f }, - { 0.413221f, -0.084704f, -0.276207f }, { 0.351405f, 0.086335f, -0.351531f }, - { 0.351405f, -0.084704f, -0.351531f }, { 0.334709f, 0.086337f, -0.138715f }, - { 0.301223f, 0.086337f, -0.201362f }, { 0.334709f, -0.084705f, -0.138715f }, - { 0.301223f, -0.084705f, -0.201362f }, { 0.459160f, -0.084704f, -0.190264f }, - { 0.459160f, 0.086335f, -0.190264f }, { 0.413226f, 0.086335f, -0.276200f }, - { 0.413226f, -0.084704f, -0.276200f }, { 0.334713f, -0.084705f, -0.138707f }, - { 0.355333f, -0.084705f, -0.070731f }, { 0.334713f, 0.086337f, -0.138707f }, - { 0.355333f, 0.086337f, -0.070731f }, { 0.459164f, 0.086335f, -0.190257f }, - { 0.487450f, 0.086335f, -0.097010f }, { 0.487450f, -0.084704f, -0.097010f }, - { 0.459164f, -0.084704f, -0.190257f }, { 0.355335f, -0.084705f, -0.070722f }, - { 0.362298f, -0.084705f, -0.000029f }, { 0.355335f, 0.086337f, -0.070722f }, - { 0.362298f, 0.086337f, -0.000029f }, { 0.497003f, -0.084704f, -0.000029f }, - { 0.497003f, 0.086335f, -0.000029f }, { 0.487452f, 0.086335f, -0.097002f }, - { 0.487452f, -0.084704f, -0.097002f }, { 0.362298f, -0.084705f, -0.000021f }, - { 0.497003f, -0.084704f, -0.000021f }, { 0.355336f, -0.084705f, 0.070673f }, - { 0.487453f, -0.084704f, 0.096952f }, { 0.497003f, 0.086335f, -0.000021f }, - { 0.362298f, 0.086337f, -0.000021f }, { 0.355336f, 0.086337f, 0.070673f }, - { 0.487453f, 0.086335f, 0.096952f }, { 0.355334f, -0.084705f, 0.070681f }, - { 0.355334f, 0.086337f, 0.070681f }, { 0.487451f, 0.086335f, 0.096961f }, - { 0.487451f, -0.084704f, 0.096961f }, { 0.334714f, -0.084705f, 0.138658f }, - { 0.459165f, -0.084704f, 0.190207f }, { 0.334714f, 0.086337f, 0.138658f }, - { 0.459165f, 0.086335f, 0.190207f }, { 0.334711f, 0.086337f, 0.138666f }, - { 0.301225f, 0.086337f, 0.201313f }, { 0.459163f, 0.086335f, 0.190215f }, - { 0.413229f, 0.086335f, 0.276151f }, { 0.334711f, -0.084705f, 0.138666f }, - { 0.301225f, -0.084705f, 0.201313f }, { 0.413229f, -0.084704f, 0.276151f }, - { 0.459163f, -0.084704f, 0.190215f }, { 0.301221f, -0.084705f, 0.201321f }, - { 0.256157f, -0.084705f, 0.256232f }, { 0.301221f, 0.086337f, 0.201321f }, - { 0.256157f, 0.086337f, 0.256232f }, { 0.413224f, -0.084704f, 0.276159f }, - { 0.413224f, 0.086335f, 0.276159f }, { 0.351408f, 0.086335f, 0.351483f }, - { 0.351408f, -0.084704f, 0.351483f }, { 0.201240f, -0.084705f, 0.301302f }, - { 0.201240f, 0.086337f, 0.301302f }, { 0.256151f, -0.084705f, 0.256238f }, - { 0.256151f, 0.086337f, 0.256238f }, { 0.351402f, 0.086335f, 0.351489f }, - { 0.351402f, -0.084704f, 0.351489f }, { 0.276078f, 0.086335f, 0.413305f }, - { 0.276078f, -0.084704f, 0.413305f }, { 0.138586f, -0.084705f, 0.334793f }, - { 0.201233f, -0.084705f, 0.301307f }, { 0.190135f, -0.084704f, 0.459244f }, - { 0.276071f, -0.084704f, 0.413311f }, { 0.201233f, 0.086337f, 0.301307f }, - { 0.138586f, 0.086337f, 0.334793f }, { 0.276071f, 0.086335f, 0.413311f }, - { 0.190135f, 0.086335f, 0.459244f }, { 0.138578f, -0.084705f, 0.334797f }, - { 0.070602f, -0.084705f, 0.355417f }, { 0.138578f, 0.086337f, 0.334797f }, - { 0.070602f, 0.086337f, 0.355417f }, { 0.190127f, 0.086335f, 0.459248f }, - { 0.190127f, -0.084704f, 0.459248f }, { 0.096881f, 0.086335f, 0.487534f }, - { 0.096881f, -0.084704f, 0.487534f }, { 0.070593f, -0.084705f, 0.355419f }, - { 0.096873f, 0.086335f, 0.487536f }, { 0.096873f, -0.084704f, 0.487536f }, - { 0.070593f, 0.086337f, 0.355419f }, { -0.000100f, 0.086337f, 0.362382f }, - { -0.000100f, 0.086335f, 0.497087f }, { -0.000100f, -0.084704f, 0.497087f }, - { -0.000100f, -0.084705f, 0.362382f }, -}; - -typedef struct WheelHullSpan -{ - int offset; - int count; -} WheelHullSpan; -static const WheelHullSpan s_metalWheel1Hulls[37] = { - { 0, 29 }, { 29, 8 }, { 37, 8 }, { 45, 8 }, { 53, 8 }, { 61, 8 }, { 69, 8 }, { 77, 8 }, - { 85, 8 }, { 93, 8 }, { 101, 8 }, { 109, 8 }, { 117, 8 }, { 125, 8 }, { 133, 8 }, { 141, 8 }, - { 149, 8 }, { 157, 8 }, { 165, 8 }, { 173, 8 }, { 181, 8 }, { 189, 8 }, { 197, 8 }, { 205, 8 }, - { 213, 8 }, { 221, 8 }, { 229, 8 }, { 237, 8 }, { 245, 8 }, { 253, 8 }, { 261, 8 }, { 269, 8 }, - { 277, 8 }, { 285, 8 }, { 293, 8 }, { 301, 8 }, { 309, 8 }, -}; -#define s_metalWheel1HullCount 37 - -// 30 metal_wheel1 props (37-piece convex decompositions) stacked. Body-pair contact merging -// lets them settle and sleep instead of wobbling. -class WheelStack : public Sample -{ -public: - explicit WheelStack( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 12.0f, 5.0f, { 0.0f, 0.85f, 0.0f } ); - } - - AddGroundBox( 10.0f ); - - constexpr int N = 512; - b3Vec3 buffer[N]; - int bufferCount = 0; - for ( int h = 0; h < s_metalWheel1HullCount; ++h ) - { - const WheelHullSpan& span = s_metalWheel1Hulls[h]; - m_hulls[h] = b3CreateHull( &s_metalWheel1Verts[span.offset], span.count, span.count ); - - const b3Vec3* points = b3GetHullPoints( m_hulls[h] ); - for ( int j = 0; j < m_hulls[h]->vertexCount && bufferCount < N; ++j ) - { - buffer[bufferCount] = points[j]; - ++bufferCount; - } - } - - // Create a single hull that wraps the input hulls. - b3HullData* wheelHull = b3CreateHull( buffer, bufferCount, bufferCount ); - - const float height = 0.171f; - const float spacing = height + 0.006f; - const float startY = 0.5f * height + 0.004f; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.6f; - - for ( int i = 0; i < m_wheelCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.name = "wheel"; - bodyDef.position = { 0.0f, startY + i * spacing, 0.0f }; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - // for ( int h = 0; h < s_metalWheel1HullCount; ++h ) - //{ - // b3CreateHullShape( bodyId, &shapeDef, m_hulls[h] ); - // } - - // Using a single hull improves the simulation. - b3CreateHullShape( bodyId, &shapeDef, wheelHull ); - } - - b3DestroyHull( wheelHull ); - - b3World_SetContactTuning( m_worldId, 240.0f, 10.0f, 3.0f ); - } - - ~WheelStack() override - { - for ( int h = 0; h < s_metalWheel1HullCount; ++h ) - { - b3DestroyHull( m_hulls[h] ); - } - } - - void Step() override - { - Sample::Step(); - - b3Profile p = b3World_GetProfile( m_worldId ); - float substepRate = m_context->hertz * m_context->subStepCount; - - DrawTextLine( "wheels %d, hull pieces/wheel %d (%d total shapes)", m_wheelCount, - s_metalWheel1HullCount, m_wheelCount * s_metalWheel1HullCount ); - DrawTextLine( "step %.0f hz, sub-steps %d -> substep rate %.0f hz", m_context->hertz, - m_context->subStepCount, substepRate ); - DrawTextLine( "eff contact hz = min(240, %.0f) = %.0f", 0.125f * substepRate, - b3MinFloat( 240.0f, 0.125f * substepRate ) ); - DrawTextLine( "step %.3f ms | collide %.3f ms (%.0f%%) | solve %.3f ms (%.0f%%)", p.step, - p.collide, p.step > 0.0f ? 100.0f * p.collide / p.step : 0.0f, p.solve, - p.step > 0.0f ? 100.0f * p.solve / p.step : 0.0f ); - } - - static Sample* Create( SampleContext* context ) - { - return new WheelStack( context ); - } - - b3HullData* m_hulls[s_metalWheel1HullCount]; - static constexpr int m_wheelCount = 30; -}; - -static int sampleWheelStack = RegisterSample( "Issues", "GMod Wheel Stack", WheelStack::Create ); - -// There was a problem where this bouncing box could gain energy. This has been fixed by the -// deferred restitution update. -class RestitutionOvershoot : public Sample -{ -public: - static constexpr float m_boxHalf = 0.5f; - static constexpr float m_floorHalfXZ = 0.375f; - static constexpr float m_floorHalfY = 0.25f; - static constexpr float m_dropHeight = 10.0f; - static constexpr float m_tolerance = 0.05f; - - explicit RestitutionOvershoot( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 0.0f, 28.0f, { 0.0f, m_dropHeight + m_boxHalf, 0.0f } ); - } - - b3BoxHull floor = b3MakeBoxHull( m_floorHalfXZ, m_floorHalfY, m_floorHalfXZ ); - b3BodyDef floorDef = b3DefaultBodyDef(); - floorDef.type = b3_staticBody; - floorDef.position = { 0.0f, -m_floorHalfY, 0.0f }; - b3BodyId floorBody = b3CreateBody( m_worldId, &floorDef ); - - b3ShapeDef floorShape = b3DefaultShapeDef(); - b3CreateHullShape( floorBody, &floorShape, &floor.base ); - - b3BoxHull box = b3MakeBoxHull( m_boxHalf, m_boxHalf, m_boxHalf ); - b3BodyDef boxDef = b3DefaultBodyDef(); - boxDef.type = b3_dynamicBody; - boxDef.position = { 0.0f, m_dropHeight, 0.0f }; - boxDef.safetyFactor = 0.1f; - m_boxBody = b3CreateBody( m_worldId, &boxDef ); - - b3ShapeDef boxShape = b3DefaultShapeDef(); - boxShape.baseMaterial.restitution = 1.0f; - b3CreateHullShape( m_boxBody, &boxShape, &box.base ); - - m_currentY = m_dropHeight; - m_maxBounceY = 0.0f; - m_bounced = false; - m_failed = false; - m_startEnergy = MeasureEnergy( m_worldId, &m_boxBody, 1 ).Total(); - m_maxEnergy = m_startEnergy; - m_energyFailed = false; - } - - void Step() override - { - Sample::Step(); - - if ( B3_IS_NON_NULL( m_boxBody ) == false ) - { - return; - } - - b3Pos position = b3Body_GetPosition( m_boxBody ); - m_currentY = position.y; - - b3Vec3 velocity = b3Body_GetLinearVelocity( m_boxBody ); - if ( m_bounced == false && velocity.y > 0.0f ) - { - m_bounced = true; - } - - if ( m_bounced ) - { - if ( position.y > m_maxBounceY ) - { - m_maxBounceY = position.y; - } - if ( position.y > m_dropHeight + m_tolerance ) - { - m_failed = true; - } - } - - b3Pos markerPoint = { 0.0f, m_dropHeight + m_boxHalf, 0.0f }; - DrawPlane( b3Vec3_axisY, markerPoint, MakeColor( b3_colorYellow ) ); - - // Perfect restitution and no friction, so the total energy may only decrease. It is the - // honest invariant here: the height check cannot tell a bounce that gained potential energy - // from one that converted it into spin, and this drop does both. - MechanicalEnergy energy = MeasureEnergy( m_worldId, &m_boxBody, 1 ); - float total = energy.Total(); - - if ( total > m_maxEnergy ) - { - m_maxEnergy = total; - } - - if ( m_bounced && total > m_startEnergy * ( 1.0f + m_energyTolerance ) ) - { - m_energyFailed = true; - } - - DrawTextLine( "drop height = %.2f m", m_dropHeight ); - DrawTextLine( "current y = %.2f m", m_currentY ); - DrawTextLine( "max bounce = %.2f m", m_maxBounceY ); - DrawTextLine( "kinetic = %.0f J linear + %.0f J angular", energy.linear, - energy.angular ); - DrawTextLine( "potential = %.0f J", energy.potential ); - DrawTextLine( "total = %.0f J (%.2f%% of start, peak %.2f%%)", total, - 100.0f * total / m_startEnergy, 100.0f * m_maxEnergy / m_startEnergy ); - - if ( m_bounced == false ) - { - DrawTextLine( "waiting for first bounce..." ); - } - else if ( m_failed ) - { - DrawTextLine( "FAIL: box exceeded drop height" ); - } - else - { - DrawTextLine( "PASS: bounce stays at or below drop height" ); - } - - if ( m_energyFailed ) - { - DrawTextLine( "FAIL: total energy increased" ); - } - else if ( m_bounced ) - { - DrawTextLine( "PASS: total energy did not increase" ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new RestitutionOvershoot( context ); - } - - static constexpr float m_energyTolerance = 0.001f; - - b3BodyId m_boxBody = {}; - float m_currentY = 0.0f; - float m_maxBounceY = 0.0f; - float m_startEnergy = 0.0f; - float m_maxEnergy = 0.0f; - bool m_bounced = false; - bool m_failed = false; - bool m_energyFailed = false; -}; - -static int sampleRestitutionOvershoot = - RegisterSample( "Issues", "Restitution Overshoot", RestitutionOvershoot::Create ); - -class SlideTwistOffCenterShape : public Sample -{ -public: - explicit SlideTwistOffCenterShape( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( -30.0f, 17.0f, 30.0f, { 0.0f, 5.0f, 0.0f } ); - } - - AddGroundBox( 50.0f ); - - b3Quat orientation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 20.0f * B3_DEG_TO_RAD ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - bodyDef.position = { 0.0f, 4.0f, 0.0f }; - bodyDef.rotation = orientation; - b3BodyId planeBody = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull plane = b3MakeBoxHull( 10.0f, 0.5f, 10.0f ); - shapeDef.baseMaterial.friction = 0.6f; - b3CreateHullShape( planeBody, &shapeDef, &plane.base ); - - b3Vec3 boxLocalCenter = { 1.0f, 0.5f, 1.0f }; - b3Vec3 boxOffset = b3RotateVector( orientation, boxLocalCenter ); - - bodyDef.type = b3_dynamicBody; - bodyDef.position = { -boxOffset.x, 5.0f - boxOffset.y, -boxOffset.z }; - bodyDef.rotation = orientation; - // bodyDef.angularVelocity = 25.0f * b3RotateVector( orientation, b3Vec3_axisY ); - b3BodyId boxBody = b3CreateBody( m_worldId, &bodyDef ); - b3BoxHull mBox = b3MakeOffsetBoxHull( 1.0f, 0.5f, 1.0f, boxLocalCenter ); - shapeDef.baseMaterial.friction = 0.3f; - b3CreateHullShape( boxBody, &shapeDef, &mBox.base ); - - b3Body_SetAngularVelocity( boxBody, 25.0f * b3RotateVector( orientation, b3Vec3_axisY ) ); - } - - static Sample* Create( SampleContext* context ) - { - return new SlideTwistOffCenterShape( context ); - } -}; - -static int sampleSlideTwistOffCenterShape = - RegisterSample( "Issues", "Slide Twist Off Center Shape", SlideTwistOffCenterShape::Create ); - -// Very large dynamic bodies have overflow when computing the inertia tensor. -class HugeBox : public Sample -{ -public: - explicit HugeBox( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 25.0f, 10.0f, b3Pos_zero ); - } - - AddGroundBox( 400.0f ); - - { - float a = 100.0f; - - b3BoxHull cube = b3MakeCubeHull( a ); - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "cube"; - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, a, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( { 0.0f, 0.0f, 1.0f }, 0.2f ); - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( m_bodyId, &shapeDef, &cube.base ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new HugeBox( context ); - } - - b3BodyId m_bodyId; -}; - -static int sampleHugeBox = RegisterSample( "Issues", "Huge Box", HugeBox::Create ); - -// A tilted cylinder whose bounds cover more than 512 height field triangles -class HeightfieldIssue : public Sample -{ -public: - explicit HeightfieldIssue( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( -90.0f, 5.0f, 50.0f, { 50.0f, 10.0f, 50.0f } ); - } - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BodyDef bodyDef = b3DefaultBodyDef(); - - m_heightField = b3CreateGrid( 100, 100, { 1, 1, 1 }, false ); - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHeightFieldShape( groundId, &shapeDef, m_heightField ); - - b3HullData* hull = b3CreateCylinder( 20, 5, -10, 24 ); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 50, 20, 50 }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisX, B3_PI / 4 ); - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, hull ); - b3DestroyHull( hull ); - } - - ~HeightfieldIssue() override - { - b3DestroyHeightField( m_heightField ); - } - - static Sample* Create( SampleContext* context ) - { - return new HeightfieldIssue( context ); - } - - b3HeightFieldData* m_heightField; -}; -static int sampleIssueIndex = RegisterSample( "Issues", "Heightfield", HeightfieldIssue::Create ); - -// Issue #135: the quasi static push out idiom, zero the velocity then step, drives a deeply -// overlapping body out through a thin static wall instead of back into the room. The solver -// resolves along the shallow exit, so once the mover center crosses the wall mid plane every -// step compounds the error outward. Interior is -x, exterior is +x. The wire box marks where -// a mover resting flush against the interior face belongs. -// This is NOT a bug. This is just how the separating axis works. I'm keeping this sample -// in case there is further discussion. -class ThinWallPushOut : public Sample -{ -public: - static constexpr float m_wallHalfThickness = 0.1f; - static constexpr float m_wallHalfHeight = 1.5f; - static constexpr float m_moverHalfExtent = 0.5f; - static constexpr float m_tolerance = 0.01f; - - explicit ThinWallPushOut( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 15.0f, 6.0f, { 0.0f, m_wallHalfHeight, 0.0f } ); - } - - // Furniture is dragged into place, never dropped - b3World_SetGravity( m_worldId, b3Vec3_zero ); - - AddGroundBox( 20.0f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BodyDef bodyDef = b3DefaultBodyDef(); - - bodyDef.name = "wall"; - bodyDef.position = { 0.0f, m_wallHalfHeight, 0.0f }; - b3BodyId wallId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull wall = b3MakeBoxHull( m_wallHalfThickness, m_wallHalfHeight, 2.0f ); - b3CreateHullShape( wallId, &shapeDef, &wall.base ); - - bodyDef.name = "mover"; - bodyDef.type = b3_dynamicBody; - bodyDef.position = { m_startX, m_wallHalfHeight, 0.0f }; - - // Velocity is zeroed every step, so without this the mover falls asleep on the first one - bodyDef.enableSleep = false; - - // A room planner slides items on the floor plane and yaws them to face a wall - bodyDef.motionLocks = { false, true, false, true, false, true }; - m_moverId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull mover = b3MakeBoxHull( m_moverHalfExtent, m_moverHalfExtent, m_moverHalfExtent ); - shapeDef.baseMaterial.friction = 0.0f; - b3CreateHullShape( m_moverId, &shapeDef, &mover.base ); - } - - void PlaceMover() - { - b3Body_SetTransform( m_moverId, { m_startX, m_wallHalfHeight, 0.0f }, b3Quat_identity ); - b3Body_SetLinearVelocity( m_moverId, b3Vec3_zero ); - b3Body_SetAngularVelocity( m_moverId, b3Vec3_zero ); - } - - bool DrawControls() override - { - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - // Anywhere past the wall mid plane tunnels out, even while the near face is far deeper - bool changed = ImGui::SliderFloat( "Start X", &m_startX, -0.6f, 0.6f, "%.2f" ); - changed = changed || ImGui::Button( "Reset Mover" ); - - if ( changed ) - { - PlaceMover(); - } - - ImGui::PopItemWidth(); - return true; - } - - void Step() override - { - // The reported idiom. Zeroing the velocity leaves the penetration correction as the - // only thing that can move the body. - b3Body_SetLinearVelocity( m_moverId, b3Vec3_zero ); - b3Body_SetAngularVelocity( m_moverId, b3Vec3_zero ); - - Sample::Step(); - - float interiorRestX = -m_wallHalfThickness - m_moverHalfExtent; - float exteriorRestX = m_wallHalfThickness + m_moverHalfExtent; - - b3Vec3 lower = { interiorRestX - m_moverHalfExtent, m_wallHalfHeight - m_moverHalfExtent, - -m_moverHalfExtent }; - b3Vec3 upper = { interiorRestX + m_moverHalfExtent, m_wallHalfHeight + m_moverHalfExtent, - m_moverHalfExtent }; - DrawAabb( lower, upper, MakeColor( b3_colorLime ) ); - - float x = (float)b3Body_GetPosition( m_moverId ).x; - DrawTextLine( "start x = %.3f m", m_startX ); - DrawTextLine( "current x = %.3f m", x ); - DrawTextLine( "interior rest x = %.3f m", interiorRestX ); - - if ( b3AbsFloat( x - exteriorRestX ) < m_tolerance ) - { - DrawTextLine( "FAIL: mover pushed out of the room" ); - } - else if ( b3AbsFloat( x - interiorRestX ) < m_tolerance ) - { - DrawTextLine( "PASS: mover pushed back into the room" ); - } - else - { - DrawTextLine( "relaxing ..." ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new ThinWallPushOut( context ); - } - - b3BodyId m_moverId = {}; - float m_startX = 0.2f; -}; - -static int sampleThinWallPushOut = - RegisterSample( "Issues", "Thin Wall Push Out", ThinWallPushOut::Create ); - -// Two crates resting on a rolling deck, one each side of the roll axis: the orange crate with -// contact recycling (the default), the blue crate with it off for its body. -// -// A recycled contact keeps the normal and anchors it was made with, fixed in the world, while each -// body turns less than B3_CONTACT_RECYCLE_ANGULAR_DISTANCE (10 degrees) from where the contact was -// made and the two stay within the recycle distance (5 cm). Only the separation is updated. A deck -// and the cargo resting on it turn together, so their contact is recycled through the roll. Its -// normal stays the deck's up as it was, and its anchors stay at the same world offsets from each -// body's center of mass, so the orange crate moves as the deck moves at that fixed spot in space, -// not as the deck under it moves. It goes straight up and down instead of along its arc, and slides -// out across the deck by about offset * (1 - cos(roll)). While that stays under the recycle -// distance the crate sways out and back. Past it (8 m and 8 degrees here, 78 mm) the contact is -// made again partway through, at the deck's angle then, and frozen there, so the crate walks off -// across the deck roll by roll. The angular tolerance doesn't stop that: at 12 or 15 degrees the -// contact is made again more often and the crate walks all the same. The blue crate rides with the -// deck. The slide arrows on the deck are drawn ten times longer. -class RollingDeck : public Sample -{ -public: - static constexpr float m_deckHalfLength = 2.0f; - static constexpr float m_deckHalfWidth = 10.0f; - static constexpr float m_deckHalfThickness = 0.25f; - static constexpr float m_crateHalf = 0.5f; - static constexpr float m_crateOffset = 8.0f; - static constexpr float m_friction = 1.0f; - static constexpr float m_settleTime = 1.0f; - static constexpr float m_slideScale = 10.0f; - - explicit RollingDeck( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 75.0f, 15.0f, 32.0f, { 0.0f, 0.5f, 0.0f } ); - } - - m_rollDegrees = 8.0f; - m_period = 6.0f; - m_deckId = {}; - m_crateIds[0] = {}; - m_crateIds[1] = {}; - - CreateScene(); - } - - void CreateScene() - { - if ( B3_IS_NON_NULL( m_deckId ) ) - { - b3DestroyBody( m_deckId ); - b3DestroyBody( m_crateIds[0] ); - b3DestroyBody( m_crateIds[1] ); - } - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = m_friction; - - // The deck rolls about the world x axis through its center - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_kinematicBody; - m_deckId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( m_deckHalfLength, m_deckHalfThickness, m_deckHalfWidth ); - shapeDef.baseMaterial.customColor = b3_colorSlateGray; - b3CreateHullShape( m_deckId, &shapeDef, &box.base ); - } - - // The crates rest on the level deck, m_crateOffset either side of the roll axis - b3BoxHull box = b3MakeBoxHull( m_crateHalf, m_crateHalf, m_crateHalf ); - for ( int i = 0; i < 2; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, m_deckHalfThickness + m_crateHalf, - i == 0 ? m_crateOffset : -m_crateOffset }; - - // The orange crate recycles its contact with the deck, the blue crate doesn't. Both - // stay awake, so a small roll can't put them to sleep. - bodyDef.enableContactRecycling = i == 0; - bodyDef.enableSleep = false; - m_crateIds[i] = b3CreateBody( m_worldId, &bodyDef ); - - shapeDef.baseMaterial.customColor = i == 0 ? b3_colorOrange : b3_colorDodgerBlue; - b3CreateHullShape( m_crateIds[i], &shapeDef, &box.base ); - - m_start[i] = b3Vec3_zero; - m_maxSlide[i] = 0.0f; - m_maxNormalError[i] = 0.0f; - } - - m_time = 0.0f; - m_started = false; - } - - // The roll angle in radians at a time since the start: still while the crates settle, then - // rolling, eased in over the first quarter roll so the crates aren't jolted by a deck starting - // at full speed. - float RollAngle( float time ) const - { - float t = time - m_settleTime; - if ( t <= 0.0f ) - { - return 0.0f; - } - - float ease = 1.0f; - if ( t < 0.25f * m_period ) - { - float u = t / ( 0.25f * m_period ); - ease = u * u * ( 3.0f - 2.0f * u ); - } - - return ease * m_rollDegrees * B3_PI / 180.0f * sinf( 2.0f * B3_PI * t / m_period ); - } - - bool DrawControls() override - { - // Changing the roll starts the scene again, so the contacts are made with the deck level. - ImGui::SliderFloat( "Roll (deg)", &m_rollDegrees, 0.0f, 15.0f, "%.1f" ); - if ( ImGui::IsItemDeactivatedAfterEdit() ) - { - CreateScene(); - } - - ImGui::SliderFloat( "Period (s)", &m_period, 2.0f, 12.0f, "%.1f" ); - if ( ImGui::IsItemDeactivatedAfterEdit() ) - { - CreateScene(); - } - - if ( ImGui::Button( "Reset" ) ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - float timeStep = m_context->hertz > 0.0f ? 1.0f / m_context->hertz : 0.0f; - if ( m_context->pause && m_context->singleStep == 0 ) - { - timeStep = 0.0f; - } - - if ( timeStep > 0.0f ) - { - b3Quat rotation = - b3MakeQuatFromAxisAngle( b3Vec3_axisX, RollAngle( m_time + timeStep ) ); - b3Body_SetTargetTransform( m_deckId, { { 0.0f, 0.0f, 0.0f }, rotation }, timeStep, - true ); - } - - Sample::Step(); - - m_time += timeStep; - - // Where the crates settled, in the deck's frame, measured from as the deck starts to roll - if ( m_started == false && m_time >= m_settleTime ) - { - for ( int i = 0; i < 2; ++i ) - { - m_start[i] = b3Body_GetLocalPoint( m_deckId, b3Body_GetPosition( m_crateIds[i] ) ); - } - m_started = true; - } - - b3Vec3 deckUp = b3Body_GetWorldVector( m_deckId, b3Vec3_axisY ); - float slide[2] = { 0.0f, 0.0f }; - float normalError[2] = { 0.0f, 0.0f }; - - for ( int i = 0; i < 2; ++i ) - { - Vec4 color = i == 0 ? MakeColor( b3_colorOrange ) : MakeColor( b3_colorDodgerBlue ); - b3Pos center = b3Body_GetPosition( m_crateIds[i] ); - - // The deck's up (white) and the crate's contact normal (in the crate's color), from the - // crate's center - DrawArrow( center, b3OffsetPos( center, b3MulSV( 2.5f, deckUp ) ), - MakeColor( b3_colorWhite ) ); - - b3ContactData contactData; - if ( b3Body_GetContactData( m_crateIds[i], &contactData, 1 ) == 1 && - contactData.manifoldCount > 0 ) - { - b3Vec3 normal = contactData.manifolds[0].normal; - if ( b3Dot( normal, deckUp ) < 0.0f ) - { - normal = b3Neg( normal ); - } - - DrawArrow( center, b3OffsetPos( center, b3MulSV( 2.5f, normal ) ), color ); - normalError[i] = - acosf( b3MinFloat( b3Dot( normal, deckUp ), 1.0f ) ) * 180.0f / B3_PI; - } - - DrawString3D( b3OffsetPos( center, b3MulSV( 3.0f, deckUp ) ), color, "%s", - i == 0 ? "recycling on" : "recycling off" ); - - if ( m_started == false ) - { - continue; - } - - // Where the crate settled, outlined on the deck's top, and how far it has slid from - // there across the deck, drawn m_slideScale times longer - b3Vec3 local = b3Body_GetLocalPoint( m_deckId, center ); - b3Vec3 offset = b3Sub( local, m_start[i] ); - offset.y = 0.0f; - slide[i] = b3Length( offset ); - - float top = m_deckHalfThickness + 0.01f; - b3Vec3 mark = { m_start[i].x, top, m_start[i].z }; - b3Vec3 corners[4] = { - { mark.x - m_crateHalf, top, mark.z - m_crateHalf }, - { mark.x + m_crateHalf, top, mark.z - m_crateHalf }, - { mark.x + m_crateHalf, top, mark.z + m_crateHalf }, - { mark.x - m_crateHalf, top, mark.z + m_crateHalf }, - }; - for ( int j = 0; j < 4; ++j ) - { - DrawLine( b3Body_GetWorldPoint( m_deckId, corners[j] ), - b3Body_GetWorldPoint( m_deckId, corners[( j + 1 ) % 4] ), color ); - } - - b3Vec3 tip = b3MulAdd( mark, m_slideScale, offset ); - DrawArrow( b3Body_GetWorldPoint( m_deckId, mark ), - b3Body_GetWorldPoint( m_deckId, tip ), color ); - - m_maxSlide[i] = b3MaxFloat( m_maxSlide[i], slide[i] ); - m_maxNormalError[i] = b3MaxFloat( m_maxNormalError[i], normalError[i] ); - } - - float roll = RollAngle( m_time ) * 180.0f / B3_PI; - float expected = m_crateOffset * ( 1.0f - cosf( m_rollDegrees * B3_PI / 180.0f ) ); - - DrawTextLine( "deck rolls %.1f deg each way every %.1f s (now %+.1f deg), crates %.0f m " - "from the roll axis, friction %.0f", - m_rollDegrees, m_period, roll, m_crateOffset, m_friction ); - DrawTextLine( "a contact is recycled while each body turns < 10 deg from where it was made " - "(B3_CONTACT_RECYCLE_ANGULAR_DISTANCE)" ); - DrawTextLine( "contacts recycled this step: %d (only the orange crate's can be)", - b3World_GetCounters( m_worldId ).recycledContactCount ); - DrawTextLine( "orange, recycling on : normal %4.1f deg off the deck's up (most %4.1f), " - "slid %5.1f mm (most %5.1f)", - normalError[0], m_maxNormalError[0], 1000.0f * slide[0], - 1000.0f * m_maxSlide[0] ); - DrawTextLine( "blue, recycling off: normal %4.1f deg off the deck's up (most %4.1f), " - "slid %5.1f mm (most %5.1f)", - normalError[1], m_maxNormalError[1], 1000.0f * slide[1], - 1000.0f * m_maxSlide[1] ); - DrawTextLine( - "recycled, the crate moves straight up and down: offset * (1 - cos(roll)) = %.1f mm at " - "each end; past the " - "%.0f cm recycle distance the contact is made again tilted and the crate walks off", - 1000.0f * expected, 100.0f * b3World_GetContactRecycleDistance( m_worldId ) ); - DrawTextLine( "arrows: white is the deck's up, colored is the contact normal; slide arrows " - "on the deck are drawn %.0fx", - m_slideScale ); - } - - static Sample* Create( SampleContext* context ) - { - return new RollingDeck( context ); - } - - b3BodyId m_deckId; - b3BodyId m_crateIds[2]; - b3Vec3 m_start[2]; - float m_maxSlide[2]; - float m_maxNormalError[2]; - float m_rollDegrees; - float m_period; - float m_time; - bool m_started; -}; - -static int sampleRollingDeck = RegisterSample( "Issues", "Rolling Deck", RollingDeck::Create ); - -// A car made of one dynamic box (the chassis) and four ray cast 'wheels'. -// There are no wheel bodies and no joints. - -// W/S to drive, A/D to steer and Space to brake. T toggles a camera that follows the car. - -// Each step every wheel casts a ray down the chassis' own down axis. Where a ray hits the ground -// the wheel applies two forces to the chassis at the contact point: -// - a spring and damper force along the contact normal, which holds the chassis up -// - a tyre force in the contact plane, which drives, brakes and stops the wheel sliding sideways -// The tyre force is limited by friction times the spring force, so a wheel that is lightly loaded -// grips less. Weight transfer, body roll and rollover come from where these forces are applied. -class RaycastVehicle : public Sample -{ -public: - static constexpr int m_wheelCount = 4; - static constexpr uint64_t m_vehicleBit = 0x2; - - struct Wheel - { - b3Vec3 localMount; - bool steered; - - // Distance from the mount down to the wheel's center - float suspensionLength; - bool grounded; - - // Rotation about the axle, for drawing only - float spinAngle; - float spinSpeed; - }; - - explicit RaycastVehicle( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 25.0f, 20.0f, 12.0f, { 0.0f, 1.0f, 0.0f } ); - } - - m_suspensionHertz = 1.5f; - m_suspensionDampingRatio = 0.45f; - m_friction = 1.0f; - m_wheelRadius = 0.35f; - m_suspensionTravel = 0.3f; - m_engineAcceleration = 5.0f; - m_brakeDeceleration = 8.0f; - m_maxSteeringAngle = 0.15f * B3_PI; - m_steeringAngle = 0.0f; - - AddGroundBox( 100.0f ); - - // A ramp to show the suspension working - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 15.0f, -0.5f, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.1f ); - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( 6.0f, 0.5f, 4.0f ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - - // The chassis is the only body. Its shape has its own category so the wheel rays can skip - // it. - float halfLength = 2.2f; - float halfHeight = 0.7f; - float halfWidth = 0.9f; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 1.2f, 0.0f }; - m_chassisId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 130.0f; - shapeDef.filter.categoryBits = m_vehicleBit; - b3BoxHull box = b3MakeBoxHull( halfLength, halfHeight, halfWidth ); - b3CreateHullShape( m_chassisId, &shapeDef, &box.base ); - - // A car tips over when its lateral acceleration exceeds half the track width divided by - // the height of its center of mass. At the middle of this box the center of mass would - // be about as high as the half track, and the car would roll before its tyres slide. - // Lower it to near the floor, where the heavy parts of a car are. - b3MassData massData = b3Body_GetMassData( m_chassisId ); - massData.center = { 0.0f, -0.45f, 0.0f }; - b3Body_SetMassData( m_chassisId, massData ); - } - - // The mounts are the top of each wheel's travel, inside the chassis at the sides. +x is - // forward. - float axle = 0.75f * halfLength; - float mountHeight = -0.3f; - m_wheels[0] = { { axle, mountHeight, halfWidth }, true, m_suspensionTravel }; - m_wheels[1] = { { axle, mountHeight, -halfWidth }, true, m_suspensionTravel }; - m_wheels[2] = { { -axle, mountHeight, halfWidth }, false, m_suspensionTravel }; - m_wheels[3] = { { -axle, mountHeight, -halfWidth }, false, m_suspensionTravel }; - - // A cylinder along its y axis, centered, for drawing the wheels - float wheelWidth = 0.25f; - m_wheelHull = b3CreateCylinder( wheelWidth, m_wheelRadius, -0.5f * wheelWidth, 12 ); - } - - ~RaycastVehicle() override - { - b3DestroyHull( m_wheelHull ); - - if ( m_camera->m_thirdPerson ) - { - ToggleThirdPerson(); - } - } - - void Keyboard( int key, int action, int mods ) override - { - if ( key == KEY_T && action == ACTION_PRESS ) - { - ToggleThirdPerson(); - } - } - - bool DrawControls() override - { - ImGui::SliderFloat( "Suspension Hertz", &m_suspensionHertz, 0.5f, 5.0f, "%.1f" ); - ImGui::SliderFloat( "Suspension Damping", &m_suspensionDampingRatio, 0.0f, 2.0f, "%.2f" ); - ImGui::SliderFloat( "Tyre Friction", &m_friction, 0.0f, 2.0f, "%.2f" ); - - bool thirdPerson = m_camera->m_thirdPerson; - if ( ImGui::Checkbox( "Third Person (T)", &thirdPerson ) ) - { - ToggleThirdPerson(); - } - - return true; - } - - // Apply the forces of every wheel to the chassis for the coming step - void UpdateWheels( float timeStep, float throttle, float brake, float steer ) - { - b3WorldTransform transform = b3Body_GetTransform( m_chassisId ); - b3Vec3 forward = b3RotateVector( transform.q, b3Vec3_axisX ); - - // The acceleration the driver asks for along the chassis' nose. The brake opposes the - // chassis' motion and is capped at what stops it this step, so it never drives it - // backwards. - float speed = b3Dot( b3Body_GetLinearVelocity( m_chassisId ), forward ); - float acceleration = m_engineAcceleration * throttle; - float stopping = b3MinFloat( m_brakeDeceleration * brake, b3AbsFloat( speed ) / timeStep ); - acceleration -= speed > 0.0f ? stopping : -stopping; - - for ( int i = 0; i < m_wheelCount; ++i ) - { - UpdateWheel( m_wheels[i], transform, timeStep, acceleration, steer ); - } - } - - // Cast one wheel's ray and apply its suspension and tyre forces to the chassis - void UpdateWheel( Wheel& wheel, b3WorldTransform transform, float timeStep, float acceleration, - float steer ) - { - b3Vec3 up = b3RotateVector( transform.q, b3Vec3_axisY ); - b3Vec3 forward = b3RotateVector( transform.q, b3Vec3_axisX ); - - // The ray reaches from the mount down through the spring's travel and the wheel's radius - float reach = m_suspensionTravel + m_wheelRadius; - b3Vec3 translation = b3MulSV( -reach, up ); - - b3QueryFilter filter = b3DefaultQueryFilter(); - filter.categoryBits = m_vehicleBit; - filter.maskBits = ~m_vehicleBit; - - b3Pos mount = b3TransformWorldPoint( transform, wheel.localMount ); - b3RayResult hit = b3World_CastRayClosest( m_worldId, mount, translation, filter ); - wheel.grounded = hit.hit; - float fraction = hit.hit ? hit.fraction : 1.0f; - wheel.suspensionLength = fraction * reach - m_wheelRadius; - - // A wheel turns at the speed of the ground under it, and keeps that speed in the air - wheel.spinAngle = b3UnwindAngle( wheel.spinAngle + wheel.spinSpeed * timeStep ); - - if ( hit.hit == false ) - { - return; - } - - // Each wheel carries an equal share of the mass. The spring rate gives that share the - // requested natural frequency. - float share = b3Body_GetMass( m_chassisId ) / m_wheelCount; - float omega = 2.0f * B3_PI * m_suspensionHertz; - float stiffness = share * omega * omega; - float damping = 2.0f * m_suspensionDampingRatio * share * omega; - - // Suspension. A spring only pushes: a negative load would pull the chassis onto the - // ground and hold it there through a jump. - float compression = ( 1.0f - hit.fraction ) * reach; - float compressionSpeed = -b3Dot( b3Body_GetWorldPointVelocity( m_chassisId, mount ), up ); - float load = b3MaxFloat( stiffness * compression + damping * compressionSpeed, 0.0f ); - b3Body_ApplyForce( m_chassisId, b3MulSV( load, hit.normal ), hit.point, true ); - - // The wheel's rolling direction in the contact plane, and the direction across it - b3Vec3 heading = forward; - if ( wheel.steered ) - { - heading = b3RotateVector( b3MakeQuatFromAxisAngle( up, steer ), forward ); - } - b3Vec3 rolling = - b3Normalize( b3MulAdd( heading, -b3Dot( heading, hit.normal ), hit.normal ) ); - b3Vec3 lateral = b3Cross( hit.normal, rolling ); - - // The lateral force cancels the contact point's sideways sliding in one step. The rolling - // force gives this wheel's share of the mass the requested acceleration, resolved onto the - // wheel, so a steered wheel puts less of it into the nose direction. - b3Vec3 contactVelocity = b3Body_GetWorldPointVelocity( m_chassisId, hit.point ); - float lateralForce = -share * b3Dot( contactVelocity, lateral ) / timeStep; - float rollingForce = share * acceleration * b3Dot( forward, rolling ); - - // Rolling forward along +x turns the wheel backwards about its axle, the chassis' +z - wheel.spinSpeed = -b3Dot( contactVelocity, rolling ) / m_wheelRadius; - - // Friction circle: the tyre cannot give more than friction times the load on it - float maxForce = m_friction * load; - float magnitude = sqrtf( lateralForce * lateralForce + rollingForce * rollingForce ); - if ( magnitude > maxForce ) - { - lateralForce *= maxForce / magnitude; - rollingForce *= maxForce / magnitude; - } - - b3Vec3 tyreForce = - b3Add( b3MulSV( rollingForce, rolling ), b3MulSV( lateralForce, lateral ) ); - b3Body_ApplyForce( m_chassisId, tyreForce, hit.point, true ); - } - - void Step() override - { - float throttle = 0.0f; - throttle += IsKeyDown( KEY_W ) ? 1.0f : 0.0f; - throttle -= IsKeyDown( KEY_S ) ? 1.0f : 0.0f; - float brake = IsKeyDown( KEY_SPACE ) ? 1.0f : 0.0f; - - m_steeringAngle = 0.0f; - m_steeringAngle += IsKeyDown( KEY_A ) ? m_maxSteeringAngle : 0.0f; - m_steeringAngle -= IsKeyDown( KEY_D ) ? m_maxSteeringAngle : 0.0f; - - // Forces accumulate until the world steps, so apply them only on a step that runs - bool stepping = m_context->pause == false || m_context->singleStep > 0; - if ( stepping && m_context->hertz > 0.0f ) - { - UpdateWheels( 1.0f / m_context->hertz, throttle, brake, m_steeringAngle ); - } - - if ( m_camera->m_thirdPerson ) - { - m_camera->m_pivot = b3Body_GetPosition( m_chassisId ); - m_camera->UpdateTransform(); - } - - Sample::Step(); - } - - void Render() override - { - Sample::Render(); - - b3WorldTransform transform = b3Body_GetTransform( m_chassisId ); - b3Vec3 down = b3RotateVector( transform.q, b3Neg( b3Vec3_axisY ) ); - - // The wheel cylinder is along y. This turns it onto the axle, the chassis' z. - b3Quat cylinderToAxle = b3MakeQuatFromAxisAngle( b3Vec3_axisX, 0.5f * B3_PI ); - - for ( int i = 0; i < m_wheelCount; ++i ) - { - const Wheel& wheel = m_wheels[i]; - b3Pos mount = b3TransformWorldPoint( transform, wheel.localMount ); - b3Pos center = b3OffsetPos( mount, b3MulSV( wheel.suspensionLength, down ) ); - - float steer = wheel.steered ? m_steeringAngle : 0.0f; - b3Quat q = b3MulQuat( transform.q, b3MakeQuatFromAxisAngle( b3Vec3_axisY, steer ) ); - q = b3MulQuat( q, b3MakeQuatFromAxisAngle( b3Vec3_axisZ, wheel.spinAngle ) ); - q = b3MulQuat( q, cylinderToAxle ); - - b3HexColor color = wheel.grounded ? b3_colorGreen : b3_colorRed; - DrawLine( mount, center, MakeColor( color ) ); - DrawHull( { center, q }, m_wheelHull, MakeColor( b3_colorGray ) ); - } - - b3Vec3 forward = b3RotateVector( b3Body_GetRotation( m_chassisId ), b3Vec3_axisX ); - float speed = b3Dot( b3Body_GetLinearVelocity( m_chassisId ), forward ); - DrawTextLine( "speed = %.1f m/s", speed ); - } - - static Sample* Create( SampleContext* context ) - { - return new RaycastVehicle( context ); - } - - b3BodyId m_chassisId; - Wheel m_wheels[m_wheelCount]; - b3HullData* m_wheelHull; - - float m_suspensionHertz; - float m_suspensionDampingRatio; - float m_friction; - float m_wheelRadius; - float m_suspensionTravel; - float m_engineAcceleration; - float m_brakeDeceleration; - float m_maxSteeringAngle; - float m_steeringAngle; -}; - -static int sampleRaycastVehicle = - RegisterSample( "Vehicle", "Raycast Vehicle", RaycastVehicle::Create ); - -// A user wants the load on a static body C when a box A lands on it, sometimes through a thin sleeping -// plate B. Hit events report approach speed, and a resting plate has none against C, so C gets no hit -// event when B is in the middle. Summing the contact impulses on C each step gives the load either way. -class StaticLoad : public Sample -{ -public: - static constexpr float m_boxHalf = 1.0f; - static constexpr float m_tableTop = 3.0f; - static constexpr float m_dropX = 1.5f; - static constexpr int m_settleSteps = 10; - static constexpr int m_historyCapacity = 240; - static constexpr int m_maxHits = 12; - - explicit StaticLoad( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 15.0f, 22.0f, { 0.0f, 5.0f, 0.0f } ); - } - - // The weld to the wall lives in game code, so Box3D only sees two static bodies - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "wall"; - bodyDef.position = { -4.25f, 4.0f, 0.0f }; - b3BodyId wallId = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 0.25f, 4.0f, 3.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( wallId, &shapeDef, &box.base ); - } - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.name = "C"; - bodyDef.position = { 0.0f, m_tableTop - 1.0f, 0.0f }; - m_bodyC = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 4.0f, 1.0f, 2.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.enableHitEvents = true; - m_shapeC = b3CreateHullShape( m_bodyC, &shapeDef, &box.base ); - } - - Reset(); - } - - void Reset() - { - if ( B3_IS_NON_NULL( m_bodyA ) ) - { - b3DestroyBody( m_bodyA ); - } - - if ( B3_IS_NON_NULL( m_bodyB ) ) - { - b3DestroyBody( m_bodyB ); - } - - m_bodyA = b3_nullBodyId; - m_bodyB = b3_nullBodyId; - m_shapeA = b3_nullShapeId; - m_shapeB = b3_nullShapeId; - - m_resetStep = m_stepCount; - m_lastStep = m_stepCount; - m_dropped = false; - m_massA = 0.0f; - m_massB = 0.0f; - m_impactStep = -1; - m_impactSpeed = 0.0f; - m_excessImpulse = 0.0f; - m_stepImpulseC = 0.0f; - m_stepImpulseAB = 0.0f; - m_stepImpulseAC = 0.0f; - m_stepImpulseBC = 0.0f; - m_peakForceC = 0.0f; - m_peakForceAB = 0.0f; - m_peakForceAC = 0.0f; - m_peakForceBC = 0.0f; - m_peakStep = -1; - m_hitCountC = 0; - m_hitCountB = 0; - m_hitCount = 0; - m_historyCount = 0; - m_historyIndex = 0; - - if ( m_includeB ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.name = "B"; - bodyDef.position = { m_dropX, m_tableTop + m_plateHalfHeight, 0.0f }; - m_bodyB = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 1.5f, m_plateHalfHeight, 1.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = m_densityB; - shapeDef.enableHitEvents = true; - m_shapeB = b3CreateHullShape( m_bodyB, &shapeDef, &box.base ); - } - else - { - DropA(); - } - } - - // B rests on C long enough to build its contact, then sleeps the way a settled game object would - void DropA() - { - float baseY = m_tableTop; - if ( m_includeB ) - { - if ( m_sleepB ) - { - b3Body_SetAwake( m_bodyB, false ); - } - - baseY += 2.0f * m_plateHalfHeight; - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.name = "A"; - bodyDef.position = { m_dropX, baseY + m_dropHeight + m_boxHalf, 0.0f }; - m_bodyA = b3CreateBody( m_worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( m_boxHalf, m_boxHalf, m_boxHalf ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = m_densityA; - shapeDef.enableHitEvents = true; - m_shapeA = b3CreateHullShape( m_bodyA, &shapeDef, &box.base ); - - m_massA = b3Body_GetMass( m_bodyA ); - m_massB = m_includeB ? b3Body_GetMass( m_bodyB ) : 0.0f; - m_dropped = true; - } - - const char* Label( b3ShapeId shapeId ) const - { - if ( B3_ID_EQUALS( shapeId, m_shapeA ) ) - { - return "A"; - } - - if ( B3_ID_EQUALS( shapeId, m_shapeB ) ) - { - return "B"; - } - - if ( B3_ID_EQUALS( shapeId, m_shapeC ) ) - { - return "C"; - } - - return "?"; - } - - // Total normal impulse a contact applied over the step, sub-steps and restitution included. - // A speculative point that never pushed contributes zero. - static float ContactImpulse( const b3ContactData& data ) - { - float impulse = 0.0f; - for ( int i = 0; i < data.manifoldCount; ++i ) - { - const b3Manifold& manifold = data.manifolds[i]; - for ( int j = 0; j < manifold.pointCount; ++j ) - { - impulse += manifold.points[j].totalNormalImpulse; - } - } - - return impulse; - } - - // Sum the impulse on a shape from every touching contact, or only the one against a given shape - float ShapeImpulse( b3ShapeId shapeId, b3ShapeId otherId, bool drawArrows ) - { - if ( B3_IS_NULL( shapeId ) ) - { - return 0.0f; - } - - int capacity = b3Shape_GetContactCapacity( shapeId ); - m_contactData.resize( capacity ); - int count = b3Shape_GetContactData( shapeId, m_contactData.data(), capacity ); - - float hertz = m_context->hertz; - float arrowScale = m_restingWeight > 0.0f ? 1.0f / m_restingWeight : 0.0f; - - float impulse = 0.0f; - for ( int i = 0; i < count; ++i ) - { - const b3ContactData& data = m_contactData[i]; - bool isShapeA = B3_ID_EQUALS( data.shapeIdA, shapeId ); - b3ShapeId other = isShapeA ? data.shapeIdB : data.shapeIdA; - if ( B3_IS_NON_NULL( otherId ) && B3_ID_EQUALS( other, otherId ) == false ) - { - continue; - } - - impulse += ContactImpulse( data ); - - if ( drawArrows == false ) - { - continue; - } - - // The normal points from shape A to shape B, so it pushes on B and pulls on A - b3Pos center = b3Body_GetWorldCenter( b3Shape_GetBody( data.shapeIdA ) ); - for ( int j = 0; j < data.manifoldCount; ++j ) - { - const b3Manifold& manifold = data.manifolds[j]; - b3Vec3 direction = isShapeA ? -manifold.normal : manifold.normal; - for ( int k = 0; k < manifold.pointCount; ++k ) - { - const b3ManifoldPoint& mp = manifold.points[k]; - if ( mp.totalNormalImpulse <= 0.0f ) - { - continue; - } - - // One meter per resting weight, clamped so an impact spike stays on screen - float length = b3MinFloat( mp.totalNormalImpulse * hertz * arrowScale, 4.0f ); - b3Pos p = b3OffsetPos( center, mp.anchorA ); - DrawArrow( b3OffsetPos( p, -length * direction ), p, MakeColor( b3_colorRed ) ); - } - } - } - - return impulse; - } - - void Step() override - { - b3Vec3 velocityA = B3_IS_NON_NULL( m_bodyA ) ? b3Body_GetLinearVelocity( m_bodyA ) : b3Vec3_zero; - - Sample::Step(); - - float gravity = -b3World_GetGravity( m_worldId ).y; - m_restingWeight = ( m_massA + m_massB ) * gravity; - - // A thin B leaves A within speculative reach of C, so part of the load can skip B entirely - m_stepImpulseC = ShapeImpulse( m_shapeC, b3_nullShapeId, true ); - m_stepImpulseAC = ShapeImpulse( m_shapeC, m_shapeA, false ); - m_stepImpulseBC = ShapeImpulse( m_shapeC, m_shapeB, false ); - m_stepImpulseAB = ShapeImpulse( m_shapeA, m_shapeB, false ); - float impulseA = ShapeImpulse( m_shapeA, b3_nullShapeId, false ); - - // Pausing keeps the last step's events, so only consume a step once - if ( m_stepCount != m_lastStep ) - { - m_lastStep = m_stepCount; - ProcessStep( impulseA, velocityA ); - } - - DrawHits(); - DrawStats(); - } - - void ProcessStep( float impulseA, b3Vec3 velocityA ) - { - if ( m_dropped == false ) - { - if ( m_stepCount - m_resetStep >= m_settleSteps ) - { - DropA(); - } - return; - } - - float hertz = m_context->hertz; - float timeStep = hertz > 0.0f ? 1.0f / hertz : 0.0f; - - if ( m_impactStep < 0 && impulseA > 0.0f ) - { - m_impactStep = m_stepCount; - m_impactSpeed = -velocityA.y; - - if ( m_pauseOnImpact ) - { - m_context->pause = true; - } - } - - // From impact on, the impulse on C beyond the resting weight removes the momentum A brought in - if ( m_impactStep >= 0 ) - { - m_excessImpulse += m_stepImpulseC - m_restingWeight * timeStep; - } - - float forceC = m_stepImpulseC * hertz; - float forceAB = m_stepImpulseAB * hertz; - if ( forceC > m_peakForceC ) - { - m_peakForceC = forceC; - m_peakStep = m_stepCount; - } - - m_peakForceAB = b3MaxFloat( m_peakForceAB, forceAB ); - m_peakForceAC = b3MaxFloat( m_peakForceAC, m_stepImpulseAC * hertz ); - m_peakForceBC = b3MaxFloat( m_peakForceBC, m_stepImpulseBC * hertz ); - - m_historyC[m_historyIndex] = forceC; - m_historyAB[m_historyIndex] = forceAB; - m_historyIndex = ( m_historyIndex + 1 ) % m_historyCapacity; - m_historyCount = b3MinInt( m_historyCount + 1, m_historyCapacity ); - - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - for ( int i = 0; i < events.hitCount; ++i ) - { - const b3ContactHitEvent& event = events.hitEvents[i]; - bool touchesC = B3_ID_EQUALS( event.shapeIdA, m_shapeC ) || B3_ID_EQUALS( event.shapeIdB, m_shapeC ); - bool touchesB = B3_ID_EQUALS( event.shapeIdA, m_shapeB ) || B3_ID_EQUALS( event.shapeIdB, m_shapeB ); - m_hitCountC += touchesC ? 1 : 0; - m_hitCountB += touchesB ? 1 : 0; - - HitRecord record = {}; - record.event = event; - record.step = m_stepCount; - if ( b3Contact_IsValid( event.contactId ) ) - { - record.impulse = ContactImpulse( b3Contact_GetData( event.contactId ) ); - } - - // Newest first, dropping the oldest when full - int count = b3MinInt( m_hitCount, m_maxHits - 1 ); - for ( int j = count; j > 0; --j ) - { - m_hits[j] = m_hits[j - 1]; - } - - m_hits[0] = record; - m_hitCount = count + 1; - } - } - - void DrawHits() - { - for ( int i = 0; i < m_hitCount; ++i ) - { - const b3ContactHitEvent& event = m_hits[i].event; - b3Pos p1 = event.point; - b3Pos p2 = b3OffsetPos( p1, -event.approachSpeed * event.normal ); - DrawPoint( p1, 10.0f, MakeColor( b3_colorYellow ) ); - DrawLine( p1, p2, MakeColor( b3_colorYellow ) ); - DrawString3D( p1, MakeColor( b3_colorWhite ), "%s-%s %.1f m/s", Label( event.shapeIdA ), - Label( event.shapeIdB ), event.approachSpeed ); - } - } - - void DrawStats() - { - float hertz = m_context->hertz; - - if ( m_dropped == false ) - { - DrawTextLine( "B settling on C" ); - return; - } - - DrawTextLine( "mass A = %.2f kg, mass B = %.2f kg, resting weight on C = %.1f N", m_massA, m_massB, - m_restingWeight ); - - if ( m_includeB ) - { - DrawTextLine( "B is %s", b3Body_IsAwake( m_bodyB ) ? "awake" : "asleep" ); - } - - if ( m_impactStep < 0 ) - { - DrawTextLine( "A falling" ); - return; - } - - float momentum = m_massA * m_impactSpeed; - DrawTextLine( "impact at step %d, speed %.2f m/s, momentum %.1f N*s", m_impactStep - m_resetStep, - m_impactSpeed, momentum ); - - // No continuous collision between dynamic bodies, so A can sink a full step of travel into B before - // they get a contact. If that reaches within speculative distance of C, A loads C directly. - if ( m_includeB ) - { - DrawTextLine( "A travels %.2f m per step, B is %.2f m thick", m_impactSpeed / hertz, - 2.0f * m_plateHalfHeight ); - } - DrawTextLine( "step load on C = %.1f N (impulse %.3f N*s)", m_stepImpulseC * hertz, m_stepImpulseC ); - DrawTextLine( "peak load on C = %.1f N at step %d, %.1fx resting weight", m_peakForceC, m_peakStep - m_resetStep, - m_restingWeight > 0.0f ? m_peakForceC / m_restingWeight : 0.0f ); - - if ( m_includeB ) - { - DrawTextLine( " from B = %.1f N, peak %.1f N", m_stepImpulseBC * hertz, m_peakForceBC ); - DrawTextLine( " from A directly = %.1f N, peak %.1f N", m_stepImpulseAC * hertz, m_peakForceAC ); - DrawTextLine( "load A on B = %.1f N, peak %.1f N", m_stepImpulseAB * hertz, m_peakForceAB ); - } - - DrawTextLine( "impulse on C beyond resting weight = %.1f N*s (A brought %.1f N*s)", m_excessImpulse, - momentum ); - DrawTextLine( "hit events touching C = %d, touching B = %d", m_hitCountC, m_hitCountB ); - - for ( int i = 0; i < m_hitCount; ++i ) - { - const HitRecord& record = m_hits[i]; - DrawTextLine( " step %d: %s-%s approach %.2f m/s, contact impulse %.3f N*s", record.step - m_resetStep, - Label( record.event.shapeIdA ), Label( record.event.shapeIdB ), record.event.approachSpeed, - record.impulse ); - } - } - - bool DrawControls() override - { - bool reset = false; - reset |= ImGui::Checkbox( "Include B", &m_includeB ); - reset |= ImGui::Checkbox( "B Asleep", &m_sleepB ); - reset |= ImGui::SliderFloat( "B Half Thickness", &m_plateHalfHeight, 0.02f, 0.5f, "%.2f m" ); - reset |= ImGui::SliderFloat( "B Density", &m_densityB, 100.0f, 10000.0f, "%.0f kg/m^3", - ImGuiSliderFlags_Logarithmic ); - reset |= ImGui::SliderFloat( "A Density", &m_densityA, 100.0f, 10000.0f, "%.0f kg/m^3", - ImGuiSliderFlags_Logarithmic ); - reset |= ImGui::SliderFloat( "Drop Height", &m_dropHeight, 0.0f, 10.0f, "%.1f m" ); - - float threshold = b3World_GetHitEventThreshold( m_worldId ); - if ( ImGui::SliderFloat( "Hit Threshold", &threshold, 0.0f, 5.0f, "%.2f m/s" ) ) - { - b3World_SetHitEventThreshold( m_worldId, threshold ); - } - - ImGui::Checkbox( "Pause On Impact", &m_pauseOnImpact ); - - if ( ImGui::Button( "Drop Again" ) ) - { - reset = true; - } - - if ( reset ) - { - Reset(); - } - - int offset = m_historyCount < m_historyCapacity ? 0 : m_historyIndex; - ImGui::PlotLines( "##loadC", m_historyC, m_historyCount, offset, "load on C (N)", 0.0f, FLT_MAX, - ImVec2( 0.0f, 80.0f ) ); - ImGui::PlotLines( "##loadAB", m_historyAB, m_historyCount, offset, "load A on B (N)", 0.0f, FLT_MAX, - ImVec2( 0.0f, 80.0f ) ); - - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new StaticLoad( context ); - } - - struct HitRecord - { - b3ContactHitEvent event; - float impulse; - int step; - }; - - std::vector m_contactData; - - b3BodyId m_bodyA = {}; - b3BodyId m_bodyB = {}; - b3BodyId m_bodyC = {}; - b3ShapeId m_shapeA = {}; - b3ShapeId m_shapeB = {}; - b3ShapeId m_shapeC = {}; - - HitRecord m_hits[m_maxHits] = {}; - float m_historyC[m_historyCapacity] = {}; - float m_historyAB[m_historyCapacity] = {}; - - float m_dropHeight = 3.0f; - float m_plateHalfHeight = 0.15f; - float m_densityA = 1000.0f; - float m_densityB = 1000.0f; - float m_massA = 0.0f; - float m_massB = 0.0f; - float m_restingWeight = 0.0f; - float m_impactSpeed = 0.0f; - float m_excessImpulse = 0.0f; - float m_stepImpulseC = 0.0f; - float m_stepImpulseAB = 0.0f; - float m_stepImpulseAC = 0.0f; - float m_stepImpulseBC = 0.0f; - float m_peakForceC = 0.0f; - float m_peakForceAB = 0.0f; - float m_peakForceAC = 0.0f; - float m_peakForceBC = 0.0f; - - int m_resetStep = 0; - int m_lastStep = 0; - int m_impactStep = -1; - int m_peakStep = -1; - int m_hitCountC = 0; - int m_hitCountB = 0; - int m_hitCount = 0; - int m_historyCount = 0; - int m_historyIndex = 0; - - bool m_includeB = true; - bool m_sleepB = true; - bool m_pauseOnImpact = false; - bool m_dropped = false; -}; - -static int sampleStaticLoad = RegisterSample( "Issues", "Static Load", StaticLoad::Create ); diff --git a/samples/sample_joint.cpp b/samples/sample_joint.cpp index ecf8ede..ac5d2fd 100644 --- a/samples/sample_joint.cpp +++ b/samples/sample_joint.cpp @@ -1161,7 +1161,7 @@ public: b3Vec3 linearVelocity = b3Body_GetLinearVelocity( m_bodyId ); float kineticEnergy = 0.5f * b3Dot( angularVelocity, b3MulMV( massData.inertia, angularVelocity ) ); kineticEnergy += 0.5f * massData.mass * b3Dot( linearVelocity, linearVelocity ); - b3Pos center = b3Body_GetWorldCenter( m_bodyId ); + b3Pos center = b3Body_GetWorldCenterOfMass( m_bodyId ); b3Vec3 gravity = b3World_GetGravity( m_worldId ); float potentialEnergy = -massData.mass * center.y * gravity.y; DrawTextLine( "kinetic energy = %g", kineticEnergy ); @@ -1953,67 +1953,6 @@ public: static int sampleBridgeIndex = RegisterSample( "Joints", "Bridge", Bridge::Create ); -class FoldOut : public Sample -{ -public: - explicit FoldOut( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 28.0f, { 0.0f, 7.0f, 0.0f } ); - } - - float halfLength = 2.0f; - float spacing = 1.0f; - - b3BoxHull box = b3MakeBoxHull( halfLength, 0.1f, 0.25f ); - - b3Quat axisQuat = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisZ, b3Vec3_axisY ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.localFrameA.p = { -halfLength, 1.0f, 0.0f }; - jointDef.base.localFrameA.q = axisQuat; - jointDef.base.localFrameB.q = axisQuat; - jointDef.base.drawScale = 0.5f; - jointDef.base.constraintHertz = 240.0f; - jointDef.enableMotor = true; - jointDef.maxMotorTorque = 1000.0f; - - b3BodyId prevBodyId = AddGroundBox( 20.0f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position.y = 0.5f * spacing; - bodyDef.type = b3_dynamicBody; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density *= 2.0f; - - for ( int i = 0; i < 6; ++i ) - { - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - float x = ( i & 1 ) ? halfLength : -halfLength; - - jointDef.base.bodyIdA = prevBodyId; - jointDef.base.bodyIdB = bodyId; - jointDef.base.localFrameB.p = { x, -0.5f * spacing, 0.0f }; - b3CreateRevoluteJoint( m_worldId, &jointDef ); - - bodyDef.position.y += spacing; - jointDef.base.localFrameA.p = { -x, 0.5f * spacing, 0.0f }; - prevBodyId = bodyId; - } - } - - static Sample* Create( SampleContext* context ) - { - return new FoldOut( context ); - } -}; - -static int sampleFoldOut = RegisterSample( "Joints", "Fold Out", FoldOut::Create ); - // This test ensures joints work correctly with bodies that have motion locks class MotionLocks : public Sample { @@ -2061,8 +2000,6 @@ public: assert( m_count < m_capacity ); bodyDef.position = position; - bodyDef.angularDamping = 0.5f; - m_bodyIds[m_count] = b3CreateBody( m_worldId, &bodyDef ); b3CreateHullShape( m_bodyIds[m_count], &shapeDef, &box.base ); @@ -2320,8 +2257,6 @@ public: m_upperSteeringDegrees = 45.0f; m_maxSteeringTorque = 5.0f; m_targetSteeringDegrees = 0.0f; - m_wheelType = WheelType::sphere; - m_cylinderSides = 16; b3BodyId groundId; { @@ -2373,10 +2308,15 @@ public: b3CreateParallelJoint( m_worldId, ¶llelJointDef ); } + shapeDef.density = 2.0f; + shapeDef.baseMaterial.friction = 3.0f; + bodyDef.type = b3_dynamicBody; bodyDef.allowFastRotation = true; bodyDef.rotation = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisY, b3Vec3_axisZ ); + // b3HullData* hull = b3CreateCylinder( 0.25f, 0.4f, 0.0f, 16 ); + b3WheelJointDef jointDef = b3DefaultWheelJointDef(); jointDef.base.bodyIdA = m_chassisId; jointDef.base.localFrameA.q = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisX, b3Vec3_axisY ); @@ -2398,11 +2338,15 @@ public: jointDef.lowerSteeringLimit = B3_PI / 180.0f * m_lowerSteeringDegrees; jointDef.upperSteeringLimit = B3_PI / 180.0f * m_upperSteeringDegrees; + b3Sphere sphere = { b3Vec3_zero, 0.4f }; + { bodyDef.position = { 1.5f, 2.0f, 0.8f }; - m_wheelIds[0] = b3CreateBody( m_worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + // b3CreateHullShape( bodyId, &shapeDef, hull ); - jointDef.base.bodyIdB = m_wheelIds[0]; + jointDef.base.bodyIdB = bodyId; jointDef.base.localFrameA.p = { 1.5f, -0.5f, 0.8f }; jointDef.enableSteering = true; jointDef.enableSpinMotor = false; @@ -2411,9 +2355,11 @@ public: { bodyDef.position = { 1.5f, 2.0f, -0.8f }; - m_wheelIds[1] = b3CreateBody( m_worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + // b3CreateHullShape( bodyId, &shapeDef, hull ); - jointDef.base.bodyIdB = m_wheelIds[1]; + jointDef.base.bodyIdB = bodyId; jointDef.base.localFrameA.p = { 1.5f, -0.5f, -0.8f }; jointDef.enableSteering = true; jointDef.enableSpinMotor = false; @@ -2422,9 +2368,11 @@ public: { bodyDef.position = { -1.5f, 2.0f, 0.8f }; - m_wheelIds[2] = b3CreateBody( m_worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + // b3CreateHullShape( bodyId, &shapeDef, hull ); - jointDef.base.bodyIdB = m_wheelIds[2]; + jointDef.base.bodyIdB = bodyId; jointDef.base.localFrameA.p = { -1.5f, -0.5f, 0.8f }; jointDef.enableSteering = false; jointDef.enableSpinMotor = true; @@ -2433,21 +2381,18 @@ public: { bodyDef.position = { -1.5f, 2.0f, -0.8f }; - m_wheelIds[3] = b3CreateBody( m_worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + // b3CreateHullShape( bodyId, &shapeDef, hull ); - jointDef.base.bodyIdB = m_wheelIds[3]; + jointDef.base.bodyIdB = bodyId; jointDef.base.localFrameA.p = { -1.5f, -0.5f, -0.8f }; jointDef.enableSteering = false; jointDef.enableSpinMotor = true; m_rearRightId = b3CreateWheelJoint( m_worldId, &jointDef ); } - for ( int i = 0; i < 4; ++i ) - { - m_wheelShapeIds[i] = b3_nullShapeId; - } - - CreateWheelShapes(); + // b3DestroyHull( hull ); m_camera->m_thirdPerson = false; @@ -2458,7 +2403,7 @@ public: ~Driving() override { - if ( m_camera->m_thirdPerson ) + if (m_camera->m_thirdPerson) { m_camera->m_thirdPerson = false; sapp_lock_mouse( false ); @@ -2466,59 +2411,6 @@ public: b3DestroyHeightField( m_heightField ); } - void CreateWheelShapes() - { - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 2.0f; - shapeDef.baseMaterial.friction = 3.0f; - - float radius = 0.4f; - float width = 0.25f; - - b3HullData* cylinder = nullptr; - if ( m_wheelType == WheelType::cylinder ) - { - float w = 1.5f * width; - cylinder = b3CreateCylinder( w, radius, -0.5f * w, m_cylinderSides ); - } - - for ( int i = 0; i < 4; ++i ) - { - if ( B3_IS_NON_NULL( m_wheelShapeIds[i] ) ) - { - b3DestroyShape( m_wheelShapeIds[i], false ); - } - - b3BodyId bodyId = m_wheelIds[i]; - - switch ( m_wheelType ) - { - case WheelType::sphere: - { - b3Sphere sphere = { b3Vec3_zero, radius }; - m_wheelShapeIds[i] = b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - break; - - case WheelType::capsule: - { - b3Capsule capsule = { { 0.0f, -0.5f * width, 0.0f }, { 0.0f, 0.5f * width, 0.0f }, radius }; - m_wheelShapeIds[i] = b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - break; - - case WheelType::cylinder: - m_wheelShapeIds[i] = b3CreateHullShape( bodyId, &shapeDef, cylinder ); - break; - } - } - - if ( cylinder != nullptr ) - { - b3DestroyHull( cylinder ); - } - } - void Keyboard( int key, int action, int mods ) override { if ( key == KEY_T && action == ACTION_PRESS ) @@ -2529,32 +2421,6 @@ public: bool DrawControls() override { - ImGui::Text( "Wheels" ); - if ( ImGui::RadioButton( "Sphere", m_wheelType == WheelType::sphere ) ) - { - m_wheelType = WheelType::sphere; - CreateWheelShapes(); - } - - if ( ImGui::RadioButton( "Capsule", m_wheelType == WheelType::capsule ) ) - { - m_wheelType = WheelType::capsule; - CreateWheelShapes(); - } - - if ( ImGui::RadioButton( "Cylinder", m_wheelType == WheelType::cylinder ) ) - { - m_wheelType = WheelType::cylinder; - CreateWheelShapes(); - } - - if ( ImGui::SliderInt( "Sides", &m_cylinderSides, 3, 32 ) && m_wheelType == WheelType::cylinder ) - { - CreateWheelShapes(); - } - - ImGui::Separator(); - ImGui::Text( "Suspension" ); if ( ImGui::SliderFloat( "Min##Suspension", &m_lowerTranslation, -10.0f, 10.0f, "%.1f" ) ) { @@ -2730,19 +2596,8 @@ public: return new Driving( context ); } - enum class WheelType - { - sphere, - capsule, - cylinder, - }; - b3HeightFieldData* m_heightField; b3BodyId m_chassisId; - b3BodyId m_wheelIds[4]; - b3ShapeId m_wheelShapeIds[4]; - WheelType m_wheelType; - int m_cylinderSides; b3JointId m_frontLeftId; b3JointId m_frontRightId; b3JointId m_rearLeftId; diff --git a/samples/sample_manifold.cpp b/samples/sample_manifold.cpp index a3875f9..c51a4f3 100644 --- a/samples/sample_manifold.cpp +++ b/samples/sample_manifold.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "ghost_oracle.h" #include "gfx/draw.h" #include "gfx/keycodes.h" #include "sample.h" @@ -10,60 +9,6 @@ #include "box3d/constants.h" #include -#include -#include - -#include - -static void DrawGizmoControls( bool* show, bool* local ) -{ - ImGui::Checkbox( "Gizmo (G)", show ); - ImGui::Checkbox( "Local axes", local ); -} - -// Must run inside the ImGui frame. The view is eye relative, so the shape is placed against the -// draw origin. -static void DrawTransformGizmo( const Camera* camera, b3WorldTransform* transform, bool local ) -{ - ImGuizmo::BeginFrame(); - - // Behind the panels like the in-world labels - ImGuizmo::SetDrawlist( ImGui::GetBackgroundDrawList() ); - - ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGuizmo::SetRect( viewport->Pos.x, viewport->Pos.y, viewport->Size.x, viewport->Size.y ); - ImGuizmo::SetOrthographic( false ); - - // Alt drag orbits the camera - ImGuizmo::Enable( ImGui::GetIO().KeyAlt == false ); - - ImGuizmo::OPERATION operation = ImGuizmo::TRANSLATE | ImGuizmo::ROTATE; - - b3Pos origin = GetDrawOrigin(); - b3Vec3 offset = b3SubPos( transform->p, origin ); - b3Matrix3 r = b3MakeMatrixFromQuat( transform->q ); - Mat4 matrix = { - { r.cx.x, r.cx.y, r.cx.z, 0.0f }, - { r.cy.x, r.cy.y, r.cy.z, 0.0f }, - { r.cz.x, r.cz.y, r.cz.z, 0.0f }, - { offset.x, offset.y, offset.z, 1.0f }, - }; - - Mat4 view = camera->View(); - Mat4 proj = camera->Proj(); - ImGuizmo::MODE space = local ? ImGuizmo::LOCAL : ImGuizmo::WORLD; - if ( ImGuizmo::Manipulate( &view.cx.x, &proj.cx.x, operation, space, &matrix.cx.x ) ) - { - // Rotation drags accumulate in the matrix, the quaternion keeps it orthonormal - b3Matrix3 m = { - { matrix.cx.x, matrix.cx.y, matrix.cx.z }, - { matrix.cy.x, matrix.cy.y, matrix.cy.z }, - { matrix.cz.x, matrix.cz.y, matrix.cz.z }, - }; - transform->q = b3NormalizeQuat( b3MakeQuatFromMatrix( &m ) ); - transform->p = b3OffsetPos( origin, { matrix.cw.x, matrix.cw.y, matrix.cw.z } ); - } -} class Manifold : public Sample { @@ -93,20 +38,24 @@ public: m_simplexCache = {}; m_satCache = {}; m_manualFeature = 0; - m_drawPoints = true; + m_baseTranslation = b3Pos_zero; + m_baseQuaternion = b3Quat_identity; + m_baseX = 0; + m_baseY = 0; + m_origin = b3Pos_zero; m_useCache = false; - m_showGizmo = true; - m_gizmoLocal = false; + m_tracking = false; + m_rotating = false; } void Render() override { + DrawTextLine( "origin: %g %g %g", m_origin.x, m_origin.y, m_origin.z ); DrawTextLine( "count = %d", m_manifold.pointCount ); - DrawAxes( b3WorldTransform_identity, 0.5f ); - DrawGroundGrid( 80 ); + DrawAxes( b3WorldTransform_identity, 1.0f ); - if ( m_manifold.pointCount == 0 || m_drawPoints == false ) + if ( m_manifold.pointCount == 0 ) { return; } @@ -135,8 +84,8 @@ public: b3Vec3 perp = b3Perp( normal ); b3FeaturePair pair = manifoldPoint.pair; - DrawString3D( point + 0.025f * normal + 0.05f * perp, MakeColor( b3_colorPapayaWhip ), - " %X:%X %X:%X", pair.owner1, pair.index1, pair.owner2, pair.index2 ); + DrawString3D( point + 0.025f * normal + 0.05f * perp, MakeColor( b3_colorPapayaWhip ), " %X:%X %X:%X", pair.owner1, + pair.index1, pair.owner2, pair.index2 ); } Sample::Render(); @@ -158,31 +107,54 @@ public: ImGui::RadioButton( "edgePair", &m_manualFeature, 3 ); } - ImGui::Checkbox( "Draw Points", &m_drawPoints ); - DrawGizmoControls( &m_showGizmo, &m_gizmoLocal ); - return true; } - void Keyboard( int key, int action, int modifiers ) override - { - if ( key == KEY_G && action == ACTION_PRESS && modifiers == 0 ) - { - m_showGizmo = !m_showGizmo; - } - } - - void DrawSampleWindows() override - { - if ( m_showGizmo ) - { - DrawTransformGizmo( m_camera, &m_transformB, m_gizmoLocal ); - } - } - - // The gizmo moves the shape, so keep the picking in Sample off void MouseDown( b3Vec2 p, int button, int modifiers ) override { + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) + { + if ( modifiers & MOD_SHIFT ) + { + m_baseX = p.x; + m_baseY = p.y; + m_baseQuaternion = m_transformB.q; + m_rotating = true; + } + else + { + PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); + m_origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); + m_baseTranslation = m_transformB.p; + m_tracking = true; + } + } + } + + void MouseUp( b3Vec2 p, int button ) override + { + m_tracking = false; + m_rotating = false; + } + + void MouseMove( b3Vec2 p ) override + { + if ( m_tracking ) + { + PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); + b3Pos origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); + m_transformB.p = m_baseTranslation + b3SubPos( origin, m_origin ); + } + + if ( m_rotating ) + { + int x = p.x; + int y = p.y; + + b3Quat qx = b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.01f * ( x - m_baseX ) ); + b3Quat qz = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.01f * ( y - m_baseY ) ); + m_transformB.q = b3NormalizeQuat( b3MulQuat( m_baseQuaternion, b3MulQuat( qx, qz ) ) ); + } } static constexpr int m_pointCapacity = 64; @@ -190,13 +162,17 @@ public: b3LocalManifoldPoint m_points[m_pointCapacity]; b3WorldTransform m_transformA; b3WorldTransform m_transformB; + b3Pos m_baseTranslation; + b3Quat m_baseQuaternion; + b3Pos m_origin; b3SimplexCache m_simplexCache; b3SATCache m_satCache; int m_manualFeature; + int m_baseX; + int m_baseY; bool m_useCache; - bool m_drawPoints; - bool m_showGizmo; - bool m_gizmoLocal; + bool m_tracking; + bool m_rotating; }; class TriangleManifold : public Sample @@ -226,21 +202,26 @@ public: m_simplexCache = {}; m_satCache = {}; + m_baseTranslation = b3Pos_zero; + m_baseQuaternion = b3Quat_identity; + m_baseX = 0; + m_baseY = 0; + m_origin = b3Pos_zero; m_useCache = false; + m_tracking = false; + m_rotating = false; m_manualFeature = 0; - m_showGizmo = true; - m_gizmoLocal = false; } void Render() override { + DrawTextLine( "origin: %g %g %g", m_origin.x, m_origin.y, m_origin.z ); DrawTextLine( "count = %d", m_manifold.pointCount ); DrawTextLine( "feature = %d", m_manifold.feature ); DrawTextLine( "cache hit = %d", m_satCache.hit ); DrawAxes( b3WorldTransform_identity, 1.0f ); - DrawGroundGrid( 10 ); if ( m_manifold.pointCount > 0 ) { @@ -251,7 +232,7 @@ public: { const b3LocalManifoldPoint& manifoldPoint = m_manifold.points[pointIndex]; - b3Pos point = b3TransformWorldPoint( m_transformB, manifoldPoint.point ); + b3Pos point = b3TransformWorldPoint(m_transformB, manifoldPoint.point ); DrawLine( point, point + length * normal, MakeColor( b3_colorWhite ) ); if ( manifoldPoint.separation > 0.0f ) @@ -263,17 +244,15 @@ public: DrawPoint( point, 10.0f, MakeColor( b3_colorYellow ) ); } - DrawString3D( point, MakeColor( b3_colorWhite ), " %.2f", - 100.0f * manifoldPoint.separation ); + DrawString3D( point, MakeColor( b3_colorWhite ), " %.2f", 100.0f * manifoldPoint.separation ); b3FeaturePair pair = manifoldPoint.pair; - DrawString3D( point + 0.025f * normal, MakeColor( b3_colorPapayaWhip ), - " %X:%X %X:%X", pair.owner1, pair.index1, pair.owner2, pair.index2 ); + DrawString3D( point + 0.025f * normal, MakeColor( b3_colorPapayaWhip ), " %X:%X %X:%X", pair.owner1, + pair.index1, pair.owner2, pair.index2 ); } } - DrawTriangle( m_transformA, m_triangle[0], m_triangle[1], m_triangle[2], - MakeColor( b3_colorCyan ) ); + DrawTriangle( m_transformA, m_triangle[0], m_triangle[1], m_triangle[2], MakeColor( b3_colorCyan ) ); b3Pos p1 = b3TransformWorldPoint( m_transformA, m_triangle[0] ); b3Pos p2 = b3TransformWorldPoint( m_transformA, m_triangle[1] ); @@ -305,30 +284,54 @@ public: ImGui::RadioButton( "edgePair", &m_manualFeature, 3 ); } - DrawGizmoControls( &m_showGizmo, &m_gizmoLocal ); - return true; } - void Keyboard( int key, int action, int modifiers ) override - { - if ( key == KEY_G && action == ACTION_PRESS && modifiers == 0 ) - { - m_showGizmo = !m_showGizmo; - } - } - - void DrawSampleWindows() override - { - if ( m_showGizmo ) - { - DrawTransformGizmo( m_camera, &m_transformB, m_gizmoLocal ); - } - } - - // The gizmo moves the shape, so keep the picking in Sample off void MouseDown( b3Vec2 p, int button, int modifiers ) override { + if ( button == 0 && ( modifiers & MOD_ALT ) == 0 ) + { + if ( modifiers & MOD_SHIFT ) + { + m_baseX = p.x; + m_baseY = p.y; + m_baseQuaternion = m_transformB.q; + m_rotating = true; + } + else + { + PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); + m_origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); + m_baseTranslation = m_transformB.p; + m_tracking = true; + } + } + } + + void MouseUp( b3Vec2 p, int button ) override + { + m_tracking = false; + m_rotating = false; + } + + void MouseMove( b3Vec2 p ) override + { + if ( m_tracking ) + { + PickRay pickRay = m_camera->BuildPickRay( p.x, p.y ); + b3Pos origin = pickRay.origin + 10.0f * b3Normalize( pickRay.translation ); + m_transformB.p = m_baseTranslation + b3SubPos( origin, m_origin ); + } + + if ( m_rotating ) + { + int x = p.x; + int y = p.y; + + b3Quat qx = b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.01f * ( x - m_baseX ) ); + b3Quat qz = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.01f * ( y - m_baseY ) ); + m_transformB.q = b3NormalizeQuat( b3MulQuat( m_baseQuaternion, b3MulQuat( qx, qz ) ) ); + } } static constexpr int m_pointCapacity = 8; @@ -342,12 +345,17 @@ public: b3WorldTransform m_transformB; b3Vec3 m_triangle[3] = {}; + b3Pos m_baseTranslation; + b3Quat m_baseQuaternion; + b3Pos m_origin; b3SimplexCache m_simplexCache; b3SATCache m_satCache; int m_manualFeature; + int m_baseX; + int m_baseY; bool m_useCache; - bool m_showGizmo; - bool m_gizmoLocal; + bool m_tracking; + bool m_rotating; }; class SphereAndSphere : public Manifold @@ -381,8 +389,7 @@ public: b3Sphere m_sphere; }; -static int sampleCollideSpheres = - RegisterSample( "Manifold", "Sphere vs Sphere", SphereAndSphere::Create ); +static int sampleCollideSpheres = RegisterSample( "Manifold", "Sphere vs Sphere", SphereAndSphere::Create ); class CapsuleAndSphere : public Manifold { @@ -413,16 +420,14 @@ public: void Step() override { b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - b3CollideCapsuleAndSphere( &m_manifold, m_pointCapacity, &m_capsule, &m_sphere, - transformBtoA ); + b3CollideCapsuleAndSphere( &m_manifold, m_pointCapacity, &m_capsule, &m_sphere, transformBtoA ); } b3Sphere m_sphere; b3Capsule m_capsule; }; -static int sampleSphereAndCapsule = - RegisterSample( "Manifold", "Capsule vs Sphere", CapsuleAndSphere::Create ); +static int sampleSphereAndCapsule = RegisterSample( "Manifold", "Capsule vs Sphere", CapsuleAndSphere::Create ); class HullAndSphere : public Manifold { @@ -453,8 +458,7 @@ public: } b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - b3CollideHullAndSphere( &m_manifold, m_pointCapacity, &m_hull.base, &m_sphere, - transformBtoA, &m_simplexCache ); + b3CollideHullAndSphere( &m_manifold, m_pointCapacity, &m_hull.base, &m_sphere, transformBtoA, &m_simplexCache ); } static Sample* Create( SampleContext* sampleContext ) @@ -466,8 +470,7 @@ public: b3BoxHull m_hull; }; -static int sampleSphereAndHull = - RegisterSample( "Manifold", "Hull vs Sphere", HullAndSphere::Create ); +static int sampleSphereAndHull = RegisterSample( "Manifold", "Hull vs Sphere", HullAndSphere::Create ); class TriangleAndSphere : public TriangleManifold { @@ -514,14 +517,13 @@ public: b3TransformPoint( xf, m_triangle[2] ), }; - b3CollideTriangleAndSphere( &m_manifold, m_pointCapacity, localTriangle, &m_sphere ); + b3CollideSphereAndTriangle( &m_manifold, m_pointCapacity, &m_sphere, localTriangle ); } b3Sphere m_sphere; }; -static int sampleSphereAndTriangle = - RegisterSample( "Manifold", "Triangle vs Sphere", TriangleAndSphere::Create ); +static int sampleSphereAndTriangle = RegisterSample( "Manifold", "Triangle vs Sphere", TriangleAndSphere::Create ); class CapsuleAndCapsule : public Manifold { @@ -557,8 +559,7 @@ public: b3Capsule m_capsule; }; -static int sampleCapsuleAndCapsule = - RegisterSample( "Manifold", "Capsule vs Capsule", CapsuleAndCapsule::Create ); +static int sampleCapsuleAndCapsule = RegisterSample( "Manifold", "Capsule vs Capsule", CapsuleAndCapsule::Create ); class CapsuleAndHull : public Manifold { @@ -571,7 +572,7 @@ public: m_camera->SetView( 0.0f, 30.0f, 5.0f, b3Pos_zero ); } - m_capsule = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, 0.15f }; + m_capsule = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, 0.5f }; m_hull = b3MakeBoxHull( 1.0f, 0.5f, 0.5f ); m_transformA = { { 0.0f, 0.0f, 0.0f }, b3Quat_identity }; @@ -582,8 +583,7 @@ public: q [ [ -0.00256555085, -0.0201825816, 0.126076236 ], 0.991811991 ] b3Quat */ // m_capsule = { - // { 0.0799999982, -0.0151330000, -0.0918010026 }, { -0.0799999982, -0.0151330000, - //-0.0918010026 }, 0.100000001 }; + // { 0.0799999982, -0.0151330000, -0.0918010026 }, { -0.0799999982, -0.0151330000, -0.0918010026 }, 0.100000001 }; // m_hull = b3CreateBox( { 0.5f, 1.0f, 1.5f } ); m_transformB = { { 1.58523774, 0.729615569, 0.451690674 }, @@ -606,8 +606,7 @@ public: } b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - b3CollideHullAndCapsule( &m_manifold, m_pointCapacity, &m_hull.base, &m_capsule, - transformBtoA, &m_simplexCache ); + b3CollideHullAndCapsule( &m_manifold, m_pointCapacity, &m_hull.base, &m_capsule, transformBtoA, &m_simplexCache ); } static Sample* Create( SampleContext* sampleContext ) @@ -619,8 +618,7 @@ public: b3Capsule m_capsule; }; -static int sampleCapsuleAndHull = - RegisterSample( "Manifold", "Capsule vs Hull", CapsuleAndHull::Create ); +static int sampleCapsuleAndHull = RegisterSample( "Manifold", "Capsule vs Hull", CapsuleAndHull::Create ); class TriangleAndCapsule : public TriangleManifold { @@ -638,13 +636,17 @@ public: m_camera->SetView( 0.0f, 30.0f, 10.0f, b3Pos_zero ); } - m_capsule = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, 0.05f }; + m_capsule = { { 0.0f, -0.2f, 0.0f }, { 0.0f, 0.2f, 0.0f }, 0.05f }; m_triangle[0] = { -4.0f, 0.0f, -4.0f }; m_triangle[1] = { -4.0f, 0.0f, 0.0f }; m_triangle[2] = { 0.0f, 0.0f, 0.0f }; m_transformA = b3WorldTransform_identity; - m_transformB = { { -1.0f, 0.0f, -1.0f }, b3Quat_identity }; + m_transformB = { { 0.0f, 0.5f, 0.0f }, b3Quat_identity }; + m_transformB.q = b3MakeQuatFromAxisAngle( { 0.0f, 0.0f, 1.0f }, 0.5f * B3_PI ); + + m_transformB = { { -0.500000000, 0.123778239, -0.500000000 }, + { { -0.157559350, 0.294042289, 0.821513653 }, -0.462417006 } }; } void Render() override @@ -670,15 +672,13 @@ public: b3TransformPoint( xf, m_triangle[2] ), }; - b3CollideTriangleAndCapsule( &m_manifold, m_pointCapacity, localTriangle, &m_capsule, - &m_simplexCache ); + b3CollideCapsuleAndTriangle( &m_manifold, m_pointCapacity, &m_capsule, localTriangle, &m_simplexCache ); } b3Capsule m_capsule; }; -static int sampleCapsuleAndTriangle = - RegisterSample( "Manifold", "Triangle vs Capsule", TriangleAndCapsule::Create ); +static int sampleCapsuleAndTriangle = RegisterSample( "Manifold", "Triangle vs Capsule", TriangleAndCapsule::Create ); class HullAndHull : public Manifold { @@ -691,8 +691,7 @@ public: m_camera->SetView( 0.0f, 15.0f, 4.0f, b3Pos_zero ); } - // m_boxA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, { { 0.0f, -0.5f, 0.0f }, - // b3Quat_identity } ); + // m_boxA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, { { 0.0f, -0.5f, 0.0f }, b3Quat_identity } ); b3Transform transform = { { 1.0f, 0.5f, 0.0f }, b3Quat_identity }; m_boxA = b3MakeTransformedBoxHull( 0.5f, 1.0f, 1.0f, transform ); @@ -705,12 +704,12 @@ public: m_hullB = &m_boxB.base; /* -- xfA {p=[ -10.0000000, 0.00000000, -10.0000000 ] q=[ [ 0.00000000, 0.00000000, 0.00000000 -], 1.00000000 ] } b3Transform + p [ -10.0000000, 0.00000000, -10.0000000 ] b3Vec3 + -q [ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] b3Quat - xfB {p=[ --10.0000000, 1.00000000, -10.0000000 ] q=[ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] } -b3Transform + p [ -10.0000000, 1.00000000, -10.0000000 ] b3Vec3 + q [ [ -0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] b3Quat +- xfA {p=[ -10.0000000, 0.00000000, -10.0000000 ] q=[ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] } b3Transform ++ p [ -10.0000000, 0.00000000, -10.0000000 ] b3Vec3 ++ q [ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] b3Quat +- xfB {p=[ -10.0000000, 1.00000000, -10.0000000 ] q=[ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] } b3Transform ++ p [ -10.0000000, 1.00000000, -10.0000000 ] b3Vec3 ++ q [ [ 0.00000000, 0.00000000, 0.00000000 ], 1.00000000 ] b3Quat */ m_transformA = { { 0.0f, 0.0f, 0.0f }, b3Quat_identity }; @@ -796,8 +795,7 @@ b3Transform + p [ -10.0000000, 1.00000000, -10.0000000 ] b3Vec3 + q [ [ } b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - b3CollideHulls( &m_manifold, m_pointCapacity, m_hullA, m_hullB, transformBtoA, - &m_satCache ); + b3CollideHulls( &m_manifold, m_pointCapacity, m_hullA, m_hullB, transformBtoA, &m_satCache ); DrawTextLine( "SAT type: %d", m_satCache.type ); } @@ -815,1139 +813,6 @@ b3Transform + p [ -10.0000000, 1.00000000, -10.0000000 ] b3Vec3 + q [ [ static int sampleCollideHulls = RegisterSample( "Manifold", "Hull vs Hull", HullAndHull::Create ); -// Shows the candidate axes culled in the separating axis test. No axis n can separate the hulls by -// more than dot(n, centerB - centerA) - innerRadiusA - innerRadiusB, so any face whose bound is -// below the best separation found so far is skipped. An edge survives only if the plane separation -// of the other hull's inscribed sphere can beat the best face separation somewhere over the Gauss -// map arc of the edge. The support points of the best faces lie on the other hull, so they give a -// second, tighter arc test. This recomputes the culling decisions of b3ComputeSeparatingAxis from -// public hull data and must be kept in sync with it. -class HullCulling : public Manifold -{ -public: - enum FeatureState - { - e_unreached = 0, - e_culled, - e_tested, - }; - - enum EdgeBound - { - e_noBound = 0, - e_sphereBound, - e_supportBound, - e_bothBounds, - }; - - // Mirrors B3_EDGE_PROBE_MIN_TESTS - static constexpr int probeMinTests = 10; - - explicit HullCulling( SampleContext* context ) - : Manifold( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 20.0f, 20.0f, 14.0f, { 0.0f, 1.8f, 0.0f } ); - } - - m_useCylinders = false; - m_cylinderHeight = 2.0f; - m_cylinderRadius = 2.0f; - m_cylinderSides = 32; - m_hullA = nullptr; - m_hullB = nullptr; - CreateHulls(); - - m_transformA = { { 0.0f, 0.0f, 0.0f }, b3Quat_identity }; - m_transformB = { { 0.4f, 3.6f, 0.2f }, - b3MakeQuatFromAxisAngle( b3Normalize( { 1.0f, 0.0f, 1.0f } ), 0.3f ) }; - - m_showSpheres = true; - m_showCulled = true; - m_showNormals = true; - m_edgeBound = e_bothBounds; - ResetCounts(); - } - - ~HullCulling() override - { - b3DestroyHull( m_hullA ); - b3DestroyHull( m_hullB ); - } - - void CreateHulls() - { - if ( m_hullA != nullptr ) - { - b3DestroyHull( m_hullA ); - b3DestroyHull( m_hullB ); - } - - if ( m_useCylinders ) - { - float yOffset = -0.5f * m_cylinderHeight; - m_hullA = - b3CreateCylinder( m_cylinderHeight, m_cylinderRadius, yOffset, m_cylinderSides ); - m_hullB = - b3CreateCylinder( m_cylinderHeight, m_cylinderRadius, yOffset, m_cylinderSides ); - } - else - { - m_hullA = b3CreateComplexHull( 2.0f ); - m_hullB = b3CreateComplexHull( 2.0f ); - } - } - - bool DrawControls() override - { - Manifold::DrawControls(); - - ImGui::Checkbox( "Inscribed spheres", &m_showSpheres ); - ImGui::Checkbox( "Culled features", &m_showCulled ); - ImGui::Checkbox( "Face normals", &m_showNormals ); - const char* edgeBounds[] = { "None", "Sphere", "Support", "Sphere + Support" }; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::SetNextItemWidth( ImGui::CalcTextSize( edgeBounds[3] ).x + ImGui::GetFrameHeight() + - 2.0f * style.FramePadding.x ); - ImGui::Combo( "Edge bound", &m_edgeBound, edgeBounds, IM_ARRAYSIZE( edgeBounds ) ); - - bool rebuild = ImGui::Checkbox( "Cylinders", &m_useCylinders ); - if ( m_useCylinders ) - { - rebuild |= ImGui::SliderFloat( "Height", &m_cylinderHeight, 0.1f, 8.0f, "%.2f" ); - rebuild |= ImGui::SliderFloat( "Radius", &m_cylinderRadius, 0.1f, 4.0f, "%.2f" ); - rebuild |= ImGui::SliderInt( "Sides", &m_cylinderSides, 3, 32 ); - } - - if ( rebuild ) - { - m_cylinderHeight = b3ClampFloat( m_cylinderHeight, 0.1f, 8.0f ); - m_cylinderRadius = b3ClampFloat( m_cylinderRadius, 0.1f, 4.0f ); - m_cylinderSides = b3ClampInt( m_cylinderSides, 3, 32 ); - CreateHulls(); - } - - return true; - } - - void ResetCounts() - { - memset( m_faceStateA, 0, sizeof( m_faceStateA ) ); - memset( m_faceStateB, 0, sizeof( m_faceStateB ) ); - memset( m_edgeStateA, 0, sizeof( m_edgeStateA ) ); - memset( m_edgeStateB, 0, sizeof( m_edgeStateB ) ); - m_seedA = 0; - m_seedB = 0; - m_probeVertexA = 0; - m_probeVertexB = 0; - m_keptEdgeCountA = 0; - m_keptEdgeCountB = 0; - m_sphereKeptEdgeCountA = 0; - m_sphereKeptEdgeCountB = 0; - m_separationA = -FLT_MAX; - m_separationB = -FLT_MAX; - m_gap = 0.0f; - m_probeApplied = false; - m_separatedFeature = b3_invalidAxis; - } - - // Face of A against the vertices of B, in frame A. The deepest vertex of B is the support - // point. - static float FaceSeparationA( const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, int faceIndex, - int* vertexIndex = nullptr ) - { - b3Plane plane = b3GetHullPlanes( hullA )[faceIndex]; - const b3Vec3* points = b3GetHullPoints( hullB ); - float separation = FLT_MAX; - int bestIndex = 0; - for ( int i = 0; i < hullB->vertexCount; ++i ) - { - b3Vec3 point = b3TransformPoint( transformBtoA, points[i] ); - float s = b3Dot( plane.normal, point ) - plane.offset; - if ( s < separation ) - { - separation = s; - bestIndex = i; - } - } - - if ( vertexIndex != nullptr ) - { - *vertexIndex = bestIndex; - } - - return separation; - } - - // Face of B against the vertices of A, in frame B. The deepest vertex of A is the support - // point. - static float FaceSeparationB( const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, int faceIndex, - int* vertexIndex = nullptr ) - { - b3Plane plane = b3GetHullPlanes( hullB )[faceIndex]; - const b3Vec3* points = b3GetHullPoints( hullA ); - float separation = FLT_MAX; - int bestIndex = 0; - for ( int i = 0; i < hullA->vertexCount; ++i ) - { - b3Vec3 point = b3InvTransformPoint( transformBtoA, points[i] ); - float s = b3Dot( plane.normal, point ) - plane.offset; - if ( s < separation ) - { - separation = s; - bestIndex = i; - } - } - - if ( vertexIndex != nullptr ) - { - *vertexIndex = bestIndex; - } - - return separation; - } - - // Mirrors b3TestEdgeCandidateSorted - static bool ArcCanReachSorted( float a, float b, float c, float bound ) - { - const float parallelTolerance = 1.0e-4f; - float hi = b3MaxFloat( a, b ); - float lo = b3MinFloat( a, b ); - float u = lo - c * hi; - float s = 1.0f - c * c; - bool exterior = hi >= bound; - bool interior = - u >= 0.0f && ( u * u >= ( bound - hi ) * ( bound + hi ) * s || s < parallelTolerance ); - return exterior || interior; - } - - // Arc test of every surviving edge against the plane separations of a point on the other hull. - // Mirrors the gather loops and b3FilterEdgeCandidates, edges that fail are culled. - static int CullEdges( const b3HullData* hull, b3Vec3 point, float bound, uint8_t* states ) - { - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Plane* planes = b3GetHullPlanes( hull ); - const float* cosines = b3GetHullEdgeCosines( hull ); - int keptCount = 0; - for ( int i = 0; i < hull->edgeCount; i += 2 ) - { - if ( states[i / 2] == e_culled ) - { - continue; - } - - b3Plane plane1 = planes[edges[i].face]; - b3Plane plane2 = planes[edges[i + 1].face]; - float d1 = b3Dot( plane1.normal, point ) - plane1.offset; - float d2 = b3Dot( plane2.normal, point ) - plane2.offset; - bool kept = ArcCanReachSorted( d1, d2, cosines[i >> 1], bound ); - states[i / 2] = kept ? e_tested : e_culled; - keptCount += kept ? 1 : 0; - } - return keptCount; - } - - // Mirrors the culling in b3ComputeSeparatingAxis with early return enabled - void ComputeCulling( b3Transform transformBtoA ) - { - ResetCounts(); - - const b3HullData* hullA = m_hullA; - const b3HullData* hullB = m_hullB; - const b3Plane* planesA = b3GetHullPlanes( hullA ); - const b3Plane* planesB = b3GetHullPlanes( hullB ); - float speculativeDistance = B3_SPECULATIVE_DISTANCE; - - b3Vec3 deltaCenter = - b3Sub( b3TransformPoint( transformBtoA, hullB->center ), hullA->center ); - float centerDistance = b3Length( deltaCenter ); - float radius = hullA->innerRadius + hullB->innerRadius; - float radiusBound = radius - ( B3_LINEAR_SLOP + 0.001f * ( centerDistance + radius ) ); - m_gap = centerDistance - radius; - - float dotA[B3_MAX_HULL_FACES]; - for ( int i = 0; i < hullA->faceCount; ++i ) - { - dotA[i] = b3Dot( planesA[i].normal, deltaCenter ); - m_seedA = dotA[i] > dotA[m_seedA] ? i : m_seedA; - } - - // The seed support vertex stands in for the probe if no face improves on it - float seedSeparationA = - FaceSeparationA( hullA, hullB, transformBtoA, m_seedA, &m_probeVertexB ); - float floorA = b3MinFloat( seedSeparationA, speculativeDistance ); - for ( int i = 0; i < hullA->faceCount; ++i ) - { - if ( dotA[i] - radiusBound < b3MaxFloat( floorA, m_separationA ) ) - { - m_faceStateA[i] = e_culled; - continue; - } - - m_faceStateA[i] = e_tested; - int vertexIndex; - float separation = FaceSeparationA( hullA, hullB, transformBtoA, i, &vertexIndex ); - if ( separation > m_separationA ) - { - m_separationA = separation; - m_probeVertexB = vertexIndex; - if ( separation > speculativeDistance ) - { - m_separatedFeature = b3_faceAxisA; - return; - } - } - } - - b3Vec3 deltaCenterB = b3Neg( b3InvRotateVector( transformBtoA.q, deltaCenter ) ); - float dotB[B3_MAX_HULL_FACES]; - for ( int i = 0; i < hullB->faceCount; ++i ) - { - dotB[i] = b3Dot( planesB[i].normal, deltaCenterB ); - m_seedB = dotB[i] > dotB[m_seedB] ? i : m_seedB; - } - - float seedSeparationB = - FaceSeparationB( hullA, hullB, transformBtoA, m_seedB, &m_probeVertexA ); - float floorB = b3MaxFloat( seedSeparationB, m_separationA ); - floorB = b3MinFloat( floorB, speculativeDistance ); - for ( int i = 0; i < hullB->faceCount; ++i ) - { - if ( dotB[i] - radiusBound < b3MaxFloat( floorB, m_separationB ) ) - { - m_faceStateB[i] = e_culled; - continue; - } - - m_faceStateB[i] = e_tested; - int vertexIndex; - float separation = FaceSeparationB( hullA, hullB, transformBtoA, i, &vertexIndex ); - if ( separation > m_separationB ) - { - m_separationB = separation; - m_probeVertexA = vertexIndex; - if ( separation > speculativeDistance ) - { - m_separatedFeature = b3_faceAxisB; - return; - } - } - } - - bool useSphere = m_edgeBound == e_sphereBound || m_edgeBound == e_bothBounds; - bool useSupport = m_edgeBound == e_supportBound || m_edgeBound == e_bothBounds; - float maxFaceSeparation = b3MaxFloat( m_separationA, m_separationB ); - - if ( useSphere ) - { - // Inscribed sphere bound, the arc inputs are plane separations of the other hull's - // center - float boundSlack = radius - radiusBound; - float thresholdA = maxFaceSeparation + hullB->innerRadius - boundSlack; - float thresholdB = maxFaceSeparation + hullA->innerRadius - boundSlack; - b3Vec3 centerBinA = b3TransformPoint( transformBtoA, hullB->center ); - b3Vec3 centerAinB = b3InvTransformPoint( transformBtoA, hullA->center ); - m_keptEdgeCountA = CullEdges( hullA, centerBinA, thresholdA, m_edgeStateA ); - m_keptEdgeCountB = CullEdges( hullB, centerAinB, thresholdB, m_edgeStateB ); - } - else - { - m_keptEdgeCountA = hullA->edgeCount / 2; - m_keptEdgeCountB = hullB->edgeCount / 2; - memset( m_edgeStateA, e_tested, m_keptEdgeCountA ); - memset( m_edgeStateB, e_tested, m_keptEdgeCountB ); - } - - m_sphereKeptEdgeCountA = m_keptEdgeCountA; - m_sphereKeptEdgeCountB = m_keptEdgeCountB; - - // The probe is gated on the edge pair work in SIMD groups of A edges - int testCount = m_keptEdgeCountB * ( ( m_keptEdgeCountA + 3 ) >> 2 ); - m_probeApplied = useSupport && testCount >= probeMinTests; - if ( m_probeApplied ) - { - float probeBound = - maxFaceSeparation - - ( 0.1f * B3_LINEAR_SLOP + 0.001f * b3AbsFloat( centerDistance + radius ) ); - b3Vec3 probeB = - b3TransformPoint( transformBtoA, b3GetHullPoints( hullB )[m_probeVertexB] ); - b3Vec3 probeA = - b3InvTransformPoint( transformBtoA, b3GetHullPoints( hullA )[m_probeVertexA] ); - m_keptEdgeCountA = CullEdges( hullA, probeB, probeBound, m_edgeStateA ); - m_keptEdgeCountB = CullEdges( hullB, probeA, probeBound, m_edgeStateB ); - } - } - - void Step() override - { - // Clear the cache so every step runs the full separating axis test - m_satCache = {}; - b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - b3CollideHulls( &m_manifold, m_pointCapacity, m_hullA, m_hullB, transformBtoA, - &m_satCache ); - ComputeCulling( transformBtoA ); - } - - static int CountState( const uint8_t* states, int count, FeatureState state ) - { - int n = 0; - for ( int i = 0; i < count; ++i ) - { - n += states[i] == state ? 1 : 0; - } - return n; - } - - void DrawEdges( b3WorldTransform transform, const b3HullData* hull, const uint8_t* states, - Vec4 keptColor ) - { - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Vec3* points = b3GetHullPoints( hull ); - for ( int i = 0; i < hull->edgeCount; i += 2 ) - { - b3Pos p1 = b3TransformWorldPoint( transform, points[edges[i].origin] ); - b3Pos p2 = b3TransformWorldPoint( transform, points[edges[i + 1].origin] ); - uint8_t state = states[i / 2]; - if ( state == e_tested ) - { - DrawLineEx( p1, p2, keptColor, 4.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DIM ); - } - else if ( state == e_culled && m_showCulled ) - { - DrawLine( p1, p2, MakeColor( b3_colorSlateGray ) ); - } - else if ( state == e_unreached ) - { - DrawLineEx( p1, p2, MakeColor( b3_colorDimGray ), 1.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DASHED ); - } - } - } - - void DrawFaceNormals( b3WorldTransform transform, const b3HullData* hull, const uint8_t* states, - int seed, Vec4 testedColor ) - { - const b3HullFace* faces = b3GetHullFaces( hull ); - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Plane* planes = b3GetHullPlanes( hull ); - const b3Vec3* points = b3GetHullPoints( hull ); - float length = 0.4f * b3GetLengthUnitsPerMeter(); - - for ( int i = 0; i < hull->faceCount; ++i ) - { - uint8_t state = states[i]; - if ( state == e_unreached || ( state == e_culled && m_showCulled == false ) ) - { - continue; - } - - b3Vec3 centroid = b3Vec3_zero; - int count = 0; - int edgeIndex = faces[i].edge; - do - { - centroid = b3Add( centroid, points[edges[edgeIndex].origin] ); - count += 1; - edgeIndex = edges[edgeIndex].next; - } - while ( edgeIndex != faces[i].edge ); - centroid = b3MulSV( 1.0f / (float)count, centroid ); - - b3Pos p1 = b3TransformWorldPoint( transform, centroid ); - b3Pos p2 = - b3TransformWorldPoint( transform, b3MulAdd( centroid, length, planes[i].normal ) ); - - if ( i == seed ) - { - DrawArrowEx( p1, p2, MakeColor( b3_colorGold ), 3.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DIM, 0.25f ); - } - else if ( state == e_tested ) - { - DrawArrowEx( p1, p2, testedColor, 2.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DIM, 0.25f ); - } - else - { - DrawLine( p1, p2, MakeColor( b3_colorSlateGray ) ); - } - } - } - - void Render() override - { - const b3HullData* hullA = m_hullA; - const b3HullData* hullB = m_hullB; - - DrawEdges( m_transformA, hullA, m_edgeStateA, MakeColor( b3_colorOrange ) ); - DrawEdges( m_transformB, hullB, m_edgeStateB, MakeColor( b3_colorDeepSkyBlue ) ); - - if ( m_showNormals ) - { - DrawFaceNormals( m_transformA, hullA, m_faceStateA, m_seedA, - MakeColor( b3_colorOrange ) ); - DrawFaceNormals( m_transformB, hullB, m_faceStateB, m_seedB, - MakeColor( b3_colorDeepSkyBlue ) ); - } - - b3Pos centerA = b3TransformWorldPoint( m_transformA, hullA->center ); - b3Pos centerB = b3TransformWorldPoint( m_transformB, hullB->center ); - DrawLine( centerA, centerB, MakeColor( b3_colorWhite ) ); - - if ( m_showSpheres ) - { - b3Sphere sphereA = { hullA->center, hullA->innerRadius }; - b3Sphere sphereB = { hullB->center, hullB->innerRadius }; - DrawWireSphere( m_transformA, &sphereA, 32, MakeColor( b3_colorOrange ) ); - DrawWireSphere( m_transformB, &sphereB, 32, MakeColor( b3_colorDeepSkyBlue ) ); - } - - if ( m_probeApplied ) - { - b3Pos probeA = - b3TransformWorldPoint( m_transformA, b3GetHullPoints( hullA )[m_probeVertexA] ); - b3Pos probeB = - b3TransformWorldPoint( m_transformB, b3GetHullPoints( hullB )[m_probeVertexB] ); - DrawPoint( probeA, 12.0f, MakeColor( b3_colorMagenta ) ); - DrawPoint( probeB, 12.0f, MakeColor( b3_colorMagenta ) ); - } - - int faceCountA = hullA->faceCount; - int faceCountB = hullB->faceCount; - int edgeCountA = hullA->edgeCount / 2; - int edgeCountB = hullB->edgeCount / 2; - int testedA = CountState( m_faceStateA, faceCountA, e_tested ); - int testedB = CountState( m_faceStateB, faceCountB, e_tested ); - int culledA = CountState( m_faceStateA, faceCountA, e_culled ); - int culledB = CountState( m_faceStateB, faceCountB, e_culled ); - bool edgesReached = m_separatedFeature == b3_invalidAxis; - int seedCount = m_separatedFeature == b3_faceAxisA ? 1 : 2; - - DrawTextLine( "vertices %d, faces %d, edges %d", hullA->vertexCount, faceCountA, - edgeCountA ); - DrawTextLine( "|d| - rA - rB = %.3f", m_gap ); - DrawTextLine( "faces A: tested %d, culled %d of %d, best separation %.4f", testedA, culledA, - faceCountA, m_separationA ); - - if ( m_separatedFeature == b3_faceAxisA ) - { - DrawTextLine( "separated by face A, B faces and edges not reached" ); - } - else - { - DrawTextLine( "faces B: tested %d, culled %d of %d, best separation %.4f", testedB, - culledB, faceCountB, m_separationB ); - } - - if ( m_separatedFeature == b3_faceAxisB ) - { - DrawTextLine( "separated by face B, edges not reached" ); - } - - DrawTextLine( "support queries: %d of %d (including %d seed)", - testedA + testedB + seedCount, faceCountA + faceCountB, seedCount ); - - if ( edgesReached ) - { - int pairCount = m_keptEdgeCountA * m_keptEdgeCountB; - int totalPairCount = edgeCountA * edgeCountB; - DrawTextLine( "edges kept: A %d of %d, B %d of %d", m_keptEdgeCountA, edgeCountA, - m_keptEdgeCountB, edgeCountB ); - DrawTextLine( "edge pairs: %d of %d (%.1f%%)", pairCount, totalPairCount, - 100.0f * pairCount / totalPairCount ); - - if ( m_probeApplied && m_edgeBound == e_bothBounds ) - { - int spherePairCount = m_sphereKeptEdgeCountA * m_sphereKeptEdgeCountB; - DrawTextLine( "sphere bound: A %d, B %d, edge pairs %d (%.1f%%)", - m_sphereKeptEdgeCountA, m_sphereKeptEdgeCountB, spherePairCount, - 100.0f * spherePairCount / totalPairCount ); - } - - if ( m_probeApplied ) - { - DrawTextLine( "magenta points are the support probes" ); - } - else if ( m_edgeBound == e_supportBound || m_edgeBound == e_bothBounds ) - { - DrawTextLine( "probe skipped, fewer than %d edge tests", probeMinTests ); - } - } - - DrawTextLine( "SAT type: %d", m_satCache.type ); - - Manifold::Render(); - } - - static Sample* Create( SampleContext* context ) - { - return new HullCulling( context ); - } - - b3HullData* m_hullA; - b3HullData* m_hullB; - uint8_t m_faceStateA[B3_MAX_HULL_FACES]; - uint8_t m_faceStateB[B3_MAX_HULL_FACES]; - uint8_t m_edgeStateA[B3_MAX_HULL_EDGES]; - uint8_t m_edgeStateB[B3_MAX_HULL_EDGES]; - int m_seedA; - int m_seedB; - - // Support vertex on each hull for the best face of the other, it probes the edges of the other - // hull - int m_probeVertexA; - int m_probeVertexB; - - int m_keptEdgeCountA; - int m_keptEdgeCountB; - int m_sphereKeptEdgeCountA; - int m_sphereKeptEdgeCountB; - float m_separationA; - float m_separationB; - float m_gap; - b3SeparatingFeature m_separatedFeature; - float m_cylinderHeight; - float m_cylinderRadius; - int m_cylinderSides; - bool m_useCylinders; - bool m_showSpheres; - bool m_showCulled; - bool m_showNormals; - int m_edgeBound; - bool m_probeApplied; -}; - -static int sampleHullCulling = RegisterSample( "Manifold", "Hull Culling", HullCulling::Create ); - -// Shows that an edge pair can win the separating axis test even when the direction between the hull -// centers peaks outside the Gauss map arc (wedge) of one of its edges. The inscribed sphere bound -// of such an edge peaks at a face normal at the end of its arc, yet the edge axis beats the real -// separation of those faces. So outside wedge edges can only be culled by their sphere bound, not -// by the face results. Everything here is brute force over all faces and all edge pairs, -// independent of the pruning in the SAT. -class EdgeAxisWedge : public Manifold -{ -public: - struct EdgeAxis - { - b3Vec3 normal; - float separation; - int edgeA; - int edgeB; - }; - - // Gauss map arc of one edge in frame A, with the peak of dot(n, d) on its great circle - struct Arc - { - b3Vec3 u; - b3Vec3 v; - b3Vec3 peak; - float a; - float b; - float c; - float separationU; - float separationV; - - // Angle from the peak to the nearest end of the arc, negative when the peak is on the arc - float outsideDegrees; - bool inside; - }; - - explicit EdgeAxisWedge( SampleContext* context ) - : Manifold( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 0.0f, 15.0f, 22.0f, { -4.5f, 1.0f, 0.0f } ); - } - - m_transformA = { { 0.0f, 0.0f, 0.0f }, b3Quat_identity }; - m_transformB = { { 0.0f, 3.6f, 0.0f }, b3Quat_identity }; - - m_gaussCenter = { -10.0f, 1.0f, 0.0f }; - m_gaussRadius = 2.0f; - m_searchCount = 0; - m_searchFound = false; - m_hullType = e_slab; - m_createdHull = nullptr; - - // Start with an example - SetHull( m_hullType ); - } - - ~EdgeAxisWedge() override - { - if ( m_createdHull != nullptr ) - { - b3DestroyHull( m_createdHull ); - } - } - - enum HullType - { - e_slab = 0, - e_tetrahedron, - e_complex, - }; - - // Both hulls are the same shape - void SetHull( int type ) - { - if ( m_createdHull != nullptr ) - { - b3DestroyHull( m_createdHull ); - m_createdHull = nullptr; - } - - if ( type == e_slab ) - { - m_box = b3MakeBoxHull( 2.0f, 0.25f, 1.0f ); - m_hullA = &m_box.base; - } - else if ( type == e_tetrahedron ) - { - b3Vec3 points[4] = { { 1.0f, 1.0f, 1.0f }, - { 1.0f, -1.0f, -1.0f }, - { -1.0f, 1.0f, -1.0f }, - { -1.0f, -1.0f, 1.0f } }; - m_createdHull = b3CreateHull( points, 4, 4 ); - m_hullA = m_createdHull; - } - else - { - m_createdHull = b3CreateComplexHull( 2.0f ); - m_hullA = m_createdHull; - } - - m_hullB = m_hullA; - m_hullType = type; - m_seed = 12345; - Search(); - } - - float RandomFloat() - { - m_seed = m_seed * 1664525u + 1013904223u; - return (float)( m_seed >> 8 ) / 16777216.0f; - } - - b3Vec3 RandomDirection() - { - b3Vec3 v; - float lengthSquared; - do - { - v = { 2.0f * RandomFloat() - 1.0f, 2.0f * RandomFloat() - 1.0f, - 2.0f * RandomFloat() - 1.0f }; - lengthSquared = b3Dot( v, v ); - } - while ( lengthSquared > 1.0f || lengthSquared < 0.01f ); - - return b3Normalize( v ); - } - - // Mirrors the Gauss map test and edge axis of the scalar path in b3ComputeSeparatingAxis, - // without pruning - static EdgeAxis FindBestEdgeAxis( const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA ) - { - const b3HullHalfEdge* edgesA = b3GetHullEdges( hullA ); - const b3Plane* planesA = b3GetHullPlanes( hullA ); - const b3Vec3* pointsA = b3GetHullPoints( hullA ); - const b3HullHalfEdge* edgesB = b3GetHullEdges( hullB ); - const b3Plane* planesB = b3GetHullPlanes( hullB ); - const b3Vec3* pointsB = b3GetHullPoints( hullB ); - - const float eps = -0.0001f; - float squaredTolerance = B3_PARALLEL_EDGE_TOL * B3_PARALLEL_EDGE_TOL; - - EdgeAxis best = { b3Vec3_zero, -FLT_MAX, B3_NULL_INDEX, B3_NULL_INDEX }; - - for ( int j = 0; j < hullB->edgeCount; j += 2 ) - { - // B face normals and vertices in frame A, negated - b3Vec3 C = b3Neg( b3RotateVector( transformBtoA.q, planesB[edgesB[j].face].normal ) ); - b3Vec3 D = - b3Neg( b3RotateVector( transformBtoA.q, planesB[edgesB[j + 1].face].normal ) ); - b3Vec3 bv0 = b3Neg( b3TransformPoint( transformBtoA, pointsB[edgesB[j].origin] ) ); - b3Vec3 bv1 = b3Neg( b3TransformPoint( transformBtoA, pointsB[edgesB[j + 1].origin] ) ); - b3Vec3 DC = b3Sub( bv1, bv0 ); - - for ( int i = 0; i < hullA->edgeCount; i += 2 ) - { - b3Vec3 n0 = planesA[edgesA[i].face].normal; - b3Vec3 n1 = planesA[edgesA[i + 1].face].normal; - b3Vec3 av0 = pointsA[edgesA[i].origin]; - b3Vec3 edge = b3Sub( pointsA[edgesA[i + 1].origin], av0 ); - - float CBA = b3Dot( C, edge ); - float DBA = b3Dot( D, edge ); - float ADC = b3Dot( n0, DC ); - float BDC = b3Dot( n1, DC ); - if ( CBA * DBA >= eps || ADC * BDC >= eps || CBA * BDC >= eps ) - { - continue; - } - - if ( b3MaxFloat( CBA * CBA, DBA * DBA ) <= squaredTolerance * b3Dot( edge, edge ) ) - { - continue; - } - - float t = -CBA / ( DBA - CBA ); - b3Vec3 normal = b3Normalize( b3MulAdd( C, t, b3Sub( D, C ) ) ); - float separation = -b3Dot( normal, b3Add( av0, bv0 ) ); - if ( separation > best.separation ) - { - best = { normal, separation, i, j }; - } - } - } - - return best; - } - - // The peak of dot(n, d) over the great circle through u and v, and whether it lies on the arc - static Arc MakeArc( b3Vec3 u, b3Vec3 v, b3Vec3 d, float separationU, float separationV ) - { - Arc arc; - arc.u = u; - arc.v = v; - arc.a = b3Dot( u, d ); - arc.b = b3Dot( v, d ); - arc.c = b3Dot( u, v ); - arc.inside = arc.a >= arc.c * arc.b && arc.b >= arc.c * arc.a; - arc.separationU = separationU; - arc.separationV = separationV; - - b3Vec3 axis = b3Normalize( b3Cross( u, v ) ); - b3Vec3 inPlane = b3MulSub( d, b3Dot( d, axis ), axis ); - arc.peak = b3LengthSquared( inPlane ) > 1.0e-12f ? b3Normalize( inPlane ) : u; - - float arcAngle = acosf( b3ClampFloat( arc.c, -1.0f, 1.0f ) ); - float angleU = acosf( b3ClampFloat( b3Dot( u, arc.peak ), -1.0f, 1.0f ) ); - float angleV = acosf( b3ClampFloat( b3Dot( v, arc.peak ), -1.0f, 1.0f ) ); - float nearest = b3MinFloat( angleU, angleV ) * 180.0f / B3_PI; - arc.outsideDegrees = ( angleU <= arcAngle && angleV <= arcAngle ) ? -nearest : nearest; - return arc; - } - - float MaxSeparation( b3Transform transformBtoA, float* faceSeparationA, float* faceSeparationB, - EdgeAxis* edgeAxis ) const - { - float separationA = -FLT_MAX; - for ( int i = 0; i < m_hullA->faceCount; ++i ) - { - separationA = b3MaxFloat( - separationA, HullCulling::FaceSeparationA( m_hullA, m_hullB, transformBtoA, i ) ); - } - - float separationB = -FLT_MAX; - for ( int i = 0; i < m_hullB->faceCount; ++i ) - { - separationB = b3MaxFloat( - separationB, HullCulling::FaceSeparationB( m_hullA, m_hullB, transformBtoA, i ) ); - } - - EdgeAxis edge = FindBestEdgeAxis( m_hullA, m_hullB, transformBtoA ); - - if ( faceSeparationA != nullptr ) - { - *faceSeparationA = separationA; - *faceSeparationB = separationB; - *edgeAxis = edge; - } - - return b3MaxFloat( edge.separation, b3MaxFloat( separationA, separationB ) ); - } - - // Random poses placed just into contact until an edge axis wins with an edge outside its wedge - void Search() - { - m_searchFound = false; - m_searchCount = 0; - - for ( int trial = 0; trial < 500 && m_searchFound == false; ++trial ) - { - m_searchCount += 1; - - b3Vec3 direction = RandomDirection(); - b3Vec3 axis = RandomDirection(); - float angle = 2.0f * B3_PI * RandomFloat(); - b3Quat rotation = b3MakeQuatFromAxisAngle( axis, angle ); - - // Bisect on the center distance to reach a slight overlap - float target = -0.02f * b3GetLengthUnitsPerMeter(); - float lower = 0.0f; - float upper = 1.1f * ( b3Length( b3AABB_Extents( m_hullA->aabb ) ) + - b3Length( b3AABB_Extents( m_hullB->aabb ) ) ); - for ( int iteration = 0; iteration < 24; ++iteration ) - { - float mid = 0.5f * ( lower + upper ); - b3Transform transform = { b3MulSV( mid, direction ), rotation }; - if ( MaxSeparation( transform, nullptr, nullptr, nullptr ) < target ) - { - lower = mid; - } - else - { - upper = mid; - } - } - - m_transformB = { m_transformA.p + b3MulSV( upper, direction ), rotation }; - Compute(); - - // Only accept clear examples, well outside the wedge with a clear edge win - float margin = m_edge.separation - b3MaxFloat( m_faceSeparationA, m_faceSeparationB ); - float outside = b3MaxFloat( m_arcA.outsideDegrees, m_arcB.outsideDegrees ); - m_searchFound = - m_edgeWins && outside >= 10.0f && margin >= 0.02f * b3GetLengthUnitsPerMeter(); - } - } - - void Compute() - { - b3Transform transformBtoA = b3InvMulWorldTransforms( m_transformA, m_transformB ); - MaxSeparation( transformBtoA, &m_faceSeparationA, &m_faceSeparationB, &m_edge ); - m_edgeWins = m_edge.edgeA != B3_NULL_INDEX && - m_edge.separation > b3MaxFloat( m_faceSeparationA, m_faceSeparationB ); - - m_centerOffset = - b3Sub( b3TransformPoint( transformBtoA, m_hullB->center ), m_hullA->center ); - m_radius = m_hullA->innerRadius + m_hullB->innerRadius; - - if ( m_edge.edgeA == B3_NULL_INDEX ) - { - return; - } - - const b3HullHalfEdge* edgesA = b3GetHullEdges( m_hullA ); - const b3Plane* planesA = b3GetHullPlanes( m_hullA ); - int faceA1 = edgesA[m_edge.edgeA].face; - int faceA2 = edgesA[m_edge.edgeA + 1].face; - m_arcA = MakeArc( planesA[faceA1].normal, planesA[faceA2].normal, m_centerOffset, - HullCulling::FaceSeparationA( m_hullA, m_hullB, transformBtoA, faceA1 ), - HullCulling::FaceSeparationA( m_hullA, m_hullB, transformBtoA, faceA2 ) ); - - const b3HullHalfEdge* edgesB = b3GetHullEdges( m_hullB ); - const b3Plane* planesB = b3GetHullPlanes( m_hullB ); - int faceB1 = edgesB[m_edge.edgeB].face; - int faceB2 = edgesB[m_edge.edgeB + 1].face; - b3Vec3 C = b3Neg( b3RotateVector( transformBtoA.q, planesB[faceB1].normal ) ); - b3Vec3 D = b3Neg( b3RotateVector( transformBtoA.q, planesB[faceB2].normal ) ); - m_arcB = MakeArc( C, D, m_centerOffset, - HullCulling::FaceSeparationB( m_hullA, m_hullB, transformBtoA, faceB1 ), - HullCulling::FaceSeparationB( m_hullA, m_hullB, transformBtoA, faceB2 ) ); - } - - bool DrawControls() override - { - const char* hullNames[] = { "Slab", "Tetrahedron", "Complex Hull" }; - int hullType = m_hullType; - if ( ImGui::Combo( "Hull", &hullType, hullNames, IM_ARRAYSIZE( hullNames ) ) ) - { - SetHull( hullType ); - } - - if ( ImGui::Button( "Find Example" ) ) - { - Search(); - } - - DrawGizmoControls( &m_showGizmo, &m_gizmoLocal ); - - return true; - } - - void Step() override - { - Compute(); - } - - b3Pos GaussPoint( b3Vec3 directionInA ) const - { - return m_gaussCenter + - b3MulSV( m_gaussRadius, b3RotateVector( m_transformA.q, directionInA ) ); - } - - void DrawGreatArc( b3Vec3 u, b3Vec3 v, Vec4 color, float thickness, - OverlayOcclusionMode mode ) const - { - constexpr int segmentCount = 32; - b3Pos previous = GaussPoint( u ); - for ( int i = 1; i <= segmentCount; ++i ) - { - float s = (float)i / segmentCount; - b3Pos point = - GaussPoint( b3Normalize( b3Add( b3MulSV( 1.0f - s, u ), b3MulSV( s, v ) ) ) ); - DrawLineEx( previous, point, color, thickness, OVERLAY_THICKNESS_PIXELS, mode ); - previous = point; - } - } - - // The full great circle through the arc, dashed - void DrawGreatCircle( b3Vec3 u, b3Vec3 v, Vec4 color ) const - { - b3Vec3 axis = b3Normalize( b3Cross( u, v ) ); - b3Vec3 w = b3Cross( axis, u ); - constexpr int segmentCount = 96; - b3CosSin cs = b3ComputeCosSin( 2.0f * B3_PI / segmentCount ); - float x1 = 1.0f, y1 = 0.0f; - b3Pos previous = GaussPoint( u ); - for ( int i = 0; i < segmentCount; ++i ) - { - float x2 = cs.cosine * x1 - cs.sine * y1; - float y2 = cs.sine * x1 + cs.cosine * y1; - b3Pos point = GaussPoint( b3Add( b3MulSV( x2, u ), b3MulSV( y2, w ) ) ); - DrawLineEx( previous, point, color, 1.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DASHED ); - x1 = x2; - y1 = y2; - previous = point; - } - } - - void DrawEdge( b3WorldTransform transform, const b3HullData* hull, int edgeIndex, - Vec4 color ) const - { - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Vec3* points = b3GetHullPoints( hull ); - b3Pos p1 = b3TransformWorldPoint( transform, points[edges[edgeIndex].origin] ); - b3Pos p2 = b3TransformWorldPoint( transform, points[edges[edgeIndex + 1].origin] ); - DrawLineEx( p1, p2, color, 5.0f, OVERLAY_THICKNESS_PIXELS, OVERLAY_OCCLUSION_DIM ); - } - - void DrawArcText( const char* name, const Arc& arc, float edgeBound ) - { - if ( arc.inside ) - { - DrawTextLine( "%s edge: d peak inside wedge", name ); - } - else - { - DrawTextLine( "%s edge: d peak OUTSIDE wedge by %.1f degrees", name, - arc.outsideDegrees ); - } - DrawTextLine( " sphere bound u %.3f v %.3f n %.3f", arc.a - m_radius, arc.b - m_radius, - edgeBound ); - DrawTextLine( " separation u %.4f v %.4f n %.4f", arc.separationU, arc.separationV, - m_edge.separation ); - } - - void Render() override - { - DrawHull( m_transformA, m_hullA, MakeColor( b3_colorSlateGray ) ); - DrawHull( m_transformB, m_hullB, MakeColor( b3_colorSlateGray ) ); - - b3Pos centerA = b3TransformWorldPoint( m_transformA, m_hullA->center ); - b3Pos centerB = b3TransformWorldPoint( m_transformB, m_hullB->center ); - DrawLine( centerA, centerB, MakeColor( b3_colorWhite ) ); - - DrawTextLine( "search: %s after %d poses", m_searchFound ? "found" : "not found", - m_searchCount ); - DrawTextLine( "best separation: face A %.4f, face B %.4f, edge %.4f -> %s", - m_faceSeparationA, m_faceSeparationB, m_edge.separation, - m_edgeWins ? "EDGE WINS" : "face wins" ); - - if ( m_edge.edgeA == B3_NULL_INDEX ) - { - Manifold::Render(); - return; - } - - Vec4 colorA = MakeColor( b3_colorOrange ); - Vec4 colorB = MakeColor( b3_colorDeepSkyBlue ); - Vec4 colorN = MakeColor( b3_colorGold ); - Vec4 colorPeak = MakeColor( b3_colorMagenta ); - - DrawEdge( m_transformA, m_hullA, m_edge.edgeA, colorA ); - DrawEdge( m_transformB, m_hullB, m_edge.edgeB, colorB ); - - // Winning axis from the midpoint of edge A - { - const b3HullHalfEdge* edges = b3GetHullEdges( m_hullA ); - const b3Vec3* points = b3GetHullPoints( m_hullA ); - b3Vec3 mid = b3Lerp( points[edges[m_edge.edgeA].origin], - points[edges[m_edge.edgeA + 1].origin], 0.5f ); - b3Pos p = b3TransformWorldPoint( m_transformA, mid ); - b3Vec3 n = b3RotateVector( m_transformA.q, m_edge.normal ); - DrawArrowEx( p, p + b3MulSV( 1.0f, n ), colorN, 3.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DIM, 0.2f ); - } - - // Gauss map: both arcs cross at the edge axis n. The magenta dots are the peaks of dot(n, - // d) on each great circle. The peak of an arc is only reachable when it lies on the arc. - b3Sphere unitSphere = { b3Vec3_zero, m_gaussRadius }; - DrawWireSphere( { m_gaussCenter, b3Quat_identity }, &unitSphere, 24, - MakeColor( b3_colorDimGray ) ); - - DrawGreatCircle( m_arcA.u, m_arcA.v, colorA ); - DrawGreatCircle( m_arcB.u, m_arcB.v, colorB ); - DrawGreatArc( m_arcA.u, m_arcA.v, colorA, 5.0f, OVERLAY_OCCLUSION_DIM ); - DrawGreatArc( m_arcB.u, m_arcB.v, colorB, 5.0f, OVERLAY_OCCLUSION_DIM ); - - DrawPoint( GaussPoint( m_arcA.u ), 8.0f, colorA ); - DrawPoint( GaussPoint( m_arcA.v ), 8.0f, colorA ); - DrawPoint( GaussPoint( m_arcB.u ), 8.0f, colorB ); - DrawPoint( GaussPoint( m_arcB.v ), 8.0f, colorB ); - DrawString3D( GaussPoint( m_arcA.u ), colorA, " uA" ); - DrawString3D( GaussPoint( m_arcA.v ), colorA, " vA" ); - DrawString3D( GaussPoint( m_arcB.u ), colorB, " uB" ); - DrawString3D( GaussPoint( m_arcB.v ), colorB, " vB" ); - - DrawPoint( GaussPoint( m_arcA.peak ), 10.0f, colorPeak ); - DrawString3D( GaussPoint( m_arcA.peak ), colorPeak, " peak A" ); - DrawPoint( GaussPoint( m_arcB.peak ), 10.0f, colorPeak ); - DrawString3D( GaussPoint( m_arcB.peak ), colorPeak, " peak B" ); - - DrawPoint( GaussPoint( m_edge.normal ), 12.0f, colorN ); - DrawString3D( GaussPoint( m_edge.normal ), colorN, " n" ); - - b3Vec3 dHat = b3Normalize( m_centerOffset ); - DrawPoint( GaussPoint( dHat ), 10.0f, MakeColor( b3_colorWhite ) ); - DrawString3D( GaussPoint( dHat ), MakeColor( b3_colorWhite ), " d" ); - - float edgeBound = b3Dot( m_edge.normal, m_centerOffset ) - m_radius; - DrawTextLine( "|d| - rA - rB = %.3f", b3Length( m_centerOffset ) - m_radius ); - DrawArcText( "A", m_arcA, edgeBound ); - DrawArcText( "B", m_arcB, edgeBound ); - - Manifold::Render(); - } - - static Sample* Create( SampleContext* context ) - { - return new EdgeAxisWedge( context ); - } - - b3HullData* m_hullA; - b3HullData* m_hullB; - EdgeAxis m_edge; - Arc m_arcA; - Arc m_arcB; - b3Vec3 m_centerOffset; - b3Pos m_gaussCenter; - float m_gaussRadius; - float m_radius; - float m_faceSeparationA; - float m_faceSeparationB; - uint32_t m_seed; - int m_searchCount; - bool m_searchFound; - bool m_edgeWins; - b3BoxHull m_box; - b3HullData* m_createdHull; - int m_hullType; -}; - -static int sampleEdgeAxisWedge = - RegisterSample( "Manifold", "Edge Axis Wedge", EdgeAxisWedge::Create ); - class TriangleAndHull : public TriangleManifold { public: @@ -1964,22 +829,18 @@ public: m_camera->SetView( 0.0f, 30.0f, 3.0f, b3Pos_zero ); } - // m_triangle[0] = { 1.00000000, 0, 1.00000000 }; - // m_triangle[1] = { 1.00000000, 0, 0.00000000 }; - // m_triangle[2] = { 0.00000000, 0, 0.00000000 }; + m_triangle[0] = { 1.00000000, 0, 1.00000000 }; + m_triangle[1] = { 1.00000000, 0, 0.00000000 }; + m_triangle[2] = { 0.00000000, 0, 0.00000000 }; - // Deep overlap where the hull face normal crosses the triangle edge, so SAT tries the edge pair, - // but the edge closest points fall outside the segments. Only the hull face clip keeps a contact, - // GJK sees overlap and returns nothing. - m_triangle[0] = { 0.259390f, -0.178787f, -0.292602f }; - m_triangle[1] = { 0.861452f, 0.228978f, 0.393873f }; - m_triangle[2] = { -0.539058f, 0.127502f, 0.225728f }; - - m_boxHull = b3MakeBoxHull( 0.4f, 0.2f, 0.4f ); + m_boxHull = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); m_transformA = b3WorldTransform_identity; m_transformB = b3WorldTransform_identity; - // m_transformB.p = { -2.16650009f, 0.912535489f, 0.00000000f }; + m_transformB.p = { 0.0f, 0.45f, 0.1f }; + + // b3MeshEdgeFlags + m_flags = 0; /* * separation -0.0415397286 float @@ -2049,1603 +910,14 @@ public: b3TransformPoint( xf, m_triangle[2] ), }; - b3CollideTriangleAndHull( &m_manifold, m_pointCapacity, localTriangle[0], localTriangle[1], - localTriangle[2], m_hull, &m_satCache, true ); + b3CollideHullAndTriangle( &m_manifold, m_pointCapacity, m_hull, localTriangle[0], localTriangle[1], localTriangle[2], + m_flags, &m_satCache ); } + int m_flags; b3BoxHull m_boxHull; b3HullData* m_cylinder; b3HullData* m_hull; }; -static int sampleHullAndTriangle = - RegisterSample( "Manifold", "Triangle vs Hull", TriangleAndHull::Create ); - -// Minimal meshes that each show one kind of ghost collision and how ghost handling treats it. -// Contacts are computed fresh every step with the same triangle pipeline the world uses, so a -// breakpoint in the mesh collide function stops on this scene. Derive per shape type. -struct GhostMesh -{ - std::vector vertices; - std::vector indices; -}; - -typedef void GhostMeshBuildFcn( std::vector& meshes ); - -struct GhostScene -{ - const char* name; - const char* ghost; - const char* handling; - GhostMeshBuildFcn* build; - - // Interpreted by the derived sample, for example box half extents - b3Vec3 extents; - - b3Vec3 position; - - // Degrees, applied as yaw * pitch * roll - b3Vec3 angles; - - bool speculative; -}; - -// Most surfaces in these scenes face up, so wind each triangle upward unless told otherwise -static void AddGhostTriangle( GhostMesh& mesh, int a, int b, int c, b3Vec3 facing = b3Vec3_axisY ) -{ - b3Vec3 va = mesh.vertices[a]; - b3Vec3 normal = b3Cross( b3Sub( mesh.vertices[b], va ), b3Sub( mesh.vertices[c], va ) ); - if ( b3Dot( normal, facing ) < 0.0f ) - { - int temp = b; - b = c; - c = temp; - } - - mesh.indices.push_back( a ); - mesh.indices.push_back( b ); - mesh.indices.push_back( c ); -} - -class GhostManifold : public Sample -{ -public: - static constexpr int m_maxScenes = 20; - static constexpr int m_manifoldCapacity = 32; - static constexpr int m_triangleCapacity = 64; - static constexpr int m_trianglePointCapacity = 64; - - enum EdgeType - { - e_boundaryEdge, - e_flatEdge, - e_convexEdge, - e_concaveEdge, - }; - - struct MeshView - { - GhostMesh source; - std::vector edgeTypes; - - // By engine triangle index, which differs from the source order - std::vector triangleCenters; - b3MeshData* data; - }; - - struct TriangleResult - { - b3LocalManifold manifold; - b3LocalManifoldPoint points[m_trianglePointCapacity]; - }; - - explicit GhostManifold( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 30.0f, 25.0f, 4.0f, { 0.0f, 0.3f, 0.0f } ); - } - - m_scenes = nullptr; - m_sceneCount = 0; - m_sceneIndex = 0; - m_handleGhosts = true; - m_speculative = true; - m_drawTriangleManifolds = false; - m_drawTriangleIndices = false; - m_drawVertexIndices = false; - m_cullDistance = 0.5f; - m_showGizmo = false; - m_gizmoLocal = false; - m_transform = b3WorldTransform_identity; - m_manifoldCount = 0; - m_triangleManifoldCount = 0; - } - - ~GhostManifold() override - { - DestroyMeshes(); - } - - // Derived samples call this from their constructor - void SetScenes( const GhostScene* scenes, int count ) - { - m_scenes = scenes; - m_sceneCount = count; - LoadScene( 0 ); - } - - virtual void CreateShape( const GhostScene& scene ) = 0; - - virtual int CollideMesh( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, - b3Transform transformBtoA, bool speculative, bool handleGhosts ) = 0; - - // Triangle in the shape frame, before any ghost handling - virtual void CollideTriangle( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, - bool speculative ) = 0; - - virtual void DrawShape( b3WorldTransform transform ) = 0; - - virtual b3AABB ComputeShapeBounds( b3Transform transform ) = 0; - - void DestroyMeshes() - { - for ( MeshView& mesh : m_meshes ) - { - b3DestroyMesh( mesh.data ); - } - m_meshes.clear(); - } - - void LoadScene( int index ) - { - DestroyMeshes(); - - m_sceneIndex = index; - const GhostScene& scene = m_scenes[index]; - - std::vector sources; - scene.build( sources ); - - for ( GhostMesh& source : sources ) - { - b3MeshDef meshDef = {}; - meshDef.vertices = source.vertices.data(); - meshDef.indices = source.indices.data(); - meshDef.vertexCount = (int)source.vertices.size(); - meshDef.triangleCount = (int)source.indices.size() / 3; - meshDef.weldVertices = true; - meshDef.weldTolerance = 0.001f; - meshDef.identifyEdges = true; - - MeshView mesh; - mesh.source = source; - mesh.data = b3CreateMesh( &meshDef, nullptr, 0 ); - ClassifyEdges( mesh ); - - b3AABB bounds = { source.vertices[0], source.vertices[0] }; - for ( b3Vec3 vertex : source.vertices ) - { - bounds.lowerBound = b3Min( bounds.lowerBound, vertex ); - bounds.upperBound = b3Max( bounds.upperBound, vertex ); - } - - b3Vec3 margin = { 0.1f, 0.1f, 0.1f }; - bounds.lowerBound = b3Sub( bounds.lowerBound, margin ); - bounds.upperBound = b3Add( bounds.upperBound, margin ); - - mesh.triangleCenters.assign( meshDef.triangleCount, b3Vec3_zero ); - b3Mesh query = { mesh.data, b3Vec3_one }; - b3QueryMesh( &query, bounds, StoreTriangleCenter, &mesh.triangleCenters ); - m_meshes.push_back( mesh ); - } - - ResetPose(); - m_speculative = scene.speculative; - CreateShape( scene ); - } - - void ResetPose() - { - const GhostScene& scene = m_scenes[m_sceneIndex]; - float toRadians = B3_PI / 180.0f; - b3Quat qx = b3MakeQuatFromAxisAngle( b3Vec3_axisX, scene.angles.x * toRadians ); - b3Quat qy = b3MakeQuatFromAxisAngle( b3Vec3_axisY, scene.angles.y * toRadians ); - b3Quat qz = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, scene.angles.z * toRadians ); - m_transform.q = b3MulQuat( qy, b3MulQuat( qx, qz ) ); - m_transform.p = b3OffsetPos( b3Pos_zero, scene.position ); - } - - // Matches edges by vertex index, so a t-junction or a seam between meshes is a boundary edge, - // as in the mesh builder - static void ClassifyEdges( MeshView& mesh ) - { - const std::vector& v = mesh.source.vertices; - const std::vector& idx = mesh.source.indices; - int triangleCount = (int)idx.size() / 3; - mesh.edgeTypes.assign( 3 * triangleCount, e_boundaryEdge ); - - for ( int i = 0; i < triangleCount; ++i ) - { - const int32_t* t = idx.data() + 3 * i; - b3Vec3 normal = - b3Normalize( b3Cross( b3Sub( v[t[1]], v[t[0]] ), b3Sub( v[t[2]], v[t[0]] ) ) ); - - for ( int k = 0; k < 3; ++k ) - { - int a = t[k]; - int b = t[k < 2 ? k + 1 : 0]; - - for ( int j = 0; j < triangleCount; ++j ) - { - const int32_t* u = idx.data() + 3 * j; - for ( int m = 0; m < 3 && j != i; ++m ) - { - if ( u[m] != b || u[m < 2 ? m + 1 : 0] != a ) - { - continue; - } - - int opposite = u[m > 0 ? m - 1 : 2]; - float distance = b3Dot( normal, b3Sub( v[opposite], v[a] ) ); - float tolerance = 0.001f; - EdgeType type = distance < -tolerance - ? e_convexEdge - : ( distance > tolerance ? e_concaveEdge : e_flatEdge ); - mesh.edgeTypes[3 * i + k] = type; - } - } - } - } - } - - static bool StoreTriangleCenter( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ) - { - std::vector* centers = (std::vector*)context; - if ( triangleIndex < (int)centers->size() ) - { - ( *centers )[triangleIndex] = b3MulSV( 1.0f / 3.0f, b3Add( a, b3Add( b, c ) ) ); - } - return true; - } - - static bool CollectTriangle( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ) - { - GhostManifold* self = (GhostManifold*)context; - if ( self->m_triangleManifoldCount == m_triangleCapacity ) - { - return false; - } - - self->m_queryTriangles[self->m_triangleManifoldCount] = { a, b, c }; - self->m_queryIndices[self->m_triangleManifoldCount] = triangleIndex; - self->m_triangleManifoldCount += 1; - return true; - } - - void Step() override - { - // Mesh frame is the world frame - b3Transform transformBtoA = - b3InvMulWorldTransforms( b3WorldTransform_identity, m_transform ); - - m_manifoldCount = 0; - for ( int i = 0; i < (int)m_meshes.size(); ++i ) - { - b3Mesh mesh = { m_meshes[i].data, b3Vec3_one }; - int count = - CollideMesh( m_manifolds + m_manifoldCount, m_manifoldCapacity - m_manifoldCount, - &mesh, transformBtoA, m_speculative, m_handleGhosts ); - for ( int j = 0; j < count; ++j ) - { - m_manifoldMesh[m_manifoldCount + j] = i; - } - m_manifoldCount += count; - } - - m_triangleManifoldCount = 0; - if ( m_drawTriangleManifolds == false ) - { - return; - } - - b3AABB bounds = ComputeShapeBounds( transformBtoA ); - float margin = B3_SPECULATIVE_DISTANCE; - bounds.lowerBound = b3Sub( bounds.lowerBound, { margin, margin, margin } ); - bounds.upperBound = b3Add( bounds.upperBound, { margin, margin, margin } ); - - b3Transform transformAtoB = - b3InvMulWorldTransforms( m_transform, b3WorldTransform_identity ); - for ( MeshView& drawMesh : m_meshes ) - { - b3Mesh mesh = { drawMesh.data, b3Vec3_one }; - int base = m_triangleManifoldCount; - b3QueryMesh( &mesh, bounds, CollectTriangle, this ); - - for ( int i = base; i < m_triangleManifoldCount; ++i ) - { - TriangleQuery& query = m_queryTriangles[i]; - b3Vec3 triangle[3] = { - b3TransformPoint( transformAtoB, query.a ), - b3TransformPoint( transformAtoB, query.b ), - b3TransformPoint( transformAtoB, query.c ), - }; - - TriangleResult& tm = m_triangleManifolds[i]; - tm.manifold = {}; - tm.manifold.points = tm.points; - CollideTriangle( &tm.manifold, m_trianglePointCapacity, triangle, m_speculative ); - tm.manifold.triangleIndex = m_queryIndices[i]; - } - } - } - - void Render() override - { - const GhostScene& scene = m_scenes[m_sceneIndex]; - DrawTextLine( "%s", scene.name ); - DrawTextLine( "ghost: %s", scene.ghost ); - DrawTextLine( "handling: %s", scene.handling ); - DrawTextLine( "manifolds: %d", m_manifoldCount ); - - DrawGroundGrid( 80 ); - - Vec4 edgeColors[] = { - MakeColor( b3_colorRed ), - MakeColor( b3_colorGray ), - MakeColor( b3_colorOrange ), - MakeColor( b3_colorDodgerBlue ), - }; - - Vec4 faceColors[] = { MakeColor( b3_colorDarkSlateGray ), - MakeColor( b3_colorDarkOliveGreen ) }; - - for ( int i = 0; i < (int)m_meshes.size(); ++i ) - { - const MeshView& mesh = m_meshes[i]; - const std::vector& v = mesh.source.vertices; - const std::vector& idx = mesh.source.indices; - int triangleCount = (int)idx.size() / 3; - - for ( int t = 0; t < triangleCount; ++t ) - { - b3Vec3 a = v[idx[3 * t]], b = v[idx[3 * t + 1]], c = v[idx[3 * t + 2]]; - DrawTriangle( b3WorldTransform_identity, a, b, c, faceColors[i & 1] ); - - b3Vec3 corners[3] = { a, b, c }; - for ( int k = 0; k < 3; ++k ) - { - b3Pos p1 = b3OffsetPos( b3Pos_zero, corners[k] ); - b3Pos p2 = b3OffsetPos( b3Pos_zero, corners[k < 2 ? k + 1 : 0] ); - DrawLine( p1, p2, edgeColors[mesh.edgeTypes[3 * t + k]] ); - } - } - } - - if ( m_drawTriangleIndices ) - { - bool multipleMeshes = m_meshes.size() > 1; - for ( int i = 0; i < (int)m_meshes.size(); ++i ) - { - const std::vector& centers = m_meshes[i].triangleCenters; - for ( int t = 0; t < (int)centers.size(); ++t ) - { - b3Pos center = b3OffsetPos( b3Pos_zero, centers[t] ); - if ( multipleMeshes ) - { - DrawString3D( center, MakeColor( b3_colorLightGray ), "m%d t%d", i, t ); - } - else - { - DrawString3D( center, MakeColor( b3_colorLightGray ), "t%d", t ); - } - } - } - } - - if ( m_drawVertexIndices ) - { - bool multipleMeshes = m_meshes.size() > 1; - for ( int i = 0; i < (int)m_meshes.size(); ++i ) - { - // Welded engine vertices, which differ from the source vertices - const b3MeshData* data = m_meshes[i].data; - const b3Vec3* vertices = b3GetMeshVertices( data ); - for ( int v = 0; v < data->vertexCount; ++v ) - { - b3Pos point = b3OffsetPos( b3Pos_zero, vertices[v] ); - if ( multipleMeshes ) - { - DrawString3D( point, MakeColor( b3_colorAquamarine ), "m%d v%d", i, v ); - } - else - { - DrawString3D( point, MakeColor( b3_colorAquamarine ), "v%d", v ); - } - } - } - } - - DrawShape( m_transform ); - - float length = 0.3f * b3GetLengthUnitsPerMeter(); - for ( int i = 0; i < m_manifoldCount; ++i ) - { - b3Vec3 offset = {0.0f, 0.01f * i, 0.0f}; - const b3Manifold& manifold = m_manifolds[i]; - for ( int j = 0; j < manifold.pointCount; ++j ) - { - const b3ManifoldPoint& mp = manifold.points[j]; - if ( mp.separation > 0.01f * m_cullDistance ) - { - continue; - } - b3Pos point = b3OffsetPos( b3Pos_zero, mp.anchorA ); - point = b3OffsetPos( point, offset ); - Vec4 color = - mp.separation > 0.0f ? MakeColor( b3_colorWhite ) : MakeColor( b3_colorYellow ); - DrawArrow( point, point + length * manifold.normal, color ); - DrawPoint( point, 8.0f, color ); - DrawString3D( point, MakeColor( b3_colorWhite ), " %.1f mm", - 1000.0f * mp.separation ); - } - - DrawTextLine( " mesh %d normal (%.3f %.3f %.3f) points %d", m_manifoldMesh[i], - manifold.normal.x, manifold.normal.y, manifold.normal.z, - manifold.pointCount ); - } - - if ( m_drawTriangleManifolds ) - { - const char* featureNames[] = { "none", "tri face", "hull face", "edge1", "edge2", - "edge3", "vertex1", "vertex2", "vertex3" }; - b3Matrix3 rotation = b3MakeMatrixFromQuat( m_transform.q ); - - for ( int i = 0; i < m_triangleManifoldCount; ++i ) - { - const b3LocalManifold& manifold = m_triangleManifolds[i].manifold; - if ( manifold.pointCount == 0 ) - { - continue; - } - - b3Vec3 normal = b3MulMV( rotation, manifold.normal ); - for ( int j = 0; j < manifold.pointCount; ++j ) - { - b3Pos point = b3TransformWorldPoint( m_transform, manifold.points[j].point ); - DrawArrow( point, point + 0.5f * length * normal, - MakeColor( b3_colorOrange ) ); - } - - b3Pos point = b3TransformWorldPoint( m_transform, manifold.points[0].point ); - DrawString3D( point + 0.5f * length * normal, MakeColor( b3_colorOrange ), - " t%d %s", manifold.triangleIndex, featureNames[manifold.feature] ); - } - } - - DrawAxes( b3WorldTransform_identity, 0.25f ); - } - - bool HasSolverControls() const override - { - return false; - } - - bool HasProfile() const override - { - return false; - } - - bool DrawControls() override - { - const char* names[m_maxScenes]; - int count = b3MinInt( m_sceneCount, m_maxScenes ); - for ( int i = 0; i < count; ++i ) - { - names[i] = m_scenes[i].name; - } - - ImGui::PushItemWidth( 220.0f ); - int index = m_sceneIndex; - if ( ImGui::Combo( "Scene", &index, names, count ) ) - { - LoadScene( index ); - } - ImGui::PopItemWidth(); - - ImGui::Checkbox( "Ghost Handling", &m_handleGhosts ); - ImGui::Checkbox( "Speculative", &m_speculative ); - ImGui::Checkbox( "Triangle Manifolds", &m_drawTriangleManifolds ); - ImGui::Checkbox( "Triangle Indices", &m_drawTriangleIndices ); - ImGui::Checkbox( "Vertex Indices", &m_drawVertexIndices ); - ImGui::SliderFloat( "Cull Distance", &m_cullDistance, 0.0f, 200.0f, "%0.1f cm" ); - if ( ImGui::Button( "Reset Pose" ) ) - { - ResetPose(); - } - - DrawGizmoControls( &m_showGizmo, &m_gizmoLocal ); - - ImGui::TextColored( ImVec4( 1.0f, 0.0f, 0.0f, 1.0f ), "boundary" ); - ImGui::SameLine(); - ImGui::TextColored( ImVec4( 0.5f, 0.5f, 0.5f, 1.0f ), "flat" ); - ImGui::SameLine(); - ImGui::TextColored( ImVec4( 1.0f, 0.65f, 0.0f, 1.0f ), "convex" ); - ImGui::SameLine(); - ImGui::TextColored( ImVec4( 0.12f, 0.56f, 1.0f, 1.0f ), "concave" ); - return true; - } - - void Keyboard( int key, int action, int modifiers ) override - { - if ( key == KEY_G && action == ACTION_PRESS && modifiers == 0 ) - { - m_showGizmo = !m_showGizmo; - } - } - - void DrawSampleWindows() override - { - if ( m_showGizmo ) - { - DrawTransformGizmo( m_camera, &m_transform, m_gizmoLocal ); - } - } - - // The gizmo moves the shape, so keep the picking in Sample off - void MouseDown( b3Vec2 p, int button, int modifiers ) override - { - } - - struct TriangleQuery - { - b3Vec3 a, b, c; - }; - - const GhostScene* m_scenes; - int m_sceneCount; - int m_sceneIndex; - std::vector m_meshes; - - b3WorldTransform m_transform; - bool m_handleGhosts; - float m_cullDistance; - bool m_speculative; - bool m_drawTriangleManifolds; - bool m_drawTriangleIndices; - bool m_drawVertexIndices; - bool m_showGizmo; - bool m_gizmoLocal; - - b3Manifold m_manifolds[m_manifoldCapacity] = {}; - int m_manifoldMesh[m_manifoldCapacity] = {}; - int m_manifoldCount; - - TriangleQuery m_queryTriangles[m_triangleCapacity] = {}; - int m_queryIndices[m_triangleCapacity] = {}; - TriangleResult m_triangleManifolds[m_triangleCapacity] = {}; - int m_triangleManifoldCount; -}; - -// Two triangles sharing the edge x = 0, optionally folded along it -static void BuildGhostFold( std::vector& meshes, float crestHeight, float sideHeight ) -{ - float w = 2.0f, l = 2.0f; - GhostMesh mesh; - mesh.vertices = { { 0.0f, crestHeight, -w }, - { 0.0f, crestHeight, w }, - { -l, sideHeight, 0.0f }, - { l, sideHeight, 0.0f } }; - AddGhostTriangle( mesh, 0, 1, 2 ); - AddGhostTriangle( mesh, 1, 0, 3 ); - meshes.push_back( mesh ); -} - -static void BuildGhostFlat( std::vector& meshes ) -{ - BuildGhostFold( meshes, 0.0f, 0.0f ); -} - -// 15 degree slopes -static void BuildGhostCrest( std::vector& meshes ) -{ - BuildGhostFold( meshes, 2.0f * tanf( 15.0f * B3_PI / 180.0f ), 0.0f ); -} - -static void BuildGhostValley( std::vector& meshes ) -{ - BuildGhostFold( meshes, 0.0f, 2.0f * tanf( 15.0f * B3_PI / 180.0f ) ); -} - -// Rotated so the box corner arrives in the middle of a wedge -static void BuildGhostFan( std::vector& meshes ) -{ - GhostMesh mesh; - mesh.vertices.push_back( b3Vec3_zero ); - for ( int i = 0; i < 6; ++i ) - { - float angle = ( i + 0.5f ) * B3_PI / 3.0f; - mesh.vertices.push_back( { 2.0f * cosf( angle ), 0.0f, 2.0f * sinf( angle ) } ); - } - - for ( int i = 0; i < 6; ++i ) - { - AddGhostTriangle( mesh, 0, 1 + i, 1 + ( i + 1 ) % 6 ); - } - meshes.push_back( mesh ); -} - -// The right side is split at a vertex in the middle of the left triangle edge -static void BuildGhostTJunction( std::vector& meshes ) -{ - GhostMesh mesh; - mesh.vertices = { { 0.0f, 0.0f, -2.0f }, - { 0.0f, 0.0f, 2.0f }, - { -2.0f, 0.0f, 0.0f }, - { 2.0f, 0.0f, 0.0f }, - b3Vec3_zero }; - AddGhostTriangle( mesh, 0, 1, 2 ); - AddGhostTriangle( mesh, 4, 1, 3 ); - AddGhostTriangle( mesh, 0, 4, 3 ); - meshes.push_back( mesh ); -} - -// A 90 degree convex ridge along z, two cells along the ridge -static void BuildGhostRidge( std::vector& meshes ) -{ - GhostMesh mesh; - b3Vec2 profile[3] = { { -1.5f, -1.5f }, { 0.0f, 0.0f }, { 1.5f, -1.5f } }; - b3Vec3 facings[2] = { { -1.0f, 1.0f, 0.0f }, { 1.0f, 1.0f, 0.0f } }; - for ( int k = 0; k < 3; ++k ) - { - for ( int i = 0; i < 3; ++i ) - { - mesh.vertices.push_back( { profile[i].x, profile[i].y, -1.0f + k } ); - } - } - - for ( int k = 0; k < 2; ++k ) - { - for ( int i = 0; i < 2; ++i ) - { - int a = 3 * k + i; - int b = a + 1; - int c = a + 4; - int d = a + 3; - AddGhostTriangle( mesh, a, b, c, facings[i] ); - AddGhostTriangle( mesh, a, c, d, facings[i] ); - } - } - meshes.push_back( mesh ); -} - -// A welded strip with an open boundary along x = 0, like a PEEL slab lying on other ground -static void BuildGhostStrip( std::vector& meshes ) -{ - GhostMesh mesh; - for ( int row = 0; row < 5; ++row ) - { - for ( int column = 0; column < 3; ++column ) - { - mesh.vertices.push_back( { 0.5f * column, 0.0f, -1.0f + 0.5f * row } ); - } - } - - for ( int row = 0; row < 4; ++row ) - { - for ( int column = 0; column < 2; ++column ) - { - int a = 3 * row + column; - int b = a + 1; - int c = a + 4; - int d = a + 3; - if ( ( row + column ) & 1 ) - { - AddGhostTriangle( mesh, a, d, b ); - AddGhostTriangle( mesh, d, c, b ); - } - else - { - AddGhostTriangle( mesh, a, d, c ); - AddGhostTriangle( mesh, c, b, a ); - } - } - } - meshes.push_back( mesh ); -} - -// s&box units are inches. Beam top at y = 0 for x > 0, chamfer dropping 1 inch over 1.5 inch for x -// < 0, 8 inch cells along z with the chamfer quads split like the s&box sample. A side depth in inches -// adds a vertical face below the chamfer, so the chamfer bottom edge is convex instead of a boundary. -static void BuildChamferBeam( std::vector& meshes, float sideDepth ) -{ - float inch = 0.0254f; - bool hasSide = sideDepth > 0.0f; - int rowSize = hasSide ? 4 : 3; - GhostMesh mesh; - for ( int k = 0; k <= 4; ++k ) - { - float z = 4.0f * ( -16.0f + 8.0f * k ) * inch; - mesh.vertices.push_back( { -1.5f * inch, -1.0f * inch, z } ); - mesh.vertices.push_back( { 0.0f, 0.0f, z } ); - mesh.vertices.push_back( { 48.0f * inch, 0.0f, z } ); - if ( hasSide ) - { - mesh.vertices.push_back( { -1.5f * inch, ( -1.0f - sideDepth ) * inch, z } ); - } - } - - for ( int k = 0; k < 4; ++k ) - { - int low0 = rowSize * k, top0 = low0 + 1, far0 = low0 + 2; - int low1 = low0 + rowSize, top1 = top0 + rowSize, far1 = far0 + rowSize; - AddGhostTriangle( mesh, low0, low1, top1 ); - AddGhostTriangle( mesh, low0, top1, top0 ); - AddGhostTriangle( mesh, top0, top1, far1 ); - AddGhostTriangle( mesh, top0, far1, far0 ); - - if ( hasSide ) - { - int side0 = low0 + 3, side1 = low1 + 3; - b3Vec3 facing = { -1.0f, 0.0f, 0.0f }; - AddGhostTriangle( mesh, side0, side1, low1, facing ); - AddGhostTriangle( mesh, side0, low1, low0, facing ); - } - } - meshes.push_back( mesh ); -} - -static void BuildGhostChamfer( std::vector& meshes ) -{ - BuildChamferBeam( meshes, 0.0f ); -} - -static void BuildGhostChamferExtended( std::vector& meshes ) -{ - BuildChamferBeam( meshes, 6.0f ); -} - -// A conveyor side rail running along x, from the Conveyor Circuit sample. The upper half of the inner -// wall facing -z and the 8 cm rail top meet at a convex edge, two cells along x so the vertex at x = 0 -// is interior. Quad diagonals alternate as in the conveyor mesh. -static void BuildGhostRail( std::vector& meshes ) -{ - GhostMesh mesh; - b3Vec2 section[3] = { { 0.0f, 0.175f }, { 0.0f, 0.35f }, { 0.08f, 0.35f } }; - for ( int row = 0; row < 3; ++row ) - { - for ( int column = 0; column < 3; ++column ) - { - mesh.vertices.push_back( { -0.25f + 0.25f * column, section[row].y, section[row].x } ); - } - } - - b3Vec3 facings[2] = { { 0.0f, 0.0f, -1.0f }, b3Vec3_axisY }; - for ( int row = 0; row < 2; ++row ) - { - for ( int column = 0; column < 2; ++column ) - { - int a = 3 * row + column; - int b = a + 1; - int c = a + 4; - int d = a + 3; - if ( ( row + column ) & 1 ) - { - AddGhostTriangle( mesh, a, d, b, facings[row] ); - AddGhostTriangle( mesh, d, c, b, facings[row] ); - } - else - { - AddGhostTriangle( mesh, a, d, c, facings[row] ); - AddGhostTriangle( mesh, c, b, a, facings[row] ); - } - } - } - meshes.push_back( mesh ); -} - -// A 35 degree ridge along x that runs into a wall rising toward x = 1, so the ridge end at the origin -// is a saddle vertex, convex across the ridge and concave along it. The ridge sags 4 mm toward x = -2. -static void BuildGhostSaddleRidge( std::vector& meshes ) -{ - GhostMesh mesh; - float xs[3] = { -2.0f, 0.0f, 1.0f }; - float crests[3] = { -0.004f, 0.0f, 0.3f }; - float sides[3] = { -0.7f, -0.7f, -0.4f }; - for ( int i = 0; i < 3; ++i ) - { - mesh.vertices.push_back( { xs[i], sides[i], -1.0f } ); - mesh.vertices.push_back( { xs[i], crests[i], 0.0f } ); - mesh.vertices.push_back( { xs[i], sides[i], 1.0f } ); - } - - for ( int i = 0; i < 2; ++i ) - { - for ( int k = 0; k < 2; ++k ) - { - int a = 3 * i + k; - int b = a + 1; - int c = a + 3; - int d = a + 4; - AddGhostTriangle( mesh, a, b, c ); - AddGhostTriangle( mesh, c, b, d ); - } - } - meshes.push_back( mesh ); -} - -// The ghost oracle wave, 3 m square with 25 cm cells -static void BuildGhostWave( std::vector& meshes ) -{ - b3MeshData* data = CreateOracleMesh( e_oracleWave ); - const b3Vec3* vertices = b3GetMeshVertices( data ); - const b3MeshTriangle* triangles = b3GetMeshTriangles( data ); - - GhostMesh mesh; - mesh.vertices.assign( vertices, vertices + data->vertexCount ); - for ( int i = 0; i < data->triangleCount; ++i ) - { - mesh.indices.push_back( triangles[i].index1 ); - mesh.indices.push_back( triangles[i].index2 ); - mesh.indices.push_back( triangles[i].index3 ); - } - - b3DestroyMesh( data ); - meshes.push_back( mesh ); -} - -static const float s_inch = 0.0254f; - -static const GhostScene s_hullGhostScenes[] = { - { - "Flat edge, side face", - "box 1 cm deep, leading face 5 mm past the shared edge, the right triangle picks the box " - "side face", - "flat edge, the hull face snaps to the triangle normal", - BuildGhostFlat, - { 0.5f, 0.5f, 0.5f }, - { -0.495f, 0.49f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Flat edge, corner", - "box yawed 45 degrees, a corner 1 mm deep stops 1 mm short of the shared edge, edge pair " - "normal", - "flat edge, snap to the triangle face, which has no points here", - BuildGhostFlat, - { 0.5f, 0.5f, 0.5f }, - { -0.708f, 0.499f, 0.0f }, - { 0.0f, 45.0f, 0.0f }, - true, - }, - { - "Flat vertex", - "the corner stops 3 mm short of the fan center, triangles ahead see the center vertex and " - "the box side faces", - "flat vertex and edges, snap", - BuildGhostFan, - { 0.5f, 0.5f, 0.5f }, - { -0.71f, 0.499f, 0.0f }, - { 0.0f, 45.0f, 0.0f }, - true, - }, - { - "Convex edge", - "box on the right slope tilted 8 degrees, the left triangle crest edge gives a normal past " - "the right slope", - "convex edge, the normal is outside the edge cone so the left triangle skips and the right " - "one owns the contact", - BuildGhostCrest, - { 0.5f, 0.5f, 0.5f }, - { 0.57f, 0.959f, 0.0f }, - { 0.0f, 0.0f, -8.0f }, - true, - }, - { - "Concave edge", - "box on the left slope tilted 20 degrees, its corner in the fold, the right triangle picks " - "the box side face", - "concave edge, snap to the triangle face", - BuildGhostValley, - { 0.5f, 0.5f, 0.5f }, - { -0.3f, 0.64f, 0.0f }, - { 0.0f, 0.0f, -20.0f }, - true, - }, - { - "Concave edge, deep", - "box on the left slope tilted 18 degrees and 2 cm deep, the right triangle picks the box side " - "face 11 mm deep", - "concave edge, snap to the triangle face, which has no points here, so the left triangle owns " - "the contact", - BuildGhostValley, - { 0.5f, 0.5f, 0.5f }, - { -0.314f, 0.61f, 0.0f }, - { 0.0f, 0.0f, -18.0f }, - true, - }, - { - "Ridge, deep", - "box corner jammed on a 90 degree ridge, the apex is 3 cm inside the box, 28 mm into the left " - "slope and 34 mm into the right", - "deep, the right triangle picks an edge pair, a convex skip that snaps when deep, and its face " - "contact is empty. The left triangles snap to their own face, which pushes the box off the apex", - BuildGhostRidge, - { 0.5f, 0.5f, 0.5f }, - { -0.564f, 0.579f, -0.016f }, - { -32.0f, -20.0f, 8.0f }, - true, - }, - { - "T-junction", - "a vertex in the middle of the left triangle edge, the left edge matches neither right edge " - "so all three are boundary edges", - "unsupported, the mesh must be welded. Boundary edges are 90 degree convex edges, so the " - "T-junction vertex admits the box side face normal", - BuildGhostTJunction, - { 0.5f, 0.5f, 0.5f }, - { -0.708f, 0.499f, 0.3f }, - { 0.0f, 45.0f, 0.0f }, - true, - }, - { - "Open boundary", - "box hanging over the open edge of a welded strip, yawed 5 degrees and 1 cm deep, its leading " - "face 5 mm past the row edge at the boundary vertex", - "boundary edge, a 90 degree convex edge. The normal leans over the next row triangle at the " - "boundary vertex, so it snaps to the triangle face", - BuildGhostStrip, - { 0.5f, 0.5f, 0.5f }, - { -0.25f, 0.49f, 0.019f }, - { 0.0f, 5.0f, 0.0f }, - true, - }, - { - "Chamfer", - "none without handling, SAT picks the box bottom for the chamfer triangles, 0.07 inch deep", - "causes the ghost, the deepest point is on a flat chamfer vertex or diagonal next to the " - "convex top edge so the " - "hull face snaps to the 34 degree chamfer normal (ghost plan step 2c)", - BuildGhostChamfer, - { 16.0f * s_inch, 36.0f * s_inch, 16.0f * s_inch }, - { 4.0f * s_inch, 36.0f * s_inch - 0.073f * s_inch, 3.0f * s_inch }, - { 0.0f, 0.0f, 0.0f }, - false, - }, - { - "Chamfer extended", - "the chamfer scene with 6 inches of vertical beam side below the chamfer, 0.07 inch deep", - "the chamfer bottom edge is convex instead of a boundary", - BuildGhostChamferExtended, - { 16.0f * s_inch, 36.0f * s_inch, 16.0f * s_inch }, - { 4.0f * s_inch, 36.0f * s_inch - 0.073f * s_inch, 3.0f * s_inch }, - { 0.0f, 0.0f, 0.0f }, - false, - }, - { - "Rail edge", - "box pitched 60 degrees across the rail, its face cuts the convex rail edge 7 cm past the x = 0 " - "vertex, the real contact is edge on edge and perpendicular to the rail", - "the edge pair is shallower than the hull face and the hull face normal crosses the rail edge, so " - "SAT takes the edge pair. Without that the hull face is admitted at a rail edge vertex and leans 60 " - "degrees along the rail.", - BuildGhostRail, - { 0.4f, 0.2f, 0.4f }, - { 0.1f, 0.77f, -0.15f }, - { -15.0f, 0.0f, 60.0f }, - true, - }, - { - "Saddle ridge", - "box resting flat on a ridge, its footprint covers the saddle where the ridge meets a wall, the " - "saddle is 4 mm deep and the ridge under the box sags to 2 mm", - "the deepest points within linear slop span the ridge edge, which admits the up normal. Taking " - "only the deepest point picks the saddle vertex, whose cone rejects up, and snaps to the 35 degree " - "slope", - BuildGhostSaddleRidge, - { 0.46f, 0.1f, 0.5f }, - { -0.44f, 0.096f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Open boundary, snapped neighbors", - "box rolled 44 degrees over the open edge of the strip, its low edge crosses the boundary 1.6 mm " - "up. Its own triangle gives a face contact and the neighbor triangles pick a box side face", - "the neighbors snap to the strip normal and join the face cluster with points 19 to 21 cm up the " - "box side, so the cluster reduction keeps those over the touching point unless the deepest point " - "is put back", - BuildGhostStrip, - { 0.145f, 0.225f, 0.155f }, - { -0.071f, 0.26f, 0.023f }, - { 5.0f, -23.0f, 44.0f }, - true, - }, - { - "Open boundary, rolled", - "box rolled 40 degrees over the open edge of the strip, its low edge 4 mm from the boundary. The " - "edge axis wins SAT by 0.1 mm but the box bottom face is kept for its points, leaning 12 degrees " - "along the boundary edge", - "the leaning face snaps to the strip normal, whose clip reaches 29 cm up the box face. A boundary " - "edge has no neighbor, so the GJK contact at the edge replaces the snapped clip with one point " - "and the edge normal", - BuildGhostStrip, - { 0.2f, 0.1f, 0.2f }, - { 0.0f, 0.184f, 0.25f }, - { -15.0f, 0.0f, 40.0f }, - true, - }, - { - "Rail end", - "box rolled 30 degrees against the open end of the rail, its corner edge 4 mm from the wall end " - "edge, SAT picks a box face whose normal is not perpendicular to that edge", - "the face normal fails the edge test and snaps to the wall face, whose clip is empty beside the " - "rail. A boundary edge has no neighbor to take the contact, so the GJK normal at the edge " - "replaces it", - BuildGhostRail, - { 0.2f, 0.2f, 0.2f }, - { 0.527f, 0.3f, 0.0f }, - { 0.0f, 0.0f, -30.0f }, - true, - }, - { - "Wave, resting cull", - "box on a wave resting within 1 degree of one triangle 12 mm away, the closest triangles are 7 mm " - "away, tilted about 5 degrees and below the lowest box corner along the resting normal", - "the closest triangles snap to their own faces. The resting cull only drops triangles farther " - "than the resting contact, otherwise these drop and the only contact left is 5 mm too far", - BuildGhostWave, - { 0.35f, 0.17f, 0.15f }, - { 0.532f, 0.198f, -1.175f }, - { -3.0f, 77.0f, -6.0f }, - true, - }, -}; - -class HullGhostManifold : public GhostManifold -{ -public: - explicit HullGhostManifold( SampleContext* context ) - : GhostManifold( context ) - { - m_box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - SetScenes( s_hullGhostScenes, IM_ARRAYSIZE( s_hullGhostScenes ) ); - } - - void CreateShape( const GhostScene& scene ) override - { - m_box = b3MakeBoxHull( scene.extents.x, scene.extents.y, scene.extents.z ); - } - - int CollideMesh( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, - b3Transform transformBtoA, bool speculative, bool handleGhosts ) override - { - return b3CollideMeshAndHull( manifolds, capacity, mesh, &m_box.base, transformBtoA, - speculative, handleGhosts ); - } - - void CollideTriangle( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, - bool speculative ) override - { - b3SATCache cache = {}; - b3CollideTriangleAndHull( manifold, capacity, triangle[0], triangle[1], triangle[2], - &m_box.base, &cache, speculative ); - } - - void DrawShape( b3WorldTransform transform ) override - { - DrawHull( transform, &m_box.base, MakeColor( b3_colorGreen ) ); - } - - b3AABB ComputeShapeBounds( b3Transform transform ) override - { - return b3ComputeHullAABB( &m_box.base, transform ); - } - - static Sample* Create( SampleContext* context ) - { - return new HullGhostManifold( context ); - } - - b3BoxHull m_box; -}; - -static int sampleHullGhostManifold = - RegisterSample( "Manifold", "Hull Ghost Manifold", HullGhostManifold::Create ); - -// A flat floor for x > 0 meeting a 10 degree ramp at the concave edge x = 0 -static void BuildGhostRamp( std::vector& meshes ) -{ - GhostMesh mesh; - mesh.vertices = { { 0.0f, 0.0f, -2.0f }, - { 0.0f, 0.0f, 2.0f }, - { -2.0f, 2.0f * tanf( 10.0f * B3_PI / 180.0f ), 0.0f }, - { 2.0f, 0.0f, 0.0f } }; - AddGhostTriangle( mesh, 0, 1, 2 ); - AddGhostTriangle( mesh, 1, 0, 3 ); - meshes.push_back( mesh ); -} - -// A hub whose six spokes alternate 8 degree ridges and 32 degree gullies, so every fan triangle has a -// concave edge and the mesh flags the hub concave. Every spoke still runs downhill, so the hub is the -// closest point for a body resting on it. -static void BuildGhostSaddle( std::vector& meshes ) -{ - float radius = 1.5f; - float toRadians = B3_PI / 180.0f; - float hubHeight = radius * tanf( 32.0f * toRadians ); - - GhostMesh mesh; - mesh.vertices.push_back( { 0.0f, hubHeight, 0.0f } ); - for ( int i = 0; i < 6; ++i ) - { - float angle = i * B3_PI / 3.0f; - float drop = ( i & 1 ) ? 32.0f : 8.0f; - mesh.vertices.push_back( - { radius * cosf( angle ), hubHeight - radius * tanf( drop * toRadians ), radius * sinf( angle ) } ); - } - - for ( int i = 0; i < 6; ++i ) - { - AddGhostTriangle( mesh, 0, 1 + i, 1 + ( i + 1 ) % 6 ); - } - meshes.push_back( mesh ); -} - -// Sphere radius in the x extent -static const GhostScene s_sphereGhostScenes[] = { - { - "Flat edge", - "sphere 1 mm deep over the left triangle, 5 cm from the shared edge, the right triangle sees the edge " - "and tilts its normal 5.7 degrees", - "flat edge, the normal leans over the left triangle and a sphere off the face cannot snap, so the " - "right triangle drops it", - BuildGhostFlat, - { 0.5f, 0.5f, 0.5f }, - { 0.0f, 0.499f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Flat vertex", - "sphere 1 mm deep, 5 cm from the fan center inside one wedge, the other triangles see the center vertex " - "or a spoke and tilt their normals 5.7 degrees", - "flat vertex and edges, the normal is not the face normal, so they drop it", - BuildGhostFan, - { 0.5f, 0.5f, 0.5f }, - { 0.0f, 0.499f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Convex edge", - "sphere 1 mm deep on the right slope 5 cm below the crest, the left triangle sees the crest edge and " - "gives a normal 5.7 degrees past the right slope", - "convex edge, the normal is outside the edge cone so the left triangle skips and the right one owns " - "the contact", - BuildGhostCrest, - { 0.5f, 0.5f, 0.5f }, - { 0.1774f, 1.005f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Concave edge", - "sphere 1 mm deep on the floor 10 cm from a 10 degree ramp, the ramp triangle sees the crease edge 9 mm " - "away and tilts its normal 11.3 degrees away from the ramp", - "concave edge, the normal is neither face normal so it snaps, and a sphere off the face cannot snap, so " - "the ramp triangle drops it", - BuildGhostRamp, - { 0.5f, 0.5f, 0.5f }, - { 0.1f, 0.499f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, - { - "Saddle vertex", - "none, sphere 1 mm deep on the hub. The spokes alternate 8 degree ridges and 32 degree gullies, so " - "every fan triangle has a concave edge, yet the hub is the closest point", - "the edge tests of every triangle reject the vertical normal across its gully. The normal is in the hub " - "fan cone, so every triangle keeps it", - BuildGhostSaddle, - { 0.5f, 0.5f, 0.5f }, - { 0.0f, 1.4363f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, - true, - }, -}; - -class SphereGhostManifold : public GhostManifold -{ -public: - explicit SphereGhostManifold( SampleContext* context ) - : GhostManifold( context ) - { - m_sphere = { b3Vec3_zero, 0.5f }; - SetScenes( s_sphereGhostScenes, IM_ARRAYSIZE( s_sphereGhostScenes ) ); - } - - void CreateShape( const GhostScene& scene ) override - { - m_sphere = { b3Vec3_zero, scene.extents.x }; - } - - int CollideMesh( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, b3Transform transformBtoA, - bool speculative, bool handleGhosts ) override - { - return b3CollideMeshAndSphere( manifolds, capacity, mesh, &m_sphere, transformBtoA, speculative, - handleGhosts ); - } - - void CollideTriangle( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, bool ) override - { - b3CollideTriangleAndSphere( manifold, capacity, triangle, &m_sphere ); - } - - void DrawShape( b3WorldTransform transform ) override - { - DrawWireSphere( transform, &m_sphere, 32, MakeColor( b3_colorGreen ) ); - } - - b3AABB ComputeShapeBounds( b3Transform transform ) override - { - b3Vec3 center = b3TransformPoint( transform, m_sphere.center ); - b3Vec3 extent = { m_sphere.radius, m_sphere.radius, m_sphere.radius }; - return { b3Sub( center, extent ), b3Add( center, extent ) }; - } - - static Sample* Create( SampleContext* context ) - { - return new SphereGhostManifold( context ); - } - - b3Sphere m_sphere; -}; - -static int sampleSphereGhostManifold = - RegisterSample( "Manifold", "Sphere Ghost Manifold", SphereGhostManifold::Create ); - -/// Separated poses judged against the union of the triangles, see shared/ghost_oracle.h. Pose N of a scene -// is the pose N the MeshGhostOracle unit test runs, so a failure index from the test replays here. -class GhostOracle : public Sample -{ -public: - explicit GhostOracle( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 30.0f, 25.0f, 5.0f, { 0.0f, 0.2f, 0.0f } ); - } - - m_scene = e_oracleFlat; - m_poseIndex = 0; - m_handleGhosts = true; - m_mesh = nullptr; - m_valid = false; - m_scanned = false; - m_searching = false; - m_status[0] = 0; - LoadScene( e_oracleFlat ); - } - - ~GhostOracle() override - { - if ( m_mesh != nullptr ) - { - b3DestroyMesh( m_mesh ); - } - } - - void LoadScene( int scene ) - { - if ( m_mesh != nullptr ) - { - b3DestroyMesh( m_mesh ); - } - - m_scene = scene; - m_mesh = CreateOracleMesh( (OracleScene)scene ); - m_scanned = false; - m_searching = false; - Evaluate(); - } - - void Evaluate() - { - m_valid = EvaluateOraclePose( &m_pose, m_mesh, (OracleScene)m_scene, m_poseIndex ); - } - - const OracleResult& Shown() const - { - return m_handleGhosts ? m_pose.handled : m_pose.raw; - } - - void StartSearch( bool ghost ) - { - m_searching = true; - m_searchGhost = ghost; - m_searchStart = m_poseIndex; - m_searchIndex = m_poseIndex + 1; - } - - // A pose costs up to 21 GJK sweeps of the mesh and most searches find nothing, so the search takes - // a time slice per frame - void UpdateSearch() - { - uint64_t ticks = b3GetTicks(); - int end = m_searchStart + m_searchCount; - while ( m_searchIndex <= end && b3GetMilliseconds( ticks ) < 8.0f ) - { - int index = m_searchIndex; - m_searchIndex += 1; - - if ( EvaluateOraclePose( &m_searchPose, m_mesh, (OracleScene)m_scene, index ) == false ) - { - continue; - } - - const OracleResult& result = m_handleGhosts ? m_searchPose.handled : m_searchPose.raw; - bool found = m_searchGhost ? result.ghostCount > 0 : IsOracleCullingMiss( &m_searchPose ); - if ( found ) - { - m_pose = m_searchPose; - m_poseIndex = index; - m_valid = true; - m_searching = false; - snprintf( m_status, sizeof( m_status ), "found pose %d", index ); - return; - } - } - - if ( m_searchIndex > end ) - { - m_searching = false; - snprintf( m_status, sizeof( m_status ), "none in poses %d to %d", m_searchStart + 1, end ); - } - else - { - snprintf( m_status, sizeof( m_status ), "searching poses %d to %d, at %d", m_searchStart + 1, end, m_searchIndex ); - } - } - - void CancelSearch() - { - m_searching = false; - m_status[0] = 0; - } - - void Step() override - { - if ( m_searching ) - { - UpdateSearch(); - } - } - - bool FocusBounds( b3AABB* bounds ) override - { - if ( m_valid == false ) - { - return false; - } - - *bounds = b3ComputeHullAABB( &m_pose.box.base, m_pose.transform ); - return true; - } - - void Render() override - { - const OracleResult& result = Shown(); - const OracleReference& reference = m_pose.reference; - - DrawTextLine( "%s, pose %d, ghost handling %s", g_oracleSceneNames[m_scene], m_poseIndex, - m_handleGhosts ? "on" : "off" ); - if ( m_valid == false ) - { - DrawTextLine( "no separated pose at this index" ); - } - else - { - DrawTextLine( "distance %.2f mm", 1000.0f * reference.distance ); - DrawTextLine( "ghost manifolds %d", result.ghostCount ); - if ( result.missed ) - { - bool cullingMiss = m_handleGhosts && IsOracleCullingMiss( &m_pose ); - DrawTextLine( "closest pair missed%s", cullingMiss ? ", by ghost handling" : "" ); - } - } - - if ( m_scanned ) - { - DrawTextLine( - "scan of %d poses: %d separated, ghost poses %d unhandled and %d handled, %d misses by handling", - ORACLE_SCAN_POSES, m_scan.validCount, m_scan.rawGhostPoses, m_scan.ghostPoses, m_scan.missedPoses ); - } - - if ( m_status[0] != 0 ) - { - DrawTextLine( "%s", m_status ); - } - - const b3Vec3* vertices = b3GetMeshVertices( m_mesh ); - const b3MeshTriangle* triangles = b3GetMeshTriangles( m_mesh ); - for ( int i = 0; i < m_mesh->triangleCount; ++i ) - { - b3Vec3 a = vertices[triangles[i].index1]; - b3Vec3 b = vertices[triangles[i].index2]; - b3Vec3 c = vertices[triangles[i].index3]; - DrawTriangle( b3WorldTransform_identity, a, b, c, MakeColor( b3_colorDarkSlateGray ) ); - - b3Vec3 corners[3] = { a, b, c }; - for ( int k = 0; k < 3; ++k ) - { - DrawLine( b3OffsetPos( b3Pos_zero, corners[k] ), b3OffsetPos( b3Pos_zero, corners[k < 2 ? k + 1 : 0] ), - MakeColor( b3_colorGray ) ); - } - } - - DrawAxes( b3WorldTransform_identity, 0.25f ); - - if ( m_valid == false ) - { - return; - } - - b3WorldTransform transform = { b3OffsetPos( b3Pos_zero, m_pose.transform.p ), m_pose.transform.q }; - DrawHull( transform, &m_pose.box.base, MakeColor( b3_colorGreen ) ); - - float speculativeDistance = B3_SPECULATIVE_DISTANCE; - for ( int i = 0; i < reference.pairCount; ++i ) - { - const OraclePair& pair = reference.pairs[i]; - if ( pair.distance > speculativeDistance ) - { - continue; - } - - b3Pos meshPoint = b3OffsetPos( b3Pos_zero, pair.meshPoint ); - b3Pos hullPoint = b3OffsetPos( b3Pos_zero, pair.hullPoint ); - if ( pair.owned ) - { - DrawLineEx( meshPoint, hullPoint, MakeColor( m_ownedColor ), 3.0f, OVERLAY_THICKNESS_PIXELS, - OVERLAY_OCCLUSION_DIM ); - DrawPoint( meshPoint, 8.0f, MakeColor( m_ownedColor ) ); - } - else - { - DrawLine( meshPoint, hullPoint, MakeColor( m_dominatedColor ) ); - } - } - - DrawPoint( b3OffsetPos( b3Pos_zero, reference.closestMeshPoint ), 12.0f, MakeColor( b3_colorWhite ) ); - - float length = 0.15f * b3GetLengthUnitsPerMeter(); - for ( int i = 0; i < result.pointCount; ++i ) - { - const OraclePoint& point = result.points[i]; - b3Pos origin = b3OffsetPos( b3Pos_zero, point.meshPoint ); - Vec4 color = MakeColor( m_verdictColors[point.verdict] ); - DrawArrow( origin, b3OffsetPos( origin, b3MulSV( length, point.normal ) ), color ); - DrawPoint( origin, 8.0f, color ); - DrawString3D( origin, color, " t%d %.1f mm", point.triangleIndex, 1000.0f * point.separation ); - } - } - - bool HasSolverControls() const override - { - return false; - } - - bool HasProfile() const override - { - return false; - } - - static void Legend( b3HexColor hexColor, const char* label ) - { - Vec4 color = MakeColor( hexColor ); - ImGui::TextColored( ImVec4( color.x, color.y, color.z, 1.0f ), "%s", label ); - } - - bool DrawControls() override - { - ImGui::PushItemWidth( 160.0f ); - int scene = m_scene; - if ( ImGui::Combo( "Scene", &scene, g_oracleSceneNames, e_oracleSceneCount ) ) - { - m_status[0] = 0; - LoadScene( scene ); - } - - if ( ImGui::InputInt( "Pose", &m_poseIndex ) ) - { - m_poseIndex = b3MaxInt( m_poseIndex, 0 ); - CancelSearch(); - Evaluate(); - } - ImGui::PopItemWidth(); - - // The search judges the shown result, so it does not survive a switch - if ( ImGui::Checkbox( "Ghost Handling", &m_handleGhosts ) ) - { - CancelSearch(); - } - - if ( m_searching ) - { - if ( ImGui::Button( "Cancel Search" ) ) - { - CancelSearch(); - } - } - else - { - if ( ImGui::Button( "Next Ghost" ) ) - { - StartSearch( true ); - } - ImGui::SameLine(); - if ( ImGui::Button( "Next Miss" ) ) - { - StartSearch( false ); - } - } - - if ( ImGui::Button( "Scan" ) ) - { - m_scan = ScanGhostOracle( m_mesh, (OracleScene)m_scene, ORACLE_SCAN_POSES ); - m_scanned = true; - } - ImGui::SameLine(); - if ( ImGui::Button( "Frame" ) ) - { - FrameSelection( m_context ); - } - - Legend( m_ownedColor, "union contact" ); - ImGui::SameLine(); - Legend( m_dominatedColor, "dominated pair" ); - Legend( m_verdictColors[e_oracleFace], "face" ); - ImGui::SameLine(); - Legend( m_verdictColors[e_oracleFeature], "edge or vertex" ); - ImGui::SameLine(); - Legend( m_verdictColors[e_oracleShared], "shared" ); - ImGui::SameLine(); - Legend( m_verdictColors[e_oracleGhost], "ghost" ); - return true; - } - - static Sample* Create( SampleContext* context ) - { - return new GhostOracle( context ); - } - - static constexpr int m_searchCount = 5000; - static constexpr b3HexColor m_ownedColor = b3_colorLimeGreen; - static constexpr b3HexColor m_dominatedColor = b3_colorDimGray; - - // Indexed by OracleVerdict - static constexpr b3HexColor m_verdictColors[4] = { b3_colorDodgerBlue, b3_colorCyan, b3_colorSilver, b3_colorRed }; - - b3MeshData* m_mesh; - int m_scene; - int m_poseIndex; - bool m_handleGhosts; - bool m_valid; - OraclePose m_pose; - - bool m_scanned; - OracleScan m_scan; - - bool m_searching; - bool m_searchGhost; - int m_searchStart; - int m_searchIndex; - OraclePose m_searchPose; - char m_status[128]; -}; - -static int sampleGhostOracle = RegisterSample( "Manifold", "Ghost Oracle", GhostOracle::Create ); +static int sampleHullAndTriangle = RegisterSample( "Manifold", "Triangle vs Hull", TriangleAndHull::Create ); diff --git a/samples/sample_mesh.cpp b/samples/sample_mesh.cpp index 38f5c67..f00f718 100644 --- a/samples/sample_mesh.cpp +++ b/samples/sample_mesh.cpp @@ -10,13 +10,9 @@ #include "box3d/box3d.h" -#include -#include #include #include #include -#include -#include enum class ShapeType { @@ -603,17 +599,12 @@ public: bodyDef.position = { -10.0f, 0.0f, 0.0f }; b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); + b3CreateMeshShape( body, &meshShapeDef, m_buildingMesh, b3Vec3_one ); m_scale = { -1.0f, 1.0f, 1.0f }; bodyDef.position = { 10.0f, 0.0f, 0.0f }; m_meshBodyId = b3CreateBody( m_worldId, &bodyDef ); - - m_meshShapeId = b3_nullShapeId; - if ( m_buildingMesh != nullptr ) - { - b3CreateMeshShape( body, &meshShapeDef, m_buildingMesh, b3Vec3_one ); - m_meshShapeId = b3CreateMeshShape( m_meshBodyId, &meshShapeDef, m_buildingMesh, m_scale ); - } + m_meshShapeId = b3CreateMeshShape( m_meshBodyId, &meshShapeDef, m_buildingMesh, m_scale ); } bodyDef.type = b3_dynamicBody; @@ -661,7 +652,7 @@ public: ~MeshReflection() override { b3DestroyMesh( m_gridMesh ); - DestroyMeshData( m_buildingMesh ); + b3DestroyMesh( m_buildingMesh ); for ( int i = 0; i < e_humanCount; ++i ) { @@ -719,10 +710,7 @@ public: { m_scale = scale; - if ( m_buildingMesh != nullptr ) - { - b3Shape_SetMesh( m_meshShapeId, m_buildingMesh, m_scale ); - } + b3Shape_SetMesh( m_meshShapeId, m_buildingMesh, m_scale ); } return true; @@ -731,7 +719,7 @@ public: void Render() override { DrawTextLine( "scale = (%.2g, %.2g, %.2g)", m_scale.x, m_scale.y, m_scale.z ); - DrawTextLine( "surface type = %d", (int)m_userMaterialId ); + DrawTextLine( "surface type = %d", m_userMaterialId ); Sample::Render(); } @@ -1059,7 +1047,7 @@ public: ~MeshViewer() override { - DestroyMeshData( m_mesh ); + b3DestroyMesh( m_mesh ); } void LoadMesh() @@ -1090,14 +1078,7 @@ public: char buffer[64] = {}; snprintf( buffer, 64, "data/meshes/%s", filesNames[m_meshIndex] ); - if ( LoadTempMesh( buffer, &m_tempMesh, scale, true ) == false ) - { - m_buildTime = 0.0f; - m_area = 0.0f; - m_height = 0; - m_drawLevel = -1; - return; - } + LoadTempMesh( buffer, &m_tempMesh, scale, true ); b3MeshDef def = {}; def.vertices = m_tempMesh.vertices.data(); @@ -1114,14 +1095,6 @@ public: m_mesh = b3CreateMesh( &def, m_degenerateTriangles, m_degenerateCapacity ); m_buildTime = b3GetMilliseconds( startTicks ); - if ( m_mesh == nullptr ) - { - m_area = 0.0f; - m_height = 0; - m_drawLevel = -1; - return; - } - b3ShapeDef shapeDef = b3DefaultShapeDef(); b3CreateMeshShape( m_bodyId, &shapeDef, m_mesh, b3Vec3_one ); @@ -1258,12 +1231,6 @@ public: Sample::Render(); DrawAxes( b3WorldTransform_identity, 1.0f ); - if ( m_mesh == nullptr ) - { - DrawTextLine( "mesh failed to load" ); - return; - } - DrawTextLine( "triangle count = %d", m_mesh->triangleCount ); DrawTextLine( "vertex count = %d", m_mesh->vertexCount ); DrawTextLine( "degenerate count = %d", m_mesh->degenerateCount ); @@ -1380,11 +1347,6 @@ public: def.weldTolerance = 0.0015f; b3MeshData* meshData = b3CreateMesh( &def, nullptr, 0 ); - if ( meshData == nullptr ) - { - continue; - } - triangleCount += i == 0 ? meshData->triangleCount : 0; if ( computeArea && i == 0 ) @@ -1458,11 +1420,8 @@ public: m_meshData = b3CreateMesh( &def, nullptr, 0 ); - if ( m_meshData != nullptr ) - { - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, m_meshData, b3Vec3_one ); - } + b3ShapeDef shapeDef = b3DefaultShapeDef(); + b3CreateMeshShape( groundId, &shapeDef, m_meshData, b3Vec3_one ); } { @@ -1516,7 +1475,7 @@ public: ~VoxelMesh() override { - DestroyMeshData( m_meshData ); + b3DestroyMesh( m_meshData ); } void Step() override @@ -1625,250 +1584,3 @@ public: }; static int sampleHollowBox = RegisterSample( "Mesh", "Hollow Box", HollowBox::Create ); - -// A sphere fitted inside an inward facing sphere mesh. Every triangle is in range and every contact -// normal is different, so the manifolds cannot be merged. From a voxel cavity filled with wedged debris. -// The sphere should stay inside and go to sleep. -class WedgedSphere : public Sample -{ -public: - explicit WedgedSphere( SampleContext* context ) - : Sample( context ) - { - if ( m_context->restart == false ) - { - m_camera->SetView( 45.0f, 20.0f, 4.0f, b3Pos_zero ); - } - - m_mesh = nullptr; - m_groundId = b3_nullBodyId; - m_bodyId = b3_nullBodyId; - m_subdivisions = 3; - m_fit = 5.0f; - - Build(); - } - - ~WedgedSphere() override - { - b3DestroyMesh( m_mesh ); - } - - static void Subdivide( std::vector& vertices, b3Vec3 a, b3Vec3 b, b3Vec3 c, int depth ) - { - if ( depth == 0 ) - { - vertices.push_back( a ); - vertices.push_back( b ); - vertices.push_back( c ); - return; - } - - b3Vec3 ab = b3Normalize( b3Add( a, b ) ); - b3Vec3 bc = b3Normalize( b3Add( b, c ) ); - b3Vec3 ca = b3Normalize( b3Add( c, a ) ); - Subdivide( vertices, a, ab, ca, depth - 1 ); - Subdivide( vertices, ab, b, bc, depth - 1 ); - Subdivide( vertices, ca, bc, c, depth - 1 ); - Subdivide( vertices, ab, bc, ca, depth - 1 ); - } - - void Build() - { - if ( B3_IS_NON_NULL( m_bodyId ) ) - { - b3DestroyBody( m_bodyId ); - b3DestroyBody( m_groundId ); - b3DestroyMesh( m_mesh ); - } - - // Unit icosphere as a triangle soup, welded by the mesh builder - float t = 0.5f * ( 1.0f + sqrtf( 5.0f ) ); - b3Vec3 corners[12] = { - { -1.0f, t, 0.0f }, { 1.0f, t, 0.0f }, { -1.0f, -t, 0.0f }, { 1.0f, -t, 0.0f }, - { 0.0f, -1.0f, t }, { 0.0f, 1.0f, t }, { 0.0f, -1.0f, -t }, { 0.0f, 1.0f, -t }, - { t, 0.0f, -1.0f }, { t, 0.0f, 1.0f }, { -t, 0.0f, -1.0f }, { -t, 0.0f, 1.0f }, - }; - - int faces[20][3] = { - { 0, 11, 5 }, { 0, 5, 1 }, { 0, 1, 7 }, { 0, 7, 10 }, { 0, 10, 11 }, { 1, 5, 9 }, { 5, 11, 4 }, - { 11, 10, 2 }, { 10, 7, 6 }, { 7, 1, 8 }, { 3, 9, 4 }, { 3, 4, 2 }, { 3, 2, 6 }, { 3, 6, 8 }, - { 3, 8, 9 }, { 4, 9, 5 }, { 2, 4, 11 }, { 6, 2, 10 }, { 8, 6, 7 }, { 9, 8, 1 }, - }; - - std::vector vertices; - for ( int i = 0; i < 20; ++i ) - { - Subdivide( vertices, b3Normalize( corners[faces[i][0]] ), b3Normalize( corners[faces[i][1]] ), - b3Normalize( corners[faces[i][2]] ), m_subdivisions ); - } - - m_triangleCount = (int)vertices.size() / 3; - - // The flat faces sit inside the unit sphere. The closest one bounds the largest sphere that fits. - m_inscribedRadius = 1.0f; - std::vector indices( vertices.size() ); - for ( int i = 0; i < m_triangleCount; ++i ) - { - b3Vec3 a = vertices[3 * i + 0]; - b3Vec3 b = vertices[3 * i + 1]; - b3Vec3 c = vertices[3 * i + 2]; - b3Vec3 normal = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) ); - m_inscribedRadius = b3MinFloat( m_inscribedRadius, b3AbsFloat( b3Dot( normal, a ) ) ); - - // Reverse the winding so the triangles face the center - indices[3 * i + 0] = 3 * i + 0; - indices[3 * i + 1] = 3 * i + 2; - indices[3 * i + 2] = 3 * i + 1; - } - - b3MeshDef meshDef = {}; - meshDef.vertices = vertices.data(); - meshDef.indices = indices.data(); - meshDef.vertexCount = (int)vertices.size(); - meshDef.triangleCount = m_triangleCount; - meshDef.weldVertices = true; - meshDef.weldTolerance = 1.0e-4f; - meshDef.identifyEdges = true; - m_mesh = b3CreateMesh( &meshDef, nullptr, 0 ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - m_groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( m_groundId, &shapeDef, m_mesh, b3Vec3_one ); - - bodyDef.type = b3_dynamicBody; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - - m_radius = m_inscribedRadius + 0.001f * m_fit; - b3Sphere sphere = { b3Vec3_zero, m_radius }; - b3CreateSphereShape( m_bodyId, &shapeDef, &sphere ); - - m_buildStep = m_stepCount; - m_sleepStep = -1; - m_maxManifoldCount = 0; - m_maxOffset = 0.0f; - m_maxSpeed = 0.0f; - } - - bool DrawControls() override - { - bool rebuild = false; - - if ( ImGui::RadioButton( "320 triangles", m_subdivisions == 2 ) ) - { - m_subdivisions = 2; - rebuild = true; - } - - if ( ImGui::RadioButton( "1280 triangles", m_subdivisions == 3 ) ) - { - m_subdivisions = 3; - rebuild = true; - } - - if ( ImGui::RadioButton( "5120 triangles", m_subdivisions == 4 ) ) - { - m_subdivisions = 4; - rebuild = true; - } - - // Positive is a sphere larger than the cavity - ImGui::SliderFloat( "Fit (mm)", &m_fit, -20.0f, 20.0f, "%.0f" ); - rebuild = rebuild || ImGui::IsItemDeactivatedAfterEdit(); - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - Build(); - } - - if ( ImGui::Button( "Kick" ) ) - { - b3Body_SetLinearVelocity( m_bodyId, { 6.0f, 7.0f, 3.9f } ); - b3Body_SetAwake( m_bodyId, true ); - m_sleepStep = -1; - } - - return true; - } - - void Step() override - { - Sample::Step(); - - int manifoldCount = 0; - b3ContactData contactData; - if ( b3Body_GetContactData( m_bodyId, &contactData, 1 ) == 1 ) - { - manifoldCount = contactData.manifoldCount; - } - - // Surface speed counts spin - b3Vec3 v = b3Body_GetLinearVelocity( m_bodyId ); - b3Vec3 w = b3Body_GetAngularVelocity( m_bodyId ); - float speed = b3Length( v ) + m_radius * b3Length( w ); - float offset = b3Length( b3SubPos( b3Body_GetPosition( m_bodyId ), b3Pos_zero ) ); - bool awake = b3Body_IsAwake( m_bodyId ); - - m_maxManifoldCount = b3MaxInt( m_maxManifoldCount, manifoldCount ); - m_maxOffset = b3MaxFloat( m_maxOffset, offset ); - m_maxSpeed = b3MaxFloat( m_maxSpeed, speed ); - - if ( awake ) - { - m_sleepStep = -1; - } - else if ( m_sleepStep < 0 ) - { - m_sleepStep = m_stepCount - m_buildStep; - } - - DrawTextLine( "triangles = %d, sphere radius = %.4f m, cavity radius = %.4f m", m_triangleCount, m_radius, - m_inscribedRadius ); - DrawTextLine( "manifolds = %d, max %d", manifoldCount, m_maxManifoldCount ); - DrawTextLine( "speed = %.3f m/s, max %.3f", speed, m_maxSpeed ); - DrawTextLine( "center offset = %.1f mm, max %.1f", 1000.0f * offset, 1000.0f * m_maxOffset ); - - if ( awake ) - { - DrawTextLine( "awake for %d steps", m_stepCount - m_buildStep ); - } - else - { - DrawTextLine( "asleep after %d steps", m_sleepStep ); - } - - // The center cannot leave the cavity unless the sphere tunnels - if ( m_maxOffset > m_inscribedRadius ) - { - DrawTextLine( "FAIL: tunneled" ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new WedgedSphere( context ); - } - - b3MeshData* m_mesh; - b3BodyId m_groundId; - b3BodyId m_bodyId; - int m_subdivisions; - int m_triangleCount; - int m_buildStep; - int m_sleepStep; - int m_maxManifoldCount; - float m_fit; - float m_radius; - float m_inscribedRadius; - float m_maxOffset; - float m_maxSpeed; -}; - -static int sampleWedgedSphere = RegisterSample( "Mesh", "Wedged Sphere", WedgedSphere::Create ); diff --git a/samples/sample_ragdoll.cpp b/samples/sample_ragdoll.cpp index 1e4ce51..6dbaf4e 100644 --- a/samples/sample_ragdoll.cpp +++ b/samples/sample_ragdoll.cpp @@ -1,11 +1,10 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "gfx/draw.h" #include "human.h" #include "imgui.h" #include "sample.h" -#include "utils.h" +#include "gfx/draw.h" #include "box3d/box3d.h" @@ -208,6 +207,15 @@ static int sampleRagdollMesh = RegisterSample( "Ragdoll", "Mesh", RagdollOnMesh: class RagdollPile : public Sample { public: + enum + { +#ifdef NDEBUG + e_count = 20 +#else + e_count = 8 +#endif + }; + explicit RagdollPile( SampleContext* context ) : Sample( context ) { @@ -224,14 +232,9 @@ public: m_groundMesh = b3CreateGridMesh( 20, 20, 1.0f, 1, true ); b3CreateMeshShape( groundId, &shapeDef, m_groundMesh, b3Vec3_one ); - g_randomSeed = 42; - float a = 0.1f * m_count; - b3Vec3 lower = { -a, -a, -a }; - b3Vec3 upper = { a, a, a }; - for ( int i = 0; i < m_count; ++i ) + for ( int i = 0; i < e_count; ++i ) { - b3Vec3 offset = RandomVec3( lower, upper ); - b3Pos position = { offset.x, 2.0f, offset.z }; + b3Pos position = { 0.1f * i, 2.0f + 0.5f * i, -0.1f * i }; float torque = 10.0f; float hertz = 0.5f; float damping = 0.7f; @@ -252,9 +255,8 @@ public: return new RagdollPile( context ); } - static constexpr int m_count = m_isDebug ? 8 : 20; b3MeshData* m_groundMesh; - Human m_humans[m_count] = {}; + Human m_humans[e_count] = {}; }; static int sampleRagdollPile = RegisterSample( "Ragdoll", "Pile", RagdollPile::Create ); diff --git a/samples/sample_replay.cpp b/samples/sample_replay.cpp index 2d3b96f..cc8b3e1 100644 --- a/samples/sample_replay.cpp +++ b/samples/sample_replay.cpp @@ -3,8 +3,6 @@ #include "gfx/debug_adapter.h" #include "gfx/draw.h" -#include "gfx/keycodes.h" -#include "gfx/shadow.h" #include "gfx/text.h" #include "imgui.h" #include "sample.h" @@ -13,7 +11,6 @@ #include #include -#include #include #include #include @@ -94,10 +91,6 @@ static const char* ReplayJointTypeName( b3JointType type ) return "weld"; case b3_wheelJoint: return "wheel"; - case b3_moverJoint: - return "mover"; - case b3_pogoJoint: - return "pogo"; default: return "?"; } @@ -186,7 +179,7 @@ static void FormatQueryLabel( char* out, int cap, const char* name, uint64_t id, { if ( name != nullptr && id != 0 ) { - snprintf( out, cap, "%s (%" PRIu64 ")", name, id ); + snprintf( out, cap, "%s (%llu)", name, (unsigned long long)id ); } else if ( name != nullptr ) { @@ -194,7 +187,7 @@ static void FormatQueryLabel( char* out, int cap, const char* name, uint64_t id, } else if ( id != 0 ) { - snprintf( out, cap, "#%" PRIu64, id ); + snprintf( out, cap, "#%llu", (unsigned long long)id ); } else { @@ -220,7 +213,7 @@ enum SelectionKind // - right info panel (DrawControls): Show Timeline button, view toggles, frame counter, and the // selection detail // - left Outline window (DrawSampleWindows): the recorded scene tree -// - Timeline tab in the metrics drawer (DrawMetricsTab): transport, scrubber, keyframe readout +// - Timeline tab in the diagnostics drawer (DrawMetricsTab): transport, scrubber, keyframe readout class ReplayViewer : public Sample { public: @@ -233,7 +226,6 @@ public: m_speed = 1.0f; m_frameAccumulator = 0.0f; m_loop = false; - m_subStepOnCreate = false; m_selKind = SelNone; m_selBodyOrdinal = -1; m_selSlot = -1; @@ -246,7 +238,6 @@ public: m_hoverQuery = -1; m_revealSelection = false; m_drawAllQueries = false; - m_followSelection = false; m_queryIndexBuilt = false; m_querySearch[0] = '\0'; m_querySearchKind = 0; @@ -305,7 +296,7 @@ public: { if ( m_player != nullptr ) { - b3DestroyPlayer( m_player ); + b3RecPlayer_Destroy( m_player ); m_player = nullptr; } m_replayWorldId = b3_nullWorldId; @@ -341,7 +332,7 @@ public: if ( recording != nullptr ) { m_player = - b3CreatePlayer( b3Recording_GetData( recording ), b3Recording_GetSize( recording ), m_context->workerCount ); + b3RecPlayer_Create( b3Recording_GetData( recording ), b3Recording_GetSize( recording ), m_context->workerCount ); b3DestroyRecording( recording ); } else @@ -399,14 +390,6 @@ public: m_camera->SetRenderTransform( b3GetLengthUnitsPerMeter(), m_context->viewZUp ); float aspect = m_camera->m_height > 0 ? (float)m_camera->m_width / (float)m_camera->m_height : 1.0f; m_camera->Frame( m_info.bounds, aspect, 0.75f ); - - // The bounds include static geometry, and a large ground plate can push the fit past the - // draw distance, which culls the whole scene. Pull in so the middle of the scene still draws. - float maxRadius = 0.75f * m_context->drawDistance; - if ( m_camera->m_radius > maxRadius ) - { - m_camera->SetOrbit( m_camera->m_yaw, m_camera->m_pitch, maxRadius ); - } } } @@ -510,79 +493,31 @@ public: } // Advance one recorded step and keep the world pointer current (stable forward, refreshed cheaply). - // Staged first parks at a frame's pre-integration pose when it spawns bodies, so the creation - // transform is drawn before the solver moves them; the next advance runs the step. - void AdvanceOne( bool staged ) + void AdvanceOne() { - if ( staged ) - { - b3RecPlayer_SubStepFrame( m_player ); - } - else - { - b3RecPlayer_StepFrame( m_player ); - } + b3RecPlayer_StepFrame( m_player ); m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); } - // Jump to a recorded frame. Rewinds through the nearest keyframe, so a backward hop costs the - // re-simulation from there. - void SeekTo( int frame ) - { - b3RecPlayer_SeekFrame( m_player, frame ); - m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); - m_frameAccumulator = 0.0f; - } - - // , steps backward. Forward is the global single step on . so it works in every sample, and the - // step count lands in the context. Shift moves five frames, matching that key. Esc drops the - // selection. - void Keyboard( int key, int action, int mods ) override - { - if ( m_generating ) - { - return; - } - - if ( m_player == nullptr || action != ACTION_PRESS || ( mods & ( MOD_CTRL | MOD_ALT ) ) != 0 ) - { - return; - } - - if ( key == KEY_ESCAPE ) - { - m_selKind = SelNone; - } - else if ( key == KEY_COMMA ) - { - int back = ( mods & MOD_SHIFT ) ? 5 : 1; - SeekTo( b3RecPlayer_GetFrame( m_player ) - back ); - m_context->pause = true; - } - } - void Step() override { - SetDrawOrigin( m_camera->DrawOrigin() ); - // Generation runs inside the imgui frame (DrawLoadPopup). While it fast-forwards, the world is // mid-replay, so hold off drawing it. if ( m_generating ) { m_stepCount = m_player != nullptr ? b3RecPlayer_GetFrame( m_player ) : 0; + SetDrawOrigin( m_camera->DrawOrigin() ); return; } if ( m_player != nullptr ) { - if ( m_context->singleStep > 0 ) + if ( m_context->pause && m_context->singleStep > 0 ) { - // Stepping takes over from playback, like the transport buttons. m_context->singleStep = b3MaxInt( 0, m_context->singleStep - 1 ); - m_context->pause = true; if ( b3RecPlayer_IsAtEnd( m_player ) == false ) { - AdvanceOne( m_subStepOnCreate ); + AdvanceOne(); } m_frameAccumulator = 0.0f; } @@ -606,7 +541,7 @@ public: break; } } - AdvanceOne( false ); + AdvanceOne(); } } @@ -614,46 +549,24 @@ public: m_stepCount = b3RecPlayer_GetFrame( m_player ); } + SetDrawOrigin( m_camera->DrawOrigin() ); + if ( B3_IS_NULL( m_replayWorldId ) ) { DrawScreenStringFormat( 5, m_textLine, MakeColor( b3_colorLightGray ), "%s", m_status ); return; } - // Retarget after the frame advances so the follow reads the pose about to be drawn, and before - // the cull box below is taken, since both it and the draw origin hang off the eye. - if ( UpdateFollowCamera() ) - { - SetDrawOrigin( m_camera->DrawOrigin() ); - } - // Draw the replay world through the same adapter path the live samples use. b3DebugDraw debugDraw; MakeDebugDraw( &debugDraw ); ApplyGuiFlags( &debugDraw ); - const b3AABB drawBox = m_camera->DrawBounds(); // view-distance box in length units around the eye - - // Reach past the view box for casters between it and the sun, see Sample::Draw. - b3Vec3 casterLo, casterHi; - const Mat4 viewInv = m_camera->ViewInverse(); - const Mat4 projInv = m_camera->ProjInverse(); - GetShadowCasterBounds( &viewInv, &projInv, &casterLo, &casterHi ); - const b3AABB casterBox = b3OffsetAABB( { casterLo, casterHi }, m_camera->DrawOrigin() ); - - debugDraw.drawingBounds.lowerBound = b3Min( drawBox.lowerBound, casterBox.lowerBound ); - debugDraw.drawingBounds.upperBound = b3Max( drawBox.upperBound, casterBox.upperBound ); - - SetViewBounds( drawBox ); + debugDraw.drawingBounds = m_camera->DrawBounds(); // view-distance box in length units around the eye // Drive the shared outline highlight from the selection. A shape selection outlines that // shape alone, a body selection outlines the whole body. Set before the draw so the mask - // is filled by the draw callback. Following already centers the selection, so the outline - // would only wrap and obscure the thing being watched. - if ( m_followSelection ) - { - ClearSelection(); - } - else if ( m_selKind == SelShape ) + // is filled by the draw callback. + if ( m_selKind == SelShape ) { SetSelectedShape( SelectedShape() ); } @@ -668,6 +581,8 @@ public: b3World_Draw( m_replayWorldId, &debugDraw, B3_DEFAULT_MASK_BITS ); + DrawSelectionHighlight(); + // Overlay query geometry and recorded hits on top of the world. The toggle draws every recorded // query, otherwise just the selected one. Re-resolve the pinned query to this frame so a repeated // query keeps drawing as the recording steps; it vanishes only on a frame that does not issue it. @@ -699,17 +614,6 @@ public: return false; } - bool HasProfile() const override - { - return false; - } - - // The base world before a recording is open - b3WorldId GetMetricsWorldId() const override - { - return B3_IS_NON_NULL( m_replayWorldId ) ? m_replayWorldId : m_worldId; - } - // Wider than the default so the detail pane, hosted in the info panel, has room for ids and vectors. float InfoPanelWidthEm() const override { @@ -765,58 +669,6 @@ public: FrameRecording(); } - // Where the follow cam should sit this frame. A body, shape or joint selection tracks the body's - // center of mass, the stable point to watch even while a shape spins about it. A query tracks the - // center of its recorded bounds. False when the selection resolves to nothing at this frame, which - // happens before a body spawns or on a frame that does not issue the pinned query. - bool FollowTarget( b3Pos* position ) const - { - if ( m_player == nullptr ) - { - return false; - } - - if ( m_selKind == SelQuery ) - { - int sel = ResolveSelectedQuery(); - if ( sel < 0 ) - { - return false; - } - - b3AABB aabb = b3RecPlayer_GetFrameQuery( m_player, sel ).aabb; - if ( b3IsValidAABB( aabb ) == false ) - { - return false; - } - - *position = b3ToPos( b3AABB_Center( aabb ) ); - return true; - } - - b3BodyId body = SelectedBody(); - if ( m_selKind == SelNone || b3Body_IsValid( body ) == false ) - { - return false; - } - - *position = b3Body_GetWorldCenter( body ); - return true; - } - - // Ride the selection. Returns true when the eye moved, so the caller can relatch the draw origin. - bool UpdateFollowCamera() - { - b3Pos position; - if ( m_followSelection == false || FollowTarget( &position ) == false ) - { - return false; - } - - m_camera->SetTarget( position ); - return true; - } - // Transport row shared by the right panel and the Timeline tab. Play is green, Pause red. void DrawTransport() { @@ -824,12 +676,16 @@ public: if ( ImGui::Button( "|<" ) ) { - SeekTo( 0 ); + b3RecPlayer_SeekFrame( m_player, 0 ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); + m_frameAccumulator = 0.0f; } ImGui::SameLine(); if ( ImGui::Button( "<" ) ) { - SeekTo( frame - 1 ); + b3RecPlayer_SeekFrame( m_player, frame - 1 ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); + m_frameAccumulator = 0.0f; m_context->pause = true; } ImGui::SameLine(); @@ -858,23 +714,17 @@ public: ImGui::SameLine(); if ( ImGui::Button( ">" ) ) { - // Staged forward keeps the creation-pose park reachable and resumes it; a plain seek - // always lands on a whole frame and would skip past the pre-step. - if ( m_subStepOnCreate ) - { - AdvanceOne( true ); - m_frameAccumulator = 0.0f; - } - else - { - SeekTo( frame + 1 ); - } + b3RecPlayer_SeekFrame( m_player, frame + 1 ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); + m_frameAccumulator = 0.0f; m_context->pause = true; } ImGui::SameLine(); if ( ImGui::Button( ">|" ) ) { - SeekTo( m_info.frameCount ); + b3RecPlayer_SeekFrame( m_player, m_info.frameCount ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); + m_frameAccumulator = 0.0f; } } @@ -897,11 +747,6 @@ public: // Overlay every recorded query, not just the one selected in the outline. ImGui::Checkbox( "Draw All Queries", &m_drawAllQueries ); - // Keep the selection centered as the recording plays. Orbit and zoom still aim the view, and the - // cursor is untouched, so picking and the scene tree keep working while it follows. The - // silhouette outline drops while following, since a centered body needs no pointing at. - ImGui::Checkbox( "Follow Selection", &m_followSelection ); - // View-only stand-up for recordings authored with +Z as up. The simulation is untouched. // Reframe on a toggle so the rotated bounds stay centered, matching the fit done on load. if ( ImGui::Checkbox( "Z-up View", &m_context->viewZUp ) ) @@ -914,10 +759,8 @@ public: ImGui::TextColored( PanelColor( b3_colorRed ), "****DIVERGED****" ); } - const char* phaseTag = b3RecPlayer_IsAtEnd( m_player ) ? " (end)" - : b3RecPlayer_IsAtPreStep( m_player ) ? " (pre-step)" - : ""; - ImGui::TextDisabled( "Frame %d / %d%s", b3RecPlayer_GetFrame( m_player ), m_info.frameCount, phaseTag ); + ImGui::TextDisabled( "Frame %d / %d%s", b3RecPlayer_GetFrame( m_player ), m_info.frameCount, + b3RecPlayer_IsAtEnd( m_player ) ? " (end)" : "" ); // Selection detail lives here in the info panel, not the Outline window, so the scene tree gets // the full left column. The child takes the remaining panel height and scrolls a long detail. @@ -1074,7 +917,7 @@ public: int count = b3Body_GetContactData( body, contacts, capacity ); for ( int i = 0; i < count; ++i ) { - b3Pos originA = b3Body_GetWorldCenter( b3Shape_GetBody( contacts[i].shapeIdA ) ); + b3Pos originA = b3Body_GetWorldCenterOfMass( b3Shape_GetBody( contacts[i].shapeIdA ) ); for ( int m = 0; m < contacts[i].manifoldCount; ++m ) { const b3Manifold* manifold = &contacts[i].manifolds[m]; @@ -1088,6 +931,53 @@ public: } } + // Selection overlays drawn on top of the outline highlight: body axes, center of mass, and + // contacts. Joints mark both connected body centers. + void DrawSelectionHighlight() + { + if ( m_selKind == SelShape ) + { + b3ShapeId shape = SelectedShape(); + if ( b3Shape_IsValid( shape ) == false ) + { + return; + } + b3BodyId body = b3Shape_GetBody( shape ); + DrawAxes( b3Body_GetTransform( body ), 0.5f ); + DrawPoint( b3Body_GetWorldCenterOfMass( body ), 8.0f, MakeColor( b3_colorYellow ) ); + DrawBodyContacts( body ); + } + else if ( m_selKind == SelBody ) + { + b3BodyId body = SelectedBody(); + if ( b3Body_IsValid( body ) == false ) + { + return; + } + DrawAxes( b3Body_GetTransform( body ), 0.5f ); + DrawPoint( b3Body_GetWorldCenterOfMass( body ), 8.0f, MakeColor( b3_colorYellow ) ); + DrawBodyContacts( body ); + } + else if ( m_selKind == SelJoint ) + { + b3JointId joint = SelectedJoint(); + if ( b3Joint_IsValid( joint ) == false ) + { + return; + } + b3BodyId a = b3Joint_GetBodyA( joint ); + b3BodyId b = b3Joint_GetBodyB( joint ); + if ( b3Body_IsValid( a ) ) + { + DrawPoint( b3Body_GetWorldCenterOfMass( a ), 8.0f, MakeColor( b3_colorMagenta ) ); + } + if ( b3Body_IsValid( b ) ) + { + DrawPoint( b3Body_GetWorldCenterOfMass( b ), 8.0f, MakeColor( b3_colorMagenta ) ); + } + } + } + // Left-edge Outline window plus the keyframe-policy popup. The selection detail lives in the right // info panel (DrawControls), so the tree owns the whole column. void DrawSampleWindows() override @@ -1104,7 +994,7 @@ public: float menuBarHeight = ImGui::GetFrameHeight(); float top = menuBarHeight + 0.5f * fontSize; - // Stop above the metrics drawer when it is open so the panels do not overlap. The 16 em + // Stop above the diagnostics drawer when it is open so the panels do not overlap. The 16 em // drawer height mirrors DrawMetrics. float bottom = m_context->showMetrics ? ( m_camera->m_height - 16.0f * fontSize - fontSize ) : ( m_camera->m_height - 0.5f * fontSize ); @@ -1230,8 +1120,8 @@ public: char base[64]; FormatQueryLabel( base, sizeof( base ), row.name, row.id, row.type, row.kindOrdinal ); char text[112]; - snprintf( text, sizeof( text ), "f%-5d %s (%d) cat 0x%" PRIx64, row.frame, base, row.hitCount, - row.filter.categoryBits ); + snprintf( text, sizeof( text ), "f%-5d %s (%d) cat 0x%llx", row.frame, base, row.hitCount, + (unsigned long long)row.filter.categoryBits ); if ( ContainsNoCase( text, m_querySearch ) == false ) { continue; @@ -1245,8 +1135,10 @@ public: ImGui::PopStyleColor(); if ( clicked ) { - SeekTo( row.frame ); + b3RecPlayer_SeekFrame( m_player, row.frame ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); m_context->pause = true; + m_frameAccumulator = 0.0f; m_selKind = SelQuery; m_selQueryKey = row.key; FormatQueryLabel( m_selQueryLabel, sizeof( m_selQueryLabel ), row.name, row.id, row.type, row.kindOrdinal ); @@ -1284,8 +1176,8 @@ public: int count = b3RecPlayer_GetBodyCount( m_player ); for ( int ord = 0; ord < count; ++ord ) { - b3BodyId bodyId = b3RecPlayer_GetBodyId( m_player, ord ); - if ( B3_IS_NULL( bodyId ) || b3Body_IsValid( bodyId ) == false ) + b3BodyId body = b3RecPlayer_GetBodyId( m_player, ord ); + if ( B3_IS_NULL( body ) || b3Body_IsValid( body ) == false ) { continue; } @@ -1293,15 +1185,10 @@ public: bool ownsSelection = m_selBodyOrdinal == ord && ( m_selKind == SelBody || m_selKind == SelShape || m_selKind == SelJoint ); - const char* bodyName = b3Body_GetName( bodyId ); - if ( bodyName == nullptr || bodyName[0] == 0 ) - { - b3BodyType bodyType = b3Body_GetType( bodyId ); - bodyName = ReplayBodyTypeName( bodyType ); - } - + const char* name = b3Body_GetName( body ); char label[64]; - snprintf( label, sizeof( label ), "Body %d %s###b%d", ord, bodyName, ord ); + snprintf( label, sizeof( label ), "Body %d %s###b%d", ord, + ( name != nullptr && name[0] != '\0' ) ? name : ReplayBodyTypeName( b3Body_GetType( body ) ), ord ); ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth; if ( m_selKind == SelBody && m_selBodyOrdinal == ord ) @@ -1329,17 +1216,12 @@ public: continue; } - BodyShapes( m_shapeBuffer, bodyId ); + BodyShapes( m_shapeBuffer, body ); for ( int s = 0; s < (int)m_shapeBuffer.size(); ++s ) { - const char* shapeName = b3Shape_GetName( m_shapeBuffer[s] ); - if ( shapeName == nullptr || shapeName[0] == 0 ) - { - b3ShapeType shapeType = b3Shape_GetType( m_shapeBuffer[s] ); - shapeName = ReplayShapeTypeName( shapeType ); - } + b3ShapeType shapeType = b3Shape_GetType( m_shapeBuffer[s] ); char sl[64]; - snprintf( sl, sizeof( sl ), "Shape %d %s###b%ds%d", s, shapeName, ord, s ); + snprintf( sl, sizeof( sl ), "Shape %d %s###b%ds%d", s, ReplayShapeTypeName( shapeType ), ord, s ); ImGuiTreeNodeFlags lf = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_NoTreePushOnOpen; if ( m_selKind == SelShape && m_selBodyOrdinal == ord && m_selSlot == s ) @@ -1360,7 +1242,7 @@ public: } b3JointId joints[16]; - int jn = b3Body_GetJoints( bodyId, joints, 16 ); + int jn = b3Body_GetJoints( body, joints, 16 ); for ( int j = 0; j < jn; ++j ) { char jl[64]; @@ -1536,8 +1418,8 @@ public: ImGui::Text( "id %d", shape.index1 ); ImGui::Text( "type %s", ReplayShapeTypeName( b3Shape_GetType( shape ) ) ); b3Filter f = b3Shape_GetFilter( shape ); - ImGui::Text( "category 0x%016" PRIx64, f.categoryBits ); - ImGui::Text( "mask 0x%016" PRIx64, f.maskBits ); + ImGui::Text( "category 0x%016llx", (unsigned long long)f.categoryBits ); + ImGui::Text( "mask 0x%016llx", (unsigned long long)f.maskBits ); ImGui::Text( "group %d", f.groupIndex ); ImGui::Text( "density %.3g", b3Shape_GetDensity( shape ) ); ImGui::Text( "friction %.3g", b3Shape_GetFriction( shape ) ); @@ -1548,20 +1430,6 @@ public: b3AABB aabb = b3Shape_GetAABB( shape ); ImGui::Text( "aabb (%.2f, %.2f, %.2f)", aabb.lowerBound.x, aabb.lowerBound.y, aabb.lowerBound.z ); ImGui::Text( " (%.2f, %.2f, %.2f)", aabb.upperBound.x, aabb.upperBound.y, aabb.upperBound.z ); - - if ( b3Shape_GetType( shape ) == b3_compoundShape ) - { - const b3CompoundData* compound = b3Shape_GetCompound( shape ); - int childCount = compound->capsuleCount + compound->hullCount + compound->meshCount + compound->sphereCount; - ImGui::Text( "children %d", childCount ); - ImGui::Text( " capsules %d", compound->capsuleCount ); - ImGui::Text( " hulls %d (%d unique)", compound->hullCount, compound->sharedHullCount ); - ImGui::Text( " meshes %d (%d unique)", compound->meshCount, compound->sharedMeshCount ); - ImGui::Text( " spheres %d", compound->sphereCount ); - ImGui::Text( "materials %d", compound->materialCount ); - ImGui::Text( "tree height %d nodes %d", compound->treeHeight, compound->nodeCount ); - ImGui::Text( "bytes %d", compound->byteCount ); - } } void DrawContactDetail( b3BodyId body ) @@ -1658,7 +1526,7 @@ public: } if ( q.id != 0 ) { - ImGui::Text( "id %" PRIu64, q.id ); + ImGui::Text( "id %llu", (unsigned long long)q.id ); } if ( q.key != 0 ) { @@ -1668,8 +1536,8 @@ public: { ImGui::Text( "type %s #%d", ReplayQueryTypeName( q.type ), m_selQueryKindOrdinal ); } - ImGui::Text( "category 0x%016" PRIx64, q.filter.categoryBits ); - ImGui::Text( "mask 0x%016" PRIx64, q.filter.maskBits ); + ImGui::Text( "category 0x%016llx", (unsigned long long)q.filter.categoryBits ); + ImGui::Text( "mask 0x%016llx", (unsigned long long)q.filter.maskBits ); if ( q.type != b3_recQueryOverlapAABB ) { ImGui::Text( "origin (%.2f, %.2f, %.2f)", q.origin.x, q.origin.y, q.origin.z ); @@ -1696,7 +1564,7 @@ public: } } - // Timeline tab in the metrics drawer: file, transport, keyframe readout, scrubber, divergence. + // Timeline tab in the diagnostics drawer: file, transport, keyframe readout, scrubber, divergence. void DrawMetricsTab() override { ImGuiTabItemFlags flags = m_selectTimelineTab ? ImGuiTabItemFlags_SetSelected : 0; @@ -1741,11 +1609,6 @@ public: ImGui::Checkbox( "Loop", &m_loop ); ImGui::SameLine(); - // Single-step parks at a frame's pre-integration pose when it spawns bodies, so a new body - // shows at its creation transform before the solver moves it. Forward single-step only. - ImGui::Checkbox( "Sub-step spawns", &m_subStepOnCreate ); - ImGui::SameLine(); - // Replaying at a different worker count re-partitions the constraint graph, a visual // cross-thread determinism check. The setter applies it without rebuilding the world. ImGui::PushItemWidth( 6.0f * fontSize ); @@ -1763,7 +1626,9 @@ public: ImGui::PushItemWidth( -FLT_MIN ); if ( ImGui::SliderInt( "##frame", &scrub, 0, m_info.frameCount ) ) { - SeekTo( scrub ); + b3RecPlayer_SeekFrame( m_player, scrub ); + m_replayWorldId = b3RecPlayer_GetWorldId( m_player ); + m_frameAccumulator = 0.0f; m_context->pause = true; } ImGui::PopItemWidth(); @@ -1783,12 +1648,7 @@ public: b3Counters c = b3World_GetCounters( m_replayWorldId ); ImGui::Text( "frames %d", m_info.frameCount ); ImGui::SameLine(); - ImGui::Text( " %.0f Hz, %d sub-steps", hz, m_info.subStepCount ); - if ( m_info.lengthScale > 0.0f ) - { - ImGui::SameLine(); - ImGui::Text( " %g units/m", m_info.lengthScale ); - } + ImGui::Text( " %.0f hz, %d sub-steps", hz, m_info.subStepCount ); ImGui::SameLine(); ImGui::Text( " bodies %d shapes %d contacts %d joints %d", c.bodyCount, c.shapeCount, c.contactCount, c.jointCount ); @@ -1838,7 +1698,6 @@ public: float m_speed; float m_frameAccumulator; bool m_loop; - bool m_subStepOnCreate; // single-step parks at a frame's pre-integration pose when it spawns bodies bool m_selectTimelineTab; // one-shot: focus the Timeline tab on the next draw bool m_prevShowMetrics; // restore the drawer state on exit @@ -1861,11 +1720,6 @@ public: bool m_drawAllQueries; // overlay every recorded query, not just the selected one int m_hoverQuery; // outline query row under the cursor, drawn as a transient highlight - // Follow cam. Unlike the third person camera the character samples use, this drives the pivot only. - // The cursor stays free, so picking, the timeline and the scene tree keep working and orbit still - // aims the view. - bool m_followSelection; - // Re-usable buffer for getting all shapes from a body. std::vector m_shapeBuffer; diff --git a/samples/sample_restitution.cpp b/samples/sample_restitution.cpp deleted file mode 100644 index d4be176..0000000 --- a/samples/sample_restitution.cpp +++ /dev/null @@ -1,1219 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "gfx/debug_adapter.h" -#include "gfx/draw.h" -#include "imgui.h" -#include "sample.h" - -#include "box3d/box3d.h" - -#include - -// Restitution is approximate since Box3D uses speculative collision -class VaryingRestitution : public Sample -{ -public: - enum ShapeType - { - e_sphereShape = 0, - e_boxShape - }; - - explicit VaryingRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 25.0f, 85.0f, { 0.0f, 20.0f, 0.0f } ); - } - - AddGroundBox( 50.0f ); - - m_shapeType = e_sphereShape; - - CreateBodies(); - } - - void CreateBodies() - { - for ( int i = 0; i < m_count; ++i ) - { - if ( B3_IS_NON_NULL( m_bodyIds[i] ) ) - { - b3DestroyBody( m_bodyIds[i] ); - m_bodyIds[i] = b3_nullBodyId; - } - } - - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.restitution = 0.0f; - shapeDef.baseMaterial.friction = 0.0f; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - float dr = 1.0f / ( m_count > 1 ? m_count - 1 : 1 ); - float x = -1.0f * ( m_count - 1 ); - float dx = 2.0f; - - for ( int i = 0; i < m_count; ++i ) - { - char buffer[32]; - snprintf( buffer, 32, "%.2f", shapeDef.baseMaterial.restitution ); - bodyDef.name = buffer; - bodyDef.position = { x, 40.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - m_bodyIds[i] = bodyId; - - if ( m_shapeType == e_sphereShape ) - { - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - else - { - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - - shapeDef.baseMaterial.restitution += dr; - x += dx; - } - } - - bool DrawControls() override - { - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - bool changed = false; - const char* shapeTypes[] = { "Sphere", "Box" }; - - int shapeType = int( m_shapeType ); - changed = changed || ImGui::Combo( "Shape", &shapeType, shapeTypes, IM_ARRAYSIZE( shapeTypes ) ); - m_shapeType = ShapeType( shapeType ); - - ImGui::PopItemWidth(); - - changed = changed || ImGui::Button( "Reset" ); - - if ( changed ) - { - CreateBodies(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - float h = 1.0f * m_count; - DrawLine( { -h, 40.5f, 0.0f }, { h, 40.5f, 0.0f }, MakeColor( b3_colorRed ) ); - } - - static Sample* Create( SampleContext* context ) - { - return new VaryingRestitution( context ); - } - - static constexpr int m_count = 40; - - b3BodyId m_bodyIds[m_count] = {}; - ShapeType m_shapeType; -}; - -static int sampleVaryingRestitution = RegisterSample( "Restitution", "Varying", VaryingRestitution::Create ); - -// Tests how a single bouncing box behaves. -class SingleBoxRestitution : public Sample -{ -public: - explicit SingleBoxRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 16.0f, { 0.0f, 3.0f, 0.0f } ); - } - - AddGroundBox( 4.0f ); - - m_height = 5.0f; - m_maxY = 5.0f; - - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.restitution = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.enableHitEvents = true; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, m_height, 0.0f }; - bodyDef.safetyFactor = 0.01f; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( m_bodyId, &shapeDef, &box.base ); - - m_startEnergy = MeasureEnergy( m_worldId, &m_bodyId, 1 ).Total(); - m_peakEnergy = m_startEnergy; - } - - void Step() override - { - Sample::Step(); - - DrawLine( { -4.0f, m_height + 0.5f, 0.0f }, { 4.0f, m_height + 0.5f, 0.0f }, MakeColor( b3_colorRed ) ); - - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - - b3Pos p = b3Body_GetPosition( m_bodyId ); - if ( events.hitCount == 1 ) - { - m_maxY = (float)p.y; - } - else - { - m_maxY = b3MaxFloat( m_maxY, (float)p.y ); - } - - DrawTextLine( "maxY = %.2f", m_maxY ); - - MechanicalEnergy energy = MeasureEnergy( m_worldId, &m_bodyId, 1 ); - float total = energy.Total(); - m_peakEnergy = b3MaxFloat( m_peakEnergy, total ); - - float scale = m_startEnergy != 0.0f ? 100.0f / m_startEnergy : 0.0f; - DrawTextLine( "kinetic = %.3f J linear + %.3f J angular", energy.linear, energy.angular ); - DrawTextLine( "potential = %.3f J", energy.potential ); - DrawTextLine( "total = %.3f J (%.2f%% of start, peak %.2f%%)", total, scale * total, scale * m_peakEnergy ); - } - - static Sample* Create( SampleContext* context ) - { - return new SingleBoxRestitution( context ); - } - - b3BodyId m_bodyId; - float m_maxY; - float m_startEnergy = 0.0f; - float m_peakEnergy = 0.0f; - float m_height; -}; - -static int sampleSingleBoxRestitution = RegisterSample( "Restitution", "Single Box Restitution", SingleBoxRestitution::Create ); - -class SingleSphereRestitution : public Sample -{ -public: - explicit SingleSphereRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 24.0f, { 0.0f, 5.0f, 0.0f } ); - } - - AddGroundBox( 4.0f ); - - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.restitution = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.enableHitEvents = true; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 10.0f, 0.0f }; - bodyDef.safetyFactor = 0.01f; - m_bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateSphereShape( m_bodyId, &shapeDef, &sphere ); - - m_maxY = (float)bodyDef.position.y; - - m_startEnergy = MeasureEnergy( m_worldId, &m_bodyId, 1 ).Total(); - m_peakEnergy = m_startEnergy; - } - - void Step() override - { - Sample::Step(); - - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - - b3Pos p = b3Body_GetPosition( m_bodyId ); - if ( events.hitCount == 1 ) - { - m_maxY = (float)p.y; - } - else - { - m_maxY = b3MaxFloat( m_maxY, (float)p.y ); - } - - DrawLine( { -4.0f, 10.5f, 0.0f }, { 4.0f, 10.5f, 0.0f }, MakeColor( b3_colorRed ) ); - - DrawTextLine( "maxY = %.2f", m_maxY ); - - MechanicalEnergy energy = MeasureEnergy( m_worldId, &m_bodyId, 1 ); - float total = energy.Total(); - m_peakEnergy = b3MaxFloat( m_peakEnergy, total ); - - float scale = m_startEnergy != 0.0f ? 100.0f / m_startEnergy : 0.0f; - DrawTextLine( "kinetic = %.3f J linear + %.3f J angular", energy.linear, energy.angular ); - DrawTextLine( "potential = %.3f J", energy.potential ); - DrawTextLine( "total = %.3f J (%.2f%% of start, peak %.2f%%)", total, scale * total, scale * m_peakEnergy ); - } - - static Sample* Create( SampleContext* context ) - { - return new SingleSphereRestitution( context ); - } - - b3BodyId m_bodyId; - float m_maxY; - float m_startEnergy = 0.0f; - float m_peakEnergy = 0.0f; -}; - -static int sampleSingleSphereRestitution = - RegisterSample( "Restitution", "Single Sphere Restitution", SingleSphereRestitution::Create ); - -// Similar to the MeasureSupportedBounce unit test -class SphereStackRestitution : public Sample -{ -public: - static constexpr float m_impactSpeed = 5.0f; - static constexpr int m_maxStackCount = 3; - - explicit SphereStackRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 12.0f, { 0.0f, 2.5f, 0.0f } ); - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - b3BoxHull box = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3ShapeId groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); - SetGroundShape( groundShapeId ); - - CreateScene(); - } - - b3BodyId CreateBall( float y, float velocityY, float restitution, bool hitEvents ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, y, 0.0f }; - bodyDef.linearVelocity = { 0.0f, velocityY, 0.0f }; - bodyDef.enableSleep = false; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = restitution; - shapeDef.enableHitEvents = hitEvents; - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - return bodyId; - } - - void CreateScene() - { - for ( int i = 0; i < m_bodyCount; ++i ) - { - b3DestroyBody( m_bodyIds[i] ); - } - m_bodyCount = 0; - - if ( m_gravity ) - { - b3World_SetGravity( m_worldId, { 0.0f, -10.0f, 0.0f } ); - } - else - { - b3World_SetGravity( m_worldId, b3Vec3_zero ); - } - - for ( int i = 0; i < m_stackCount; ++i ) - { - m_bodyIds[m_bodyCount] = CreateBall( 0.5f + 1.0f * i, 0.0f, 0.0f, false ); - m_bodyCount += 1; - } - - // Start half a step of travel above contact so the impact lands mid step, matching the test - m_startHeight = 0.5f + 1.0f * m_stackCount + 0.5f * m_impactSpeed * ( 1.0f / 60.0f ); - - m_impactorId = CreateBall( m_startHeight, -m_impactSpeed, m_restitution, true ); - m_bodyIds[m_bodyCount] = m_impactorId; - m_bodyCount += 1; - - m_startEnergy = MeasureEnergy( m_worldId, m_bodyIds, m_bodyCount ).Total(); - m_peakEnergy = m_startEnergy; - - m_coefficient = 0.0f; - m_latched = false; - m_hit = false; - } - - bool DrawControls() override - { - bool rebuild = false; - - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - if ( ImGui::SliderFloat( "Restitution", &m_restitution, 0.0f, 1.0f, "%.2f" ) ) - { - rebuild = true; - } - - if ( ImGui::SliderInt( "Stack", &m_stackCount, 0, m_maxStackCount ) ) - { - rebuild = true; - } - - ImGui::PopItemWidth(); - - if ( ImGui::Checkbox( "Gravity", &m_gravity ) ) - { - rebuild = true; - } - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - if ( events.hitCount > 0 ) - { - m_hit = true; - } - - float vy = b3Body_GetLinearVelocity( m_impactorId ).y; - - // The rebound only means something once the impact has happened and the impactor is leaving - if ( m_latched == false && m_hit && vy > 0.0f ) - { - m_coefficient = vy / m_impactSpeed; - m_latched = true; - } - - float supportSpeed = 0.0f; - for ( int i = 0; i < m_stackCount; ++i ) - { - supportSpeed = b3MaxFloat( supportSpeed, b3Length( b3Body_GetLinearVelocity( m_bodyIds[i] ) ) ); - } - - DrawLine( { -2.0f, m_startHeight, 0.0f }, { 2.0f, m_startHeight, 0.0f }, MakeColor( b3_colorRed ) ); - - MechanicalEnergy energy = MeasureEnergy( m_worldId, m_bodyIds, m_bodyCount ); - float total = energy.Total(); - m_peakEnergy = b3MaxFloat( m_peakEnergy, total ); - - DrawTextLine( "impactor vy = %.3f m/s", vy ); - - DrawTextLine( "coefficient = %.4f live (target %.2f)", vy / m_impactSpeed, m_restitution ); - - if ( m_latched ) - { - DrawTextLine( "coefficient = %.4f at first rebound", m_coefficient ); - } - - DrawTextLine( "support speed = %.4f m/s", supportSpeed ); - - float scale = m_startEnergy != 0.0f ? 100.0f / m_startEnergy : 0.0f; - DrawTextLine( "kinetic = %.3f J linear + %.3f J angular", energy.linear, energy.angular ); - DrawTextLine( "potential = %.3f J", energy.potential ); - DrawTextLine( "total = %.3f J (%.2f%% of start, peak %.2f%%)", total, scale * total, scale * m_peakEnergy ); - } - - static Sample* Create( SampleContext* context ) - { - return new SphereStackRestitution( context ); - } - - b3BodyId m_bodyIds[m_maxStackCount + 1] = {}; - b3BodyId m_impactorId = b3_nullBodyId; - int m_bodyCount = 0; - int m_stackCount = 2; - float m_restitution = 1.0f; - float m_startHeight = 0.0f; - float m_coefficient = 0.0f; - float m_startEnergy = 0.0f; - float m_peakEnergy = 0.0f; - bool m_gravity = false; - bool m_latched = false; - bool m_hit = false; -}; - -static int sampleSphereStackRestitution = RegisterSample( "Restitution", "Sphere Stack Restitution", SphereStackRestitution::Create ); - -class RestitutionPropagation : public Sample -{ -public: - static constexpr int m_columnCount = 3; - static constexpr float m_dropHeight = 5.0f; - - explicit RestitutionPropagation( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 10.0f, 24.0f, { 0.0f, 4.0f, 0.0f } ); - } - - AddGroundBox( 40.0f ); - - CreateScene(); - } - - void CreateScene() - { - for ( int i = 0; i < m_bodyCount; ++i ) - { - b3DestroyBody( m_bodyIds[i] ); - } - m_bodyCount = 0; - m_crateCount = 0; - m_kick = 0.0f; - - b3BoxHull box = b3MakeCubeHull( 0.5f ); - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - - for ( int column = 0; column < m_columnCount; ++column ) - { - float x = 4.0f * ( column - 1 ); - - for ( int k = 0; k < column; ++k ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { x, 0.5f + 1.0f * k, 0.0f }; - bodyDef.enableSleep = false; - b3BodyId crateId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( crateId, &shapeDef, &box.base ); - - m_bodyIds[m_bodyCount++] = crateId; - m_crateIds[m_crateCount++] = crateId; - } - - m_restHeight[column] = 0.5f + 1.0f * column; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { x, m_restHeight[column] + m_dropHeight, 0.0f }; - bodyDef.enableSleep = false; - b3BodyId ballId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.restitution = m_restitution; - b3CreateSphereShape( ballId, &shapeDef, &sphere ); - - m_bodyIds[m_bodyCount++] = ballId; - m_ballIds[column] = ballId; - m_apex[column] = 0.0f; - m_rebounding[column] = false; - m_done[column] = false; - } - } - - bool DrawControls() override - { - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - bool rebuild = ImGui::SliderFloat( "Restitution", &m_restitution, 0.0f, 1.0f, "%.2f" ); - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - static const char* labels[m_columnCount] = { "ground", "one crate", "two crates" }; - - for ( int column = 0; column < m_columnCount; ++column ) - { - b3Vec3 v = b3Body_GetLinearVelocity( m_ballIds[column] ); - float height = float( b3Body_GetPosition( m_ballIds[column] ).y ) - m_restHeight[column]; - - // The ball starts at rest and falls, so upward velocity means it bounced - if ( m_rebounding[column] == false && v.y > 0.0f ) - { - m_rebounding[column] = true; - } - - if ( m_rebounding[column] && m_done[column] == false ) - { - m_apex[column] = b3MaxFloat( m_apex[column], height ); - if ( v.y < 0.0f ) - { - m_done[column] = true; - } - } - - float x = 4.0f * ( column - 1 ); - float dropY = m_restHeight[column] + m_dropHeight; - DrawLine( { x - 1.0f, dropY, 0.0f }, { x + 1.0f, dropY, 0.0f }, MakeColor( b3_colorRed ) ); - if ( m_apex[column] > 0.0f ) - { - float apexY = m_restHeight[column] + m_apex[column]; - DrawLine( { x - 1.0f, apexY, 0.0f }, { x + 1.0f, apexY, 0.0f }, MakeColor( b3_colorGreen ) ); - } - - DrawTextLine( "%s: apex %.2f m (%.0f%% of drop)", labels[column], m_apex[column], - 100.0f * m_apex[column] / m_dropHeight ); - } - - for ( int i = 0; i < m_crateCount; ++i ) - { - m_kick = b3MaxFloat( m_kick, b3Length( b3Body_GetLinearVelocity( m_crateIds[i] ) ) ); - } - - DrawTextLine( "peak crate speed %.2f m/s", m_kick ); - } - - static Sample* Create( SampleContext* context ) - { - return new RestitutionPropagation( context ); - } - - b3BodyId m_bodyIds[2 * m_columnCount] = {}; - b3BodyId m_ballIds[m_columnCount] = {}; - b3BodyId m_crateIds[m_columnCount] = {}; - float m_restHeight[m_columnCount] = {}; - float m_apex[m_columnCount] = {}; - bool m_rebounding[m_columnCount] = {}; - bool m_done[m_columnCount] = {}; - int m_bodyCount = 0; - int m_crateCount = 0; - float m_restitution = 0.9f; - float m_kick = 0.0f; -}; - -static int sampleRestitutionPropagation = RegisterSample( "Restitution", "Restitution Propagation", RestitutionPropagation::Create ); - -// Similar to the MeasureFlatBounce and SpinTest unit tests -class BoxRestitution : public Sample -{ -public: - static constexpr float m_impactSpeed = 5.0f; - - explicit BoxRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 14.0f, { 0.0f, 3.0f, 0.0f } ); - } - - // Gravity would bias the measured coefficient - b3World_SetGravity( m_worldId, b3Vec3_zero ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - b3BoxHull box = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3ShapeId groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); - SetGroundShape( groundShapeId ); - - CreateScene(); - } - - void CreateScene() - { - if ( B3_IS_NON_NULL( m_boxId ) ) - { - b3DestroyBody( m_boxId ); - } - - // Start half a step of travel above contact so the impact lands mid step, matching the test - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 0.25f + 0.5f * m_impactSpeed * ( 1.0f / 60.0f ), 0.0f }; - bodyDef.linearVelocity = { 0.0f, -m_impactSpeed, 0.0f }; - bodyDef.angularVelocity = { 0.0f, 0.0f, m_spin }; - bodyDef.enableSleep = false; - m_boxId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = m_restitution; - shapeDef.enableHitEvents = true; - b3BoxHull box = b3MakeBoxHull( 1.0f, 0.25f, 1.0f ); - b3CreateHullShape( m_boxId, &shapeDef, &box.base ); - - m_startEnergy = MeasureEnergy( m_worldId, &m_boxId, 1 ).Total(); - m_peakEnergy = m_startEnergy; - - m_coefficient = 0.0f; - m_latched = false; - m_hit = false; - } - - bool DrawControls() override - { - bool rebuild = false; - - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - if ( ImGui::SliderFloat( "Restitution", &m_restitution, 0.0f, 1.0f, "%.2f" ) ) - { - rebuild = true; - } - - if ( ImGui::SliderFloat( "Spin", &m_spin, 0.0f, 2.0f, "%.2f" ) ) - { - rebuild = true; - } - - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - if ( events.hitCount > 0 ) - { - m_hit = true; - } - - float vy = b3Body_GetLinearVelocity( m_boxId ).y; - b3Vec3 w = b3Body_GetAngularVelocity( m_boxId ); - - if ( m_latched == false && m_hit && vy > 0.0f ) - { - m_coefficient = vy / m_impactSpeed; - m_latched = true; - } - - Vec4 yellow = MakeColor( b3_colorYellow ); - DrawPoint( b3Body_GetWorldPoint( m_boxId, { -1.0f, -0.25f, -1.0f } ), 8.0f, yellow ); - DrawPoint( b3Body_GetWorldPoint( m_boxId, { 1.0f, -0.25f, -1.0f } ), 8.0f, yellow ); - DrawPoint( b3Body_GetWorldPoint( m_boxId, { -1.0f, -0.25f, 1.0f } ), 8.0f, yellow ); - DrawPoint( b3Body_GetWorldPoint( m_boxId, { 1.0f, -0.25f, 1.0f } ), 8.0f, yellow ); - - MechanicalEnergy energy = MeasureEnergy( m_worldId, &m_boxId, 1 ); - float total = energy.Total(); - m_peakEnergy = b3MaxFloat( m_peakEnergy, total ); - - DrawTextLine( "vy = %.3f m/s", vy ); - - DrawTextLine( "coefficient = %.4f live (target %.2f)", vy / m_impactSpeed, m_restitution ); - - if ( m_latched ) - { - DrawTextLine( "coefficient = %.4f at first rebound", m_coefficient ); - } - - // The spin is about z, so any x or y component is residual from the sequential point solve - DrawTextLine( "spin in = %.2f, spin out = %.4f (ideal %.2f at e = 1)", m_spin, w.z, -m_spin ); - DrawTextLine( "off axis spin = %.4f rad/s", sqrtf( w.x * w.x + w.y * w.y ) ); - - float scale = m_startEnergy != 0.0f ? 100.0f / m_startEnergy : 0.0f; - DrawTextLine( "kinetic = %.3f J linear + %.3f J angular", energy.linear, energy.angular ); - DrawTextLine( "potential = %.3f J", energy.potential ); - DrawTextLine( "total = %.3f J (%.2f%% of start, peak %.2f%%)", total, scale * total, scale * m_peakEnergy ); - } - - static Sample* Create( SampleContext* context ) - { - return new BoxRestitution( context ); - } - - b3BodyId m_boxId = b3_nullBodyId; - float m_restitution = 0.9f; - float m_spin = 0.0f; - float m_coefficient = 0.0f; - float m_startEnergy = 0.0f; - float m_peakEnergy = 0.0f; - bool m_latched = false; - bool m_hit = false; -}; - -static int sampleBoxRestitution = RegisterSample( "Restitution", "Box Restitution", BoxRestitution::Create ); - -class RotatedBoxRestitution : public Sample -{ -public: - static constexpr int m_count = 12; - static constexpr float m_dropHeight = 10.0f; - - explicit RotatedBoxRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 15.0f, 36.0f, { 0.0f, 5.0f, 0.0f } ); - } - - AddGroundBox( 2.0f * m_count + 1.0f ); - - CreateScene(); - } - - void CreateScene() - { - for ( int i = 0; i < m_count; ++i ) - { - if ( B3_IS_NON_NULL( m_bodyIds[i] ) ) - { - b3DestroyBody( m_bodyIds[i] ); - m_bodyIds[i] = b3_nullBodyId; - } - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.safetyFactor = m_safetyFactor; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = m_friction; - shapeDef.baseMaterial.restitution = m_restitution; - - // Boxes in a negative group never collide with each other - shapeDef.filter.groupIndex = -1; - - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - // A cube repeats every quarter turn - float dq = 0.5f * B3_PI / m_count; - float x = -1.0f * ( m_count - 1 ); - - for ( int i = 0; i < m_count; ++i ) - { - bodyDef.position = { x, m_dropHeight, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, i * dq ); - m_bodyIds[i] = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( m_bodyIds[i], &shapeDef, &box.base ); - - m_startEnergy[i] = MeasureEnergy( m_worldId, &m_bodyIds[i], 1 ).Total(); - - x += 2.0f; - } - } - - bool DrawControls() override - { - bool rebuild = false; - - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - if ( ImGui::SliderFloat( "Restitution", &m_restitution, 0.0f, 1.0f, "%.1f" ) ) - { - rebuild = true; - } - - if ( ImGui::SliderFloat( "Friction", &m_friction, 0.0f, 1.0f, "%.1f" ) ) - { - rebuild = true; - } - - if ( ImGui::SliderFloat( "Safety Factor", &m_safetyFactor, 0.01f, 0.5f, "%.2f" ) ) - { - rebuild = true; - } - - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - float h = 1.0f * m_count; - DrawLine( { -h, m_dropHeight + 0.5f, 0.0f }, { h, m_dropHeight + 0.5f, 0.0f }, MakeColor( b3_colorRed ) ); - - float minPercent = 0.0f; - float maxPercent = 0.0f; - float x = -1.0f * ( m_count - 1 ); - Vec4 white = MakeColor( b3_colorWhite ); - - for ( int i = 0; i < m_count; ++i ) - { - float total = MeasureEnergy( m_worldId, &m_bodyIds[i], 1 ).Total(); - - float percent = m_startEnergy[i] != 0.0f ? 100.0f * total / m_startEnergy[i] : 0.0f; - minPercent = i == 0 ? percent : b3MinFloat( minPercent, percent ); - maxPercent = i == 0 ? percent : b3MaxFloat( maxPercent, percent ); - - DrawString3D( { x - 0.5f, m_dropHeight + 1.5f, 0.0f }, white, "%.1f%%", percent ); - x += 2.0f; - } - - DrawTextLine( "energy: min %.2f%%, max %.2f%% of start", minPercent, maxPercent ); - } - - static Sample* Create( SampleContext* context ) - { - return new RotatedBoxRestitution( context ); - } - - b3BodyId m_bodyIds[m_count] = {}; - float m_startEnergy[m_count] = {}; - float m_restitution = 0.9f; - float m_friction = 0.0f; - float m_safetyFactor = 0.5f; -}; - -static int sampleRotatedBoxRestitution = RegisterSample( "Restitution", "Rotated Box Restitution", RotatedBoxRestitution::Create ); - -// Based on https://github.com/erincatto/box2d/discussions/957 -class TwoBoxRestitution : public Sample -{ -public: - explicit TwoBoxRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 14.0f, { 0.0f, 3.0f, 0.0f } ); - } - - AddGroundBox( 10.0f ); - - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.restitution = 0.9f; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - bodyDef.position.y = 0.5f; - m_bodyIds[0] = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( m_bodyIds[0], &shapeDef, &box.base ); - - bodyDef.position.x += 0.1f; - bodyDef.position.y = 6.0f; - m_bodyIds[1] = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( m_bodyIds[1], &shapeDef, &box.base ); - - m_startEnergy = MeasureEnergy( m_worldId, m_bodyIds, 2 ).Total(); - m_peakEnergy = m_startEnergy; - } - - void Step() override - { - Sample::Step(); - - MechanicalEnergy energy = MeasureEnergy( m_worldId, m_bodyIds, 2 ); - float total = energy.Total(); - m_peakEnergy = b3MaxFloat( m_peakEnergy, total ); - - float scale = m_startEnergy != 0.0f ? 100.0f / m_startEnergy : 0.0f; - DrawTextLine( "kinetic = %.3f J linear + %.3f J angular", energy.linear, energy.angular ); - DrawTextLine( "potential = %.3f J", energy.potential ); - DrawTextLine( "total = %.3f J (%.2f%% of start, peak %.2f%%)", total, scale * total, scale * m_peakEnergy ); - } - - static Sample* Create( SampleContext* context ) - { - return new TwoBoxRestitution( context ); - } - - b3BodyId m_bodyIds[2] = {}; - float m_startEnergy = 0.0f; - float m_peakEnergy = 0.0f; -}; - -static int sampleTwoBoxRestitution = RegisterSample( "Restitution", "Two Box Restitution", TwoBoxRestitution::Create ); - -class SphereRestitution : public Sample -{ -public: - explicit SphereRestitution( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 15.0f, 30.0f, { 0.0f, 3.0f, 0.0f } ); - } - - AddGroundBox( 2.0f * m_count ); - - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.restitution = 0.0f; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - float dr = 1.0f / ( m_count > 1 ? m_count - 1 : 1 ); - float x = -1.0f * ( m_count - 1 ); - float dx = 2.0f; - - for ( int i = 0; i < m_count; ++i ) - { - char buffer[32]; - snprintf( buffer, 32, "%.2f", shapeDef.baseMaterial.restitution ); - bodyDef.name = buffer; - - bodyDef.position = { x, 1.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - bodyDef.position = { x, 4.0f, 0.0f }; - bodyId = b3CreateBody( m_worldId, &bodyDef ); - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - shapeDef.baseMaterial.restitution += dr; - x += dx; - } - } - - static Sample* Create( SampleContext* context ) - { - return new SphereRestitution( context ); - } - - static constexpr int m_count = 10; -}; - -static int sampleSphereRestitution = RegisterSample( "Restitution", "Sphere Restitution", SphereRestitution::Create ); - -// Similar to the ImpulseTest unit test. The hit event marks the bounce and carries the approach speed, -// so the impulse the contact reports can be checked against reversing that speed at the coefficient. -// The total runs a little over because the contact also carries the weight for the part of the step -// it is active. -class BounceImpulse : public Sample -{ -public: - explicit BounceImpulse( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 20.0f, 10.0f, 36.0f, { 0.0f, 8.0f, 0.0f } ); - } - - b3World_SetGravity( m_worldId, { 0.0f, -10.0f, 0.0f } ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = { 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - b3BoxHull box = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3ShapeId groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); - SetGroundShape( groundShapeId ); - - CreateScene(); - } - - void CreateScene() - { - if ( B3_IS_NON_NULL( m_ballId ) ) - { - b3DestroyBody( m_ballId ); - } - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = { 0.0f, 0.5f + m_dropHeight, 0.0f }; - bodyDef.enableSleep = false; - m_ballId = b3CreateBody( m_worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = m_restitution; - shapeDef.enableHitEvents = true; - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - b3CreateSphereShape( m_ballId, &shapeDef, &sphere ); - - m_mass = b3Body_GetMass( m_ballId ); - - m_approachSpeed = 0.0f; - m_totalImpulse = 0.0f; - m_expectedImpulse = 0.0f; - m_contactSteps = 0; - m_hit = false; - m_bouncing = false; - } - - bool DrawControls() override - { - bool rebuild = false; - - ImGui::PushItemWidth( 6.0f * ImGui::GetFontSize() ); - - if ( ImGui::SliderFloat( "Restitution", &m_restitution, 0.0f, 1.0f, "%.2f" ) ) - { - rebuild = true; - } - - if ( ImGui::SliderFloat( "Height", &m_dropHeight, 0.5f, 50.0f, "%.1f" ) ) - { - rebuild = true; - } - - ImGui::PopItemWidth(); - - if ( ImGui::Button( "Reset" ) ) - { - rebuild = true; - } - - if ( rebuild ) - { - CreateScene(); - } - - return true; - } - - void Step() override - { - Sample::Step(); - - if ( m_didStep ) - { - b3ContactEvents events = b3World_GetContactEvents( m_worldId ); - if ( m_hit == false && events.hitCount > 0 ) - { - m_hit = true; - m_bouncing = true; - m_approachSpeed = events.hitEvents[0].approachSpeed; - m_expectedImpulse = ( 1.0f + m_restitution ) * m_mass * m_approachSpeed; - } - - // Keep summing until the contact lets go, a slow bounce can take a few steps to leave - if ( m_bouncing ) - { - b3ContactData contactData[4]; - int contactCount = b3Body_GetContactData( m_ballId, contactData, 4 ); - for ( int c = 0; c < contactCount; ++c ) - { - for ( int m = 0; m < contactData[c].manifoldCount; ++m ) - { - const b3Manifold* manifold = contactData[c].manifolds + m; - for ( int p = 0; p < manifold->pointCount; ++p ) - { - m_totalImpulse += manifold->points[p].totalNormalImpulse; - } - } - } - - if ( contactCount > 0 ) - { - m_contactSteps += 1; - } - else - { - m_bouncing = false; - } - } - } - - float startHeight = 0.5f + m_dropHeight; - DrawLine( { -2.0f, startHeight, 0.0f }, { 2.0f, startHeight, 0.0f }, MakeColor( b3_colorRed ) ); - - DrawTextLine( "vy = %.3f m/s", b3Body_GetLinearVelocity( m_ballId ).y ); - - if ( m_hit ) - { - DrawTextLine( "approach speed = %.3f m/s", m_approachSpeed ); - DrawTextLine( "total impulse = %.2f N s over %d steps", m_totalImpulse, m_contactSteps ); - DrawTextLine( "expected impulse = %.2f N s", m_expectedImpulse ); - } - else - { - DrawTextLine( "waiting for the hit" ); - } - } - - static Sample* Create( SampleContext* context ) - { - return new BounceImpulse( context ); - } - - b3BodyId m_ballId = b3_nullBodyId; - float m_restitution = 0.5f; - float m_dropHeight = 20.0f; - float m_mass = 0.0f; - float m_approachSpeed = 0.0f; - float m_totalImpulse = 0.0f; - float m_expectedImpulse = 0.0f; - int m_contactSteps = 0; - bool m_hit = false; - bool m_bouncing = false; -}; - -static int sampleBounceImpulse = RegisterSample( "Restitution", "Bounce Impulse", BounceImpulse::Create ); diff --git a/samples/sample_shapes.cpp b/samples/sample_shapes.cpp index 6bcd458..564c9d9 100644 --- a/samples/sample_shapes.cpp +++ b/samples/sample_shapes.cpp @@ -1,7 +1,6 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "gfx/debug_adapter.h" #include "gfx/draw.h" #include "human.h" #include "imgui.h" @@ -37,7 +36,7 @@ public: bodyDef.type = b3_dynamicBody; for ( int index = 0; index < m_boxCount; ++index ) { - bodyDef.position = { -10.0f + 5.0f * index, 14.25f, -10.6f }; + bodyDef.position = { -10.0f + 5.0f * index, 15.75f, -10.6f }; b3BodyId boxBody = b3CreateBody( m_worldId, &bodyDef ); shapeDef.baseMaterial.friction = ( index + 1 ) * ( index + 1 ) * 0.04f; b3CreateHullShape( boxBody, &shapeDef, &box.base ); @@ -65,7 +64,7 @@ public: m_camera->SetView( -140.0f, 17.0f, 60.0f, { 0.0f, 7.5f, 0.0f } ); } - AddGroundBox( 80.0f ); + AddGroundBox( 50.0f ); b3BodyDef bodyDef = b3DefaultBodyDef(); b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -239,6 +238,104 @@ public: static int sampleSlideTwist = RegisterSample( "Shapes", "Slide Twist", SlideTwist::Create ); +class Restitution : public Sample +{ +public: + enum ShapeType + { + e_sphereShape = 0, + e_boxShape + }; + + explicit Restitution( SampleContext* context ) + : Sample( context ) + { + if ( context->restart == false ) + { + m_camera->SetView( 0.0f, 25.0f, 85.0f, { 0.0f, 20.0f, 0.0f } ); + } + + AddGroundBox( 50.0f ); + + m_shapeType = e_sphereShape; + + CreateBodies(); + } + + void CreateBodies() + { + for ( int i = 0; i < m_count; ++i ) + { + if ( B3_IS_NON_NULL( m_bodyIds[i] ) ) + { + b3DestroyBody( m_bodyIds[i] ); + m_bodyIds[i] = b3_nullBodyId; + } + } + + b3Sphere sphere = { b3Vec3_zero, 0.5f }; + b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); + + b3ShapeDef shapeDef = b3DefaultShapeDef(); + + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; + + float dr = 1.0f / ( m_count > 1 ? m_count - 1 : 1 ); + float x = -1.0f * ( m_count - 1 ); + float dx = 2.0f; + + for ( int i = 0; i < m_count; ++i ) + { + bodyDef.position = { x, 40.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( m_worldId, &bodyDef ); + + m_bodyIds[i] = bodyId; + + if ( m_shapeType == e_sphereShape ) + { + b3CreateSphereShape( bodyId, &shapeDef, &sphere ); + } + else + { + b3CreateHullShape( bodyId, &shapeDef, &box.base ); + } + + shapeDef.baseMaterial.restitution += dr; + x += dx; + } + } + + bool DrawControls() override + { + if ( ImGui::RadioButton( "Sphere", m_shapeType == e_sphereShape ) ) + { + m_shapeType = e_sphereShape; + CreateBodies(); + } + + if ( ImGui::RadioButton( "Box", m_shapeType == e_boxShape ) ) + { + m_shapeType = e_boxShape; + CreateBodies(); + } + + return true; + } + + static Sample* Create( SampleContext* context ) + { + return new Restitution( context ); + } + + static constexpr int m_count = 40; + + b3BodyId m_bodyIds[m_count] = {}; + ShapeType m_shapeType; +}; + +static int sampleRestitution = RegisterSample( "Shapes", "Restitution", Restitution::Create ); + // This shows an optimization when creating many static shapes you can skip having them invoke collision, assuming // dynamic bodies are added after the static bodies. class StaticInvoke : public Sample @@ -402,10 +499,9 @@ public: AddGroundBox( 20.0f ); // Mesh - m_meshData = CreateMeshData( "data/meshes/conveyor.obj", 1.0f, false, true, true, true ); - - if ( m_meshData != nullptr ) { + m_meshData = CreateMeshData( "data/meshes/conveyor.obj", 1.0f, false, true, true, true ); + int triangleCount = m_meshData->triangleCount; uint8_t* materialIndices = (uint8_t*)( (intptr_t)m_meshData + m_meshData->materialOffset ); @@ -524,7 +620,7 @@ public: ~ConveyorMesh() override { - DestroyMeshData( m_meshData ); + b3DestroyMesh( m_meshData ); b3DestroyHull( m_cylinderHull ); } @@ -532,11 +628,6 @@ public: { Sample::Render(); - if ( m_meshData == nullptr ) - { - return; - } - int triangleCount = m_meshData->triangleCount; const b3MeshTriangle* triangles = b3GetMeshTriangles( m_meshData ); const b3Vec3* vertices = b3GetMeshVertices( m_meshData ); diff --git a/samples/sample_stacking.cpp b/samples/sample_stacking.cpp index 4730110..d803e46 100644 --- a/samples/sample_stacking.cpp +++ b/samples/sample_stacking.cpp @@ -6,10 +6,87 @@ #include "imgui.h" #include "mesh_loader.h" #include "sample.h" +#include "gfx/draw.h" #include "box3d/box3d.h" -#include +class CardHouseThick : public Sample +{ +public: + explicit CardHouseThick( SampleContext* context ) + : Sample( context ) + { + if ( context->restart == false ) + { + m_camera->SetView( 0.0f, 25.0f, 10.0f, { 0.0f, 2.0f, 0.0f } ); + } + + AddGroundBox( 10.0f ); + + const float alpha = 25.0f * B3_DEG_TO_RAD; + const float width = 0.38f; + const float height = 0.98f; + const float depth = 0.08f; + + float offsetX = 0.5f * height * b3Sin( alpha ) + 0.045f; + float offsetY = 0.5f * height * b3Cos( alpha ) + 0.035f; + + b3BoxHull box = b3MakeBoxHull( 0.5f * depth, 0.5f * height, 0.5f * width ); + AddVerticalRow( 4, -6.0f * offsetX, offsetX, offsetY, alpha, box ); + AddHorizontalRow( 3, -4.0f * offsetX, 4.0f * offsetX, 2.0f * offsetY + 0.04f, box ); + AddVerticalRow( 3, -4.0f * offsetX, offsetX, 3.0f * offsetY + 0.08f, alpha, box ); + AddHorizontalRow( 2, -2.0f * offsetX, 4.0f * offsetX, 4.0f * offsetY + 0.12f, box ); + AddVerticalRow( 2, -2.0f * offsetX, offsetX, 5.0f * offsetY + 0.16f, alpha, box ); + AddHorizontalRow( 1, -0.0f * offsetX, 4.0f * offsetX, 6.0f * offsetY + 0.20f, box ); + AddVerticalRow( 1, -0.0f * offsetX, offsetX, 7.0f * offsetY + 0.24f, alpha, box ); + } + + void AddVerticalRow( int n, float startX, float offsetX, float startY, float alpha, const b3BoxHull& box ) + { + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.baseMaterial.friction = 0.8f; + + for ( int index = 0; index < n; ++index ) + { + bodyDef.position = { startX - offsetX, startY, 0.0f }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, -alpha ); + b3BodyId body1 = b3CreateBody( m_worldId, &bodyDef ); + b3CreateHullShape( body1, &shapeDef, &box.base ); + + bodyDef.position = { startX + offsetX, startY, 0.0f }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, alpha ); + b3BodyId body2 = b3CreateBody( m_worldId, &bodyDef ); + b3CreateHullShape( body2, &shapeDef, &box.base ); + + startX += 4.0f * offsetX; + } + } + + void AddHorizontalRow( int n, float startX, float offsetX, float startY, const b3BoxHull& box ) + { + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.baseMaterial.friction = 0.8f; + + for ( int index = 0; index < n; ++index ) + { + bodyDef.position = { startX + index * offsetX, startY, 0.0f }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ); + b3BodyId body = b3CreateBody( m_worldId, &bodyDef ); + b3CreateHullShape( body, &shapeDef, &box.base ); + } + } + + static Sample* Create( SampleContext* context ) + { + return new CardHouseThick( context ); + } +}; + +static int sampleCardHouseThick = RegisterSample( "Stacking", "Card House Thick", CardHouseThick::Create ); // From PEEL class CardHouse : public Sample @@ -26,7 +103,6 @@ public: AddGroundBox( 10.0f ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = 0.05f; shapeDef.baseMaterial.friction = 0.7f; float cardHeight = 0.2f; @@ -210,7 +286,7 @@ public: bodyDef.name = "cube"; bodyDef.type = b3_dynamicBody; bodyDef.position = { 0.0f, 0.5f, 0.0f }; - // bodyDef.angularVelocity = { 0.0f, 10.0f, 0.0f }; + bodyDef.angularVelocity = { 0.0f, 10.0f, 0.0f }; m_bodyId = b3CreateBody( m_worldId, &bodyDef ); b3ShapeDef shapeDef = b3DefaultShapeDef(); @@ -353,7 +429,7 @@ public: { if ( context->restart == false ) { - m_camera->SetView( 40.0f, 15.0f, 50.0f, { 0.0f, 20.0f, 0.0f } ); + m_camera->SetView( 0.0f, 15.0f, 50.0f, { 0.0f, 20.0f, 0.0f } ); } AddGroundBox( 40.0f ); @@ -364,6 +440,7 @@ public: bodyDef.type = b3_dynamicBody; b3BoxHull cube = b3MakeBoxHull( a, a, a ); + // b3Quat q = b3MakeQuatFromAxisAngle( { 1.0f, 0.0f, 0.0f }, 0.5f * B3_PI ); for ( int i = 0; i < 40; ++i ) { @@ -374,9 +451,7 @@ public: b3ShapeDef shapeDef = b3DefaultShapeDef(); shapeDef.baseMaterial.rollingResistance = 0.1f; - char buffer[16]; - snprintf( buffer, sizeof( buffer ), "box_%.3d", i ); - shapeDef.name = buffer; + b3CreateHullShape( bodyId, &shapeDef, &cube.base ); } @@ -409,7 +484,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 35.0f, 15.0f, 12.0f, { 0.0f, 2.0f, 0.0f } ); + m_camera->SetView( 35.0f, 15.0f, 30.0f, { 0.0f, 10.0f, 0.0f } ); } m_shapeType = b3_hullShape; @@ -418,43 +493,42 @@ public: void CreateStack() { - AddGroundBox( 20.0f ); + AddGroundBox( 60.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = m_shapeType == b3_capsuleShape ? 0.1f : 0.05f; - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - float h = 1.0f; - float r = 0.1f; - - b3BoxHull box = b3MakeBoxHull( h, r, r ); - b3Capsule capsule = { { -h, 0.0f, 0.0f }, { h, 0.0f, 0.0f }, r }; - int count = 30; - for ( int i = 0; i < count; ++i ) { - float alpha = ( i & 1 ) == 1 ? 0.0f : 0.5f * B3_PI; + b3ShapeDef shapeDef = b3DefaultShapeDef(); + shapeDef.baseMaterial.rollingResistance = m_shapeType == b3_capsuleShape ? 0.1f : 0.01f; + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.type = b3_dynamicBody; - float x = ( i & 1 ) == 0 ? h - 2.0f * r : 0.0f; - float z = ( i & 1 ) == 0 ? 0.0f : h - 2.0f * r; + b3BoxHull box = b3MakeBoxHull( 2.5f, 0.25f, 0.25f ); + b3Capsule capsule = { { -2.5f, 0.0f, 0.0f }, { 2.5f, 0.0f, 0.0f }, 0.25f }; - bodyDef.position = { x, ( 2.1f * i + 0.5f ) * r, z }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha ); - b3BodyId boxBody1 = b3CreateBody( m_worldId, &bodyDef ); - - bodyDef.position = { -x, ( 2.1f * i + 0.5f ) * r, -z }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha ); - b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef ); - - if ( m_shapeType == b3_capsuleShape ) + for ( int i = 0; i < m_size; ++i ) { - b3CreateCapsuleShape( boxBody1, &shapeDef, &capsule ); - b3CreateCapsuleShape( boxBody2, &shapeDef, &capsule ); - } - else - { - b3CreateHullShape( boxBody1, &shapeDef, &box.base ); - b3CreateHullShape( boxBody2, &shapeDef, &box.base ); + float alpha = ( i & 1 ) == 1 ? 0.0f : 0.5f * B3_PI; + + float x = ( i & 1 ) == 0 ? 1.75f : 0.0f; + float z = ( i & 1 ) == 0 ? 0.0f : 1.75f; + + bodyDef.position = { x, 0.5f * i + 0.25f, z }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha ); + b3BodyId boxBody1 = b3CreateBody( m_worldId, &bodyDef ); + + bodyDef.position = { -x, 0.5f * i + 0.25f, -z }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisY, alpha ); + b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef ); + + if ( m_shapeType == b3_capsuleShape ) + { + b3CreateCapsuleShape( boxBody1, &shapeDef, &capsule ); + b3CreateCapsuleShape( boxBody2, &shapeDef, &capsule ); + } + else + { + b3CreateHullShape( boxBody1, &shapeDef, &box.base ); + b3CreateHullShape( boxBody2, &shapeDef, &box.base ); + } } } } @@ -485,6 +559,7 @@ public: return new JengaStack( context ); } + static constexpr int m_size = 40; b3ShapeType m_shapeType; }; @@ -498,7 +573,7 @@ public: { if ( m_context->restart == false ) { - if ( m_isDebug ) + if (m_isDebug) { m_camera->SetView( 0.0f, 15.0f, 25.0f, b3Pos_zero ); } @@ -811,7 +886,7 @@ public: { if ( m_context->restart == false ) { - m_camera->SetView( 40.0f, 15.0f, 50.0f, { 0.0f, 12.0f, 0.0f } ); + m_camera->SetView( 0.0f, 30.0f, 50.0f, { 0.0f, 5.0f, 0.0f } ); } AddGroundBox( 40.0f ); @@ -847,93 +922,3 @@ public: }; static int samplePyramid2D = RegisterSample( "Stacking", "Pyramid2D", Pyramid2D::Create ); - -// This stresses the edge-edge handling. -class EdgeCrossing : public Sample -{ -public: - explicit EdgeCrossing( SampleContext* context ) - : Sample( context ) - { - if ( context->restart == false ) - { - m_camera->SetView( 0.0f, 25.0f, 10.0f, b3Pos_zero ); - } - - AddGroundBox( 40.0f ); - - b3Vec3 h = { 0.2f, 0.02f, 0.04f }; - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - bodyDef.position.x = -10.0f; - bodyDef.position.z = -2.0f; - - b3BoxHull box1 = b3MakeBoxHull( h.x, h.y, h.z ); - b3BoxHull box2 = b3MakeBoxHull( h.x, h.z, h.y ); - - b3Vec3 axis = b3Normalize( { 0.1f, 0.9f, 0.0f } ); - for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI ) - { - bodyDef.position.y = h.y; - bodyDef.rotation = b3Quat_identity; - b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId1, &shapeDef, &box1.base ); - - bodyDef.position.y = 20.0f * h.y; - bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle ); - b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef ); - - b3CreateHullShape( boxBody2, &shapeDef, &box1.base ); - - bodyDef.position.x += 1.0f; - } - - bodyDef.position.x = -10.0f; - bodyDef.position.z = 0.0f; - - for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI ) - { - bodyDef.position.y = h.z; - bodyDef.rotation = b3Quat_identity; - b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId1, &shapeDef, &box2.base ); - - bodyDef.position.y = 20.0f * h.z; - bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle ); - b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef ); - - b3CreateHullShape( boxBody2, &shapeDef, &box2.base ); - - bodyDef.position.x += 1.0f; - } - - bodyDef.position.x = -10.0f; - bodyDef.position.z = 2.0f; - - for ( float angle = -B3_PI; angle < B3_PI + 0.001f; angle += 0.1f * B3_PI ) - { - bodyDef.position.y = h.y; - bodyDef.rotation = b3Quat_identity; - b3BodyId bodyId1 = b3CreateBody( m_worldId, &bodyDef ); - b3CreateHullShape( bodyId1, &shapeDef, &box1.base ); - - bodyDef.position.y = 20.0f * h.y; - bodyDef.rotation = b3MakeQuatFromAxisAngle( axis, angle ); - b3BodyId boxBody2 = b3CreateBody( m_worldId, &bodyDef ); - - b3CreateHullShape( boxBody2, &shapeDef, &box2.base ); - - bodyDef.position.x += 1.0f; - } - } - - static Sample* Create( SampleContext* context ) - { - return new EdgeCrossing( context ); - } -}; - -static int sampleEdgeCrossing = RegisterSample( "Stacking", "Edge Crossing", EdgeCrossing::Create ); diff --git a/samples/sample_tree.cpp b/samples/sample_tree.cpp index f8ad5d6..1816a10 100644 --- a/samples/sample_tree.cpp +++ b/samples/sample_tree.cpp @@ -5,15 +5,13 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include "gfx/draw.h" #include "imgui.h" -#include "sample.h" #include "utils.h" +#include "sample.h" +#include "gfx/draw.h" #include "box3d/box3d.h" -#include "dynamic_tree.h" - #include #include #include @@ -44,6 +42,106 @@ struct Ray b3Vec3 origin, translation; }; +#ifdef _WIN32 + +#include + +// Warning: this code has not been validated +void ClosestPointAVX2( const float* aabbMinX, const float* aabbMinY, const float* aabbMinZ, const float* aabbMaxX, + const float* aabbMaxY, const float* aabbMaxZ, int proxyCount, b3Vec3 point, b3Vec3* outClosestPoint, + float* outMinDistSq ) +{ + const __m256 px = _mm256_set1_ps( point.x ); + const __m256 py = _mm256_set1_ps( point.y ); + const __m256 pz = _mm256_set1_ps( point.z ); + + __m256 bestDistSq = _mm256_set1_ps( FLT_MAX ); + __m256i bestIndex = _mm256_set1_epi32( -1 ); + + int j = 0; + for ( ; j + 8 <= proxyCount; j += 8 ) + { + // Load AABB bounds for 8 proxies + __m256 minX = _mm256_loadu_ps( aabbMinX + j ); + __m256 minY = _mm256_loadu_ps( aabbMinY + j ); + __m256 minZ = _mm256_loadu_ps( aabbMinZ + j ); + __m256 maxX = _mm256_loadu_ps( aabbMaxX + j ); + __m256 maxY = _mm256_loadu_ps( aabbMaxY + j ); + __m256 maxZ = _mm256_loadu_ps( aabbMaxZ + j ); + + // Closest point on AABB to point: clamp each coordinate + __m256 cx = _mm256_min_ps( _mm256_max_ps( px, minX ), maxX ); + __m256 cy = _mm256_min_ps( _mm256_max_ps( py, minY ), maxY ); + __m256 cz = _mm256_min_ps( _mm256_max_ps( pz, minZ ), maxZ ); + + // d = point - closest + __m256 dx = _mm256_sub_ps( px, cx ); + __m256 dy = _mm256_sub_ps( py, cy ); + __m256 dz = _mm256_sub_ps( pz, cz ); + + __m256 dx2 = _mm256_mul_ps( dx, dx ); + __m256 dy2 = _mm256_mul_ps( dy, dy ); + __m256 dz2 = _mm256_mul_ps( dz, dz ); + __m256 distSq = _mm256_add_ps( _mm256_add_ps( dx2, dy2 ), dz2 ); + + // Compare to current best + __m256 mask = _mm256_cmp_ps( distSq, bestDistSq, _CMP_LT_OQ ); + bestDistSq = _mm256_blendv_ps( bestDistSq, distSq, mask ); + + __m256i indices = _mm256_set_epi32( j + 7, j + 6, j + 5, j + 4, j + 3, j + 2, j + 1, j + 0 ); + + // Tracks the 8 best indices + bestIndex = + _mm256_castps_si256( _mm256_blendv_ps( _mm256_castsi256_ps( bestIndex ), _mm256_castsi256_ps( indices ), mask ) ); + } + + // Now find the best index among the best 8. + alignas( 32 ) float distBuf[8]; + alignas( 32 ) int indexBuf[8]; + + _mm256_store_ps( distBuf, bestDistSq ); + _mm256_store_si256( (__m256i*)indexBuf, bestIndex ); + + float minDist = distBuf[0]; + int minIdx = indexBuf[0]; + for ( int k = 1; k < 8; ++k ) + { + if ( distBuf[k] < minDist ) + { + minDist = distBuf[k]; + minIdx = indexBuf[k]; + } + } + + // Remainder + for ( ; j < proxyCount; ++j ) + { + float cx = b3MinFloat( b3MaxFloat( point.x, aabbMinX[j] ), aabbMaxX[j] ); + float cy = b3MinFloat( b3MaxFloat( point.y, aabbMinY[j] ), aabbMaxY[j] ); + float cz = b3MinFloat( b3MaxFloat( point.z, aabbMinZ[j] ), aabbMaxZ[j] ); + + float dx = point.x - cx; + float dy = point.y - cy; + float dz = point.z - cz; + float d2 = dx * dx + dy * dy + dz * dz; + + if ( d2 < minDist ) + { + minDist = d2; + minIdx = j; + } + } + + b3Vec3 cp; + cp.x = b3MinFloat( b3MaxFloat( point.x, aabbMinX[minIdx] ), aabbMaxX[minIdx] ); + cp.y = b3MinFloat( b3MaxFloat( point.y, aabbMinY[minIdx] ), aabbMaxY[minIdx] ); + cp.z = b3MinFloat( b3MaxFloat( point.z, aabbMinZ[minIdx] ), aabbMaxZ[minIdx] ); + + *outClosestPoint = cp; + *outMinDistSq = minDist; +} +#endif + class TreeBenchmark : public Sample { public: @@ -65,7 +163,6 @@ public: m_closestPoint = b3Pos_zero; m_timeStamp = 1; - m_drawLevel = -1; m_doOverlap = false; m_doClosest = false; m_doRay = false; @@ -81,64 +178,65 @@ public: m_height = 0; m_tree = {}; + m_aabbMinX = nullptr; + m_aabbMinY = nullptr; + m_aabbMinZ = nullptr; + m_aabbMaxX = nullptr; + m_aabbMaxY = nullptr; + m_aabbMaxZ = nullptr; + CreateTree(); } ~TreeBenchmark() override { b3DynamicTree_Destroy( &m_tree ); + +#ifdef _WIN32 + _aligned_free( m_aabbMinX ); + _aligned_free( m_aabbMinY ); + _aligned_free( m_aabbMinZ ); + _aligned_free( m_aabbMaxX ); + _aligned_free( m_aabbMaxY ); + _aligned_free( m_aabbMaxZ ); +#endif } // Breath-first search to compute node depth values start with 0 at the root. - // The tree is walked a sibling pair at a time, so depth is tracked alongside - // each queued pair rather than looked up through the parent index. int ComputeDepths() { m_depths.resize( m_tree.nodeCapacity, 0 ); - if ( m_tree.nodes == nullptr || m_tree.proxyCount == 0 ) - { - return 0; - } - - b3TreeNode* nodes = m_tree.nodes; - m_depths[B3_ROOT_NODE] = 0; - - if ( b3IsLeaf( nodes + B3_ROOT_NODE ) ) - { - return 0; - } - - struct QueueItem - { - int pair; - int depth; - }; - - QueueItem* queue = (QueueItem*)malloc( m_tree.nodeEnd * sizeof( QueueItem ) ); + int* queue = (int*)malloc( m_tree.nodeCount * sizeof( int ) ); int front = 0; int back = 0; - queue[back++] = { b3GetLeftChild( nodes + B3_ROOT_NODE ), 1 }; - + b3TreeNode* nodes = m_tree.nodes; + queue[0] = m_tree.root; + back += 1; int depth = 0; while ( back > front ) { - QueueItem item = queue[front++]; - depth = b3MaxInt( depth, item.depth ); + int index = queue[front]; + front += 1; - for ( int i = 0; i < 2; ++i ) + b3TreeNode* node = nodes + index; + if ( node->parent == B3_NULL_INDEX ) { - int index = item.pair + i; - b3TreeNode* node = nodes + index; - m_depths[index] = item.depth; + m_depths[index] = 0; + } + else + { + m_depths[index] = m_depths[node->parent] + 1; + depth = b3MaxInt( depth, m_depths[index] ); + } - if ( b3IsLeaf( node ) == false ) - { - B3_ASSERT( back < m_tree.nodeEnd ); - queue[back++] = { b3GetLeftChild( node ), item.depth + 1 }; - } + if ( ( node->flags & b3_leafNode ) == 0 ) + { + B3_ASSERT( back < m_tree.nodeCount - 1 ); + queue[back++] = node->children.child1; + queue[back++] = node->children.child2; } } @@ -157,6 +255,15 @@ public: m_proxies.clear(); +#ifdef _WIN32 + _aligned_free( m_aabbMinX ); + _aligned_free( m_aabbMinY ); + _aligned_free( m_aabbMinZ ); + _aligned_free( m_aabbMaxX ); + _aligned_free( m_aabbMaxY ); + _aligned_free( m_aabbMaxZ ); +#endif + m_tree = b3DynamicTree_Create( 512 ); char filePath[64] = {}; @@ -167,7 +274,6 @@ public: FILE* file = fopen( filePath, "r" ); if ( file == nullptr ) { - fprintf( stderr, "Failed to open '%s'\n", filePath ); return; } @@ -236,12 +342,28 @@ public: // } } - fclose( file ); +#ifdef _WIN32 + int proxyCount = m_proxies.size(); + m_aabbMinX = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMinY = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMinZ = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxX = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxY = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxZ = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); - if ( m_proxies.empty() ) + for ( int i = 0; i < proxyCount; ++i ) { - return; + b3Vec3 lb = m_proxies[i].aabb.lowerBound; + b3Vec3 ub = m_proxies[i].aabb.upperBound; + + m_aabbMinX[i] = lb.x; + m_aabbMinY[i] = lb.y; + m_aabbMinZ[i] = lb.z; + m_aabbMaxX[i] = ub.x; + m_aabbMaxY[i] = ub.y; + m_aabbMaxZ[i] = ub.z; } +#endif printf( "max index = %d\n", maxAreaIndex ); @@ -277,34 +399,37 @@ public: m_proxies.clear(); +#ifdef _WIN32 + _aligned_free( m_aabbMinX ); + _aligned_free( m_aabbMinY ); + _aligned_free( m_aabbMinZ ); + _aligned_free( m_aabbMaxX ); + _aligned_free( m_aabbMaxY ); + _aligned_free( m_aabbMaxZ ); +#endif + { - // bool zUp = true; + //bool zUp = true; m_tree = b3DynamicTree_Load( m_saveFileName, m_loadScale ); } - // A missing or stale save file loads as an empty tree, which has no root to walk - if ( m_tree.nodes == nullptr || m_tree.proxyCount == 0 ) - { - fprintf( stderr, "Failed to load tree '%s'\n", m_saveFileName ); - m_height = 0; - m_drawLevel = -1; - m_buildTime = 0.0f; - m_areaRatio = 0.0f; - return; - } + constexpr int bufferSize = 512; + char buffer[bufferSize]; int maxArea = 0.0f; int maxAreaIndex = -1; - for ( int i = 0; i < m_tree.nodeEnd; ++i ) + for ( int i = 0; i < m_tree.nodeCapacity; ++i ) { b3TreeNode* node = m_tree.nodes + i; - if ( b3IsLeaf( node ) == false || b3IsEmptyNode( node ) ) + if ( ( node->flags & b3_leafNode ) == 0 ) { continue; } + assert( node->flags & b3_allocatedNode ); + Proxy proxy = {}; proxy.aabb = node->aabb; @@ -315,11 +440,33 @@ public: maxAreaIndex = (int)m_proxies.size(); } - int proxyId = b3GetProxyId( node ); - proxy.proxyId = proxyId; - m_proxies[m_tree.proxies[proxyId].userData] = proxy; + proxy.proxyId = i; + m_proxies[node->userData] = proxy; } +#ifdef _WIN32 + int proxyCount = m_proxies.size(); + m_aabbMinX = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMinY = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMinZ = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxX = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxY = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + m_aabbMaxZ = (float*)_aligned_malloc( proxyCount * sizeof( float ), 32 ); + + for ( int i = 0; i < proxyCount; ++i ) + { + b3Vec3 lb = m_proxies[i].aabb.lowerBound; + b3Vec3 ub = m_proxies[i].aabb.upperBound; + + m_aabbMinX[i] = lb.x; + m_aabbMinY[i] = lb.y; + m_aabbMinZ[i] = lb.z; + m_aabbMaxX[i] = ub.x; + m_aabbMaxY[i] = ub.y; + m_aabbMaxZ[i] = ub.z; + } +#endif + printf( "max index = %d\n", maxAreaIndex ); // constexpr int n = m_isDebug ? 1000 : INT_MAX; @@ -374,7 +521,7 @@ public: { srand( 42 ); - b3AABB bounds = m_tree.nodes[B3_ROOT_NODE].aabb; + b3AABB bounds = m_tree.nodes[m_tree.root].aabb; b3Vec3 extents = b3AABB_Extents( bounds ); float radius = ( extents.x + extents.y + extents.z ) / 3.0f; @@ -418,6 +565,42 @@ public: } m_overlapTime = b3GetMilliseconds( ticks ); +#if 0 && defined( _WIN32 ) + // brute force avx2 + int proxyCount = (int)m_proxies.size(); + for ( int i = 0; i < m_testCount; ++i ) + { + b3Vec3 point = m_closestPointQueries[i].center; + float minDistSq; + b3Vec3 closest; + + ClosestPointAVX2( m_aabbMinX, m_aabbMinY, m_aabbMinZ, m_aabbMaxX, m_aabbMaxY, m_aabbMaxZ, proxyCount, point, &closest, + &minDistSq ); + + m_closestPoint = closest; + m_haveClosest = true; + } +#elif 0 + // Brute force + int proxyCount = (int)m_proxies.size(); + for ( int i = 0; i < m_testCount; ++i ) + { + b3Vec3 point = m_closestPointQueries[i].center; + float minDistanceSquared = FLT_MAX; + m_haveClosest = false; + for ( int j = 0; j < proxyCount; ++j ) + { + b3Vec3 closestPoint = b3ClosestPointToAABB( point, m_proxies[j].aabb ); + float d = b3DistanceSquared( point, closestPoint ); + if ( d < minDistanceSquared ) + { + m_closestPoint = closestPoint; + m_haveClosest = true; + minDistanceSquared = d; + } + } + } +#else for ( int i = 0; i < m_testCount; ++i ) { b3Vec3 point = m_closestPointQueries[i].center; @@ -428,7 +611,7 @@ public: b3DynamicTree_QueryClosest( &m_tree, point, B3_DEFAULT_MASK_BITS, false, ClosetPointCallback, this, &distanceSquared ); } - +#endif m_closestTime = b3GetMilliseconds( ticks ); } @@ -439,11 +622,6 @@ public: bool DrawControls() override { - if ( m_tree.proxyCount == 0 ) - { - return false; - } - DrawTextLine( "leaves = %d, height = %d, area = %g", m_tree.proxyCount, m_height, m_areaRatio ); DrawTextLine( "build time = %g ms", m_buildTime ); DrawTextLine( "total: ray = %g ms, overlap = %g ms, closest = %g ms", m_rayTime, m_overlapTime, m_closestTime ); @@ -501,11 +679,6 @@ public: DrawAxes( b3WorldTransform_identity, 2.0f ); - if ( m_tree.proxyCount == 0 ) - { - return; - } - b3Pos cp = m_camera->DrawOrigin(); b3TreeNode* nodes = m_tree.nodes; float distSquared = m_drawDistance * m_drawDistance * 1000.0f * 1000.0f; @@ -520,11 +693,13 @@ public: b3_colorCoral, b3_colorCornflowerBlue, b3_colorCornsilk, b3_colorCrimson, b3_colorCyan, }; - for ( int i = 0; i < m_tree.nodeEnd; ++i ) + int capacity = m_tree.nodeCapacity; + for ( int i = 0; i < capacity; ++i ) { b3TreeNode* node = nodes + i; - if ( m_depths[i] != m_drawLevel || b3IsEmptyNode( node ) ) + if ( m_depths[i] != m_drawLevel || ( node->flags & b3_allocatedNode ) == 0 ) { + // skip internal nodes continue; } @@ -537,13 +712,12 @@ public: } else { - // Live leaves only. A mark on a leaf says its ancestors still need a refit, the - // leaf box itself is already current, so moved leaves still draw. - for ( int i = 0; i < m_tree.nodeEnd; ++i ) + uint16_t requiredFlags = b3_allocatedNode | b3_leafNode; + for ( int i = 0; i < m_tree.nodeCapacity; ++i ) { b3TreeNode* node = nodes + i; - if ( b3IsEmptyNode( node ) || b3IsLeaf( node ) == false ) + if ( node->flags != requiredFlags ) { continue; } @@ -554,7 +728,7 @@ public: continue; } - Proxy& proxy = m_proxies[m_tree.proxies[b3GetProxyId( node )].userData]; + Proxy& proxy = m_proxies[node->userData]; if ( proxy.queryTimeStamp == m_timeStamp || proxy.rayTimeStamp == m_timeStamp ) { DrawBounds( node->aabb, 0.0f, MakeColor( b3_colorLightGray ) ); @@ -592,14 +766,8 @@ public: void Step() override { Sample::Step(); - - if ( m_tree.proxyCount == 0 ) - { - return; - } - ++m_timeStamp; - + if ( m_doRay ) { Ray ray = m_rays[m_testIndex]; @@ -644,14 +812,19 @@ public: FileConfig m_config[m_fileCount]; int m_fileIndex; + float* m_aabbMinX; + float* m_aabbMinY; + float* m_aabbMinZ; + float* m_aabbMaxX; + float* m_aabbMaxY; + float* m_aabbMaxZ; + std::unordered_map m_proxies; std::vector m_depths; b3DynamicTree m_tree; - - // Zeroed because the queries are only generated once a tree loads - Ray m_rays[m_testCount] = {}; - b3AABB m_overlapQueries[m_testCount] = {}; - b3Sphere m_closestPointQueries[m_testCount] = {}; + Ray m_rays[m_testCount]; + b3AABB m_overlapQueries[m_testCount]; + b3Sphere m_closestPointQueries[m_testCount]; b3Pos m_closestPoint; float m_areaRatio; float m_rayTime; diff --git a/samples/sample_world.cpp b/samples/sample_world.cpp index 1f8d142..241a1fc 100644 --- a/samples/sample_world.cpp +++ b/samples/sample_world.cpp @@ -101,7 +101,7 @@ public: // Height of the top box above the ground, measured in the offset's own frame. This holds // steady at any offset under double precision and drifts once float runs out of resolution. - b3Vec3 top = b3SubPos( b3Body_GetWorldCenter( m_topBodyId ), m_base ); + b3Vec3 top = b3SubPos( b3Body_GetWorldCenterOfMass( m_topBodyId ), m_base ); DrawTextLine( "double precision: %s", b3IsDoublePrecision() ? "ON" : "OFF" ); DrawTextLine( "world offset: %.1f km", m_offsetKilometers ); diff --git a/samples/shaders/CMakeLists.txt b/samples/shaders/CMakeLists.txt index ee94b87..cb4921f 100644 --- a/samples/shaders/CMakeLists.txt +++ b/samples/shaders/CMakeLists.txt @@ -3,25 +3,13 @@ # Each .glsl file in shaders/ becomes a single C header in # generated/.glsl.h that holds source/bytecode for every enabled backend # (D3D11, Metal, GL 4.5 core). The generated headers are committed so a fresh -# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default OFF) recompiles +# clone builds without sokol-shdc. BOX3D_BUILD_SHADERS (default ON) recompiles # them in place when a .glsl changes; off builds straight from the committed # headers and fetches no tooling. set(SHADER_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated" CACHE INTERNAL "Directory holding generated shader headers") -# Shared @include fragments - sokol-shdc's @include resolves relative to the -# input file, so shaders include these via "../common/.glsl". Listed in -# the shaders target's SOURCES so they show up in IDE project trees, which is -# the only way they get there - sokol-shdc never sees them as direct inputs. -# Globbed unconditionally so they stay searchable when codegen is off, which -# is the default. With codegen on they are also DEPENDS on every shader so an -# edit to a shared file rebuilds everything that might include it. -# CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of a -# configure-step stat each build. -file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS - "${CMAKE_CURRENT_LIST_DIR}/common/*.glsl") - if(BOX3D_BUILD_SHADERS) if(NOT SOKOL_SHDC_EXECUTABLE OR NOT EXISTS "${SOKOL_SHDC_EXECUTABLE}") message(FATAL_ERROR @@ -29,6 +17,17 @@ if(BOX3D_BUILD_SHADERS) "${SOKOL_SHDC_EXECUTABLE}") endif() file(MAKE_DIRECTORY "${SHADER_OUTPUT_DIR}") + + # Shared @include fragments - sokol-shdc's @include resolves relative to + # the input file, so shaders include these via "../common/.glsl". + # Tracked as DEPENDS on every shader so an edit to a shared file triggers + # a rebuild of everything that might include it, and listed in the shaders + # target's SOURCES so they show up in IDE project trees - sokol-shdc never + # sees them as direct inputs, so they would be invisible otherwise. + # CONFIGURE_DEPENDS re-globs when a new common file appears, at the cost of + # a configure-step stat each build. + file(GLOB SHADER_COMMON_INCLUDES CONFIGURE_DEPENDS + "${CMAKE_CURRENT_LIST_DIR}/common/*.glsl") endif() # Reset the accumulators on every configure so stale entries from a prior @@ -104,36 +103,35 @@ add_shader(highlight_outline "post/highlight_outline.glsl") # overlay add_shader(overlay_line "overlays/line.glsl") add_shader(overlay_point "overlays/point.glsl") -add_shader(world_text "overlays/world_text.glsl") get_property(_outputs GLOBAL PROPERTY SHADER_OUTPUTS) get_property(_inputs GLOBAL PROPERTY SHADER_INPUTS) -# SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files in -# the project tree even though nothing here is compiled. We list the leaf .glsl -# shaders, the common/ @include fragments, and the generated .glsl.h. if(BOX3D_BUILD_SHADERS) # DEPENDS drives the build (run sokol-shdc when the .glsl inputs change). + # SOURCES is purely an IDE hint - Visual Studio and Xcode show listed files + # in the project tree even though nothing here is compiled. We list the leaf + # .glsl shaders, the common/ @include fragments, and the generated .glsl.h. add_custom_target(shaders DEPENDS ${_outputs} SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs} ) + + # IDE grouping. TREE mirrors the on-disk shaders layout. + source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" + FILES ${_inputs} ${SHADER_COMMON_INCLUDES}) + source_group("Generated" FILES ${_outputs}) + + # The Visual Studio generator emits a build-stamp file named + # CMakeFiles/ for each custom target. Left ungrouped it floats at + # the project root as a stray "shaders" node with a can't-find-file icon - + # file it under the build-rule machinery. + source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders") else() # No codegen: the samples build straight from the committed headers. - add_custom_target(shaders SOURCES ${_inputs} ${SHADER_COMMON_INCLUDES} ${_outputs}) + add_custom_target(shaders SOURCES ${_inputs} ${_outputs}) endif() -# IDE grouping. TREE mirrors the on-disk shaders layout. -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" - FILES ${_inputs} ${SHADER_COMMON_INCLUDES}) -source_group("Generated" FILES ${_outputs}) - -# The Visual Studio generator emits a build-stamp file named CMakeFiles/ -# for each custom target. Left ungrouped it floats at the project root as a -# stray "shaders" node with a can't-find-file icon - file it under the -# build-rule machinery. -source_group("CMake Rules" FILES "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/shaders") - # shader_gen is the INTERFACE library consumers link to. It forwards the include # path for the generated headers (SYSTEM so /WX doesn't trip on shdc output) and # pulls in the shaders target so any link forces the headers to exist first. diff --git a/samples/shaders/common/shadow_cascade.glsl b/samples/shaders/common/shadow_cascade.glsl deleted file mode 100644 index 6e01a7b..0000000 --- a/samples/shaders/common/shadow_cascade.glsl +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// Cascade count plus the parts of the cascaded lookup that touch no -// uniform block, shared by the lit shape shaders via @include. Each -// shader declares its own ub_pass, so the per-cascade values stay there -// and arrive as parameters. - -// Must match SHADOW_CASCADE_COUNT in gfx/shadow.h. The renderer static -// asserts the two agree, so a mismatch fails the build instead of -// rendering garbage. Changing it here only reaches the committed headers -// after a shader regen, which needs BOX3D_BUILD_SHADERS=ON. -// -// Four is the ceiling. Per-cascade values ride in vec4 lanes and a fifth -// cascade would need a second vec4 for each of them. -#define SHADOW_CASCADE_COUNT 4 - -// Cascade whose slice holds this view depth. The last one is a fallback -// rather than a range: its map footprint runs well past the final split, -// so content past the split range still gets shadowed. -int selectShadowCascade( vec4 far_view_z, float view_z ) -{ - int cascade = SHADOW_CASCADE_COUNT - 1; - for ( int i = 0; i < SHADOW_CASCADE_COUNT - 1; ++i ) - { - if ( view_z < far_view_z[i] ) - { - cascade = i; - break; - } - } - return cascade; -} - -// Debug view 2. -vec3 shadowCascadeTint( int cascade ) -{ - if ( cascade == 0 ) - { - return vec3( 1.0, 0.4, 0.4 ); - } - if ( cascade == 1 ) - { - return vec3( 0.4, 1.0, 0.4 ); - } - if ( cascade == 2 ) - { - return vec3( 0.4, 0.4, 1.0 ); - } - return vec3( 1.0, 0.9, 0.3 ); -} diff --git a/samples/shaders/common/shadow_pcf.glsl b/samples/shaders/common/shadow_pcf.glsl deleted file mode 100644 index fc89f25..0000000 --- a/samples/shaders/common/shadow_pcf.glsl +++ /dev/null @@ -1,96 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// Cascaded shadow map PCF, shared by the lit shape shaders via -// @include. The texture and comparison sampler are passed as parameters -// so this file has no binding declarations of its own. -// -// 7x7 uniform kernel evaluated with 16 bilinear comparison taps. Tap -// positions and weights steer the hardware 2x2 compare so the fetches -// reproduce the full 49-texel kernel with triangle-filtered sub-texel -// placement, a moving shadow edge slides smoothly instead of stepping -// texel by texel. Follows the optimized PCF from The Witness (Ignacio -// Castano), via MJP's shadows sample. -// -// Manually unrolled: the HLSL compiler emits warning X3570 ("gradient -// instruction used in a loop with varying iteration") on looped texture -// calls. Unrolling keeps cross-compilation clean on the D3D11 backend. - -float sampleShadowTap( texture2DArray tex, samplerShadow smp, vec2 uv, float layer, float ref_z ) -{ - return texture( sampler2DArrayShadow( tex, smp ), vec4( uv, layer, ref_z ) ); -} - -// scale multiplies the tap offsets. Cascades cover different world sizes -// per texel, so the caller passes the texel-size ratio against the near -// cascade and the penumbra keeps a constant world width instead of -// jumping from crisp to blurry at every cascade boundary. 1.0 = the full -// 7x7 kernel. -// -// inv_size is one texel in UV. Passed in rather than baked in so the -// kernel follows SHADOW_RESOLUTION without a second place to edit. -float sampleShadowPCF( texture2DArray tex, samplerShadow smp, int cascade, vec3 light_uv, float bias, float scale, - float inv_size ) -{ - float size = 1.0 / inv_size; - - float ly = float( cascade ); - float rz = light_uv.z - bias; - - // Texel-space position split into the nearest texel corner and the - // sub-texel fraction that drives the tap weights. - vec2 tuv = light_uv.xy * size; - vec2 base = floor( tuv + 0.5 ); - float s = tuv.x + 0.5 - base.x; - float t = tuv.y + 0.5 - base.y; - base = ( base - 0.5 ) * inv_size; - - // Shrinking the offsets bunches the 16 bilinear taps inside a smaller - // footprint. The box property degrades gracefully, at the 0.25 floor - // the taps still span ~2 texels and overlap through the hardware 2x2 - // compare, so the response stays smooth. - float step = inv_size * scale; - - float uw0 = 5.0 * s - 6.0; - float uw1 = 11.0 * s - 28.0; - float uw2 = -( 11.0 * s + 17.0 ); - float uw3 = -( 5.0 * s + 1.0 ); - - float u0 = ( 4.0 * s - 5.0 ) / uw0 - 3.0; - float u1 = ( 4.0 * s - 16.0 ) / uw1 - 1.0; - float u2 = -( 7.0 * s + 5.0 ) / uw2 + 1.0; - float u3 = -s / uw3 + 3.0; - - float vw0 = 5.0 * t - 6.0; - float vw1 = 11.0 * t - 28.0; - float vw2 = -( 11.0 * t + 17.0 ); - float vw3 = -( 5.0 * t + 1.0 ); - - float v0 = ( 4.0 * t - 5.0 ) / vw0 - 3.0; - float v1 = ( 4.0 * t - 16.0 ) / vw1 - 1.0; - float v2 = -( 7.0 * t + 5.0 ) / vw2 + 1.0; - float v3 = -t / vw3 + 3.0; - - float sum = 0.0; - sum += uw0 * vw0 * sampleShadowTap( tex, smp, base + vec2( u0, v0 ) * step, ly, rz ); - sum += uw1 * vw0 * sampleShadowTap( tex, smp, base + vec2( u1, v0 ) * step, ly, rz ); - sum += uw2 * vw0 * sampleShadowTap( tex, smp, base + vec2( u2, v0 ) * step, ly, rz ); - sum += uw3 * vw0 * sampleShadowTap( tex, smp, base + vec2( u3, v0 ) * step, ly, rz ); - - sum += uw0 * vw1 * sampleShadowTap( tex, smp, base + vec2( u0, v1 ) * step, ly, rz ); - sum += uw1 * vw1 * sampleShadowTap( tex, smp, base + vec2( u1, v1 ) * step, ly, rz ); - sum += uw2 * vw1 * sampleShadowTap( tex, smp, base + vec2( u2, v1 ) * step, ly, rz ); - sum += uw3 * vw1 * sampleShadowTap( tex, smp, base + vec2( u3, v1 ) * step, ly, rz ); - - sum += uw0 * vw2 * sampleShadowTap( tex, smp, base + vec2( u0, v2 ) * step, ly, rz ); - sum += uw1 * vw2 * sampleShadowTap( tex, smp, base + vec2( u1, v2 ) * step, ly, rz ); - sum += uw2 * vw2 * sampleShadowTap( tex, smp, base + vec2( u2, v2 ) * step, ly, rz ); - sum += uw3 * vw2 * sampleShadowTap( tex, smp, base + vec2( u3, v2 ) * step, ly, rz ); - - sum += uw0 * vw3 * sampleShadowTap( tex, smp, base + vec2( u0, v3 ) * step, ly, rz ); - sum += uw1 * vw3 * sampleShadowTap( tex, smp, base + vec2( u1, v3 ) * step, ly, rz ); - sum += uw2 * vw3 * sampleShadowTap( tex, smp, base + vec2( u2, v3 ) * step, ly, rz ); - sum += uw3 * vw3 * sampleShadowTap( tex, smp, base + vec2( u3, v3 ) * step, ly, rz ); - - return sum / 2704.0; -} diff --git a/samples/shaders/generated/capsule.glsl.h b/samples/shaders/generated/capsule.glsl.h index c2da366..51244f2 100644 --- a/samples/shaders/generated/capsule.glsl.h +++ b/samples/shaders/generated/capsule.glsl.h @@ -104,10 +104,7 @@ SOKOL_SHDC_ALIGN(16) typedef struct capsule_ub_pass_t { Mat4 view_proj; Mat4 view; Vec4 cascade_far_view_z; - Vec4 cascade_texel_world; - Vec4 cascade_depth_bias; - Vec4 shadow_params; - Mat4 cascade_matrices[4]; + Mat4 cascade_matrices[3]; Vec4 sh[9]; Vec4 ibl_params; } capsule_ub_pass_t; @@ -307,15 +304,12 @@ static const uint8_t capsule_vs_source_glsl430[1888] = { mat4 view_proj; mat4 view; vec4 cascade_far_view_z; - vec4 cascade_texel_world; - vec4 cascade_depth_bias; - vec4 shadow_params; - mat4 cascade_matrices[4]; + mat4 cascade_matrices[3]; vec4 sh[9]; vec4 ibl_params; }; - uniform ub_pass _1071; + uniform ub_pass _707; layout(binding = 0) uniform sampler2D tex_ao_smp_ao; layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; @@ -334,218 +328,94 @@ static const uint8_t capsule_vs_source_glsl430[1888] = { layout(location = 0) out vec4 out_color; layout(location = 9) flat in vec4 v_material; - int selectShadowCascade(vec4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - vec3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return vec3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - - float sampleShadowTap(vec2 uv, float layer, float ref_z, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - return texture(SPIRV_Cross_Combinedtexsmp, vec4(vec4(uv, layer, ref_z).xyz, ref_z)); - } - - float sampleShadowPCF(int cascade, vec3 light_uv, float bias, float scale, float inv_size, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias; - vec2 _625 = light_uv.xy * (1.0 / inv_size); - vec2 _630 = floor(_625 + vec2(0.5)); - float _637 = (_625.x + 0.5) - _630.x; - float _644 = (_625.y + 0.5) - _630.y; - vec2 _649 = (_630 - vec2(0.5)) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0 * _637; - float _658 = _656 - 6.0; - float _662 = 11.0 * _637; - float _664 = _662 - 28.0; - float _670 = (-17.0) - _662; - float _675 = (-1.0) - _656; - float _679 = 4.0 * _637; - float _683 = ((_679 - 5.0) / _658) - 3.0; - float _691 = ((_679 - 16.0) / _664) - 1.0; - float _700 = (((-5.0) - (7.0 * _637)) / _670) + 1.0; - float _706 = ((-_637) / _675) + 3.0; - float _709 = 5.0 * _644; - float _710 = _709 - 6.0; - float _713 = 11.0 * _644; - float _714 = _713 - 28.0; - float _719 = (-17.0) - _713; - float _724 = (-1.0) - _709; - float _727 = 4.0 * _644; - float _731 = ((_727 - 5.0) / _710) - 3.0; - float _738 = ((_727 - 16.0) / _714) - 1.0; - float _746 = (((-5.0) - (7.0 * _644)) / _719) + 1.0; - float _752 = ((-_644) / _724) + 3.0; - float sum = 0.0; - vec2 param = _649 + (vec2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(param, param_1, param_2, SPIRV_Cross_Combinedtexsmp)); - vec2 param_3 = _649 + (vec2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(param_3, param_4, param_5, SPIRV_Cross_Combinedtexsmp)); - vec2 param_6 = _649 + (vec2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(param_6, param_7, param_8, SPIRV_Cross_Combinedtexsmp)); - vec2 param_9 = _649 + (vec2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(param_9, param_10, param_11, SPIRV_Cross_Combinedtexsmp)); - vec2 param_12 = _649 + (vec2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(param_12, param_13, param_14, SPIRV_Cross_Combinedtexsmp)); - vec2 param_15 = _649 + (vec2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(param_15, param_16, param_17, SPIRV_Cross_Combinedtexsmp)); - vec2 param_18 = _649 + (vec2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(param_18, param_19, param_20, SPIRV_Cross_Combinedtexsmp)); - vec2 param_21 = _649 + (vec2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(param_21, param_22, param_23, SPIRV_Cross_Combinedtexsmp)); - vec2 param_24 = _649 + (vec2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(param_24, param_25, param_26, SPIRV_Cross_Combinedtexsmp)); - vec2 param_27 = _649 + (vec2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(param_27, param_28, param_29, SPIRV_Cross_Combinedtexsmp)); - vec2 param_30 = _649 + (vec2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(param_30, param_31, param_32, SPIRV_Cross_Combinedtexsmp)); - vec2 param_33 = _649 + (vec2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(param_33, param_34, param_35, SPIRV_Cross_Combinedtexsmp)); - vec2 param_36 = _649 + (vec2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(param_36, param_37, param_38, SPIRV_Cross_Combinedtexsmp)); - vec2 param_39 = _649 + (vec2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(param_39, param_40, param_41, SPIRV_Cross_Combinedtexsmp)); - vec2 param_42 = _649 + (vec2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(param_42, param_43, param_44, SPIRV_Cross_Combinedtexsmp)); - vec2 param_45 = _649 + (vec2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(param_45, param_46, param_47, SPIRV_Cross_Combinedtexsmp)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875; + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float _584 = light_uv.x + 0.00048828125; + float _652 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_550, _554, _529, _534).xyz, _534)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _652, _529, _534).xyz, _534))) * 0.111111111938953399658203125; } float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) { - float _1086 = clamp(_1071.cascade_texel_world.x / _1071.cascade_texel_world[cascade], 0.25, 1.0); - float _1095 = max(dot(world_normal, normalize(_1071.sun_dir_world.xyz)), 0.0); - float _1105 = 3.0 * _1086; - vec4 _1128 = _1071.cascade_matrices[cascade] * vec4(world_pos + (world_normal * ((((_1105 + 0.5) * 1.41420996189117431640625) * sqrt(max(1.0 - (_1095 * _1095), 0.0))) * _1071.cascade_texel_world[cascade])), 1.0); - vec3 _1136 = _1128.xyz / vec3(_1128.w); - float _1153 = _1136.z; - vec3 _1154 = vec3((_1136.x * 0.5) + 0.5, ((_1136.y * _1071.shadow_params.x) * 0.5) + 0.5, _1153); - bool _1157 = _1153 < 0.0; - bool _1164; - if (!_1157) + vec4 _717 = _707.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _724 = _717.xyz / vec3(_717.w); + vec3 _742 = vec3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(lessThan(_742, vec3(0.0))); + bool _753; + if (!_746) { - _1164 = _1153 > 1.0; + _753 = any(greaterThan(_742, vec3(1.0))); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0; - } - float _1174 = (_1105 + 1.0) * _1071.shadow_params.y; - vec2 _1176 = _1154.xy; - bool _1182 = any(lessThan(_1176, vec2(-_1174))); - bool _1193; - if (!_1182) - { - _1193 = any(greaterThan(_1176, vec2(1.0 + _1174))); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0; } int param = cascade; - vec3 param_1 = _1154; - float param_2 = _1071.cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071.shadow_params.y; - return sampleShadowPCF(param, param_1, param_2, param_3, param_4, tex_shadow_smp_shadow); + vec3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _785 = _742.xy; + vec2 _790 = min(_785, vec2(1.0) - _785); + pcf = mix(1.0, pcf, clamp(min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; } float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) { - vec4 param = _1071.cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - vec3 param_3 = world_pos; - vec3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) { - _1239 = 0.0; + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; } else { - _1239 = _1071.cascade_far_view_z[_1219 - 1]; + _835 = _707.cascade_far_view_z.y; } - float _1252 = mix(_1071.cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - vec3 param_6 = world_pos; - vec3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1252) / (_1071.cascade_far_view_z[_1219] - _1252)); + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -553,56 +423,56 @@ static const uint8_t capsule_vs_source_glsl430[1888] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0)) + 1.0; - return _133 / ((3.1415927410125732421875 * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _155 = alpha * alpha; - float _162 = 1.0 - _155; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06); + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); } vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) { - float _191 = 1.0 - v_dot_h; - float _195 = _191 * _191; - return f0 + ((vec3(1.0) - f0) * ((_195 * _195) * _191)); + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((vec3(1.0) - f0) * ((_169 * _169) * _165)); } vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) { - float _214 = max(dot(N, L), 0.0); - vec3 _225 = normalize(V + L); - float _239 = max(roughness, 0.04500000178813934326171875); - float _243 = _239 * _239; - float param = max(dot(N, _225), 0.0); - float param_1 = _243; + float _188 = max(dot(N, L), 0.0); + vec3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0); + float param_1 = _217; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _214; - float param_4 = _243; - float param_5 = max(dot(V, _225), 0.0); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0); vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); - vec3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((vec3(1.0) - _270) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + vec3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _244) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) { - vec3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _424; + vec3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; } vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) { - float _431 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - vec3 _441 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _416 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); vec3 param = N_world; vec4 param_1[9] = sh; - vec4 _505 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_431, roughness)); - return (((((vec3(1.0) - (_441 + ((max(vec3(1.0 - roughness), _441) - _441) * pow(max(0.0, 1.0 - _431), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_441 * _505.x) + vec3(_505.y))); + vec4 _482 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_406, roughness)); + return (((((vec3(1.0) - (_416 + ((max(vec3(1.0 - roughness), _416) - _416) * pow(max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + vec3(_482.y))); } vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) @@ -624,190 +494,213 @@ static const uint8_t capsule_vs_source_glsl430[1888] = { void main() { - vec3 _1290 = normalize(v_world_pos_proxy - _1071.camera_pos.xyz); - vec3 _1301 = v_axis_x_world * v_half_length; - vec3 _1302 = v_center - _1301; - vec3 _1308 = v_center + _1301; - vec3 _1312 = _1308 - _1302; - vec3 _1316 = _1071.camera_pos.xyz - _1302; - float _1320 = dot(_1312, _1312); - float _1324 = dot(_1312, _1290); - float _1328 = dot(_1312, _1316); - float _1336 = dot(_1316, _1316); - float _1342 = _1320 - (_1324 * _1324); - float _1350 = (_1320 * dot(_1290, _1316)) - (_1328 * _1324); - float _1362 = v_radius * v_radius; - float _1373 = (_1350 * _1350) - (_1342 * (((_1320 * _1336) - (_1328 * _1328)) - (_1362 * _1320))); - vec3 _1394 = _1302 + (_1312 * clamp((_1328 - ((_1350 / max(_1342, 9.9999999392252902907785028219223e-09)) * _1324)) / _1320, 0.0, 1.0)); - vec3 _1398 = _1071.camera_pos.xyz - _1394; - float _1402 = dot(_1398, _1290); - float _1416 = sqrt(max(0.0, dot(_1398, _1398) - (_1402 * _1402))) - v_radius; - float _1419 = fwidth(_1416); - float _1421 = max(_1419, 9.9999999747524270787835121154785e-07); - float _1428 = 1.0 - smoothstep(-_1421, _1421, _1416); + vec3 _896 = normalize(v_world_pos_proxy - _707.camera_pos.xyz); + vec3 _907 = v_axis_x_world * v_half_length; + vec3 _908 = v_center - _907; + vec3 _914 = v_center + _907; + vec3 _918 = _914 - _908; + vec3 _922 = _707.camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = v_radius * v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + vec3 _1000 = _908 + (_918 * clamp((_934 - ((_956 / max(_948, 9.9999999392252902907785028219223e-09)) * _930)) / _926, 0.0, 1.0)); + vec3 _1004 = _707.camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(max(0.0, dot(_1004, _1004) - (_1008 * _1008))) - v_radius; + float _1025 = fwidth(_1022); + float _1027 = max(_1025, 9.9999999747524270787835121154785e-07); + float _1034 = 1.0 - smoothstep(-_1027, _1027, _1022); float t = -1.0; vec3 n_world = vec3(0.0); - if ((_1373 >= 0.0) && (_1342 > 9.9999999392252902907785028219223e-09)) + if ((_979 >= 0.0) && (_948 > 9.9999999392252902907785028219223e-09)) { - float _1446 = ((-_1350) - sqrt(_1373)) / _1342; - float _1452 = _1328 + (_1446 * _1324); - if (((_1446 > 0.0) && (_1452 > 0.0)) && (_1452 < _1320)) + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0) && (_1058 > 0.0)) && (_1058 < _926)) { - n_world = ((_1071.camera_pos.xyz + (_1290 * _1446)) - (_1302 + (_1312 * (_1452 / _1320)))) / vec3(v_radius); - t = _1446; + n_world = ((_707.camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / vec3(v_radius); + t = _1052; } } - float _1492 = dot(_1316, _1290); - float _1506 = (_1492 * _1492) - (_1336 - _1362); - if (_1506 >= 0.0) + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0) { - float _1516 = (-_1492) - sqrt(_1506); - bool _1518 = _1516 > 0.0; - bool _1527; - if (_1518) + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0; + bool _1133; + if (_1124) { - _1527 = (t < 0.0) || (_1516 < t); + _1133 = (t < 0.0) || (_1122 < t); } else { - _1527 = _1518; + _1133 = _1124; } - if (_1527) + if (_1133) { - vec3 _1538 = (_1071.camera_pos.xyz + (_1290 * _1516)) - _1302; - if (dot(_1538, v_axis_x_world) <= 0.0) + vec3 _1144 = (_707.camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, v_axis_x_world) <= 0.0) { - n_world = _1538 / vec3(v_radius); - t = _1516; + n_world = _1144 / vec3(v_radius); + t = _1122; } } } - vec3 _1554 = _1071.camera_pos.xyz - _1308; - float _1558 = dot(_1554, _1290); - float _1572 = (_1558 * _1558) - (dot(_1554, _1554) - _1362); - if (_1572 >= 0.0) + vec3 _1160 = _707.camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0) { - float _1582 = (-_1558) - sqrt(_1572); - bool _1584 = _1582 > 0.0; - bool _1593; - if (_1584) + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0; + bool _1199; + if (_1190) { - _1593 = (t < 0.0) || (_1582 < t); + _1199 = (t < 0.0) || (_1188 < t); } else { - _1593 = _1584; + _1199 = _1190; } - if (_1593) + if (_1199) { - vec3 _1604 = (_1071.camera_pos.xyz + (_1290 * _1582)) - _1308; - if (dot(_1604, v_axis_x_world) >= 0.0) + vec3 _1210 = (_707.camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, v_axis_x_world) >= 0.0) { - n_world = _1604 / vec3(v_radius); - t = _1582; + n_world = _1210 / vec3(v_radius); + t = _1188; } } } if (t < 0.0) { - float _1622 = -_1402; - t = _1622; - n_world = normalize((_1071.camera_pos.xyz + (_1290 * _1622)) - _1394); + float _1228 = -_1008; + t = _1228; + n_world = normalize((_707.camera_pos.xyz + (_896 * _1228)) - _1000); } - if ((_1428 <= 0.0) || (t < 0.0)) + if ((_1034 <= 0.0) || (t < 0.0)) { discard; } - vec3 _1646 = _1071.camera_pos.xyz + (_1290 * t); - float _1684 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); - float _1701 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); - vec3 _1715 = v_base_color.xyz * ((_1684 > 0.0) ? 1.0 : 0.64999997615814208984375); - float _1719 = fwidth(_1684); - float _1730 = fwidth(_1701); - vec3 _1750 = mix(_1715, _1715 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, _1719 * 1.5, abs(_1684)), 1.0 - smoothstep(0.0, _1730 * 1.5, abs(_1701))))); - vec4 _1758 = vec4(_1646, 1.0); - vec4 _1759 = _1071.view_proj * _1758; - gl_FragDepth = _1759.z / _1759.w; - if (_1071.flags.x == 1) + vec3 _1252 = _707.camera_pos.xyz + (_896 * t); + float _1290 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); + float _1307 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); + vec3 _1321 = v_base_color.xyz * ((_1290 > 0.0) ? 1.0 : 0.64999997615814208984375); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + vec3 _1356 = mix(_1321, _1321 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, _1325 * 1.5, abs(_1290)), 1.0 - smoothstep(0.0, _1336 * 1.5, abs(_1307))))); + vec4 _1364 = vec4(_1252, 1.0); + vec4 _1365 = _707.view_proj * _1364; + gl_FragDepth = _1365.z / _1365.w; + if (_707.flags.x == 1) { - float _1791 = clamp((_1071.view * _1758).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out_color = vec4(_1791, _1791, _1791, 1.0); + float _1397 = clamp((_707.view * _1364).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1397, _1397, _1397, 1.0); return; } - if (_1071.flags.x == 2) + if (_707.flags.x == 2) { - vec4 param = _1071.cascade_far_view_z; - float param_1 = -(_1071.view * _1758).z; - int _1819 = selectShadowCascade(param, param_1); - vec4 _1829 = _1071.cascade_matrices[_1819] * _1758; - vec3 _1836 = _1829.xyz / vec3(_1829.w); - vec3 _1853 = vec3((_1836.x * 0.5) + 0.5, ((_1836.y * _1071.shadow_params.x) * 0.5) + 0.5, _1836.z); - bool _1858 = any(lessThan(_1853, vec3(0.0))); - bool _1865; - if (!_1858) + float _1418 = -(_707.view * _1364).z; + int cascade = 2; + if (_1418 < _707.cascade_far_view_z.x) { - _1865 = any(greaterThan(_1853, vec3(1.0))); + cascade = 0; } else { - _1865 = _1858; + if (_1418 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1442 = _707.cascade_matrices[cascade] * _1364; + vec3 _1449 = _1442.xyz / vec3(_1442.w); + vec3 _1466 = vec3((_1449.x * 0.5) + 0.5, ((_1449.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1449.z); + bool _1470 = any(lessThan(_1466, vec3(0.0))); + bool _1477; + if (!_1470) + { + _1477 = any(greaterThan(_1466, vec3(1.0))); + } + else + { + _1477 = _1470; } vec3 tint = vec3(1.0); - if (!_1865) + if (!_1477) { - int param_2 = _1819; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out_color = vec4(tint, 1.0); return; } - if (_1071.flags.x == 3) + if (_707.flags.x == 3) { - out_color = vec4((normalize((_1071.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + out_color = vec4((normalize((_707.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); return; } - vec4 _1924 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); - float _1925 = _1924.x; - if (_1071.flags.x == 4) + vec4 _1547 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1548 = _1547.x; + if (_707.flags.x == 4) { - out_color = vec4(_1925, _1925, _1925, 1.0); + out_color = vec4(_1548, _1548, _1548, 1.0); return; } - vec3 param_3 = _1646; - vec3 param_4 = n_world; - float param_5 = -(_1071.view * _1758).z; - vec3 _1973 = normalize(_1071.camera_pos.xyz - _1646); - vec3 param_6 = n_world; - vec3 param_7 = _1973; - vec3 param_8 = normalize(_1071.sun_dir_world.xyz); - vec3 param_9 = _1071.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); - vec3 param_10 = _1750; - float param_11 = v_material.x; - float param_12 = v_material.y; - bool param_13 = _1071.ibl_params.y > 0.5; - vec3 param_14 = n_world; - vec3 param_15 = _1973; - vec3 param_16 = _1750; - float param_17 = v_material.x; - float param_18 = v_material.y; - float param_19 = _1071.sun_color.w; - vec4 param_20[9]; - param_20[0] = _1071.sh[0]; - param_20[1] = _1071.sh[1]; - param_20[2] = _1071.sh[2]; - param_20[3] = _1071.sh[3]; - param_20[4] = _1071.sh[4]; - param_20[5] = _1071.sh[5]; - param_20[6] = _1071.sh[6]; - param_20[7] = _1071.sh[7]; - param_20[8] = _1071.sh[8]; - float param_21 = _1071.ibl_params.x; - float _2053 = v_base_color.w * _1428; - out_color = vec4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1925)) * _2053, _2053); + vec3 param = _1252; + vec3 param_1 = n_world; + float param_2 = -(_707.view * _1364).z; + vec3 _1596 = normalize(_707.camera_pos.xyz - _1252); + vec3 param_3 = n_world; + vec3 param_4 = _1596; + vec3 param_5 = normalize(_707.sun_dir_world.xyz); + vec3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = _1356; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + vec3 param_11 = n_world; + vec3 param_12 = _1596; + vec3 param_13 = _1356; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707.sun_color.w; + vec4 param_17[9]; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1675 = v_base_color.w * _1034; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1548)) * _1675, _1675); } */ -static const uint8_t capsule_fs_source_glsl430[19981] = { +static const uint8_t capsule_fs_source_glsl430[15511] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, @@ -819,1244 +712,965 @@ static const uint8_t capsule_fs_source_glsl430[19981] = { 0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69, 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73, 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f, - 0x72,0x6d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e, - 0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f, - 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62, - 0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66, - 0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72, - 0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a, - 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, - 0x20,0x32,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, - 0x63,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e, - 0x67,0x20,0x3d,0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, - 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74, - 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, - 0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, - 0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a, - 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x36,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x37,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, + 0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29,0x20, + 0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43, + 0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20, + 0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, + 0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61, 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x37,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, - 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x38,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29, - 0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x39,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x3b,0x0a,0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x76,0x65,0x63,0x34, - 0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69, - 0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b, + 0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29, + 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x38,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, + 0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x39,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62, + 0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x35,0x35,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78, + 0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35, + 0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39, + 0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32, + 0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, + 0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x34, + 0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65, + 0x63,0x33,0x28,0x5f,0x37,0x31,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34, + 0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36, 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28, - 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, - 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x31, - 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, - 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, - 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, - 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, - 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, - 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, - 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c, - 0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39, - 0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x72,0x65,0x66,0x5f,0x7a,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x2c,0x20,0x76,0x65,0x63,0x34, - 0x28,0x76,0x65,0x63,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c, - 0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66, - 0x5f,0x7a,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69, - 0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33, - 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x62,0x69,0x61,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61, - 0x6c,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72, - 0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x73,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x36,0x31,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, - 0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x5f,0x36,0x32,0x35,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, - 0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f, - 0x72,0x28,0x5f,0x36,0x32,0x35,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e, - 0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x33,0x37,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x78,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x34,0x20,0x3d,0x20, - 0x28,0x5f,0x36,0x32,0x35,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d, - 0x20,0x5f,0x36,0x33,0x30,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x5f,0x36,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x30,0x20,0x2d, - 0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e, - 0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a, - 0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20, - 0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x36,0x20,0x2d,0x20, - 0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x36,0x32,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36, - 0x34,0x20,0x3d,0x20,0x5f,0x36,0x36,0x32,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20, - 0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x35, - 0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x36, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x39, - 0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20, - 0x5f,0x36,0x35,0x38,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f, - 0x36,0x36,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x28, - 0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f, - 0x36,0x33,0x37,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x30,0x29,0x20,0x2b,0x20, - 0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x37,0x29,0x20,0x2f, - 0x20,0x5f,0x36,0x37,0x35,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x39,0x20,0x3d,0x20,0x35, - 0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x39, - 0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x31,0x33,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20, - 0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x33,0x20,0x2d,0x20,0x32,0x38, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x31,0x39,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, - 0x37,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x32,0x34,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, - 0x37,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x32,0x37,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31, - 0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20, - 0x2f,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20, - 0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20, - 0x2a,0x20,0x5f,0x36,0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x39,0x29, - 0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34,0x34, - 0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d, - 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76, - 0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, - 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28, - 0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37, - 0x30,0x30,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x53,0x50, - 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, - 0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36, - 0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37, - 0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x34,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x33, - 0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c, - 0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37, - 0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34, - 0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c, - 0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37, - 0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x38,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20, - 0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x35, - 0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c, - 0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x30,0x35,0x36,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x35,0x36,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20, - 0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x37,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x5f,0x31,0x30,0x35,0x37,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39, - 0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37, - 0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x30,0x38,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65, - 0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20, - 0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x35,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d, - 0x20,0x33,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, - 0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a, - 0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31, - 0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20, - 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d, - 0x20,0x28,0x5f,0x31,0x30,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x35,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x5f,0x31,0x31,0x33,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79, - 0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x77, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, - 0x35,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x76, - 0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31, - 0x33,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20, - 0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31, - 0x35,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x36,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x35,0x37, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3e,0x20, - 0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65, - 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x31,0x36,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x31,0x37,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b, - 0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x31,0x37,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x35,0x34,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x38,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c, - 0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x37,0x36,0x2c,0x20,0x76, - 0x65,0x63,0x32,0x28,0x2d,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x33,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x38,0x32,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, - 0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72, - 0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x37,0x36,0x2c,0x20,0x76,0x65,0x63,0x32, - 0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x31,0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x33, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61, - 0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a, + 0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74, + 0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37, + 0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69, + 0x78,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39, + 0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31, + 0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31, + 0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, + 0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f, + 0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69, + 0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37, + 0x39,0x30,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a, 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65, 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65, 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x5f,0x31,0x32,0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x32,0x31,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20, - 0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31, - 0x39,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x32,0x33,0x39,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x20,0x2d, - 0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x35,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x39,0x2c, - 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, - 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, - 0x20,0x5f,0x31,0x32,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20, + 0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20, + 0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31, + 0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72, 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, 0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70, 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, - 0x5f,0x31,0x32,0x35,0x32,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35, - 0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33, - 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32, - 0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20, - 0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2f, - 0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31, - 0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31, - 0x34,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, - 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, - 0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d, - 0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, - 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f, - 0x31,0x35,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, - 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x29,0x20,0x2b, - 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, - 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, - 0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33, - 0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69, - 0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x31,0x20,0x3d,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x35,0x20,0x3d,0x20,0x5f,0x31, - 0x39,0x31,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28, - 0x28,0x5f,0x31,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x39,0x35,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x39,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, - 0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65, - 0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72, - 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, + 0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20, + 0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, + 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20, + 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x30,0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30, + 0x37,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34, + 0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69, + 0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65, + 0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f, + 0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20, + 0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, + 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, + 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63, + 0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f, + 0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d, + 0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28, + 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20, + 0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, + 0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20, + 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x31,0x39,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30, + 0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37, + 0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f, + 0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, + 0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72, + 0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, + 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, + 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76, + 0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33, + 0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b, + 0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39, + 0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33, + 0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, + 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, + 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38, + 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, + 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, + 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e, + 0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31, + 0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33, + 0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, + 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, + 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37, + 0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30, + 0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63, + 0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61, 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x32,0x35, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b, - 0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x33,0x39,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e, - 0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31, - 0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, - 0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x33,0x39,0x20,0x2a,0x20,0x5f,0x32,0x33,0x39, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f, - 0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, - 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f, - 0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, - 0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, - 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, - 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65, - 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x32,0x37,0x30,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65, - 0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, - 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x30, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62, + 0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x34,0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30,0x36, + 0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76, + 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29, 0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c, 0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38, - 0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30, - 0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x30, - 0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, - 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69, - 0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65, - 0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e, - 0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, - 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53, - 0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33, - 0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x32,0x34,0x20, - 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30, - 0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37, - 0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, - 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, - 0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e, - 0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33, - 0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e, - 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, - 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, - 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35, - 0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36, - 0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20, - 0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34, - 0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35, - 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32, - 0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76, - 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74, - 0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, - 0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, - 0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, - 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x34, - 0x31,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, - 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, - 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65, - 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x35,0x30,0x35,0x20,0x3d,0x20,0x74,0x65, - 0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37, + 0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37, + 0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f, + 0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20, + 0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33, + 0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41, + 0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74, + 0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20, + 0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62, + 0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f, + 0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39, + 0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, + 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72, 0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x33,0x31,0x2c,0x20,0x72, - 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x31,0x20,0x2b,0x20, - 0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34, - 0x31,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77, - 0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x5f,0x34,0x33,0x31,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a, - 0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29, - 0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65, - 0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34, - 0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72, - 0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f, - 0x35,0x30,0x35,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x35, - 0x30,0x35,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33, - 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69, - 0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62, - 0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74, - 0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, - 0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, - 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69, - 0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d, - 0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78, - 0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, - 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, - 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x30,0x31, + 0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x37, 0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, 0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, - 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x30, - 0x32,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f, - 0x31,0x33,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, - 0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20, - 0x2b,0x20,0x5f,0x31,0x33,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x5f,0x31,0x33,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x38,0x20, - 0x2d,0x20,0x5f,0x31,0x33,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x5f,0x31,0x33,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, - 0x20,0x5f,0x31,0x33,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x33,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x34,0x20,0x3d,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32, - 0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20,0x5f, - 0x31,0x33,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33, - 0x31,0x36,0x2c,0x20,0x5f,0x31,0x33,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x34,0x32,0x20,0x3d,0x20,0x5f,0x31, - 0x33,0x32,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x34,0x20,0x2a,0x20,0x5f, - 0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x35,0x30,0x20,0x3d,0x20,0x28,0x5f,0x31,0x33,0x32,0x30,0x20, - 0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x30,0x2c,0x20,0x5f,0x31,0x33, - 0x31,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x38,0x20,0x2a,0x20, - 0x5f,0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x36,0x32,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, - 0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x33,0x20,0x3d, - 0x20,0x28,0x5f,0x31,0x33,0x35,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x30,0x29, - 0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x34,0x32,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f, - 0x31,0x33,0x32,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33,0x33,0x36,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x31,0x33,0x32,0x38,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x38,0x29,0x29, - 0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x36,0x32,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32, - 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, - 0x31,0x33,0x39,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x32,0x20,0x2b,0x20,0x28, - 0x5f,0x31,0x33,0x31,0x32,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f, - 0x31,0x33,0x32,0x38,0x20,0x2d,0x20,0x28,0x28,0x5f,0x31,0x33,0x35,0x30,0x20,0x2f, - 0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x34,0x32,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39, + 0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x31, + 0x34,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f, + 0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39, + 0x31,0x38,0x20,0x3d,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x32,0x32,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x32, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x34,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f, + 0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20,0x28,0x5f, + 0x39,0x33,0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20,0x28,0x5f, + 0x39,0x32,0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36,0x2c,0x20, + 0x5f,0x39,0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28, + 0x5f,0x39,0x35,0x36,0x20,0x2a,0x20,0x5f,0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28, + 0x5f,0x39,0x34,0x38,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a, + 0x20,0x5f,0x39,0x34,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20, + 0x2a,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39, 0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30, 0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30, - 0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29,0x29,0x20,0x2f,0x20, - 0x5f,0x31,0x33,0x32,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x39, - 0x38,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61, - 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x39,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x30, - 0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x39,0x38,0x2c,0x20,0x5f, - 0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x34,0x31,0x36,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61, - 0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x39,0x38, - 0x2c,0x20,0x5f,0x31,0x33,0x39,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x34,0x30, - 0x32,0x20,0x2a,0x20,0x5f,0x31,0x34,0x30,0x32,0x29,0x29,0x29,0x20,0x2d,0x20,0x76, - 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74, - 0x68,0x28,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, - 0x5f,0x31,0x34,0x31,0x39,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31, - 0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x38,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, - 0x70,0x28,0x2d,0x5f,0x31,0x34,0x32,0x31,0x2c,0x20,0x5f,0x31,0x34,0x32,0x31,0x2c, - 0x20,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x28,0x5f,0x31,0x33,0x37,0x33,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, - 0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x33,0x34,0x32,0x20,0x3e,0x20,0x39,0x2e, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32, - 0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65, - 0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x36,0x20, - 0x3d,0x20,0x28,0x28,0x2d,0x5f,0x31,0x33,0x35,0x30,0x29,0x20,0x2d,0x20,0x73,0x71, - 0x72,0x74,0x28,0x5f,0x31,0x33,0x37,0x33,0x29,0x29,0x20,0x2f,0x20,0x5f,0x31,0x33, - 0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x35,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x38,0x20, - 0x2b,0x20,0x28,0x5f,0x31,0x34,0x34,0x36,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, - 0x28,0x5f,0x31,0x34,0x34,0x36,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26, - 0x20,0x28,0x5f,0x31,0x34,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20, - 0x26,0x26,0x20,0x28,0x5f,0x31,0x34,0x35,0x32,0x20,0x3c,0x20,0x5f,0x31,0x33,0x32, - 0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x20,0x3d,0x20,0x28,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65, - 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31, - 0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x36,0x29,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x31,0x33,0x30,0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x32,0x20, - 0x2a,0x20,0x28,0x5f,0x31,0x34,0x35,0x32,0x20,0x2f,0x20,0x5f,0x31,0x33,0x32,0x30, - 0x29,0x29,0x29,0x29,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61, - 0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x32,0x20,0x3d,0x20, - 0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x36,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, - 0x30,0x36,0x20,0x3d,0x20,0x28,0x5f,0x31,0x34,0x39,0x32,0x20,0x2a,0x20,0x5f,0x31, - 0x34,0x39,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x33,0x36,0x20,0x2d,0x20, - 0x5f,0x31,0x33,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x35,0x30,0x36,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x34,0x39, - 0x32,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x35,0x30,0x36,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x35,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3e,0x20,0x30, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x35,0x32,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x31,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x5f,0x31,0x35,0x32,0x37,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e, - 0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x35,0x31,0x36,0x20,0x3c,0x20,0x74, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x35,0x32,0x37,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x38,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x32,0x37,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x33,0x38,0x20,0x3d,0x20,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20, - 0x5f,0x31,0x35,0x31,0x36,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x33,0x38,0x2c,0x20,0x76,0x5f,0x61,0x78, - 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30, - 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x35,0x33, - 0x38,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, - 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2f,0x20,0x5f, + 0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x30,0x34,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x30,0x38,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x38,0x39,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30, + 0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e, + 0x30,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x31, + 0x30,0x30,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x38,0x20,0x2a,0x20, + 0x5f,0x31,0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x30,0x32, + 0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35, + 0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35, + 0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f, + 0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74, + 0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x5f,0x39,0x37,0x39,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20, + 0x28,0x5f,0x39,0x34,0x38,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35, + 0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f, + 0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d, + 0x20,0x5f,0x39,0x33,0x34,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a, + 0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e, + 0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c, + 0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20, + 0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20, + 0x2d,0x20,0x28,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20, + 0x2a,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29, + 0x29,0x29,0x29,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f, - 0x74,0x28,0x5f,0x31,0x35,0x35,0x34,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x32, - 0x20,0x3d,0x20,0x28,0x5f,0x31,0x35,0x35,0x38,0x20,0x2a,0x20,0x5f,0x31,0x35,0x35, - 0x38,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x35,0x34,0x2c, - 0x20,0x5f,0x31,0x35,0x35,0x34,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x32,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x37,0x32,0x20, - 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38, - 0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x35,0x38,0x29,0x20,0x2d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x5f,0x31,0x35,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x38,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x35,0x38,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x35,0x38,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x33, - 0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20, - 0x28,0x5f,0x31,0x35,0x38,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, - 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x35,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x35,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x31,0x36,0x30,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20, + 0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32, + 0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, + 0x32,0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e, 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b, - 0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x32,0x29, - 0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, - 0x31,0x36,0x30,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x36,0x30,0x34,0x20,0x2f,0x20,0x76,0x65, - 0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20, - 0x3d,0x20,0x5f,0x31,0x35,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74, - 0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x32, - 0x32,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x34,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d, - 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, - 0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32, - 0x32,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x39,0x34,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x34, - 0x32,0x38,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74, - 0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, - 0x31,0x36,0x34,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d, - 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, - 0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x34,0x20,0x3d,0x20,0x28,0x28,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f, - 0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x37,0x30,0x31,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31, - 0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a, - 0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x3d,0x20, - 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a, - 0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x38,0x34,0x20,0x3e,0x20,0x30,0x2e,0x30, - 0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39, - 0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34, - 0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x37,0x31,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f, - 0x31,0x36,0x38,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x37,0x33,0x30,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28, - 0x5f,0x31,0x37,0x30,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x31,0x37,0x35,0x30,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x37, - 0x31,0x35,0x2c,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, - 0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32, - 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x61, - 0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, - 0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x37,0x31,0x39,0x20,0x2a,0x20, - 0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x36,0x38,0x34,0x29,0x29, - 0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, - 0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x37,0x33,0x30,0x20,0x2a,0x20, - 0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x37,0x30,0x31,0x29,0x29, - 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, - 0x37,0x35,0x38,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x36,0x34,0x36, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, - 0x20,0x5f,0x31,0x37,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76, - 0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, - 0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x39,0x2e,0x7a,0x20,0x2f,0x20,0x5f, - 0x31,0x37,0x35,0x39,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, - 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x39,0x31,0x20,0x3d,0x20, - 0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65, - 0x77,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28, - 0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39, - 0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x37,0x39,0x31,0x2c,0x20,0x5f,0x31,0x37, - 0x39,0x31,0x2c,0x20,0x5f,0x31,0x37,0x39,0x31,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f, - 0x31,0x37,0x35,0x38,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x38,0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c, - 0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, - 0x31,0x38,0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31, - 0x38,0x31,0x39,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x38,0x33,0x36, - 0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76, - 0x65,0x63,0x33,0x28,0x5f,0x31,0x38,0x32,0x39,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x38,0x35,0x33, - 0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x38,0x33,0x36,0x2e,0x78, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28, - 0x28,0x5f,0x31,0x38,0x33,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, - 0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, - 0x5f,0x31,0x38,0x33,0x36,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x35,0x38,0x20,0x3d,0x20,0x61, - 0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x38,0x35, - 0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38, - 0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32,0x29,0x29, + 0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31, + 0x34,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f,0x20,0x76,0x65,0x63,0x33, + 0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x31,0x36,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36, + 0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f, + 0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x37,0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x39,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x31,0x37,0x38,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x36,0x34,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31, + 0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x31,0x31,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x31,0x38,0x38,0x20,0x3c,0x20,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x38,0x36,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65, - 0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x38,0x35,0x33,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x36,0x35,0x20,0x3d,0x20,0x5f, - 0x31,0x38,0x35,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x74,0x69,0x6e, - 0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x38,0x36, - 0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x39,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d, - 0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69, - 0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x31,0x39,0x39,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x3d,0x20,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x38, + 0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28, + 0x5f,0x31,0x32,0x31,0x30,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x2f,0x20,0x76, + 0x65,0x63,0x33,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x32,0x32,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x38, + 0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x32,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72, + 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39, + 0x36,0x20,0x2a,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x30, + 0x37,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, + 0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20, + 0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f, + 0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39, + 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31, + 0x33,0x35,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x33,0x32,0x31,0x2c, + 0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39, + 0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30, + 0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x30,0x37,0x29,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x33,0x36,0x34, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x33,0x36,0x35, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x34,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, - 0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31, + 0x33,0x39,0x37,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31, + 0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x34,0x34,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x34, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x34,0x34,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x36, + 0x36,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37, + 0x30,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x31,0x34,0x36,0x36,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x34,0x37,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x34,0x36,0x36, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37, + 0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78, + 0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x35, + 0x34,0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28, + 0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c, + 0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20,0x5f,0x31, + 0x35,0x34,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f, + 0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76, - 0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a, - 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35, - 0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x39,0x32,0x34,0x20,0x3d,0x20, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61, - 0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32, - 0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78, - 0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x39,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x32,0x34,0x2e,0x78, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x39, - 0x32,0x35,0x2c,0x20,0x5f,0x31,0x39,0x32,0x35,0x2c,0x20,0x5f,0x31,0x39,0x32,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x36,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38,0x29,0x2e,0x7a,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x39,0x37,0x33,0x20, - 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, - 0x20,0x2d,0x20,0x5f,0x31,0x36,0x34,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6e,0x5f, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x39,0x36, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6e,0x5f, 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x33,0x3b, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, - 0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20, - 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, - 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b, + 0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73, + 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, - 0x3d,0x20,0x5f,0x31,0x39,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x37, - 0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73, - 0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68, - 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b, - 0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x34, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, - 0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x35,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x36, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x32,0x30,0x35,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x38, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76, - 0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, - 0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, - 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x39,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x32,0x30,0x35,0x33,0x2c, - 0x20,0x5f,0x32,0x30,0x35,0x33,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, + 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73, + 0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x38,0x29, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f,0x31,0x36,0x37,0x35, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* struct instance @@ -2382,19 +1996,16 @@ static const uint8_t capsule_vs_source_hlsl5[3455] = { /* cbuffer ub_pass : register(b1) { - float4 _1071_sun_dir_world : packoffset(c0); - float4 _1071_sun_color : packoffset(c1); - int4 _1071_flags : packoffset(c2); - float4 _1071_camera_pos : packoffset(c3); - row_major float4x4 _1071_view_proj : packoffset(c4); - row_major float4x4 _1071_view : packoffset(c8); - float4 _1071_cascade_far_view_z : packoffset(c12); - float4 _1071_cascade_texel_world : packoffset(c13); - float4 _1071_cascade_depth_bias : packoffset(c14); - float4 _1071_shadow_params : packoffset(c15); - row_major float4x4 _1071_cascade_matrices[4] : packoffset(c16); - float4 _1071_sh[9] : packoffset(c32); - float4 _1071_ibl_params : packoffset(c41); + float4 _707_sun_dir_world : packoffset(c0); + float4 _707_sun_color : packoffset(c1); + int4 _707_flags : packoffset(c2); + float4 _707_camera_pos : packoffset(c3); + row_major float4x4 _707_view_proj : packoffset(c4); + row_major float4x4 _707_view : packoffset(c8); + float4 _707_cascade_far_view_z : packoffset(c12); + row_major float4x4 _707_cascade_matrices[3] : packoffset(c13); + float4 _707_sh[9] : packoffset(c25); + float4 _707_ibl_params : packoffset(c34); }; Texture2DArray tex_shadow : register(t0); @@ -2448,220 +2059,94 @@ static const uint8_t capsule_vs_source_hlsl5[3455] = { return ret; } - int selectShadowCascade(float4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, float3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - float3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); - } - return float3(1.0f, 0.89999997615814208984375f, 0.300000011920928955078125f); - } - - float sampleShadowTap(Texture2DArray tex, SamplerComparisonState smp, float2 uv, float layer, float ref_z) - { - return tex.SampleCmp(smp, float4(uv, layer, ref_z).xyz, ref_z); - } - - float sampleShadowPCF(Texture2DArray tex, SamplerComparisonState smp, int cascade, float3 light_uv, float bias, float scale, float inv_size) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias; - float2 _625 = light_uv.xy * (1.0f / inv_size); - float2 _630 = floor(_625 + 0.5f.xx); - float _637 = (_625.x + 0.5f) - _630.x; - float _644 = (_625.y + 0.5f) - _630.y; - float2 _649 = (_630 - 0.5f.xx) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0f * _637; - float _658 = _656 - 6.0f; - float _662 = 11.0f * _637; - float _664 = _662 - 28.0f; - float _670 = (-17.0f) - _662; - float _675 = (-1.0f) - _656; - float _679 = 4.0f * _637; - float _683 = ((_679 - 5.0f) / _658) - 3.0f; - float _691 = ((_679 - 16.0f) / _664) - 1.0f; - float _700 = (((-5.0f) - (7.0f * _637)) / _670) + 1.0f; - float _706 = ((-_637) / _675) + 3.0f; - float _709 = 5.0f * _644; - float _710 = _709 - 6.0f; - float _713 = 11.0f * _644; - float _714 = _713 - 28.0f; - float _719 = (-17.0f) - _713; - float _724 = (-1.0f) - _709; - float _727 = 4.0f * _644; - float _731 = ((_727 - 5.0f) / _710) - 3.0f; - float _738 = ((_727 - 16.0f) / _714) - 1.0f; - float _746 = (((-5.0f) - (7.0f * _644)) / _719) + 1.0f; - float _752 = ((-_644) / _724) + 3.0f; - float sum = 0.0f; - float2 param = _649 + (float2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _649 + (float2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _649 + (float2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _649 + (float2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _649 + (float2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _649 + (float2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _649 + (float2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _649 + (float2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _649 + (float2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _649 + (float2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _649 + (float2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _649 + (float2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _649 + (float2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _649 + (float2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _649 + (float2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _649 + (float2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875f; + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125f; + float _554 = light_uv.y - 0.00048828125f; + float _584 = light_uv.x + 0.00048828125f; + float _652 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_550, _554, _529, _534).xyz, _534) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _652, _529, _534).xyz, _534)) * 0.111111111938953399658203125f; } float sampleCascade(int cascade, float3 world_pos, float3 world_normal) { - float _1086 = clamp(_1071_cascade_texel_world.x / _1071_cascade_texel_world[cascade], 0.25f, 1.0f); - float _1095 = max(dot(world_normal, normalize(_1071_sun_dir_world.xyz)), 0.0f); - float _1105 = 3.0f * _1086; - float4 _1128 = mul(float4(world_pos + (world_normal * ((((_1105 + 0.5f) * 1.41420996189117431640625f) * sqrt(max(1.0f - (_1095 * _1095), 0.0f))) * _1071_cascade_texel_world[cascade])), 1.0f), _1071_cascade_matrices[cascade]); - float3 _1136 = _1128.xyz / _1128.w.xxx; - float _1153 = _1136.z; - float3 _1154 = float3((_1136.x * 0.5f) + 0.5f, ((_1136.y * _1071_shadow_params.x) * 0.5f) + 0.5f, _1153); - bool _1157 = _1153 < 0.0f; - bool _1164; - if (!_1157) + float4 _717 = mul(float4(world_pos, 1.0f), _707_cascade_matrices[cascade]); + float3 _724 = _717.xyz / _717.w.xxx; + float3 _742 = float3((_724.x * 0.5f) + 0.5f, ((_724.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _724.z); + bool _746 = any(bool3(_742.x < 0.0f.xxx.x, _742.y < 0.0f.xxx.y, _742.z < 0.0f.xxx.z)); + bool _753; + if (!_746) { - _1164 = _1153 > 1.0f; + _753 = any(bool3(_742.x > 1.0f.xxx.x, _742.y > 1.0f.xxx.y, _742.z > 1.0f.xxx.z)); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0f; - } - float _1174 = (_1105 + 1.0f) * _1071_shadow_params.y; - float2 _1176 = _1154.xy; - float2 _1179 = (-_1174).xx; - bool _1182 = any(bool2(_1176.x < _1179.x, _1176.y < _1179.y)); - bool _1193; - if (!_1182) - { - float2 _1190 = (1.0f + _1174).xx; - _1193 = any(bool2(_1176.x > _1190.x, _1176.y > _1190.y)); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0f; } int param = cascade; - float3 param_1 = _1154; - float param_2 = _1071_cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071_shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _742; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_707_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = min(_785, 1.0f.xx - _785); + pcf = lerp(1.0f, pcf, clamp(min(_790.x, _790.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; } float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) { - float4 param = _1071_cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707_cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707_cascade_far_view_z.y) { - _1239 = 0.0f; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707_cascade_far_view_z.x; } else { - _1239 = _1071_cascade_far_view_z[_1219 - 1]; + _835 = _707_cascade_far_view_z.y; } - float _1252 = lerp(_1071_cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625f); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = lerp(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1252) / (_1071_cascade_far_view_z[_1219] - _1252)); + _847 = 0.0f; + } + else + { + _847 = _707_cascade_far_view_z.x; + } + float _858 = lerp(_835, _847, 0.100000001490116119384765625f); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -2669,56 +2154,56 @@ static const uint8_t capsule_vs_source_hlsl5[3455] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0f)) + 1.0f; - return _133 / ((3.1415927410125732421875f * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0f)) + 1.0f; + return _107 / ((3.1415927410125732421875f * _116) * _116); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _155 = alpha * alpha; - float _162 = 1.0f - _155; - return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06f); + float _129 = alpha * alpha; + float _136 = 1.0f - _129; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06f); } float3 pbrFresnelSchlick(float v_dot_h, float3 f0) { - float _191 = 1.0f - v_dot_h; - float _195 = _191 * _191; - return f0 + ((1.0f.xxx - f0) * ((_195 * _195) * _191)); + float _165 = 1.0f - v_dot_h; + float _169 = _165 * _165; + return f0 + ((1.0f.xxx - f0) * ((_169 * _169) * _165)); } float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) { - float _214 = max(dot(N, L), 0.0f); - float3 _225 = normalize(V + L); - float _239 = max(roughness, 0.04500000178813934326171875f); - float _243 = _239 * _239; - float param = max(dot(N, _225), 0.0f); - float param_1 = _243; + float _188 = max(dot(N, L), 0.0f); + float3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875f); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0f); + float param_1 = _217; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); - float param_3 = _214; - float param_4 = _243; - float param_5 = max(dot(V, _225), 0.0f); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0f); float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); - float3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((1.0f.xxx - _270) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _244) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) { - float3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); - return _424; + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _399; } float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) { - float _431 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); - float3 _441 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _416 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); float3 param = N_world; float4 param_1[9] = sh; - float4 _505 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_431, roughness)); - return (((((1.0f.xxx - (_441 + ((max((1.0f - roughness).xxx, _441) - _441) * pow(max(0.0f, 1.0f - _431), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_441 * _505.x) + _505.y.xxx)); + float4 _482 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_406, roughness)); + return (((((1.0f.xxx - (_416 + ((max((1.0f - roughness).xxx, _416) - _416) * pow(max(0.0f, 1.0f - _406), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + _482.y.xxx)); } float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) @@ -2740,187 +2225,210 @@ static const uint8_t capsule_vs_source_hlsl5[3455] = { void frag_main() { - float3 _1290 = normalize(v_world_pos_proxy - _1071_camera_pos.xyz); - float3 _1301 = v_axis_x_world * v_half_length; - float3 _1302 = v_center - _1301; - float3 _1308 = v_center + _1301; - float3 _1312 = _1308 - _1302; - float3 _1316 = _1071_camera_pos.xyz - _1302; - float _1320 = dot(_1312, _1312); - float _1324 = dot(_1312, _1290); - float _1328 = dot(_1312, _1316); - float _1336 = dot(_1316, _1316); - float _1342 = _1320 - (_1324 * _1324); - float _1350 = (_1320 * dot(_1290, _1316)) - (_1328 * _1324); - float _1362 = v_radius * v_radius; - float _1373 = (_1350 * _1350) - (_1342 * (((_1320 * _1336) - (_1328 * _1328)) - (_1362 * _1320))); - float3 _1394 = _1302 + (_1312 * clamp((_1328 - ((_1350 / max(_1342, 9.9999999392252902907785028219223e-09f)) * _1324)) / _1320, 0.0f, 1.0f)); - float3 _1398 = _1071_camera_pos.xyz - _1394; - float _1402 = dot(_1398, _1290); - float _1416 = sqrt(max(0.0f, dot(_1398, _1398) - (_1402 * _1402))) - v_radius; - float _1419 = fwidth(_1416); - float _1421 = max(_1419, 9.9999999747524270787835121154785e-07f); - float _1428 = 1.0f - smoothstep(-_1421, _1421, _1416); + float3 _896 = normalize(v_world_pos_proxy - _707_camera_pos.xyz); + float3 _907 = v_axis_x_world * v_half_length; + float3 _908 = v_center - _907; + float3 _914 = v_center + _907; + float3 _918 = _914 - _908; + float3 _922 = _707_camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = v_radius * v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + float3 _1000 = _908 + (_918 * clamp((_934 - ((_956 / max(_948, 9.9999999392252902907785028219223e-09f)) * _930)) / _926, 0.0f, 1.0f)); + float3 _1004 = _707_camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(max(0.0f, dot(_1004, _1004) - (_1008 * _1008))) - v_radius; + float _1025 = fwidth(_1022); + float _1027 = max(_1025, 9.9999999747524270787835121154785e-07f); + float _1034 = 1.0f - smoothstep(-_1027, _1027, _1022); float t = -1.0f; float3 n_world = 0.0f.xxx; - if ((_1373 >= 0.0f) && (_1342 > 9.9999999392252902907785028219223e-09f)) + if ((_979 >= 0.0f) && (_948 > 9.9999999392252902907785028219223e-09f)) { - float _1446 = ((-_1350) - sqrt(_1373)) / _1342; - float _1452 = _1328 + (_1446 * _1324); - if (((_1446 > 0.0f) && (_1452 > 0.0f)) && (_1452 < _1320)) + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0f) && (_1058 > 0.0f)) && (_1058 < _926)) { - n_world = ((_1071_camera_pos.xyz + (_1290 * _1446)) - (_1302 + (_1312 * (_1452 / _1320)))) / v_radius.xxx; - t = _1446; + n_world = ((_707_camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / v_radius.xxx; + t = _1052; } } - float _1492 = dot(_1316, _1290); - float _1506 = (_1492 * _1492) - (_1336 - _1362); - if (_1506 >= 0.0f) + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0f) { - float _1516 = (-_1492) - sqrt(_1506); - bool _1518 = _1516 > 0.0f; - bool _1527; - if (_1518) + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0f; + bool _1133; + if (_1124) { - _1527 = (t < 0.0f) || (_1516 < t); + _1133 = (t < 0.0f) || (_1122 < t); } else { - _1527 = _1518; + _1133 = _1124; } - if (_1527) + if (_1133) { - float3 _1538 = (_1071_camera_pos.xyz + (_1290 * _1516)) - _1302; - if (dot(_1538, v_axis_x_world) <= 0.0f) + float3 _1144 = (_707_camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, v_axis_x_world) <= 0.0f) { - n_world = _1538 / v_radius.xxx; - t = _1516; + n_world = _1144 / v_radius.xxx; + t = _1122; } } } - float3 _1554 = _1071_camera_pos.xyz - _1308; - float _1558 = dot(_1554, _1290); - float _1572 = (_1558 * _1558) - (dot(_1554, _1554) - _1362); - if (_1572 >= 0.0f) + float3 _1160 = _707_camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0f) { - float _1582 = (-_1558) - sqrt(_1572); - bool _1584 = _1582 > 0.0f; - bool _1593; - if (_1584) + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0f; + bool _1199; + if (_1190) { - _1593 = (t < 0.0f) || (_1582 < t); + _1199 = (t < 0.0f) || (_1188 < t); } else { - _1593 = _1584; + _1199 = _1190; } - if (_1593) + if (_1199) { - float3 _1604 = (_1071_camera_pos.xyz + (_1290 * _1582)) - _1308; - if (dot(_1604, v_axis_x_world) >= 0.0f) + float3 _1210 = (_707_camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, v_axis_x_world) >= 0.0f) { - n_world = _1604 / v_radius.xxx; - t = _1582; + n_world = _1210 / v_radius.xxx; + t = _1188; } } } if (t < 0.0f) { - float _1622 = -_1402; - t = _1622; - n_world = normalize((_1071_camera_pos.xyz + (_1290 * _1622)) - _1394); + float _1228 = -_1008; + t = _1228; + n_world = normalize((_707_camera_pos.xyz + (_896 * _1228)) - _1000); } - if ((_1428 <= 0.0f) || (t < 0.0f)) + if ((_1034 <= 0.0f) || (t < 0.0f)) { discard; } - float3 _1646 = _1071_camera_pos.xyz + (_1290 * t); - float _1684 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); - float _1701 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); - float3 _1715 = v_base_color.xyz * ((_1684 > 0.0f) ? 1.0f : 0.64999997615814208984375f); - float _1719 = fwidth(_1684); - float _1730 = fwidth(_1701); - float3 _1750 = lerp(_1715, _1715 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, _1719 * 1.5f, abs(_1684)), 1.0f - smoothstep(0.0f, _1730 * 1.5f, abs(_1701))).xxx); - float4 _1758 = float4(_1646, 1.0f); - float4 _1759 = mul(_1758, _1071_view_proj); - gl_FragDepth = _1759.z / _1759.w; - if (_1071_flags.x == 1) + float3 _1252 = _707_camera_pos.xyz + (_896 * t); + float _1290 = ((v_rot_row0.y * n_world.x) + (v_rot_row1.y * n_world.y)) + (v_rot_row2.y * n_world.z); + float _1307 = ((v_rot_row0.z * n_world.x) + (v_rot_row1.z * n_world.y)) + (v_rot_row2.z * n_world.z); + float3 _1321 = v_base_color.xyz * ((_1290 > 0.0f) ? 1.0f : 0.64999997615814208984375f); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + float3 _1356 = lerp(_1321, _1321 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, _1325 * 1.5f, abs(_1290)), 1.0f - smoothstep(0.0f, _1336 * 1.5f, abs(_1307))).xxx); + float4 _1364 = float4(_1252, 1.0f); + float4 _1365 = mul(_1364, _707_view_proj); + gl_FragDepth = _1365.z / _1365.w; + if (_707_flags.x == 1) { - float _1791 = clamp(mul(_1758, _1071_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); - out_color = float4(_1791, _1791, _1791, 1.0f); + float _1397 = clamp(mul(_1364, _707_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1397, _1397, _1397, 1.0f); return; } - if (_1071_flags.x == 2) + if (_707_flags.x == 2) { - float4 param = _1071_cascade_far_view_z; - float param_1 = -mul(_1758, _1071_view).z; - int _1819 = selectShadowCascade(param, param_1); - float4 _1829 = mul(_1758, _1071_cascade_matrices[_1819]); - float3 _1836 = _1829.xyz / _1829.w.xxx; - float3 _1853 = float3((_1836.x * 0.5f) + 0.5f, ((_1836.y * _1071_shadow_params.x) * 0.5f) + 0.5f, _1836.z); - bool _1858 = any(bool3(_1853.x < 0.0f.xxx.x, _1853.y < 0.0f.xxx.y, _1853.z < 0.0f.xxx.z)); - bool _1865; - if (!_1858) + float _1418 = -mul(_1364, _707_view).z; + int cascade = 2; + if (_1418 < _707_cascade_far_view_z.x) { - _1865 = any(bool3(_1853.x > 1.0f.xxx.x, _1853.y > 1.0f.xxx.y, _1853.z > 1.0f.xxx.z)); + cascade = 0; } else { - _1865 = _1858; + if (_1418 < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1442 = mul(_1364, _707_cascade_matrices[cascade]); + float3 _1449 = _1442.xyz / _1442.w.xxx; + float3 _1466 = float3((_1449.x * 0.5f) + 0.5f, ((_1449.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _1449.z); + bool _1470 = any(bool3(_1466.x < 0.0f.xxx.x, _1466.y < 0.0f.xxx.y, _1466.z < 0.0f.xxx.z)); + bool _1477; + if (!_1470) + { + _1477 = any(bool3(_1466.x > 1.0f.xxx.x, _1466.y > 1.0f.xxx.y, _1466.z > 1.0f.xxx.z)); + } + else + { + _1477 = _1470; } float3 tint = 1.0f.xxx; - if (!_1865) + if (!_1477) { - int param_2 = _1819; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } } out_color = float4(tint, 1.0f); return; } - if (_1071_flags.x == 3) + if (_707_flags.x == 3) { - out_color = float4((normalize(mul(float4(n_world, 0.0f), _1071_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + out_color = float4((normalize(mul(float4(n_world, 0.0f), _707_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); return; } - uint _1916_dummy_parameter; - float4 _1924 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1916_dummy_parameter))), 0.0f); - float _1925 = _1924.x; - if (_1071_flags.x == 4) + uint _1539_dummy_parameter; + float4 _1547 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1539_dummy_parameter))), 0.0f); + float _1548 = _1547.x; + if (_707_flags.x == 4) { - out_color = float4(_1925, _1925, _1925, 1.0f); + out_color = float4(_1548, _1548, _1548, 1.0f); return; } - float3 param_3 = _1646; - float3 param_4 = n_world; - float param_5 = -mul(_1758, _1071_view).z; - float3 _1973 = normalize(_1071_camera_pos.xyz - _1646); - float3 param_6 = n_world; - float3 param_7 = _1973; - float3 param_8 = normalize(_1071_sun_dir_world.xyz); - float3 param_9 = _1071_sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); - float3 param_10 = _1750; - float param_11 = v_material.x; - float param_12 = v_material.y; - bool param_13 = _1071_ibl_params.y > 0.5f; - float3 param_14 = n_world; - float3 param_15 = _1973; - float3 param_16 = _1750; - float param_17 = v_material.x; - float param_18 = v_material.y; - float param_19 = _1071_sun_color.w; - float4 param_20[9]; - param_20[0] = _1071_sh[0]; - param_20[1] = _1071_sh[1]; - param_20[2] = _1071_sh[2]; - param_20[3] = _1071_sh[3]; - param_20[4] = _1071_sh[4]; - param_20[5] = _1071_sh[5]; - param_20[6] = _1071_sh[6]; - param_20[7] = _1071_sh[7]; - param_20[8] = _1071_sh[8]; - float param_21 = _1071_ibl_params.x; - float _2053 = v_base_color.w * _1428; - out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1925)) * _2053, _2053); + float3 param = _1252; + float3 param_1 = n_world; + float param_2 = -mul(_1364, _707_view).z; + float3 _1596 = normalize(_707_camera_pos.xyz - _1252); + float3 param_3 = n_world; + float3 param_4 = _1596; + float3 param_5 = normalize(_707_sun_dir_world.xyz); + float3 param_6 = _707_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = _1356; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707_ibl_params.y > 0.5f; + float3 param_11 = n_world; + float3 param_12 = _1596; + float3 param_13 = _1356; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707_sun_color.w; + float4 param_17[9]; + param_17[0] = _707_sh[0]; + param_17[1] = _707_sh[1]; + param_17[2] = _707_sh[2]; + param_17[3] = _707_sh[3]; + param_17[4] = _707_sh[4]; + param_17[5] = _707_sh[5]; + param_17[6] = _707_sh[6]; + param_17[7] = _707_sh[7]; + param_17[8] = _707_sh[8]; + float param_18 = _707_ibl_params.x; + float _1675 = v_base_color.w * _1034; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1548)) * _1675, _1675); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) @@ -2944,1393 +2452,1118 @@ static const uint8_t capsule_vs_source_hlsl5[3455] = { return stage_output; } */ -static const uint8_t capsule_fs_source_hlsl5[22171] = { +static const uint8_t capsule_fs_source_hlsl5[17765] = { 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, - 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c, - 0x61,0x67,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, - 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, - 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a, - 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62, - 0x69,0x61,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, - 0x65,0x74,0x28,0x63,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, - 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68, - 0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x33,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, - 0x63,0x34,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72, - 0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65, - 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61, - 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20, - 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, - 0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, - 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67, - 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, - 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65, - 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, - 0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, - 0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, - 0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, - 0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a, - 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b,0x0a,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c, - 0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, - 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x31,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, - 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73, - 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, - 0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, - 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, - 0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, - 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, - 0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3a,0x20,0x54, - 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73, + 0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, + 0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20,0x54, - 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, - 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, - 0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, - 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, - 0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74, - 0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3a,0x20,0x54, - 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, - 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x38,0x3b,0x0a,0x20, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, - 0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x39, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f, - 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, - 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20, - 0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, - 0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d, - 0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74, - 0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, - 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75, - 0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75, - 0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e, - 0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20, - 0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69, - 0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e, - 0x74,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, + 0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, + 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, + 0x44,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, + 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a, + 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70, + 0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54, + 0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20, + 0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65, + 0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65, + 0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61, + 0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72, + 0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38, + 0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x35,0x35,0x30,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35, + 0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33, + 0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x6d,0x75, + 0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73, + 0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37, + 0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x37,0x31,0x37,0x2e,0x77,0x2e, + 0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x34, + 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37, + 0x34,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f, + 0x37,0x34,0x32,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x78,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34, + 0x32,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78, + 0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3e,0x20, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x30,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32, + 0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33, + 0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33, + 0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, + 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, - 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, - 0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, - 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, - 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, - 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, - 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, - 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, - 0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39, - 0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34, - 0x33,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31, - 0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35, - 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x54,0x65,0x78, - 0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x2e,0x53,0x61,0x6d,0x70,0x6c, - 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66,0x5f, - 0x7a,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65, - 0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, - 0x74,0x65,0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70, - 0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e, - 0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x31,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, - 0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x32,0x35,0x20,0x3d, - 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28, - 0x31,0x2e,0x30,0x66,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33, - 0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32,0x35,0x20,0x2b, - 0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x37,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32, - 0x35,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36, - 0x33,0x30,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x36,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x79,0x20,0x2b, - 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x79,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x34,0x39, - 0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x30,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e, - 0x78,0x78,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x33,0x20,0x3d, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c, - 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35, - 0x36,0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x38,0x20, - 0x3d,0x20,0x5f,0x36,0x35,0x36,0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x32,0x20,0x3d,0x20, - 0x31,0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x34,0x20,0x3d,0x20,0x5f, - 0x36,0x36,0x32,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20,0x3d,0x20,0x28,0x2d, - 0x31,0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x35,0x20,0x3d,0x20, - 0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x39,0x20,0x3d, - 0x20,0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20, - 0x5f,0x36,0x35,0x38,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29,0x20,0x2f, - 0x20,0x5f,0x36,0x36,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20, - 0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30, - 0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37, - 0x30,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f, - 0x36,0x33,0x37,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x35,0x29,0x20,0x2b,0x20,0x33, - 0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x30,0x39,0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31, - 0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x39,0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x33,0x20, - 0x3d,0x20,0x31,0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x34,0x20,0x3d, - 0x20,0x5f,0x37,0x31,0x33,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x39,0x20,0x3d,0x20, - 0x28,0x2d,0x31,0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x34,0x20, - 0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x30,0x39, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x37, - 0x20,0x3d,0x20,0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31,0x20,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20, - 0x2f,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20, - 0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37, - 0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f, - 0x37,0x31,0x39,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x28,0x28, - 0x2d,0x5f,0x36,0x34,0x34,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2b, - 0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, - 0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39, - 0x31,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30, - 0x30,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30, - 0x36,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37, - 0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x30,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35, - 0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20, - 0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x35,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34,0x36, - 0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78, - 0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36, - 0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a, - 0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37, - 0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x30,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32, - 0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x35,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x3d, - 0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x30,0x35,0x37,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x2b,0x20, - 0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x2a,0x20,0x30, - 0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39, - 0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38, - 0x37,0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38, - 0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35, - 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, - 0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20, - 0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d, - 0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x31,0x30, - 0x35,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31, - 0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36, - 0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x6d, - 0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x39,0x35, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29, - 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x31,0x33,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79,0x7a, - 0x20,0x2f,0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x33,0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20, - 0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28, - 0x5f,0x31,0x31,0x33,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c, - 0x20,0x5f,0x31,0x31,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, - 0x6c,0x20,0x5f,0x31,0x31,0x35,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20, - 0x3c,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x31,0x35,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x35,0x33,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x36,0x34,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x37,0x34,0x20,0x3d,0x20, - 0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x5f,0x31,0x31,0x37,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x34, - 0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x5f,0x31,0x31,0x37,0x39,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x37,0x34,0x29, - 0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, - 0x31,0x38,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28, - 0x5f,0x31,0x31,0x37,0x36,0x2e,0x78,0x20,0x3c,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e, - 0x78,0x2c,0x20,0x5f,0x31,0x31,0x37,0x36,0x2e,0x79,0x20,0x3c,0x20,0x5f,0x31,0x31, - 0x37,0x39,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x31,0x38,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31, - 0x39,0x30,0x20,0x3d,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x5f,0x31,0x31, - 0x37,0x34,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x31,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c, - 0x32,0x28,0x5f,0x31,0x31,0x37,0x36,0x2e,0x78,0x20,0x3e,0x20,0x5f,0x31,0x31,0x39, - 0x30,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x31,0x37,0x36,0x2e,0x79,0x20,0x3e,0x20,0x5f, - 0x31,0x31,0x39,0x30,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x34,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x6e,0x74,0x20,0x5f,0x31,0x32,0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63, - 0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, - 0x3d,0x20,0x5f,0x31,0x32,0x31,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x5f,0x31,0x32,0x31,0x39,0x20,0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x32,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20,0x30,0x2e,0x30, - 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x38,0x35, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30,0x20, + 0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x31,0x2e,0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39, + 0x30,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x5b,0x5f,0x31,0x32,0x31,0x39,0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d,0x20,0x6c,0x65,0x72, - 0x70,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39, - 0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x39,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30, - 0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38, - 0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20, - 0x5f,0x31,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x39, - 0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65, - 0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f, - 0x31,0x32,0x35,0x32,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, - 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20, - 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x20, - 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2d, - 0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20, - 0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30, - 0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20, - 0x5f,0x31,0x34,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, - 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, - 0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35, - 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x32, - 0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66,0x20, - 0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73, - 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29, - 0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29, - 0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, - 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, - 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, - 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x39,0x31,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f, - 0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x39,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x31,0x20,0x2a,0x20,0x5f, - 0x31,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20, - 0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x39,0x35,0x20,0x2a, - 0x20,0x5f,0x31,0x39,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x29,0x29,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f, - 0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75, - 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34, - 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x32,0x32,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x39,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30, - 0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34, - 0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32, - 0x33,0x39,0x20,0x2a,0x20,0x5f,0x32,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78, - 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30, - 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56, - 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, - 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, - 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, - 0x5f,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f, - 0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, + 0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, + 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20, + 0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62, + 0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28, + 0x5f,0x31,0x30,0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20, + 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x31,0x30,0x37,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35, + 0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38, + 0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x31,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72, + 0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b, + 0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36, + 0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31, + 0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38, + 0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31, + 0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, + 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30, + 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, + 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f, + 0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37, + 0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, + 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38, + 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, + 0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30, + 0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31, + 0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37, + 0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e, + 0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36, + 0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38, + 0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, + 0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b, + 0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, + 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, + 0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30, + 0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x36,0x20, 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, 0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f, 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e, 0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x32,0x37,0x30,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, - 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31,0x2e, - 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32,0x37,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, - 0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33, - 0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66, - 0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x30,0x20,0x2a,0x20, - 0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, - 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, - 0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29, - 0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, - 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, - 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x34,0x32,0x34,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73, - 0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32, - 0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30, - 0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, - 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, - 0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, - 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a, - 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a, - 0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, - 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39, - 0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35, - 0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, - 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, - 0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37, - 0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32, - 0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30, - 0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, - 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, - 0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, - 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x66, - 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32, - 0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30, + 0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c, + 0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a, + 0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30, + 0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33, + 0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35, + 0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65, + 0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c, + 0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34,0x38, + 0x32,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c, 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, - 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78, - 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, - 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x63,0x6c, - 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, - 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, - 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, - 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70, - 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, - 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e, - 0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, - 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39, - 0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x35,0x30,0x35,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, - 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x31,0x2c,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78, - 0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x31,0x20,0x2b,0x20,0x28,0x28,0x6d, - 0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x34,0x31,0x29, - 0x20,0x2d,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d, - 0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, - 0x5f,0x34,0x33,0x31,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20, - 0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, - 0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20,0x30, - 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, - 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29, - 0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d, - 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66, - 0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, - 0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f,0x35,0x30, - 0x35,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x35,0x30,0x35,0x2e,0x79,0x2e,0x78,0x78, - 0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e, - 0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, - 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, - 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61, - 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72, - 0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70, - 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65, - 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, - 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, - 0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73, - 0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d, - 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73, - 0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61, - 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, - 0x33,0x30,0x31,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65, - 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x31,0x33,0x30,0x32,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f, - 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x31,0x33,0x30,0x31,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x31,0x32, - 0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33, - 0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72, - 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, - 0x32,0x30,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20, - 0x5f,0x31,0x33,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x32,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x3d,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x33,0x31,0x36,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33, - 0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x36,0x2c,0x20,0x5f, - 0x31,0x33,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x34,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x2d, - 0x20,0x28,0x5f,0x31,0x33,0x32,0x34,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35, - 0x30,0x20,0x3d,0x20,0x28,0x5f,0x31,0x33,0x32,0x30,0x20,0x2a,0x20,0x64,0x6f,0x74, - 0x28,0x5f,0x31,0x32,0x39,0x30,0x2c,0x20,0x5f,0x31,0x33,0x31,0x36,0x29,0x29,0x20, - 0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x38,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, - 0x36,0x32,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x33,0x20,0x3d,0x20,0x28,0x5f,0x31,0x33, - 0x35,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f, - 0x31,0x33,0x34,0x32,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x32,0x30,0x20, - 0x2a,0x20,0x5f,0x31,0x33,0x33,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32, - 0x38,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x38,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f, - 0x31,0x33,0x36,0x32,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x39, - 0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33, - 0x31,0x32,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x33,0x32, - 0x38,0x20,0x2d,0x20,0x28,0x28,0x5f,0x31,0x33,0x35,0x30,0x20,0x2f,0x20,0x6d,0x61, - 0x78,0x28,0x5f,0x31,0x33,0x34,0x32,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38, - 0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29, - 0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x31, - 0x33,0x32,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, - 0x33,0x39,0x38,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65, - 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33, - 0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x34,0x30,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x39,0x38,0x2c, - 0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x36,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28, - 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x33,0x39,0x38,0x2c,0x20,0x5f,0x31,0x33,0x39,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f, - 0x31,0x34,0x30,0x32,0x20,0x2a,0x20,0x5f,0x31,0x34,0x30,0x32,0x29,0x29,0x29,0x20, - 0x2d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x39,0x20,0x3d,0x20,0x66,0x77, - 0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x31,0x20,0x3d,0x20,0x6d, - 0x61,0x78,0x28,0x5f,0x31,0x34,0x31,0x39,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, - 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34, - 0x32,0x38,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, - 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x34,0x32,0x31,0x2c,0x20,0x5f, - 0x31,0x34,0x32,0x31,0x2c,0x20,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30, - 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x33,0x37,0x33, - 0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31, - 0x33,0x34,0x32,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33, - 0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32, - 0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x31, - 0x33,0x35,0x30,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x33,0x37, - 0x33,0x29,0x29,0x20,0x2f,0x20,0x5f,0x31,0x33,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x32, - 0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x2b,0x20,0x28,0x5f,0x31,0x34,0x34, - 0x36,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x34,0x34,0x36,0x20, - 0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x34,0x35, - 0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f, - 0x31,0x34,0x35,0x32,0x20,0x3c,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a, - 0x20,0x5f,0x31,0x34,0x34,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x30, - 0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x32,0x20,0x2a,0x20,0x28,0x5f,0x31, - 0x34,0x35,0x32,0x20,0x2f,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x29,0x29,0x20, - 0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, - 0x5f,0x31,0x34,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x34,0x39,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33, - 0x31,0x36,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x30,0x36,0x20,0x3d,0x20,0x28,0x5f, - 0x31,0x34,0x39,0x32,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x32,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x31,0x33,0x33,0x36,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x32,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x30,0x36,0x20,0x3e, - 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x31, - 0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x34,0x39,0x32,0x29,0x20,0x2d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x5f,0x31,0x35,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x31,0x38,0x20,0x3d, - 0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x32, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x35,0x31,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32, - 0x37,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c, - 0x7c,0x20,0x28,0x5f,0x31,0x35,0x31,0x36,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32, - 0x37,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x5f,0x31,0x35,0x32,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x33,0x38,0x20,0x3d,0x20,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31, - 0x35,0x31,0x36,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x35,0x33,0x38,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30, - 0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x35,0x33,0x38, - 0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, - 0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74, - 0x28,0x5f,0x31,0x35,0x35,0x34,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x32,0x20, - 0x3d,0x20,0x28,0x5f,0x31,0x35,0x35,0x38,0x20,0x2a,0x20,0x5f,0x31,0x35,0x35,0x38, - 0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x35,0x34,0x2c,0x20, - 0x5f,0x31,0x35,0x35,0x34,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x32,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x37,0x32,0x20,0x3e, - 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38, - 0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x35,0x35,0x38,0x29,0x20,0x2d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x5f,0x31,0x35,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x38,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x35,0x38,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x35,0x38,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39, - 0x33,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c, - 0x7c,0x20,0x28,0x5f,0x31,0x35,0x38,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39, - 0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x5f,0x31,0x35,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x36,0x30,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31, - 0x35,0x38,0x32,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x36,0x30,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, - 0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x36,0x30,0x34, - 0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20, + 0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, + 0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d, + 0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66, + 0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x38,0x20,0x3d, + 0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x32,0x32,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, + 0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74, + 0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x32,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x32, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x39,0x32, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33, + 0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20,0x28,0x5f,0x39,0x32, + 0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36,0x2c,0x20,0x5f,0x39, + 0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f, + 0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, + 0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28,0x5f,0x39, + 0x35,0x36,0x20,0x2a,0x20,0x5f,0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39, + 0x34,0x38,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x5f, + 0x39,0x34,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f, + 0x39,0x33,0x34,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20,0x2a,0x20, + 0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38, + 0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30, + 0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30, + 0x39,0x66,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x29,0x20,0x2f,0x20, + 0x5f,0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x31,0x30,0x30,0x34,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x30, + 0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x30,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c, + 0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30, + 0x30,0x34,0x2c,0x20,0x5f,0x31,0x30,0x30,0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31, + 0x30,0x30,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x5f,0x31,0x30,0x32,0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33, + 0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31, + 0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x37,0x39,0x20,0x3e, + 0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x39,0x34,0x38, + 0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32, + 0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31, + 0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x36,0x32,0x32,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x34,0x30,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20, - 0x5f,0x31,0x36,0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x39,0x34,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x28,0x5f,0x31,0x34,0x32,0x38,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20, - 0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73, - 0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x36,0x34,0x36,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, - 0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x74, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, - 0x38,0x34,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x5f,0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x39,0x35,0x36,0x29, + 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39,0x29,0x29,0x20,0x2f, + 0x20,0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d,0x20,0x5f,0x39,0x33, + 0x34,0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a,0x20,0x5f,0x39,0x33, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x28,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20, + 0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c,0x20,0x5f, + 0x39,0x32,0x36,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20, + 0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29, + 0x29,0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20,0x3d,0x20,0x28,0x5f, + 0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32,0x20,0x3e,0x3d,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x32,0x32,0x20, + 0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20,0x3d,0x20,0x5f, + 0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31, + 0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20, + 0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32,0x29, + 0x29,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x31,0x34,0x34,0x2c,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x31,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x31,0x36,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39, + 0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c, + 0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x31,0x37,0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34, + 0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d, + 0x20,0x5f,0x39,0x36,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x37,0x38,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31, + 0x36,0x34,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x31,0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20, + 0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20, + 0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x31,0x38,0x38,0x20, + 0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x39,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x31, + 0x30,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36, + 0x20,0x2a,0x20,0x5f,0x31,0x31,0x38,0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31, + 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x31,0x30,0x2c,0x20,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x31,0x30,0x20,0x2f,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x2e, + 0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30, + 0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, + 0x5f,0x31,0x32,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20, + 0x2a,0x20,0x5f,0x31,0x32,0x32,0x38,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x30,0x30, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x28,0x5f,0x31,0x30,0x33,0x34,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66, + 0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64, + 0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x74, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, + 0x39,0x30,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, 0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29, 0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x79, 0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b, 0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a, 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x30,0x31,0x20,0x3d,0x20,0x28, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x30,0x37,0x20,0x3d,0x20,0x28, 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20, 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f, 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77, 0x6f,0x72,0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, 0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f, - 0x31,0x36,0x38,0x34,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31, + 0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31, 0x2e,0x30,0x66,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37, 0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37, - 0x31,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x36,0x38, - 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x37,0x33,0x30,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x37, - 0x30,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x37,0x35,0x30,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x37, - 0x31,0x35,0x2c,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x33,0x35,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x33, + 0x32,0x31,0x2c,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, 0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32, 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e, 0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, - 0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x37,0x31,0x39,0x20,0x2a,0x20,0x31,0x2e, - 0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x36,0x38,0x34,0x29,0x29,0x2c, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e, + 0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c, 0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, - 0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x37,0x33,0x30,0x20,0x2a, - 0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x37,0x30,0x31, + 0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x2a, + 0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x30,0x37, 0x29,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x35,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x5f,0x31,0x36,0x34,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37, - 0x35,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x37,0x35,0x38,0x2c,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, - 0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x39,0x2e,0x7a,0x20,0x2f,0x20,0x5f, - 0x31,0x37,0x35,0x39,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, - 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x39,0x31,0x20,0x3d,0x20, - 0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x37,0x35,0x38,0x2c, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x20,0x2a, - 0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35, - 0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32, - 0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x37, - 0x39,0x31,0x2c,0x20,0x5f,0x31,0x37,0x39,0x31,0x2c,0x20,0x5f,0x31,0x37,0x39,0x31, - 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c,0x61, - 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f, - 0x31,0x37,0x35,0x38,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77, - 0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x5f,0x31,0x38,0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x38, - 0x32,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x37,0x35,0x38,0x2c,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x38,0x31,0x39,0x5d,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x38,0x33,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x39,0x2e,0x78,0x79,0x7a, - 0x20,0x2f,0x20,0x5f,0x31,0x38,0x32,0x39,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x38,0x35,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, - 0x31,0x38,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b, - 0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x38,0x33,0x36,0x2e,0x79, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66, - 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x38,0x33,0x36,0x2e, - 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x38,0x35,0x38,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, - 0x6c,0x33,0x28,0x5f,0x31,0x38,0x35,0x33,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30, - 0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x38,0x35,0x33,0x2e,0x79, - 0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f, - 0x31,0x38,0x35,0x33,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, - 0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x38,0x35,0x38,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x36,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79, - 0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x38,0x35,0x33,0x2e,0x78,0x20,0x3e, - 0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x38, - 0x35,0x33,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, - 0x79,0x2c,0x20,0x5f,0x31,0x38,0x35,0x33,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30, - 0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x36,0x35,0x20,0x3d,0x20, - 0x5f,0x31,0x38,0x35,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, - 0x38,0x36,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74, - 0x20,0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x54,0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d, - 0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x31, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x36,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33, + 0x36,0x35,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74, + 0x68,0x20,0x3d,0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d, + 0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36, + 0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x39,0x37,0x2c, + 0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x31, 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x39,0x31,0x36,0x5f,0x64,0x75,0x6d,0x6d,0x79, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x39,0x32,0x34,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65, - 0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2c,0x20,0x75, - 0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x39,0x31,0x36,0x5f,0x64,0x75, - 0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x29,0x29,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x39,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x32,0x34, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, - 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x5f,0x31,0x39,0x32,0x35,0x2c,0x20,0x5f,0x31,0x39,0x32,0x35,0x2c,0x20,0x5f, - 0x31,0x39,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x36,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, - 0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x37,0x35,0x38,0x2c,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x37,0x33,0x20,0x3d,0x20,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63, - 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20, - 0x5f,0x31,0x36,0x34,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x37, - 0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, - 0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x6e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31, - 0x39,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, - 0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73, - 0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68, - 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b, - 0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x34, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, - 0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x35,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x36, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x36,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x38, + 0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x34,0x34,0x32,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, + 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x34,0x34,0x32,0x2e,0x77,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x34,0x36,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x34,0x34,0x39, + 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20, + 0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x30,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x34,0x36,0x36,0x2e,0x78, + 0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, + 0x31,0x34,0x36,0x36,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x7a,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, + 0x34,0x37,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x34, + 0x36,0x36,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, + 0x78,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x34,0x36,0x36,0x2e,0x7a, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, + 0x34,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20, + 0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x33,0x39,0x5f, + 0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x34, + 0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67, + 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x61,0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x35, + 0x33,0x39,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74, + 0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20, + 0x5f,0x31,0x35,0x34,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34, + 0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x32,0x30,0x35,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x38, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65, - 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20, - 0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d, - 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, - 0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x32,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x32, - 0x30,0x35,0x33,0x2c,0x20,0x5f,0x32,0x30,0x35,0x33,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, - 0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, - 0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f, - 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, - 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78, - 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, - 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, - 0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, - 0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20, - 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, + 0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x33,0x36,0x34,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x36,0x20,0x3d,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, + 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68, + 0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x35, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x36,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, + 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x35,0x34,0x38,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f, + 0x31,0x36,0x37,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69, + 0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, + 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, - 0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, - 0x77,0x32,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, - 0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, - 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61, + 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, + 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68, + 0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74, + 0x3b,0x0a,0x7d,0x0a,0x00, }; /* #include @@ -4603,10 +3836,7 @@ static const uint8_t capsule_vs_source_metal_macos[2227] = { float4x4 view_proj; float4x4 view; float4 cascade_far_view_z; - float4 cascade_texel_world; - float4 cascade_depth_bias; - float4 shadow_params; - float4x4 cascade_matrices[4]; + float4x4 cascade_matrices[3]; float4 sh[9]; float4 ibl_params; }; @@ -4632,224 +3862,105 @@ static const uint8_t capsule_vs_source_metal_macos[2227] = { }; static inline __attribute__((always_inline)) - int selectShadowCascade(thread const float4& far_view_z, thread const float& view_z) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; + float _529 = float(cascade); + float _534 = light_uv.z - bias0; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float4 _557 = float4(_550, _554, _529, _534); + float4 _573 = float4(light_uv.x, _554, _529, _534); + float _584 = light_uv.x + 0.00048828125; + float4 _591 = float4(_584, _554, _529, _534); + float4 _607 = float4(_550, light_uv.y, _529, _534); + float4 _621 = float4(light_uv.xy, _529, _534); + float4 _637 = float4(_584, light_uv.y, _529, _534); + float _652 = light_uv.y + 0.00048828125; + float4 _655 = float4(_550, _652, _529, _534); + float4 _671 = float4(light_uv.x, _652, _529, _534); + float4 _689 = float4(_584, _652, _529, _534); + return ((((((((tex_shadow.sample_compare(smp_shadow, _557.xy, uint(rint(_557.z)), _534) + tex_shadow.sample_compare(smp_shadow, _573.xy, uint(rint(_573.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _591.xy, uint(rint(_591.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _607.xy, uint(rint(_607.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _621.xy, uint(rint(_621.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _637.xy, uint(rint(_637.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _655.xy, uint(rint(_655.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _671.xy, uint(rint(_671.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _689.xy, uint(rint(_689.z)), _534)) * 0.111111111938953399658203125; } static inline __attribute__((always_inline)) - float3 shadowCascadeTint(thread const int& cascade) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) { - if (cascade == 0) + float4 _717 = _707.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _724 = _717.xyz / float3(_717.w); + float3 _742 = float3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(_742 < float3(0.0)); + bool _753; + if (!_746) { - return float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return float3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - - static inline __attribute__((always_inline)) - float sampleShadowTap(depth2d_array tex, sampler smp, thread const float2& uv, thread const float& layer, thread const float& ref_z) - { - float4 _605 = float4(uv, layer, ref_z); - return tex.sample_compare(smp, _605.xy, uint(rint(_605.z)), ref_z); - } - - static inline __attribute__((always_inline)) - float sampleShadowPCF(depth2d_array tex, sampler smp, thread const int& cascade, thread const float3& light_uv, thread const float& bias0, thread const float& scale, thread const float& inv_size) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias0; - float2 _625 = light_uv.xy * (1.0 / inv_size); - float2 _630 = floor(_625 + float2(0.5)); - float _637 = (_625.x + 0.5) - _630.x; - float _644 = (_625.y + 0.5) - _630.y; - float2 _649 = (_630 - float2(0.5)) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0 * _637; - float _658 = _656 - 6.0; - float _662 = 11.0 * _637; - float _664 = _662 - 28.0; - float _670 = (-17.0) - _662; - float _675 = (-1.0) - _656; - float _679 = 4.0 * _637; - float _683 = ((_679 - 5.0) / _658) - 3.0; - float _691 = ((_679 - 16.0) / _664) - 1.0; - float _700 = (((-5.0) - (7.0 * _637)) / _670) + 1.0; - float _706 = ((-_637) / _675) + 3.0; - float _709 = 5.0 * _644; - float _710 = _709 - 6.0; - float _713 = 11.0 * _644; - float _714 = _713 - 28.0; - float _719 = (-17.0) - _713; - float _724 = (-1.0) - _709; - float _727 = 4.0 * _644; - float _731 = ((_727 - 5.0) / _710) - 3.0; - float _738 = ((_727 - 16.0) / _714) - 1.0; - float _746 = (((-5.0) - (7.0 * _644)) / _719) + 1.0; - float _752 = ((-_644) / _724) + 3.0; - float sum = 0.0; - float2 param = _649 + (float2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _649 + (float2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _649 + (float2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _649 + (float2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _649 + (float2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _649 + (float2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _649 + (float2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _649 + (float2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _649 + (float2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _649 + (float2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _649 + (float2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _649 + (float2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _649 + (float2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _649 + (float2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _649 + (float2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _649 + (float2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875; - } - - static inline __attribute__((always_inline)) - float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, constant ub_pass& _1071, depth2d_array tex_shadow, sampler smp_shadow) - { - float _1086 = fast::clamp(_1071.cascade_texel_world.x / _1071.cascade_texel_world[cascade], 0.25, 1.0); - float _1095 = fast::max(dot(world_normal, fast::normalize(_1071.sun_dir_world.xyz)), 0.0); - float _1105 = 3.0 * _1086; - float4 _1128 = _1071.cascade_matrices[cascade] * float4(world_pos + (world_normal * ((((_1105 + 0.5) * 1.41420996189117431640625) * sqrt(fast::max(1.0 - (_1095 * _1095), 0.0))) * _1071.cascade_texel_world[cascade])), 1.0); - float3 _1136 = _1128.xyz / float3(_1128.w); - float _1153 = _1136.z; - float3 _1154 = float3((_1136.x * 0.5) + 0.5, ((_1136.y * _1071.shadow_params.x) * 0.5) + 0.5, _1153); - bool _1157 = _1153 < 0.0; - bool _1164; - if (!_1157) - { - _1164 = _1153 > 1.0; + _753 = any(_742 > float3(1.0)); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0; - } - float _1174 = (_1105 + 1.0) * _1071.shadow_params.y; - float2 _1176 = _1154.xy; - bool _1182 = any(_1176 < float2(-_1174)); - bool _1193; - if (!_1182) - { - _1193 = any(_1176 > float2(1.0 + _1174)); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0; } int param = cascade; - float3 param_1 = _1154; - float param_2 = _1071.cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071.shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = fast::min(_785, float2(1.0) - _785); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; } static inline __attribute__((always_inline)) - float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, constant ub_pass& _1071, depth2d_array tex_shadow, sampler smp_shadow) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) { - float4 param = _1071.cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4, _1071, tex_shadow, smp_shadow); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) { - _1239 = 0.0; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _707); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; } else { - _1239 = _1071.cascade_far_view_z[_1219 - 1]; + _835 = _707.cascade_far_view_z.y; } - float _1252 = mix(_1071.cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7, _1071, tex_shadow, smp_shadow), (view_z - _1252) / (_1071.cascade_far_view_z[_1219] - _1252)); + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _707), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -4858,61 +3969,61 @@ static const uint8_t capsule_vs_source_metal_macos[2227] = { static inline __attribute__((always_inline)) float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0)) + 1.0; - return _133 / ((3.1415927410125732421875 * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); } static inline __attribute__((always_inline)) float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) { - float _155 = alpha * alpha; - float _162 = 1.0 - _155; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06); + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); } static inline __attribute__((always_inline)) float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) { - float _191 = 1.0 - v_dot_h; - float _195 = _191 * _191; - return f0 + ((float3(1.0) - f0) * ((_195 * _195) * _191)); + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((float3(1.0) - f0) * ((_169 * _169) * _165)); } static inline __attribute__((always_inline)) float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) { - float _214 = fast::max(dot(N, L), 0.0); - float3 _225 = fast::normalize(V + L); - float _239 = fast::max(roughness, 0.04500000178813934326171875); - float _243 = _239 * _239; - float param = fast::max(dot(N, _225), 0.0); - float param_1 = _243; + float _188 = fast::max(dot(N, L), 0.0); + float3 _199 = fast::normalize(V + L); + float _213 = fast::max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = fast::max(dot(N, _199), 0.0); + float param_1 = _217; float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _214; - float param_4 = _243; - float param_5 = fast::max(dot(V, _225), 0.0); + float param_3 = _188; + float param_4 = _217; + float param_5 = fast::max(dot(V, _199), 0.0); float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); - float3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((float3(1.0) - _270) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _244) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } static inline __attribute__((always_inline)) float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) { - float3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _424; + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; } static inline __attribute__((always_inline)) float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) { - float _431 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - float3 _441 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float _406 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _416 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); float3 param = N_world; spvUnsafeArray param_1 = sh; - float4 _505 = tex_brdf_lut.sample(smp_brdf_lut, float2(_431, roughness)); - return (((((float3(1.0) - (_441 + ((fast::max(float3(1.0 - roughness), _441) - _441) * powr(fast::max(0.0, 1.0 - _431), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_441 * _505.x) + float3(_505.y))); + float4 _482 = tex_brdf_lut.sample(smp_brdf_lut, float2(_406, roughness)); + return (((((float3(1.0) - (_416 + ((fast::max(float3(1.0 - roughness), _416) - _416) * powr(fast::max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_416 * _482.x) + float3(_482.y))); } static inline __attribute__((always_inline)) @@ -4933,194 +4044,217 @@ static const uint8_t capsule_vs_source_metal_macos[2227] = { return result; } - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _1071 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _707 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) { main0_out out = {}; - float3 _1290 = fast::normalize(in.v_world_pos_proxy - _1071.camera_pos.xyz); - float3 _1301 = in.v_axis_x_world * in.v_half_length; - float3 _1302 = in.v_center - _1301; - float3 _1308 = in.v_center + _1301; - float3 _1312 = _1308 - _1302; - float3 _1316 = _1071.camera_pos.xyz - _1302; - float _1320 = dot(_1312, _1312); - float _1324 = dot(_1312, _1290); - float _1328 = dot(_1312, _1316); - float _1336 = dot(_1316, _1316); - float _1342 = _1320 - (_1324 * _1324); - float _1350 = (_1320 * dot(_1290, _1316)) - (_1328 * _1324); - float _1362 = in.v_radius * in.v_radius; - float _1373 = (_1350 * _1350) - (_1342 * (((_1320 * _1336) - (_1328 * _1328)) - (_1362 * _1320))); - float3 _1394 = _1302 + (_1312 * fast::clamp((_1328 - ((_1350 / fast::max(_1342, 9.9999999392252902907785028219223e-09)) * _1324)) / _1320, 0.0, 1.0)); - float3 _1398 = _1071.camera_pos.xyz - _1394; - float _1402 = dot(_1398, _1290); - float _1416 = sqrt(fast::max(0.0, dot(_1398, _1398) - (_1402 * _1402))) - in.v_radius; - float _1419 = fwidth(_1416); - float _1421 = fast::max(_1419, 9.9999999747524270787835121154785e-07); - float _1428 = 1.0 - smoothstep(-_1421, _1421, _1416); + float3 _896 = fast::normalize(in.v_world_pos_proxy - _707.camera_pos.xyz); + float3 _907 = in.v_axis_x_world * in.v_half_length; + float3 _908 = in.v_center - _907; + float3 _914 = in.v_center + _907; + float3 _918 = _914 - _908; + float3 _922 = _707.camera_pos.xyz - _908; + float _926 = dot(_918, _918); + float _930 = dot(_918, _896); + float _934 = dot(_918, _922); + float _942 = dot(_922, _922); + float _948 = _926 - (_930 * _930); + float _956 = (_926 * dot(_896, _922)) - (_934 * _930); + float _968 = in.v_radius * in.v_radius; + float _979 = (_956 * _956) - (_948 * (((_926 * _942) - (_934 * _934)) - (_968 * _926))); + float3 _1000 = _908 + (_918 * fast::clamp((_934 - ((_956 / fast::max(_948, 9.9999999392252902907785028219223e-09)) * _930)) / _926, 0.0, 1.0)); + float3 _1004 = _707.camera_pos.xyz - _1000; + float _1008 = dot(_1004, _896); + float _1022 = sqrt(fast::max(0.0, dot(_1004, _1004) - (_1008 * _1008))) - in.v_radius; + float _1025 = fwidth(_1022); + float _1027 = fast::max(_1025, 9.9999999747524270787835121154785e-07); + float _1034 = 1.0 - smoothstep(-_1027, _1027, _1022); float t = -1.0; float3 n_world = float3(0.0); - if ((_1373 >= 0.0) && (_1342 > 9.9999999392252902907785028219223e-09)) + if ((_979 >= 0.0) && (_948 > 9.9999999392252902907785028219223e-09)) { - float _1446 = ((-_1350) - sqrt(_1373)) / _1342; - float _1452 = _1328 + (_1446 * _1324); - if (((_1446 > 0.0) && (_1452 > 0.0)) && (_1452 < _1320)) + float _1052 = ((-_956) - sqrt(_979)) / _948; + float _1058 = _934 + (_1052 * _930); + if (((_1052 > 0.0) && (_1058 > 0.0)) && (_1058 < _926)) { - n_world = ((_1071.camera_pos.xyz + (_1290 * _1446)) - (_1302 + (_1312 * (_1452 / _1320)))) / float3(in.v_radius); - t = _1446; + n_world = ((_707.camera_pos.xyz + (_896 * _1052)) - (_908 + (_918 * (_1058 / _926)))) / float3(in.v_radius); + t = _1052; } } - float _1492 = dot(_1316, _1290); - float _1506 = (_1492 * _1492) - (_1336 - _1362); - if (_1506 >= 0.0) + float _1098 = dot(_922, _896); + float _1112 = (_1098 * _1098) - (_942 - _968); + if (_1112 >= 0.0) { - float _1516 = (-_1492) - sqrt(_1506); - bool _1518 = _1516 > 0.0; - bool _1527; - if (_1518) + float _1122 = (-_1098) - sqrt(_1112); + bool _1124 = _1122 > 0.0; + bool _1133; + if (_1124) { - _1527 = (t < 0.0) || (_1516 < t); + _1133 = (t < 0.0) || (_1122 < t); } else { - _1527 = _1518; + _1133 = _1124; } - if (_1527) + if (_1133) { - float3 _1538 = (_1071.camera_pos.xyz + (_1290 * _1516)) - _1302; - if (dot(_1538, in.v_axis_x_world) <= 0.0) + float3 _1144 = (_707.camera_pos.xyz + (_896 * _1122)) - _908; + if (dot(_1144, in.v_axis_x_world) <= 0.0) { - n_world = _1538 / float3(in.v_radius); - t = _1516; + n_world = _1144 / float3(in.v_radius); + t = _1122; } } } - float3 _1554 = _1071.camera_pos.xyz - _1308; - float _1558 = dot(_1554, _1290); - float _1572 = (_1558 * _1558) - (dot(_1554, _1554) - _1362); - if (_1572 >= 0.0) + float3 _1160 = _707.camera_pos.xyz - _914; + float _1164 = dot(_1160, _896); + float _1178 = (_1164 * _1164) - (dot(_1160, _1160) - _968); + if (_1178 >= 0.0) { - float _1582 = (-_1558) - sqrt(_1572); - bool _1584 = _1582 > 0.0; - bool _1593; - if (_1584) + float _1188 = (-_1164) - sqrt(_1178); + bool _1190 = _1188 > 0.0; + bool _1199; + if (_1190) { - _1593 = (t < 0.0) || (_1582 < t); + _1199 = (t < 0.0) || (_1188 < t); } else { - _1593 = _1584; + _1199 = _1190; } - if (_1593) + if (_1199) { - float3 _1604 = (_1071.camera_pos.xyz + (_1290 * _1582)) - _1308; - if (dot(_1604, in.v_axis_x_world) >= 0.0) + float3 _1210 = (_707.camera_pos.xyz + (_896 * _1188)) - _914; + if (dot(_1210, in.v_axis_x_world) >= 0.0) { - n_world = _1604 / float3(in.v_radius); - t = _1582; + n_world = _1210 / float3(in.v_radius); + t = _1188; } } } if (t < 0.0) { - float _1622 = -_1402; - t = _1622; - n_world = fast::normalize((_1071.camera_pos.xyz + (_1290 * _1622)) - _1394); + float _1228 = -_1008; + t = _1228; + n_world = fast::normalize((_707.camera_pos.xyz + (_896 * _1228)) - _1000); } - if ((_1428 <= 0.0) || (t < 0.0)) + if ((_1034 <= 0.0) || (t < 0.0)) { discard_fragment(); } - float3 _1646 = _1071.camera_pos.xyz + (_1290 * t); - float _1684 = ((in.v_rot_row0.y * n_world.x) + (in.v_rot_row1.y * n_world.y)) + (in.v_rot_row2.y * n_world.z); - float _1701 = ((in.v_rot_row0.z * n_world.x) + (in.v_rot_row1.z * n_world.y)) + (in.v_rot_row2.z * n_world.z); - float3 _1715 = in.v_base_color.xyz * ((_1684 > 0.0) ? 1.0 : 0.64999997615814208984375); - float _1719 = fwidth(_1684); - float _1730 = fwidth(_1701); - float3 _1750 = mix(_1715, _1715 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, _1719 * 1.5, abs(_1684)), 1.0 - smoothstep(0.0, _1730 * 1.5, abs(_1701))))); - float4 _1758 = float4(_1646, 1.0); - float4 _1759 = _1071.view_proj * _1758; - out.gl_FragDepth = _1759.z / _1759.w; - if (_1071.flags.x == 1) + float3 _1252 = _707.camera_pos.xyz + (_896 * t); + float _1290 = ((in.v_rot_row0.y * n_world.x) + (in.v_rot_row1.y * n_world.y)) + (in.v_rot_row2.y * n_world.z); + float _1307 = ((in.v_rot_row0.z * n_world.x) + (in.v_rot_row1.z * n_world.y)) + (in.v_rot_row2.z * n_world.z); + float3 _1321 = in.v_base_color.xyz * ((_1290 > 0.0) ? 1.0 : 0.64999997615814208984375); + float _1325 = fwidth(_1290); + float _1336 = fwidth(_1307); + float3 _1356 = mix(_1321, _1321 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, _1325 * 1.5, abs(_1290)), 1.0 - smoothstep(0.0, _1336 * 1.5, abs(_1307))))); + float4 _1364 = float4(_1252, 1.0); + float4 _1365 = _707.view_proj * _1364; + out.gl_FragDepth = _1365.z / _1365.w; + if (_707.flags.x == 1) { - float _1791 = fast::clamp((_1071.view * _1758).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out.out_color = float4(_1791, _1791, _1791, 1.0); + float _1397 = fast::clamp((_707.view * _1364).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1397, _1397, _1397, 1.0); return out; } - if (_1071.flags.x == 2) + if (_707.flags.x == 2) { - float4 param = _1071.cascade_far_view_z; - float param_1 = -(_1071.view * _1758).z; - int _1819 = selectShadowCascade(param, param_1); - float4 _1829 = _1071.cascade_matrices[_1819] * _1758; - float3 _1836 = _1829.xyz / float3(_1829.w); - float3 _1853 = float3((_1836.x * 0.5) + 0.5, ((_1836.y * _1071.shadow_params.x) * 0.5) + 0.5, _1836.z); - bool _1858 = any(_1853 < float3(0.0)); - bool _1865; - if (!_1858) + float _1418 = -(_707.view * _1364).z; + int cascade = 2; + if (_1418 < _707.cascade_far_view_z.x) { - _1865 = any(_1853 > float3(1.0)); + cascade = 0; } else { - _1865 = _1858; + if (_1418 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1442 = _707.cascade_matrices[cascade] * _1364; + float3 _1449 = _1442.xyz / float3(_1442.w); + float3 _1466 = float3((_1449.x * 0.5) + 0.5, ((_1449.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1449.z); + bool _1470 = any(_1466 < float3(0.0)); + bool _1477; + if (!_1470) + { + _1477 = any(_1466 > float3(1.0)); + } + else + { + _1477 = _1470; } float3 tint = float3(1.0); - if (!_1865) + if (!_1477) { - int param_2 = _1819; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out.out_color = float4(tint, 1.0); return out; } - if (_1071.flags.x == 3) + if (_707.flags.x == 3) { - out.out_color = float4((fast::normalize((_1071.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + out.out_color = float4((fast::normalize((_707.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); return out; } - float4 _1924 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); - float _1925 = _1924.x; - if (_1071.flags.x == 4) + float4 _1547 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1548 = _1547.x; + if (_707.flags.x == 4) { - out.out_color = float4(_1925, _1925, _1925, 1.0); + out.out_color = float4(_1548, _1548, _1548, 1.0); return out; } - float3 param_3 = _1646; - float3 param_4 = n_world; - float param_5 = -(_1071.view * _1758).z; - float3 _1973 = fast::normalize(_1071.camera_pos.xyz - _1646); - float3 param_6 = n_world; - float3 param_7 = _1973; - float3 param_8 = fast::normalize(_1071.sun_dir_world.xyz); - float3 param_9 = _1071.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, _1071, tex_shadow, smp_shadow); - float3 param_10 = _1750; - float param_11 = in.v_material.x; - float param_12 = in.v_material.y; - bool param_13 = _1071.ibl_params.y > 0.5; - float3 param_14 = n_world; - float3 param_15 = _1973; - float3 param_16 = _1750; - float param_17 = in.v_material.x; - float param_18 = in.v_material.y; - float param_19 = _1071.sun_color.w; - spvUnsafeArray param_20; - param_20[0] = _1071.sh[0]; - param_20[1] = _1071.sh[1]; - param_20[2] = _1071.sh[2]; - param_20[3] = _1071.sh[3]; - param_20[4] = _1071.sh[4]; - param_20[5] = _1071.sh[5]; - param_20[6] = _1071.sh[6]; - param_20[7] = _1071.sh[7]; - param_20[8] = _1071.sh[8]; - float param_21 = _1071.ibl_params.x; - float _2053 = in.v_base_color.w * _1428; - out.out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1925)) * _2053, _2053); + float3 param = _1252; + float3 param_1 = n_world; + float param_2 = -(_707.view * _1364).z; + float3 _1596 = fast::normalize(_707.camera_pos.xyz - _1252); + float3 param_3 = n_world; + float3 param_4 = _1596; + float3 param_5 = fast::normalize(_707.sun_dir_world.xyz); + float3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _707); + float3 param_7 = _1356; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + float3 param_11 = n_world; + float3 param_12 = _1596; + float3 param_13 = _1356; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _707.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1675 = in.v_base_color.w * _1034; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1548)) * _1675, _1675); return out; } */ -static const uint8_t capsule_fs_source_metal_macos[23113] = { +static const uint8_t capsule_fs_source_metal_macos[19080] = { 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, @@ -5196,1376 +4330,1124 @@ static const uint8_t capsule_fs_source_metal_macos[23113] = { 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61, 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, - 0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, - 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, - 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65, - 0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x61,0x6e,0x79,0x29, - 0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, - 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, - 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73, - 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68, - 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b,0x75,0x73,0x65, - 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61, - 0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, - 0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, - 0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, - 0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70, + 0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20, - 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x2c,0x20,0x66, - 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75, - 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x37,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, - 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, - 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, - 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x38,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, - 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, - 0x6c,0x6f,0x63,0x6e,0x39,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26,0x20,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b, - 0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e, - 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, - 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, - 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, - 0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, - 0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c, - 0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39, - 0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, - 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20, - 0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x30,0x35,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20, - 0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, - 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x2c,0x20,0x5f,0x36,0x30,0x35,0x2e, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, + 0x68,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c, + 0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73, + 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x36,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x37, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x38,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x39,0x29,0x2c,0x20,0x66, + 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73, + 0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x37,0x33,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x30,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x37,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x36,0x37,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x39,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x35,0x37,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x37,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x37,0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x37,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x35,0x39,0x31,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x35,0x39,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x37,0x2e, 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, - 0x30,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, - 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, - 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x50,0x43,0x46,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72, - 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69,0x67, - 0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73,0x30, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x31,0x35,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x6c, - 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36, - 0x32,0x35,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79, - 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32, - 0x35,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x37, - 0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x36, - 0x32,0x35,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36, - 0x33,0x30,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x30,0x20,0x2d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69, - 0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x36,0x20,0x2d, - 0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x36,0x36,0x32,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x36,0x34,0x20,0x3d,0x20,0x5f,0x36,0x36,0x32,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30, - 0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, - 0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, - 0x39,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f, - 0x20,0x5f,0x36,0x35,0x38,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20, - 0x5f,0x36,0x36,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20,0x28,0x28, - 0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20, - 0x5f,0x36,0x33,0x37,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x30,0x29,0x20,0x2b, - 0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x37,0x29,0x20, - 0x2f,0x20,0x5f,0x36,0x37,0x35,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x39,0x20,0x3d,0x20, - 0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30, - 0x39,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x31,0x33,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x33,0x20,0x2d,0x20,0x32, - 0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x31,0x39,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x32,0x37,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33, - 0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x35,0x2e,0x30, - 0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20, - 0x3d,0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, - 0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x39, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34, - 0x34,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20, - 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f, - 0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36, - 0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37, - 0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x34,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38, - 0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20, - 0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x34,0x36, - 0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78, - 0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x37,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x35, - 0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36, - 0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38, - 0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69, - 0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, - 0x26,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64, - 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38,0x36,0x20, - 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65, - 0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20, - 0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x35,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, - 0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x33,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69, - 0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31, - 0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20, - 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x39,0x35,0x20,0x2a,0x20, - 0x5f,0x31,0x30,0x39,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74, - 0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x33,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x33,0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x33,0x36, - 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x35,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35,0x37, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x36,0x34,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x35,0x37,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3e,0x20,0x31,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31, - 0x36,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x31,0x37,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x37,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x35,0x34,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x38,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f, - 0x31,0x31,0x37,0x36,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x5f, - 0x31,0x31,0x37,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x31,0x38,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e, - 0x79,0x28,0x5f,0x31,0x31,0x37,0x36,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, - 0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x33,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69, - 0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, - 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, - 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, - 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72, - 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32, - 0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20, - 0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31, - 0x39,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x32,0x33,0x39,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x20,0x2d, - 0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x35,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x39,0x2c, - 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, - 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, - 0x20,0x5f,0x31,0x32,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, - 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x20,0x2d,0x20,0x5f, - 0x31,0x32,0x35,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, - 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, - 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c, - 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x20,0x3d,0x20,0x28, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2f,0x20,0x28,0x28,0x33, - 0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33, - 0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, - 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74, - 0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65, - 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, - 0x35,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68, - 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, - 0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f, - 0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71, - 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20, - 0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, - 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, - 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x30,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x32,0x31,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x31,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x36,0x33,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x33,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x36,0x35,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x31,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x37,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38,0x39,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x39,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39, + 0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68, - 0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x31,0x20,0x3d,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x35,0x20,0x3d,0x20,0x5f,0x31, - 0x39,0x31,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x28,0x5f,0x31,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x39,0x35,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x39,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74, + 0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x31,0x37, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, + 0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x5f,0x37,0x34,0x32,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38, + 0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36, + 0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20, + 0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, - 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38, + 0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, + 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f, + 0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30, + 0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37, + 0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, + 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, + 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b, + 0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f, - 0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x32,0x32,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x39,0x20,0x3d, - 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30, - 0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38, - 0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x33,0x39,0x20,0x2a,0x20,0x5f,0x32,0x33, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64, - 0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, - 0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, - 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, - 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, - 0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31, - 0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32, - 0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, - 0x37,0x30,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53, - 0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29, - 0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, - 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, - 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x30,0x20, - 0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, - 0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, - 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, - 0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29, - 0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, - 0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, - 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, - 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49, - 0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73, - 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x32,0x34,0x20, - 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30, - 0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37, - 0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, - 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, - 0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e, - 0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33, - 0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e, - 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, - 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, - 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35, - 0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36, - 0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20, - 0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34, - 0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35, - 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32, - 0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, - 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, - 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, - 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, - 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32, - 0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, - 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, - 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, - 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, - 0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x6d, + 0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20, + 0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34, + 0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33, + 0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33, + 0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39, + 0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, 0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39, 0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36, 0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74, 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, - 0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20, - 0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x30,0x35, - 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x31, - 0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34, - 0x34,0x31,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34,0x31,0x29,0x20, - 0x2d,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x5f,0x34,0x33,0x31,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29, - 0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61, - 0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72, - 0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35, - 0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29, - 0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f,0x35,0x30, - 0x35,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x35, - 0x30,0x35,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72, + 0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31, + 0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74, + 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20, + 0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, + 0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38, + 0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39, + 0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39, + 0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36, + 0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, - 0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68, - 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26, + 0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34, + 0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c, + 0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c, + 0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, + 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66, + 0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55, 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78, - 0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74, - 0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, - 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, - 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73, - 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e, - 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e, - 0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, - 0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x30,0x37,0x31,0x20,0x5b,0x5b, - 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70, - 0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d, - 0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28, - 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, - 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b, - 0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, - 0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, - 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e, - 0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, - 0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72, - 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x30,0x31,0x20,0x3d,0x20,0x69, - 0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, - 0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x33,0x30,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e, - 0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20, - 0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x31, - 0x33,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x33,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x2d,0x20, - 0x5f,0x31,0x33,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x5f,0x31,0x33,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, - 0x20,0x5f,0x31,0x33,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x33,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x34,0x20,0x3d,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32, - 0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x31,0x32,0x2c,0x20,0x5f, - 0x31,0x33,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33, - 0x31,0x36,0x2c,0x20,0x5f,0x31,0x33,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x34,0x32,0x20,0x3d,0x20,0x5f,0x31, - 0x33,0x32,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x34,0x20,0x2a,0x20,0x5f, - 0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x35,0x30,0x20,0x3d,0x20,0x28,0x5f,0x31,0x33,0x32,0x30,0x20, - 0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x30,0x2c,0x20,0x5f,0x31,0x33, - 0x31,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x38,0x20,0x2a,0x20, - 0x5f,0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x36,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x33,0x37,0x33,0x20,0x3d,0x20,0x28,0x5f,0x31,0x33,0x35,0x30,0x20,0x2a,0x20, - 0x5f,0x31,0x33,0x35,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x34,0x32,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x5f,0x31,0x33,0x32,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33, - 0x33,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x32,0x38,0x20,0x2a,0x20,0x5f, - 0x31,0x33,0x32,0x38,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x36,0x32,0x20, - 0x2a,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x39,0x34,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x30,0x32,0x20,0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x32,0x20,0x2a,0x20, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x33, - 0x32,0x38,0x20,0x2d,0x20,0x28,0x28,0x5f,0x31,0x33,0x35,0x30,0x20,0x2f,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x34,0x32,0x2c,0x20, - 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39, - 0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32, - 0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29, - 0x29,0x20,0x2f,0x20,0x5f,0x31,0x33,0x32,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, + 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, + 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29, + 0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d, + 0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c, + 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x39,0x30,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x39,0x30, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39, + 0x31,0x38,0x20,0x3d,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x32, + 0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x36,0x20,0x3d, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x39,0x31,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x30, + 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f,0x38,0x39, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x33,0x34,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x31,0x38,0x2c,0x20,0x5f, + 0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x34,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c, + 0x20,0x5f,0x39,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x39,0x34,0x38,0x20,0x3d,0x20,0x5f,0x39,0x32,0x36,0x20,0x2d,0x20, + 0x28,0x5f,0x39,0x33,0x30,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x35,0x36,0x20,0x3d,0x20, + 0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x38,0x39,0x36, + 0x2c,0x20,0x5f,0x39,0x32,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x33,0x34, + 0x20,0x2a,0x20,0x5f,0x39,0x33,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x37,0x39,0x20,0x3d,0x20,0x28,0x5f,0x39,0x35,0x36,0x20,0x2a,0x20,0x5f, + 0x39,0x35,0x36,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x38,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x5f,0x39,0x32,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34,0x32,0x29,0x20,0x2d, + 0x20,0x28,0x5f,0x39,0x33,0x34,0x20,0x2a,0x20,0x5f,0x39,0x33,0x34,0x29,0x29,0x20, + 0x2d,0x20,0x28,0x5f,0x39,0x36,0x38,0x20,0x2a,0x20,0x5f,0x39,0x32,0x36,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x30,0x30,0x30,0x20,0x3d,0x20,0x5f,0x39,0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39, + 0x31,0x38,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x39,0x33,0x34,0x20,0x2d,0x20,0x28,0x28,0x5f,0x39,0x35,0x36,0x20, + 0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x39,0x34,0x38, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35, + 0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39, + 0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30, + 0x29,0x29,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x5f,0x31,0x33,0x39,0x38,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, - 0x20,0x5f,0x31,0x33,0x39,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x30,0x32,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x33,0x39,0x38,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x36,0x20,0x3d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e, - 0x30,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x33,0x39,0x38,0x2c,0x20,0x5f,0x31, - 0x33,0x39,0x38,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x34,0x30,0x32,0x20,0x2a,0x20, - 0x5f,0x31,0x34,0x30,0x32,0x29,0x29,0x29,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x31,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68, - 0x28,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x34,0x31,0x39,0x2c,0x20,0x39,0x2e,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38, - 0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30, - 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x34,0x32,0x38,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, - 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x34,0x32,0x31,0x2c,0x20,0x5f, - 0x31,0x34,0x32,0x31,0x2c,0x20,0x5f,0x31,0x34,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x33, - 0x37,0x33,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f, - 0x31,0x33,0x34,0x32,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30, - 0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x31, - 0x33,0x35,0x30,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x33,0x37, - 0x33,0x29,0x29,0x20,0x2f,0x20,0x5f,0x31,0x33,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x32, - 0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x2b,0x20,0x28,0x5f,0x31,0x34,0x34, - 0x36,0x20,0x2a,0x20,0x5f,0x31,0x33,0x32,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x28,0x5f,0x31,0x34,0x34,0x36,0x20, - 0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x34,0x35,0x32, - 0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x34, - 0x35,0x32,0x20,0x3c,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x28,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, - 0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f, - 0x31,0x34,0x34,0x36,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x30,0x32,0x20, - 0x2b,0x20,0x28,0x5f,0x31,0x33,0x31,0x32,0x20,0x2a,0x20,0x28,0x5f,0x31,0x34,0x35, - 0x32,0x20,0x2f,0x20,0x5f,0x31,0x33,0x32,0x30,0x29,0x29,0x29,0x29,0x20,0x2f,0x20, + 0x33,0x20,0x5f,0x31,0x30,0x30,0x34,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20, + 0x5f,0x31,0x30,0x30,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x30,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30, + 0x30,0x34,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x32,0x32,0x20,0x3d,0x20,0x73,0x71,0x72, + 0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, + 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x30,0x34,0x2c,0x20,0x5f,0x31,0x30,0x30, + 0x34,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x30,0x38,0x20,0x2a,0x20,0x5f,0x31, + 0x30,0x30,0x38,0x29,0x29,0x29,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61, + 0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f, + 0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x32,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x5f,0x31,0x30,0x32,0x35,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33, + 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, + 0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x30,0x32,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x32,0x37,0x2c,0x20,0x5f,0x31,0x30,0x32,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x37,0x39,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x39,0x34,0x38, + 0x20,0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32, + 0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31, + 0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x30,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x39,0x35,0x36,0x29,0x20, + 0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x37,0x39,0x29,0x29,0x20,0x2f,0x20, + 0x5f,0x39,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d,0x20,0x5f,0x39,0x33,0x34, + 0x20,0x2b,0x20,0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x2a,0x20,0x5f,0x39,0x33,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28, + 0x28,0x5f,0x31,0x30,0x35,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26, + 0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x29,0x20, + 0x26,0x26,0x20,0x28,0x5f,0x31,0x30,0x35,0x38,0x20,0x3c,0x20,0x5f,0x39,0x32,0x36, + 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36, + 0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x32,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39, + 0x30,0x38,0x20,0x2b,0x20,0x28,0x5f,0x39,0x31,0x38,0x20,0x2a,0x20,0x28,0x5f,0x31, + 0x30,0x35,0x38,0x20,0x2f,0x20,0x5f,0x39,0x32,0x36,0x29,0x29,0x29,0x29,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x64, + 0x6f,0x74,0x28,0x5f,0x39,0x32,0x32,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x31,0x32,0x20, + 0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x38, + 0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x32,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x31,0x32, + 0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, + 0x32,0x32,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x30,0x39,0x38,0x29,0x20,0x2d,0x20, + 0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x32,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33, + 0x33,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c, + 0x20,0x28,0x5f,0x31,0x31,0x32,0x32,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x31,0x33,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a, + 0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x32,0x32, + 0x29,0x29,0x20,0x2d,0x20,0x5f,0x39,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f, + 0x31,0x31,0x34,0x34,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, + 0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x36,0x30,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x37, + 0x38,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x36,0x34,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x31,0x36,0x30, + 0x2c,0x20,0x5f,0x31,0x31,0x36,0x30,0x29,0x20,0x2d,0x20,0x5f,0x39,0x36,0x38,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x37,0x38,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x38, + 0x38,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x36,0x34,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x31,0x31,0x37,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x30,0x20,0x3d, + 0x20,0x5f,0x31,0x31,0x38,0x38,0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x31,0x39,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39, + 0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20, + 0x28,0x5f,0x31,0x31,0x38,0x38,0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x39,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x39,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x39,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x3d,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, + 0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x31,0x38,0x38,0x29, + 0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x32,0x31,0x30,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x30,0x20,0x2f,0x20, 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69, 0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x32,0x20,0x3d,0x20,0x64,0x6f, - 0x74,0x28,0x5f,0x31,0x33,0x31,0x36,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x30,0x36, - 0x20,0x3d,0x20,0x28,0x5f,0x31,0x34,0x39,0x32,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39, - 0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x31,0x33,0x33,0x36,0x20,0x2d,0x20,0x5f,0x31, - 0x33,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x35,0x30,0x36,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x35,0x31,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x34,0x39,0x32,0x29, - 0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x35,0x30,0x36,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35, - 0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3e,0x20,0x30,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x35,0x32,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x35,0x31,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, - 0x31,0x35,0x32,0x37,0x20,0x3d,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, - 0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x35,0x31,0x36,0x20,0x3c,0x20,0x74,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x35,0x32,0x37,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x38,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x35,0x32,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x33,0x38,0x20,0x3d,0x20,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20, - 0x5f,0x31,0x35,0x31,0x36,0x29,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x33,0x38,0x2c,0x20,0x69,0x6e,0x2e,0x76, - 0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x20,0x3c, - 0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f, - 0x31,0x35,0x33,0x38,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x69,0x6e, - 0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20, - 0x5f,0x31,0x35,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x35,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61, - 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f, - 0x31,0x33,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x35,0x35,0x38,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x35, - 0x34,0x2c,0x20,0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x32,0x20,0x3d,0x20,0x28,0x5f,0x31, - 0x35,0x35,0x38,0x20,0x2a,0x20,0x5f,0x31,0x35,0x35,0x38,0x29,0x20,0x2d,0x20,0x28, - 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x35,0x34,0x2c,0x20,0x5f,0x31,0x35,0x35,0x34, - 0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x37,0x32,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x32,0x20,0x3d,0x20,0x28,0x2d, - 0x5f,0x31,0x35,0x35,0x38,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31, - 0x35,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x35,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x32, - 0x20,0x3e,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x38,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x33,0x20,0x3d,0x20,0x28,0x74,0x20, - 0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x35,0x38,0x32, - 0x20,0x3c,0x20,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x35,0x39,0x33,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x36, - 0x30,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65, - 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31, - 0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x38,0x32,0x29,0x29,0x20,0x2d,0x20, - 0x5f,0x31,0x33,0x30,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x36,0x30,0x34, - 0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x36,0x30,0x34,0x20,0x2f,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x38,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x38,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x30,0x30, + 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28, + 0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x38,0x29,0x29,0x20,0x2d, + 0x20,0x5f,0x31,0x30,0x30,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x33,0x34,0x20,0x3c,0x3d, + 0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e, + 0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65, + 0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x30, + 0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x30,0x37,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f, + 0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39, + 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, + 0x32,0x35,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x32,0x39, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x33,0x36,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33, + 0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x33,0x35,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x33,0x32, + 0x31,0x2c,0x20,0x5f,0x31,0x33,0x32,0x31,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39, + 0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34, + 0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f, + 0x31,0x33,0x32,0x35,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x32,0x39,0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f, + 0x31,0x33,0x33,0x36,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x33,0x30,0x37,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x36,0x34,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x35,0x32,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, + 0x33,0x36,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x33,0x36,0x35,0x2e,0x7a,0x20,0x2f,0x20,0x5f, + 0x31,0x33,0x36,0x35,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x37,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a, + 0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39, + 0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33, + 0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31,0x33,0x39,0x37,0x2c,0x20,0x5f,0x31, + 0x33,0x39,0x37,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29, + 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x34,0x31,0x38,0x20,0x3c, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x34,0x31,0x38,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x34,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, + 0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x34, + 0x32,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x31,0x34,0x34,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x36,0x36,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x34,0x34,0x39,0x2e,0x78,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28, + 0x5f,0x31,0x34,0x34,0x39,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x30,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x34,0x36,0x36,0x20,0x3c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x34, + 0x37,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x34,0x36,0x36,0x20,0x3e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d, + 0x20,0x5f,0x31,0x34,0x37,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x31,0x34,0x37,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x36,0x32,0x32,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x34,0x30,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x36,0x32, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65, - 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31, - 0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x32,0x29,0x29,0x20,0x2d,0x20, - 0x5f,0x31,0x33,0x39,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x34,0x32,0x38,0x20,0x3c,0x3d,0x20, - 0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30, - 0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, - 0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x36,0x34,0x36,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x74,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38, - 0x34,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f, - 0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x37,0x30,0x31,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2e,0x79,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72, - 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x6e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x28,0x5f,0x31,0x36,0x38,0x34,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20, - 0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39, - 0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x37,0x31,0x39,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x36, - 0x38,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x37,0x33,0x30,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, - 0x37,0x30,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x31,0x37,0x35,0x30,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x37, - 0x31,0x35,0x2c,0x20,0x5f,0x31,0x37,0x31,0x35,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, - 0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32, - 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20, - 0x5f,0x31,0x37,0x31,0x39,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73, - 0x28,0x5f,0x31,0x36,0x38,0x34,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20, - 0x5f,0x31,0x37,0x33,0x30,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73, - 0x28,0x5f,0x31,0x37,0x30,0x31,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x35,0x38,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x36,0x34,0x36,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, - 0x31,0x37,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65, - 0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, - 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x39,0x2e,0x7a,0x20,0x2f, - 0x20,0x5f,0x31,0x37,0x35,0x39,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x39,0x31,0x20, - 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x37,0x35, - 0x38,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34, - 0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x5f,0x31,0x37,0x39,0x31,0x2c,0x20,0x5f,0x31,0x37,0x39,0x31, - 0x2c,0x20,0x5f,0x31,0x37,0x39,0x31,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, - 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, - 0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77, - 0x20,0x2a,0x20,0x5f,0x31,0x37,0x35,0x38,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x38,0x31,0x39,0x20,0x3d, - 0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, - 0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x38,0x32,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69, - 0x63,0x65,0x73,0x5b,0x5f,0x31,0x38,0x31,0x39,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x37, - 0x35,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x5f,0x31,0x38,0x33,0x36,0x20,0x3d,0x20,0x5f,0x31,0x38,0x32,0x39, - 0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31, - 0x38,0x32,0x39,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x38,0x35,0x33,0x20,0x3d,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x38,0x33,0x36,0x2e,0x78,0x20,0x2a, - 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f, - 0x31,0x38,0x33,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20, - 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31, - 0x38,0x33,0x36,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x35,0x38,0x20,0x3d,0x20,0x61,0x6e,0x79, - 0x28,0x5f,0x31,0x38,0x35,0x33,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x38,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x38,0x35,0x38,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x36,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79, - 0x28,0x5f,0x31,0x38,0x35,0x33,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x5f,0x31,0x38,0x36,0x35,0x20,0x3d,0x20,0x5f,0x31,0x38,0x35, - 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x38, - 0x36,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x38,0x31,0x39,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20, - 0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54, - 0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73, - 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30, - 0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x39,0x32,0x34,0x20,0x3d, - 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73, - 0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, - 0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74, - 0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f, - 0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29, - 0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x32,0x35,0x20,0x3d, - 0x20,0x5f,0x31,0x39,0x32,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x39,0x32,0x35, - 0x2c,0x20,0x5f,0x31,0x39,0x32,0x35,0x2c,0x20,0x5f,0x31,0x39,0x32,0x35,0x2c,0x20, - 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79, + 0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x34,0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f, + 0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f, + 0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e, + 0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32, + 0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74, + 0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f, + 0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76, + 0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x34,0x38,0x20,0x3d,0x20,0x5f,0x31,0x35,0x34, + 0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30, + 0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x5f,0x31,0x35,0x34, + 0x38,0x2c,0x20,0x5f,0x31,0x35,0x34,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x32, + 0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65, + 0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x34,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x36,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, + 0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, - 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x37, - 0x35,0x38,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x5f,0x31,0x39,0x37,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d, - 0x20,0x5f,0x31,0x36,0x34,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x75, - 0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x75,0x6e, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, - 0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x69, + 0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x69, 0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30, - 0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x37,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20, - 0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74, - 0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, - 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73, - 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68, - 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b, - 0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x35, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, - 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x36,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x32,0x30,0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f, - 0x31,0x34,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75, - 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, - 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, - 0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x32, - 0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x32,0x30,0x35,0x33,0x2c,0x20,0x5f,0x32,0x30, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x37,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a, + 0x20,0x5f,0x31,0x30,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29, + 0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41, + 0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73, + 0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x34,0x38, + 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x37,0x35,0x2c,0x20,0x5f,0x31,0x36,0x37, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* capsule_impostor_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -6587,46 +5469,37 @@ static inline const sg_shader_desc* capsule_impostor_shader_desc(sg_backend back desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_1071.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_707.sun_dir_world"; desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_1071.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_707.sun_color"; desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_1071.flags"; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_707.flags"; desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_1071.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_707.camera_pos"; desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_1071.view_proj"; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_707.view_proj"; desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_1071.view"; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_707.view"; desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_1071.cascade_far_view_z"; - desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[7].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_1071.cascade_texel_world"; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_707.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_707.cascade_matrices"; desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_1071.cascade_depth_bias"; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_707.sh"; desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_1071.shadow_params"; - desc.uniform_blocks[1].glsl_uniforms[10].type = SG_UNIFORMTYPE_MAT4; - desc.uniform_blocks[1].glsl_uniforms[10].array_count = 4; - desc.uniform_blocks[1].glsl_uniforms[10].glsl_name = "_1071.cascade_matrices"; - desc.uniform_blocks[1].glsl_uniforms[11].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[11].array_count = 9; - desc.uniform_blocks[1].glsl_uniforms[11].glsl_name = "_1071.sh"; - desc.uniform_blocks[1].glsl_uniforms[12].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[12].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[12].glsl_name = "_1071.ibl_params"; + desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_707.ibl_params"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -6700,7 +5573,7 @@ static inline const sg_shader_desc* capsule_impostor_shader_desc(sg_backend back desc.uniform_blocks[0].hlsl_register_b_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; @@ -6773,7 +5646,7 @@ static inline const sg_shader_desc* capsule_impostor_shader_desc(sg_backend back desc.uniform_blocks[0].msl_buffer_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; diff --git a/samples/shaders/generated/cube.glsl.h b/samples/shaders/generated/cube.glsl.h index 72714ad..70d5460 100644 --- a/samples/shaders/generated/cube.glsl.h +++ b/samples/shaders/generated/cube.glsl.h @@ -106,10 +106,7 @@ SOKOL_SHDC_ALIGN(16) typedef struct ub_pass_t { Vec4 sun_color; int flags[4]; Vec4 cascade_far_view_z; - Vec4 cascade_texel_world; - Vec4 cascade_depth_bias; - Vec4 shadow_params; - Mat4 cascade_matrices[4]; + Mat4 cascade_matrices[3]; Mat4 view; Vec4 camera_pos_world; Vec4 sh[9]; @@ -248,17 +245,14 @@ static const uint8_t vs_source_glsl430[1126] = { vec4 sun_color; ivec4 flags; vec4 cascade_far_view_z; - vec4 cascade_texel_world; - vec4 cascade_depth_bias; - vec4 shadow_params; - mat4 cascade_matrices[4]; + mat4 cascade_matrices[3]; mat4 view; vec4 camera_pos_world; vec4 sh[9]; vec4 ibl_params; }; - uniform ub_pass _1073; + uniform ub_pass _706; layout(binding = 0) uniform sampler2D tex_ao_smp_ao; layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; @@ -271,219 +265,95 @@ static const uint8_t vs_source_glsl430[1126] = { layout(location = 2) flat in vec4 v_base_color; layout(location = 3) flat in vec4 v_material; - int selectShadowCascade(vec4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; + float _528 = float(cascade); + float _533 = light_uv.z - bias; + float _549 = light_uv.x - 0.00048828125; + float _553 = light_uv.y - 0.00048828125; + float _583 = light_uv.x + 0.00048828125; + float _651 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_549, _553, _528, _533).xyz, _533)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _553, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, _553, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_549, light_uv.y, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, light_uv.y, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_549, _651, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _651, _528, _533).xyz, _533))) + texture(tex_shadow_smp_shadow, vec4(vec4(_583, _651, _528, _533).xyz, _533))) * 0.111111111938953399658203125; } - vec3 shadowCascadeTint(int cascade) + float sampleCascade(int cascade, vec3 world_pos, float n_dot_l) { - if (cascade == 0) + vec4 _716 = _706.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _723 = _716.xyz / vec3(_716.w); + vec3 _741 = vec3((_723.x * 0.5) + 0.5, ((_723.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _723.z); + bool _745 = any(lessThan(_741, vec3(0.0))); + bool _752; + if (!_745) { - return vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + _752 = any(greaterThan(_741, vec3(1.0))); } - if (cascade == 1) + else { - return vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + _752 = _745; } + if (_752) + { + return 1.0; + } + float _759 = clamp(n_dot_l, 0.001000000047497451305389404296875, 1.0); + int param = cascade; + vec3 param_1 = _741; + float param_2 = clamp(0.001000000047497451305389404296875 * (sqrt(1.0 - (_759 * _759)) / _759), 0.0005000000237487256526947021484375, 0.0500000007450580596923828125); + float pcf = sampleShadowPCF(param, param_1, param_2); if (cascade == 2) { - return vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + vec2 _790 = _741.xy; + vec2 _795 = min(_790, vec2(1.0) - _790); + pcf = mix(1.0, pcf, clamp(min(_795.x, _795.y) * 10.0, 0.0, 1.0)); } - return vec3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); + return pcf; } - float sampleShadowTap(vec2 uv, float layer, float ref_z, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) + float sampleShadowCascaded(vec3 world_pos, float n_dot_l, float view_z) { - return texture(SPIRV_Cross_Combinedtexsmp, vec4(vec4(uv, layer, ref_z).xyz, ref_z)); - } - - float sampleShadowPCF(int cascade, vec3 light_uv, float bias, float scale, float inv_size, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - float _617 = float(cascade); - float _622 = light_uv.z - bias; - vec2 _627 = light_uv.xy * (1.0 / inv_size); - vec2 _632 = floor(_627 + vec2(0.5)); - float _639 = (_627.x + 0.5) - _632.x; - float _646 = (_627.y + 0.5) - _632.y; - vec2 _651 = (_632 - vec2(0.5)) * inv_size; - float _655 = inv_size * scale; - float _658 = 5.0 * _639; - float _660 = _658 - 6.0; - float _664 = 11.0 * _639; - float _666 = _664 - 28.0; - float _672 = (-17.0) - _664; - float _677 = (-1.0) - _658; - float _681 = 4.0 * _639; - float _685 = ((_681 - 5.0) / _660) - 3.0; - float _693 = ((_681 - 16.0) / _666) - 1.0; - float _702 = (((-5.0) - (7.0 * _639)) / _672) + 1.0; - float _708 = ((-_639) / _677) + 3.0; - float _711 = 5.0 * _646; - float _712 = _711 - 6.0; - float _715 = 11.0 * _646; - float _716 = _715 - 28.0; - float _721 = (-17.0) - _715; - float _726 = (-1.0) - _711; - float _729 = 4.0 * _646; - float _733 = ((_729 - 5.0) / _712) - 3.0; - float _740 = ((_729 - 16.0) / _716) - 1.0; - float _748 = (((-5.0) - (7.0 * _646)) / _721) + 1.0; - float _754 = ((-_646) / _726) + 3.0; - float sum = 0.0; - vec2 param = _651 + (vec2(_685, _733) * _655); - float param_1 = _617; - float param_2 = _622; - sum += ((_660 * _712) * sampleShadowTap(param, param_1, param_2, SPIRV_Cross_Combinedtexsmp)); - vec2 param_3 = _651 + (vec2(_693, _733) * _655); - float param_4 = _617; - float param_5 = _622; - sum += ((_666 * _712) * sampleShadowTap(param_3, param_4, param_5, SPIRV_Cross_Combinedtexsmp)); - vec2 param_6 = _651 + (vec2(_702, _733) * _655); - float param_7 = _617; - float param_8 = _622; - sum += ((_672 * _712) * sampleShadowTap(param_6, param_7, param_8, SPIRV_Cross_Combinedtexsmp)); - vec2 param_9 = _651 + (vec2(_708, _733) * _655); - float param_10 = _617; - float param_11 = _622; - sum += ((_677 * _712) * sampleShadowTap(param_9, param_10, param_11, SPIRV_Cross_Combinedtexsmp)); - vec2 param_12 = _651 + (vec2(_685, _740) * _655); - float param_13 = _617; - float param_14 = _622; - sum += ((_660 * _716) * sampleShadowTap(param_12, param_13, param_14, SPIRV_Cross_Combinedtexsmp)); - vec2 param_15 = _651 + (vec2(_693, _740) * _655); - float param_16 = _617; - float param_17 = _622; - sum += ((_666 * _716) * sampleShadowTap(param_15, param_16, param_17, SPIRV_Cross_Combinedtexsmp)); - vec2 param_18 = _651 + (vec2(_702, _740) * _655); - float param_19 = _617; - float param_20 = _622; - sum += ((_672 * _716) * sampleShadowTap(param_18, param_19, param_20, SPIRV_Cross_Combinedtexsmp)); - vec2 param_21 = _651 + (vec2(_708, _740) * _655); - float param_22 = _617; - float param_23 = _622; - sum += ((_677 * _716) * sampleShadowTap(param_21, param_22, param_23, SPIRV_Cross_Combinedtexsmp)); - vec2 param_24 = _651 + (vec2(_685, _748) * _655); - float param_25 = _617; - float param_26 = _622; - sum += ((_660 * _721) * sampleShadowTap(param_24, param_25, param_26, SPIRV_Cross_Combinedtexsmp)); - vec2 param_27 = _651 + (vec2(_693, _748) * _655); - float param_28 = _617; - float param_29 = _622; - sum += ((_666 * _721) * sampleShadowTap(param_27, param_28, param_29, SPIRV_Cross_Combinedtexsmp)); - vec2 param_30 = _651 + (vec2(_702, _748) * _655); - float param_31 = _617; - float param_32 = _622; - sum += ((_672 * _721) * sampleShadowTap(param_30, param_31, param_32, SPIRV_Cross_Combinedtexsmp)); - vec2 param_33 = _651 + (vec2(_708, _748) * _655); - float param_34 = _617; - float param_35 = _622; - sum += ((_677 * _721) * sampleShadowTap(param_33, param_34, param_35, SPIRV_Cross_Combinedtexsmp)); - vec2 param_36 = _651 + (vec2(_685, _754) * _655); - float param_37 = _617; - float param_38 = _622; - sum += ((_660 * _726) * sampleShadowTap(param_36, param_37, param_38, SPIRV_Cross_Combinedtexsmp)); - vec2 param_39 = _651 + (vec2(_693, _754) * _655); - float param_40 = _617; - float param_41 = _622; - sum += ((_666 * _726) * sampleShadowTap(param_39, param_40, param_41, SPIRV_Cross_Combinedtexsmp)); - vec2 param_42 = _651 + (vec2(_702, _754) * _655); - float param_43 = _617; - float param_44 = _622; - sum += ((_672 * _726) * sampleShadowTap(param_42, param_43, param_44, SPIRV_Cross_Combinedtexsmp)); - vec2 param_45 = _651 + (vec2(_708, _754) * _655); - float param_46 = _617; - float param_47 = _622; - float _1058 = sum; - float _1059 = _1058 + ((_677 * _726) * sampleShadowTap(param_45, param_46, param_47, SPIRV_Cross_Combinedtexsmp)); - sum = _1059; - return _1059 * 0.000369822490029036998748779296875; - } - - float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal, float n_dot_l) - { - float _1088 = clamp(_1073.cascade_texel_world.x / _1073.cascade_texel_world[cascade], 0.25, 1.0); - float _1098 = 3.0 * _1088; - vec4 _1120 = _1073.cascade_matrices[cascade] * vec4(world_pos + (world_normal * ((((_1098 + 0.5) * 1.41420996189117431640625) * sqrt(max(1.0 - (n_dot_l * n_dot_l), 0.0))) * _1073.cascade_texel_world[cascade])), 1.0); - vec3 _1128 = _1120.xyz / vec3(_1120.w); - float _1144 = _1128.z; - vec3 _1145 = vec3((_1128.x * 0.5) + 0.5, ((_1128.y * _1073.shadow_params.x) * 0.5) + 0.5, _1144); - bool _1148 = _1144 < 0.0; - bool _1155; - if (!_1148) + int cascade = 2; + if (view_z < _706.cascade_far_view_z.x) { - _1155 = _1144 > 1.0; + cascade = 0; } else { - _1155 = _1148; - } - if (_1155) - { - return 1.0; - } - float _1165 = (_1098 + 1.0) * _1073.shadow_params.y; - vec2 _1167 = _1145.xy; - bool _1173 = any(lessThan(_1167, vec2(-_1165))); - bool _1184; - if (!_1173) - { - _1184 = any(greaterThan(_1167, vec2(1.0 + _1165))); - } - else - { - _1184 = _1173; - } - if (_1184) - { - return 1.0; + if (view_z < _706.cascade_far_view_z.y) + { + cascade = 1; + } } int param = cascade; - vec3 param_1 = _1145; - float param_2 = _1073.cascade_depth_bias[cascade]; - float param_3 = _1088; - float param_4 = _1073.shadow_params.y; - return sampleShadowPCF(param, param_1, param_2, param_3, param_4, tex_shadow_smp_shadow); - } - - float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float n_dot_l, float view_z) - { - vec4 param = _1073.cascade_far_view_z; - float param_1 = view_z; - int _1211 = selectShadowCascade(param, param_1); - int param_2 = _1211; - vec3 param_3 = world_pos; - vec3 param_4 = world_normal; - float param_5 = n_dot_l; - float shadow = sampleCascade(param_2, param_3, param_4, param_5); - if (_1211 < 3) + vec3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) { - float _1233; - if (_1211 == 0) + float _840; + if (cascade == 0) { - _1233 = 0.0; + _840 = _706.cascade_far_view_z.x; } else { - _1233 = _1073.cascade_far_view_z[_1211 - 1]; + _840 = _706.cascade_far_view_z.y; } - float _1246 = mix(_1073.cascade_far_view_z[_1211], _1233, 0.100000001490116119384765625); - if (view_z > _1246) + float _852; + if (cascade == 0) { - int param_6 = _1211 + 1; - vec3 param_7 = world_pos; - vec3 param_8 = world_normal; - float param_9 = n_dot_l; - shadow = mix(shadow, sampleCascade(param_6, param_7, param_8, param_9), (view_z - _1246) / (_1073.cascade_far_view_z[_1211] - _1246)); + _852 = 0.0; + } + else + { + _852 = _706.cascade_far_view_z.x; + } + float _863 = mix(_840, _852, 0.100000001490116119384765625); + if (view_z > _863) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _863) / (_840 - _863)); } } return shadow; @@ -491,56 +361,56 @@ static const uint8_t vs_source_glsl430[1126] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _135 = alpha * alpha; - float _144 = ((n_dot_h * n_dot_h) * (_135 - 1.0)) + 1.0; - return _135 / ((3.1415927410125732421875 * _144) * _144); + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0)) + 1.0; + return _106 / ((3.1415927410125732421875 * _115) * _115); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _157 = alpha * alpha; - float _164 = 1.0 - _157; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _164) + _157)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _164) + _157))) + 9.9999997473787516355514526367188e-06); + float _128 = alpha * alpha; + float _135 = 1.0 - _128; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06); } vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) { - float _193 = 1.0 - v_dot_h; - float _197 = _193 * _193; - return f0 + ((vec3(1.0) - f0) * ((_197 * _197) * _193)); + float _164 = 1.0 - v_dot_h; + float _168 = _164 * _164; + return f0 + ((vec3(1.0) - f0) * ((_168 * _168) * _164)); } vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) { - float _216 = max(dot(N, L), 0.0); - vec3 _227 = normalize(V + L); - float _241 = max(roughness, 0.04500000178813934326171875); - float _245 = _241 * _241; - float param = max(dot(N, _227), 0.0); - float param_1 = _245; + float _187 = max(dot(N, L), 0.0); + vec3 _198 = normalize(V + L); + float _212 = max(roughness, 0.04500000178813934326171875); + float _216 = _212 * _212; + float param = max(dot(N, _198), 0.0); + float param_1 = _216; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _216; - float param_4 = _245; - float param_5 = max(dot(V, _227), 0.0); + float param_3 = _187; + float param_4 = _216; + float param_5 = max(dot(V, _198), 0.0); vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); - vec3 _272 = pbrFresnelSchlick(param_5, param_6); - return ((((((vec3(1.0) - _272) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_272 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _216; + vec3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _243) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; } vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) { - vec3 _426 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _426; + vec3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _398; } vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) { - float _433 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - vec3 _443 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + float _405 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _415 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); vec3 param = N_world; vec4 param_1[9] = sh; - vec4 _507 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_433, roughness)); - return (((((vec3(1.0) - (_443 + ((max(vec3(1.0 - roughness), _443) - _443) * pow(max(0.0, 1.0 - _433), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_443 * _507.x) + vec3(_507.y))); + vec4 _481 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_405, roughness)); + return (((((vec3(1.0) - (_415 + ((max(vec3(1.0 - roughness), _415) - _415) * pow(max(0.0, 1.0 - _405), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_415 * _481.x) + vec3(_481.y))); } vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) @@ -562,91 +432,111 @@ static const uint8_t vs_source_glsl430[1126] = { void main() { - vec3 _1280 = dFdx(v_view_pos); - vec3 _1283 = dFdy(v_view_pos); - vec3 _1292 = normalize(cross(_1283 * (-_1073.shadow_params.x), _1280)); - float _1297 = -v_view_pos.z; - if (_1073.flags.x == 1) + vec3 _895 = dFdx(v_view_pos); + vec3 _898 = dFdy(v_view_pos); + vec3 _907 = normalize(cross(_898 * (-_706.cascade_far_view_z.w), _895)); + float _912 = -v_view_pos.z; + if (_706.flags.x == 1) { - float _1308 = clamp(v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); - out_color = vec4(_1308, _1308, _1308, 1.0); + float _923 = clamp(v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_923, _923, _923, 1.0); return; } - if (_1073.flags.x == 2) + if (_706.flags.x == 2) { - vec4 param = _1073.cascade_far_view_z; - float param_1 = _1297; - int _1325 = selectShadowCascade(param, param_1); - vec4 _1336 = _1073.cascade_matrices[_1325] * vec4(v_world_pos, 1.0); - vec3 _1343 = _1336.xyz / vec3(_1336.w); - vec3 _1360 = vec3((_1343.x * 0.5) + 0.5, ((_1343.y * _1073.shadow_params.x) * 0.5) + 0.5, _1343.z); - bool _1365 = any(lessThan(_1360, vec3(0.0))); - bool _1372; - if (!_1365) + int cascade = 2; + if (_912 < _706.cascade_far_view_z.x) { - _1372 = any(greaterThan(_1360, vec3(1.0))); + cascade = 0; } else { - _1372 = _1365; + if (_912 < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _958 = _706.cascade_matrices[cascade] * vec4(v_world_pos, 1.0); + vec3 _965 = _958.xyz / vec3(_958.w); + vec3 _982 = vec3((_965.x * 0.5) + 0.5, ((_965.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _965.z); + bool _986 = any(lessThan(_982, vec3(0.0))); + bool _993; + if (!_986) + { + _993 = any(greaterThan(_982, vec3(1.0))); + } + else + { + _993 = _986; } vec3 tint = vec3(1.0); - if (!_1372) + if (!_993) { - int param_2 = _1325; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out_color = vec4(tint, 1.0); return; } - if (_1073.flags.x == 3) + if (_706.flags.x == 3) { - out_color = vec4((_1292 * 0.5) + vec3(0.5), 1.0); + out_color = vec4((_907 * 0.5) + vec3(0.5), 1.0); return; } - vec4 _1421 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); - float _1422 = _1421.x; - if (_1073.flags.x == 4) + vec4 _1053 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1054 = _1053.x; + if (_706.flags.x == 4) { - out_color = vec4(_1422, _1422, _1422, 1.0); + out_color = vec4(_1054, _1054, _1054, 1.0); return; } - vec3 _1452 = normalize(transpose(mat3(_1073.view[0].xyz, _1073.view[1].xyz, _1073.view[2].xyz)) * _1292); - vec3 _1457 = normalize(_1073.sun_dir_view.xyz); - vec3 param_3 = v_world_pos; - vec3 param_4 = _1452; - float param_5 = max(dot(_1292, _1457), 0.0); - float param_6 = _1297; - vec3 param_7 = _1292; - vec3 param_8 = normalize(-v_view_pos); - vec3 param_9 = _1457; - vec3 param_10 = _1073.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, param_6); - vec3 param_11 = v_base_color.xyz; - float param_12 = v_material.x; - float param_13 = v_material.y; - bool param_14 = _1073.ibl_params.y > 0.5; - vec3 param_15 = _1452; - vec3 param_16 = normalize(_1073.camera_pos_world.xyz - v_world_pos); - vec3 param_17 = v_base_color.xyz; - float param_18 = v_material.x; - float param_19 = v_material.y; - float param_20 = _1073.sun_color.w; - vec4 param_21[9]; - param_21[0] = _1073.sh[0]; - param_21[1] = _1073.sh[1]; - param_21[2] = _1073.sh[2]; - param_21[3] = _1073.sh[3]; - param_21[4] = _1073.sh[4]; - param_21[5] = _1073.sh[5]; - param_21[6] = _1073.sh[6]; - param_21[7] = _1073.sh[7]; - param_21[8] = _1073.sh[8]; - float param_22 = _1073.ibl_params.x; - out_color = vec4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, param_22, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1422)) * v_base_color.w, v_base_color.w); + vec3 _1072 = normalize(_706.sun_dir_view.xyz); + vec3 param = v_world_pos; + float param_1 = max(dot(_907, _1072), 0.0); + float param_2 = _912; + vec3 param_3 = _907; + vec3 param_4 = normalize(-v_view_pos); + vec3 param_5 = _1072; + vec3 param_6 = _706.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = v_base_color.xyz; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _706.ibl_params.y > 0.5; + vec3 param_11 = normalize(transpose(mat3(_706.view[0].xyz, _706.view[1].xyz, _706.view[2].xyz)) * _907); + vec3 param_12 = normalize(_706.camera_pos_world.xyz - v_world_pos); + vec3 param_13 = v_base_color.xyz; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _706.sun_color.w; + vec4 param_17[9]; + param_17[0] = _706.sh[0]; + param_17[1] = _706.sh[1]; + param_17[2] = _706.sh[2]; + param_17[3] = _706.sh[3]; + param_17[4] = _706.sh[4]; + param_17[5] = _706.sh[5]; + param_17[6] = _706.sh[6]; + param_17[7] = _706.sh[7]; + param_17[8] = _706.sh[8]; + float param_18 = _706.ibl_params.x; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1054)) * v_base_color.w, v_base_color.w); } */ -static const uint8_t fs_source_glsl430[16144] = { +static const uint8_t fs_source_glsl430[11675] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, @@ -654,1009 +544,729 @@ static const uint8_t fs_source_glsl430[16144] = { 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x76, 0x65,0x63,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, 0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d, - 0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, - 0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74, - 0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, - 0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66, - 0x6f,0x72,0x6d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, - 0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f, - 0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, - 0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69, - 0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72, - 0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20, - 0x3d,0x20,0x32,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, - 0x65,0x63,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, - 0x6e,0x67,0x20,0x3d,0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, - 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, - 0x63,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c, - 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, - 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20, - 0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, - 0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, - 0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, - 0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x76,0x65,0x63,0x34,0x20,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20, - 0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x69,0x6e,0x74, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e, - 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, - 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, - 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31, - 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, - 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, - 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, - 0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35, - 0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e, - 0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39, - 0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x72,0x65,0x66,0x5f,0x7a,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44, - 0x41,0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, - 0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, - 0x63,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65, - 0x66,0x5f,0x7a,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x6c,0x69, - 0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69, - 0x61,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x2c, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, + 0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76, + 0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x36,0x3b,0x0a,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, + 0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x31,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x32,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a, - 0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x5f,0x36,0x32,0x37,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, - 0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e, - 0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x5f,0x36,0x33,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f, - 0x36,0x32,0x37,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x39, - 0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x37,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x32,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x36,0x20,0x3d,0x20,0x28,0x5f,0x36, - 0x32,0x37,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36, - 0x33,0x32,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f, - 0x36,0x35,0x31,0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x32,0x20,0x2d,0x20,0x76,0x65, - 0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73, - 0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x35,0x35,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a, - 0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f, - 0x36,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x36,0x30,0x20,0x3d,0x20,0x5f,0x36,0x35,0x38,0x20,0x2d,0x20,0x36,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x34, - 0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x36,0x20,0x3d, - 0x20,0x5f,0x36,0x36,0x34,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x32,0x20,0x3d,0x20,0x28, - 0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x34,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x37,0x20,0x3d,0x20, - 0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x38,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20,0x3d,0x20, - 0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x35,0x20,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x38,0x31,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36, - 0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x33,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36,0x38, - 0x31,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36,0x36, - 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x30,0x32,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e, - 0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39, - 0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x32,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x38, - 0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x39,0x29,0x20,0x2f,0x20,0x5f,0x36, - 0x37,0x37,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x31,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20, - 0x2a,0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x31,0x32,0x20,0x3d,0x20,0x5f,0x37,0x31,0x31,0x20,0x2d,0x20, - 0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x31,0x35,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31, - 0x36,0x20,0x3d,0x20,0x5f,0x37,0x31,0x35,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x31,0x20, - 0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x36, - 0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x31, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x39, - 0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x33,0x20,0x3d,0x20, - 0x28,0x28,0x5f,0x37,0x32,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20, - 0x5f,0x37,0x31,0x32,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x30,0x20,0x3d,0x20,0x28,0x28, - 0x5f,0x37,0x32,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f, - 0x37,0x31,0x36,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28, - 0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f, - 0x36,0x34,0x36,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2b,0x20, - 0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x35,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34,0x36,0x29,0x20,0x2f, - 0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32, - 0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f, - 0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37, - 0x31,0x32,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, - 0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x39, - 0x33,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, - 0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c, - 0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36, - 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31, - 0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f, - 0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, - 0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36, - 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, - 0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f, - 0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x35, - 0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, - 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28, - 0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x37,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76, - 0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32, - 0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20, - 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37, - 0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, - 0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f, - 0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x35, - 0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, - 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28, - 0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f, - 0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x39,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76, - 0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32, - 0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20, - 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37, - 0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, - 0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f, - 0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x35, - 0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, - 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28, - 0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f, - 0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x31,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x76, - 0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32, - 0x20,0x2a,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20, - 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37, - 0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30, - 0x35,0x38,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35, - 0x38,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x32, - 0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x37,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, - 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x39, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30, - 0x35,0x39,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32, - 0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37, - 0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38, - 0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x33,0x2e,0x30,0x20,0x2a,0x20, - 0x5f,0x31,0x30,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, - 0x5f,0x31,0x31,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28,0x28,0x5f, - 0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e, - 0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33, - 0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, - 0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x2c,0x20,0x30, - 0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31, - 0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x30,0x2e,0x78,0x79,0x7a,0x20,0x2f, - 0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x31,0x32,0x30,0x2e,0x77,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x34,0x34,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x5f,0x31,0x31,0x34,0x35,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, - 0x28,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, - 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e, - 0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x34,0x34,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x34,0x38,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x34,0x38,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, - 0x35,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3e,0x20,0x31,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, - 0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35, - 0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, - 0x36,0x35,0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x31,0x2e, - 0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x31,0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x34,0x35,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x31,0x31,0x37,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73, - 0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x36,0x37,0x2c,0x20,0x76,0x65,0x63,0x32, - 0x28,0x2d,0x5f,0x31,0x31,0x36,0x35,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x37,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x38,0x34,0x20, - 0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61, - 0x6e,0x28,0x5f,0x31,0x31,0x36,0x37,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e, - 0x30,0x20,0x2b,0x20,0x5f,0x31,0x31,0x36,0x35,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x38,0x34, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x38,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29, + 0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, + 0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b, + 0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, + 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, + 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50, + 0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34, + 0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32, + 0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20,0x5f,0x35, + 0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35, + 0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76, + 0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39, + 0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x37, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x31,0x36, + 0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x37,0x31,0x36, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37, + 0x34,0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34,0x31,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28, + 0x5f,0x37,0x34,0x31,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34, + 0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39, + 0x36,0x38,0x37,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33, + 0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x28,0x73, + 0x71,0x72,0x74,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20, + 0x2a,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x35,0x39,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33, + 0x37,0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36,0x39,0x34,0x37,0x30,0x32,0x31, + 0x34,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33, + 0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x35,0x20,0x3d,0x20, + 0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31, + 0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x35,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a, 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32,0x31, - 0x31,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x31, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31, - 0x31,0x20,0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x32,0x31,0x31,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x32,0x33,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, - 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31, - 0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x32,0x34,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33, - 0x33,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39, - 0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x34,0x36,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x31,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x39,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, - 0x5f,0x31,0x32,0x34,0x36,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20, + 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e, 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x34, - 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35, - 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34, - 0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x35,0x20, - 0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x35,0x20,0x2f, - 0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31, - 0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31, - 0x34,0x34,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, - 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, - 0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20,0x3d, - 0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, - 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x29,0x20,0x2b,0x20,0x5f, - 0x31,0x35,0x37,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, - 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x36,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x37,0x29,0x29,0x29,0x20,0x2b, - 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, - 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, - 0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33, - 0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69, - 0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x33,0x20,0x3d,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x5f,0x31, - 0x39,0x33,0x20,0x2a,0x20,0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28, - 0x28,0x5f,0x31,0x39,0x37,0x20,0x2a,0x20,0x5f,0x31,0x39,0x37,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x39,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, - 0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65, - 0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72, - 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x36,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x32,0x37, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b, - 0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x34,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e, - 0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31, - 0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, - 0x34,0x35,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f, - 0x32,0x32,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x5f,0x32,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, - 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f, - 0x32,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, - 0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, - 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, - 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65, - 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x32,0x37,0x32,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65, - 0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, - 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x32, - 0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c, - 0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38, - 0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30, - 0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x32, - 0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, - 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69, - 0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65, - 0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e, - 0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, - 0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53, - 0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33, - 0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x32,0x36,0x20, - 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30, - 0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37, - 0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, + 0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x36,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f, + 0x38,0x35,0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31, + 0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36, + 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d, + 0x20,0x5f,0x38,0x36,0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30,0x20,0x2d, + 0x20,0x5f,0x38,0x36,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75, + 0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f, + 0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31, + 0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37, + 0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20, + 0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73, + 0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72, + 0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x32,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x33,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x38,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20, + 0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73, + 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, + 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, + 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53, + 0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20, + 0x3d,0x20,0x5f,0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28, + 0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29, + 0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x65,0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73, + 0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x37,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x39,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30, + 0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x31,0x36,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20, + 0x5f,0x32,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, + 0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30, + 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, + 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72, + 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, + 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, + 0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, + 0x33,0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68, + 0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30, + 0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32, + 0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, - 0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e, - 0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33, - 0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e, - 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, - 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, - 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35, - 0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36, - 0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20, - 0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34, - 0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35, - 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32, - 0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76, - 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74, - 0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, - 0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x34,0x33,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28, - 0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, - 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x34, - 0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, - 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, - 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65, - 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x35,0x30,0x37,0x20,0x3d,0x20,0x74,0x65, - 0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x33,0x33,0x2c,0x20,0x72, - 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x33,0x20,0x2b,0x20, - 0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34, - 0x33,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34,0x33,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77, - 0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x5f,0x34,0x33,0x33,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a, - 0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29, - 0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65, - 0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34, - 0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72, - 0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x33,0x20,0x2a,0x20,0x5f, - 0x35,0x30,0x37,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x35, - 0x30,0x37,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33, - 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69, - 0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62, - 0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74, - 0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, - 0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, - 0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69, - 0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d, - 0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78, - 0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34, + 0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35, + 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35, + 0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36, + 0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32, + 0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39, + 0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65, + 0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75, + 0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, - 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3d,0x20,0x64,0x46,0x64, - 0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x38,0x33,0x20,0x3d,0x20, - 0x64,0x46,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x39,0x32, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f, - 0x73,0x73,0x28,0x5f,0x31,0x32,0x38,0x33,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x31,0x30, - 0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x2e,0x78,0x29,0x2c,0x20,0x5f,0x31,0x32,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x37,0x20,0x3d,0x20, - 0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66,0x6c,0x61, - 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76,0x5f,0x76, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, + 0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x35,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x34,0x31,0x35,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x31,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30, + 0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c, + 0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2a, + 0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e, + 0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c, + 0x6f,0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c, + 0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x35, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63, + 0x33,0x28,0x5f,0x34,0x38,0x31,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75, + 0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43, + 0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65, + 0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74, + 0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b, + 0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, + 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x35,0x20,0x3d,0x20, + 0x64,0x46,0x64,0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x38,0x20, + 0x3d,0x20,0x64,0x46,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, + 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30, + 0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72, + 0x6f,0x73,0x73,0x28,0x5f,0x38,0x39,0x38,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x37,0x30, + 0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x2c,0x20,0x5f,0x38,0x39,0x35,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x32,0x20, + 0x3d,0x20,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x32,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x76,0x5f,0x76, 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e, 0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31, 0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30, 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x34,0x28,0x5f,0x31,0x33,0x30,0x38,0x2c,0x20,0x5f,0x31,0x33,0x30,0x38,0x2c, - 0x20,0x5f,0x31,0x33,0x30,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37, - 0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32, - 0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x5f,0x31,0x33,0x32,0x35,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x33,0x33,0x36,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x33,0x32,0x35,0x5d,0x20, - 0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x34,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x33,0x36,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28, - 0x5f,0x31,0x33,0x33,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x36,0x30,0x20,0x3d,0x20,0x76, - 0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x33,0x34,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x33, - 0x34,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20, - 0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x33,0x34, - 0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x33,0x36,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c, - 0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x33,0x36,0x30,0x2c,0x20,0x76, + 0x63,0x34,0x28,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f, + 0x39,0x32,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31, + 0x32,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x39,0x35,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x36,0x35, + 0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65, + 0x63,0x33,0x28,0x5f,0x39,0x35,0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x38,0x32,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36, + 0x35,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f, + 0x39,0x36,0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28, + 0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x39,0x38,0x32,0x2c,0x20,0x76, 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x37,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33, - 0x36,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20, - 0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61, - 0x6e,0x28,0x5f,0x31,0x33,0x36,0x30,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, - 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x36,0x35, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x39,0x38,0x36, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x39,0x33,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f, + 0x39,0x38,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x37,0x32,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66,0x6c,0x61,0x67, - 0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x5f,0x31,0x32,0x39,0x32,0x20, - 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, - 0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x34,0x32,0x31,0x20,0x3d, - 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f, - 0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63, - 0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65, - 0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d, + 0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34, + 0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30, + 0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37,0x32,0x29, 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x32,0x31,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31, - 0x34,0x32,0x32,0x2c,0x20,0x5f,0x31,0x34,0x32,0x32,0x2c,0x20,0x5f,0x31,0x34,0x32, - 0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x35,0x32,0x20,0x3d,0x20, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x74,0x72,0x61,0x6e,0x73,0x70, - 0x6f,0x73,0x65,0x28,0x6d,0x61,0x74,0x33,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x76, - 0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x2e,0x76,0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, - 0x31,0x30,0x37,0x33,0x2e,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a, - 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x39,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x35,0x37,0x20,0x3d,0x20,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x75, - 0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d, - 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x32,0x2c,0x20,0x5f,0x31, - 0x34,0x35,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x32,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x32,0x39,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f, - 0x31,0x34,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e, - 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x39,0x31,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20, + 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72, + 0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x74,0x72,0x61,0x6e,0x73, + 0x70,0x6f,0x73,0x65,0x28,0x6d,0x61,0x74,0x33,0x28,0x5f,0x37,0x30,0x36,0x2e,0x76, + 0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x76,0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29, + 0x20,0x2a,0x20,0x5f,0x39,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e, + 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68, + 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x33, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e, - 0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30, - 0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30, - 0x37,0x33,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, - 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73, - 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x39,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x30, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x31,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x32,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x33,0x5d,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x34,0x5d,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x33,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45, - 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, - 0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a, - 0x20,0x5f,0x31,0x34,0x32,0x32,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, - + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x38,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35, + 0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* struct cube_instance @@ -1902,18 +1512,15 @@ static const uint8_t vs_source_hlsl5[2466] = { /* cbuffer ub_pass : register(b1) { - float4 _1073_sun_dir_view : packoffset(c0); - float4 _1073_sun_color : packoffset(c1); - int4 _1073_flags : packoffset(c2); - float4 _1073_cascade_far_view_z : packoffset(c3); - float4 _1073_cascade_texel_world : packoffset(c4); - float4 _1073_cascade_depth_bias : packoffset(c5); - float4 _1073_shadow_params : packoffset(c6); - row_major float4x4 _1073_cascade_matrices[4] : packoffset(c7); - row_major float4x4 _1073_view : packoffset(c23); - float4 _1073_camera_pos_world : packoffset(c27); - float4 _1073_sh[9] : packoffset(c28); - float4 _1073_ibl_params : packoffset(c37); + float4 _706_sun_dir_view : packoffset(c0); + float4 _706_sun_color : packoffset(c1); + int4 _706_flags : packoffset(c2); + float4 _706_cascade_far_view_z : packoffset(c3); + row_major float4x4 _706_cascade_matrices[3] : packoffset(c4); + row_major float4x4 _706_view : packoffset(c16); + float4 _706_camera_pos_world : packoffset(c20); + float4 _706_sh[9] : packoffset(c21); + float4 _706_ibl_params : packoffset(c30); }; Texture2DArray tex_shadow : register(t0); @@ -1953,221 +1560,95 @@ static const uint8_t vs_source_hlsl5[2466] = { return ret; } - int selectShadowCascade(float4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, float3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; + float _528 = float(cascade); + float _533 = light_uv.z - bias; + float _549 = light_uv.x - 0.00048828125f; + float _553 = light_uv.y - 0.00048828125f; + float _583 = light_uv.x + 0.00048828125f; + float _651 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_549, _553, _528, _533).xyz, _533) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _553, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, _553, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_549, light_uv.y, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, light_uv.y, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_549, _651, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _651, _528, _533).xyz, _533)) + tex_shadow.SampleCmp(smp_shadow, float4(_583, _651, _528, _533).xyz, _533)) * 0.111111111938953399658203125f; } - float3 shadowCascadeTint(int cascade) + float sampleCascade(int cascade, float3 world_pos, float n_dot_l) { - if (cascade == 0) + float4 _716 = mul(float4(world_pos, 1.0f), _706_cascade_matrices[cascade]); + float3 _723 = _716.xyz / _716.w.xxx; + float3 _741 = float3((_723.x * 0.5f) + 0.5f, ((_723.y * _706_cascade_far_view_z.w) * 0.5f) + 0.5f, _723.z); + bool _745 = any(bool3(_741.x < 0.0f.xxx.x, _741.y < 0.0f.xxx.y, _741.z < 0.0f.xxx.z)); + bool _752; + if (!_745) { - return float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + _752 = any(bool3(_741.x > 1.0f.xxx.x, _741.y > 1.0f.xxx.y, _741.z > 1.0f.xxx.z)); } - if (cascade == 1) + else { - return float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + _752 = _745; } + if (_752) + { + return 1.0f; + } + float _759 = clamp(n_dot_l, 0.001000000047497451305389404296875f, 1.0f); + int param = cascade; + float3 param_1 = _741; + float param_2 = clamp(0.001000000047497451305389404296875f * (sqrt(1.0f - (_759 * _759)) / _759), 0.0005000000237487256526947021484375f, 0.0500000007450580596923828125f); + float pcf = sampleShadowPCF(param, param_1, param_2); if (cascade == 2) { - return float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + float2 _790 = _741.xy; + float2 _795 = min(_790, 1.0f.xx - _790); + pcf = lerp(1.0f, pcf, clamp(min(_795.x, _795.y) * 10.0f, 0.0f, 1.0f)); } - return float3(1.0f, 0.89999997615814208984375f, 0.300000011920928955078125f); + return pcf; } - float sampleShadowTap(Texture2DArray tex, SamplerComparisonState smp, float2 uv, float layer, float ref_z) + float sampleShadowCascaded(float3 world_pos, float n_dot_l, float view_z) { - return tex.SampleCmp(smp, float4(uv, layer, ref_z).xyz, ref_z); - } - - float sampleShadowPCF(Texture2DArray tex, SamplerComparisonState smp, int cascade, float3 light_uv, float bias, float scale, float inv_size) - { - float _617 = float(cascade); - float _622 = light_uv.z - bias; - float2 _627 = light_uv.xy * (1.0f / inv_size); - float2 _632 = floor(_627 + 0.5f.xx); - float _639 = (_627.x + 0.5f) - _632.x; - float _646 = (_627.y + 0.5f) - _632.y; - float2 _651 = (_632 - 0.5f.xx) * inv_size; - float _655 = inv_size * scale; - float _658 = 5.0f * _639; - float _660 = _658 - 6.0f; - float _664 = 11.0f * _639; - float _666 = _664 - 28.0f; - float _672 = (-17.0f) - _664; - float _677 = (-1.0f) - _658; - float _681 = 4.0f * _639; - float _685 = ((_681 - 5.0f) / _660) - 3.0f; - float _693 = ((_681 - 16.0f) / _666) - 1.0f; - float _702 = (((-5.0f) - (7.0f * _639)) / _672) + 1.0f; - float _708 = ((-_639) / _677) + 3.0f; - float _711 = 5.0f * _646; - float _712 = _711 - 6.0f; - float _715 = 11.0f * _646; - float _716 = _715 - 28.0f; - float _721 = (-17.0f) - _715; - float _726 = (-1.0f) - _711; - float _729 = 4.0f * _646; - float _733 = ((_729 - 5.0f) / _712) - 3.0f; - float _740 = ((_729 - 16.0f) / _716) - 1.0f; - float _748 = (((-5.0f) - (7.0f * _646)) / _721) + 1.0f; - float _754 = ((-_646) / _726) + 3.0f; - float sum = 0.0f; - float2 param = _651 + (float2(_685, _733) * _655); - float param_1 = _617; - float param_2 = _622; - sum += ((_660 * _712) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _651 + (float2(_693, _733) * _655); - float param_4 = _617; - float param_5 = _622; - sum += ((_666 * _712) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _651 + (float2(_702, _733) * _655); - float param_7 = _617; - float param_8 = _622; - sum += ((_672 * _712) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _651 + (float2(_708, _733) * _655); - float param_10 = _617; - float param_11 = _622; - sum += ((_677 * _712) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _651 + (float2(_685, _740) * _655); - float param_13 = _617; - float param_14 = _622; - sum += ((_660 * _716) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _651 + (float2(_693, _740) * _655); - float param_16 = _617; - float param_17 = _622; - sum += ((_666 * _716) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _651 + (float2(_702, _740) * _655); - float param_19 = _617; - float param_20 = _622; - sum += ((_672 * _716) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _651 + (float2(_708, _740) * _655); - float param_22 = _617; - float param_23 = _622; - sum += ((_677 * _716) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _651 + (float2(_685, _748) * _655); - float param_25 = _617; - float param_26 = _622; - sum += ((_660 * _721) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _651 + (float2(_693, _748) * _655); - float param_28 = _617; - float param_29 = _622; - sum += ((_666 * _721) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _651 + (float2(_702, _748) * _655); - float param_31 = _617; - float param_32 = _622; - sum += ((_672 * _721) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _651 + (float2(_708, _748) * _655); - float param_34 = _617; - float param_35 = _622; - sum += ((_677 * _721) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _651 + (float2(_685, _754) * _655); - float param_37 = _617; - float param_38 = _622; - sum += ((_660 * _726) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _651 + (float2(_693, _754) * _655); - float param_40 = _617; - float param_41 = _622; - sum += ((_666 * _726) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _651 + (float2(_702, _754) * _655); - float param_43 = _617; - float param_44 = _622; - sum += ((_672 * _726) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _651 + (float2(_708, _754) * _655); - float param_46 = _617; - float param_47 = _622; - float _1058 = sum; - float _1059 = _1058 + ((_677 * _726) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1059; - return _1059 * 0.000369822490029036998748779296875f; - } - - float sampleCascade(int cascade, float3 world_pos, float3 world_normal, float n_dot_l) - { - float _1088 = clamp(_1073_cascade_texel_world.x / _1073_cascade_texel_world[cascade], 0.25f, 1.0f); - float _1098 = 3.0f * _1088; - float4 _1120 = mul(float4(world_pos + (world_normal * ((((_1098 + 0.5f) * 1.41420996189117431640625f) * sqrt(max(1.0f - (n_dot_l * n_dot_l), 0.0f))) * _1073_cascade_texel_world[cascade])), 1.0f), _1073_cascade_matrices[cascade]); - float3 _1128 = _1120.xyz / _1120.w.xxx; - float _1144 = _1128.z; - float3 _1145 = float3((_1128.x * 0.5f) + 0.5f, ((_1128.y * _1073_shadow_params.x) * 0.5f) + 0.5f, _1144); - bool _1148 = _1144 < 0.0f; - bool _1155; - if (!_1148) + int cascade = 2; + if (view_z < _706_cascade_far_view_z.x) { - _1155 = _1144 > 1.0f; + cascade = 0; } else { - _1155 = _1148; - } - if (_1155) - { - return 1.0f; - } - float _1165 = (_1098 + 1.0f) * _1073_shadow_params.y; - float2 _1167 = _1145.xy; - float2 _1170 = (-_1165).xx; - bool _1173 = any(bool2(_1167.x < _1170.x, _1167.y < _1170.y)); - bool _1184; - if (!_1173) - { - float2 _1181 = (1.0f + _1165).xx; - _1184 = any(bool2(_1167.x > _1181.x, _1167.y > _1181.y)); - } - else - { - _1184 = _1173; - } - if (_1184) - { - return 1.0f; + if (view_z < _706_cascade_far_view_z.y) + { + cascade = 1; + } } int param = cascade; - float3 param_1 = _1145; - float param_2 = _1073_cascade_depth_bias[cascade]; - float param_3 = _1088; - float param_4 = _1073_shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); - } - - float sampleShadowCascaded(float3 world_pos, float3 world_normal, float n_dot_l, float view_z) - { - float4 param = _1073_cascade_far_view_z; - float param_1 = view_z; - int _1211 = selectShadowCascade(param, param_1); - int param_2 = _1211; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float param_5 = n_dot_l; - float shadow = sampleCascade(param_2, param_3, param_4, param_5); - if (_1211 < 3) + float3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) { - float _1233; - if (_1211 == 0) + float _840; + if (cascade == 0) { - _1233 = 0.0f; + _840 = _706_cascade_far_view_z.x; } else { - _1233 = _1073_cascade_far_view_z[_1211 - 1]; + _840 = _706_cascade_far_view_z.y; } - float _1246 = lerp(_1073_cascade_far_view_z[_1211], _1233, 0.100000001490116119384765625f); - if (view_z > _1246) + float _852; + if (cascade == 0) { - int param_6 = _1211 + 1; - float3 param_7 = world_pos; - float3 param_8 = world_normal; - float param_9 = n_dot_l; - shadow = lerp(shadow, sampleCascade(param_6, param_7, param_8, param_9), (view_z - _1246) / (_1073_cascade_far_view_z[_1211] - _1246)); + _852 = 0.0f; + } + else + { + _852 = _706_cascade_far_view_z.x; + } + float _863 = lerp(_840, _852, 0.100000001490116119384765625f); + if (view_z > _863) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _863) / (_840 - _863)); } } return shadow; @@ -2175,56 +1656,56 @@ static const uint8_t vs_source_hlsl5[2466] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _135 = alpha * alpha; - float _144 = ((n_dot_h * n_dot_h) * (_135 - 1.0f)) + 1.0f; - return _135 / ((3.1415927410125732421875f * _144) * _144); + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0f)) + 1.0f; + return _106 / ((3.1415927410125732421875f * _115) * _115); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _157 = alpha * alpha; - float _164 = 1.0f - _157; - return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _164) + _157)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _164) + _157))) + 9.9999997473787516355514526367188e-06f); + float _128 = alpha * alpha; + float _135 = 1.0f - _128; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06f); } float3 pbrFresnelSchlick(float v_dot_h, float3 f0) { - float _193 = 1.0f - v_dot_h; - float _197 = _193 * _193; - return f0 + ((1.0f.xxx - f0) * ((_197 * _197) * _193)); + float _164 = 1.0f - v_dot_h; + float _168 = _164 * _164; + return f0 + ((1.0f.xxx - f0) * ((_168 * _168) * _164)); } float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) { - float _216 = max(dot(N, L), 0.0f); - float3 _227 = normalize(V + L); - float _241 = max(roughness, 0.04500000178813934326171875f); - float _245 = _241 * _241; - float param = max(dot(N, _227), 0.0f); - float param_1 = _245; + float _187 = max(dot(N, L), 0.0f); + float3 _198 = normalize(V + L); + float _212 = max(roughness, 0.04500000178813934326171875f); + float _216 = _212 * _212; + float param = max(dot(N, _198), 0.0f); + float param_1 = _216; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); - float param_3 = _216; - float param_4 = _245; - float param_5 = max(dot(V, _227), 0.0f); + float param_3 = _187; + float param_4 = _216; + float param_5 = max(dot(V, _198), 0.0f); float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); - float3 _272 = pbrFresnelSchlick(param_5, param_6); - return ((((((1.0f.xxx - _272) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_272 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _216; + float3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _243) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; } float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) { - float3 _426 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); - return _426; + float3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _398; } float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) { - float _433 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); - float3 _443 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float _405 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _415 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); float3 param = N_world; float4 param_1[9] = sh; - float4 _507 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_433, roughness)); - return (((((1.0f.xxx - (_443 + ((max((1.0f - roughness).xxx, _443) - _443) * pow(max(0.0f, 1.0f - _433), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_443 * _507.x) + _507.y.xxx)); + float4 _481 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_405, roughness)); + return (((((1.0f.xxx - (_415 + ((max((1.0f - roughness).xxx, _415) - _415) * pow(max(0.0f, 1.0f - _405), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_415 * _481.x) + _481.y.xxx)); } float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) @@ -2246,88 +1727,108 @@ static const uint8_t vs_source_hlsl5[2466] = { void frag_main() { - float3 _1280 = ddx(v_view_pos); - float3 _1283 = ddy(v_view_pos); - float3 _1292 = normalize(cross(_1283 * (-_1073_shadow_params.x), _1280)); - float _1297 = -v_view_pos.z; - if (_1073_flags.x == 1) + float3 _895 = ddx(v_view_pos); + float3 _898 = ddy(v_view_pos); + float3 _907 = normalize(cross(_898 * (-_706_cascade_far_view_z.w), _895)); + float _912 = -v_view_pos.z; + if (_706_flags.x == 1) { - float _1308 = clamp(v_view_pos.z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); - out_color = float4(_1308, _1308, _1308, 1.0f); + float _923 = clamp(v_view_pos.z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_923, _923, _923, 1.0f); return; } - if (_1073_flags.x == 2) + if (_706_flags.x == 2) { - float4 param = _1073_cascade_far_view_z; - float param_1 = _1297; - int _1325 = selectShadowCascade(param, param_1); - float4 _1336 = mul(float4(v_world_pos, 1.0f), _1073_cascade_matrices[_1325]); - float3 _1343 = _1336.xyz / _1336.w.xxx; - float3 _1360 = float3((_1343.x * 0.5f) + 0.5f, ((_1343.y * _1073_shadow_params.x) * 0.5f) + 0.5f, _1343.z); - bool _1365 = any(bool3(_1360.x < 0.0f.xxx.x, _1360.y < 0.0f.xxx.y, _1360.z < 0.0f.xxx.z)); - bool _1372; - if (!_1365) + int cascade = 2; + if (_912 < _706_cascade_far_view_z.x) { - _1372 = any(bool3(_1360.x > 1.0f.xxx.x, _1360.y > 1.0f.xxx.y, _1360.z > 1.0f.xxx.z)); + cascade = 0; } else { - _1372 = _1365; + if (_912 < _706_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _958 = mul(float4(v_world_pos, 1.0f), _706_cascade_matrices[cascade]); + float3 _965 = _958.xyz / _958.w.xxx; + float3 _982 = float3((_965.x * 0.5f) + 0.5f, ((_965.y * _706_cascade_far_view_z.w) * 0.5f) + 0.5f, _965.z); + bool _986 = any(bool3(_982.x < 0.0f.xxx.x, _982.y < 0.0f.xxx.y, _982.z < 0.0f.xxx.z)); + bool _993; + if (!_986) + { + _993 = any(bool3(_982.x > 1.0f.xxx.x, _982.y > 1.0f.xxx.y, _982.z > 1.0f.xxx.z)); + } + else + { + _993 = _986; } float3 tint = 1.0f.xxx; - if (!_1372) + if (!_993) { - int param_2 = _1325; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } } out_color = float4(tint, 1.0f); return; } - if (_1073_flags.x == 3) + if (_706_flags.x == 3) { - out_color = float4((_1292 * 0.5f) + 0.5f.xxx, 1.0f); + out_color = float4((_907 * 0.5f) + 0.5f.xxx, 1.0f); return; } - uint _1413_dummy_parameter; - float4 _1421 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1413_dummy_parameter))), 0.0f); - float _1422 = _1421.x; - if (_1073_flags.x == 4) + uint _1045_dummy_parameter; + float4 _1053 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1045_dummy_parameter))), 0.0f); + float _1054 = _1053.x; + if (_706_flags.x == 4) { - out_color = float4(_1422, _1422, _1422, 1.0f); + out_color = float4(_1054, _1054, _1054, 1.0f); return; } - float3 _1452 = normalize(mul(_1292, transpose(float3x3(_1073_view[0].xyz, _1073_view[1].xyz, _1073_view[2].xyz)))); - float3 _1457 = normalize(_1073_sun_dir_view.xyz); - float3 param_3 = v_world_pos; - float3 param_4 = _1452; - float param_5 = max(dot(_1292, _1457), 0.0f); - float param_6 = _1297; - float3 param_7 = _1292; - float3 param_8 = normalize(-v_view_pos); - float3 param_9 = _1457; - float3 param_10 = _1073_sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, param_6); - float3 param_11 = v_base_color.xyz; - float param_12 = v_material.x; - float param_13 = v_material.y; - bool param_14 = _1073_ibl_params.y > 0.5f; - float3 param_15 = _1452; - float3 param_16 = normalize(_1073_camera_pos_world.xyz - v_world_pos); - float3 param_17 = v_base_color.xyz; - float param_18 = v_material.x; - float param_19 = v_material.y; - float param_20 = _1073_sun_color.w; - float4 param_21[9]; - param_21[0] = _1073_sh[0]; - param_21[1] = _1073_sh[1]; - param_21[2] = _1073_sh[2]; - param_21[3] = _1073_sh[3]; - param_21[4] = _1073_sh[4]; - param_21[5] = _1073_sh[5]; - param_21[6] = _1073_sh[6]; - param_21[7] = _1073_sh[7]; - param_21[8] = _1073_sh[8]; - float param_22 = _1073_ibl_params.x; - out_color = float4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_22) * _1422)) * v_base_color.w, v_base_color.w); + float3 _1072 = normalize(_706_sun_dir_view.xyz); + float3 param = v_world_pos; + float param_1 = max(dot(_907, _1072), 0.0f); + float param_2 = _912; + float3 param_3 = _907; + float3 param_4 = normalize(-v_view_pos); + float3 param_5 = _1072; + float3 param_6 = _706_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = v_base_color.xyz; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _706_ibl_params.y > 0.5f; + float3 param_11 = normalize(mul(_907, transpose(float3x3(_706_view[0].xyz, _706_view[1].xyz, _706_view[2].xyz)))); + float3 param_12 = normalize(_706_camera_pos_world.xyz - v_world_pos); + float3 param_13 = v_base_color.xyz; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _706_sun_color.w; + float4 param_17[9]; + param_17[0] = _706_sh[0]; + param_17[1] = _706_sh[1]; + param_17[2] = _706_sh[2]; + param_17[3] = _706_sh[3]; + param_17[4] = _706_sh[4]; + param_17[5] = _706_sh[5]; + param_17[6] = _706_sh[6]; + param_17[7] = _706_sh[7]; + param_17[8] = _706_sh[8]; + float param_18 = _706_ibl_params.x; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1054)) * v_base_color.w, v_base_color.w); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) @@ -2344,1111 +1845,836 @@ static const uint8_t vs_source_hlsl5[2466] = { return stage_output; } */ -static const uint8_t fs_source_hlsl5[17663] = { +static const uint8_t fs_source_hlsl5[13249] = { 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a, - 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61, - 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x66,0x6c,0x61, - 0x67,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, - 0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, - 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, - 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30, - 0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68, - 0x5f,0x62,0x69,0x61,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, - 0x65,0x74,0x28,0x63,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, - 0x73,0x65,0x74,0x28,0x63,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x20, + 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30, + 0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d, + 0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69, + 0x63,0x65,0x73,0x5b,0x33,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x78,0x34,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20, - 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, - 0x63,0x32,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x38,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61, - 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x37,0x29,0x3b,0x0a,0x7d, - 0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61, - 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, - 0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70, - 0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, - 0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20, - 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a, - 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, - 0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, - 0x33,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, - 0x74,0x31,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, - 0x65,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a, - 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54, - 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20, - 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, - 0x65,0x72,0x28,0x73,0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, - 0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d, - 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, - 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58, - 0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3a, - 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, - 0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, - 0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56, - 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, - 0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b, - 0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69, - 0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69, - 0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54, - 0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73, - 0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72, - 0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20, - 0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74, - 0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, - 0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34, - 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, - 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39, - 0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33, - 0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31, - 0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x54,0x65,0x78,0x74, + 0x5f,0x37,0x30,0x36,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66, + 0x73,0x65,0x74,0x28,0x63,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x36,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x28,0x63,0x33,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74, 0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43, - 0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, - 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a, - 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, - 0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, - 0x65,0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61, - 0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x2c,0x20, + 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72, + 0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20, + 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69, + 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, + 0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, + 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f, + 0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72, + 0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54, + 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, + 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61, + 0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32, + 0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65, + 0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61, + 0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72, + 0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44, + 0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c, + 0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50, + 0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28, 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f, 0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x76, - 0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x31,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, - 0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x32,0x37,0x20,0x3d,0x20, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31, - 0x2e,0x30,0x66,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33,0x32, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32,0x37,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x37, - 0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33, - 0x32,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x34,0x36,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x37,0x2e,0x79,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x32,0x2e,0x79,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x35,0x31,0x20, - 0x3d,0x20,0x28,0x5f,0x36,0x33,0x32,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, - 0x78,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x35,0x20,0x3d,0x20, - 0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x38, - 0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x35,0x38,0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x34,0x20,0x3d,0x20,0x31, - 0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x36,0x34,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x32,0x20,0x3d,0x20,0x28,0x2d,0x31, - 0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x34,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x37,0x20,0x3d,0x20,0x28, - 0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x38,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20,0x3d,0x20, - 0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x35,0x20,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x38,0x31,0x20,0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f, - 0x36,0x36,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x33,0x20,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x38,0x31,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20, - 0x5f,0x36,0x36,0x36,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x32,0x20,0x3d,0x20,0x28, - 0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x66, - 0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x32, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x38,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36, - 0x33,0x39,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x37,0x29,0x20,0x2b,0x20,0x33,0x2e, - 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x31,0x31,0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x32, - 0x20,0x3d,0x20,0x5f,0x37,0x31,0x31,0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x35,0x20,0x3d, - 0x20,0x31,0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x36,0x20,0x3d,0x20, - 0x5f,0x37,0x31,0x35,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x31,0x20,0x3d,0x20,0x28, - 0x2d,0x31,0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x36,0x20,0x3d, - 0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x39,0x20, - 0x3d,0x20,0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x33,0x20,0x3d,0x20, - 0x28,0x28,0x5f,0x37,0x32,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20,0x2f, - 0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x30,0x20,0x3d,0x20, - 0x28,0x28,0x5f,0x37,0x32,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29,0x20, - 0x2f,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x38,0x20,0x3d, - 0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e, - 0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37, - 0x32,0x31,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d, - 0x5f,0x36,0x34,0x36,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2b,0x20, - 0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36, - 0x38,0x35,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x36,0x35, - 0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x33, - 0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36,0x35, - 0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x32, - 0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x35, - 0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x38, - 0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x31,0x32,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20, - 0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f, - 0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20, - 0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x34, - 0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30, - 0x32,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f, - 0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20, - 0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37, - 0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29, - 0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f, - 0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37, - 0x32,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31, - 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c, - 0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20, - 0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f, - 0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20, - 0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x35, - 0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30, - 0x32,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x35,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x3d,0x20, - 0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x30,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x38,0x20,0x2b,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35,0x39,0x20,0x2a,0x20,0x30,0x2e, - 0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30, - 0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37, - 0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38,0x38,0x20, - 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35,0x66,0x2c, - 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x30,0x39,0x38,0x20,0x3d,0x20,0x33,0x2e,0x30,0x66,0x20,0x2a, - 0x20,0x5f,0x31,0x30,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x31,0x32,0x30,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x66,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36, - 0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66, - 0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30, - 0x66,0x20,0x2d,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31, - 0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x30,0x2e,0x78,0x79,0x7a,0x20,0x2f, - 0x20,0x5f,0x31,0x31,0x32,0x30,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x32,0x38,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x34,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31, - 0x31,0x32,0x38,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a, - 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f, - 0x31,0x31,0x34,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x31,0x31,0x34,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3c,0x20, - 0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f, - 0x31,0x31,0x34,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34, - 0x34,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x35,0x20,0x3d,0x20,0x28,0x5f, - 0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x5f,0x31,0x31,0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x35,0x2e,0x78, - 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31, - 0x31,0x37,0x30,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x36,0x35,0x29,0x2e,0x78, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x37, - 0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31, - 0x31,0x36,0x37,0x2e,0x78,0x20,0x3c,0x20,0x5f,0x31,0x31,0x37,0x30,0x2e,0x78,0x2c, - 0x20,0x5f,0x31,0x31,0x36,0x37,0x2e,0x79,0x20,0x3c,0x20,0x5f,0x31,0x31,0x37,0x30, - 0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x31,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f, - 0x31,0x31,0x37,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x38,0x31, - 0x20,0x3d,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x5f,0x31,0x31,0x36,0x35, - 0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x31,0x38,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28, - 0x5f,0x31,0x31,0x36,0x37,0x2e,0x78,0x20,0x3e,0x20,0x5f,0x31,0x31,0x38,0x31,0x2e, - 0x78,0x2c,0x20,0x5f,0x31,0x31,0x36,0x37,0x2e,0x79,0x20,0x3e,0x20,0x5f,0x31,0x31, - 0x38,0x31,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x31,0x38,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70, + 0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20, + 0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35, + 0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c, + 0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35, + 0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20, + 0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33, + 0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35, + 0x33,0x33,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20, + 0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38, + 0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x66, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x36,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x31,0x36,0x2e, + 0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x37,0x31,0x36,0x2e,0x77,0x2e,0x78,0x78,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34, + 0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x33, + 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35, + 0x66,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x33,0x2e,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x35,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x31, + 0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c, + 0x20,0x5f,0x37,0x34,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x31,0x2e,0x7a,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x31,0x2e,0x78, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, + 0x37,0x34,0x31,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, + 0x2e,0x79,0x2c,0x20,0x5f,0x37,0x34,0x31,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e, - 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38,0x38,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x5f,0x31,0x32,0x31,0x31,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x32,0x31,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x31,0x20,0x3c,0x20,0x33,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x31,0x20,0x3d,0x3d,0x20,0x30, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x33,0x20,0x3d,0x20, - 0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x34,0x36,0x20,0x3d,0x20, - 0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31, - 0x32,0x31,0x31,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x33,0x2c,0x20,0x30,0x2e,0x31, - 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31, - 0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x20,0x3e,0x20,0x5f,0x31,0x32,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31, - 0x32,0x31,0x31,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x39,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20, - 0x5f,0x31,0x32,0x34,0x36,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x5f, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x34, - 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x30,0x2e,0x30,0x30,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30, + 0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x34,0x37,0x34,0x39,0x37,0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34, + 0x30,0x34,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x28,0x73,0x71,0x72, + 0x74,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x28,0x5f,0x37,0x35,0x39,0x20,0x2a, + 0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x35,0x39,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x32,0x33,0x37, + 0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36,0x39,0x34,0x37,0x30,0x32,0x31,0x34, + 0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x35,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30,0x35,0x39,0x36,0x39,0x32,0x33, + 0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, + 0x37,0x39,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37, + 0x39,0x35,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x20,0x2d,0x20,0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6c,0x65, + 0x72,0x70,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c,0x20, + 0x5f,0x37,0x39,0x35,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35, - 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34, - 0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x35,0x20, - 0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x35, - 0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, - 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a, - 0x20,0x5f,0x31,0x34,0x34,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69, - 0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65, - 0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, - 0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68, - 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, - 0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x35,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66, - 0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20, - 0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a, - 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34, - 0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x37,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, - 0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x37, - 0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, - 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, - 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, - 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x39,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76, - 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x5f,0x31,0x39,0x33,0x20,0x2a,0x20, - 0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x39,0x37,0x20, - 0x2a,0x20,0x5f,0x31,0x39,0x37,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x33,0x29,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66, - 0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73, - 0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, - 0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c, - 0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x32,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x6d, - 0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e, - 0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33, - 0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x35,0x20,0x3d,0x20,0x5f, - 0x32,0x34,0x31,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x37,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x3b, + 0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20, - 0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, - 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, - 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, + 0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x36,0x33,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f,0x38,0x35, + 0x32,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39, + 0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x2d,0x20,0x5f,0x38,0x36,0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30, + 0x20,0x2d,0x20,0x5f,0x38,0x36,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61, + 0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20, + 0x28,0x5f,0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b, + 0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x5f,0x31,0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31, + 0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31, + 0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74, + 0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x5f,0x31,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20,0x3d,0x20,0x5f, + 0x31,0x36,0x34,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28, + 0x28,0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x38,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x38,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20, + 0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, + 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20,0x5f,0x32,0x31,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f, + 0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, 0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20, - 0x5f,0x32,0x32,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, + 0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64, + 0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e, + 0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33, + 0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x70, + 0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20, + 0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38, + 0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30, + 0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28, + 0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72, + 0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72, + 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, + 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x38,0x20,0x3d,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32, + 0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35, + 0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35, + 0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, + 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20, + 0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33, + 0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33, + 0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33, + 0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20, + 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49, + 0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68, + 0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61, + 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, + 0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34, + 0x30,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38, + 0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37, + 0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x35, 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39, 0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31, 0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65, 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, 0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x5f,0x32,0x37,0x32,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, - 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31, - 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32,0x37,0x32,0x29,0x20, - 0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33, - 0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35, - 0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x32,0x20,0x2a, - 0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f, - 0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69, - 0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61, - 0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29, - 0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, - 0x29,0x20,0x2a,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53, - 0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x34,0x32,0x36,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, - 0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38, - 0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39, - 0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, - 0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38, - 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, - 0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, - 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e, - 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35, - 0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35, - 0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30, - 0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37, - 0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a, - 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35, - 0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31, - 0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20, - 0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, - 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, - 0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34, - 0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35, - 0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, - 0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34, - 0x32,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, - 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54, - 0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x31,0x20,0x3d, + 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34, + 0x30,0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28, + 0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20, + 0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29,0x20, + 0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e, + 0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37, + 0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37, + 0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c, + 0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31, + 0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34, + 0x38,0x31,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62, + 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, + 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c, + 0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65, + 0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, 0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73, - 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, - 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x33,0x20,0x3d,0x20,0x63, - 0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, - 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, - 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, - 0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x33,0x20,0x3d,0x20,0x6c,0x65,0x72, - 0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35, - 0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66, - 0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b, - 0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x5f,0x35,0x30,0x37,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, - 0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x33,0x2c,0x20,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e, - 0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x33,0x20,0x2b,0x20,0x28,0x28, - 0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x34,0x33, - 0x29,0x20,0x2d,0x20,0x5f,0x34,0x34,0x33,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28, - 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d, - 0x20,0x5f,0x34,0x33,0x33,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c, - 0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, - 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20, - 0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31, - 0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78, - 0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73, - 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65, - 0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, - 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, - 0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x33,0x20,0x2a,0x20,0x5f,0x35, - 0x30,0x37,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x35,0x30,0x37,0x2e,0x79,0x2e,0x78, - 0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, - 0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, - 0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74, - 0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c, - 0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, - 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73, - 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72, - 0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, - 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f, - 0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, - 0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, - 0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, - 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72, - 0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3d,0x20,0x64, - 0x64,0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x33, - 0x20,0x3d,0x20,0x64,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, - 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x32,0x39,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x31,0x32,0x38,0x33,0x20,0x2a,0x20,0x28, - 0x2d,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x5f,0x31,0x32,0x38,0x30,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39, - 0x37,0x20,0x3d,0x20,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e, - 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33, - 0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, - 0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20, - 0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32, - 0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35, - 0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x30, - 0x38,0x2c,0x20,0x5f,0x31,0x33,0x30,0x38,0x2c,0x20,0x5f,0x31,0x33,0x30,0x38,0x2c, - 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x5f,0x66,0x6c,0x61,0x67, - 0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b, + 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c, + 0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a, + 0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, + 0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x39,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x33,0x32, - 0x35,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x3d,0x20, - 0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, - 0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, - 0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x33,0x32,0x35,0x5d,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, - 0x33,0x34,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x36,0x2e,0x78,0x79,0x7a,0x20, - 0x2f,0x20,0x5f,0x31,0x33,0x33,0x36,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, - 0x33,0x36,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31, - 0x33,0x34,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x33,0x34,0x33,0x2e,0x79,0x20, - 0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29, - 0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x33,0x34,0x33,0x2e,0x7a, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x31,0x33,0x36,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c, - 0x33,0x28,0x5f,0x31,0x33,0x36,0x30,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, - 0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x33,0x36,0x30,0x2e,0x79,0x20, - 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31, - 0x33,0x36,0x30,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x33,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x36,0x35,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28, - 0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x33,0x36,0x30,0x2e,0x78,0x20,0x3e,0x20, - 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x33,0x36, - 0x30,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79, - 0x2c,0x20,0x5f,0x31,0x33,0x36,0x30,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66, - 0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74, - 0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33, - 0x37,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x32,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20, - 0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54, - 0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20, + 0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76, + 0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39, + 0x35,0x20,0x3d,0x20,0x64,0x64,0x78,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x38,0x39,0x38,0x20,0x3d,0x20,0x64,0x64,0x79,0x28,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x38,0x39,0x38,0x20,0x2a, + 0x20,0x28,0x2d,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x2c,0x20,0x5f, + 0x38,0x39,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20, + 0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35, + 0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31, + 0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39, + 0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20, + 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x39,0x36,0x35,0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x5f,0x39,0x35,0x38,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x39,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x39,0x36,0x35, + 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, + 0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, + 0x6c,0x33,0x28,0x5f,0x39,0x38,0x32,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e,0x79,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x39,0x38, + 0x32,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x39,0x38,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33, + 0x28,0x5f,0x39,0x38,0x32,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e,0x79,0x20,0x3e,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x39,0x38,0x32,0x2e, + 0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x30,0x37,0x33,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20,0x2a,0x20, + 0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x78, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x30,0x34,0x35,0x5f,0x64,0x75, + 0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x35,0x33,0x20, + 0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c, + 0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f, + 0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x30,0x34,0x35, + 0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72, + 0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31, + 0x30,0x35,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x37,0x30,0x36,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34, 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x28,0x28,0x5f,0x31,0x32,0x39,0x32,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66, - 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x75, - 0x69,0x6e,0x74,0x20,0x5f,0x31,0x34,0x31,0x33,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x32,0x31,0x20,0x3d,0x20,0x74,0x65, - 0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c, - 0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72, - 0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2c,0x20,0x75,0x69, - 0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x34,0x31,0x33,0x5f,0x64,0x75,0x6d, - 0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x29,0x29,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x32,0x31,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33, - 0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x5f,0x31,0x34,0x32,0x32,0x2c,0x20,0x5f,0x31,0x34,0x32,0x32,0x2c,0x20,0x5f,0x31, - 0x34,0x32,0x32,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34, - 0x35,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d, - 0x75,0x6c,0x28,0x5f,0x31,0x32,0x39,0x32,0x2c,0x20,0x74,0x72,0x61,0x6e,0x73,0x70, - 0x6f,0x73,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x5f,0x31,0x30, - 0x37,0x33,0x5f,0x76,0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x5f,0x76,0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79, - 0x7a,0x2c,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d, - 0x2e,0x78,0x79,0x7a,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x35,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x75,0x6e, - 0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, + 0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c, + 0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37, + 0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, + 0x39,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x34,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d, + 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, - 0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x32,0x2c, - 0x20,0x5f,0x31,0x34,0x35,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x20,0x3d,0x20,0x5f,0x31,0x32,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, - 0x5f,0x31,0x32,0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, - 0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x75,0x6e,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x69,0x62, - 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35, - 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, - 0x5f,0x31,0x30,0x37,0x33,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d, - 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, - 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74, - 0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, + 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d, + 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x5f, + 0x39,0x30,0x37,0x2c,0x20,0x74,0x72,0x61,0x6e,0x73,0x70,0x6f,0x73,0x65,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x5f,0x37,0x30,0x36,0x5f,0x76,0x69,0x65, + 0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x5f,0x76, + 0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x36,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20, + 0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78, + 0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x31,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x31,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x31,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f, - 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x31,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73, - 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68, - 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b, - 0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, - 0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b,0x35, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b, - 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b,0x36,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x37, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x38,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x5f,0x69,0x62,0x6c,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68, + 0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x32, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x5f,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x36,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x5f, + 0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36, + 0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, 0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61, 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, - 0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, - 0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, - 0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32, - 0x32,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f, - 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, - 0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, - 0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, - 0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61, - 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, - 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x30,0x35,0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, + 0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f, + 0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a, + 0x00, }; /* #include @@ -3669,10 +2895,7 @@ static const uint8_t vs_source_metal_macos[1543] = { float4 sun_color; int4 flags; float4 cascade_far_view_z; - float4 cascade_texel_world; - float4 cascade_depth_bias; - float4 shadow_params; - float4x4 cascade_matrices[4]; + float4x4 cascade_matrices[3]; float4x4 view; float4 camera_pos_world; float4 sh[9]; @@ -3693,225 +2916,106 @@ static const uint8_t vs_source_metal_macos[1543] = { }; static inline __attribute__((always_inline)) - int selectShadowCascade(thread const float4& far_view_z, thread const float& view_z) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; + float _528 = float(cascade); + float _533 = light_uv.z - bias0; + float _549 = light_uv.x - 0.00048828125; + float _553 = light_uv.y - 0.00048828125; + float4 _556 = float4(_549, _553, _528, _533); + float4 _572 = float4(light_uv.x, _553, _528, _533); + float _583 = light_uv.x + 0.00048828125; + float4 _590 = float4(_583, _553, _528, _533); + float4 _606 = float4(_549, light_uv.y, _528, _533); + float4 _620 = float4(light_uv.xy, _528, _533); + float4 _636 = float4(_583, light_uv.y, _528, _533); + float _651 = light_uv.y + 0.00048828125; + float4 _654 = float4(_549, _651, _528, _533); + float4 _670 = float4(light_uv.x, _651, _528, _533); + float4 _688 = float4(_583, _651, _528, _533); + return ((((((((tex_shadow.sample_compare(smp_shadow, _556.xy, uint(rint(_556.z)), _533) + tex_shadow.sample_compare(smp_shadow, _572.xy, uint(rint(_572.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _590.xy, uint(rint(_590.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _606.xy, uint(rint(_606.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _620.xy, uint(rint(_620.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _636.xy, uint(rint(_636.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _654.xy, uint(rint(_654.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _670.xy, uint(rint(_670.z)), _533)) + tex_shadow.sample_compare(smp_shadow, _688.xy, uint(rint(_688.z)), _533)) * 0.111111111938953399658203125; } static inline __attribute__((always_inline)) - float3 shadowCascadeTint(thread const int& cascade) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float& n_dot_l, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _706) { - if (cascade == 0) + float4 _716 = _706.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _723 = _716.xyz / float3(_716.w); + float3 _741 = float3((_723.x * 0.5) + 0.5, ((_723.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _723.z); + bool _745 = any(_741 < float3(0.0)); + bool _752; + if (!_745) { - return float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + _752 = any(_741 > float3(1.0)); } - if (cascade == 1) + else { - return float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + _752 = _745; } + if (_752) + { + return 1.0; + } + float _759 = fast::clamp(n_dot_l, 0.001000000047497451305389404296875, 1.0); + int param = cascade; + float3 param_1 = _741; + float param_2 = fast::clamp(0.001000000047497451305389404296875 * (sqrt(1.0 - (_759 * _759)) / _759), 0.0005000000237487256526947021484375, 0.0500000007450580596923828125); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); if (cascade == 2) { - return float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + float2 _790 = _741.xy; + float2 _795 = fast::min(_790, float2(1.0) - _790); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_795.x, _795.y) * 10.0, 0.0, 1.0)); } - return float3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); + return pcf; } static inline __attribute__((always_inline)) - float sampleShadowTap(depth2d_array tex, sampler smp, thread const float2& uv, thread const float& layer, thread const float& ref_z) + float sampleShadowCascaded(thread const float3& world_pos, thread const float& n_dot_l, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _706) { - float4 _607 = float4(uv, layer, ref_z); - return tex.sample_compare(smp, _607.xy, uint(rint(_607.z)), ref_z); - } - - static inline __attribute__((always_inline)) - float sampleShadowPCF(depth2d_array tex, sampler smp, thread const int& cascade, thread const float3& light_uv, thread const float& bias0, thread const float& scale, thread const float& inv_size) - { - float _617 = float(cascade); - float _622 = light_uv.z - bias0; - float2 _627 = light_uv.xy * (1.0 / inv_size); - float2 _632 = floor(_627 + float2(0.5)); - float _639 = (_627.x + 0.5) - _632.x; - float _646 = (_627.y + 0.5) - _632.y; - float2 _651 = (_632 - float2(0.5)) * inv_size; - float _655 = inv_size * scale; - float _658 = 5.0 * _639; - float _660 = _658 - 6.0; - float _664 = 11.0 * _639; - float _666 = _664 - 28.0; - float _672 = (-17.0) - _664; - float _677 = (-1.0) - _658; - float _681 = 4.0 * _639; - float _685 = ((_681 - 5.0) / _660) - 3.0; - float _693 = ((_681 - 16.0) / _666) - 1.0; - float _702 = (((-5.0) - (7.0 * _639)) / _672) + 1.0; - float _708 = ((-_639) / _677) + 3.0; - float _711 = 5.0 * _646; - float _712 = _711 - 6.0; - float _715 = 11.0 * _646; - float _716 = _715 - 28.0; - float _721 = (-17.0) - _715; - float _726 = (-1.0) - _711; - float _729 = 4.0 * _646; - float _733 = ((_729 - 5.0) / _712) - 3.0; - float _740 = ((_729 - 16.0) / _716) - 1.0; - float _748 = (((-5.0) - (7.0 * _646)) / _721) + 1.0; - float _754 = ((-_646) / _726) + 3.0; - float sum = 0.0; - float2 param = _651 + (float2(_685, _733) * _655); - float param_1 = _617; - float param_2 = _622; - sum += ((_660 * _712) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _651 + (float2(_693, _733) * _655); - float param_4 = _617; - float param_5 = _622; - sum += ((_666 * _712) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _651 + (float2(_702, _733) * _655); - float param_7 = _617; - float param_8 = _622; - sum += ((_672 * _712) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _651 + (float2(_708, _733) * _655); - float param_10 = _617; - float param_11 = _622; - sum += ((_677 * _712) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _651 + (float2(_685, _740) * _655); - float param_13 = _617; - float param_14 = _622; - sum += ((_660 * _716) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _651 + (float2(_693, _740) * _655); - float param_16 = _617; - float param_17 = _622; - sum += ((_666 * _716) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _651 + (float2(_702, _740) * _655); - float param_19 = _617; - float param_20 = _622; - sum += ((_672 * _716) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _651 + (float2(_708, _740) * _655); - float param_22 = _617; - float param_23 = _622; - sum += ((_677 * _716) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _651 + (float2(_685, _748) * _655); - float param_25 = _617; - float param_26 = _622; - sum += ((_660 * _721) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _651 + (float2(_693, _748) * _655); - float param_28 = _617; - float param_29 = _622; - sum += ((_666 * _721) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _651 + (float2(_702, _748) * _655); - float param_31 = _617; - float param_32 = _622; - sum += ((_672 * _721) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _651 + (float2(_708, _748) * _655); - float param_34 = _617; - float param_35 = _622; - sum += ((_677 * _721) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _651 + (float2(_685, _754) * _655); - float param_37 = _617; - float param_38 = _622; - sum += ((_660 * _726) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _651 + (float2(_693, _754) * _655); - float param_40 = _617; - float param_41 = _622; - sum += ((_666 * _726) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _651 + (float2(_702, _754) * _655); - float param_43 = _617; - float param_44 = _622; - sum += ((_672 * _726) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _651 + (float2(_708, _754) * _655); - float param_46 = _617; - float param_47 = _622; - float _1058 = sum; - float _1059 = _1058 + ((_677 * _726) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1059; - return _1059 * 0.000369822490029036998748779296875; - } - - static inline __attribute__((always_inline)) - float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, thread const float& n_dot_l, constant ub_pass& _1073, depth2d_array tex_shadow, sampler smp_shadow) - { - float _1088 = fast::clamp(_1073.cascade_texel_world.x / _1073.cascade_texel_world[cascade], 0.25, 1.0); - float _1098 = 3.0 * _1088; - float4 _1120 = _1073.cascade_matrices[cascade] * float4(world_pos + (world_normal * ((((_1098 + 0.5) * 1.41420996189117431640625) * sqrt(fast::max(1.0 - (n_dot_l * n_dot_l), 0.0))) * _1073.cascade_texel_world[cascade])), 1.0); - float3 _1128 = _1120.xyz / float3(_1120.w); - float _1144 = _1128.z; - float3 _1145 = float3((_1128.x * 0.5) + 0.5, ((_1128.y * _1073.shadow_params.x) * 0.5) + 0.5, _1144); - bool _1148 = _1144 < 0.0; - bool _1155; - if (!_1148) + int cascade = 2; + if (view_z < _706.cascade_far_view_z.x) { - _1155 = _1144 > 1.0; + cascade = 0; } else { - _1155 = _1148; - } - if (_1155) - { - return 1.0; - } - float _1165 = (_1098 + 1.0) * _1073.shadow_params.y; - float2 _1167 = _1145.xy; - bool _1173 = any(_1167 < float2(-_1165)); - bool _1184; - if (!_1173) - { - _1184 = any(_1167 > float2(1.0 + _1165)); - } - else - { - _1184 = _1173; - } - if (_1184) - { - return 1.0; + if (view_z < _706.cascade_far_view_z.y) + { + cascade = 1; + } } int param = cascade; - float3 param_1 = _1145; - float param_2 = _1073.cascade_depth_bias[cascade]; - float param_3 = _1088; - float param_4 = _1073.shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); - } - - static inline __attribute__((always_inline)) - float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& n_dot_l, thread const float& view_z, constant ub_pass& _1073, depth2d_array tex_shadow, sampler smp_shadow) - { - float4 param = _1073.cascade_far_view_z; - float param_1 = view_z; - int _1211 = selectShadowCascade(param, param_1); - int param_2 = _1211; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float param_5 = n_dot_l; - float shadow = sampleCascade(param_2, param_3, param_4, param_5, _1073, tex_shadow, smp_shadow); - if (_1211 < 3) + float3 param_1 = world_pos; + float param_2 = n_dot_l; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _706); + if (cascade < 2) { - float _1233; - if (_1211 == 0) + float _840; + if (cascade == 0) { - _1233 = 0.0; + _840 = _706.cascade_far_view_z.x; } else { - _1233 = _1073.cascade_far_view_z[_1211 - 1]; + _840 = _706.cascade_far_view_z.y; } - float _1246 = mix(_1073.cascade_far_view_z[_1211], _1233, 0.100000001490116119384765625); - if (view_z > _1246) + float _852; + if (cascade == 0) { - int param_6 = _1211 + 1; - float3 param_7 = world_pos; - float3 param_8 = world_normal; - float param_9 = n_dot_l; - shadow = mix(shadow, sampleCascade(param_6, param_7, param_8, param_9, _1073, tex_shadow, smp_shadow), (view_z - _1246) / (_1073.cascade_far_view_z[_1211] - _1246)); + _852 = 0.0; + } + else + { + _852 = _706.cascade_far_view_z.x; + } + float _863 = mix(_840, _852, 0.100000001490116119384765625); + if (view_z > _863) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float param_5 = n_dot_l; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _706), (view_z - _863) / (_840 - _863)); } } return shadow; @@ -3920,61 +3024,61 @@ static const uint8_t vs_source_metal_macos[1543] = { static inline __attribute__((always_inline)) float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) { - float _135 = alpha * alpha; - float _144 = ((n_dot_h * n_dot_h) * (_135 - 1.0)) + 1.0; - return _135 / ((3.1415927410125732421875 * _144) * _144); + float _106 = alpha * alpha; + float _115 = ((n_dot_h * n_dot_h) * (_106 - 1.0)) + 1.0; + return _106 / ((3.1415927410125732421875 * _115) * _115); } static inline __attribute__((always_inline)) float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) { - float _157 = alpha * alpha; - float _164 = 1.0 - _157; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _164) + _157)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _164) + _157))) + 9.9999997473787516355514526367188e-06); + float _128 = alpha * alpha; + float _135 = 1.0 - _128; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _135) + _128)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _135) + _128))) + 9.9999997473787516355514526367188e-06); } static inline __attribute__((always_inline)) float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) { - float _193 = 1.0 - v_dot_h; - float _197 = _193 * _193; - return f0 + ((float3(1.0) - f0) * ((_197 * _197) * _193)); + float _164 = 1.0 - v_dot_h; + float _168 = _164 * _164; + return f0 + ((float3(1.0) - f0) * ((_168 * _168) * _164)); } static inline __attribute__((always_inline)) float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) { - float _216 = fast::max(dot(N, L), 0.0); - float3 _227 = fast::normalize(V + L); - float _241 = fast::max(roughness, 0.04500000178813934326171875); - float _245 = _241 * _241; - float param = fast::max(dot(N, _227), 0.0); - float param_1 = _245; + float _187 = fast::max(dot(N, L), 0.0); + float3 _198 = fast::normalize(V + L); + float _212 = fast::max(roughness, 0.04500000178813934326171875); + float _216 = _212 * _212; + float param = fast::max(dot(N, _198), 0.0); + float param_1 = _216; float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _216; - float param_4 = _245; - float param_5 = fast::max(dot(V, _227), 0.0); + float param_3 = _187; + float param_4 = _216; + float param_5 = fast::max(dot(V, _198), 0.0); float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); - float3 _272 = pbrFresnelSchlick(param_5, param_6); - return ((((((float3(1.0) - _272) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_272 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _216; + float3 _243 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _243) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_243 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _187; } static inline __attribute__((always_inline)) float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) { - float3 _426 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _426; + float3 _398 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _398; } static inline __attribute__((always_inline)) float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) { - float _433 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - float3 _443 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float _405 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _415 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); float3 param = N_world; spvUnsafeArray param_1 = sh; - float4 _507 = tex_brdf_lut.sample(smp_brdf_lut, float2(_433, roughness)); - return (((((float3(1.0) - (_443 + ((fast::max(float3(1.0 - roughness), _443) - _443) * powr(fast::max(0.0, 1.0 - _433), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_443 * _507.x) + float3(_507.y))); + float4 _481 = tex_brdf_lut.sample(smp_brdf_lut, float2(_405, roughness)); + return (((((float3(1.0) - (_415 + ((fast::max(float3(1.0 - roughness), _415) - _415) * powr(fast::max(0.0, 1.0 - _405), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_415 * _481.x) + float3(_481.y))); } static inline __attribute__((always_inline)) @@ -3995,95 +3099,115 @@ static const uint8_t vs_source_metal_macos[1543] = { return result; } - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _1073 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _706 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) { main0_out out = {}; - float3 _1280 = dfdx(in.v_view_pos); - float3 _1283 = dfdy(in.v_view_pos); - float3 _1292 = fast::normalize(cross(_1283 * (-_1073.shadow_params.x), _1280)); - float _1297 = -in.v_view_pos.z; - if (_1073.flags.x == 1) + float3 _895 = dfdx(in.v_view_pos); + float3 _898 = dfdy(in.v_view_pos); + float3 _907 = fast::normalize(cross(_898 * (-_706.cascade_far_view_z.w), _895)); + float _912 = -in.v_view_pos.z; + if (_706.flags.x == 1) { - float _1308 = fast::clamp(in.v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); - out.out_color = float4(_1308, _1308, _1308, 1.0); + float _923 = fast::clamp(in.v_view_pos.z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_923, _923, _923, 1.0); return out; } - if (_1073.flags.x == 2) + if (_706.flags.x == 2) { - float4 param = _1073.cascade_far_view_z; - float param_1 = _1297; - int _1325 = selectShadowCascade(param, param_1); - float4 _1336 = _1073.cascade_matrices[_1325] * float4(in.v_world_pos, 1.0); - float3 _1343 = _1336.xyz / float3(_1336.w); - float3 _1360 = float3((_1343.x * 0.5) + 0.5, ((_1343.y * _1073.shadow_params.x) * 0.5) + 0.5, _1343.z); - bool _1365 = any(_1360 < float3(0.0)); - bool _1372; - if (!_1365) + int cascade = 2; + if (_912 < _706.cascade_far_view_z.x) { - _1372 = any(_1360 > float3(1.0)); + cascade = 0; } else { - _1372 = _1365; + if (_912 < _706.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _958 = _706.cascade_matrices[cascade] * float4(in.v_world_pos, 1.0); + float3 _965 = _958.xyz / float3(_958.w); + float3 _982 = float3((_965.x * 0.5) + 0.5, ((_965.y * _706.cascade_far_view_z.w) * 0.5) + 0.5, _965.z); + bool _986 = any(_982 < float3(0.0)); + bool _993; + if (!_986) + { + _993 = any(_982 > float3(1.0)); + } + else + { + _993 = _986; } float3 tint = float3(1.0); - if (!_1372) + if (!_993) { - int param_2 = _1325; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out.out_color = float4(tint, 1.0); return out; } - if (_1073.flags.x == 3) + if (_706.flags.x == 3) { - out.out_color = float4((_1292 * 0.5) + float3(0.5), 1.0); + out.out_color = float4((_907 * 0.5) + float3(0.5), 1.0); return out; } - float4 _1421 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); - float _1422 = _1421.x; - if (_1073.flags.x == 4) + float4 _1053 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1054 = _1053.x; + if (_706.flags.x == 4) { - out.out_color = float4(_1422, _1422, _1422, 1.0); + out.out_color = float4(_1054, _1054, _1054, 1.0); return out; } - float3 _1452 = fast::normalize(transpose(float3x3(_1073.view[0].xyz, _1073.view[1].xyz, _1073.view[2].xyz)) * _1292); - float3 _1457 = fast::normalize(_1073.sun_dir_view.xyz); - float3 param_3 = in.v_world_pos; - float3 param_4 = _1452; - float param_5 = fast::max(dot(_1292, _1457), 0.0); - float param_6 = _1297; - float3 param_7 = _1292; - float3 param_8 = fast::normalize(-in.v_view_pos); - float3 param_9 = _1457; - float3 param_10 = _1073.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, param_6, _1073, tex_shadow, smp_shadow); - float3 param_11 = in.v_base_color.xyz; - float param_12 = in.v_material.x; - float param_13 = in.v_material.y; - bool param_14 = _1073.ibl_params.y > 0.5; - float3 param_15 = _1452; - float3 param_16 = fast::normalize(_1073.camera_pos_world.xyz - in.v_world_pos); - float3 param_17 = in.v_base_color.xyz; - float param_18 = in.v_material.x; - float param_19 = in.v_material.y; - float param_20 = _1073.sun_color.w; - spvUnsafeArray param_21; - param_21[0] = _1073.sh[0]; - param_21[1] = _1073.sh[1]; - param_21[2] = _1073.sh[2]; - param_21[3] = _1073.sh[3]; - param_21[4] = _1073.sh[4]; - param_21[5] = _1073.sh[5]; - param_21[6] = _1073.sh[6]; - param_21[7] = _1073.sh[7]; - param_21[8] = _1073.sh[8]; - float param_22 = _1073.ibl_params.x; - out.out_color = float4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_22) * _1422)) * in.v_base_color.w, in.v_base_color.w); + float3 _1072 = fast::normalize(_706.sun_dir_view.xyz); + float3 param = in.v_world_pos; + float param_1 = fast::max(dot(_907, _1072), 0.0); + float param_2 = _912; + float3 param_3 = _907; + float3 param_4 = fast::normalize(-in.v_view_pos); + float3 param_5 = _1072; + float3 param_6 = _706.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _706); + float3 param_7 = in.v_base_color.xyz; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _706.ibl_params.y > 0.5; + float3 param_11 = fast::normalize(transpose(float3x3(_706.view[0].xyz, _706.view[1].xyz, _706.view[2].xyz)) * _907); + float3 param_12 = fast::normalize(_706.camera_pos_world.xyz - in.v_world_pos); + float3 param_13 = in.v_base_color.xyz; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _706.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _706.sh[0]; + param_17[1] = _706.sh[1]; + param_17[2] = _706.sh[2]; + param_17[3] = _706.sh[3]; + param_17[4] = _706.sh[4]; + param_17[5] = _706.sh[5]; + param_17[6] = _706.sh[6]; + param_17[7] = _706.sh[7]; + param_17[8] = _706.sh[8]; + float param_18 = _706.ibl_params.x; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1054)) * in.v_base_color.w, in.v_base_color.w); return out; } */ -static const uint8_t fs_source_metal_macos[19158] = { +static const uint8_t fs_source_metal_macos[15098] = { 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, @@ -4155,1133 +3279,879 @@ static const uint8_t fs_source_metal_macos[19158] = { 0x20,0x69,0x6e,0x74,0x34,0x20,0x66,0x6c,0x61,0x67,0x73,0x3b,0x0a,0x20,0x20,0x20, 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74, - 0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64, - 0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, - 0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, - 0x65,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, - 0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f, - 0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, - 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, - 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b, - 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, - 0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33, - 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, - 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, - 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x69,0x6e,0x74,0x20, - 0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20, - 0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20, - 0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x6d,0x65, + 0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e, + 0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61, + 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73,0x30,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x35,0x32,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x33,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x34,0x39,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x35,0x35,0x33,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x35,0x35,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35, + 0x34,0x39,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x35,0x37,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x33, + 0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x33,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x30,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x35,0x35,0x33,0x2c, + 0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x30,0x36,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38, + 0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x31,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x35,0x34,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x34,0x39,0x2c,0x20,0x5f,0x36,0x35, + 0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x37,0x30,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32,0x38,0x2c, + 0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x36,0x38,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x38,0x33,0x2c,0x20,0x5f,0x36,0x35,0x31,0x2c,0x20,0x5f,0x35,0x32, + 0x38,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x35,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x36,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x33,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35, + 0x37,0x32,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x35,0x37,0x32,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x39,0x30,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x39, + 0x30,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x30,0x36,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x36,0x32,0x30,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x30,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36, + 0x33,0x36,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x36,0x33,0x36,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x35,0x34,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x35, + 0x34,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x30,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x37,0x30,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x35,0x33,0x33,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x36,0x38,0x38,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x38,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x35,0x33,0x33,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31, + 0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32, + 0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, + 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74, + 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x36,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31, + 0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x32,0x33,0x20,0x3d,0x20,0x5f, + 0x37,0x31,0x36,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x5f,0x37,0x31,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x33,0x2e, + 0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32, + 0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, + 0x37,0x34,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x31,0x20,0x3c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x35,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20, + 0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x31,0x20,0x3e,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x5f,0x37,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x35,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x30, + 0x2e,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37, + 0x34,0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38, + 0x37,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x30,0x2e, + 0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x34,0x37,0x34,0x39,0x37,0x34, + 0x35,0x31,0x33,0x30,0x35,0x33,0x38,0x39,0x34,0x30,0x34,0x32,0x39,0x36,0x38,0x37, + 0x35,0x20,0x2a,0x20,0x28,0x73,0x71,0x72,0x74,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x28,0x5f,0x37,0x35,0x39,0x20,0x2a,0x20,0x5f,0x37,0x35,0x39,0x29,0x29,0x20,0x2f, + 0x20,0x5f,0x37,0x35,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x35,0x30,0x30, + 0x30,0x30,0x30,0x30,0x32,0x33,0x37,0x34,0x38,0x37,0x32,0x35,0x36,0x35,0x32,0x36, + 0x39,0x34,0x37,0x30,0x32,0x31,0x34,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e, + 0x30,0x35,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x37,0x34,0x35,0x30,0x35,0x38,0x30, + 0x35,0x39,0x36,0x39,0x32,0x33,0x38,0x32,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30, + 0x20,0x3d,0x20,0x5f,0x37,0x34,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x35,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x30, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, + 0x5f,0x37,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70, + 0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63, + 0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x37,0x39,0x35,0x2e,0x78,0x2c, + 0x20,0x5f,0x37,0x39,0x35,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63, + 0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x36,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30, 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, - 0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, - 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, - 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x54,0x69,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30, - 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, - 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e, - 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, - 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, - 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c, - 0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31, - 0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x33,0x30, - 0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35, - 0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, - 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x64, - 0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20,0x75,0x76,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x65, - 0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x36,0x30,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65, - 0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65, - 0x28,0x73,0x6d,0x70,0x2c,0x20,0x5f,0x36,0x30,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75, - 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x30,0x37,0x2e,0x7a,0x29, - 0x29,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, - 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, - 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46, - 0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66, - 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73,0x30,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x69,0x6e,0x76,0x5f, - 0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x31,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x32,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, - 0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x32,0x37,0x20,0x3d,0x20, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31, - 0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33,0x32,0x20, - 0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32,0x37,0x20,0x2b,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x39,0x20,0x3d,0x20,0x28,0x5f, - 0x36,0x32,0x37,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f, - 0x36,0x33,0x32,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x36,0x34,0x36,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x37,0x2e,0x79,0x20, - 0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x32,0x2e,0x79,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x35,0x31, - 0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x32,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x35,0x35,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20, - 0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x36,0x30,0x20,0x3d,0x20,0x5f,0x36,0x35,0x38,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x34,0x20, - 0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x36,0x20,0x3d,0x20, - 0x5f,0x36,0x36,0x34,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x32,0x20,0x3d,0x20,0x28,0x2d, - 0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x34,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x37,0x20,0x3d,0x20,0x28, - 0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x38,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20,0x3d,0x20,0x34, - 0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x35,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x38,0x31,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36,0x30, - 0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x39,0x33,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36,0x38,0x31, - 0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36,0x36,0x29, - 0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x30,0x32,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x39,0x29, - 0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x32,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x38,0x20, - 0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x39,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37, - 0x37,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x31,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x31,0x32,0x20,0x3d,0x20,0x5f,0x37,0x31,0x31,0x20,0x2d,0x20,0x36, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x31,0x35,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x36, - 0x20,0x3d,0x20,0x5f,0x37,0x31,0x35,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x31,0x20,0x3d, - 0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x35,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x36,0x20, - 0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x39,0x20, - 0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x33,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x37,0x32,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f, - 0x37,0x31,0x32,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x30,0x20,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x32,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x37, - 0x31,0x36,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d, - 0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x34,0x36,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x35,0x34,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34,0x36,0x29,0x20,0x2f,0x20, - 0x5f,0x37,0x32,0x36,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x32,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x32,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, - 0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37,0x33,0x33,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x32,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x34, - 0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x36, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39, - 0x33,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x34,0x30,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f, - 0x37,0x34,0x30,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, - 0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x36, - 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37,0x31,0x36,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37, - 0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x33,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29, - 0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f, - 0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36, - 0x36,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31, - 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c, - 0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20,0x2a,0x20,0x5f,0x37,0x32,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20, - 0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f,0x37,0x34,0x38,0x29,0x20,0x2a,0x20,0x5f, - 0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20, - 0x5f,0x37,0x32,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x35,0x2c,0x20,0x5f,0x37,0x35, - 0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x36,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x36, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39, - 0x33,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20, - 0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x36,0x20,0x2a,0x20,0x5f,0x37,0x32,0x36, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x32,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x37,0x30,0x32,0x2c,0x20,0x5f,0x37,0x35,0x34,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x32,0x20, - 0x2a,0x20,0x5f,0x37,0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x36,0x35,0x31,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x38,0x2c,0x20,0x5f, - 0x37,0x35,0x34,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36, - 0x20,0x3d,0x20,0x5f,0x36,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x36, - 0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x30,0x35,0x38,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x35,0x38,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x37,0x20,0x2a,0x20,0x5f,0x37, - 0x32,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x39,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35, - 0x39,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34, - 0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37, - 0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, - 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74, - 0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x30,0x37,0x33,0x2c, - 0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66, - 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x30,0x38,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x30,0x39,0x38,0x20,0x3d,0x20,0x33,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x30,0x38, - 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, - 0x31,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28,0x28,0x5f, - 0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e, - 0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33, - 0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65, - 0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d, - 0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x32,0x30,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x5f,0x31,0x31,0x32,0x30,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32, - 0x38,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x31,0x34,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28, - 0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, - 0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x79,0x20, - 0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, - 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x34,0x34,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x34,0x38,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x34,0x34,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x34,0x38,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x35,0x35, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x34,0x20,0x3e,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, - 0x35,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x35, - 0x20,0x3d,0x20,0x28,0x5f,0x31,0x30,0x39,0x38,0x20,0x2b,0x20,0x31,0x2e,0x30,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x36,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x34,0x35,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x31,0x31,0x37,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x31,0x36, - 0x37,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x5f,0x31,0x31,0x36, - 0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, - 0x31,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, - 0x31,0x37,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x31,0x38,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f, - 0x31,0x31,0x36,0x37,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x31,0x2e, - 0x30,0x20,0x2b,0x20,0x5f,0x31,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x38,0x34,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x38,0x34,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x34, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65,0x78,0x5f,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, - 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, - 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, - 0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x30,0x37,0x33,0x2c,0x20,0x64, - 0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32,0x31,0x31,0x20,0x3d,0x20,0x73, - 0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x31,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, - 0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x33,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x31,0x20, - 0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31, - 0x31,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x32,0x33,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x33,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x20,0x2d, - 0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x34,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x33,0x2c, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x38,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x30,0x2e, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x35,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x36,0x33,0x20,0x3d, + 0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x34,0x30,0x2c,0x20,0x5f,0x38,0x35,0x32,0x2c, 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x34,0x36,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, - 0x20,0x5f,0x31,0x32,0x31,0x31,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d, - 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x5f,0x31,0x30,0x37,0x33,0x2c,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d, - 0x20,0x5f,0x31,0x32,0x34,0x36,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x31,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32, - 0x34,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, - 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47, - 0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x61,0x6c,0x70, - 0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x20,0x3d,0x20,0x28,0x28,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x35,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x35,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31, - 0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34, - 0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34,0x34,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x34,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, - 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, - 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72, - 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, - 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x37,0x20, - 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20, - 0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x35,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28, - 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, - 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x34,0x29,0x20,0x2b,0x20, - 0x5f,0x31,0x35,0x37,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x36,0x34,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x37,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38, - 0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37, - 0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, - 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, - 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, - 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69, - 0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20, - 0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x5f,0x31,0x39,0x33, - 0x20,0x2a,0x20,0x5f,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28, - 0x28,0x5f,0x31,0x39,0x37,0x20,0x2a,0x20,0x5f,0x31,0x39,0x37,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x39,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x36,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x36, + 0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x36, + 0x33,0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x34,0x30,0x20,0x2d,0x20,0x5f,0x38,0x36, + 0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, - 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62, - 0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, - 0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74, - 0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x32,0x31,0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, - 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x32,0x32,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x31,0x20,0x3d,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, - 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, - 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34, - 0x35,0x20,0x3d,0x20,0x5f,0x32,0x34,0x31,0x20,0x2a,0x20,0x5f,0x32,0x34,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, - 0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20, - 0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, - 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, - 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, - 0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35, - 0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29, - 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x32, - 0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68, - 0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x32,0x29,0x20,0x2a,0x20,0x28, - 0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29, - 0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39, - 0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39, - 0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x32,0x20,0x2a,0x20, - 0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, - 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, - 0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29, - 0x20,0x2a,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62, + 0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29, + 0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x31,0x30,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34, + 0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32, + 0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x31,0x35,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56, + 0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f, + 0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x20,0x3d, + 0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d, + 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x38,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, + 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f, + 0x31,0x32,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, + 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x33,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x38,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, + 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, + 0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72, - 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76, - 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x32,0x36,0x20,0x3d,0x20, - 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34, - 0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29, - 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33, - 0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35, - 0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35, - 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, - 0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38, - 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, - 0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, - 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, - 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, - 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39, - 0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35, - 0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20, - 0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, - 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, - 0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, - 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a, - 0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37, - 0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a, - 0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20, - 0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32,0x36,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, - 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70, - 0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d, - 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e, - 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36, - 0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65, - 0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31, - 0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c, - 0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65, - 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x30,0x37,0x20,0x3d, - 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x33,0x2c,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x33, - 0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34,0x33,0x29,0x20,0x2d,0x20, - 0x5f,0x34,0x34,0x33,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20, - 0x2d,0x20,0x5f,0x34,0x33,0x33,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70, - 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, - 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, - 0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, - 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, - 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, - 0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20, - 0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x33,0x20,0x2a,0x20,0x5f,0x35,0x30,0x37,0x2e, - 0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x35,0x30,0x37, - 0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x38,0x20,0x3d,0x20,0x5f,0x31,0x36,0x34,0x20, + 0x2a,0x20,0x5f,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x38,0x20,0x2a,0x20,0x5f,0x31,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, 0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62, 0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e, - 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, - 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74, - 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f, - 0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68, - 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72, + 0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65, 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, - 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72, - 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c, - 0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73, - 0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c, - 0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, - 0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c, - 0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65, - 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62, - 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72, - 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, + 0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x38,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x39,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x32,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38, + 0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x32,0x31,0x32,0x20,0x2a,0x20,0x5f,0x32,0x31,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62, - 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74, - 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, - 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, - 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, - 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, - 0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x30,0x37,0x33,0x20,0x5b,0x5b,0x62,0x75, - 0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70,0x74,0x68, - 0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, - 0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f, - 0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29, - 0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, - 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, - 0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f, - 0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3d,0x20,0x64,0x66,0x64,0x78, - 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38, - 0x33,0x20,0x3d,0x20,0x64,0x66,0x64,0x79,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, - 0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73, - 0x73,0x28,0x5f,0x31,0x32,0x38,0x33,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x31,0x30,0x37, - 0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x78,0x29,0x2c,0x20,0x5f,0x31,0x32,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x37,0x20,0x3d,0x20,0x2d, - 0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66, - 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63, - 0x6c,0x61,0x6d,0x70,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, - 0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34, - 0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x30,0x38,0x2c,0x20,0x5f,0x31,0x33,0x30,0x38, - 0x2c,0x20,0x5f,0x31,0x33,0x30,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, - 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, - 0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x3d,0x20,0x73, - 0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x33,0x33,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, - 0x73,0x5b,0x5f,0x31,0x33,0x32,0x35,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x34,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x33,0x36,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x5f,0x31,0x33,0x33,0x36,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x36,0x30, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x33,0x34,0x33, - 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c, - 0x20,0x28,0x28,0x5f,0x31,0x33,0x34,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30, - 0x37,0x33,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35, - 0x2c,0x20,0x5f,0x31,0x33,0x34,0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x36,0x35,0x20,0x3d, - 0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x33,0x36,0x30,0x20,0x3c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x37,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x36, - 0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20,0x3d, - 0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x33,0x36,0x30,0x20,0x3e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x37,0x32,0x20,0x3d,0x20, - 0x5f,0x31,0x33,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x33,0x37,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x32, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, - 0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66, - 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, - 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x28,0x28,0x5f,0x31,0x32,0x39,0x32,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, - 0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x32,0x31,0x20, - 0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, - 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65, - 0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61, - 0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29, - 0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x32,0x20, - 0x3d,0x20,0x5f,0x31,0x34,0x32,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, - 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x34,0x32, - 0x32,0x2c,0x20,0x5f,0x31,0x34,0x32,0x32,0x2c,0x20,0x5f,0x31,0x34,0x32,0x32,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x35, - 0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x69,0x7a,0x65,0x28,0x74,0x72,0x61,0x6e,0x73,0x70,0x6f,0x73,0x65,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x78,0x33,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x76,0x69,0x65, - 0x77,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e, - 0x76,0x69,0x65,0x77,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x31,0x30, - 0x37,0x33,0x2e,0x76,0x69,0x65,0x77,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x32,0x39,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x35,0x37,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, - 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x32,0x2c, - 0x20,0x5f,0x31,0x34,0x35,0x37,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x20,0x3d,0x20,0x5f,0x31,0x32,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f, - 0x31,0x32,0x39,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x2d,0x69,0x6e,0x2e,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d, - 0x20,0x5f,0x31,0x34,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x5f,0x31,0x30, - 0x37,0x33,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31, - 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e, - 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, - 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x69,0x62, - 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x34,0x35,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x33,0x2e,0x63,0x61,0x6d,0x65,0x72, - 0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x20, - 0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38, - 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x33,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56, + 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f, + 0x31,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x36,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x56,0x2c,0x20,0x5f,0x31,0x39,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, + 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x33,0x20, + 0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c, + 0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x34,0x33,0x29,0x20,0x2a,0x20,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20, + 0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x33,0x20,0x2a,0x20,0x28, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x38,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55, + 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x38,0x20,0x3d,0x20,0x28, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33, + 0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, + 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30, + 0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37, + 0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31, + 0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33, + 0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38, + 0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32, + 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38, + 0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20, + 0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28, + 0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x38,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76, + 0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x34,0x30,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x35,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x33,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x31,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33, - 0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x31,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e, - 0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x31,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73, - 0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68, - 0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b, - 0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, - 0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x36, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b, - 0x37,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x37,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x38, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x31,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30,0x35,0x2c,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x35,0x20, + 0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x31,0x35,0x29,0x20,0x2d,0x20,0x5f, + 0x34,0x31,0x35,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x5f,0x34,0x30,0x35,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e, + 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, + 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c, + 0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a, + 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x5f,0x34,0x31,0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x31,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x31,0x2e, + 0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, + 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f, + 0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, + 0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20, + 0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63, + 0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c, + 0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f, + 0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69, + 0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x36,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66, + 0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64, + 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75, + 0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b, + 0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b, + 0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, + 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x38,0x39,0x35,0x20,0x3d,0x20,0x64,0x66,0x64,0x78,0x28,0x69,0x6e, + 0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x38,0x20,0x3d,0x20, + 0x64,0x66,0x64,0x79,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x39,0x30,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x63,0x72,0x6f,0x73,0x73,0x28,0x5f,0x38,0x39, + 0x38,0x20,0x2a,0x20,0x28,0x2d,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29, + 0x2c,0x20,0x5f,0x38,0x39,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x2d,0x69,0x6e,0x2e,0x76, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x33, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a, + 0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35, + 0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32, + 0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39, + 0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20,0x5f,0x39,0x32,0x33,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x31,0x32, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x39,0x35,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x36,0x35,0x20,0x3d,0x20,0x5f,0x39,0x35,0x38,0x2e, + 0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x39,0x35, + 0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x39,0x36,0x35,0x2e, + 0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x39,0x36, + 0x35,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x39,0x38,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x39, + 0x38,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x39,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x38,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x39,0x38,0x32,0x20,0x3e, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x39,0x33, + 0x20,0x3d,0x20,0x5f,0x39,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x21,0x5f,0x39,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x5f,0x39,0x30,0x37,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x31,0x30,0x35,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20, + 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65, + 0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69, + 0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28, + 0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x33,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x36,0x2e,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20, + 0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x76,0x69,0x65,0x77,0x2e,0x78,0x79,0x7a,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x37,0x2c,0x20,0x5f,0x31,0x30, + 0x37,0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, + 0x39,0x31,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x30,0x37,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x2d,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x30,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x69,0x6e, + 0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x74,0x72,0x61,0x6e,0x73,0x70,0x6f,0x73,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x78,0x33,0x28,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x30,0x5d,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x37,0x30,0x36,0x2e,0x76,0x69,0x65,0x77, + 0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x30,0x37, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x36,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, + 0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x33,0x2e,0x69,0x62,0x6c,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, - 0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x74,0x65,0x78, - 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69, - 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29,0x20,0x2a, - 0x20,0x5f,0x31,0x34,0x32,0x32,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x5f,0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66, + 0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39, + 0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36, + 0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73, + 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b, + 0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, + 0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x34,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35, + 0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x36,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x36,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x36,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72, + 0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c, + 0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73, + 0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x35,0x34,0x29,0x29,0x20,0x2a,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77, + 0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* cube_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -5303,43 +4173,34 @@ static inline const sg_shader_desc* cube_shader_desc(sg_backend backend) { desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 608; + desc.uniform_blocks[1].size = 496; desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_1073.sun_dir_view"; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_706.sun_dir_view"; desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_1073.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_706.sun_color"; desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_1073.flags"; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_706.flags"; desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_1073.cascade_far_view_z"; - desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_1073.cascade_texel_world"; - desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_706.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[4].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_706.cascade_matrices"; + desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_1073.cascade_depth_bias"; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_706.view"; desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_1073.shadow_params"; - desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; - desc.uniform_blocks[1].glsl_uniforms[7].array_count = 4; - desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_1073.cascade_matrices"; - desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_706.camera_pos_world"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_706.sh"; + desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_1073.view"; - desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_1073.camera_pos_world"; - desc.uniform_blocks[1].glsl_uniforms[10].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[10].array_count = 9; - desc.uniform_blocks[1].glsl_uniforms[10].glsl_name = "_1073.sh"; - desc.uniform_blocks[1].glsl_uniforms[11].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[11].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[11].glsl_name = "_1073.ibl_params"; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_706.ibl_params"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -5413,7 +4274,7 @@ static inline const sg_shader_desc* cube_shader_desc(sg_backend backend) { desc.uniform_blocks[0].hlsl_register_b_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 608; + desc.uniform_blocks[1].size = 496; desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; @@ -5486,7 +4347,7 @@ static inline const sg_shader_desc* cube_shader_desc(sg_backend backend) { desc.uniform_blocks[0].msl_buffer_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 608; + desc.uniform_blocks[1].size = 496; desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; diff --git a/samples/shaders/generated/geom.glsl.h b/samples/shaders/generated/geom.glsl.h index ca629d9..0bac3cc 100644 --- a/samples/shaders/generated/geom.glsl.h +++ b/samples/shaders/generated/geom.glsl.h @@ -106,10 +106,7 @@ SOKOL_SHDC_ALIGN(16) typedef struct geom_ub_pass_t { Vec4 grid_offset; Mat4 view; Vec4 cascade_far_view_z; - Vec4 cascade_texel_world; - Vec4 cascade_depth_bias; - Vec4 shadow_params; - Mat4 cascade_matrices[4]; + Mat4 cascade_matrices[3]; Vec4 sh[9]; Vec4 ibl_params; } geom_ub_pass_t; @@ -261,15 +258,12 @@ static const uint8_t geom_vs_source_glsl430[1269] = { vec4 grid_offset; mat4 view; vec4 cascade_far_view_z; - vec4 cascade_texel_world; - vec4 cascade_depth_bias; - vec4 shadow_params; - mat4 cascade_matrices[4]; + mat4 cascade_matrices[3]; vec4 sh[9]; vec4 ibl_params; }; - uniform ub_pass _1198; + uniform ub_pass _834; layout(binding = 0) uniform sampler2D tex_ao_smp_ao; layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; @@ -282,228 +276,104 @@ static const uint8_t geom_vs_source_glsl430[1269] = { layout(location = 2) flat in vec4 v_base_color; layout(location = 3) flat in vec4 v_material; - int selectShadowCascade(vec4 far_view_z, float view_z) - { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - vec3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return vec3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - vec3 proceduralGrid(vec2 line_xz, vec2 axis_xz, vec3 base_color, float cell_size) { - vec2 _559 = line_xz / vec2(cell_size); - vec2 _575 = abs(fract(_559 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_559), vec2(9.9999999747524270787835121154785e-07)); - vec2 _590 = line_xz / vec2(cell_size * 10.0); - vec2 _604 = abs(fract(_590 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_590), vec2(9.9999999747524270787835121154785e-07)); - vec2 _635 = max(fwidth(axis_xz), vec2(9.9999999747524270787835121154785e-07)); - return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, vec3(1.0 - clamp(min(_575.x, _575.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, vec3(1.0 - clamp(min(_604.x, _604.y), 0.0, 1.0))), vec3(1.0, 0.0, 0.0), vec3((1.0 - clamp(abs(axis_xz.y) / _635.y, 0.0, 1.0)) * step(0.0, axis_xz.x))), vec3(0.0, 0.0, 1.0), vec3((1.0 - clamp(abs(axis_xz.x) / _635.x, 0.0, 1.0)) * step(0.0, axis_xz.y))); + vec2 _536 = line_xz / vec2(cell_size); + vec2 _552 = abs(fract(_536 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_536), vec2(9.9999999747524270787835121154785e-07)); + vec2 _567 = line_xz / vec2(cell_size * 10.0); + vec2 _581 = abs(fract(_567 - vec2(0.5)) - vec2(0.5)) / max(fwidth(_567), vec2(9.9999999747524270787835121154785e-07)); + vec2 _612 = max(fwidth(axis_xz), vec2(9.9999999747524270787835121154785e-07)); + return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, vec3(1.0 - clamp(min(_552.x, _552.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, vec3(1.0 - clamp(min(_581.x, _581.y), 0.0, 1.0))), vec3(1.0, 0.0, 0.0), vec3((1.0 - clamp(abs(axis_xz.y) / _612.y, 0.0, 1.0)) * step(0.0, axis_xz.x))), vec3(0.0, 0.0, 1.0), vec3((1.0 - clamp(abs(axis_xz.x) / _612.x, 0.0, 1.0)) * step(0.0, axis_xz.y))); } - float sampleShadowTap(vec2 uv, float layer, float ref_z, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) { - return texture(SPIRV_Cross_Combinedtexsmp, vec4(vec4(uv, layer, ref_z).xyz, ref_z)); - } - - float sampleShadowPCF(int cascade, vec3 light_uv, float bias, float scale, float inv_size, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - float _742 = float(cascade); - float _747 = light_uv.z - bias; - vec2 _752 = light_uv.xy * (1.0 / inv_size); - vec2 _757 = floor(_752 + vec2(0.5)); - float _764 = (_752.x + 0.5) - _757.x; - float _771 = (_752.y + 0.5) - _757.y; - vec2 _776 = (_757 - vec2(0.5)) * inv_size; - float _780 = inv_size * scale; - float _783 = 5.0 * _764; - float _785 = _783 - 6.0; - float _789 = 11.0 * _764; - float _791 = _789 - 28.0; - float _797 = (-17.0) - _789; - float _802 = (-1.0) - _783; - float _806 = 4.0 * _764; - float _810 = ((_806 - 5.0) / _785) - 3.0; - float _818 = ((_806 - 16.0) / _791) - 1.0; - float _827 = (((-5.0) - (7.0 * _764)) / _797) + 1.0; - float _833 = ((-_764) / _802) + 3.0; - float _836 = 5.0 * _771; - float _837 = _836 - 6.0; - float _840 = 11.0 * _771; - float _841 = _840 - 28.0; - float _846 = (-17.0) - _840; - float _851 = (-1.0) - _836; - float _854 = 4.0 * _771; - float _858 = ((_854 - 5.0) / _837) - 3.0; - float _865 = ((_854 - 16.0) / _841) - 1.0; - float _873 = (((-5.0) - (7.0 * _771)) / _846) + 1.0; - float _879 = ((-_771) / _851) + 3.0; - float sum = 0.0; - vec2 param = _776 + (vec2(_810, _858) * _780); - float param_1 = _742; - float param_2 = _747; - sum += ((_785 * _837) * sampleShadowTap(param, param_1, param_2, SPIRV_Cross_Combinedtexsmp)); - vec2 param_3 = _776 + (vec2(_818, _858) * _780); - float param_4 = _742; - float param_5 = _747; - sum += ((_791 * _837) * sampleShadowTap(param_3, param_4, param_5, SPIRV_Cross_Combinedtexsmp)); - vec2 param_6 = _776 + (vec2(_827, _858) * _780); - float param_7 = _742; - float param_8 = _747; - sum += ((_797 * _837) * sampleShadowTap(param_6, param_7, param_8, SPIRV_Cross_Combinedtexsmp)); - vec2 param_9 = _776 + (vec2(_833, _858) * _780); - float param_10 = _742; - float param_11 = _747; - sum += ((_802 * _837) * sampleShadowTap(param_9, param_10, param_11, SPIRV_Cross_Combinedtexsmp)); - vec2 param_12 = _776 + (vec2(_810, _865) * _780); - float param_13 = _742; - float param_14 = _747; - sum += ((_785 * _841) * sampleShadowTap(param_12, param_13, param_14, SPIRV_Cross_Combinedtexsmp)); - vec2 param_15 = _776 + (vec2(_818, _865) * _780); - float param_16 = _742; - float param_17 = _747; - sum += ((_791 * _841) * sampleShadowTap(param_15, param_16, param_17, SPIRV_Cross_Combinedtexsmp)); - vec2 param_18 = _776 + (vec2(_827, _865) * _780); - float param_19 = _742; - float param_20 = _747; - sum += ((_797 * _841) * sampleShadowTap(param_18, param_19, param_20, SPIRV_Cross_Combinedtexsmp)); - vec2 param_21 = _776 + (vec2(_833, _865) * _780); - float param_22 = _742; - float param_23 = _747; - sum += ((_802 * _841) * sampleShadowTap(param_21, param_22, param_23, SPIRV_Cross_Combinedtexsmp)); - vec2 param_24 = _776 + (vec2(_810, _873) * _780); - float param_25 = _742; - float param_26 = _747; - sum += ((_785 * _846) * sampleShadowTap(param_24, param_25, param_26, SPIRV_Cross_Combinedtexsmp)); - vec2 param_27 = _776 + (vec2(_818, _873) * _780); - float param_28 = _742; - float param_29 = _747; - sum += ((_791 * _846) * sampleShadowTap(param_27, param_28, param_29, SPIRV_Cross_Combinedtexsmp)); - vec2 param_30 = _776 + (vec2(_827, _873) * _780); - float param_31 = _742; - float param_32 = _747; - sum += ((_797 * _846) * sampleShadowTap(param_30, param_31, param_32, SPIRV_Cross_Combinedtexsmp)); - vec2 param_33 = _776 + (vec2(_833, _873) * _780); - float param_34 = _742; - float param_35 = _747; - sum += ((_802 * _846) * sampleShadowTap(param_33, param_34, param_35, SPIRV_Cross_Combinedtexsmp)); - vec2 param_36 = _776 + (vec2(_810, _879) * _780); - float param_37 = _742; - float param_38 = _747; - sum += ((_785 * _851) * sampleShadowTap(param_36, param_37, param_38, SPIRV_Cross_Combinedtexsmp)); - vec2 param_39 = _776 + (vec2(_818, _879) * _780); - float param_40 = _742; - float param_41 = _747; - sum += ((_791 * _851) * sampleShadowTap(param_39, param_40, param_41, SPIRV_Cross_Combinedtexsmp)); - vec2 param_42 = _776 + (vec2(_827, _879) * _780); - float param_43 = _742; - float param_44 = _747; - sum += ((_797 * _851) * sampleShadowTap(param_42, param_43, param_44, SPIRV_Cross_Combinedtexsmp)); - vec2 param_45 = _776 + (vec2(_833, _879) * _780); - float param_46 = _742; - float param_47 = _747; - float _1183 = sum; - float _1184 = _1183 + ((_802 * _851) * sampleShadowTap(param_45, param_46, param_47, SPIRV_Cross_Combinedtexsmp)); - sum = _1184; - return _1184 * 0.000369822490029036998748779296875; + float _656 = float(cascade); + float _661 = light_uv.z - bias; + float _677 = light_uv.x - 0.00048828125; + float _681 = light_uv.y - 0.00048828125; + float _711 = light_uv.x + 0.00048828125; + float _779 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_677, _681, _656, _661).xyz, _661)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _681, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(_711, _681, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(_677, light_uv.y, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(_711, light_uv.y, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(_677, _779, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _779, _656, _661).xyz, _661))) + texture(tex_shadow_smp_shadow, vec4(vec4(_711, _779, _656, _661).xyz, _661))) * 0.111111111938953399658203125; } float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) { - float _1213 = clamp(_1198.cascade_texel_world.x / _1198.cascade_texel_world[cascade], 0.25, 1.0); - float _1222 = max(dot(world_normal, normalize(_1198.sun_dir_world.xyz)), 0.0); - float _1232 = 3.0 * _1213; - vec4 _1255 = _1198.cascade_matrices[cascade] * vec4(world_pos + (world_normal * ((((_1232 + 0.5) * 1.41420996189117431640625) * sqrt(max(1.0 - (_1222 * _1222), 0.0))) * _1198.cascade_texel_world[cascade])), 1.0); - vec3 _1263 = _1255.xyz / vec3(_1255.w); - float _1280 = _1263.z; - vec3 _1281 = vec3((_1263.x * 0.5) + 0.5, ((_1263.y * _1198.shadow_params.x) * 0.5) + 0.5, _1280); - bool _1284 = _1280 < 0.0; - bool _1291; - if (!_1284) + vec4 _844 = _834.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _851 = _844.xyz / vec3(_844.w); + vec3 _869 = vec3((_851.x * 0.5) + 0.5, ((_851.y * _834.cascade_far_view_z.w) * 0.5) + 0.5, _851.z); + bool _873 = any(lessThan(_869, vec3(0.0))); + bool _880; + if (!_873) { - _1291 = _1280 > 1.0; + _880 = any(greaterThan(_869, vec3(1.0))); } else { - _1291 = _1284; + _880 = _873; } - if (_1291) - { - return 1.0; - } - float _1301 = (_1232 + 1.0) * _1198.shadow_params.y; - vec2 _1303 = _1281.xy; - bool _1309 = any(lessThan(_1303, vec2(-_1301))); - bool _1320; - if (!_1309) - { - _1320 = any(greaterThan(_1303, vec2(1.0 + _1301))); - } - else - { - _1320 = _1309; - } - if (_1320) + if (_880) { return 1.0; } int param = cascade; - vec3 param_1 = _1281; - float param_2 = _1198.cascade_depth_bias[cascade]; - float param_3 = _1213; - float param_4 = _1198.shadow_params.y; - return sampleShadowPCF(param, param_1, param_2, param_3, param_4, tex_shadow_smp_shadow); + vec3 param_1 = _869; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_834.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _912 = _869.xy; + vec2 _917 = min(_912, vec2(1.0) - _912); + pcf = mix(1.0, pcf, clamp(min(_917.x, _917.y) * 10.0, 0.0, 1.0)); + } + return pcf; } float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) { - vec4 param = _1198.cascade_far_view_z; - float param_1 = view_z; - int _1346 = selectShadowCascade(param, param_1); - int param_2 = _1346; - vec3 param_3 = world_pos; - vec3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1346 < 3) + int cascade = 2; + if (view_z < _834.cascade_far_view_z.x) { - float _1366; - if (_1346 == 0) + cascade = 0; + } + else + { + if (view_z < _834.cascade_far_view_z.y) { - _1366 = 0.0; + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _961; + if (cascade == 0) + { + _961 = _834.cascade_far_view_z.x; } else { - _1366 = _1198.cascade_far_view_z[_1346 - 1]; + _961 = _834.cascade_far_view_z.y; } - float _1379 = mix(_1198.cascade_far_view_z[_1346], _1366, 0.100000001490116119384765625); - if (view_z > _1379) + float _973; + if (cascade == 0) { - int param_5 = _1346 + 1; - vec3 param_6 = world_pos; - vec3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1379) / (_1198.cascade_far_view_z[_1346] - _1379)); + _973 = 0.0; + } + else + { + _973 = _834.cascade_far_view_z.x; + } + float _984 = mix(_961, _973, 0.100000001490116119384765625); + if (view_z > _984) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _984) / (_961 - _984)); } } return shadow; @@ -511,56 +381,56 @@ static const uint8_t geom_vs_source_glsl430[1269] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _140 = alpha * alpha; - float _149 = ((n_dot_h * n_dot_h) * (_140 - 1.0)) + 1.0; - return _140 / ((3.1415927410125732421875 * _149) * _149); + float _116 = alpha * alpha; + float _125 = ((n_dot_h * n_dot_h) * (_116 - 1.0)) + 1.0; + return _116 / ((3.1415927410125732421875 * _125) * _125); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _162 = alpha * alpha; - float _169 = 1.0 - _162; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _169) + _162)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _169) + _162))) + 9.9999997473787516355514526367188e-06); + float _138 = alpha * alpha; + float _145 = 1.0 - _138; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _145) + _138)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _145) + _138))) + 9.9999997473787516355514526367188e-06); } vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) { - float _198 = 1.0 - v_dot_h; - float _202 = _198 * _198; - return f0 + ((vec3(1.0) - f0) * ((_202 * _202) * _198)); + float _174 = 1.0 - v_dot_h; + float _178 = _174 * _174; + return f0 + ((vec3(1.0) - f0) * ((_178 * _178) * _174)); } vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) { - float _221 = max(dot(N, L), 0.0); - vec3 _232 = normalize(V + L); - float _246 = max(roughness, 0.04500000178813934326171875); - float _250 = _246 * _246; - float param = max(dot(N, _232), 0.0); - float param_1 = _250; + float _197 = max(dot(N, L), 0.0); + vec3 _208 = normalize(V + L); + float _222 = max(roughness, 0.04500000178813934326171875); + float _226 = _222 * _222; + float param = max(dot(N, _208), 0.0); + float param_1 = _226; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _221; - float param_4 = _250; - float param_5 = max(dot(V, _232), 0.0); + float param_3 = _197; + float param_4 = _226; + float param_5 = max(dot(V, _208), 0.0); vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); - vec3 _277 = pbrFresnelSchlick(param_5, param_6); - return ((((((vec3(1.0) - _277) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_277 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _221; + vec3 _253 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _253) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_253 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _197; } vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) { - vec3 _431 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _431; + vec3 _408 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _408; } vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) { - float _438 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - vec3 _448 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + float _415 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _425 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); vec3 param = N_world; vec4 param_1[9] = sh; - vec4 _512 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_438, roughness)); - return (((((vec3(1.0) - (_448 + ((max(vec3(1.0 - roughness), _448) - _448) * pow(max(0.0, 1.0 - _438), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_448 * _512.x) + vec3(_512.y))); + vec4 _489 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_415, roughness)); + return (((((vec3(1.0) - (_425 + ((max(vec3(1.0 - roughness), _425) - _425) * pow(max(0.0, 1.0 - _415), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_425 * _489.x) + vec3(_489.y))); } vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) @@ -582,102 +452,125 @@ static const uint8_t geom_vs_source_glsl430[1269] = { void main() { - vec3 _1411 = normalize(v_world_normal); - vec3 n_world = _1411; - vec3 _1418 = _1198.camera_pos.xyz - v_view_pos; - if (dot(_1411, _1418) < 0.0) + vec3 _1016 = normalize(v_world_normal); + vec3 n_world = _1016; + vec3 _1023 = _834.camera_pos.xyz - v_view_pos; + if (dot(_1016, _1023) < 0.0) { n_world = -n_world; } - if (_1198.flags.x == 1) + if (_834.flags.x == 1) { - float _1449 = clamp((_1198.view * vec4(v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out_color = vec4(_1449, _1449, _1449, 1.0); + float _1054 = clamp((_834.view * vec4(v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1054, _1054, _1054, 1.0); return; } - if (_1198.flags.x == 2) + if (_834.flags.x == 2) { - vec4 _1467 = vec4(v_view_pos, 1.0); - vec4 param = _1198.cascade_far_view_z; - float param_1 = -(_1198.view * _1467).z; - int _1477 = selectShadowCascade(param, param_1); - vec4 _1487 = _1198.cascade_matrices[_1477] * _1467; - vec3 _1494 = _1487.xyz / vec3(_1487.w); - vec3 _1511 = vec3((_1494.x * 0.5) + 0.5, ((_1494.y * _1198.shadow_params.x) * 0.5) + 0.5, _1494.z); - bool _1516 = any(lessThan(_1511, vec3(0.0))); - bool _1523; - if (!_1516) + vec4 _1072 = vec4(v_view_pos, 1.0); + float _1075 = -(_834.view * _1072).z; + int cascade = 2; + if (_1075 < _834.cascade_far_view_z.x) { - _1523 = any(greaterThan(_1511, vec3(1.0))); + cascade = 0; } else { - _1523 = _1516; + if (_1075 < _834.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1099 = _834.cascade_matrices[cascade] * _1072; + vec3 _1106 = _1099.xyz / vec3(_1099.w); + vec3 _1123 = vec3((_1106.x * 0.5) + 0.5, ((_1106.y * _834.cascade_far_view_z.w) * 0.5) + 0.5, _1106.z); + bool _1127 = any(lessThan(_1123, vec3(0.0))); + bool _1134; + if (!_1127) + { + _1134 = any(greaterThan(_1123, vec3(1.0))); + } + else + { + _1134 = _1127; } vec3 tint = vec3(1.0); - if (!_1523) + if (!_1134) { - int param_2 = _1477; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out_color = vec4(tint, 1.0); return; } - if (_1198.flags.x == 3) + if (_834.flags.x == 3) { - out_color = vec4((normalize((_1198.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + out_color = vec4((normalize((_834.view * vec4(n_world, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); return; } - vec4 _1583 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); - float _1584 = _1583.x; - if (_1198.flags.x == 4) + vec4 _1205 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1206 = _1205.x; + if (_834.flags.x == 4) { - out_color = vec4(_1584, _1584, _1584, 1.0); + out_color = vec4(_1206, _1206, _1206, 1.0); return; } vec3 baseColor = v_base_color.xyz; if (v_material.z > 0.5) { - vec2 param_3 = v_view_pos.xz + _1198.grid_offset.xy; - vec2 param_4 = v_view_pos.xz + _1198.grid_offset.zw; - vec3 param_5 = v_base_color.xyz; - float param_6 = v_material.w; - baseColor = mix(v_base_color.xyz, proceduralGrid(param_3, param_4, param_5, param_6), vec3(pow(clamp(n_world.y, 0.0, 1.0), 8.0))); + vec2 param = v_view_pos.xz + _834.grid_offset.xy; + vec2 param_1 = v_view_pos.xz + _834.grid_offset.zw; + vec3 param_2 = v_base_color.xyz; + float param_3 = v_material.w; + baseColor = mix(v_base_color.xyz, proceduralGrid(param, param_1, param_2, param_3), vec3(pow(clamp(n_world.y, 0.0, 1.0), 8.0))); } - vec3 param_7 = v_view_pos; - vec3 param_8 = n_world; - float param_9 = -(_1198.view * vec4(v_view_pos, 1.0)).z; - vec3 _1683 = normalize(_1418); - vec3 param_10 = n_world; - vec3 param_11 = _1683; - vec3 param_12 = normalize(_1198.sun_dir_world.xyz); - vec3 param_13 = _1198.sun_color.xyz * sampleShadowCascaded(param_7, param_8, param_9); - vec3 param_14 = baseColor; - float param_15 = v_material.x; - float param_16 = v_material.y; - bool param_17 = _1198.ibl_params.y > 0.5; - vec3 param_18 = n_world; - vec3 param_19 = _1683; - vec3 param_20 = baseColor; - float param_21 = v_material.x; - float param_22 = v_material.y; - float param_23 = _1198.sun_color.w; - vec4 param_24[9]; - param_24[0] = _1198.sh[0]; - param_24[1] = _1198.sh[1]; - param_24[2] = _1198.sh[2]; - param_24[3] = _1198.sh[3]; - param_24[4] = _1198.sh[4]; - param_24[5] = _1198.sh[5]; - param_24[6] = _1198.sh[6]; - param_24[7] = _1198.sh[7]; - param_24[8] = _1198.sh[8]; - float param_25 = _1198.ibl_params.x; - out_color = vec4((brdf_evaluate(param_10, param_11, param_12, param_13, param_14, param_15, param_16) + (pbrEvaluateAmbient(param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24, param_25, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1584)) * v_base_color.w, v_base_color.w); + vec3 param_4 = v_view_pos; + vec3 param_5 = n_world; + float param_6 = -(_834.view * vec4(v_view_pos, 1.0)).z; + vec3 _1305 = normalize(_1023); + vec3 param_7 = n_world; + vec3 param_8 = _1305; + vec3 param_9 = normalize(_834.sun_dir_world.xyz); + vec3 param_10 = _834.sun_color.xyz * sampleShadowCascaded(param_4, param_5, param_6); + vec3 param_11 = baseColor; + float param_12 = v_material.x; + float param_13 = v_material.y; + bool param_14 = _834.ibl_params.y > 0.5; + vec3 param_15 = n_world; + vec3 param_16 = _1305; + vec3 param_17 = baseColor; + float param_18 = v_material.x; + float param_19 = v_material.y; + float param_20 = _834.sun_color.w; + vec4 param_21[9]; + param_21[0] = _834.sh[0]; + param_21[1] = _834.sh[1]; + param_21[2] = _834.sh[2]; + param_21[3] = _834.sh[3]; + param_21[4] = _834.sh[4]; + param_21[5] = _834.sh[5]; + param_21[6] = _834.sh[6]; + param_21[7] = _834.sh[7]; + param_21[8] = _834.sh[8]; + float param_22 = _834.ibl_params.x; + out_color = vec4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, param_22, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1206)) * v_base_color.w, v_base_color.w); } */ -static const uint8_t geom_fs_source_glsl430[17425] = { +static const uint8_t geom_fs_source_glsl430[13040] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, @@ -689,1085 +582,811 @@ static const uint8_t geom_fs_source_glsl430[17425] = { 0x66,0x66,0x73,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20, 0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63, 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b, - 0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69, - 0x66,0x6f,0x72,0x6d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, - 0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61, - 0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41, - 0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72, + 0x6d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x38,0x33,0x34,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d, + 0x70,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e, + 0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72, + 0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79, + 0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61, + 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32, + 0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20, + 0x3d,0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a, + 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, + 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75, + 0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76, + 0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c, + 0x47,0x72,0x69,0x64,0x28,0x76,0x65,0x63,0x32,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78, + 0x7a,0x2c,0x20,0x76,0x65,0x63,0x32,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a, + 0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35, + 0x33,0x36,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x76, + 0x65,0x63,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x33,0x36,0x20,0x2d, + 0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65, + 0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x33,0x36,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32, + 0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34, + 0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x35,0x36,0x37,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f, + 0x78,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73, + 0x69,0x7a,0x65,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x38,0x31,0x20,0x3d,0x20,0x61,0x62,0x73, + 0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x36,0x37,0x20,0x2d,0x20,0x76,0x65, + 0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28, + 0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x5f,0x35,0x36,0x37,0x29,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37, + 0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35, + 0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, + 0x20,0x5f,0x36,0x31,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32, + 0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34, + 0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69, + 0x78,0x28,0x6d,0x69,0x78,0x28,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30, + 0x2e,0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31, + 0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28, + 0x5f,0x35,0x35,0x32,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x32,0x2e,0x79,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39, + 0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34, + 0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x38, + 0x31,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x38,0x31,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79,0x29, + 0x20,0x2f,0x20,0x5f,0x36,0x31,0x32,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30, + 0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f, + 0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31,0x32,0x2e,0x78,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65, + 0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79, + 0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e, + 0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x36,0x36,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x37,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38, + 0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x37,0x31,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, + 0x37,0x39,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x36,0x37, + 0x37,0x2c,0x20,0x5f,0x36,0x38,0x31,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29, + 0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73, 0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67, - 0x20,0x3d,0x20,0x32,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, - 0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73, - 0x70,0x65,0x63,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64, - 0x69,0x6e,0x67,0x20,0x3d,0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, - 0x5f,0x6c,0x75,0x74,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f, - 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,0x76, - 0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, - 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33, - 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30, - 0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, - 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, - 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, - 0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x3b,0x0a,0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x76,0x65,0x63, - 0x34,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20, - 0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b, - 0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61, - 0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74, - 0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, - 0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28, - 0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, - 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, - 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, - 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30, - 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, - 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39, - 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, - 0x2c,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30, - 0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61, - 0x6c,0x47,0x72,0x69,0x64,0x28,0x76,0x65,0x63,0x32,0x20,0x6c,0x69,0x6e,0x65,0x5f, - 0x78,0x7a,0x2c,0x20,0x76,0x65,0x63,0x32,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69, - 0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f, - 0x35,0x35,0x39,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20, - 0x76,0x65,0x63,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x37,0x35,0x20,0x3d, - 0x20,0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x35,0x39,0x20, - 0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76, - 0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28, - 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x35,0x39,0x29,0x2c,0x20,0x76,0x65, - 0x63,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35, - 0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35, - 0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x5f,0x35,0x39,0x30,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65, - 0x5f,0x78,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f, - 0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x36,0x30,0x34,0x20,0x3d,0x20,0x61,0x62, - 0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x39,0x30,0x20,0x2d,0x20,0x76, - 0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32, - 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, - 0x64,0x74,0x68,0x28,0x5f,0x35,0x39,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x32,0x28, - 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32, - 0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38, - 0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x5f,0x36,0x33,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, - 0x64,0x74,0x68,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x76,0x65, - 0x63,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35, - 0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35, - 0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d, - 0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20, - 0x30,0x2e,0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37, - 0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e, - 0x28,0x5f,0x35,0x37,0x35,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x37,0x35,0x2e,0x79,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34, - 0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32, - 0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x36, - 0x30,0x34,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x30,0x34,0x2e,0x79,0x29,0x2c,0x20,0x30, - 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x63,0x6c,0x61, - 0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79, - 0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e, - 0x30,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, - 0x31,0x2e,0x30,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x31,0x2e,0x30,0x20, - 0x2d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x78,0x2c, - 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74, - 0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e, - 0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x76, - 0x65,0x63,0x32,0x20,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6c,0x61, - 0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x65,0x66,0x5f,0x7a, - 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d, - 0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x75,0x76, - 0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x2e, - 0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, - 0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, - 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x37,0x20,0x3d, - 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69, - 0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x35, - 0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x20, - 0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a, - 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x35, - 0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x37,0x35,0x32,0x20,0x2b, - 0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x36,0x34,0x20,0x3d,0x20,0x28,0x5f, - 0x37,0x35,0x32,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f, - 0x37,0x35,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x37,0x35,0x32,0x2e,0x79,0x20, - 0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x37,0x35,0x37,0x2e,0x79,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x37,0x36,0x20,0x3d, - 0x20,0x28,0x5f,0x37,0x35,0x37,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e, - 0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x30,0x20,0x3d, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c, - 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38, - 0x33,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d, - 0x20,0x5f,0x37,0x38,0x33,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x39,0x20,0x3d,0x20,0x31,0x31, - 0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x31,0x20,0x3d,0x20,0x5f,0x37,0x38,0x39, - 0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x39,0x37,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x38,0x30,0x32,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x38,0x30,0x36,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x37,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x38,0x31,0x30,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d, - 0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x37,0x38,0x35,0x29,0x20,0x2d,0x20, - 0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x38,0x31,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d,0x20,0x31, - 0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x37,0x39,0x31,0x29,0x20,0x2d,0x20,0x31, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, - 0x32,0x37,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x29,0x29,0x20,0x2f,0x20, - 0x5f,0x37,0x39,0x37,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x33,0x20,0x3d,0x20,0x28,0x28, - 0x2d,0x5f,0x37,0x36,0x34,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30,0x32,0x29,0x20,0x2b, - 0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x33,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x37, - 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33, - 0x37,0x20,0x3d,0x20,0x5f,0x38,0x33,0x36,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d, - 0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x31,0x20,0x3d,0x20,0x5f, - 0x38,0x34,0x30,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x36,0x20,0x3d,0x20,0x28,0x2d,0x31, - 0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x31,0x20,0x3d,0x20,0x28,0x2d, - 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x38,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x34,0x20,0x3d,0x20,0x34,0x2e, - 0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35, - 0x34,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x38,0x33,0x37,0x29, - 0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x38,0x36,0x35,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35,0x34,0x20, - 0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x38,0x34,0x31,0x29,0x20, - 0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x38,0x37,0x33,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29, - 0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x29,0x29, - 0x20,0x2f,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d, - 0x20,0x28,0x28,0x2d,0x5f,0x37,0x37,0x31,0x29,0x20,0x2f,0x20,0x5f,0x38,0x35,0x31, - 0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x30, - 0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, - 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, - 0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20, - 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20,0x5f,0x38, - 0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37, - 0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20, - 0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x35,0x38, - 0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37, - 0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73, - 0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76, - 0x65,0x63,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20, - 0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37, - 0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32, - 0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x36, - 0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c, - 0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38, - 0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20, - 0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37, - 0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c, - 0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38, - 0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x32,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20, - 0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37, - 0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c, - 0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38, - 0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x34,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x38,0x33,0x20,0x3d,0x20, - 0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x31,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x33,0x20,0x2b,0x20,0x28, - 0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x2c,0x20,0x53,0x50, - 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, - 0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x38,0x34,0x20,0x2a,0x20, - 0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32, - 0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36, - 0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x31,0x33,0x20,0x3d,0x20, - 0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x78,0x20,0x2f,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x32,0x32,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x75,0x6e,0x5f, - 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x32,0x33,0x32,0x20,0x3d,0x20,0x33,0x2e,0x30,0x20,0x2a,0x20,0x5f, - 0x31,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, - 0x31,0x32,0x35,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31, - 0x32,0x33,0x32,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34, - 0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31, - 0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x6d, - 0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x32,0x32,0x32,0x20, - 0x2a,0x20,0x5f,0x31,0x32,0x32,0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x36,0x33,0x20,0x3d,0x20, - 0x5f,0x31,0x32,0x35,0x35,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33, - 0x28,0x5f,0x31,0x32,0x35,0x35,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3d,0x20,0x5f,0x31,0x32, - 0x36,0x33,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, - 0x31,0x32,0x38,0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x32, - 0x36,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x32,0x36,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, - 0x2e,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32, - 0x38,0x30,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x32,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x21,0x5f,0x31,0x32,0x38,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x31,0x20,0x3d,0x20, - 0x5f,0x31,0x32,0x38,0x30,0x20,0x3e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x31,0x20, - 0x3d,0x20,0x5f,0x31,0x32,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x39,0x31,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x30,0x31,0x20,0x3d,0x20, - 0x28,0x5f,0x31,0x32,0x33,0x32,0x20,0x2b,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20, - 0x5f,0x31,0x33,0x30,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x31,0x2e,0x78,0x79, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x30,0x39, - 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28, - 0x5f,0x31,0x33,0x30,0x33,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x2d,0x5f,0x31,0x33, - 0x30,0x31,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x31,0x33,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21, - 0x5f,0x31,0x33,0x30,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x61,0x6e,0x79, - 0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x33, - 0x30,0x33,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x5f, - 0x31,0x33,0x30,0x31,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31, - 0x33,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x33,0x32,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64, - 0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x33,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x38,0x31,0x2c,0x20,0x5f,0x36, + 0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x5f,0x36,0x38,0x31,0x2c,0x20,0x5f,0x36, + 0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x36,0x37,0x37,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65, + 0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c, + 0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f, + 0x36,0x37,0x37,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c, + 0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c, + 0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74, + 0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c, + 0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39, + 0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x38,0x34, + 0x34,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x38,0x35,0x31,0x20,0x3d,0x20,0x5f,0x38,0x34,0x34,0x2e, + 0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x38,0x34,0x34,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x36, + 0x39,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x38,0x35,0x31,0x2e,0x78, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28, + 0x28,0x5f,0x38,0x35,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x5f,0x38,0x35,0x31,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28, + 0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x38,0x36,0x39,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x38,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x38,0x37,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x38,0x30,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f, + 0x38,0x36,0x39,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x38,0x38,0x30,0x20,0x3d,0x20,0x5f,0x38,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x38,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x38,0x36,0x39, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x30,0x2e,0x30,0x30,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32, + 0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30, + 0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37, + 0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x5f,0x38,0x33,0x34,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63, + 0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, + 0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x5f,0x38, + 0x36,0x39,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x32,0x20,0x5f,0x39,0x31,0x37,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f, + 0x39,0x31,0x32,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x5f,0x39,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70, + 0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x39, + 0x31,0x37,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x31,0x37,0x2e,0x79,0x29,0x20,0x2a,0x20, + 0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, 0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64, 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64, 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x33,0x34,0x36,0x20,0x3d,0x20, - 0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x33,0x34,0x36,0x20,0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x36,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x34,0x36,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x30,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f, + 0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f, + 0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x5b,0x5f,0x31,0x33,0x34,0x36,0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x39,0x20,0x3d,0x20,0x6d,0x69,0x78, - 0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, - 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36,0x5d, - 0x2c,0x20,0x5f,0x31,0x33,0x36,0x36,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34, - 0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31, - 0x33,0x37,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x36,0x20,0x2b, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x36,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x36,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x37,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x33,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x38,0x34,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x39,0x36,0x31, + 0x2c,0x20,0x5f,0x39,0x37,0x33,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37, + 0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x39,0x38, + 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b, 0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77, + 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77, 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64, 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x2c,0x20,0x28,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x20,0x2f, - 0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36, - 0x5d,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74, - 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x30,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61, - 0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20, - 0x2a,0x20,0x28,0x5f,0x31,0x34,0x30,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20, - 0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x5f,0x31,0x34,0x30,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31, - 0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31, - 0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31, - 0x34,0x39,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62, - 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, - 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a, - 0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f, - 0x31,0x36,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, - 0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x36,0x39,0x29,0x20,0x2b,0x20,0x5f,0x31,0x36,0x32,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28, - 0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2b,0x20,0x5f, - 0x31,0x36,0x32,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, - 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, - 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x66, - 0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x39,0x38,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f, - 0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x30,0x32,0x20,0x3d,0x20,0x5f,0x31,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x39, - 0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30, - 0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, - 0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x32,0x30,0x32,0x20,0x2a,0x20, - 0x5f,0x32,0x30,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x38,0x29,0x29,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x20,0x2f,0x20, + 0x28,0x5f,0x39,0x36,0x31,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44, + 0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x35,0x20,0x3d,0x20,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x31,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e, + 0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32, + 0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d, + 0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68, + 0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x5f,0x31,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f, + 0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20, + 0x2a,0x20,0x5f,0x31,0x34,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x38,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71, + 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x35,0x29,0x20, + 0x2b,0x20,0x5f,0x31,0x33,0x38,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x46, + 0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x37,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x37,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x34,0x20,0x2a,0x20, + 0x5f,0x31,0x37,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, + 0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x37,0x38, + 0x20,0x2a,0x20,0x5f,0x31,0x37,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37,0x34,0x29, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62,0x72,0x64,0x66,0x5f, + 0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4c,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e, + 0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c, + 0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x30,0x38,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d, + 0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, + 0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33, + 0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x36,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x32,0x20,0x2a,0x20,0x5f,0x32,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x30,0x38,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x32,0x36,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20, + 0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, + 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, + 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x31,0x39,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x32,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f, + 0x32,0x30,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31, + 0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32, + 0x35,0x33,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53, + 0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x35,0x33,0x29,0x20,0x2a,0x20,0x28, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29, + 0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a, + 0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37, + 0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37, + 0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x35,0x33,0x20,0x2a,0x20,0x28,0x70, + 0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47, + 0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74, + 0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a, + 0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x39,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x30,0x38,0x20,0x3d,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37, + 0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d, + 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, + 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, + 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, + 0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e, + 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, + 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, + 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, + 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37, + 0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33, + 0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28, + 0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e, + 0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x30,0x38,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, 0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x32,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c, - 0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x36,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30, - 0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34, - 0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x30,0x20,0x3d,0x20,0x5f,0x32,0x34, - 0x36,0x20,0x2a,0x20,0x5f,0x32,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, - 0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x35,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, - 0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c, - 0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37, - 0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31, - 0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32, - 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, - 0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x33,0x32, - 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36, - 0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x37,0x37,0x20, - 0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c, - 0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x37,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, - 0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x76,0x65, - 0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34, - 0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x37,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44, - 0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a, - 0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d, - 0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75, - 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32, - 0x32,0x31,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45, - 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61, - 0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x34, - 0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28, - 0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e, - 0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39, - 0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, - 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, - 0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, - 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a, - 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a, - 0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, - 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29, - 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, - 0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38, - 0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32, - 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, - 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32, - 0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a, - 0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a, - 0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e, - 0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38, - 0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78, - 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a, - 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x33,0x31,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, - 0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, - 0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, - 0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, - 0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73, - 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, + 0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34, + 0x31,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29, + 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38, + 0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37, + 0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x32,0x35,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31, + 0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b, + 0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x34,0x20,0x5f,0x34,0x38,0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65, + 0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x38,0x20, - 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39, - 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, - 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, - 0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x34,0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, - 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36, - 0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20, - 0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, - 0x35,0x31,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50, + 0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76, + 0x65,0x63,0x32,0x28,0x5f,0x34,0x31,0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x34,0x32,0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78, + 0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x32,0x35,0x29,0x20,0x2d,0x20, + 0x5f,0x34,0x32,0x35,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29, + 0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61, + 0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49, + 0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28, + 0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, + 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, + 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63, + 0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20, + 0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x5f,0x34,0x32,0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x39,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x34,0x38,0x39,0x2e,0x79,0x29, + 0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62, + 0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65, + 0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, + 0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, + 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61, + 0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, + 0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50, 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, 0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d, - 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x76,0x65,0x63,0x32, - 0x28,0x5f,0x34,0x33,0x38,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, - 0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x34,0x34,0x38,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x76,0x65, - 0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, - 0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34,0x38,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34, - 0x38,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30, - 0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x33,0x38,0x29,0x2c,0x20,0x35, - 0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70, - 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61, - 0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, - 0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38, - 0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30, - 0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x74, - 0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73, - 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d, - 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d, - 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, - 0x5f,0x34,0x34,0x38,0x20,0x2a,0x20,0x5f,0x35,0x31,0x32,0x2e,0x78,0x29,0x20,0x2b, - 0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x35,0x31,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, - 0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c, - 0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20, - 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20, - 0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73, - 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44, - 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d, - 0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74, - 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20, - 0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, - 0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70, - 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c, - 0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34, - 0x31,0x31,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x20,0x3d,0x20,0x5f,0x31,0x34,0x31,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, - 0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x34,0x31,0x31,0x2c, - 0x20,0x5f,0x31,0x34,0x31,0x38,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x63, - 0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69,0x65,0x77, + 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, + 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x30,0x31,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x30,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x32,0x33,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x31, + 0x36,0x2c,0x20,0x5f,0x31,0x30,0x32,0x33,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x38,0x33,0x34,0x2e,0x76,0x69,0x65,0x77, 0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, 0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d, 0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36, 0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c, 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x5f,0x31,0x34,0x34, - 0x39,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35, + 0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x34,0x36,0x37,0x20,0x3d,0x20,0x76,0x65,0x63, - 0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x36,0x37,0x29, - 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x5f,0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x34,0x38,0x37,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x34,0x37,0x37,0x5d,0x20, - 0x2a,0x20,0x5f,0x31,0x34,0x36,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x39,0x34,0x20,0x3d,0x20,0x5f,0x31, - 0x34,0x38,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f, - 0x31,0x34,0x38,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x35,0x31,0x31,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x33,0x28,0x28,0x5f,0x31,0x34,0x39,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x34,0x39, - 0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x34,0x39,0x34, - 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, - 0x6c,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65, - 0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x35,0x31,0x31,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x32,0x33,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x31, - 0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32,0x33,0x20,0x3d, - 0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e, - 0x28,0x5f,0x31,0x35,0x31,0x31,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, - 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x5f,0x31,0x35,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, - 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x32,0x33,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38, + 0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x34,0x20,0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x37,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x33,0x34,0x2e, + 0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x32,0x29,0x2e,0x7a,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x35,0x20,0x3c,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30, + 0x37,0x35,0x20,0x3c,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x5f,0x31,0x30,0x39,0x39,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31, + 0x30,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f, + 0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x30,0x39,0x39,0x2e,0x77,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31, + 0x32,0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x31,0x30,0x36, + 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c, + 0x20,0x28,0x28,0x5f,0x31,0x31,0x30,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33, + 0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x30,0x36,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31, + 0x32,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61, + 0x6e,0x28,0x5f,0x31,0x31,0x32,0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, + 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x37,0x29,0x0a,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, - 0x3d,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73, - 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28, + 0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x32, + 0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, + 0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x31,0x31,0x33,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, + 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20, + 0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, - 0x7a,0x65,0x28,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, - 0x20,0x76,0x65,0x63,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30, - 0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, - 0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e, + 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e, 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x5f,0x31,0x35,0x38,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70, - 0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, - 0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74, - 0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73, - 0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38, - 0x34,0x20,0x3d,0x20,0x5f,0x31,0x35,0x38,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73, - 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x35,0x38,0x34,0x2c,0x20,0x5f, - 0x31,0x35,0x38,0x34,0x2c,0x20,0x5f,0x31,0x35,0x38,0x34,0x2c,0x20,0x31,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x67, - 0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x67,0x72,0x69,0x64, - 0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x7a,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, - 0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x76,0x5f,0x6d, - 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6d, - 0x69,0x78,0x28,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, - 0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47, - 0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x70,0x6f, - 0x77,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, - 0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x38,0x2e, - 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, - 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x36, - 0x38,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f, - 0x31,0x34,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x31,0x36,0x38,0x33,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, - 0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x34,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20, - 0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d, - 0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d, - 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79, + 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28, + 0x5f,0x38,0x33,0x34,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34, + 0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e, + 0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65, + 0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, + 0x32,0x30,0x35,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64, + 0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20, + 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20, + 0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69, + 0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f, + 0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x36,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x30,0x35,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, + 0x34,0x28,0x5f,0x31,0x32,0x30,0x36,0x2c,0x20,0x5f,0x31,0x32,0x30,0x36,0x2c,0x20, + 0x5f,0x31,0x32,0x30,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65, + 0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x7a,0x20,0x3e, + 0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b, + 0x20,0x5f,0x38,0x33,0x34,0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65, + 0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x38,0x33, + 0x34,0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x7a,0x77, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65, + 0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x28,0x70,0x6f,0x77,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x2c,0x20,0x38,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20, + 0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x2d, + 0x28,0x5f,0x38,0x33,0x34,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x33,0x30,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x31,0x30,0x32,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, + 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33, + 0x34,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e, + 0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73, + 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x31,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x75,0x6e, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x39,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x30,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x31,0x5d,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x32,0x5d,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x34,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x34,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e, - 0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, - 0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73, - 0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x35,0x38,0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x00, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x62,0x61, + 0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f, + 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d, + 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x31,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73, + 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x31,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b, + 0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x34,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x35, + 0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x36,0x5d,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x37,0x5d,0x20,0x3d,0x20, + 0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f, + 0x38,0x33,0x34,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, + 0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x32,0x30,0x36,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + }; /* struct instance @@ -2017,19 +1636,16 @@ static const uint8_t geom_vs_source_hlsl5[2542] = { /* cbuffer ub_pass : register(b1) { - float4 _1198_sun_dir_world : packoffset(c0); - float4 _1198_sun_color : packoffset(c1); - int4 _1198_flags : packoffset(c2); - float4 _1198_camera_pos : packoffset(c3); - float4 _1198_grid_offset : packoffset(c4); - row_major float4x4 _1198_view : packoffset(c5); - float4 _1198_cascade_far_view_z : packoffset(c9); - float4 _1198_cascade_texel_world : packoffset(c10); - float4 _1198_cascade_depth_bias : packoffset(c11); - float4 _1198_shadow_params : packoffset(c12); - row_major float4x4 _1198_cascade_matrices[4] : packoffset(c13); - float4 _1198_sh[9] : packoffset(c29); - float4 _1198_ibl_params : packoffset(c38); + float4 _834_sun_dir_world : packoffset(c0); + float4 _834_sun_color : packoffset(c1); + int4 _834_flags : packoffset(c2); + float4 _834_camera_pos : packoffset(c3); + float4 _834_grid_offset : packoffset(c4); + row_major float4x4 _834_view : packoffset(c5); + float4 _834_cascade_far_view_z : packoffset(c9); + row_major float4x4 _834_cascade_matrices[3] : packoffset(c10); + float4 _834_sh[9] : packoffset(c22); + float4 _834_ibl_params : packoffset(c31); }; Texture2DArray tex_shadow : register(t0); @@ -2069,230 +1685,104 @@ static const uint8_t geom_vs_source_hlsl5[2542] = { return ret; } - int selectShadowCascade(float4 far_view_z, float view_z) - { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - float3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); - } - return float3(1.0f, 0.89999997615814208984375f, 0.300000011920928955078125f); - } - float3 proceduralGrid(float2 line_xz, float2 axis_xz, float3 base_color, float cell_size) { - float2 _559 = line_xz / cell_size.xx; - float2 _575 = abs(frac(_559 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_559), 9.9999999747524270787835121154785e-07f.xx); - float2 _590 = line_xz / (cell_size * 10.0f).xx; - float2 _604 = abs(frac(_590 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_590), 9.9999999747524270787835121154785e-07f.xx); - float2 _635 = max(fwidth(axis_xz), 9.9999999747524270787835121154785e-07f.xx); - return lerp(lerp(lerp(lerp(base_color, base_color * 0.699999988079071044921875f, (1.0f - clamp(min(_575.x, _575.y), 0.0f, 1.0f)).xxx), base_color * 0.3499999940395355224609375f, (1.0f - clamp(min(_604.x, _604.y), 0.0f, 1.0f)).xxx), float3(1.0f, 0.0f, 0.0f), ((1.0f - clamp(abs(axis_xz.y) / _635.y, 0.0f, 1.0f)) * step(0.0f, axis_xz.x)).xxx), float3(0.0f, 0.0f, 1.0f), ((1.0f - clamp(abs(axis_xz.x) / _635.x, 0.0f, 1.0f)) * step(0.0f, axis_xz.y)).xxx); + float2 _536 = line_xz / cell_size.xx; + float2 _552 = abs(frac(_536 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_536), 9.9999999747524270787835121154785e-07f.xx); + float2 _567 = line_xz / (cell_size * 10.0f).xx; + float2 _581 = abs(frac(_567 - 0.5f.xx) - 0.5f.xx) / max(fwidth(_567), 9.9999999747524270787835121154785e-07f.xx); + float2 _612 = max(fwidth(axis_xz), 9.9999999747524270787835121154785e-07f.xx); + return lerp(lerp(lerp(lerp(base_color, base_color * 0.699999988079071044921875f, (1.0f - clamp(min(_552.x, _552.y), 0.0f, 1.0f)).xxx), base_color * 0.3499999940395355224609375f, (1.0f - clamp(min(_581.x, _581.y), 0.0f, 1.0f)).xxx), float3(1.0f, 0.0f, 0.0f), ((1.0f - clamp(abs(axis_xz.y) / _612.y, 0.0f, 1.0f)) * step(0.0f, axis_xz.x)).xxx), float3(0.0f, 0.0f, 1.0f), ((1.0f - clamp(abs(axis_xz.x) / _612.x, 0.0f, 1.0f)) * step(0.0f, axis_xz.y)).xxx); } - float sampleShadowTap(Texture2DArray tex, SamplerComparisonState smp, float2 uv, float layer, float ref_z) + float sampleShadowPCF(int cascade, float3 light_uv, float bias) { - return tex.SampleCmp(smp, float4(uv, layer, ref_z).xyz, ref_z); - } - - float sampleShadowPCF(Texture2DArray tex, SamplerComparisonState smp, int cascade, float3 light_uv, float bias, float scale, float inv_size) - { - float _742 = float(cascade); - float _747 = light_uv.z - bias; - float2 _752 = light_uv.xy * (1.0f / inv_size); - float2 _757 = floor(_752 + 0.5f.xx); - float _764 = (_752.x + 0.5f) - _757.x; - float _771 = (_752.y + 0.5f) - _757.y; - float2 _776 = (_757 - 0.5f.xx) * inv_size; - float _780 = inv_size * scale; - float _783 = 5.0f * _764; - float _785 = _783 - 6.0f; - float _789 = 11.0f * _764; - float _791 = _789 - 28.0f; - float _797 = (-17.0f) - _789; - float _802 = (-1.0f) - _783; - float _806 = 4.0f * _764; - float _810 = ((_806 - 5.0f) / _785) - 3.0f; - float _818 = ((_806 - 16.0f) / _791) - 1.0f; - float _827 = (((-5.0f) - (7.0f * _764)) / _797) + 1.0f; - float _833 = ((-_764) / _802) + 3.0f; - float _836 = 5.0f * _771; - float _837 = _836 - 6.0f; - float _840 = 11.0f * _771; - float _841 = _840 - 28.0f; - float _846 = (-17.0f) - _840; - float _851 = (-1.0f) - _836; - float _854 = 4.0f * _771; - float _858 = ((_854 - 5.0f) / _837) - 3.0f; - float _865 = ((_854 - 16.0f) / _841) - 1.0f; - float _873 = (((-5.0f) - (7.0f * _771)) / _846) + 1.0f; - float _879 = ((-_771) / _851) + 3.0f; - float sum = 0.0f; - float2 param = _776 + (float2(_810, _858) * _780); - float param_1 = _742; - float param_2 = _747; - sum += ((_785 * _837) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _776 + (float2(_818, _858) * _780); - float param_4 = _742; - float param_5 = _747; - sum += ((_791 * _837) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _776 + (float2(_827, _858) * _780); - float param_7 = _742; - float param_8 = _747; - sum += ((_797 * _837) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _776 + (float2(_833, _858) * _780); - float param_10 = _742; - float param_11 = _747; - sum += ((_802 * _837) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _776 + (float2(_810, _865) * _780); - float param_13 = _742; - float param_14 = _747; - sum += ((_785 * _841) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _776 + (float2(_818, _865) * _780); - float param_16 = _742; - float param_17 = _747; - sum += ((_791 * _841) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _776 + (float2(_827, _865) * _780); - float param_19 = _742; - float param_20 = _747; - sum += ((_797 * _841) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _776 + (float2(_833, _865) * _780); - float param_22 = _742; - float param_23 = _747; - sum += ((_802 * _841) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _776 + (float2(_810, _873) * _780); - float param_25 = _742; - float param_26 = _747; - sum += ((_785 * _846) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _776 + (float2(_818, _873) * _780); - float param_28 = _742; - float param_29 = _747; - sum += ((_791 * _846) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _776 + (float2(_827, _873) * _780); - float param_31 = _742; - float param_32 = _747; - sum += ((_797 * _846) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _776 + (float2(_833, _873) * _780); - float param_34 = _742; - float param_35 = _747; - sum += ((_802 * _846) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _776 + (float2(_810, _879) * _780); - float param_37 = _742; - float param_38 = _747; - sum += ((_785 * _851) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _776 + (float2(_818, _879) * _780); - float param_40 = _742; - float param_41 = _747; - sum += ((_791 * _851) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _776 + (float2(_827, _879) * _780); - float param_43 = _742; - float param_44 = _747; - sum += ((_797 * _851) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _776 + (float2(_833, _879) * _780); - float param_46 = _742; - float param_47 = _747; - float _1183 = sum; - float _1184 = _1183 + ((_802 * _851) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1184; - return _1184 * 0.000369822490029036998748779296875f; + float _656 = float(cascade); + float _661 = light_uv.z - bias; + float _677 = light_uv.x - 0.00048828125f; + float _681 = light_uv.y - 0.00048828125f; + float _711 = light_uv.x + 0.00048828125f; + float _779 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_677, _681, _656, _661).xyz, _661) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _681, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(_711, _681, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(_677, light_uv.y, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(_711, light_uv.y, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(_677, _779, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _779, _656, _661).xyz, _661)) + tex_shadow.SampleCmp(smp_shadow, float4(_711, _779, _656, _661).xyz, _661)) * 0.111111111938953399658203125f; } float sampleCascade(int cascade, float3 world_pos, float3 world_normal) { - float _1213 = clamp(_1198_cascade_texel_world.x / _1198_cascade_texel_world[cascade], 0.25f, 1.0f); - float _1222 = max(dot(world_normal, normalize(_1198_sun_dir_world.xyz)), 0.0f); - float _1232 = 3.0f * _1213; - float4 _1255 = mul(float4(world_pos + (world_normal * ((((_1232 + 0.5f) * 1.41420996189117431640625f) * sqrt(max(1.0f - (_1222 * _1222), 0.0f))) * _1198_cascade_texel_world[cascade])), 1.0f), _1198_cascade_matrices[cascade]); - float3 _1263 = _1255.xyz / _1255.w.xxx; - float _1280 = _1263.z; - float3 _1281 = float3((_1263.x * 0.5f) + 0.5f, ((_1263.y * _1198_shadow_params.x) * 0.5f) + 0.5f, _1280); - bool _1284 = _1280 < 0.0f; - bool _1291; - if (!_1284) + float4 _844 = mul(float4(world_pos, 1.0f), _834_cascade_matrices[cascade]); + float3 _851 = _844.xyz / _844.w.xxx; + float3 _869 = float3((_851.x * 0.5f) + 0.5f, ((_851.y * _834_cascade_far_view_z.w) * 0.5f) + 0.5f, _851.z); + bool _873 = any(bool3(_869.x < 0.0f.xxx.x, _869.y < 0.0f.xxx.y, _869.z < 0.0f.xxx.z)); + bool _880; + if (!_873) { - _1291 = _1280 > 1.0f; + _880 = any(bool3(_869.x > 1.0f.xxx.x, _869.y > 1.0f.xxx.y, _869.z > 1.0f.xxx.z)); } else { - _1291 = _1284; + _880 = _873; } - if (_1291) - { - return 1.0f; - } - float _1301 = (_1232 + 1.0f) * _1198_shadow_params.y; - float2 _1303 = _1281.xy; - float2 _1306 = (-_1301).xx; - bool _1309 = any(bool2(_1303.x < _1306.x, _1303.y < _1306.y)); - bool _1320; - if (!_1309) - { - float2 _1317 = (1.0f + _1301).xx; - _1320 = any(bool2(_1303.x > _1317.x, _1303.y > _1317.y)); - } - else - { - _1320 = _1309; - } - if (_1320) + if (_880) { return 1.0f; } int param = cascade; - float3 param_1 = _1281; - float param_2 = _1198_cascade_depth_bias[cascade]; - float param_3 = _1213; - float param_4 = _1198_shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _869; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_834_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _912 = _869.xy; + float2 _917 = min(_912, 1.0f.xx - _912); + pcf = lerp(1.0f, pcf, clamp(min(_917.x, _917.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; } float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) { - float4 param = _1198_cascade_far_view_z; - float param_1 = view_z; - int _1346 = selectShadowCascade(param, param_1); - int param_2 = _1346; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1346 < 3) + int cascade = 2; + if (view_z < _834_cascade_far_view_z.x) { - float _1366; - if (_1346 == 0) + cascade = 0; + } + else + { + if (view_z < _834_cascade_far_view_z.y) { - _1366 = 0.0f; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _961; + if (cascade == 0) + { + _961 = _834_cascade_far_view_z.x; } else { - _1366 = _1198_cascade_far_view_z[_1346 - 1]; + _961 = _834_cascade_far_view_z.y; } - float _1379 = lerp(_1198_cascade_far_view_z[_1346], _1366, 0.100000001490116119384765625f); - if (view_z > _1379) + float _973; + if (cascade == 0) { - int param_5 = _1346 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = lerp(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1379) / (_1198_cascade_far_view_z[_1346] - _1379)); + _973 = 0.0f; + } + else + { + _973 = _834_cascade_far_view_z.x; + } + float _984 = lerp(_961, _973, 0.100000001490116119384765625f); + if (view_z > _984) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _984) / (_961 - _984)); } } return shadow; @@ -2300,56 +1790,56 @@ static const uint8_t geom_vs_source_hlsl5[2542] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _140 = alpha * alpha; - float _149 = ((n_dot_h * n_dot_h) * (_140 - 1.0f)) + 1.0f; - return _140 / ((3.1415927410125732421875f * _149) * _149); + float _116 = alpha * alpha; + float _125 = ((n_dot_h * n_dot_h) * (_116 - 1.0f)) + 1.0f; + return _116 / ((3.1415927410125732421875f * _125) * _125); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _162 = alpha * alpha; - float _169 = 1.0f - _162; - return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _169) + _162)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _169) + _162))) + 9.9999997473787516355514526367188e-06f); + float _138 = alpha * alpha; + float _145 = 1.0f - _138; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _145) + _138)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _145) + _138))) + 9.9999997473787516355514526367188e-06f); } float3 pbrFresnelSchlick(float v_dot_h, float3 f0) { - float _198 = 1.0f - v_dot_h; - float _202 = _198 * _198; - return f0 + ((1.0f.xxx - f0) * ((_202 * _202) * _198)); + float _174 = 1.0f - v_dot_h; + float _178 = _174 * _174; + return f0 + ((1.0f.xxx - f0) * ((_178 * _178) * _174)); } float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) { - float _221 = max(dot(N, L), 0.0f); - float3 _232 = normalize(V + L); - float _246 = max(roughness, 0.04500000178813934326171875f); - float _250 = _246 * _246; - float param = max(dot(N, _232), 0.0f); - float param_1 = _250; + float _197 = max(dot(N, L), 0.0f); + float3 _208 = normalize(V + L); + float _222 = max(roughness, 0.04500000178813934326171875f); + float _226 = _222 * _222; + float param = max(dot(N, _208), 0.0f); + float param_1 = _226; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); - float param_3 = _221; - float param_4 = _250; - float param_5 = max(dot(V, _232), 0.0f); + float param_3 = _197; + float param_4 = _226; + float param_5 = max(dot(V, _208), 0.0f); float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); - float3 _277 = pbrFresnelSchlick(param_5, param_6); - return ((((((1.0f.xxx - _277) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_277 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _221; + float3 _253 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _253) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_253 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _197; } float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) { - float3 _431 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); - return _431; + float3 _408 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _408; } float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) { - float _438 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); - float3 _448 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float _415 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _425 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); float3 param = N_world; float4 param_1[9] = sh; - float4 _512 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_438, roughness)); - return (((((1.0f.xxx - (_448 + ((max((1.0f - roughness).xxx, _448) - _448) * pow(max(0.0f, 1.0f - _438), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_448 * _512.x) + _512.y.xxx)); + float4 _489 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_415, roughness)); + return (((((1.0f.xxx - (_425 + ((max((1.0f - roughness).xxx, _425) - _425) * pow(max(0.0f, 1.0f - _415), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_425 * _489.x) + _489.y.xxx)); } float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) @@ -2371,99 +1861,122 @@ static const uint8_t geom_vs_source_hlsl5[2542] = { void frag_main() { - float3 _1411 = normalize(v_world_normal); - float3 n_world = _1411; - float3 _1418 = _1198_camera_pos.xyz - v_view_pos; - if (dot(_1411, _1418) < 0.0f) + float3 _1016 = normalize(v_world_normal); + float3 n_world = _1016; + float3 _1023 = _834_camera_pos.xyz - v_view_pos; + if (dot(_1016, _1023) < 0.0f) { n_world = -n_world; } - if (_1198_flags.x == 1) + if (_834_flags.x == 1) { - float _1449 = clamp(mul(float4(v_view_pos, 1.0f), _1198_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); - out_color = float4(_1449, _1449, _1449, 1.0f); + float _1054 = clamp(mul(float4(v_view_pos, 1.0f), _834_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1054, _1054, _1054, 1.0f); return; } - if (_1198_flags.x == 2) + if (_834_flags.x == 2) { - float4 _1467 = float4(v_view_pos, 1.0f); - float4 param = _1198_cascade_far_view_z; - float param_1 = -mul(_1467, _1198_view).z; - int _1477 = selectShadowCascade(param, param_1); - float4 _1487 = mul(_1467, _1198_cascade_matrices[_1477]); - float3 _1494 = _1487.xyz / _1487.w.xxx; - float3 _1511 = float3((_1494.x * 0.5f) + 0.5f, ((_1494.y * _1198_shadow_params.x) * 0.5f) + 0.5f, _1494.z); - bool _1516 = any(bool3(_1511.x < 0.0f.xxx.x, _1511.y < 0.0f.xxx.y, _1511.z < 0.0f.xxx.z)); - bool _1523; - if (!_1516) + float4 _1072 = float4(v_view_pos, 1.0f); + float _1075 = -mul(_1072, _834_view).z; + int cascade = 2; + if (_1075 < _834_cascade_far_view_z.x) { - _1523 = any(bool3(_1511.x > 1.0f.xxx.x, _1511.y > 1.0f.xxx.y, _1511.z > 1.0f.xxx.z)); + cascade = 0; } else { - _1523 = _1516; + if (_1075 < _834_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1099 = mul(_1072, _834_cascade_matrices[cascade]); + float3 _1106 = _1099.xyz / _1099.w.xxx; + float3 _1123 = float3((_1106.x * 0.5f) + 0.5f, ((_1106.y * _834_cascade_far_view_z.w) * 0.5f) + 0.5f, _1106.z); + bool _1127 = any(bool3(_1123.x < 0.0f.xxx.x, _1123.y < 0.0f.xxx.y, _1123.z < 0.0f.xxx.z)); + bool _1134; + if (!_1127) + { + _1134 = any(bool3(_1123.x > 1.0f.xxx.x, _1123.y > 1.0f.xxx.y, _1123.z > 1.0f.xxx.z)); + } + else + { + _1134 = _1127; } float3 tint = 1.0f.xxx; - if (!_1523) + if (!_1134) { - int param_2 = _1477; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } } out_color = float4(tint, 1.0f); return; } - if (_1198_flags.x == 3) + if (_834_flags.x == 3) { - out_color = float4((normalize(mul(float4(n_world, 0.0f), _1198_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + out_color = float4((normalize(mul(float4(n_world, 0.0f), _834_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); return; } - uint _1575_dummy_parameter; - float4 _1583 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1575_dummy_parameter))), 0.0f); - float _1584 = _1583.x; - if (_1198_flags.x == 4) + uint _1197_dummy_parameter; + float4 _1205 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1197_dummy_parameter))), 0.0f); + float _1206 = _1205.x; + if (_834_flags.x == 4) { - out_color = float4(_1584, _1584, _1584, 1.0f); + out_color = float4(_1206, _1206, _1206, 1.0f); return; } float3 baseColor = v_base_color.xyz; if (v_material.z > 0.5f) { - float2 param_3 = v_view_pos.xz + _1198_grid_offset.xy; - float2 param_4 = v_view_pos.xz + _1198_grid_offset.zw; - float3 param_5 = v_base_color.xyz; - float param_6 = v_material.w; - baseColor = lerp(v_base_color.xyz, proceduralGrid(param_3, param_4, param_5, param_6), pow(clamp(n_world.y, 0.0f, 1.0f), 8.0f).xxx); + float2 param = v_view_pos.xz + _834_grid_offset.xy; + float2 param_1 = v_view_pos.xz + _834_grid_offset.zw; + float3 param_2 = v_base_color.xyz; + float param_3 = v_material.w; + baseColor = lerp(v_base_color.xyz, proceduralGrid(param, param_1, param_2, param_3), pow(clamp(n_world.y, 0.0f, 1.0f), 8.0f).xxx); } - float3 param_7 = v_view_pos; - float3 param_8 = n_world; - float param_9 = -mul(float4(v_view_pos, 1.0f), _1198_view).z; - float3 _1683 = normalize(_1418); - float3 param_10 = n_world; - float3 param_11 = _1683; - float3 param_12 = normalize(_1198_sun_dir_world.xyz); - float3 param_13 = _1198_sun_color.xyz * sampleShadowCascaded(param_7, param_8, param_9); - float3 param_14 = baseColor; - float param_15 = v_material.x; - float param_16 = v_material.y; - bool param_17 = _1198_ibl_params.y > 0.5f; - float3 param_18 = n_world; - float3 param_19 = _1683; - float3 param_20 = baseColor; - float param_21 = v_material.x; - float param_22 = v_material.y; - float param_23 = _1198_sun_color.w; - float4 param_24[9]; - param_24[0] = _1198_sh[0]; - param_24[1] = _1198_sh[1]; - param_24[2] = _1198_sh[2]; - param_24[3] = _1198_sh[3]; - param_24[4] = _1198_sh[4]; - param_24[5] = _1198_sh[5]; - param_24[6] = _1198_sh[6]; - param_24[7] = _1198_sh[7]; - param_24[8] = _1198_sh[8]; - float param_25 = _1198_ibl_params.x; - out_color = float4((brdf_evaluate(param_10, param_11, param_12, param_13, param_14, param_15, param_16) + (pbrEvaluateAmbient(param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_25) * _1584)) * v_base_color.w, v_base_color.w); + float3 param_4 = v_view_pos; + float3 param_5 = n_world; + float param_6 = -mul(float4(v_view_pos, 1.0f), _834_view).z; + float3 _1305 = normalize(_1023); + float3 param_7 = n_world; + float3 param_8 = _1305; + float3 param_9 = normalize(_834_sun_dir_world.xyz); + float3 param_10 = _834_sun_color.xyz * sampleShadowCascaded(param_4, param_5, param_6); + float3 param_11 = baseColor; + float param_12 = v_material.x; + float param_13 = v_material.y; + bool param_14 = _834_ibl_params.y > 0.5f; + float3 param_15 = n_world; + float3 param_16 = _1305; + float3 param_17 = baseColor; + float param_18 = v_material.x; + float param_19 = v_material.y; + float param_20 = _834_sun_color.w; + float4 param_21[9]; + param_21[0] = _834_sh[0]; + param_21[1] = _834_sh[1]; + param_21[2] = _834_sh[2]; + param_21[3] = _834_sh[3]; + param_21[4] = _834_sh[4]; + param_21[5] = _834_sh[5]; + param_21[6] = _834_sh[6]; + param_21[7] = _834_sh[7]; + param_21[8] = _834_sh[8]; + float param_22 = _834_ibl_params.x; + out_color = float4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_22) * _1206)) * v_base_color.w, v_base_color.w); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) @@ -2480,186 +1993,129 @@ static const uint8_t geom_vs_source_hlsl5[2542] = { return stage_output; } */ -static const uint8_t geom_fs_source_hlsl5[19032] = { +static const uint8_t geom_fs_source_hlsl5[14711] = { 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, - 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x66,0x6c, - 0x61,0x67,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x5f,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f, - 0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63, - 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, - 0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65, - 0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, - 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63, - 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x34, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x34, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x38,0x33,0x34,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38, + 0x33,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x34,0x5f, + 0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x20,0x3a,0x20,0x70,0x61, + 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20, 0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x20,0x3a, - 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, - 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x69,0x62,0x6c, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, - 0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x38,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54, - 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b, - 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73, - 0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, - 0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, - 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20, - 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a, - 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, - 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b, + 0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x34,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x35,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x34, + 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, + 0x28,0x63,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61, + 0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, + 0x65,0x73,0x5b,0x33,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x31,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70, + 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x31,0x29,0x3b,0x0a, + 0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72, + 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, + 0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d, + 0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, + 0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b, 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, - 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67, - 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, - 0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, - 0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75, - 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, - 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, + 0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c, + 0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, + 0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61, + 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a, + 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73, + 0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3a, + 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, - 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, - 0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20, - 0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a, - 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78, - 0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65, - 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20, - 0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20, - 0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f, - 0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c, - 0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20, - 0x69,0x20,0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b, - 0x2b,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61, - 0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69, - 0x6e,0x74,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, - 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, - 0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20, - 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, - 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, - 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30, - 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30, - 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, - 0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39, - 0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38, - 0x34,0x33,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30, - 0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32, - 0x35,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, + 0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e, + 0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a,0x20, + 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, + 0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, + 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72,0x67, + 0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73, + 0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, + 0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c, + 0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d, + 0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72, + 0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72, + 0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, 0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x66,0x6c, 0x6f,0x61,0x74,0x32,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x2c,0x20,0x66,0x6c, 0x6f,0x61,0x74,0x32,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2c,0x20,0x66,0x6c, 0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65, 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, - 0x35,0x35,0x39,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20, + 0x35,0x33,0x36,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20, 0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x37,0x35,0x20,0x3d,0x20, - 0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x28,0x5f,0x35,0x35,0x39,0x20,0x2d,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x35,0x32,0x20,0x3d,0x20, + 0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x28,0x5f,0x35,0x33,0x36,0x20,0x2d,0x20, 0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e, 0x78,0x78,0x29,0x20,0x2f,0x20,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68, - 0x28,0x5f,0x35,0x35,0x39,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x28,0x5f,0x35,0x33,0x36,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, 0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35, 0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x2e,0x78, 0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, - 0x35,0x39,0x30,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20, + 0x35,0x36,0x37,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20, 0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x31,0x30,0x2e, 0x30,0x66,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x5f,0x36,0x30,0x34,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72, - 0x61,0x63,0x28,0x5f,0x35,0x39,0x30,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, + 0x74,0x32,0x20,0x5f,0x35,0x38,0x31,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72, + 0x61,0x63,0x28,0x5f,0x35,0x36,0x37,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78, 0x78,0x29,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2f,0x20, - 0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x39,0x30,0x29, + 0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x36,0x37,0x29, 0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32, 0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34, 0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x2e,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33,0x35,0x20,0x3d,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x31,0x32,0x20,0x3d,0x20, 0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x61,0x78,0x69,0x73,0x5f, 0x78,0x7a,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, 0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31, @@ -2670,1007 +2126,794 @@ static const uint8_t geom_fs_source_hlsl5[19032] = { 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x36,0x39,0x39,0x39,0x39, 0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31, 0x38,0x37,0x35,0x66,0x2c,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x63,0x6c, - 0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x37,0x35,0x2e,0x78,0x2c,0x20, - 0x5f,0x35,0x37,0x35,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, + 0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x35,0x32,0x2e,0x78,0x2c,0x20, + 0x5f,0x35,0x35,0x32,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31, 0x2e,0x30,0x66,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39, 0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30, 0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x63, - 0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x36,0x30,0x34,0x2e,0x78,0x2c, - 0x20,0x5f,0x36,0x30,0x34,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, + 0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x38,0x31,0x2e,0x78,0x2c, + 0x20,0x5f,0x35,0x38,0x31,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, 0x31,0x2e,0x30,0x66,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x2c,0x20,0x66,0x6c,0x6f, 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, 0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, 0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78, - 0x7a,0x2e,0x79,0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30, + 0x7a,0x2e,0x79,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31,0x32,0x2e,0x79,0x2c,0x20,0x30, 0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x73,0x74, 0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a, 0x2e,0x78,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, 0x33,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, 0x30,0x66,0x29,0x2c,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x63,0x6c, 0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e, - 0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30, + 0x78,0x29,0x20,0x2f,0x20,0x5f,0x36,0x31,0x32,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30, 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70, 0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79, 0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x53,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53, - 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6c,0x61,0x79,0x65,0x72, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x2e, - 0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c, - 0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66, - 0x5f,0x7a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, - 0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x37,0x20,0x3d, - 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69, - 0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, - 0x37,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78, - 0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f, - 0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x5f,0x37,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f, - 0x37,0x35,0x32,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x36,0x34,0x20,0x3d, - 0x20,0x28,0x5f,0x37,0x35,0x32,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29, - 0x20,0x2d,0x20,0x5f,0x37,0x35,0x37,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x31,0x20,0x3d,0x20,0x28,0x5f,0x37,0x35, - 0x32,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37, - 0x35,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x5f,0x37,0x37,0x36,0x20,0x3d,0x20,0x28,0x5f,0x37,0x35,0x37,0x20,0x2d,0x20, - 0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73, - 0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x38,0x30,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a, - 0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x38,0x33,0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20,0x2a,0x20, - 0x5f,0x37,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x38,0x33,0x20,0x2d,0x20,0x36,0x2e, - 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x38,0x39,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x37,0x36, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39, - 0x31,0x20,0x3d,0x20,0x5f,0x37,0x38,0x39,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x66, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x39,0x37, - 0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37, - 0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, - 0x30,0x32,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x5f, - 0x37,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x38,0x30,0x36,0x20,0x3d,0x20,0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x37,0x36, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31, - 0x30,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d,0x20,0x35,0x2e,0x30, - 0x66,0x29,0x20,0x2f,0x20,0x5f,0x37,0x38,0x35,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30, - 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31, - 0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d,0x20,0x31,0x36,0x2e, - 0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x37,0x39,0x31,0x29,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, - 0x32,0x37,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29,0x20,0x2d, - 0x20,0x28,0x37,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x29,0x29,0x20, - 0x2f,0x20,0x5f,0x37,0x39,0x37,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x33,0x20,0x3d, - 0x20,0x28,0x28,0x2d,0x5f,0x37,0x36,0x34,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30,0x32, - 0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30,0x66,0x20, - 0x2a,0x20,0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x38,0x33,0x37,0x20,0x3d,0x20,0x5f,0x38,0x33,0x36,0x20,0x2d,0x20, - 0x36,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f, - 0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x38,0x34,0x31,0x20,0x3d,0x20,0x5f,0x38,0x34,0x30,0x20,0x2d,0x20,0x32,0x38,0x2e, - 0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, - 0x34,0x36,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20, - 0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x35,0x31,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x20,0x2d, - 0x20,0x5f,0x38,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x38,0x35,0x34,0x20,0x3d,0x20,0x34,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f, - 0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x38,0x35,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35,0x34,0x20,0x2d,0x20,0x35, - 0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2d,0x20,0x33, - 0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x38,0x36,0x35,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35,0x34,0x20,0x2d,0x20,0x31, - 0x36,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2d,0x20, - 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x37,0x33,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x66,0x29, - 0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x29, - 0x29,0x20,0x2f,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x37,0x39, - 0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x37,0x37,0x31,0x29,0x20,0x2f,0x20,0x5f,0x38, - 0x35,0x31,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20, - 0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a, - 0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f, - 0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f, - 0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, - 0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20,0x2a, - 0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x36, - 0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31, - 0x38,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20, - 0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x38,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20, - 0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f, - 0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, - 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37, - 0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20, - 0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38, - 0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29, - 0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39, - 0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36, - 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c, - 0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f, - 0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20, - 0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37, - 0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31, - 0x38,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20, - 0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x32,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20, - 0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f, - 0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36, - 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37, - 0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x31,0x38,0x33,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x38,0x33,0x20,0x2b,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38, - 0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x34,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x38, - 0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34, - 0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37, - 0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x32,0x31,0x33,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f, - 0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78, - 0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c, - 0x20,0x30,0x2e,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x32,0x20,0x3d, - 0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x33,0x32,0x20,0x3d,0x20,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x31,0x32,0x31, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, - 0x32,0x35,0x35,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28, - 0x28,0x5f,0x31,0x32,0x33,0x32,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2a, - 0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31, - 0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x73, - 0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x28, - 0x5f,0x31,0x32,0x32,0x32,0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x32,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x66,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20, - 0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x36,0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x35, - 0x35,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x32,0x35,0x35,0x2e,0x77,0x2e, - 0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x32,0x38,0x30,0x20,0x3d,0x20,0x5f,0x31,0x32,0x36,0x33,0x2e,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x31, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x32,0x36,0x33, - 0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35, - 0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x32,0x36,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x32,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x5f, - 0x31,0x32,0x38,0x30,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x38,0x34,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x31, - 0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x32,0x39,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x39,0x31, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33, - 0x30,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x32,0x33,0x32,0x20,0x2b,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x33,0x30,0x33,0x20,0x3d,0x20, - 0x5f,0x31,0x32,0x38,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x33,0x30,0x36,0x20,0x3d,0x20,0x28,0x2d,0x5f, - 0x31,0x33,0x30,0x31,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x33,0x30,0x39,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62, - 0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x33,0x30,0x33,0x2e,0x78,0x20,0x3c,0x20,0x5f, - 0x31,0x33,0x30,0x36,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x33,0x30,0x33,0x2e,0x79,0x20, - 0x3c,0x20,0x5f,0x31,0x33,0x30,0x36,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x30,0x39,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x5f,0x31,0x33,0x31,0x37,0x20,0x3d,0x20,0x28,0x31,0x2e,0x30,0x66,0x20, - 0x2b,0x20,0x5f,0x31,0x33,0x30,0x31,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x61,0x6e,0x79, - 0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x33,0x30,0x33,0x2e,0x78,0x20,0x3e, - 0x20,0x5f,0x31,0x33,0x31,0x37,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x33,0x30,0x33,0x2e, - 0x79,0x20,0x3e,0x20,0x5f,0x31,0x33,0x31,0x37,0x2e,0x79,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x32, - 0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x32,0x30,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, - 0x31,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69, - 0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x33,0x34,0x36,0x20,0x3d,0x20, - 0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x34,0x36,0x20,0x3c,0x20,0x33,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x34,0x36,0x20,0x3d,0x3d, - 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x36,0x36,0x20, - 0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43, + 0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x31,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, + 0x37,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x31,0x20,0x3d,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30, + 0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x39,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65, + 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x37,0x2c,0x20,0x5f,0x36,0x38,0x31, + 0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x36,0x38,0x31,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x5f,0x36,0x38, + 0x31,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78, + 0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d, + 0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x37,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36, + 0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31, + 0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20, + 0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x37, + 0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36, + 0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36, + 0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36, + 0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37, + 0x31,0x31,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20, + 0x5f,0x36,0x36,0x31,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39, + 0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32, + 0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34,0x34, + 0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, + 0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x35,0x31, + 0x20,0x3d,0x20,0x5f,0x38,0x34,0x34,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x38, + 0x34,0x34,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x36,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x28,0x5f,0x38,0x35,0x31,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, + 0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x38,0x35, + 0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29, + 0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c, + 0x20,0x5f,0x38,0x35,0x31,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x38,0x37,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f, + 0x6f,0x6c,0x33,0x28,0x5f,0x38,0x36,0x39,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x38,0x36,0x39,0x2e,0x79,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x38, + 0x36,0x39,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, + 0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38, + 0x38,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x38,0x37, + 0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x38,0x38,0x30,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c, + 0x33,0x28,0x5f,0x38,0x36,0x39,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x38,0x36,0x39,0x2e,0x79,0x20,0x3e,0x20, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x38,0x36,0x39, + 0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x38,0x38,0x30,0x20,0x3d,0x20,0x5f,0x38,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x38,0x30,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x38,0x36,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30, + 0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39, + 0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36, + 0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x34,0x5f,0x73, + 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a, + 0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x5f,0x38,0x36,0x39,0x2e,0x78,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x39,0x31,0x37,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x32,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x20,0x2d,0x20,0x5f,0x39,0x31,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20, + 0x6c,0x65,0x72,0x70,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x37,0x2e,0x78, + 0x2c,0x20,0x5f,0x39,0x31,0x37,0x2e,0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3c,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, + 0x3c,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x36,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x36,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36,0x20,0x2d,0x20,0x31,0x5d, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x36,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34, + 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x39,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x39,0x20, - 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b, - 0x5f,0x31,0x33,0x34,0x36,0x5d,0x2c,0x20,0x5f,0x31,0x33,0x36,0x36,0x2c,0x20,0x30, - 0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36, - 0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, - 0x5f,0x31,0x33,0x34,0x36,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31, - 0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36,0x5d,0x20,0x2d,0x20, - 0x5f,0x31,0x33,0x37,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75, - 0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70, - 0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x34,0x30,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x34,0x39,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f, - 0x31,0x34,0x30,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x5f,0x31,0x34,0x30,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39, - 0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37, - 0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34, - 0x39,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72, - 0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43, - 0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c, - 0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20, - 0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f, - 0x31,0x36,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20, - 0x5f,0x31,0x36,0x39,0x29,0x20,0x2b,0x20,0x5f,0x31,0x36,0x32,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, - 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2b,0x20, - 0x5f,0x31,0x36,0x32,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, - 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, - 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, - 0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x38,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66, - 0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x32,0x20,0x3d,0x20,0x5f,0x31,0x39, - 0x38,0x20,0x2a,0x20,0x5f,0x31,0x39,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66, - 0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f, - 0x32,0x30,0x32,0x20,0x2a,0x20,0x5f,0x32,0x30,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31, - 0x39,0x38,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, - 0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x32,0x32,0x31,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, - 0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x36, - 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, - 0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38, - 0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x35,0x30, - 0x20,0x3d,0x20,0x5f,0x32,0x34,0x36,0x20,0x2a,0x20,0x5f,0x32,0x34,0x36,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x33, - 0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, - 0x32,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, - 0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, - 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, - 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, + 0x39,0x37,0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x34,0x20,0x3d,0x20, + 0x6c,0x65,0x72,0x70,0x28,0x5f,0x39,0x36,0x31,0x2c,0x20,0x5f,0x39,0x37,0x33,0x2c, + 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, + 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x39,0x38,0x34,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x2c,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x20,0x2f,0x20,0x28, + 0x5f,0x39,0x36,0x31,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69, + 0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x31,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66, + 0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x36,0x20,0x2f,0x20,0x28,0x28,0x33, + 0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33, + 0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79, + 0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x38,0x20,0x3d,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31, + 0x33,0x38,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20, + 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x34,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x38,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68, + 0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74, + 0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x34,0x20, + 0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x38, + 0x20,0x3d,0x20,0x5f,0x31,0x37,0x34,0x20,0x2a,0x20,0x5f,0x31,0x37,0x34,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29, + 0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x37,0x38,0x20,0x2a,0x20,0x5f,0x31,0x37,0x38, + 0x29,0x20,0x2a,0x20,0x5f,0x31,0x37,0x34,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x32,0x30,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, + 0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30, + 0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37, + 0x31,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x32,0x32,0x36,0x20,0x3d,0x20,0x5f,0x32,0x32,0x32,0x20,0x2a,0x20, + 0x5f,0x32,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x4e,0x2c,0x20,0x5f,0x32,0x30,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f, - 0x32,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, - 0x28,0x56,0x2c,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e, + 0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36, + 0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65, + 0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x30,0x38,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72, + 0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35, + 0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66, + 0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x35,0x33, + 0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68, + 0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x20,0x2d,0x20,0x5f,0x32,0x35,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, + 0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a, + 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, + 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29, + 0x20,0x2b,0x20,0x28,0x5f,0x32,0x35,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44, + 0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a, + 0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d, + 0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x39,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62, + 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64, + 0x69,0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x30,0x38,0x20, + 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30, + 0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, + 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, + 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34, + 0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35, + 0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39, + 0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36, + 0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20, + 0x28,0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35, + 0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20, + 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30, + 0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28, + 0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e, + 0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x30,0x38,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32, + 0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x34,0x31,0x35,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x34,0x32,0x35,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33, 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20, 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61, 0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x37,0x20,0x3d,0x20,0x70,0x62,0x72, - 0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, - 0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32, - 0x37,0x37,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65, - 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30, - 0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35, - 0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32, - 0x37,0x37,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62, - 0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69, - 0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72, - 0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69, - 0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x28,0x28, - 0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32, - 0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20, - 0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d, - 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, - 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, - 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, - 0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, - 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e, - 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, - 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, - 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35, - 0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36, - 0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30, - 0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20, - 0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, - 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, - 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29, - 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, - 0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32, - 0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39, - 0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20, - 0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e, - 0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x5f,0x34,0x33,0x31,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, - 0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, - 0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61, - 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65, - 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x38, - 0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, - 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, - 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, - 0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x38,0x20,0x3d, - 0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30, - 0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78, - 0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x31,0x32,0x20,0x3d,0x20,0x74, - 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61, - 0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x38, - 0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31, - 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x38,0x20, - 0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20, - 0x5f,0x34,0x34,0x38,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34,0x38,0x29,0x20,0x2a,0x20, - 0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, - 0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x33,0x38,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66, - 0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62, - 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64, - 0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29, - 0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33, - 0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66, - 0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, - 0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76, - 0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, - 0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x38,0x20, - 0x2a,0x20,0x5f,0x35,0x31,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x35,0x31,0x32, - 0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41, - 0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45, - 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54, - 0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73, - 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, - 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, - 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66, - 0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x34, + 0x38,0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x5f,0x34,0x31,0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20, + 0x28,0x5f,0x34,0x32,0x35,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29, + 0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x32,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34, + 0x32,0x35,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e, + 0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x31,0x35,0x29, + 0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e, + 0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20, + 0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20, + 0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53, + 0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28, + 0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20, + 0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x28,0x5f,0x34,0x32,0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x39,0x2e,0x78,0x29,0x20, + 0x2b,0x20,0x5f,0x34,0x38,0x39,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f, + 0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, + 0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68, + 0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53, + 0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, + 0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61, + 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f, + 0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72, + 0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67, + 0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, + 0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x30,0x31,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x30,0x31,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x32,0x33, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x31,0x30,0x31,0x36,0x2c,0x20,0x5f,0x31,0x30,0x32,0x33,0x29,0x20,0x3c, + 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x34,0x5f,0x66,0x6c,0x61,0x67, + 0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x35,0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f, + 0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33,0x34,0x5f,0x76, + 0x69,0x65,0x77,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35, + 0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x38,0x33,0x34,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32, 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, - 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, - 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20, - 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, - 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, - 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, - 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, - 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69, - 0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x31,0x31, - 0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x20,0x3d,0x20,0x5f,0x31,0x34,0x31,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x31,0x38,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, - 0x7a,0x20,0x2d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x34,0x31, - 0x31,0x2c,0x20,0x5f,0x31,0x34,0x31,0x38,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x39,0x20, - 0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31, - 0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x76,0x69,0x65,0x77, - 0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39, - 0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35, - 0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20, - 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, - 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x28,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20, - 0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39, - 0x38,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x36,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20, - 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x36,0x37,0x2c,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x73, - 0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x34,0x38,0x37,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, - 0x31,0x34,0x36,0x37,0x2c,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x34, - 0x37,0x37,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x39,0x34,0x20,0x3d,0x20,0x5f,0x31,0x34, - 0x38,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x34,0x38,0x37,0x2e,0x77, - 0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x31,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x34,0x39,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f, - 0x31,0x34,0x39,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20, - 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20, - 0x5f,0x31,0x34,0x39,0x34,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3d,0x20,0x61, - 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x35,0x31,0x31,0x2e,0x78, - 0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, - 0x31,0x35,0x31,0x31,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, - 0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x35,0x31,0x31,0x2e,0x7a,0x20,0x3c,0x20,0x30, - 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x32,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, - 0x35,0x31,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32,0x33, - 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x35, - 0x31,0x31,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, - 0x78,0x2c,0x20,0x5f,0x31,0x35,0x31,0x31,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30, - 0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x35,0x31,0x31,0x2e,0x7a, - 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x35,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30, - 0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x32,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x32,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x35,0x20,0x3d,0x20,0x2d, + 0x6d,0x75,0x6c,0x28,0x5f,0x31,0x30,0x37,0x32,0x2c,0x20,0x5f,0x38,0x33,0x34,0x5f, + 0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, + 0x30,0x37,0x35,0x20,0x3c,0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x34,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x35,0x20,0x3c,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x39,0x39,0x20, + 0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x30,0x37,0x32,0x2c,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, + 0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31, + 0x30,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f, + 0x20,0x5f,0x31,0x30,0x39,0x39,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31, + 0x32,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x31, + 0x30,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x30,0x36,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x38,0x33,0x34,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x31,0x30, + 0x36,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x32,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62, + 0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x31,0x32,0x33,0x2e,0x78,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x31,0x32,0x33, + 0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c, + 0x20,0x5f,0x31,0x31,0x32,0x33,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e, + 0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x37,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31,0x31,0x32,0x33,0x2e,0x78, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f, + 0x31,0x31,0x32,0x33,0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x31,0x32,0x33,0x2e,0x7a,0x20,0x3e,0x20,0x31, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x33,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x31,0x32,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21, + 0x5f,0x31,0x31,0x33,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35, + 0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x38,0x33,0x34,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d, + 0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33,0x34, + 0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20, 0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x66,0x6c,0x61,0x67,0x73, - 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e, - 0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x37,0x35, - 0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35, - 0x38,0x33,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20, - 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20, - 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70, - 0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78, - 0x5f,0x61,0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31, - 0x35,0x37,0x35,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65, - 0x74,0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x35,0x38,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x38,0x34,0x2c,0x20,0x5f,0x31, - 0x35,0x38,0x34,0x2c,0x20,0x5f,0x31,0x35,0x38,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x5f,0x6d,0x61,0x74,0x65, - 0x72,0x69,0x61,0x6c,0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x5f,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e, - 0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x76,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x5f,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x7a, - 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65, - 0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x76,0x5f,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70, - 0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x29,0x2c,0x20,0x70,0x6f,0x77,0x28,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x2c,0x20,0x38,0x2e,0x30,0x66,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, - 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x76, - 0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x5f,0x31,0x36,0x38,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x34,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, - 0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20, - 0x3d,0x20,0x5f,0x31,0x36,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73, - 0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73, - 0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x3b,0x0a, + 0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x31,0x39,0x37,0x5f,0x64,0x75,0x6d,0x6d, + 0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x30,0x35,0x20,0x3d,0x20, + 0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76, + 0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54,0x65,0x78,0x74, + 0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x31,0x39,0x37,0x5f,0x64, + 0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x29,0x29, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x36,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30, + 0x35,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33, + 0x34,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x31,0x32,0x30,0x36,0x2c,0x20,0x5f,0x31,0x32,0x30,0x36,0x2c,0x20,0x5f, + 0x31,0x32,0x30,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61, + 0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x7a, + 0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x38,0x33,0x34,0x5f,0x67,0x72,0x69,0x64,0x5f, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x7a,0x20,0x2b,0x20,0x5f,0x38,0x33,0x34,0x5f,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x2e,0x7a,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, + 0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78, + 0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6c,0x65, + 0x72,0x70,0x28,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47, + 0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x70,0x6f,0x77,0x28,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x66, + 0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x38,0x2e,0x30,0x66,0x29,0x2e,0x78, + 0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, + 0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x2d,0x6d, + 0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x30,0x35,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x32,0x33,0x29,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x34,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20, - 0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x38,0x33, + 0x5f,0x37,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x6e, + 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x34,0x5f,0x73,0x75, + 0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74, - 0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x34,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x34,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x34,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f, - 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x34,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73, - 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x34,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68, - 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x34,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x5b, - 0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34, - 0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x5b,0x35, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b, - 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x5b,0x36,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x37, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x38,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a, + 0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x75,0x6e, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, + 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x31,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x32,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35, + 0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x37,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x35,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x5f,0x69,0x62,0x6c,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x36,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69, - 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x35,0x38,0x34,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49, - 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, - 0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, - 0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, - 0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, - 0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20, - 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, - 0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, - 0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, - 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, - 0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, - 0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, + 0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x31,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x30, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b, + 0x31,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x32,0x5d, + 0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x33,0x5d,0x20,0x3d, + 0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f, + 0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33, + 0x34,0x5f,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x31,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f, + 0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x31,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68, + 0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x31,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x73,0x68,0x5b,0x38, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x5f,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x32,0x30,0x36,0x29,0x29,0x20,0x2a,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, + 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, + 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, + 0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, + 0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c,0x5f, + 0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74, + 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, }; /* #include @@ -3897,10 +3140,7 @@ static const uint8_t geom_vs_source_metal_macos[1633] = { float4 grid_offset; float4x4 view; float4 cascade_far_view_z; - float4 cascade_texel_world; - float4 cascade_depth_bias; - float4 shadow_params; - float4x4 cascade_matrices[4]; + float4x4 cascade_matrices[3]; float4 sh[9]; float4 ibl_params; }; @@ -3918,236 +3158,117 @@ static const uint8_t geom_vs_source_metal_macos[1633] = { float4 v_material [[user(locn3), flat]]; }; - static inline __attribute__((always_inline)) - int selectShadowCascade(thread const float4& far_view_z, thread const float& view_z) - { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - static inline __attribute__((always_inline)) - float3 shadowCascadeTint(thread const int& cascade) - { - if (cascade == 0) - { - return float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return float3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - static inline __attribute__((always_inline)) float3 proceduralGrid(thread const float2& line_xz, thread const float2& axis_xz, thread const float3& base_color, thread const float& cell_size) { - float2 _559 = line_xz / float2(cell_size); - float2 _575 = abs(fract(_559 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_559), float2(9.9999999747524270787835121154785e-07)); - float2 _590 = line_xz / float2(cell_size * 10.0); - float2 _604 = abs(fract(_590 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_590), float2(9.9999999747524270787835121154785e-07)); - float2 _635 = fast::max(fwidth(axis_xz), float2(9.9999999747524270787835121154785e-07)); - return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, float3(1.0 - fast::clamp(fast::min(_575.x, _575.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, float3(1.0 - fast::clamp(fast::min(_604.x, _604.y), 0.0, 1.0))), float3(1.0, 0.0, 0.0), float3((1.0 - fast::clamp(abs(axis_xz.y) / _635.y, 0.0, 1.0)) * step(0.0, axis_xz.x))), float3(0.0, 0.0, 1.0), float3((1.0 - fast::clamp(abs(axis_xz.x) / _635.x, 0.0, 1.0)) * step(0.0, axis_xz.y))); + float2 _536 = line_xz / float2(cell_size); + float2 _552 = abs(fract(_536 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_536), float2(9.9999999747524270787835121154785e-07)); + float2 _567 = line_xz / float2(cell_size * 10.0); + float2 _581 = abs(fract(_567 - float2(0.5)) - float2(0.5)) / fast::max(fwidth(_567), float2(9.9999999747524270787835121154785e-07)); + float2 _612 = fast::max(fwidth(axis_xz), float2(9.9999999747524270787835121154785e-07)); + return mix(mix(mix(mix(base_color, base_color * 0.699999988079071044921875, float3(1.0 - fast::clamp(fast::min(_552.x, _552.y), 0.0, 1.0))), base_color * 0.3499999940395355224609375, float3(1.0 - fast::clamp(fast::min(_581.x, _581.y), 0.0, 1.0))), float3(1.0, 0.0, 0.0), float3((1.0 - fast::clamp(abs(axis_xz.y) / _612.y, 0.0, 1.0)) * step(0.0, axis_xz.x))), float3(0.0, 0.0, 1.0), float3((1.0 - fast::clamp(abs(axis_xz.x) / _612.x, 0.0, 1.0)) * step(0.0, axis_xz.y))); } static inline __attribute__((always_inline)) - float sampleShadowTap(depth2d_array tex, sampler smp, thread const float2& uv, thread const float& layer, thread const float& ref_z) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) { - float4 _732 = float4(uv, layer, ref_z); - return tex.sample_compare(smp, _732.xy, uint(rint(_732.z)), ref_z); + float _656 = float(cascade); + float _661 = light_uv.z - bias0; + float _677 = light_uv.x - 0.00048828125; + float _681 = light_uv.y - 0.00048828125; + float4 _684 = float4(_677, _681, _656, _661); + float4 _700 = float4(light_uv.x, _681, _656, _661); + float _711 = light_uv.x + 0.00048828125; + float4 _718 = float4(_711, _681, _656, _661); + float4 _734 = float4(_677, light_uv.y, _656, _661); + float4 _748 = float4(light_uv.xy, _656, _661); + float4 _764 = float4(_711, light_uv.y, _656, _661); + float _779 = light_uv.y + 0.00048828125; + float4 _782 = float4(_677, _779, _656, _661); + float4 _798 = float4(light_uv.x, _779, _656, _661); + float4 _816 = float4(_711, _779, _656, _661); + return ((((((((tex_shadow.sample_compare(smp_shadow, _684.xy, uint(rint(_684.z)), _661) + tex_shadow.sample_compare(smp_shadow, _700.xy, uint(rint(_700.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _718.xy, uint(rint(_718.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _734.xy, uint(rint(_734.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _748.xy, uint(rint(_748.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _764.xy, uint(rint(_764.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _782.xy, uint(rint(_782.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _798.xy, uint(rint(_798.z)), _661)) + tex_shadow.sample_compare(smp_shadow, _816.xy, uint(rint(_816.z)), _661)) * 0.111111111938953399658203125; } static inline __attribute__((always_inline)) - float sampleShadowPCF(depth2d_array tex, sampler smp, thread const int& cascade, thread const float3& light_uv, thread const float& bias0, thread const float& scale, thread const float& inv_size) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _834) { - float _742 = float(cascade); - float _747 = light_uv.z - bias0; - float2 _752 = light_uv.xy * (1.0 / inv_size); - float2 _757 = floor(_752 + float2(0.5)); - float _764 = (_752.x + 0.5) - _757.x; - float _771 = (_752.y + 0.5) - _757.y; - float2 _776 = (_757 - float2(0.5)) * inv_size; - float _780 = inv_size * scale; - float _783 = 5.0 * _764; - float _785 = _783 - 6.0; - float _789 = 11.0 * _764; - float _791 = _789 - 28.0; - float _797 = (-17.0) - _789; - float _802 = (-1.0) - _783; - float _806 = 4.0 * _764; - float _810 = ((_806 - 5.0) / _785) - 3.0; - float _818 = ((_806 - 16.0) / _791) - 1.0; - float _827 = (((-5.0) - (7.0 * _764)) / _797) + 1.0; - float _833 = ((-_764) / _802) + 3.0; - float _836 = 5.0 * _771; - float _837 = _836 - 6.0; - float _840 = 11.0 * _771; - float _841 = _840 - 28.0; - float _846 = (-17.0) - _840; - float _851 = (-1.0) - _836; - float _854 = 4.0 * _771; - float _858 = ((_854 - 5.0) / _837) - 3.0; - float _865 = ((_854 - 16.0) / _841) - 1.0; - float _873 = (((-5.0) - (7.0 * _771)) / _846) + 1.0; - float _879 = ((-_771) / _851) + 3.0; - float sum = 0.0; - float2 param = _776 + (float2(_810, _858) * _780); - float param_1 = _742; - float param_2 = _747; - sum += ((_785 * _837) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _776 + (float2(_818, _858) * _780); - float param_4 = _742; - float param_5 = _747; - sum += ((_791 * _837) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _776 + (float2(_827, _858) * _780); - float param_7 = _742; - float param_8 = _747; - sum += ((_797 * _837) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _776 + (float2(_833, _858) * _780); - float param_10 = _742; - float param_11 = _747; - sum += ((_802 * _837) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _776 + (float2(_810, _865) * _780); - float param_13 = _742; - float param_14 = _747; - sum += ((_785 * _841) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _776 + (float2(_818, _865) * _780); - float param_16 = _742; - float param_17 = _747; - sum += ((_791 * _841) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _776 + (float2(_827, _865) * _780); - float param_19 = _742; - float param_20 = _747; - sum += ((_797 * _841) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _776 + (float2(_833, _865) * _780); - float param_22 = _742; - float param_23 = _747; - sum += ((_802 * _841) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _776 + (float2(_810, _873) * _780); - float param_25 = _742; - float param_26 = _747; - sum += ((_785 * _846) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _776 + (float2(_818, _873) * _780); - float param_28 = _742; - float param_29 = _747; - sum += ((_791 * _846) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _776 + (float2(_827, _873) * _780); - float param_31 = _742; - float param_32 = _747; - sum += ((_797 * _846) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _776 + (float2(_833, _873) * _780); - float param_34 = _742; - float param_35 = _747; - sum += ((_802 * _846) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _776 + (float2(_810, _879) * _780); - float param_37 = _742; - float param_38 = _747; - sum += ((_785 * _851) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _776 + (float2(_818, _879) * _780); - float param_40 = _742; - float param_41 = _747; - sum += ((_791 * _851) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _776 + (float2(_827, _879) * _780); - float param_43 = _742; - float param_44 = _747; - sum += ((_797 * _851) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _776 + (float2(_833, _879) * _780); - float param_46 = _742; - float param_47 = _747; - float _1183 = sum; - float _1184 = _1183 + ((_802 * _851) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1184; - return _1184 * 0.000369822490029036998748779296875; - } - - static inline __attribute__((always_inline)) - float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, constant ub_pass& _1198, depth2d_array tex_shadow, sampler smp_shadow) - { - float _1213 = fast::clamp(_1198.cascade_texel_world.x / _1198.cascade_texel_world[cascade], 0.25, 1.0); - float _1222 = fast::max(dot(world_normal, fast::normalize(_1198.sun_dir_world.xyz)), 0.0); - float _1232 = 3.0 * _1213; - float4 _1255 = _1198.cascade_matrices[cascade] * float4(world_pos + (world_normal * ((((_1232 + 0.5) * 1.41420996189117431640625) * sqrt(fast::max(1.0 - (_1222 * _1222), 0.0))) * _1198.cascade_texel_world[cascade])), 1.0); - float3 _1263 = _1255.xyz / float3(_1255.w); - float _1280 = _1263.z; - float3 _1281 = float3((_1263.x * 0.5) + 0.5, ((_1263.y * _1198.shadow_params.x) * 0.5) + 0.5, _1280); - bool _1284 = _1280 < 0.0; - bool _1291; - if (!_1284) + float4 _844 = _834.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _851 = _844.xyz / float3(_844.w); + float3 _869 = float3((_851.x * 0.5) + 0.5, ((_851.y * _834.cascade_far_view_z.w) * 0.5) + 0.5, _851.z); + bool _873 = any(_869 < float3(0.0)); + bool _880; + if (!_873) { - _1291 = _1280 > 1.0; + _880 = any(_869 > float3(1.0)); } else { - _1291 = _1284; + _880 = _873; } - if (_1291) - { - return 1.0; - } - float _1301 = (_1232 + 1.0) * _1198.shadow_params.y; - float2 _1303 = _1281.xy; - bool _1309 = any(_1303 < float2(-_1301)); - bool _1320; - if (!_1309) - { - _1320 = any(_1303 > float2(1.0 + _1301)); - } - else - { - _1320 = _1309; - } - if (_1320) + if (_880) { return 1.0; } int param = cascade; - float3 param_1 = _1281; - float param_2 = _1198.cascade_depth_bias[cascade]; - float param_3 = _1213; - float param_4 = _1198.shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _869; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_834.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _912 = _869.xy; + float2 _917 = fast::min(_912, float2(1.0) - _912); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_917.x, _917.y) * 10.0, 0.0, 1.0)); + } + return pcf; } static inline __attribute__((always_inline)) - float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, constant ub_pass& _1198, depth2d_array tex_shadow, sampler smp_shadow) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _834) { - float4 param = _1198.cascade_far_view_z; - float param_1 = view_z; - int _1346 = selectShadowCascade(param, param_1); - int param_2 = _1346; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4, _1198, tex_shadow, smp_shadow); - if (_1346 < 3) + int cascade = 2; + if (view_z < _834.cascade_far_view_z.x) { - float _1366; - if (_1346 == 0) + cascade = 0; + } + else + { + if (view_z < _834.cascade_far_view_z.y) { - _1366 = 0.0; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _834); + if (cascade < 2) + { + float _961; + if (cascade == 0) + { + _961 = _834.cascade_far_view_z.x; } else { - _1366 = _1198.cascade_far_view_z[_1346 - 1]; + _961 = _834.cascade_far_view_z.y; } - float _1379 = mix(_1198.cascade_far_view_z[_1346], _1366, 0.100000001490116119384765625); - if (view_z > _1379) + float _973; + if (cascade == 0) { - int param_5 = _1346 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7, _1198, tex_shadow, smp_shadow), (view_z - _1379) / (_1198.cascade_far_view_z[_1346] - _1379)); + _973 = 0.0; + } + else + { + _973 = _834.cascade_far_view_z.x; + } + float _984 = mix(_961, _973, 0.100000001490116119384765625); + if (view_z > _984) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _834), (view_z - _984) / (_961 - _984)); } } return shadow; @@ -4156,61 +3277,61 @@ static const uint8_t geom_vs_source_metal_macos[1633] = { static inline __attribute__((always_inline)) float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) { - float _140 = alpha * alpha; - float _149 = ((n_dot_h * n_dot_h) * (_140 - 1.0)) + 1.0; - return _140 / ((3.1415927410125732421875 * _149) * _149); + float _116 = alpha * alpha; + float _125 = ((n_dot_h * n_dot_h) * (_116 - 1.0)) + 1.0; + return _116 / ((3.1415927410125732421875 * _125) * _125); } static inline __attribute__((always_inline)) float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) { - float _162 = alpha * alpha; - float _169 = 1.0 - _162; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _169) + _162)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _169) + _162))) + 9.9999997473787516355514526367188e-06); + float _138 = alpha * alpha; + float _145 = 1.0 - _138; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _145) + _138)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _145) + _138))) + 9.9999997473787516355514526367188e-06); } static inline __attribute__((always_inline)) float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) { - float _198 = 1.0 - v_dot_h; - float _202 = _198 * _198; - return f0 + ((float3(1.0) - f0) * ((_202 * _202) * _198)); + float _174 = 1.0 - v_dot_h; + float _178 = _174 * _174; + return f0 + ((float3(1.0) - f0) * ((_178 * _178) * _174)); } static inline __attribute__((always_inline)) float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) { - float _221 = fast::max(dot(N, L), 0.0); - float3 _232 = fast::normalize(V + L); - float _246 = fast::max(roughness, 0.04500000178813934326171875); - float _250 = _246 * _246; - float param = fast::max(dot(N, _232), 0.0); - float param_1 = _250; + float _197 = fast::max(dot(N, L), 0.0); + float3 _208 = fast::normalize(V + L); + float _222 = fast::max(roughness, 0.04500000178813934326171875); + float _226 = _222 * _222; + float param = fast::max(dot(N, _208), 0.0); + float param_1 = _226; float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _221; - float param_4 = _250; - float param_5 = fast::max(dot(V, _232), 0.0); + float param_3 = _197; + float param_4 = _226; + float param_5 = fast::max(dot(V, _208), 0.0); float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); - float3 _277 = pbrFresnelSchlick(param_5, param_6); - return ((((((float3(1.0) - _277) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_277 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _221; + float3 _253 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _253) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_253 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _197; } static inline __attribute__((always_inline)) float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) { - float3 _431 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _431; + float3 _408 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _408; } static inline __attribute__((always_inline)) float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) { - float _438 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - float3 _448 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float _415 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _425 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); float3 param = N_world; spvUnsafeArray param_1 = sh; - float4 _512 = tex_brdf_lut.sample(smp_brdf_lut, float2(_438, roughness)); - return (((((float3(1.0) - (_448 + ((fast::max(float3(1.0 - roughness), _448) - _448) * powr(fast::max(0.0, 1.0 - _438), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_448 * _512.x) + float3(_512.y))); + float4 _489 = tex_brdf_lut.sample(smp_brdf_lut, float2(_415, roughness)); + return (((((float3(1.0) - (_425 + ((fast::max(float3(1.0 - roughness), _425) - _425) * powr(fast::max(0.0, 1.0 - _415), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_425 * _489.x) + float3(_489.y))); } static inline __attribute__((always_inline)) @@ -4231,106 +3352,129 @@ static const uint8_t geom_vs_source_metal_macos[1633] = { return result; } - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _1198 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _834 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) { main0_out out = {}; - float3 _1411 = fast::normalize(in.v_world_normal); - float3 n_world = _1411; - float3 _1418 = _1198.camera_pos.xyz - in.v_view_pos; - if (dot(_1411, _1418) < 0.0) + float3 _1016 = fast::normalize(in.v_world_normal); + float3 n_world = _1016; + float3 _1023 = _834.camera_pos.xyz - in.v_view_pos; + if (dot(_1016, _1023) < 0.0) { n_world = -n_world; } - if (_1198.flags.x == 1) + if (_834.flags.x == 1) { - float _1449 = fast::clamp((_1198.view * float4(in.v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out.out_color = float4(_1449, _1449, _1449, 1.0); + float _1054 = fast::clamp((_834.view * float4(in.v_view_pos, 1.0)).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1054, _1054, _1054, 1.0); return out; } - if (_1198.flags.x == 2) + if (_834.flags.x == 2) { - float4 _1467 = float4(in.v_view_pos, 1.0); - float4 param = _1198.cascade_far_view_z; - float param_1 = -(_1198.view * _1467).z; - int _1477 = selectShadowCascade(param, param_1); - float4 _1487 = _1198.cascade_matrices[_1477] * _1467; - float3 _1494 = _1487.xyz / float3(_1487.w); - float3 _1511 = float3((_1494.x * 0.5) + 0.5, ((_1494.y * _1198.shadow_params.x) * 0.5) + 0.5, _1494.z); - bool _1516 = any(_1511 < float3(0.0)); - bool _1523; - if (!_1516) + float4 _1072 = float4(in.v_view_pos, 1.0); + float _1075 = -(_834.view * _1072).z; + int cascade = 2; + if (_1075 < _834.cascade_far_view_z.x) { - _1523 = any(_1511 > float3(1.0)); + cascade = 0; } else { - _1523 = _1516; + if (_1075 < _834.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1099 = _834.cascade_matrices[cascade] * _1072; + float3 _1106 = _1099.xyz / float3(_1099.w); + float3 _1123 = float3((_1106.x * 0.5) + 0.5, ((_1106.y * _834.cascade_far_view_z.w) * 0.5) + 0.5, _1106.z); + bool _1127 = any(_1123 < float3(0.0)); + bool _1134; + if (!_1127) + { + _1134 = any(_1123 > float3(1.0)); + } + else + { + _1134 = _1127; } float3 tint = float3(1.0); - if (!_1523) + if (!_1134) { - int param_2 = _1477; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out.out_color = float4(tint, 1.0); return out; } - if (_1198.flags.x == 3) + if (_834.flags.x == 3) { - out.out_color = float4((fast::normalize((_1198.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + out.out_color = float4((fast::normalize((_834.view * float4(n_world, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); return out; } - float4 _1583 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); - float _1584 = _1583.x; - if (_1198.flags.x == 4) + float4 _1205 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1206 = _1205.x; + if (_834.flags.x == 4) { - out.out_color = float4(_1584, _1584, _1584, 1.0); + out.out_color = float4(_1206, _1206, _1206, 1.0); return out; } float3 baseColor = in.v_base_color.xyz; if (in.v_material.z > 0.5) { - float2 param_3 = in.v_view_pos.xz + _1198.grid_offset.xy; - float2 param_4 = in.v_view_pos.xz + _1198.grid_offset.zw; - float3 param_5 = in.v_base_color.xyz; - float param_6 = in.v_material.w; - baseColor = mix(in.v_base_color.xyz, proceduralGrid(param_3, param_4, param_5, param_6), float3(powr(fast::clamp(n_world.y, 0.0, 1.0), 8.0))); + float2 param = in.v_view_pos.xz + _834.grid_offset.xy; + float2 param_1 = in.v_view_pos.xz + _834.grid_offset.zw; + float3 param_2 = in.v_base_color.xyz; + float param_3 = in.v_material.w; + baseColor = mix(in.v_base_color.xyz, proceduralGrid(param, param_1, param_2, param_3), float3(powr(fast::clamp(n_world.y, 0.0, 1.0), 8.0))); } - float3 param_7 = in.v_view_pos; - float3 param_8 = n_world; - float param_9 = -(_1198.view * float4(in.v_view_pos, 1.0)).z; - float3 _1683 = fast::normalize(_1418); - float3 param_10 = n_world; - float3 param_11 = _1683; - float3 param_12 = fast::normalize(_1198.sun_dir_world.xyz); - float3 param_13 = _1198.sun_color.xyz * sampleShadowCascaded(param_7, param_8, param_9, _1198, tex_shadow, smp_shadow); - float3 param_14 = baseColor; - float param_15 = in.v_material.x; - float param_16 = in.v_material.y; - bool param_17 = _1198.ibl_params.y > 0.5; - float3 param_18 = n_world; - float3 param_19 = _1683; - float3 param_20 = baseColor; - float param_21 = in.v_material.x; - float param_22 = in.v_material.y; - float param_23 = _1198.sun_color.w; - spvUnsafeArray param_24; - param_24[0] = _1198.sh[0]; - param_24[1] = _1198.sh[1]; - param_24[2] = _1198.sh[2]; - param_24[3] = _1198.sh[3]; - param_24[4] = _1198.sh[4]; - param_24[5] = _1198.sh[5]; - param_24[6] = _1198.sh[6]; - param_24[7] = _1198.sh[7]; - param_24[8] = _1198.sh[8]; - float param_25 = _1198.ibl_params.x; - out.out_color = float4((brdf_evaluate(param_10, param_11, param_12, param_13, param_14, param_15, param_16) + (pbrEvaluateAmbient(param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_25) * _1584)) * in.v_base_color.w, in.v_base_color.w); + float3 param_4 = in.v_view_pos; + float3 param_5 = n_world; + float param_6 = -(_834.view * float4(in.v_view_pos, 1.0)).z; + float3 _1305 = fast::normalize(_1023); + float3 param_7 = n_world; + float3 param_8 = _1305; + float3 param_9 = fast::normalize(_834.sun_dir_world.xyz); + float3 param_10 = _834.sun_color.xyz * sampleShadowCascaded(param_4, param_5, param_6, tex_shadow, smp_shadow, _834); + float3 param_11 = baseColor; + float param_12 = in.v_material.x; + float param_13 = in.v_material.y; + bool param_14 = _834.ibl_params.y > 0.5; + float3 param_15 = n_world; + float3 param_16 = _1305; + float3 param_17 = baseColor; + float param_18 = in.v_material.x; + float param_19 = in.v_material.y; + float param_20 = _834.sun_color.w; + spvUnsafeArray param_21; + param_21[0] = _834.sh[0]; + param_21[1] = _834.sh[1]; + param_21[2] = _834.sh[2]; + param_21[3] = _834.sh[3]; + param_21[4] = _834.sh[4]; + param_21[5] = _834.sh[5]; + param_21[6] = _834.sh[6]; + param_21[7] = _834.sh[7]; + param_21[8] = _834.sh[8]; + float param_22 = _834.ibl_params.x; + out.out_color = float4((brdf_evaluate(param_7, param_8, param_9, param_10, param_11, param_12, param_13) + (pbrEvaluateAmbient(param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_22) * _1206)) * in.v_base_color.w, in.v_base_color.w); return out; } */ -static const uint8_t geom_fs_source_metal_macos[20644] = { +static const uint8_t geom_fs_source_metal_macos[16696] = { 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, @@ -4406,1097 +3550,852 @@ static const uint8_t geom_fs_source_metal_macos[20644] = { 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61, 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, - 0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, - 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, - 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a, - 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, - 0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, - 0x6d,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31, - 0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75, - 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, - 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, - 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, - 0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b, - 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, - 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, - 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, - 0x29,0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26,0x20,0x66, - 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30, - 0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, - 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, - 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, - 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, - 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, - 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, - 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, - 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, - 0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, - 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31, - 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, - 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30, - 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, - 0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, - 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, - 0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39, - 0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35, - 0x2c,0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30, - 0x39,0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, - 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, - 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c, - 0x47,0x72,0x69,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78, - 0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2c, - 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35, - 0x35,0x39,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x37, - 0x35,0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35, - 0x35,0x39,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29, - 0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, - 0x20,0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69, - 0x64,0x74,0x68,0x28,0x5f,0x35,0x35,0x39,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32, - 0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34, - 0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x39,0x30,0x20,0x3d,0x20,0x6c,0x69,0x6e, - 0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x63,0x65, - 0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x30,0x34, - 0x20,0x3d,0x20,0x61,0x62,0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x39, - 0x30,0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, - 0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20, - 0x2f,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64, - 0x74,0x68,0x28,0x5f,0x35,0x39,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34, - 0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37, - 0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, - 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x61,0x78,0x69, - 0x73,0x5f,0x78,0x7a,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e, - 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30, - 0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65, - 0x2d,0x30,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69, - 0x78,0x28,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x36,0x39,0x39, - 0x39,0x39,0x39,0x39,0x38,0x38,0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39, - 0x32,0x31,0x38,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x35,0x37,0x35,0x2e,0x78, - 0x2c,0x20,0x5f,0x35,0x37,0x35,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, - 0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34, - 0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x36,0x30,0x34,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x30, - 0x34,0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, - 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, - 0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c, - 0x61,0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e, - 0x79,0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30, - 0x2e,0x30,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, - 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, - 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61, - 0x6d,0x70,0x28,0x61,0x62,0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78, - 0x29,0x20,0x2f,0x20,0x5f,0x36,0x33,0x35,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e, - 0x30,0x2c,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x29,0x29,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61, - 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68, - 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x26,0x20,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6c,0x61,0x79,0x65,0x72, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x33,0x32,0x20,0x3d, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65, - 0x72,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x2c,0x20,0x5f,0x37, - 0x33,0x32,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, - 0x28,0x5f,0x37,0x33,0x32,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, - 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, - 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, - 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64, - 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74, - 0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69, - 0x61,0x73,0x30,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x26,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x37,0x20, - 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62, - 0x69,0x61,0x73,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, - 0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76, - 0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x5f,0x37,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28, - 0x5f,0x37,0x35,0x32,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e, - 0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x36,0x34,0x20,0x3d,0x20,0x28,0x5f,0x37,0x35,0x32,0x2e,0x78,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x37,0x35,0x37,0x2e,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x37,0x31,0x20,0x3d,0x20, - 0x28,0x5f,0x37,0x35,0x32,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d, - 0x20,0x5f,0x37,0x35,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x5f,0x37,0x37,0x36,0x20,0x3d,0x20,0x28,0x5f,0x37,0x35,0x37, - 0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20, - 0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x30,0x20,0x3d,0x20,0x69,0x6e,0x76, - 0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x33,0x20,0x3d,0x20, - 0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x38, - 0x33,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x38,0x39,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x37,0x36,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x39,0x31,0x20,0x3d,0x20,0x5f,0x37,0x38,0x39,0x20,0x2d,0x20,0x32, - 0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x39,0x37,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x38,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x30,0x32,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x30,0x36,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x36, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31, - 0x30,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d,0x20,0x35,0x2e,0x30, - 0x29,0x20,0x2f,0x20,0x5f,0x37,0x38,0x35,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x31,0x38,0x20, - 0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x36,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x39,0x31,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x32,0x37,0x20,0x3d, - 0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x37,0x36,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x39,0x37, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x38,0x33,0x33,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x37,0x36, - 0x34,0x29,0x20,0x2f,0x20,0x5f,0x38,0x30,0x32,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x36, - 0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x37,0x20,0x3d,0x20, - 0x5f,0x38,0x33,0x36,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x30,0x20,0x3d,0x20,0x31,0x31,0x2e, - 0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x31,0x20,0x3d,0x20,0x5f,0x38,0x34,0x30,0x20, - 0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x38,0x34,0x36,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29, - 0x20,0x2d,0x20,0x5f,0x38,0x34,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x38,0x35,0x31,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29, - 0x20,0x2d,0x20,0x5f,0x38,0x33,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x38,0x35,0x34,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20, - 0x5f,0x37,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35,0x34,0x20,0x2d,0x20, - 0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2d,0x20,0x33, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, - 0x36,0x35,0x20,0x3d,0x20,0x28,0x28,0x5f,0x38,0x35,0x34,0x20,0x2d,0x20,0x31,0x36, - 0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x37, - 0x33,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28, - 0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x37,0x37,0x31,0x29,0x29,0x20,0x2f,0x20,0x5f, - 0x38,0x34,0x36,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x37,0x39,0x20,0x3d,0x20,0x28,0x28,0x2d, - 0x5f,0x37,0x37,0x31,0x29,0x20,0x2f,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2b,0x20, - 0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73, - 0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x37,0x37, - 0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x30, - 0x2c,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20, - 0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20, - 0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, - 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20, - 0x5f,0x38,0x35,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x30,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38,0x33,0x37,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20, - 0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x34,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38, - 0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29, - 0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39, - 0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36, - 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c, - 0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x39,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38,0x34,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x36,0x35,0x29,0x20,0x2a,0x20,0x5f, - 0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20, - 0x5f,0x38,0x34,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37, - 0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d, - 0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x37, - 0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31, - 0x38,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20, - 0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x31,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x30,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c,0x20,0x5f,0x38,0x37,0x33,0x29,0x20,0x2a, - 0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20, - 0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73, - 0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f, - 0x38,0x37,0x33,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34, - 0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37, - 0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28, - 0x28,0x5f,0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38,0x34,0x36,0x29,0x20,0x2a,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28, - 0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20, - 0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x38,0x31,0x30,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x38,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x38,0x35,0x20,0x2a,0x20,0x5f,0x38, - 0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x39,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x31,0x38,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29, - 0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f, - 0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x37,0x39, - 0x31,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x37,0x37,0x36, - 0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x38,0x32,0x37,0x2c, - 0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f,0x37,0x38,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20, - 0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x37,0x39,0x37,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20, - 0x3d,0x20,0x5f,0x37,0x37,0x36,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x38,0x33,0x33,0x2c,0x20,0x5f,0x38,0x37,0x39,0x29,0x20,0x2a,0x20,0x5f, - 0x37,0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x38,0x33,0x20,0x3d,0x20,0x73,0x75, - 0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31, - 0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x33,0x20,0x2b,0x20,0x28,0x28,0x5f, - 0x38,0x30,0x32,0x20,0x2a,0x20,0x5f,0x38,0x35,0x31,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x38,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x5f,0x31,0x31,0x38,0x34,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30, - 0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36, - 0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73, - 0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, - 0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x31,0x39,0x38,0x2c,0x20,0x64,0x65,0x70,0x74, - 0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x31,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70, - 0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74, - 0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78, - 0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x32,0x20,0x3d, - 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x32,0x20,0x3d,0x20, - 0x33,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x31,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x35,0x35,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20, - 0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x20,0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x20,0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x32,0x33,0x32,0x20,0x2b, - 0x20,0x30,0x2e,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39, - 0x39,0x36,0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32, - 0x35,0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x32,0x32,0x32, - 0x20,0x2a,0x20,0x5f,0x31,0x32,0x32,0x32,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29, - 0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x36,0x33, - 0x20,0x3d,0x20,0x5f,0x31,0x32,0x35,0x35,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x32,0x35,0x35,0x2e,0x77,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x30,0x20, - 0x3d,0x20,0x5f,0x31,0x32,0x36,0x33,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x38,0x31,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x32,0x36,0x33,0x2e,0x78,0x20,0x2a,0x20, - 0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31, - 0x32,0x36,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a, - 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x32, - 0x38,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31, - 0x32,0x38,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3c,0x20,0x30,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x39, - 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x38, - 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x5f,0x31,0x32,0x39,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x30,0x20,0x3e, - 0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x32,0x39,0x31,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x32,0x39,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x30,0x31,0x20,0x3d,0x20,0x28,0x5f,0x31,0x32,0x33,0x32,0x20, - 0x2b,0x20,0x31,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x33,0x30,0x33, - 0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x31,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x30,0x39,0x20,0x3d,0x20,0x61,0x6e, - 0x79,0x28,0x5f,0x31,0x33,0x30,0x33,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x2d,0x5f,0x31,0x33,0x30,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x33,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x21,0x5f,0x31,0x33,0x30,0x39,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x32,0x30,0x20,0x3d, - 0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x33,0x30,0x33,0x20,0x3e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x5f,0x31,0x33,0x30,0x31,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x33,0x32,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x39,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33, - 0x32,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x5f,0x31,0x32,0x38,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x31, - 0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68, - 0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46, - 0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70, - 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, - 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, - 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, - 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f, - 0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78, - 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x5f,0x31,0x33,0x34,0x36,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x2c,0x20,0x5f,0x31,0x31,0x39,0x38,0x2c,0x20,0x74,0x65,0x78,0x5f, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33, - 0x34,0x36,0x20,0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x33,0x34,0x36,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x36,0x36, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34, - 0x36,0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x33,0x37,0x39,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x31,0x39, - 0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36,0x5d,0x2c,0x20,0x5f,0x31,0x33, - 0x36,0x36,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, - 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, - 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x20,0x3d,0x20,0x5f,0x31,0x33,0x34,0x36,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x5f,0x31,0x31,0x39, - 0x38,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, - 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x2c,0x20,0x28,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x20,0x2f,0x20,0x28, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x33,0x34,0x36,0x5d,0x20, - 0x2d,0x20,0x5f,0x31,0x33,0x37,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74, - 0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x30,0x20, - 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x39,0x20, - 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x34,0x30,0x20,0x2d, - 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x34,0x30,0x20,0x2f,0x20, - 0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32, - 0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34, - 0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, - 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, - 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, - 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53, - 0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65, + 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20, + 0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, + 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, + 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x74,0x32,0x26,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, + 0x26,0x20,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70, - 0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x36, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e, - 0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a, - 0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20, - 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36, - 0x39,0x29,0x20,0x2b,0x20,0x5f,0x31,0x36,0x32,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2b,0x20,0x5f,0x31,0x36, - 0x32,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35, - 0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d, + 0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x33,0x36,0x20,0x3d,0x20,0x6c, + 0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x35,0x32,0x20,0x3d,0x20,0x61,0x62, + 0x73,0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x33,0x36,0x20,0x2d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35, + 0x33,0x36,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38, + 0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30, + 0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x5f,0x35,0x36,0x37,0x20,0x3d,0x20,0x6c,0x69,0x6e,0x65,0x5f,0x78,0x7a,0x20,0x2f, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x63,0x65,0x6c,0x6c,0x5f,0x73,0x69,0x7a, + 0x65,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x35,0x38,0x31,0x20,0x3d,0x20,0x61,0x62,0x73, + 0x28,0x66,0x72,0x61,0x63,0x74,0x28,0x5f,0x35,0x36,0x37,0x20,0x2d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2f,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x35,0x36, + 0x37,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37, + 0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f, + 0x36,0x31,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, + 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x29,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35, + 0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6d,0x69,0x78,0x28, + 0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x6d,0x69,0x78,0x28,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x2a,0x20,0x30,0x2e,0x36,0x39,0x39,0x39,0x39,0x39,0x39,0x38,0x38, + 0x30,0x37,0x39,0x30,0x37,0x31,0x30,0x34,0x34,0x39,0x32,0x31,0x38,0x37,0x35,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x69,0x6e,0x28,0x5f,0x35,0x35,0x32,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x32, + 0x2e,0x79,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29, + 0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35, + 0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63, + 0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f, + 0x35,0x38,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x38,0x31,0x2e,0x79,0x29,0x2c,0x20, + 0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e, + 0x30,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62, + 0x73,0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x20,0x2f,0x20,0x5f, + 0x36,0x31,0x32,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x29,0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x61,0x78, + 0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x29,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x61,0x62,0x73, + 0x28,0x61,0x78,0x69,0x73,0x5f,0x78,0x7a,0x2e,0x78,0x29,0x20,0x2f,0x20,0x5f,0x36, + 0x31,0x32,0x2e,0x78,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, + 0x20,0x2a,0x20,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x61,0x78,0x69, + 0x73,0x5f,0x78,0x7a,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, + 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, + 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, + 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46, + 0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e, + 0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62, + 0x69,0x61,0x73,0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x31,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73, + 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, + 0x37,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x31,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x34,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x36,0x37,0x37,0x2c,0x20,0x5f,0x36,0x38,0x31, + 0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x36,0x38,0x31,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20, + 0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x37,0x31,0x31,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31, + 0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x37,0x31,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31, + 0x31,0x2c,0x20,0x5f,0x36,0x38,0x31,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x33,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x36,0x37,0x37,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c, + 0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x34,0x38,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x78,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x36,0x34, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x36,0x35,0x36, + 0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x37,0x37,0x39,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x75,0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32, + 0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x38,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x36,0x37,0x37,0x2c,0x20,0x5f,0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c, + 0x20,0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x37,0x39,0x38,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x37, + 0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x31,0x36,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x31,0x31,0x2c,0x20,0x5f, + 0x37,0x37,0x39,0x2c,0x20,0x5f,0x36,0x35,0x36,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, + 0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38,0x34,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x38,0x34,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x30,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x30,0x30,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x31,0x38,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x31,0x38,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37, + 0x33,0x34,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x37,0x33,0x34,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x34,0x38,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x34, + 0x38,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x36,0x34,0x2e,0x78,0x79,0x2c,0x20,0x75, + 0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x36,0x34,0x2e,0x7a,0x29, + 0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, + 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x5f,0x37,0x38,0x32,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28, + 0x72,0x69,0x6e,0x74,0x28,0x5f,0x37,0x38,0x32,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f, + 0x36,0x36,0x31,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72, + 0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37, + 0x39,0x38,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74, + 0x28,0x5f,0x37,0x39,0x38,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x31,0x36,0x2e,0x78, + 0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x38,0x31, + 0x36,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x36,0x36,0x31,0x29,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35, + 0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d, 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c, - 0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f, - 0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x38,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x30,0x32,0x20,0x3d, - 0x20,0x5f,0x31,0x39,0x38,0x20,0x2a,0x20,0x5f,0x31,0x39,0x38,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30, - 0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x32,0x30,0x32,0x20,0x2a,0x20,0x5f,0x32,0x30, - 0x32,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x38,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61, + 0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, + 0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x38,0x33,0x34,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x34,0x34,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d, + 0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d, + 0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x35,0x31,0x20,0x3d,0x20,0x5f,0x38,0x34, + 0x34,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, + 0x38,0x34,0x34,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x38,0x36,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x28,0x5f,0x38,0x35,0x31,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x38,0x35,0x31,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x38,0x35,0x31,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x37, + 0x33,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x38,0x36,0x39,0x20,0x3c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x38,0x38,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x38,0x37,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x38,0x30,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x5f,0x38,0x36,0x39,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x38,0x30,0x20,0x3d,0x20,0x5f,0x38,0x37, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x38,0x38,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x38,0x36,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38, + 0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37, + 0x31,0x38,0x37,0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34, + 0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x38,0x33,0x34,0x2e,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, + 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x32,0x20,0x3d,0x20,0x5f,0x38,0x36, + 0x39,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x5f,0x39,0x31,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x69,0x6e,0x28,0x5f,0x39,0x31,0x32,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d, + 0x69,0x78,0x28,0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x69,0x6e,0x28,0x5f,0x39,0x31,0x37,0x2e,0x78,0x2c,0x20,0x5f,0x39,0x31,0x37,0x2e, + 0x79,0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a, 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f, 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77, 0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74, - 0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56, + 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x38, + 0x33,0x34,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, + 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x33,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c, + 0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x36,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x36,0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x36, + 0x31,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x37,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37, + 0x33,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x37,0x33,0x20,0x3d,0x20,0x5f,0x38,0x33, + 0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x38,0x34,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x39,0x36,0x31,0x2c, + 0x20,0x5f,0x39,0x37,0x33,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36, + 0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x39,0x38,0x34, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73, + 0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x33,0x34,0x29,0x2c,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x20,0x2f, + 0x20,0x28,0x5f,0x39,0x36,0x31,0x20,0x2d,0x20,0x5f,0x39,0x38,0x34,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73, + 0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c, + 0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x36,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x32,0x35,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28, + 0x5f,0x31,0x31,0x36,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31, + 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f, + 0x31,0x31,0x36,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32, + 0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35, + 0x20,0x2a,0x20,0x5f,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x35,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76, 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73, - 0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x38,0x20,0x3d,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x5f,0x31,0x33,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x34,0x35,0x29,0x20,0x2b,0x20,0x5f,0x31,0x33,0x38,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73, + 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x35,0x29, + 0x20,0x2b,0x20,0x5f,0x31,0x33,0x38,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39, + 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, + 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, + 0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74, + 0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46, + 0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68, 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65, - 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x31,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c, - 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x32,0x33,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34, - 0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30, - 0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31, - 0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x32,0x35,0x30,0x20,0x3d,0x20,0x5f,0x32,0x34,0x36,0x20,0x2a,0x20, - 0x5f,0x32,0x34,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x35,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, - 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f, - 0x32,0x35,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, - 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x33,0x32,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, - 0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x32,0x37,0x37,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, - 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x37, - 0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c, - 0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33, - 0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33, - 0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32, - 0x37,0x37,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62, - 0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69, - 0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72, - 0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69, - 0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x32,0x31,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, - 0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34, - 0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b, - 0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39, - 0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33, - 0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, - 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, - 0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38, - 0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35, - 0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, - 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, - 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, - 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20, - 0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e, - 0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31, - 0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33, - 0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29, - 0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e, - 0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36, - 0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37, - 0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30, - 0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e, - 0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, - 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, - 0x5f,0x34,0x33,0x31,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75, - 0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c, - 0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65, - 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26, - 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74, - 0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61, - 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68, - 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, + 0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x34,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64, + 0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x37,0x38,0x20,0x3d,0x20,0x5f,0x31,0x37,0x34,0x20,0x2a,0x20,0x5f,0x31, + 0x37,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66, + 0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x37,0x38, + 0x20,0x2a,0x20,0x5f,0x31,0x37,0x38,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37,0x34,0x29, + 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, + 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, + 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20, 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x38,0x20,0x3d,0x20, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28, - 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, - 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, - 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x38,0x20, + 0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39, + 0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f, + 0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x30,0x38,0x20,0x3d, + 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, + 0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x32,0x32,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30, + 0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39, + 0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x32,0x36,0x20,0x3d,0x20,0x5f, + 0x32,0x32,0x32,0x20,0x2a,0x20,0x5f,0x32,0x32,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f, + 0x32,0x30,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x32,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39, + 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, + 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, + 0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x39,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x32,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20, + 0x5f,0x32,0x30,0x38,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, 0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30, 0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32, 0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73, 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55, - 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, - 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, - 0x35,0x31,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f, - 0x34,0x33,0x38,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28, - 0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x34,0x34,0x38,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34, - 0x38,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34,0x38,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77, - 0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x33,0x38,0x29,0x2c,0x20,0x35,0x2e, - 0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53, - 0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61, - 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33, - 0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70, - 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74, - 0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x38,0x20,0x2a,0x20, - 0x5f,0x35,0x31,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x5f,0x35,0x31,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x35,0x33,0x20,0x3d,0x20,0x70,0x62, + 0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28, + 0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20, + 0x2d,0x20,0x5f,0x32,0x35,0x33,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d, + 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34, + 0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x5f,0x32,0x35,0x33,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44, + 0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a, + 0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d, + 0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x39,0x37,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e, + 0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e, + 0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66, + 0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39, + 0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x34,0x30,0x38,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30, + 0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33, + 0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e, + 0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33, + 0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35, + 0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35, + 0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39, + 0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35, + 0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33, + 0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20, + 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35, + 0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38, + 0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e, + 0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20, + 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x30,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d, - 0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62, - 0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, - 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, + 0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74, + 0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73, - 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65, - 0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, - 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65, - 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74, - 0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, + 0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, + 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, 0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20, - 0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74, - 0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, - 0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, - 0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c, - 0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d, - 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d, - 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, - 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, - 0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20, - 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, - 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, - 0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, - 0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d, - 0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61, - 0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e, - 0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, - 0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x31,0x31,0x20,0x3d, - 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f,0x31,0x34,0x31,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x31, - 0x38,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61, - 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x34,0x31,0x31,0x2c,0x20,0x5f,0x31,0x34, - 0x31,0x38,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x34,0x34,0x39,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69, - 0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29, - 0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37, - 0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, - 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x28,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x5f,0x31,0x34,0x34,0x39,0x2c,0x20, - 0x5f,0x31,0x34,0x34,0x39,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b, + 0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63, + 0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x34,0x31,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d, + 0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, + 0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31, + 0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x34,0x32,0x35,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30, + 0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35, + 0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x34,0x38,0x39,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x31,0x35,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x32,0x35,0x20,0x2b,0x20,0x28,0x28, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x29,0x2c,0x20,0x5f,0x34,0x32,0x35,0x29,0x20,0x2d,0x20,0x5f,0x34,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61, + 0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x31, + 0x35,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20, + 0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20, + 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29, + 0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72, + 0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c, + 0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78, + 0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f, + 0x34,0x32,0x35,0x20,0x2a,0x20,0x5f,0x34,0x38,0x39,0x2e,0x78,0x29,0x20,0x2b,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x39,0x2e,0x79,0x29,0x29,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69, + 0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74, + 0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20, + 0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f, + 0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75, + 0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62, + 0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, + 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, + 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67, + 0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e, + 0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26, + 0x20,0x5f,0x38,0x33,0x34,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31, + 0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72, + 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30, + 0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, + 0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31, + 0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66, + 0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d, + 0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70, + 0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d, + 0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d, + 0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b, + 0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31, + 0x30,0x31,0x36,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x5f, + 0x31,0x30,0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x31,0x30,0x32,0x33,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x69, + 0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x30,0x31,0x36,0x2c, + 0x20,0x5f,0x31,0x30,0x32,0x33,0x29,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x2d,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x36,0x37,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69,0x65, - 0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x36,0x37,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x34,0x37,0x37,0x20, - 0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x38,0x37,0x20,0x3d,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, - 0x69,0x63,0x65,0x73,0x5b,0x5f,0x31,0x34,0x37,0x37,0x5d,0x20,0x2a,0x20,0x5f,0x31, - 0x34,0x36,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x39,0x34,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38, - 0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f, - 0x31,0x34,0x38,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x31,0x31,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x34,0x39,0x34,0x2e,0x78,0x20, - 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28, - 0x5f,0x31,0x34,0x39,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f, - 0x31,0x34,0x39,0x34,0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x31,0x36,0x20,0x3d,0x20,0x61,0x6e, - 0x79,0x28,0x5f,0x31,0x35,0x31,0x31,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x31,0x36,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32,0x33,0x20,0x3d,0x20,0x61,0x6e, - 0x79,0x28,0x5f,0x31,0x35,0x31,0x31,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x35,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35, - 0x31,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e, - 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31, - 0x35,0x32,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x34,0x37,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74, - 0x20,0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65, - 0x54,0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x34,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x38,0x33,0x34,0x2e, + 0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e, + 0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39, + 0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34, + 0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x5f,0x31,0x30,0x35,0x34, + 0x2c,0x20,0x5f,0x31,0x30,0x35,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x32,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x35, + 0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x33,0x34,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x5f,0x31,0x30,0x37,0x32,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x31,0x30,0x37,0x35,0x20,0x3c,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e, + 0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x35,0x20,0x3c,0x20,0x5f, + 0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x39, + 0x39,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x30,0x36, + 0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x30,0x39,0x39,0x2e,0x77,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x31,0x31,0x32,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x31,0x31,0x30,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x30,0x36,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x38,0x33,0x34,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e, + 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x30,0x36,0x2e, + 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, + 0x20,0x5f,0x31,0x31,0x32,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x31, + 0x32,0x33,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x31,0x33,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x32,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31,0x31, + 0x32,0x33,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x37,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67, - 0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28, - 0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28, - 0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, - 0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x38,0x33,0x20, - 0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, - 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65, - 0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61, - 0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29, - 0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x38,0x34,0x20, - 0x3d,0x20,0x5f,0x31,0x35,0x38,0x33,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x33,0x34,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c, + 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20, + 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30, + 0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x28,0x5f,0x38,0x33,0x34,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x30,0x35, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61, + 0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67, + 0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29, + 0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x36, + 0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x35,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x5f,0x38,0x33,0x34,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x38, - 0x34,0x2c,0x20,0x5f,0x31,0x35,0x38,0x34,0x2c,0x20,0x5f,0x31,0x35,0x38,0x34,0x2c, + 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x30, + 0x36,0x2c,0x20,0x5f,0x31,0x32,0x30,0x36,0x2c,0x20,0x5f,0x31,0x32,0x30,0x36,0x2c, 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, 0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65, @@ -5505,123 +4404,121 @@ static const uint8_t geom_fs_source_metal_macos[20644] = { 0x20,0x69,0x66,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, 0x61,0x6c,0x2e,0x7a,0x20,0x3e,0x20,0x30,0x2e,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x31, - 0x31,0x39,0x38,0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e, - 0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e, - 0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x2e,0x7a,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x69, - 0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78, - 0x79,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, - 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x6d,0x69,0x78,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65,0x64, - 0x75,0x72,0x61,0x6c,0x47,0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x28,0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x63,0x6c,0x61,0x6d,0x70,0x28,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c, - 0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x2c,0x20,0x38,0x2e,0x30,0x29, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x69, - 0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38, - 0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20, - 0x2d,0x28,0x5f,0x31,0x31,0x39,0x38,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x36,0x38,0x33,0x20,0x3d, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x78,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x7a,0x20,0x2b,0x20,0x5f,0x38,0x33, + 0x34,0x2e,0x67,0x72,0x69,0x64,0x5f,0x6f,0x66,0x66,0x73,0x65,0x74,0x2e,0x7a,0x77, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6d,0x69,0x78, + 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x70,0x72,0x6f,0x63,0x65,0x64,0x75,0x72,0x61,0x6c, + 0x47,0x72,0x69,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x70, + 0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28, + 0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x79,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20, + 0x31,0x2e,0x30,0x29,0x2c,0x20,0x38,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x38,0x33,0x34, + 0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x69, + 0x6e,0x2e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x5f,0x31,0x33,0x30,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x32,0x33,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x38,0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d, 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x5f,0x31,0x34,0x31,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x6e, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x31, - 0x36,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, - 0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38, - 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73, - 0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, + 0x28,0x5f,0x38,0x33,0x34,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20, + 0x5f,0x38,0x33,0x34,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x38,0x33, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f, + 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20, + 0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x34,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x20,0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x20,0x3d,0x20,0x5f,0x31,0x33,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20, + 0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20, + 0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x31,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b, + 0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31, + 0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x31,0x5d, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x32, + 0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x33,0x5d,0x20, + 0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x34,0x5d,0x20,0x3d,0x20, + 0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x38, + 0x33,0x34,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x31,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34, + 0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x32,0x31,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73, + 0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x31,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x73,0x68,0x5b, + 0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x38,0x33,0x34,0x2e,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70, 0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, - 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x69,0x6e,0x2e, - 0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20, - 0x3d,0x20,0x6e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d, - 0x20,0x5f,0x31,0x36,0x38,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x62,0x61, - 0x73,0x65,0x43,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e, - 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x34,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b, - 0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34, - 0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x31, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b, - 0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x32,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x33, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x34,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x35,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x36,0x5d,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x37,0x5d,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x39,0x38,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x39,0x38,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x36,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69, - 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x35,0x38,0x34,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61, - 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20,0x69,0x6e,0x2e,0x76, - 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x00, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x32,0x30,0x36,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x2c,0x20, + 0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, + 0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* geom_triangle_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -5645,46 +4542,37 @@ static inline const sg_shader_desc* geom_triangle_shader_desc(sg_backend backend desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 624; + desc.uniform_blocks[1].size = 512; desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_1198.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_834.sun_dir_world"; desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_1198.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_834.sun_color"; desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_1198.flags"; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_834.flags"; desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_1198.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_834.camera_pos"; desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_1198.grid_offset"; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_834.grid_offset"; desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_1198.view"; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_834.view"; desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_1198.cascade_far_view_z"; - desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[7].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_1198.cascade_texel_world"; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_834.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_834.cascade_matrices"; desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_1198.cascade_depth_bias"; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_834.sh"; desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_1198.shadow_params"; - desc.uniform_blocks[1].glsl_uniforms[10].type = SG_UNIFORMTYPE_MAT4; - desc.uniform_blocks[1].glsl_uniforms[10].array_count = 4; - desc.uniform_blocks[1].glsl_uniforms[10].glsl_name = "_1198.cascade_matrices"; - desc.uniform_blocks[1].glsl_uniforms[11].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[11].array_count = 9; - desc.uniform_blocks[1].glsl_uniforms[11].glsl_name = "_1198.sh"; - desc.uniform_blocks[1].glsl_uniforms[12].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[12].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[12].glsl_name = "_1198.ibl_params"; + desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_834.ibl_params"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -5761,7 +4649,7 @@ static inline const sg_shader_desc* geom_triangle_shader_desc(sg_backend backend desc.uniform_blocks[0].hlsl_register_b_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 624; + desc.uniform_blocks[1].size = 512; desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; @@ -5835,7 +4723,7 @@ static inline const sg_shader_desc* geom_triangle_shader_desc(sg_backend backend desc.uniform_blocks[0].msl_buffer_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 624; + desc.uniform_blocks[1].size = 512; desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; diff --git a/samples/shaders/generated/shadow_caster_capsule.glsl.h b/samples/shaders/generated/shadow_caster_capsule.glsl.h index 0887101..17cb593 100644 --- a/samples/shaders/generated/shadow_caster_capsule.glsl.h +++ b/samples/shaders/generated/shadow_caster_capsule.glsl.h @@ -14,7 +14,8 @@ Vertex Shader: vs Fragment Shader: fs Attributes: - ATTR_shadow_capsule_caster_in_pos => 0 + ATTR_shadow_capsule_caster_in_axis => 0 + ATTR_shadow_capsule_caster_in_radial => 1 Bindings: Uniform block 'ub_draw': C struct: shadow_capsule_ub_draw_t @@ -22,9 +23,6 @@ Uniform block 'ub_frame': C struct: shadow_capsule_ub_frame_t Bind slot: UB_shadow_capsule_ub_frame => 0 - Uniform block 'ub_pass': - C struct: shadow_capsule_ub_pass_t - Bind slot: UB_shadow_capsule_ub_pass => 1 Storage buffer 'instances': C struct: shadow_capsule_instance_t Bind slot: VIEW_shadow_capsule_instances => 0 @@ -40,10 +38,10 @@ #define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) #endif #endif -#define ATTR_shadow_capsule_caster_in_pos (0) +#define ATTR_shadow_capsule_caster_in_axis (0) +#define ATTR_shadow_capsule_caster_in_radial (1) #define UB_shadow_capsule_ub_draw (2) #define UB_shadow_capsule_ub_frame (0) -#define UB_shadow_capsule_ub_pass (1) #define VIEW_shadow_capsule_instances (0) #pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_ub_draw_t { @@ -56,12 +54,6 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_ub_frame_t { } shadow_capsule_ub_frame_t; #pragma pack(pop) #pragma pack(push,1) -SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_ub_pass_t { - Vec4 light_dir; - Vec4 depth_row; -} shadow_capsule_ub_pass_t; -#pragma pack(pop) -#pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_instance_t { Vec4 xform_row0; Vec4 xform_row1; @@ -91,29 +83,18 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_capsule_instance_t { uniform ivec4 ub_draw[1]; uniform vec4 ub_frame[4]; - layout(location = 0) in vec3 in_pos; - layout(location = 0) out vec3 v_world_pos_proxy; - layout(location = 1) flat out vec3 v_center; - layout(location = 2) flat out float v_half_length; - layout(location = 3) flat out float v_radius; - layout(location = 4) flat out vec3 v_axis_x_world; + layout(location = 0) in vec3 in_axis; + layout(location = 1) in vec3 in_radial; void main() { int _30 = ub_draw[0].x + gl_InstanceID; - vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); - vec3 _94 = vec3((in_pos.x * 2.0) * (_15.items[_30].params.x + _15.items[_30].params.y), (in_pos.y * 2.0) * _15.items[_30].params.y, (in_pos.z * 2.0) * _15.items[_30].params.y); - vec3 _113 = _63 + vec3(dot(_15.items[_30].xform_row0.xyz, _94), dot(_15.items[_30].xform_row1.xyz, _94), dot(_15.items[_30].xform_row2.xyz, _94)); - v_world_pos_proxy = _113; - v_center = _63; - v_half_length = _15.items[_30].params.x; - v_radius = _15.items[_30].params.y; - v_axis_x_world = vec3(_15.items[_30].xform_row0.x, _15.items[_30].xform_row1.x, _15.items[_30].xform_row2.x); - gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_113, 1.0); + vec3 _81 = (in_axis * _15.items[_30].params.x) + (in_radial * _15.items[_30].params.y); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + vec3(dot(_15.items[_30].xform_row0.xyz, _81), dot(_15.items[_30].xform_row1.xyz, _81), dot(_15.items[_30].xform_row2.xyz, _81)), 1.0); } */ -static const uint8_t shadow_capsule_vs_source_glsl430[1419] = { +static const uint8_t shadow_capsule_vs_source_glsl430[838] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, @@ -134,274 +115,52 @@ static const uint8_t shadow_capsule_vs_source_glsl430[1419] = { 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, - 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, - 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f, 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76, - 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, - 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c, - 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68, - 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66, - 0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x61, - 0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x0a,0x76,0x6f, - 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, - 0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e, + 0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69, + 0x61,0x6c,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d, + 0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20, + 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x38,0x31,0x20,0x3d,0x20,0x28,0x69, + 0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, + 0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x2a, + 0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74, + 0x34,0x28,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75, + 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, + 0x72,0x61,0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, + 0x65,0x5b,0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, + 0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f, + 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e, 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, - 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, - 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, - 0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28, + 0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29, + 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, - 0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x34, - 0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e, - 0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35,0x2e, - 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, - 0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20, - 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, - 0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20,0x28,0x69,0x6e,0x5f, - 0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x5f,0x31,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x76, - 0x65,0x63,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d, - 0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, - 0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20,0x64,0x6f,0x74, - 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20, - 0x5f,0x39,0x34,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, - 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, - 0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, - 0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, - 0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, - 0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31, - 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69, - 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x76,0x65,0x63,0x33, - 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x31, - 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, - 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, - 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, - 0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f, - 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, - 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f, - 0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, - 0x6d,0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, - 0x33,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x31,0x33,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; /* #version 430 - layout(depth_greater) out float gl_FragDepth; - - uniform vec4 ub_pass[2]; - layout(location = 0) in vec3 v_world_pos_proxy; - layout(location = 1) flat in vec3 v_center; - layout(location = 2) flat in float v_half_length; - layout(location = 4) flat in vec3 v_axis_x_world; - layout(location = 3) flat in float v_radius; void main() { - vec3 _32 = v_axis_x_world * v_half_length; - vec3 _33 = v_center - _32; - vec3 _39 = v_center + _32; - vec3 _43 = _39 - _33; - vec3 _47 = v_world_pos_proxy - _33; - float _52 = dot(_43, _43); - float _56 = dot(_43, ub_pass[0].xyz); - float _60 = dot(_43, _47); - float _74 = _52 - (_56 * _56); - float _82 = (_52 * dot(ub_pass[0].xyz, _47)) - (_60 * _56); - float _94 = v_radius * v_radius; - float _105 = (_82 * _82) - (_74 * (((_52 * dot(_47, _47)) - (_60 * _60)) - (_94 * _52))); - float t = -1.0; - if ((_105 >= 0.0) && (_74 > 9.9999999392252902907785028219223e-09)) - { - float _120 = sqrt(_105); - float _122 = -_82; - if ((_122 + _120) >= 0.0) - { - float _135 = max((_122 - _120) / _74, 0.0); - float _141 = _60 + (_135 * _56); - if ((_141 > 0.0) && (_141 < _52)) - { - t = _135; - } - } - } - for (int i = 0; i < 2; i++) - { - bvec3 _167 = bvec3(i == 0); - vec3 _172 = v_world_pos_proxy - vec3(_167.x ? _33.x : _39.x, _167.y ? _33.y : _39.y, _167.z ? _33.z : _39.z); - float _176 = dot(_172, ub_pass[0].xyz); - float _190 = (_176 * _176) - (dot(_172, _172) - _94); - if (_190 >= 0.0) - { - float _197 = sqrt(_190); - float _199 = -_176; - if ((_199 + _197) >= 0.0) - { - float _210 = max(_199 - _197, 0.0); - if ((t < 0.0) || (_210 < t)) - { - t = _210; - } - } - } - } - if (t < 0.0) - { - discard; - } - gl_FragDepth = dot(ub_pass[1], vec4(v_world_pos_proxy + (ub_pass[0].xyz * t), 1.0)); } */ -static const uint8_t shadow_capsule_fs_source_glsl430[2055] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x64,0x65,0x70,0x74,0x68,0x5f,0x67,0x72,0x65,0x61,0x74,0x65, - 0x72,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f, - 0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66, - 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, - 0x5b,0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74, - 0x68,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20, - 0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, - 0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20, - 0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a, - 0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x76, - 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x33,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x39,0x20,0x3d,0x20,0x76,0x5f, - 0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x33,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x33,0x39, - 0x20,0x2d,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x34,0x37,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x33,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x20,0x3d,0x20, - 0x64,0x6f,0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x34,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x36,0x20,0x3d,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b, - 0x30,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x30,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x33, - 0x2c,0x20,0x5f,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x34,0x20,0x3d,0x20,0x5f,0x35,0x32,0x20,0x2d,0x20,0x28,0x5f, - 0x35,0x36,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x32,0x20,0x3d,0x20,0x28,0x5f,0x35,0x32,0x20, - 0x2a,0x20,0x64,0x6f,0x74,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d, - 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x34,0x37,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f, - 0x36,0x30,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x20,0x3d, - 0x20,0x28,0x5f,0x38,0x32,0x20,0x2a,0x20,0x5f,0x38,0x32,0x29,0x20,0x2d,0x20,0x28, - 0x5f,0x37,0x34,0x20,0x2a,0x20,0x28,0x28,0x28,0x5f,0x35,0x32,0x20,0x2a,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x34,0x37,0x2c,0x20,0x5f,0x34,0x37,0x29,0x29,0x20,0x2d,0x20, - 0x28,0x5f,0x36,0x30,0x20,0x2a,0x20,0x5f,0x36,0x30,0x29,0x29,0x20,0x2d,0x20,0x28, - 0x5f,0x39,0x34,0x20,0x2a,0x20,0x5f,0x35,0x32,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x35,0x20, - 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x37,0x34,0x20, - 0x3e,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35, - 0x32,0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39, - 0x32,0x32,0x33,0x65,0x2d,0x30,0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x32,0x30,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x30,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x32,0x32,0x20,0x3d,0x20,0x2d,0x5f,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2b,0x20, - 0x5f,0x31,0x32,0x30,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d, - 0x20,0x6d,0x61,0x78,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2d,0x20,0x5f,0x31,0x32, - 0x30,0x29,0x20,0x2f,0x20,0x5f,0x37,0x34,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x30,0x20,0x2b,0x20,0x28, - 0x5f,0x31,0x33,0x35,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31, - 0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31, - 0x34,0x31,0x20,0x3c,0x20,0x5f,0x35,0x32,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x33, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20, - 0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x32,0x3b,0x20,0x69,0x2b,0x2b,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62, - 0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x36,0x37,0x20,0x3d,0x20,0x62,0x76,0x65,0x63, - 0x33,0x28,0x69,0x20,0x3d,0x3d,0x20,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x37,0x32,0x20,0x3d,0x20,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, - 0x20,0x2d,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x36,0x37,0x2e,0x78,0x20,0x3f, - 0x20,0x5f,0x33,0x33,0x2e,0x78,0x20,0x3a,0x20,0x5f,0x33,0x39,0x2e,0x78,0x2c,0x20, - 0x5f,0x31,0x36,0x37,0x2e,0x79,0x20,0x3f,0x20,0x5f,0x33,0x33,0x2e,0x79,0x20,0x3a, - 0x20,0x5f,0x33,0x39,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x36,0x37,0x2e,0x7a,0x20,0x3f, - 0x20,0x5f,0x33,0x33,0x2e,0x7a,0x20,0x3a,0x20,0x5f,0x33,0x39,0x2e,0x7a,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x37,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x32,0x2c,0x20, - 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x39,0x30,0x20,0x3d,0x20,0x28,0x5f,0x31,0x37,0x36,0x20,0x2a,0x20,0x5f,0x31, - 0x37,0x36,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x32,0x2c, - 0x20,0x5f,0x31,0x37,0x32,0x29,0x20,0x2d,0x20,0x5f,0x39,0x34,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x39,0x30,0x20, - 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28, - 0x5f,0x31,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20, - 0x2d,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x39,0x39,0x20,0x2b,0x20,0x5f, - 0x31,0x39,0x37,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x32,0x31,0x30,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f,0x31,0x39,0x39, - 0x20,0x2d,0x20,0x5f,0x31,0x39,0x37,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20, - 0x28,0x5f,0x32,0x31,0x30,0x20,0x3c,0x20,0x74,0x29,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x32,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61, - 0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74, - 0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x65,0x63, - 0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, +static const uint8_t shadow_capsule_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + }; /* struct instance @@ -422,32 +181,24 @@ static const uint8_t shadow_capsule_fs_source_glsl430[2055] = { cbuffer ub_frame : register(b0) { - row_major float4x4 _139_light_view_proj : packoffset(c0); + row_major float4x4 _108_light_view_proj : packoffset(c0); }; static float4 gl_Position; static int gl_InstanceIndex; - static float3 in_pos; - static float3 v_world_pos_proxy; - static float3 v_center; - static float v_half_length; - static float v_radius; - static float3 v_axis_x_world; + static float3 in_axis; + static float3 in_radial; struct SPIRV_Cross_Input { - float3 in_pos : TEXCOORD0; + float3 in_axis : TEXCOORD0; + float3 in_radial : TEXCOORD1; uint gl_InstanceIndex : SV_InstanceID; }; struct SPIRV_Cross_Output { - float3 v_world_pos_proxy : TEXCOORD0; - nointerpolation float3 v_center : TEXCOORD1; - nointerpolation float v_half_length : TEXCOORD2; - nointerpolation float v_radius : TEXCOORD3; - nointerpolation float3 v_axis_x_world : TEXCOORD4; float4 gl_Position : SV_Position; }; @@ -460,33 +211,22 @@ static const uint8_t shadow_capsule_fs_source_glsl430[2055] = { _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); - float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w); - float3 _94 = float3((in_pos.x * 2.0f) * (_33.params.x + _33.params.y), (in_pos.y * 2.0f) * _33.params.y, (in_pos.z * 2.0f) * _33.params.y); - float3 _113 = _63 + float3(dot(_33.xform_row0.xyz, _94), dot(_33.xform_row1.xyz, _94), dot(_33.xform_row2.xyz, _94)); - v_world_pos_proxy = _113; - v_center = _63; - v_half_length = _33.params.x; - v_radius = _33.params.y; - v_axis_x_world = float3(_33.xform_row0.x, _33.xform_row1.x, _33.xform_row2.x); - gl_Position = mul(float4(_113, 1.0f), _139_light_view_proj); + float3 _81 = (in_axis * _33.params.x) + (in_radial * _33.params.y); + gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + float3(dot(_33.xform_row0.xyz, _81), dot(_33.xform_row1.xyz, _81), dot(_33.xform_row2.xyz, _81)), 1.0f), _108_light_view_proj); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) { gl_InstanceIndex = int(stage_input.gl_InstanceIndex); - in_pos = stage_input.in_pos; + in_axis = stage_input.in_axis; + in_radial = stage_input.in_radial; vert_main(); SPIRV_Cross_Output stage_output; stage_output.gl_Position = gl_Position; - stage_output.v_world_pos_proxy = v_world_pos_proxy; - stage_output.v_center = v_center; - stage_output.v_half_length = v_half_length; - stage_output.v_radius = v_radius; - stage_output.v_axis_x_world = v_axis_x_world; return stage_output; } */ -static const uint8_t shadow_capsule_vs_source_hlsl5[2687] = { +static const uint8_t shadow_capsule_vs_source_hlsl5[1860] = { 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, @@ -507,432 +247,119 @@ static const uint8_t shadow_capsule_vs_source_hlsl5[2687] = { 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x33,0x39,0x5f,0x6c,0x69,0x67,0x68, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x38,0x5f,0x6c,0x69,0x67,0x68, 0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61, 0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b, 0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74, 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, - 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, + 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73, 0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65, - 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61, - 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69, - 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, 0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, - 0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, - 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, - 0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b, - 0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20, - 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e, - 0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a, - 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e, - 0x67,0x74,0x68,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78, - 0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58, - 0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a, - 0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b, - 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78, - 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c, - 0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f, - 0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b, - 0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, - 0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77, - 0x31,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, - 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, - 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, - 0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66, - 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28, - 0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, - 0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, - 0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31, - 0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, - 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39, - 0x36,0x20,0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33, - 0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, - 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, - 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, - 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, - 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, + 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e, + 0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, + 0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, + 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, + 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67, + 0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28, + 0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69, + 0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f, + 0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a, + 0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, - 0x38,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33, + 0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, + 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e, + 0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49, + 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20, + 0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, + 0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73, + 0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28, + 0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78, + 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e, + 0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x31, + 0x20,0x3d,0x20,0x28,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x33, + 0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2b,0x20,0x28,0x69, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, + 0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33, 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20, 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77, 0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, - 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x39,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e, - 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2a, - 0x20,0x28,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2b, - 0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c,0x20, - 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66, - 0x29,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, - 0x2c,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32,0x2e, - 0x30,0x66,0x29,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x2e,0x79,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, - 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29, - 0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, - 0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20, - 0x64,0x6f,0x74,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, - 0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, - 0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67, - 0x74,0x68,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, - 0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x33, - 0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20, - 0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, - 0x5f,0x31,0x31,0x33,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x33, - 0x39,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, - 0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, - 0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, - 0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, - 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, - 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20, - 0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, - 0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d, - 0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x68,0x61, - 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x76,0x5f,0x68,0x61, - 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61, - 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, - 0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, -}; -/* - cbuffer ub_pass : register(b1) - { - float4 _17_light_dir : packoffset(c0); - float4 _17_depth_row : packoffset(c1); - }; - - - static float gl_FragDepth; - static float3 v_world_pos_proxy; - static float3 v_center; - static float v_half_length; - static float3 v_axis_x_world; - static float v_radius; - - struct SPIRV_Cross_Input - { - float3 v_world_pos_proxy : TEXCOORD0; - nointerpolation float3 v_center : TEXCOORD1; - nointerpolation float v_half_length : TEXCOORD2; - nointerpolation float v_radius : TEXCOORD3; - nointerpolation float3 v_axis_x_world : TEXCOORD4; - }; - - struct SPIRV_Cross_Output - { - float gl_FragDepth : SV_DepthGreaterEqual; - }; - - void frag_main() - { - float3 _32 = v_axis_x_world * v_half_length; - float3 _33 = v_center - _32; - float3 _39 = v_center + _32; - float3 _43 = _39 - _33; - float3 _47 = v_world_pos_proxy - _33; - float _52 = dot(_43, _43); - float _56 = dot(_43, _17_light_dir.xyz); - float _60 = dot(_43, _47); - float _74 = _52 - (_56 * _56); - float _82 = (_52 * dot(_17_light_dir.xyz, _47)) - (_60 * _56); - float _94 = v_radius * v_radius; - float _105 = (_82 * _82) - (_74 * (((_52 * dot(_47, _47)) - (_60 * _60)) - (_94 * _52))); - float t = -1.0f; - if ((_105 >= 0.0f) && (_74 > 9.9999999392252902907785028219223e-09f)) - { - float _120 = sqrt(_105); - float _122 = -_82; - if ((_122 + _120) >= 0.0f) - { - float _135 = max((_122 - _120) / _74, 0.0f); - float _141 = _60 + (_135 * _56); - if ((_141 > 0.0f) && (_141 < _52)) - { - t = _135; - } - } - } - for (int i = 0; i < 2; i++) - { - bool3 _167 = (i == 0).xxx; - float3 _172 = v_world_pos_proxy - float3(_167.x ? _33.x : _39.x, _167.y ? _33.y : _39.y, _167.z ? _33.z : _39.z); - float _176 = dot(_172, _17_light_dir.xyz); - float _190 = (_176 * _176) - (dot(_172, _172) - _94); - if (_190 >= 0.0f) - { - float _197 = sqrt(_190); - float _199 = -_176; - if ((_199 + _197) >= 0.0f) - { - float _210 = max(_199 - _197, 0.0f); - if ((t < 0.0f) || (_210 < t)) - { - t = _210; - } - } - } - } - if (t < 0.0f) - { - discard; - } - gl_FragDepth = dot(_17_depth_row, float4(v_world_pos_proxy + (_17_light_dir.xyz * t), 1.0f)); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - v_world_pos_proxy = stage_input.v_world_pos_proxy; - v_center = stage_input.v_center; - v_half_length = stage_input.v_half_length; - v_axis_x_world = stage_input.v_axis_x_world; - v_radius = stage_input.v_radius; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_FragDepth = gl_FragDepth; - return stage_output; - } -*/ -static const uint8_t shadow_capsule_fs_source_hlsl5[2835] = { - 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, - 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68, - 0x5f,0x72,0x6f,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68, - 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, - 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43, - 0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74, - 0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58, - 0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e, - 0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20, - 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, - 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, - 0x44,0x34,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75, - 0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f, - 0x44,0x65,0x70,0x74,0x68,0x47,0x72,0x65,0x61,0x74,0x65,0x72,0x45,0x71,0x75,0x61, - 0x6c,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67, - 0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x76,0x5f,0x61,0x78,0x69, - 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x76,0x5f,0x68,0x61, - 0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x76,0x5f,0x63,0x65, - 0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x20,0x3d,0x20,0x76,0x5f,0x63, - 0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20,0x5f,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x33, - 0x39,0x20,0x2d,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x34,0x37,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x33, - 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32, - 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x34,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x36,0x20, - 0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x31,0x37,0x5f,0x6c, - 0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x30,0x20,0x3d,0x20,0x64, - 0x6f,0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x20,0x3d,0x20,0x5f,0x35, - 0x32,0x20,0x2d,0x20,0x28,0x5f,0x35,0x36,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x32,0x20,0x3d, - 0x20,0x28,0x5f,0x35,0x32,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x5f, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, - 0x34,0x37,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x30,0x20,0x2a,0x20,0x5f,0x35, - 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, - 0x34,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76, - 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x20,0x3d,0x20,0x28,0x5f,0x38,0x32,0x20,0x2a, - 0x20,0x5f,0x38,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20,0x2a,0x20,0x28, - 0x28,0x28,0x5f,0x35,0x32,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x37,0x2c, - 0x20,0x5f,0x34,0x37,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x30,0x20,0x2a,0x20, - 0x5f,0x36,0x30,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x20,0x2a,0x20,0x5f, - 0x35,0x32,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x35,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, - 0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x37,0x34,0x20,0x3e,0x20,0x39,0x2e,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39, - 0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d, - 0x30,0x39,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x20,0x3d, - 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x20, - 0x3d,0x20,0x2d,0x5f,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2b,0x20,0x5f,0x31,0x32,0x30, - 0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2d,0x20,0x5f,0x31,0x32,0x30,0x29,0x20, - 0x2f,0x20,0x5f,0x37,0x34,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x30,0x20,0x2b,0x20,0x28,0x5f,0x31, - 0x33,0x35,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x34,0x31, - 0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31,0x34, - 0x31,0x20,0x3c,0x20,0x5f,0x35,0x32,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x33,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d, - 0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x32,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x33,0x20,0x5f,0x31,0x36,0x37,0x20,0x3d,0x20,0x28,0x69,0x20,0x3d,0x3d, - 0x20,0x30,0x29,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x37,0x32,0x20,0x3d,0x20,0x76, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79, - 0x20,0x2d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x36,0x37,0x2e,0x78, - 0x20,0x3f,0x20,0x5f,0x33,0x33,0x2e,0x78,0x20,0x3a,0x20,0x5f,0x33,0x39,0x2e,0x78, - 0x2c,0x20,0x5f,0x31,0x36,0x37,0x2e,0x79,0x20,0x3f,0x20,0x5f,0x33,0x33,0x2e,0x79, - 0x20,0x3a,0x20,0x5f,0x33,0x39,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x36,0x37,0x2e,0x7a, - 0x20,0x3f,0x20,0x5f,0x33,0x33,0x2e,0x7a,0x20,0x3a,0x20,0x5f,0x33,0x39,0x2e,0x7a, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x32, - 0x2c,0x20,0x5f,0x31,0x37,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e, - 0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x30,0x20,0x3d,0x20,0x28,0x5f,0x31,0x37,0x36, - 0x20,0x2a,0x20,0x5f,0x31,0x37,0x36,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28, - 0x5f,0x31,0x37,0x32,0x2c,0x20,0x5f,0x31,0x37,0x32,0x29,0x20,0x2d,0x20,0x5f,0x39, - 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x39,0x30,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20,0x3d, - 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x39,0x39,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31, - 0x39,0x39,0x20,0x2b,0x20,0x5f,0x31,0x39,0x37,0x29,0x20,0x3e,0x3d,0x20,0x30,0x2e, - 0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x30,0x20,0x3d,0x20,0x6d, - 0x61,0x78,0x28,0x5f,0x31,0x39,0x39,0x20,0x2d,0x20,0x5f,0x31,0x39,0x37,0x2c,0x20, - 0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x74,0x20,0x3c,0x20, - 0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32,0x31,0x30,0x20,0x3c, - 0x20,0x74,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f, - 0x32,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x74,0x20,0x3c, - 0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, - 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x5f,0x64, - 0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, - 0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f, - 0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x74,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x2e,0x77,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f, + 0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x33,0x33, + 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c, + 0x20,0x5f,0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x31,0x30,0x38,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, 0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, - 0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, - 0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20, - 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x5f,0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, - 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x61,0x78,0x69,0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, - 0x7d,0x0a,0x00, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73, + 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d, + 0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56, + 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74, + 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f, + 0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, + 0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_capsule_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, }; /* #include @@ -967,37 +394,26 @@ static const uint8_t shadow_capsule_fs_source_hlsl5[2835] = { struct main0_out { - float3 v_world_pos_proxy [[user(locn0)]]; - float3 v_center [[user(locn1)]]; - float v_half_length [[user(locn2)]]; - float v_radius [[user(locn3)]]; - float3 v_axis_x_world [[user(locn4)]]; float4 gl_Position [[position]]; }; struct main0_in { - float3 in_pos [[attribute(0)]]; + float3 in_axis [[attribute(0)]]; + float3 in_radial [[attribute(1)]]; }; - vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _139 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _108 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) { main0_out out = {}; int _30 = _21.inst_base.x + int(gl_InstanceIndex); - float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); - float3 _94 = float3((in.in_pos.x * 2.0) * (_15.items[_30].params.x + _15.items[_30].params.y), (in.in_pos.y * 2.0) * _15.items[_30].params.y, (in.in_pos.z * 2.0) * _15.items[_30].params.y); - float3 _113 = _63 + float3(dot(_15.items[_30].xform_row0.xyz, _94), dot(_15.items[_30].xform_row1.xyz, _94), dot(_15.items[_30].xform_row2.xyz, _94)); - out.v_world_pos_proxy = _113; - out.v_center = _63; - out.v_half_length = _15.items[_30].params.x; - out.v_radius = _15.items[_30].params.y; - out.v_axis_x_world = float3(_15.items[_30].xform_row0.x, _15.items[_30].xform_row1.x, _15.items[_30].xform_row2.x); - out.gl_Position = _139.light_view_proj * float4(_113, 1.0); + float3 _81 = (in.in_axis * _15.items[_30].params.x) + (in.in_radial * _15.items[_30].params.y); + out.gl_Position = _108.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + float3(dot(_15.items[_30].xform_row0.xyz, _81), dot(_15.items[_30].xform_row1.xyz, _81), dot(_15.items[_30].xform_row2.xyz, _81)), 1.0); return out; } */ -static const uint8_t shadow_capsule_vs_source_metal_macos[1790] = { +static const uint8_t shadow_capsule_vs_source_metal_macos[1216] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -1022,94 +438,59 @@ static const uint8_t shadow_capsule_vs_source_metal_macos[1790] = { 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69, 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75, - 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x68, - 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b,0x75,0x73,0x65, - 0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b, - 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x5d,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69, - 0x73,0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, - 0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, - 0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, - 0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62, - 0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65, - 0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d, - 0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e, - 0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, - 0x26,0x20,0x5f,0x31,0x33,0x39,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, - 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, - 0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75, - 0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, - 0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, - 0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74, - 0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f, - 0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, - 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, - 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, - 0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, - 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x5b,0x5b, + 0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65, + 0x28,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65, + 0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f, + 0x31,0x30,0x38,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d, + 0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64, + 0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65, + 0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65, + 0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20, + 0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d, + 0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20, + 0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, + 0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, + 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x31,0x20,0x3d,0x20,0x28,0x69,0x6e,0x2e, + 0x69,0x6e,0x5f,0x61,0x78,0x69,0x73,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x72,0x61,0x64,0x69, + 0x61,0x6c,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, + 0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, + 0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29, + 0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, + 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31, + 0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x38,0x31,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28, 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, - 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x35, - 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x78,0x20,0x2b,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, - 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x2c, - 0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x79,0x20,0x2a,0x20, - 0x32,0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, - 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x2c,0x20, - 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x2e,0x7a,0x20,0x2a,0x20,0x32, - 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, - 0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x33,0x20, - 0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x64, - 0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, - 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x79,0x7a, - 0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e, - 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, - 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x2c, - 0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f, - 0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78, - 0x79,0x7a,0x2c,0x20,0x5f,0x39,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f, - 0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, - 0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20, - 0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x68, - 0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x35, - 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f, - 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, - 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, - 0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x2c,0x20,0x5f, - 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66, - 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x2e, - 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, - 0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75, - 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x5f,0x31,0x33,0x39,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31, - 0x31,0x33,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f, + 0x38,0x31,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + }; /* #include @@ -1117,229 +498,19 @@ static const uint8_t shadow_capsule_vs_source_metal_macos[1790] = { using namespace metal; - struct ub_pass + fragment void main0() { - float4 light_dir; - float4 depth_row; - }; - - struct main0_out - { - float gl_FragDepth [[depth(greater)]]; - }; - - struct main0_in - { - float3 v_world_pos_proxy [[user(locn0)]]; - float3 v_center [[user(locn1), flat]]; - float v_half_length [[user(locn2), flat]]; - float v_radius [[user(locn3), flat]]; - float3 v_axis_x_world [[user(locn4), flat]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _17 [[buffer(1)]]) - { - main0_out out = {}; - float3 _32 = in.v_axis_x_world * in.v_half_length; - float3 _33 = in.v_center - _32; - float3 _39 = in.v_center + _32; - float3 _43 = _39 - _33; - float3 _47 = in.v_world_pos_proxy - _33; - float _52 = dot(_43, _43); - float _56 = dot(_43, _17.light_dir.xyz); - float _60 = dot(_43, _47); - float _74 = _52 - (_56 * _56); - float _82 = (_52 * dot(_17.light_dir.xyz, _47)) - (_60 * _56); - float _94 = in.v_radius * in.v_radius; - float _105 = (_82 * _82) - (_74 * (((_52 * dot(_47, _47)) - (_60 * _60)) - (_94 * _52))); - float t = -1.0; - if ((_105 >= 0.0) && (_74 > 9.9999999392252902907785028219223e-09)) - { - float _120 = sqrt(_105); - float _122 = -_82; - if ((_122 + _120) >= 0.0) - { - float _135 = fast::max((_122 - _120) / _74, 0.0); - float _141 = _60 + (_135 * _56); - if ((_141 > 0.0) && (_141 < _52)) - { - t = _135; - } - } - } - for (int i = 0; i < 2; i++) - { - float3 _172 = in.v_world_pos_proxy - select(_39, _33, bool3(i == 0)); - float _176 = dot(_172, _17.light_dir.xyz); - float _190 = (_176 * _176) - (dot(_172, _172) - _94); - if (_190 >= 0.0) - { - float _197 = sqrt(_190); - float _199 = -_176; - if ((_199 + _197) >= 0.0) - { - float _210 = fast::max(_199 - _197, 0.0); - if ((t < 0.0) || (_210 < t)) - { - t = _210; - } - } - } - } - if (t < 0.0) - { - discard_fragment(); - } - out.gl_FragDepth = dot(_17.depth_row, float4(in.v_world_pos_proxy + (_17.light_dir.xyz * t), 1.0)); - return out; } */ -static const uint8_t shadow_capsule_fs_source_metal_macos[2302] = { +static const uint8_t shadow_capsule_fs_source_metal_macos[100] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, - 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x64,0x65,0x70,0x74,0x68,0x5f, - 0x72,0x6f,0x77,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, - 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, - 0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x67,0x72,0x65,0x61,0x74, - 0x65,0x72,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, - 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, - 0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b, - 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c, - 0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x76,0x5f,0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x20,0x5b,0x5b, - 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61, - 0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, - 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c, - 0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, - 0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69, - 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, - 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20, - 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62, - 0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, - 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x33,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x61,0x78,0x69,0x73, - 0x5f,0x78,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x68,0x61,0x6c,0x66,0x5f,0x6c,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2d,0x20,0x5f,0x33,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x33,0x39,0x20, - 0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x2b,0x20, - 0x5f,0x33,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x33,0x39,0x20,0x2d,0x20,0x5f,0x33,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x37,0x20, - 0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x20,0x3d,0x20,0x64,0x6f, - 0x74,0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x34,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74, - 0x28,0x5f,0x34,0x33,0x2c,0x20,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f, - 0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x30,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34, - 0x33,0x2c,0x20,0x5f,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x34,0x20,0x3d,0x20,0x5f,0x35,0x32,0x20,0x2d,0x20,0x28, - 0x5f,0x35,0x36,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x32,0x20,0x3d,0x20,0x28,0x5f,0x35,0x32, - 0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74, - 0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x34,0x37,0x29,0x29,0x20, - 0x2d,0x20,0x28,0x5f,0x36,0x30,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x20,0x3d,0x20,0x69, - 0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x20,0x3d,0x20,0x28,0x5f,0x38,0x32,0x20, - 0x2a,0x20,0x5f,0x38,0x32,0x29,0x20,0x2d,0x20,0x28,0x5f,0x37,0x34,0x20,0x2a,0x20, - 0x28,0x28,0x28,0x5f,0x35,0x32,0x20,0x2a,0x20,0x64,0x6f,0x74,0x28,0x5f,0x34,0x37, - 0x2c,0x20,0x5f,0x34,0x37,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x36,0x30,0x20,0x2a, - 0x20,0x5f,0x36,0x30,0x29,0x29,0x20,0x2d,0x20,0x28,0x5f,0x39,0x34,0x20,0x2a,0x20, - 0x5f,0x35,0x32,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x74,0x20,0x3d,0x20,0x2d,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x30,0x35,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, - 0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x37,0x34,0x20,0x3e,0x20,0x39,0x2e,0x39,0x39, - 0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30, - 0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30, - 0x39,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x30,0x20,0x3d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x5f,0x31,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x32,0x20,0x3d,0x20, - 0x2d,0x5f,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2b,0x20,0x5f,0x31,0x32,0x30,0x29,0x20, - 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6d,0x61,0x78,0x28,0x28,0x5f,0x31,0x32,0x32,0x20,0x2d,0x20,0x5f,0x31,0x32, - 0x30,0x29,0x20,0x2f,0x20,0x5f,0x37,0x34,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x30,0x20,0x2b,0x20,0x28, - 0x5f,0x31,0x33,0x35,0x20,0x2a,0x20,0x5f,0x35,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31, - 0x34,0x31,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x26,0x26,0x20,0x28,0x5f,0x31, - 0x34,0x31,0x20,0x3c,0x20,0x5f,0x35,0x32,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x20,0x3d,0x20,0x5f,0x31,0x33, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20, - 0x3d,0x20,0x30,0x3b,0x20,0x69,0x20,0x3c,0x20,0x32,0x3b,0x20,0x69,0x2b,0x2b,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x37,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e, - 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, - 0x79,0x20,0x2d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x28,0x5f,0x33,0x39,0x2c,0x20, - 0x5f,0x33,0x33,0x2c,0x20,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x69,0x20,0x3d,0x3d,0x20, - 0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x37,0x36,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x37,0x32,0x2c,0x20,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69, - 0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x30,0x20,0x3d,0x20,0x28,0x5f,0x31, - 0x37,0x36,0x20,0x2a,0x20,0x5f,0x31,0x37,0x36,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f, - 0x74,0x28,0x5f,0x31,0x37,0x32,0x2c,0x20,0x5f,0x31,0x37,0x32,0x29,0x20,0x2d,0x20, - 0x5f,0x39,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x39,0x30,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x37,0x20, - 0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x37,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f, - 0x31,0x39,0x39,0x20,0x2b,0x20,0x5f,0x31,0x39,0x37,0x29,0x20,0x3e,0x3d,0x20,0x30, - 0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x30,0x20,0x3d,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x39,0x39,0x20,0x2d,0x20, - 0x5f,0x31,0x39,0x37,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x32, - 0x31,0x30,0x20,0x3c,0x20,0x74,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, - 0x20,0x3d,0x20,0x5f,0x32,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x74,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f, - 0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37, - 0x2e,0x64,0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x2e,0x6c, - 0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x74, - 0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* shadow_capsule_caster_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -1352,19 +523,15 @@ static inline const sg_shader_desc* shadow_capsule_caster_shader_desc(sg_backend desc.fragment_func.source = (const char*)shadow_capsule_fs_source_glsl430; desc.fragment_func.entry = "main"; desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; - desc.attrs[0].glsl_name = "in_pos"; + desc.attrs[0].glsl_name = "in_axis"; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].glsl_name = "in_radial"; desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[0].array_count = 2; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -1392,14 +559,13 @@ static inline const sg_shader_desc* shadow_capsule_caster_shader_desc(sg_backend desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; desc.attrs[0].hlsl_sem_name = "TEXCOORD"; desc.attrs[0].hlsl_sem_index = 0; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].hlsl_sem_name = "TEXCOORD"; + desc.attrs[1].hlsl_sem_index = 1; desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].hlsl_register_b_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -1421,14 +587,11 @@ static inline const sg_shader_desc* shadow_capsule_caster_shader_desc(sg_backend desc.fragment_func.source = (const char*)shadow_capsule_fs_source_metal_macos; desc.fragment_func.entry = "main0"; desc.attrs[0].base_type = SG_SHADERATTRBASETYPE_FLOAT; + desc.attrs[1].base_type = SG_SHADERATTRBASETYPE_FLOAT; desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].msl_buffer_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; diff --git a/samples/shaders/generated/shadow_caster_sphere.glsl.h b/samples/shaders/generated/shadow_caster_sphere.glsl.h index 183904c..9718f31 100644 --- a/samples/shaders/generated/shadow_caster_sphere.glsl.h +++ b/samples/shaders/generated/shadow_caster_sphere.glsl.h @@ -22,9 +22,6 @@ Uniform block 'ub_frame': C struct: shadow_sphere_ub_frame_t Bind slot: UB_shadow_sphere_ub_frame => 0 - Uniform block 'ub_pass': - C struct: shadow_sphere_ub_pass_t - Bind slot: UB_shadow_sphere_ub_pass => 1 Storage buffer 'instances': C struct: shadow_sphere_instance_t Bind slot: VIEW_shadow_sphere_instances => 0 @@ -43,7 +40,6 @@ #define ATTR_shadow_sphere_caster_in_pos (0) #define UB_shadow_sphere_ub_draw (2) #define UB_shadow_sphere_ub_frame (0) -#define UB_shadow_sphere_ub_pass (1) #define VIEW_shadow_sphere_instances (0) #pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_draw_t { @@ -56,12 +52,6 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_frame_t { } shadow_sphere_ub_frame_t; #pragma pack(pop) #pragma pack(push,1) -SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_ub_pass_t { - Vec4 light_dir; - Vec4 depth_row; -} shadow_sphere_ub_pass_t; -#pragma pack(pop) -#pragma pack(push,1) SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t { Vec4 xform_row0; Vec4 xform_row1; @@ -92,23 +82,15 @@ SOKOL_SHDC_ALIGN(16) typedef struct shadow_sphere_instance_t { uniform ivec4 ub_draw[1]; uniform vec4 ub_frame[4]; layout(location = 0) in vec3 in_pos; - layout(location = 0) out vec3 v_world_pos_proxy; - layout(location = 1) flat out vec3 v_center; - layout(location = 2) flat out float v_radius; void main() { int _30 = ub_draw[0].x + gl_InstanceID; - vec3 _63 = vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); - vec3 _76 = _63 + (in_pos * (2.0 * _15.items[_30].params.x)); - v_world_pos_proxy = _76; - v_center = _63; - v_radius = _15.items[_30].params.x; - gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(_76, 1.0); + gl_Position = mat4(ub_frame[0], ub_frame[1], ub_frame[2], ub_frame[3]) * vec4(vec3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in_pos * _15.items[_30].params.x), 1.0); } */ -static const uint8_t shadow_sphere_vs_source_glsl430[889] = { +static const uint8_t shadow_sphere_vs_source_glsl430[612] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, @@ -129,102 +111,38 @@ static const uint8_t shadow_sphere_vs_source_glsl430[889] = { 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, 0x65,0x5b,0x34,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65, - 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75, - 0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20, - 0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x33,0x20,0x76, - 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28, - 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c, - 0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33, - 0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b,0x30,0x5d,0x2e,0x78, - 0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d, - 0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, - 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e, - 0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30, - 0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20, - 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78, - 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33, - 0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e, - 0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, - 0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, - 0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f, - 0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75, - 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66, - 0x72,0x61,0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d, - 0x65,0x5b,0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33, - 0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31, - 0x2e,0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x63,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64, + 0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, + 0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x5b, + 0x30,0x5d,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x44,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x5b,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, + 0x6d,0x65,0x5b,0x31,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, + 0x32,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x33,0x5d,0x29, + 0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35, + 0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74, + 0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, + 0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73, + 0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20, + 0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70, + 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, }; /* #version 430 - layout(depth_greater) out float gl_FragDepth; - - uniform vec4 ub_pass[2]; - layout(location = 0) in vec3 v_world_pos_proxy; - layout(location = 1) flat in vec3 v_center; - layout(location = 2) flat in float v_radius; void main() { - vec3 _28 = v_world_pos_proxy - v_center; - float _33 = dot(_28, ub_pass[0].xyz); - float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius)); - if (_49 < 0.0) - { - discard; - } - gl_FragDepth = dot(ub_pass[1], vec4(v_world_pos_proxy + (ub_pass[0].xyz * max((-_33) - sqrt(_49), 0.0)), 1.0)); } */ -static const uint8_t shadow_sphere_fs_source_glsl430[563] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x64,0x65,0x70,0x74,0x68,0x5f,0x67,0x72,0x65,0x61,0x74,0x65, - 0x72,0x29,0x20,0x6f,0x75,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f, - 0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66, - 0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, - 0x5b,0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x76, - 0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20, - 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32, - 0x38,0x2c,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x30,0x5d,0x2e,0x78,0x79, - 0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34, - 0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20, - 0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29, - 0x20,0x2d,0x20,0x28,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76, - 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63, - 0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67, - 0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f, - 0x74,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b,0x31,0x5d,0x2c,0x20,0x76,0x65, - 0x63,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, - 0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x5b, - 0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f, - 0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x00, +static const uint8_t shadow_sphere_fs_source_glsl430[32] = { + 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x76,0x6f, + 0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x00, + }; /* struct instance @@ -245,16 +163,13 @@ static const uint8_t shadow_sphere_fs_source_glsl430[563] = { cbuffer ub_frame : register(b0) { - row_major float4x4 _93_light_view_proj : packoffset(c0); + row_major float4x4 _83_light_view_proj : packoffset(c0); }; static float4 gl_Position; static int gl_InstanceIndex; static float3 in_pos; - static float3 v_world_pos_proxy; - static float3 v_center; - static float v_radius; struct SPIRV_Cross_Input { @@ -264,9 +179,6 @@ static const uint8_t shadow_sphere_fs_source_glsl430[563] = { struct SPIRV_Cross_Output { - float3 v_world_pos_proxy : TEXCOORD0; - nointerpolation float3 v_center : TEXCOORD1; - nointerpolation float v_radius : TEXCOORD2; float4 gl_Position : SV_Position; }; @@ -279,12 +191,7 @@ static const uint8_t shadow_sphere_fs_source_glsl430[563] = { _33.base_color = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 48)); _33.params = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 64)); _33.material = asfloat(_15.Load4((_21_inst_base.x + gl_InstanceIndex) * 96 + 80)); - float3 _63 = float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w); - float3 _76 = _63 + (in_pos * (2.0f * _33.params.x)); - v_world_pos_proxy = _76; - v_center = _63; - v_radius = _33.params.x; - gl_Position = mul(float4(_76, 1.0f), _93_light_view_proj); + gl_Position = mul(float4(float3(_33.xform_row0.w, _33.xform_row1.w, _33.xform_row2.w) + (in_pos * _33.params.x), 1.0f), _83_light_view_proj); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) @@ -294,13 +201,10 @@ static const uint8_t shadow_sphere_fs_source_glsl430[563] = { vert_main(); SPIRV_Cross_Output stage_output; stage_output.gl_Position = gl_Position; - stage_output.v_world_pos_proxy = v_world_pos_proxy; - stage_output.v_center = v_center; - stage_output.v_radius = v_radius; return stage_output; } */ -static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = { +static const uint8_t shadow_sphere_vs_source_hlsl5[1611] = { 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a, 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x78,0x66,0x6f, 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, @@ -321,7 +225,7 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = { 0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a, 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a, 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x39,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74, 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x7d,0x3b,0x0a, 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, @@ -329,11 +233,6 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = { 0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61, 0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, 0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, 0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, @@ -342,219 +241,87 @@ static const uint8_t shadow_sphere_vs_source_hlsl5[2093] = { 0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, 0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, - 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, - 0x78,0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, - 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, - 0x74,0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73, - 0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20, - 0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x33,0x33,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, - 0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35, - 0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74, - 0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36, - 0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x61,0x73,0x66, - 0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28, - 0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, - 0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64, - 0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72, - 0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31, - 0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73, - 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39, - 0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33, - 0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61, - 0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34, - 0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e, - 0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, - 0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x34,0x38,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, - 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, - 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, - 0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, - 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, + 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, + 0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20, + 0x5f,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, + 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, + 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31, + 0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x20, + 0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f, + 0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61, + 0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, + 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20, + 0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f, 0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32, 0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20, 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, - 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72,0x6d, - 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f, - 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78, - 0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f, - 0x36,0x33,0x20,0x2b,0x20,0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28, - 0x32,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f, - 0x37,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, - 0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x61, - 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x39, - 0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, - 0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f, - 0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, - 0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, - 0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70, - 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, - 0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20, - 0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f, - 0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3d, - 0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61, - 0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, -}; -/* - cbuffer ub_pass : register(b1) - { - float4 _17_light_dir : packoffset(c0); - float4 _17_depth_row : packoffset(c1); - }; - - - static float gl_FragDepth; - static float3 v_world_pos_proxy; - static float3 v_center; - static float v_radius; - - struct SPIRV_Cross_Input - { - float3 v_world_pos_proxy : TEXCOORD0; - nointerpolation float3 v_center : TEXCOORD1; - nointerpolation float v_radius : TEXCOORD2; - }; - - struct SPIRV_Cross_Output - { - float gl_FragDepth : SV_DepthGreaterEqual; - }; - - void frag_main() - { - float3 _28 = v_world_pos_proxy - v_center; - float _33 = dot(_28, _17_light_dir.xyz); - float _49 = (_33 * _33) - (dot(_28, _28) - (v_radius * v_radius)); - if (_49 < 0.0f) - { - discard; - } - gl_FragDepth = dot(_17_depth_row, float4(v_world_pos_proxy + (_17_light_dir.xyz * max((-_33) - sqrt(_49), 0.0f)), 1.0f)); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - v_world_pos_proxy = stage_input.v_world_pos_proxy; - v_center = stage_input.v_center; - v_radius = stage_input.v_radius; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_FragDepth = gl_FragDepth; - return stage_output; - } -*/ -static const uint8_t shadow_sphere_fs_source_hlsl5[1155] = { - 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, - 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68, - 0x5f,0x72,0x6f,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20, - 0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, - 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, - 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x7d,0x3b, - 0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, - 0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x47, - 0x72,0x65,0x61,0x74,0x65,0x72,0x45,0x71,0x75,0x61,0x6c,0x3b,0x0a,0x7d,0x3b,0x0a, - 0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x32,0x38,0x20,0x3d,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33, - 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x5f, - 0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20, - 0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64, - 0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20,0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x34,0x39,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46, - 0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, - 0x31,0x37,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x5f,0x6c,0x69, - 0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x6d,0x61, - 0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28, - 0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x66,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, + 0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x5f,0x33,0x33,0x2e,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e, + 0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f, + 0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20, + 0x2b,0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x33,0x33,0x2e, + 0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x28,0x5f,0x32,0x31,0x5f, + 0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c, + 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x20, + 0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x36,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x5f,0x33,0x33,0x2e,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20, + 0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64, + 0x34,0x28,0x28,0x5f,0x32,0x31,0x5f,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65, + 0x2e,0x78,0x20,0x2b,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, + 0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x2a,0x20,0x39,0x36,0x20,0x2b,0x20,0x38,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x33,0x33,0x2e,0x78,0x66,0x6f,0x72, + 0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e,0x78,0x66, + 0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x33,0x33,0x2e, + 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x20,0x2b,0x20, + 0x28,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x5f,0x33,0x33,0x2e,0x70,0x61, + 0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20, + 0x5f,0x38,0x33,0x5f,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70, + 0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, 0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, 0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, - 0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, - 0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a, - 0x7d,0x0a,0x00, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, + 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, + 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, + 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, + 0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, +}; +/* + void frag_main() + { + } + + void main() + { + frag_main(); + } +*/ +static const uint8_t shadow_sphere_fs_source_hlsl5[56] = { + 0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, + 0x0a,0x7b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, + 0x6e,0x28,0x29,0x3b,0x0a,0x7d,0x0a,0x00, }; /* #include @@ -589,9 +356,6 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[1155] = { struct main0_out { - float3 v_world_pos_proxy [[user(locn0)]]; - float3 v_center [[user(locn1)]]; - float v_radius [[user(locn2)]]; float4 gl_Position [[position]]; }; @@ -600,21 +364,16 @@ static const uint8_t shadow_sphere_fs_source_hlsl5[1155] = { float3 in_pos [[attribute(0)]]; }; - vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _93 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) + vertex main0_out main0(main0_in in [[stage_in]], constant ub_frame& _83 [[buffer(0)]], constant ub_draw& _21 [[buffer(2)]], const device instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]]) { main0_out out = {}; int _30 = _21.inst_base.x + int(gl_InstanceIndex); - float3 _63 = float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w); - float3 _76 = _63 + (in.in_pos * (2.0 * _15.items[_30].params.x)); - out.v_world_pos_proxy = _76; - out.v_center = _63; - out.v_radius = _15.items[_30].params.x; - out.gl_Position = _93.light_view_proj * float4(_76, 1.0); + out.gl_Position = _83.light_view_proj * float4(float3(_15.items[_30].xform_row0.w, _15.items[_30].xform_row1.w, _15.items[_30].xform_row2.w) + (in.in_pos * _15.items[_30].params.x), 1.0); return out; } */ -static const uint8_t shadow_sphere_vs_source_metal_macos[1254] = { +static const uint8_t shadow_sphere_vs_source_metal_macos[982] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, @@ -639,59 +398,42 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[1254] = { 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x76,0x69, 0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, 0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75, - 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, - 0x6e,0x32,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b, - 0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, - 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f, - 0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28, - 0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78, - 0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, - 0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x39, - 0x33,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61, - 0x77,0x26,0x20,0x5f,0x32,0x31,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28, - 0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69, - 0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31, - 0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c, - 0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61, - 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20, - 0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73,0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20, - 0x2b,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x36,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e, - 0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31, - 0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f, - 0x72,0x6d,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69, - 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f, - 0x72,0x6f,0x77,0x32,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x37,0x36,0x20,0x3d,0x20,0x5f,0x36,0x33,0x20,0x2b,0x20, - 0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x2a,0x20,0x28,0x32,0x2e, - 0x30,0x20,0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33, - 0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x5f,0x37,0x36,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72, - 0x20,0x3d,0x20,0x5f,0x36,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69, - 0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x39,0x33,0x2e,0x6c,0x69, - 0x67,0x68,0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x37,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f, + 0x6e,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20,0x5b,0x5b,0x61, + 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d, + 0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f, + 0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f, + 0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38,0x33,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61, + 0x6e,0x74,0x20,0x75,0x62,0x5f,0x64,0x72,0x61,0x77,0x26,0x20,0x5f,0x32,0x31,0x20, + 0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x69,0x6e,0x73,0x74, + 0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f,0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66, + 0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20, + 0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, + 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x6e,0x74,0x20,0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x32,0x31,0x2e,0x69,0x6e,0x73, + 0x74,0x5f,0x62,0x61,0x73,0x65,0x2e,0x78,0x20,0x2b,0x20,0x69,0x6e,0x74,0x28,0x67, + 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73, + 0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x5f,0x38,0x33,0x2e,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x2e, + 0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65, + 0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x77,0x2c,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b, + 0x5f,0x33,0x30,0x5d,0x2e,0x78,0x66,0x6f,0x72,0x6d,0x5f,0x72,0x6f,0x77,0x32,0x2e, + 0x77,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x69,0x6e,0x5f,0x70,0x6f,0x73,0x20, + 0x2a,0x20,0x5f,0x31,0x35,0x2e,0x69,0x74,0x65,0x6d,0x73,0x5b,0x5f,0x33,0x30,0x5d, + 0x2e,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74, 0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; @@ -701,94 +443,19 @@ static const uint8_t shadow_sphere_vs_source_metal_macos[1254] = { using namespace metal; - struct ub_pass + fragment void main0() { - float4 light_dir; - float4 depth_row; - }; - - struct main0_out - { - float gl_FragDepth [[depth(greater)]]; - }; - - struct main0_in - { - float3 v_world_pos_proxy [[user(locn0)]]; - float3 v_center [[user(locn1), flat]]; - float v_radius [[user(locn2), flat]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _17 [[buffer(1)]]) - { - main0_out out = {}; - float3 _28 = in.v_world_pos_proxy - in.v_center; - float _33 = dot(_28, _17.light_dir.xyz); - float _49 = (_33 * _33) - (dot(_28, _28) - (in.v_radius * in.v_radius)); - if (_49 < 0.0) - { - discard_fragment(); - } - out.gl_FragDepth = dot(_17.depth_row, float4(in.v_world_pos_proxy + (_17.light_dir.xyz * fast::max((-_33) - sqrt(_49), 0.0)), 1.0)); - return out; } */ -static const uint8_t shadow_sphere_fs_source_metal_macos[861] = { +static const uint8_t shadow_sphere_fs_source_metal_macos[100] = { 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, - 0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69,0x72,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x64,0x65,0x70,0x74,0x68,0x5f, - 0x72,0x6f,0x77,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, - 0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, - 0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x67,0x72,0x65,0x61,0x74, - 0x65,0x72,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, - 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, - 0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b, - 0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c, - 0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, - 0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69, - 0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69, - 0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20, - 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x37,0x20,0x5b,0x5b,0x62, - 0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, - 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x32,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x33,0x33,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f, - 0x32,0x38,0x2c,0x20,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67,0x68,0x74,0x5f,0x64,0x69, - 0x72,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x33,0x33,0x20,0x2a,0x20,0x5f, - 0x33,0x33,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x32,0x38,0x2c,0x20, - 0x5f,0x32,0x38,0x29,0x20,0x2d,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, - 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x34,0x39, - 0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72, - 0x61,0x67,0x6d,0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44, - 0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x37,0x2e,0x64, - 0x65,0x70,0x74,0x68,0x5f,0x72,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f, - 0x70,0x72,0x6f,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x31,0x37,0x2e,0x6c,0x69,0x67, - 0x68,0x74,0x5f,0x64,0x69,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x28,0x2d,0x5f,0x33,0x33,0x29,0x20,0x2d,0x20, - 0x73,0x71,0x72,0x74,0x28,0x5f,0x34,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, + 0x20,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x29,0x0a,0x7b,0x0a, + 0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -808,12 +475,6 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[0].glsl_uniforms[0].array_count = 4; desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[0].array_count = 2; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_pass"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -845,10 +506,6 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].hlsl_register_b_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -874,10 +531,6 @@ static inline const sg_shader_desc* shadow_sphere_caster_shader_desc(sg_backend desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[0].size = 64; desc.uniform_blocks[0].msl_buffer_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; diff --git a/samples/shaders/generated/sky.glsl.h b/samples/shaders/generated/sky.glsl.h index 3609576..a9435a9 100644 --- a/samples/shaders/generated/sky.glsl.h +++ b/samples/shaders/generated/sky.glsl.h @@ -5,7 +5,7 @@ Generated by sokol-shdc (https://github.com/floooh/sokol-tools) Cmdline: - sokol-shdc --input E:/box/box3d/samples/shaders/ibl/sky.glsl --output E:/box/box3d/samples/shaders/generated/sky.glsl.h --slang hlsl5:metal_macos:glsl430 + sokol-shdc --input ibl/sky.glsl --output generated/sky.glsl.h --slang hlsl5:metal_macos:glsl430 Overview: ========= diff --git a/samples/shaders/generated/sky_to_cube.glsl.h b/samples/shaders/generated/sky_to_cube.glsl.h index 2252fad..06e099e 100644 --- a/samples/shaders/generated/sky_to_cube.glsl.h +++ b/samples/shaders/generated/sky_to_cube.glsl.h @@ -5,7 +5,7 @@ Generated by sokol-shdc (https://github.com/floooh/sokol-tools) Cmdline: - sokol-shdc --input E:/box/box3d/samples/shaders/ibl/sky_to_cube.glsl --output E:/box/box3d/samples/shaders/generated/sky_to_cube.glsl.h --slang hlsl5:metal_macos:glsl430 + sokol-shdc --input ibl/sky_to_cube.glsl --output generated/sky_to_cube.glsl.h --slang hlsl5:metal_macos:glsl430 Overview: ========= diff --git a/samples/shaders/generated/sphere.glsl.h b/samples/shaders/generated/sphere.glsl.h index e17df2a..5c49fd1 100644 --- a/samples/shaders/generated/sphere.glsl.h +++ b/samples/shaders/generated/sphere.glsl.h @@ -104,10 +104,7 @@ SOKOL_SHDC_ALIGN(16) typedef struct sphere_ub_pass_t { Mat4 view_proj; Mat4 view; Vec4 cascade_far_view_z; - Vec4 cascade_texel_world; - Vec4 cascade_depth_bias; - Vec4 shadow_params; - Mat4 cascade_matrices[4]; + Mat4 cascade_matrices[3]; Vec4 sh[9]; Vec4 ibl_params; } sphere_ub_pass_t; @@ -268,15 +265,12 @@ static const uint8_t sphere_vs_source_glsl430[1358] = { mat4 view_proj; mat4 view; vec4 cascade_far_view_z; - vec4 cascade_texel_world; - vec4 cascade_depth_bias; - vec4 shadow_params; - mat4 cascade_matrices[4]; + mat4 cascade_matrices[3]; vec4 sh[9]; vec4 ibl_params; }; - uniform ub_pass _1071; + uniform ub_pass _707; layout(binding = 0) uniform sampler2D tex_ao_smp_ao; layout(binding = 1) uniform sampler2DArrayShadow tex_shadow_smp_shadow; @@ -293,218 +287,94 @@ static const uint8_t sphere_vs_source_glsl430[1358] = { layout(location = 0) out vec4 out_color; layout(location = 7) flat in vec4 v_material; - int selectShadowCascade(vec4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, vec3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - vec3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return vec3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - - float sampleShadowTap(vec2 uv, float layer, float ref_z, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - return texture(SPIRV_Cross_Combinedtexsmp, vec4(vec4(uv, layer, ref_z).xyz, ref_z)); - } - - float sampleShadowPCF(int cascade, vec3 light_uv, float bias, float scale, float inv_size, sampler2DArrayShadow SPIRV_Cross_Combinedtexsmp) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias; - vec2 _625 = light_uv.xy * (1.0 / inv_size); - vec2 _630 = floor(_625 + vec2(0.5)); - float _637 = (_625.x + 0.5) - _630.x; - float _644 = (_625.y + 0.5) - _630.y; - vec2 _649 = (_630 - vec2(0.5)) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0 * _637; - float _658 = _656 - 6.0; - float _662 = 11.0 * _637; - float _664 = _662 - 28.0; - float _670 = (-17.0) - _662; - float _675 = (-1.0) - _656; - float _679 = 4.0 * _637; - float _683 = ((_679 - 5.0) / _658) - 3.0; - float _691 = ((_679 - 16.0) / _664) - 1.0; - float _700 = (((-5.0) - (7.0 * _637)) / _670) + 1.0; - float _706 = ((-_637) / _675) + 3.0; - float _709 = 5.0 * _644; - float _710 = _709 - 6.0; - float _713 = 11.0 * _644; - float _714 = _713 - 28.0; - float _719 = (-17.0) - _713; - float _724 = (-1.0) - _709; - float _727 = 4.0 * _644; - float _731 = ((_727 - 5.0) / _710) - 3.0; - float _738 = ((_727 - 16.0) / _714) - 1.0; - float _746 = (((-5.0) - (7.0 * _644)) / _719) + 1.0; - float _752 = ((-_644) / _724) + 3.0; - float sum = 0.0; - vec2 param = _649 + (vec2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(param, param_1, param_2, SPIRV_Cross_Combinedtexsmp)); - vec2 param_3 = _649 + (vec2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(param_3, param_4, param_5, SPIRV_Cross_Combinedtexsmp)); - vec2 param_6 = _649 + (vec2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(param_6, param_7, param_8, SPIRV_Cross_Combinedtexsmp)); - vec2 param_9 = _649 + (vec2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(param_9, param_10, param_11, SPIRV_Cross_Combinedtexsmp)); - vec2 param_12 = _649 + (vec2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(param_12, param_13, param_14, SPIRV_Cross_Combinedtexsmp)); - vec2 param_15 = _649 + (vec2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(param_15, param_16, param_17, SPIRV_Cross_Combinedtexsmp)); - vec2 param_18 = _649 + (vec2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(param_18, param_19, param_20, SPIRV_Cross_Combinedtexsmp)); - vec2 param_21 = _649 + (vec2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(param_21, param_22, param_23, SPIRV_Cross_Combinedtexsmp)); - vec2 param_24 = _649 + (vec2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(param_24, param_25, param_26, SPIRV_Cross_Combinedtexsmp)); - vec2 param_27 = _649 + (vec2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(param_27, param_28, param_29, SPIRV_Cross_Combinedtexsmp)); - vec2 param_30 = _649 + (vec2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(param_30, param_31, param_32, SPIRV_Cross_Combinedtexsmp)); - vec2 param_33 = _649 + (vec2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(param_33, param_34, param_35, SPIRV_Cross_Combinedtexsmp)); - vec2 param_36 = _649 + (vec2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(param_36, param_37, param_38, SPIRV_Cross_Combinedtexsmp)); - vec2 param_39 = _649 + (vec2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(param_39, param_40, param_41, SPIRV_Cross_Combinedtexsmp)); - vec2 param_42 = _649 + (vec2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(param_42, param_43, param_44, SPIRV_Cross_Combinedtexsmp)); - vec2 param_45 = _649 + (vec2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(param_45, param_46, param_47, SPIRV_Cross_Combinedtexsmp)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875; + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float _584 = light_uv.x + 0.00048828125; + float _652 = light_uv.y + 0.00048828125; + return ((((((((texture(tex_shadow_smp_shadow, vec4(vec4(_550, _554, _529, _534).xyz, _534)) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _554, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.xy, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, light_uv.y, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_550, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(light_uv.x, _652, _529, _534).xyz, _534))) + texture(tex_shadow_smp_shadow, vec4(vec4(_584, _652, _529, _534).xyz, _534))) * 0.111111111938953399658203125; } float sampleCascade(int cascade, vec3 world_pos, vec3 world_normal) { - float _1086 = clamp(_1071.cascade_texel_world.x / _1071.cascade_texel_world[cascade], 0.25, 1.0); - float _1095 = max(dot(world_normal, normalize(_1071.sun_dir_world.xyz)), 0.0); - float _1105 = 3.0 * _1086; - vec4 _1128 = _1071.cascade_matrices[cascade] * vec4(world_pos + (world_normal * ((((_1105 + 0.5) * 1.41420996189117431640625) * sqrt(max(1.0 - (_1095 * _1095), 0.0))) * _1071.cascade_texel_world[cascade])), 1.0); - vec3 _1136 = _1128.xyz / vec3(_1128.w); - float _1153 = _1136.z; - vec3 _1154 = vec3((_1136.x * 0.5) + 0.5, ((_1136.y * _1071.shadow_params.x) * 0.5) + 0.5, _1153); - bool _1157 = _1153 < 0.0; - bool _1164; - if (!_1157) + vec4 _717 = _707.cascade_matrices[cascade] * vec4(world_pos, 1.0); + vec3 _724 = _717.xyz / vec3(_717.w); + vec3 _742 = vec3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(lessThan(_742, vec3(0.0))); + bool _753; + if (!_746) { - _1164 = _1153 > 1.0; + _753 = any(greaterThan(_742, vec3(1.0))); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0; - } - float _1174 = (_1105 + 1.0) * _1071.shadow_params.y; - vec2 _1176 = _1154.xy; - bool _1182 = any(lessThan(_1176, vec2(-_1174))); - bool _1193; - if (!_1182) - { - _1193 = any(greaterThan(_1176, vec2(1.0 + _1174))); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0; } int param = cascade; - vec3 param_1 = _1154; - float param_2 = _1071.cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071.shadow_params.y; - return sampleShadowPCF(param, param_1, param_2, param_3, param_4, tex_shadow_smp_shadow); + vec3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, max(dot(world_normal, normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + vec2 _785 = _742.xy; + vec2 _790 = min(_785, vec2(1.0) - _785); + pcf = mix(1.0, pcf, clamp(min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; } float sampleShadowCascaded(vec3 world_pos, vec3 world_normal, float view_z) { - vec4 param = _1071.cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - vec3 param_3 = world_pos; - vec3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) { - _1239 = 0.0; + cascade = 1; + } + } + int param = cascade; + vec3 param_1 = world_pos; + vec3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; } else { - _1239 = _1071.cascade_far_view_z[_1219 - 1]; + _835 = _707.cascade_far_view_z.y; } - float _1252 = mix(_1071.cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - vec3 param_6 = world_pos; - vec3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1252) / (_1071.cascade_far_view_z[_1219] - _1252)); + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + vec3 param_4 = world_pos; + vec3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -512,56 +382,56 @@ static const uint8_t sphere_vs_source_glsl430[1358] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0)) + 1.0; - return _133 / ((3.1415927410125732421875 * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _155 = alpha * alpha; - float _162 = 1.0 - _155; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06); + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); } vec3 pbrFresnelSchlick(float v_dot_h, vec3 f0) { - float _191 = 1.0 - v_dot_h; - float _195 = _191 * _191; - return f0 + ((vec3(1.0) - f0) * ((_195 * _195) * _191)); + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((vec3(1.0) - f0) * ((_169 * _169) * _165)); } vec3 brdf_evaluate(vec3 N, vec3 V, vec3 L, vec3 sun_radiance, vec3 base_color, float metallic, float roughness) { - float _214 = max(dot(N, L), 0.0); - vec3 _225 = normalize(V + L); - float _239 = max(roughness, 0.04500000178813934326171875); - float _243 = _239 * _239; - float param = max(dot(N, _225), 0.0); - float param_1 = _243; + float _188 = max(dot(N, L), 0.0); + vec3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0); + float param_1 = _217; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _214; - float param_4 = _243; - float param_5 = max(dot(V, _225), 0.0); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0); vec3 param_6 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); - vec3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((vec3(1.0) - _270) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + vec3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((vec3(1.0) - _244) * (1.0 - metallic)) * base_color) * vec3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } vec3 pbrEvaluateShIrradiance(vec3 N, vec4 sh[9]) { - vec3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _424; + vec3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; } vec3 pbrEvaluateIbl(vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) { - float _431 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - vec3 _441 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + vec3 _416 = mix(vec3(0.039999999105930328369140625), base_color, vec3(metallic)); vec3 param = N_world; vec4 param_1[9] = sh; - vec4 _505 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_431, roughness)); - return (((((vec3(1.0) - (_441 + ((max(vec3(1.0 - roughness), _441) - _441) * pow(max(0.0, 1.0 - _431), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_441 * _505.x) + vec3(_505.y))); + vec4 _482 = texture(SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut, vec2(_406, roughness)); + return (((((vec3(1.0) - (_416 + ((max(vec3(1.0 - roughness), _416) - _416) * pow(max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), vec3(0.0))) * vec3(0.3183098733425140380859375)) + (textureLod(SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + vec3(_482.y))); } vec3 pbrEvaluateAmbient(bool iblEnabled, vec3 N_world, vec3 V_world, vec3 base_color, float metallic, float roughness, float flat_strength, vec4 sh[9], float max_lod, samplerCube SPIRV_Cross_Combinedtex_spec_cubesmp_spec_cube, sampler2D SPIRV_Cross_Combinedtex_brdf_lutsmp_brdf_lut) @@ -583,121 +453,144 @@ static const uint8_t sphere_vs_source_glsl430[1358] = { void main() { - vec3 _1290 = normalize(v_world_pos_proxy - _1071.camera_pos.xyz); - vec3 _1295 = _1071.camera_pos.xyz - v_center; - float _1299 = dot(_1295, _1290); - float _1308 = v_radius * v_radius; - float _1315 = (_1299 * _1299) - (dot(_1295, _1295) - _1308); - float _1325 = sqrt(max(0.0, _1308 - _1315)) - v_radius; - float _1328 = fwidth(_1325); - float _1330 = max(_1328, 9.9999999747524270787835121154785e-07); - float _1337 = 1.0 - smoothstep(-_1330, _1330, _1325); - float _1341; - if (_1315 >= 0.0) + vec3 _896 = normalize(v_world_pos_proxy - _707.camera_pos.xyz); + vec3 _901 = _707.camera_pos.xyz - v_center; + float _905 = dot(_901, _896); + float _914 = v_radius * v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(max(0.0, _914 - _921)) - v_radius; + float _934 = fwidth(_931); + float _936 = max(_934, 9.9999999747524270787835121154785e-07); + float _943 = 1.0 - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0) { - _1341 = (-_1299) - sqrt(_1315); + _947 = (-_905) - sqrt(_921); } else { - _1341 = -_1299; + _947 = -_905; } - if ((_1337 <= 0.0) || (_1341 < 0.0)) + if ((_943 <= 0.0) || (_947 < 0.0)) { discard; } - vec3 _1366 = _1071.camera_pos.xyz + (_1290 * _1341); - vec3 _1371 = normalize(_1366 - v_center); - float _1377 = _1371.x; - float _1383 = _1371.y; - float _1390 = _1371.z; - float _1392 = ((v_rot_row0.x * _1377) + (v_rot_row1.x * _1383)) + (v_rot_row2.x * _1390); - float _1409 = ((v_rot_row0.y * _1377) + (v_rot_row1.y * _1383)) + (v_rot_row2.y * _1390); - float _1426 = ((v_rot_row0.z * _1377) + (v_rot_row1.z * _1383)) + (v_rot_row2.z * _1390); - vec3 _1477 = v_base_color.xyz * ((_1409 > 0.0) ? 1.0 : 0.64999997615814208984375); - vec3 _1487 = mix(_1477, _1477 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, fwidth(_1392) * 1.5, abs(_1392)), max(1.0 - smoothstep(0.0, fwidth(_1409) * 1.5, abs(_1409)), 1.0 - smoothstep(0.0, fwidth(_1426) * 1.5, abs(_1426)))))); - vec4 _1495 = vec4(_1366, 1.0); - vec4 _1496 = _1071.view_proj * _1495; - gl_FragDepth = _1496.z / _1496.w; - if (_1071.flags.x == 1) + vec3 _972 = _707.camera_pos.xyz + (_896 * _947); + vec3 _977 = normalize(_972 - v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((v_rot_row0.x * _983) + (v_rot_row1.x * _989)) + (v_rot_row2.x * _996); + float _1015 = ((v_rot_row0.y * _983) + (v_rot_row1.y * _989)) + (v_rot_row2.y * _996); + float _1032 = ((v_rot_row0.z * _983) + (v_rot_row1.z * _989)) + (v_rot_row2.z * _996); + vec3 _1083 = v_base_color.xyz * ((_1015 > 0.0) ? 1.0 : 0.64999997615814208984375); + vec3 _1093 = mix(_1083, _1083 * 0.3499999940395355224609375, vec3(max(1.0 - smoothstep(0.0, fwidth(_998) * 1.5, abs(_998)), max(1.0 - smoothstep(0.0, fwidth(_1015) * 1.5, abs(_1015)), 1.0 - smoothstep(0.0, fwidth(_1032) * 1.5, abs(_1032)))))); + vec4 _1101 = vec4(_972, 1.0); + vec4 _1102 = _707.view_proj * _1101; + gl_FragDepth = _1102.z / _1102.w; + if (_707.flags.x == 1) { - float _1528 = clamp((_1071.view * _1495).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out_color = vec4(_1528, _1528, _1528, 1.0); + float _1134 = clamp((_707.view * _1101).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out_color = vec4(_1134, _1134, _1134, 1.0); return; } - if (_1071.flags.x == 2) + if (_707.flags.x == 2) { - vec4 param = _1071.cascade_far_view_z; - float param_1 = -(_1071.view * _1495).z; - int _1556 = selectShadowCascade(param, param_1); - vec4 _1566 = _1071.cascade_matrices[_1556] * _1495; - vec3 _1573 = _1566.xyz / vec3(_1566.w); - vec3 _1590 = vec3((_1573.x * 0.5) + 0.5, ((_1573.y * _1071.shadow_params.x) * 0.5) + 0.5, _1573.z); - bool _1595 = any(lessThan(_1590, vec3(0.0))); - bool _1602; - if (!_1595) + float _1155 = -(_707.view * _1101).z; + int cascade = 2; + if (_1155 < _707.cascade_far_view_z.x) { - _1602 = any(greaterThan(_1590, vec3(1.0))); + cascade = 0; } else { - _1602 = _1595; + if (_1155 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + vec4 _1179 = _707.cascade_matrices[cascade] * _1101; + vec3 _1186 = _1179.xyz / vec3(_1179.w); + vec3 _1203 = vec3((_1186.x * 0.5) + 0.5, ((_1186.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1186.z); + bool _1207 = any(lessThan(_1203, vec3(0.0))); + bool _1214; + if (!_1207) + { + _1214 = any(greaterThan(_1203, vec3(1.0))); + } + else + { + _1214 = _1207; } vec3 tint = vec3(1.0); - if (!_1602) + if (!_1214) { - int param_2 = _1556; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = vec3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = vec3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = vec3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out_color = vec4(tint, 1.0); return; } - if (_1071.flags.x == 3) + if (_707.flags.x == 3) { - out_color = vec4((normalize((_1071.view * vec4(_1377, _1383, _1390, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); + out_color = vec4((normalize((_707.view * vec4(_983, _989, _996, 0.0)).xyz) * 0.5) + vec3(0.5), 1.0); return; } - vec4 _1661 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); - float _1662 = _1661.x; - if (_1071.flags.x == 4) + vec4 _1284 = textureLod(tex_ao_smp_ao, gl_FragCoord.xy / vec2(textureSize(tex_ao_smp_ao, 0)), 0.0); + float _1285 = _1284.x; + if (_707.flags.x == 4) { - out_color = vec4(_1662, _1662, _1662, 1.0); + out_color = vec4(_1285, _1285, _1285, 1.0); return; } - vec3 param_3 = _1366; - vec3 param_4 = _1371; - float param_5 = -(_1071.view * _1495).z; - vec3 _1710 = normalize(_1071.camera_pos.xyz - _1366); - vec3 param_6 = _1371; - vec3 param_7 = _1710; - vec3 param_8 = normalize(_1071.sun_dir_world.xyz); - vec3 param_9 = _1071.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); - vec3 param_10 = _1487; - float param_11 = v_material.x; - float param_12 = v_material.y; - bool param_13 = _1071.ibl_params.y > 0.5; - vec3 param_14 = _1371; - vec3 param_15 = _1710; - vec3 param_16 = _1487; - float param_17 = v_material.x; - float param_18 = v_material.y; - float param_19 = _1071.sun_color.w; - vec4 param_20[9]; - param_20[0] = _1071.sh[0]; - param_20[1] = _1071.sh[1]; - param_20[2] = _1071.sh[2]; - param_20[3] = _1071.sh[3]; - param_20[4] = _1071.sh[4]; - param_20[5] = _1071.sh[5]; - param_20[6] = _1071.sh[6]; - param_20[7] = _1071.sh[7]; - param_20[8] = _1071.sh[8]; - float param_21 = _1071.ibl_params.x; - float _1790 = v_base_color.w * _1337; - out_color = vec4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1662)) * _1790, _1790); + vec3 param = _972; + vec3 param_1 = _977; + float param_2 = -(_707.view * _1101).z; + vec3 _1333 = normalize(_707.camera_pos.xyz - _972); + vec3 param_3 = _977; + vec3 param_4 = _1333; + vec3 param_5 = normalize(_707.sun_dir_world.xyz); + vec3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + vec3 param_7 = _1093; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + vec3 param_11 = _977; + vec3 param_12 = _1333; + vec3 param_13 = _1093; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707.sun_color.w; + vec4 param_17[9]; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1412 = v_base_color.w * _943; + out_color = vec4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, param_18, tex_ibl_spec_smp_ibl_spec, tex_brdf_lut_smp_brdf_lut) * _1285)) * _1412, _1412); } */ -static const uint8_t sphere_fs_source_glsl430[17624] = { +static const uint8_t sphere_fs_source_glsl430[13172] = { 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, 0x72,0x75,0x63,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x0a,0x7b,0x0a,0x20, 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f, @@ -709,1097 +602,819 @@ static const uint8_t sphere_fs_source_glsl430[17624] = { 0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x76,0x69, 0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73, 0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f, - 0x72,0x6d,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e, - 0x67,0x20,0x3d,0x20,0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f, - 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62, - 0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66, - 0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72, - 0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a, - 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d, - 0x20,0x32,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, - 0x63,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e, - 0x67,0x20,0x3d,0x20,0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69, - 0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x3d,0x20,0x32,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61, - 0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x33,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20, - 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, - 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, - 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66, - 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29,0x20,0x66,0x6c,0x61, - 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, - 0x20,0x76,0x65,0x63,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, - 0x20,0x3d,0x20,0x37,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, - 0x63,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a, - 0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x76,0x65,0x63,0x34,0x20,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30, - 0x3b,0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20, - 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, - 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34, - 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, - 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33, - 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, - 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, - 0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, - 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, - 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, - 0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38, - 0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c,0x20,0x30,0x2e,0x33, - 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32,0x38,0x39,0x35, - 0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x76,0x65,0x63,0x32,0x20,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, - 0x65,0x66,0x5f,0x7a,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41, - 0x72,0x72,0x61,0x79,0x53,0x68,0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x73,0x6d,0x70,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63, - 0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66, - 0x5f,0x7a,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x6c,0x69,0x67, - 0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61, - 0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x2c,0x20, + 0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, + 0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, + 0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20,0x5f,0x37,0x30,0x37,0x3b,0x0a,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x30,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f, + 0x61,0x6f,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69, + 0x6e,0x67,0x20,0x3d,0x20,0x31,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20, 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x31, - 0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x32,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20, - 0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, - 0x20,0x5f,0x36,0x32,0x35,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, - 0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76, - 0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, - 0x20,0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36, - 0x32,0x35,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x37,0x20, - 0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29, - 0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32, - 0x35,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33, - 0x30,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x30,0x20,0x2d,0x20,0x76,0x65,0x63, - 0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x20,0x2a,0x20, - 0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x35,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x36,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x32,0x20, - 0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x36,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x36,0x32,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30,0x20,0x3d,0x20,0x28,0x2d, - 0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x35,0x20,0x3d,0x20,0x28, - 0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x39,0x20,0x3d,0x20,0x34, - 0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x37,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35,0x38, - 0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x39, - 0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36,0x34,0x29, - 0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x29, - 0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x30,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x36,0x20, - 0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x37,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37, - 0x35,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x39,0x20,0x3d,0x20,0x35,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30,0x39,0x20,0x2d,0x20,0x36, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x31,0x33,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x34, - 0x20,0x3d,0x20,0x5f,0x37,0x31,0x33,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x39,0x20,0x3d, - 0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x34,0x20, - 0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x30,0x39,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x37,0x20, - 0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f, - 0x37,0x31,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f, - 0x37,0x32,0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20,0x5f,0x37, - 0x31,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d, - 0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37, - 0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34,0x34,0x29,0x20,0x2f,0x20, - 0x5f,0x37,0x32,0x34,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x30,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28, - 0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x53,0x50, - 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, - 0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x39,0x31, - 0x2c,0x20,0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20, - 0x5f,0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37, - 0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, - 0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65, - 0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20, - 0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37, - 0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c, - 0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37, - 0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x37,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x33, - 0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c, - 0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x35,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x36,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x39,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37, - 0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x39,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x30,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20, - 0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x32,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x34, - 0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x2c,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64, - 0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x36, - 0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c, - 0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d,0x20, - 0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61, - 0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x2c,0x20, - 0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62, - 0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x20, - 0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f, - 0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75, - 0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37, - 0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x31,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x76,0x65, - 0x63,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a, - 0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20, - 0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x34,0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, - 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73, - 0x6d,0x70,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x35, - 0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35, - 0x36,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x36, - 0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34, - 0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37, - 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, - 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x73,0x6d,0x70,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x35,0x37,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x35, - 0x37,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36,0x39,0x38,0x32,0x32,0x34, - 0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38,0x37,0x34,0x38,0x37,0x37, - 0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, - 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38, - 0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c, - 0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35, - 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x30,0x39,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, - 0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x33,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, - 0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63, - 0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20,0x2b,0x20,0x28,0x77, - 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20,0x2a,0x20,0x28,0x28, - 0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2a, - 0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31,0x38,0x39,0x31,0x31, - 0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20,0x2a,0x20,0x73,0x71, - 0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31, - 0x30,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x30,0x39,0x35,0x29,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31,0x33, - 0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, - 0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x33,0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28, - 0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, - 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x79, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, - 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x35,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35,0x37,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x36,0x34,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x35,0x37,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x36, - 0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3e,0x20,0x31,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x36,0x34, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x37, - 0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x31,0x2e,0x30, - 0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x32,0x20,0x5f,0x31,0x31,0x37,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35, - 0x34,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x31,0x38,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54, - 0x68,0x61,0x6e,0x28,0x5f,0x31,0x31,0x37,0x36,0x2c,0x20,0x76,0x65,0x63,0x32,0x28, - 0x2d,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x38,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20,0x3d, - 0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e, - 0x28,0x5f,0x31,0x31,0x37,0x36,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e,0x30, - 0x20,0x2b,0x20,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x33,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x34,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x34,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73, - 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x61,0x64,0x6f,0x77,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x6c,0x61,0x79,0x6f, + 0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x32,0x29,0x20, + 0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43, + 0x75,0x62,0x65,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x3b,0x0a,0x6c, + 0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20, + 0x33,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x3b,0x0a, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b, + 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e, + 0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65, + 0x63,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74, + 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x33,0x29,0x20,0x66, + 0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, + 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x34,0x29,0x20,0x66,0x6c,0x61, + 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x31,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63, + 0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x35,0x29,0x20,0x66,0x6c,0x61,0x74,0x20, + 0x69,0x6e,0x20,0x76,0x65,0x63,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x36,0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e, + 0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63, + 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79, + 0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x37, + 0x29,0x20,0x66,0x6c,0x61,0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43, + 0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20, + 0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30, + 0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30, + 0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38, + 0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x35,0x35,0x34, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79, + 0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34, + 0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76,0x65,0x63,0x34,0x28,0x76,0x65, + 0x63,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x76, + 0x65,0x63,0x34,0x28,0x76,0x65,0x63,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f, + 0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x30,0x2e,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35, + 0x33,0x33,0x39,0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, + 0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34, + 0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f, + 0x37,0x31,0x37,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f, + 0x37,0x31,0x37,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x37, + 0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e, + 0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, + 0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20, + 0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20, + 0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e,0x28,0x5f,0x37,0x34, + 0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33, + 0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67,0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68, + 0x61,0x6e,0x28,0x5f,0x37,0x34,0x32,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, + 0x30,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20, + 0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x30,0x2e, + 0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38,0x39,0x38, + 0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x2c, + 0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x39,0x37, + 0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36,0x32,0x31, + 0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77, + 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c, + 0x20,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, + 0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x38,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x31,0x2e, + 0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x31,0x2e, + 0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69, + 0x6e,0x28,0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79, + 0x29,0x20,0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x76,0x65,0x63,0x33,0x20,0x77, 0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x77, 0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f, 0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32,0x31, - 0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x39, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20,0x3c,0x20,0x33,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20,0x3d,0x3d, - 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20, - 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, + 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x20,0x2d,0x20,0x31,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x35,0x32,0x20,0x3d, - 0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31, - 0x32,0x31,0x39,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x39,0x2c,0x20,0x30,0x2e,0x31, - 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31, - 0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20, - 0x3e,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, - 0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32, - 0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64, + 0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35,0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39, + 0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e, + 0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, + 0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e, 0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29, - 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35, - 0x32,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f, - 0x31,0x32,0x31,0x39,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72, - 0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x20,0x3d,0x20,0x28, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2f,0x20,0x28,0x28,0x33, - 0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33, - 0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53, - 0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20,0x61,0x6c,0x70, - 0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30, - 0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73, - 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29, - 0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39, - 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, - 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, - 0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72, - 0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x76,0x65, - 0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x39,0x31,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x39,0x35,0x20,0x3d,0x20,0x5f,0x31,0x39,0x31,0x20,0x2a, - 0x20,0x5f,0x31,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, - 0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x39, - 0x35,0x20,0x2a,0x20,0x5f,0x31,0x39,0x35,0x29,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31, - 0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62,0x72,0x64,0x66, - 0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4c, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61, - 0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x37,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37,0x20,0x2f,0x20, + 0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32, + 0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20, + 0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28, + 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31, + 0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20, + 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c, + 0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31, + 0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, + 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, + 0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63, + 0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c, + 0x20,0x76,0x65,0x63,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30, + 0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x76,0x65,0x63,0x33, + 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28, + 0x5f,0x31,0x36,0x39,0x20,0x2a,0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x62, + 0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x76,0x65,0x63, + 0x33,0x20,0x4e,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x2c,0x20,0x76,0x65,0x63, + 0x33,0x20,0x4c,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61, + 0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, + 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, + 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x39,0x39,0x20, + 0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20, + 0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32, + 0x31,0x33,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37, + 0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31, + 0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31, + 0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, + 0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74, + 0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39, + 0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34, + 0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28, + 0x56,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76, + 0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x34,0x34,0x29, + 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, + 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, + 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x34,0x20, + 0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, + 0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29, + 0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, + 0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65, + 0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, + 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20, + 0x4e,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x33,0x39,0x39,0x20,0x3d, + 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36, + 0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32, + 0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37, + 0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34, + 0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35, + 0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30, + 0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31, + 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, + 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, + 0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33, + 0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39, + 0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a, + 0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31, + 0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, + 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, + 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20, + 0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d, + 0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39,0x39, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f, - 0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x32,0x32,0x35,0x20,0x3d,0x20,0x6e, - 0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x39,0x20, - 0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, - 0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31, - 0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x34,0x33,0x20,0x3d, - 0x20,0x5f,0x32,0x33,0x39,0x20,0x2a,0x20,0x5f,0x32,0x33,0x39,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20, - 0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c, - 0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, - 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, - 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20, - 0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20, - 0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39, - 0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f, - 0x32,0x37,0x30,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c, - 0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33, - 0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x30,0x29,0x20,0x2a,0x20, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x31,0x36, + 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33, + 0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38, + 0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74, + 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x74,0x75,0x72,0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28, + 0x28,0x6d,0x61,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x31,0x36, + 0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28, + 0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f, + 0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20, 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, 0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20, - 0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, - 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, - 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x30,0x20,0x2a,0x20,0x28, - 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, - 0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, - 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, - 0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20, - 0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20, - 0x2a,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72, - 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x2c,0x20, - 0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x32,0x34,0x20,0x3d,0x20,0x28,0x28, - 0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32, - 0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b, - 0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, - 0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33, - 0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a, - 0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36, - 0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36, - 0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31, - 0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37, - 0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39, - 0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35, - 0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35, - 0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31, - 0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e, - 0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29, - 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a, - 0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34, - 0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35, - 0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28, - 0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e, - 0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32,0x34,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x49,0x62,0x6c,0x28,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, - 0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, - 0x73,0x73,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x34,0x33,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28, - 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, - 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, - 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20, - 0x6d,0x69,0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39, - 0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39, - 0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x5f,0x35,0x30,0x35,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72, - 0x65,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, - 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20, - 0x76,0x65,0x63,0x32,0x28,0x5f,0x34,0x33,0x31,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30, - 0x29,0x20,0x2d,0x20,0x28,0x5f,0x34,0x34,0x31,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61, - 0x78,0x28,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2d, - 0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78, - 0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x33,0x31, - 0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a, - 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d, - 0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, - 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76,0x65,0x63,0x33, - 0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x33,0x28,0x30, - 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, - 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65, - 0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, - 0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f,0x35,0x30,0x35,0x2e, - 0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x35,0x30,0x35,0x2e,0x79, - 0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28, - 0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76, - 0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x76,0x65,0x63, - 0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67, - 0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x2c,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50,0x49,0x52,0x56, - 0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74, - 0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73,0x6d,0x70,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, - 0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x72,0x65, - 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, - 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e, - 0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, - 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20, - 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b, + 0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61, + 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x76,0x65,0x63, + 0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32, + 0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65, + 0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e, + 0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20,0x2a,0x20,0x5f,0x34, + 0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x34,0x38, + 0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x65,0x63,0x33,0x20, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, + 0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c, + 0x65,0x64,0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, + 0x2c,0x20,0x76,0x65,0x63,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, + 0x76,0x65,0x63,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72, + 0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x76,0x65,0x63,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, + 0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x75,0x62,0x65,0x20,0x53,0x50, + 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e, + 0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72, + 0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65, + 0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62, + 0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74, - 0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62, - 0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53, - 0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f,0x6d,0x62,0x69, - 0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x73, - 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72, - 0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d, - 0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, - 0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, - 0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70, - 0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d, - 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x39,0x35,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, - 0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x39,0x20, - 0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x35,0x2c,0x20,0x5f,0x31,0x32, - 0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20, - 0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x31,0x35,0x20,0x3d,0x20,0x28,0x5f, - 0x31,0x32,0x39,0x39,0x20,0x2a,0x20,0x5f,0x31,0x32,0x39,0x39,0x29,0x20,0x2d,0x20, - 0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x35,0x2c,0x20,0x5f,0x31,0x32,0x39, - 0x35,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x3d,0x20,0x73, - 0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33, - 0x30,0x38,0x20,0x2d,0x20,0x5f,0x31,0x33,0x31,0x35,0x29,0x29,0x20,0x2d,0x20,0x76, - 0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x3d,0x20,0x66,0x77,0x69,0x64,0x74, - 0x68,0x28,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x30,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28, - 0x5f,0x31,0x33,0x32,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39, - 0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31, - 0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x37,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, - 0x70,0x28,0x2d,0x5f,0x31,0x33,0x33,0x30,0x2c,0x20,0x5f,0x31,0x33,0x33,0x30,0x2c, - 0x20,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x34,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x33,0x31,0x35,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x33,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x32,0x39,0x39,0x29,0x20,0x2d, - 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x33,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x34,0x31, - 0x20,0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x31,0x33,0x33,0x37,0x20, - 0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x31,0x33,0x34, - 0x31,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61, - 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28, - 0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33,0x34,0x31,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x33,0x37,0x31,0x20,0x3d, - 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x33,0x36,0x36, - 0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x37,0x20,0x3d,0x20, - 0x5f,0x31,0x33,0x37,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31, - 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x33,0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x2e,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x32,0x20,0x3d, - 0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x20, - 0x2a,0x20,0x5f,0x31,0x33,0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33, - 0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32, - 0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31,0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x30,0x39,0x20,0x3d,0x20,0x28, - 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20, - 0x5f,0x31,0x33,0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f, - 0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79, - 0x20,0x2a,0x20,0x5f,0x31,0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x36,0x20,0x3d,0x20,0x28,0x28,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x31, - 0x33,0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, - 0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a, - 0x20,0x5f,0x31,0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x5f,0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f, - 0x31,0x34,0x30,0x39,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e, - 0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31, - 0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x34,0x38,0x37,0x20,0x3d, - 0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x34,0x37,0x37,0x2c,0x20,0x5f,0x31,0x34,0x37, - 0x37,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30, - 0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c, - 0x20,0x76,0x65,0x63,0x33,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20, - 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33,0x39,0x32,0x29,0x20,0x2a,0x20, - 0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x39,0x32,0x29,0x29, - 0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, - 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64, - 0x74,0x68,0x28,0x5f,0x31,0x34,0x30,0x39,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c, - 0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34,0x30,0x39,0x29,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30, - 0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x34,0x32,0x36, - 0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34, - 0x32,0x36,0x29,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x34,0x20,0x5f,0x31,0x34,0x39,0x35,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, - 0x5f,0x31,0x33,0x36,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x34,0x39,0x36,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20, - 0x5f,0x31,0x34,0x39,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x34,0x39,0x36,0x2e, - 0x7a,0x20,0x2f,0x20,0x5f,0x31,0x34,0x39,0x36,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73, - 0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, - 0x32,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x29,0x2e, - 0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30, - 0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x35,0x32,0x38, - 0x2c,0x20,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20, - 0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, - 0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65, - 0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x35,0x36,0x20, - 0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x34,0x20,0x5f,0x31,0x35,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, - 0x65,0x73,0x5b,0x5f,0x31,0x35,0x35,0x36,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39, - 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x5f,0x31,0x35,0x37,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x36,0x36,0x2e,0x78,0x79, - 0x7a,0x20,0x2f,0x20,0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x35,0x36,0x36,0x2e,0x77, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, - 0x5f,0x31,0x35,0x39,0x30,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31, - 0x35,0x37,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, - 0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x35,0x37,0x33,0x2e,0x79,0x20,0x2a,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x35,0x37,0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39, - 0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, - 0x28,0x5f,0x31,0x35,0x39,0x30,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, + 0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63, + 0x75,0x62,0x65,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x43,0x6f, + 0x6d,0x62,0x69,0x6e,0x65,0x64,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69, + 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x30,0x31,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x30,0x35,0x20,0x3d,0x20, + 0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x38,0x39,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x31,0x34,0x20, + 0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x76,0x5f,0x72, + 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x32,0x31,0x20,0x3d,0x20,0x28,0x5f,0x39,0x30,0x35,0x20,0x2a,0x20, + 0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30, + 0x31,0x2c,0x20,0x5f,0x39,0x30,0x31,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x31, + 0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c, + 0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32,0x31,0x29,0x29,0x20,0x2d, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d,0x20,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x5f, + 0x39,0x33,0x34,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31, + 0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x33,0x20,0x3d,0x20,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d, + 0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x32,0x31,0x20, + 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f, + 0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x2d,0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34, + 0x33,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39, + 0x34,0x37,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d, + 0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f, + 0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x39,0x37,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x76,0x5f, + 0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x78, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x39, + 0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37, + 0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x30,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39, + 0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x32,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20, + 0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a, + 0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33, + 0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e, + 0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39, + 0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31,0x35,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x30, + 0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31,0x34,0x32, + 0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30,0x38,0x33,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35, + 0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x76,0x65,0x63,0x33, + 0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74, + 0x68,0x28,0x5f,0x39,0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61, + 0x62,0x73,0x28,0x5f,0x39,0x39,0x38,0x29,0x29,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31, + 0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28, + 0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x31, + 0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31, + 0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f, + 0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69, + 0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29,0x29,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x31,0x30, + 0x31,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x39,0x37,0x32,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31, + 0x31,0x30,0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d, + 0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32, + 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, + 0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31, + 0x31,0x30,0x31,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39, + 0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31, + 0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31, + 0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c, + 0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76, + 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35, + 0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f, + 0x31,0x31,0x37,0x39,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x31,0x38, + 0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x76,0x65,0x63,0x33,0x28,0x5f,0x31,0x31,0x37,0x39,0x2e,0x77,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x32,0x30, + 0x33,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e, + 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20, + 0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37, + 0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32,0x30, + 0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x6c,0x65,0x73,0x73,0x54,0x68,0x61,0x6e, + 0x28,0x5f,0x31,0x32,0x30,0x33,0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x30, 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, - 0x6c,0x20,0x5f,0x31,0x36,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x39,0x35,0x29,0x0a,0x20,0x20,0x20, + 0x6c,0x20,0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x36,0x30,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67, - 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x35,0x39,0x30, + 0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x67, + 0x72,0x65,0x61,0x74,0x65,0x72,0x54,0x68,0x61,0x6e,0x28,0x5f,0x31,0x32,0x30,0x33, 0x2c,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x29,0x29,0x29,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x36,0x30, - 0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31, + 0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x76,0x65,0x63, 0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e, 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x36,0x30,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x35, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, - 0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, - 0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, - 0x5f,0x31,0x33,0x37,0x37,0x2c,0x20,0x5f,0x31,0x33,0x38,0x33,0x2c,0x20,0x5f,0x31, - 0x33,0x39,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20, - 0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e, - 0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x36,0x36,0x31,0x20,0x3d, - 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f, - 0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63, - 0x32,0x28,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65, - 0x78,0x5f,0x61,0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29, - 0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x36,0x36,0x32,0x20,0x3d,0x20,0x5f,0x31,0x36,0x36,0x31,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31, - 0x36,0x36,0x32,0x2c,0x20,0x5f,0x31,0x36,0x36,0x32,0x2c,0x20,0x5f,0x31,0x36,0x36, - 0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x21,0x5f,0x31,0x32,0x31,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69, + 0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30, + 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, + 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74, + 0x69,0x6e,0x74,0x20,0x3d,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34, + 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37, + 0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, + 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x76, + 0x65,0x63,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39, + 0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c, + 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, + 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, + 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d, + 0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, + 0x63,0x34,0x28,0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28, + 0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38,0x39,0x2c,0x20,0x5f,0x39,0x39,0x36, + 0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c, + 0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, + 0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x76,0x65,0x63,0x34,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x4c,0x6f,0x64,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x5f, + 0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43, + 0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x74, + 0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61, + 0x6f,0x5f,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x30,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x38,0x34,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c, + 0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31, + 0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x76, + 0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39,0x37,0x32, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d, + 0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x31, + 0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20, + 0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, + 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29,0x3b,0x0a,0x20, 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x33,0x36,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37, - 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76, - 0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x29,0x2e,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x5f,0x31,0x37,0x31,0x30,0x20,0x3d, - 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20, - 0x2d,0x20,0x5f,0x31,0x33,0x36,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, - 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33, - 0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x37,0x31,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d, - 0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78, - 0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x75, - 0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30, - 0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76, + 0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20, + 0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65, + 0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33, + 0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x76, 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20, 0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20, - 0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x37, - 0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x37,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x63,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x39, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, - 0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x30,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x31, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x32,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x33,0x5d,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x34,0x5d,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x35,0x5d,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37, - 0x39,0x30,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63, - 0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, + 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34, + 0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65,0x63,0x34, + 0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b, + 0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62, + 0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70, 0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, - 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65, - 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x36,0x32, - 0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37,0x39,0x30,0x2c,0x20,0x5f,0x31,0x37,0x39, - 0x30,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x5f,0x73,0x6d,0x70,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x29,0x20,0x2a,0x20,0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x34,0x31,0x32,0x2c,0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x00, }; /* struct instance @@ -2079,19 +1694,16 @@ static const uint8_t sphere_vs_source_hlsl5[2863] = { /* cbuffer ub_pass : register(b1) { - float4 _1071_sun_dir_world : packoffset(c0); - float4 _1071_sun_color : packoffset(c1); - int4 _1071_flags : packoffset(c2); - float4 _1071_camera_pos : packoffset(c3); - row_major float4x4 _1071_view_proj : packoffset(c4); - row_major float4x4 _1071_view : packoffset(c8); - float4 _1071_cascade_far_view_z : packoffset(c12); - float4 _1071_cascade_texel_world : packoffset(c13); - float4 _1071_cascade_depth_bias : packoffset(c14); - float4 _1071_shadow_params : packoffset(c15); - row_major float4x4 _1071_cascade_matrices[4] : packoffset(c16); - float4 _1071_sh[9] : packoffset(c32); - float4 _1071_ibl_params : packoffset(c41); + float4 _707_sun_dir_world : packoffset(c0); + float4 _707_sun_color : packoffset(c1); + int4 _707_flags : packoffset(c2); + float4 _707_camera_pos : packoffset(c3); + row_major float4x4 _707_view_proj : packoffset(c4); + row_major float4x4 _707_view : packoffset(c8); + float4 _707_cascade_far_view_z : packoffset(c12); + row_major float4x4 _707_cascade_matrices[3] : packoffset(c13); + float4 _707_sh[9] : packoffset(c25); + float4 _707_ibl_params : packoffset(c34); }; Texture2DArray tex_shadow : register(t0); @@ -2141,220 +1753,94 @@ static const uint8_t sphere_vs_source_hlsl5[2863] = { return ret; } - int selectShadowCascade(float4 far_view_z, float view_z) + float sampleShadowPCF(int cascade, float3 light_uv, float bias) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; - } - - float3 shadowCascadeTint(int cascade) - { - if (cascade == 0) - { - return float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); - } - return float3(1.0f, 0.89999997615814208984375f, 0.300000011920928955078125f); - } - - float sampleShadowTap(Texture2DArray tex, SamplerComparisonState smp, float2 uv, float layer, float ref_z) - { - return tex.SampleCmp(smp, float4(uv, layer, ref_z).xyz, ref_z); - } - - float sampleShadowPCF(Texture2DArray tex, SamplerComparisonState smp, int cascade, float3 light_uv, float bias, float scale, float inv_size) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias; - float2 _625 = light_uv.xy * (1.0f / inv_size); - float2 _630 = floor(_625 + 0.5f.xx); - float _637 = (_625.x + 0.5f) - _630.x; - float _644 = (_625.y + 0.5f) - _630.y; - float2 _649 = (_630 - 0.5f.xx) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0f * _637; - float _658 = _656 - 6.0f; - float _662 = 11.0f * _637; - float _664 = _662 - 28.0f; - float _670 = (-17.0f) - _662; - float _675 = (-1.0f) - _656; - float _679 = 4.0f * _637; - float _683 = ((_679 - 5.0f) / _658) - 3.0f; - float _691 = ((_679 - 16.0f) / _664) - 1.0f; - float _700 = (((-5.0f) - (7.0f * _637)) / _670) + 1.0f; - float _706 = ((-_637) / _675) + 3.0f; - float _709 = 5.0f * _644; - float _710 = _709 - 6.0f; - float _713 = 11.0f * _644; - float _714 = _713 - 28.0f; - float _719 = (-17.0f) - _713; - float _724 = (-1.0f) - _709; - float _727 = 4.0f * _644; - float _731 = ((_727 - 5.0f) / _710) - 3.0f; - float _738 = ((_727 - 16.0f) / _714) - 1.0f; - float _746 = (((-5.0f) - (7.0f * _644)) / _719) + 1.0f; - float _752 = ((-_644) / _724) + 3.0f; - float sum = 0.0f; - float2 param = _649 + (float2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _649 + (float2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _649 + (float2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _649 + (float2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _649 + (float2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _649 + (float2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _649 + (float2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _649 + (float2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _649 + (float2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _649 + (float2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _649 + (float2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _649 + (float2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _649 + (float2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _649 + (float2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _649 + (float2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _649 + (float2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875f; + float _529 = float(cascade); + float _534 = light_uv.z - bias; + float _550 = light_uv.x - 0.00048828125f; + float _554 = light_uv.y - 0.00048828125f; + float _584 = light_uv.x + 0.00048828125f; + float _652 = light_uv.y + 0.00048828125f; + return ((((((((tex_shadow.SampleCmp(smp_shadow, float4(_550, _554, _529, _534).xyz, _534) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _554, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.xy, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, light_uv.y, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_550, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(light_uv.x, _652, _529, _534).xyz, _534)) + tex_shadow.SampleCmp(smp_shadow, float4(_584, _652, _529, _534).xyz, _534)) * 0.111111111938953399658203125f; } float sampleCascade(int cascade, float3 world_pos, float3 world_normal) { - float _1086 = clamp(_1071_cascade_texel_world.x / _1071_cascade_texel_world[cascade], 0.25f, 1.0f); - float _1095 = max(dot(world_normal, normalize(_1071_sun_dir_world.xyz)), 0.0f); - float _1105 = 3.0f * _1086; - float4 _1128 = mul(float4(world_pos + (world_normal * ((((_1105 + 0.5f) * 1.41420996189117431640625f) * sqrt(max(1.0f - (_1095 * _1095), 0.0f))) * _1071_cascade_texel_world[cascade])), 1.0f), _1071_cascade_matrices[cascade]); - float3 _1136 = _1128.xyz / _1128.w.xxx; - float _1153 = _1136.z; - float3 _1154 = float3((_1136.x * 0.5f) + 0.5f, ((_1136.y * _1071_shadow_params.x) * 0.5f) + 0.5f, _1153); - bool _1157 = _1153 < 0.0f; - bool _1164; - if (!_1157) + float4 _717 = mul(float4(world_pos, 1.0f), _707_cascade_matrices[cascade]); + float3 _724 = _717.xyz / _717.w.xxx; + float3 _742 = float3((_724.x * 0.5f) + 0.5f, ((_724.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _724.z); + bool _746 = any(bool3(_742.x < 0.0f.xxx.x, _742.y < 0.0f.xxx.y, _742.z < 0.0f.xxx.z)); + bool _753; + if (!_746) { - _1164 = _1153 > 1.0f; + _753 = any(bool3(_742.x > 1.0f.xxx.x, _742.y > 1.0f.xxx.y, _742.z > 1.0f.xxx.z)); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0f; - } - float _1174 = (_1105 + 1.0f) * _1071_shadow_params.y; - float2 _1176 = _1154.xy; - float2 _1179 = (-_1174).xx; - bool _1182 = any(bool2(_1176.x < _1179.x, _1176.y < _1179.y)); - bool _1193; - if (!_1182) - { - float2 _1190 = (1.0f + _1174).xx; - _1193 = any(bool2(_1176.x > _1190.x, _1176.y > _1190.y)); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0f; } int param = cascade; - float3 param_1 = _1154; - float param_2 = _1071_cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071_shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _742; + float param_2 = lerp(0.0040000001899898052215576171875f, 0.0007999999797903001308441162109375f, max(dot(world_normal, normalize(_707_sun_dir_world.xyz)), 0.0f)); + float pcf = sampleShadowPCF(param, param_1, param_2); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = min(_785, 1.0f.xx - _785); + pcf = lerp(1.0f, pcf, clamp(min(_790.x, _790.y) * 10.0f, 0.0f, 1.0f)); + } + return pcf; } float sampleShadowCascaded(float3 world_pos, float3 world_normal, float view_z) { - float4 param = _1071_cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707_cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707_cascade_far_view_z.y) { - _1239 = 0.0f; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707_cascade_far_view_z.x; } else { - _1239 = _1071_cascade_far_view_z[_1219 - 1]; + _835 = _707_cascade_far_view_z.y; } - float _1252 = lerp(_1071_cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625f); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = lerp(shadow, sampleCascade(param_5, param_6, param_7), (view_z - _1252) / (_1071_cascade_far_view_z[_1219] - _1252)); + _847 = 0.0f; + } + else + { + _847 = _707_cascade_far_view_z.x; + } + float _858 = lerp(_835, _847, 0.100000001490116119384765625f); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = lerp(shadow, sampleCascade(param_3, param_4, param_5), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -2362,56 +1848,56 @@ static const uint8_t sphere_vs_source_hlsl5[2863] = { float pbrDistributionGGX(float n_dot_h, float alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0f)) + 1.0f; - return _133 / ((3.1415927410125732421875f * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0f)) + 1.0f; + return _107 / ((3.1415927410125732421875f * _116) * _116); } float pbrVisibilitySmithCorrelated(float n_dot_v, float n_dot_l, float alpha) { - float _155 = alpha * alpha; - float _162 = 1.0f - _155; - return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06f); + float _129 = alpha * alpha; + float _136 = 1.0f - _129; + return 0.5f / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06f); } float3 pbrFresnelSchlick(float v_dot_h, float3 f0) { - float _191 = 1.0f - v_dot_h; - float _195 = _191 * _191; - return f0 + ((1.0f.xxx - f0) * ((_195 * _195) * _191)); + float _165 = 1.0f - v_dot_h; + float _169 = _165 * _165; + return f0 + ((1.0f.xxx - f0) * ((_169 * _169) * _165)); } float3 brdf_evaluate(float3 N, float3 V, float3 L, float3 sun_radiance, float3 base_color, float metallic, float roughness) { - float _214 = max(dot(N, L), 0.0f); - float3 _225 = normalize(V + L); - float _239 = max(roughness, 0.04500000178813934326171875f); - float _243 = _239 * _239; - float param = max(dot(N, _225), 0.0f); - float param_1 = _243; + float _188 = max(dot(N, L), 0.0f); + float3 _199 = normalize(V + L); + float _213 = max(roughness, 0.04500000178813934326171875f); + float _217 = _213 * _213; + float param = max(dot(N, _199), 0.0f); + float param_1 = _217; float param_2 = max(dot(N, V), 9.9999997473787516355514526367188e-05f); - float param_3 = _214; - float param_4 = _243; - float param_5 = max(dot(V, _225), 0.0f); + float param_3 = _188; + float param_4 = _217; + float param_5 = max(dot(V, _199), 0.0f); float3 param_6 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); - float3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((1.0f.xxx - _270) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((1.0f.xxx - _244) * (1.0f - metallic)) * base_color) * 0.3183098733425140380859375f.xxx) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } float3 pbrEvaluateShIrradiance(float3 N, float4 sh[9]) { - float3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); - return _424; + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375f) + (sh[1].xyz * ((-0.48860251903533935546875f) * N.y))) + (sh[2].xyz * (0.48860251903533935546875f * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875f) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125f * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125f) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125f * (((3.0f * N.z) * N.z) - 1.0f)))) + (sh[7].xyz * (((-1.09254848957061767578125f) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625f * ((N.x * N.x) - (N.y * N.y)))); + return _399; } float3 pbrEvaluateIbl(float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) { - float _431 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); - float3 _441 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); + float _406 = clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05f, 1.0f); + float3 _416 = lerp(0.039999999105930328369140625f.xxx, base_color, metallic.xxx); float3 param = N_world; float4 param_1[9] = sh; - float4 _505 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_431, roughness)); - return (((((1.0f.xxx - (_441 + ((max((1.0f - roughness).xxx, _441) - _441) * pow(max(0.0f, 1.0f - _431), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_441 * _505.x) + _505.y.xxx)); + float4 _482 = tex_brdf_lut_1.Sample(smp_brdf_lut_1, float2(_406, roughness)); + return (((((1.0f.xxx - (_416 + ((max((1.0f - roughness).xxx, _416) - _416) * pow(max(0.0f, 1.0f - _406), 5.0f)))) * (1.0f - metallic)) * base_color) * max(pbrEvaluateShIrradiance(param, param_1), 0.0f.xxx)) * 0.3183098733425140380859375f.xxx) + (tex_spec_cube.SampleLevel(smp_spec_cube, reflect(-V_world, N_world), roughness * max_lod).xyz * ((_416 * _482.x) + _482.y.xxx)); } float3 pbrEvaluateAmbient(bool iblEnabled, float3 N_world, float3 V_world, float3 base_color, float metallic, float roughness, float flat_strength, float4 sh[9], TextureCube tex_spec_cube, SamplerState smp_spec_cube, Texture2D tex_brdf_lut_1, SamplerState smp_brdf_lut_1, float max_lod) @@ -2433,118 +1919,141 @@ static const uint8_t sphere_vs_source_hlsl5[2863] = { void frag_main() { - float3 _1290 = normalize(v_world_pos_proxy - _1071_camera_pos.xyz); - float3 _1295 = _1071_camera_pos.xyz - v_center; - float _1299 = dot(_1295, _1290); - float _1308 = v_radius * v_radius; - float _1315 = (_1299 * _1299) - (dot(_1295, _1295) - _1308); - float _1325 = sqrt(max(0.0f, _1308 - _1315)) - v_radius; - float _1328 = fwidth(_1325); - float _1330 = max(_1328, 9.9999999747524270787835121154785e-07f); - float _1337 = 1.0f - smoothstep(-_1330, _1330, _1325); - float _1341; - if (_1315 >= 0.0f) + float3 _896 = normalize(v_world_pos_proxy - _707_camera_pos.xyz); + float3 _901 = _707_camera_pos.xyz - v_center; + float _905 = dot(_901, _896); + float _914 = v_radius * v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(max(0.0f, _914 - _921)) - v_radius; + float _934 = fwidth(_931); + float _936 = max(_934, 9.9999999747524270787835121154785e-07f); + float _943 = 1.0f - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0f) { - _1341 = (-_1299) - sqrt(_1315); + _947 = (-_905) - sqrt(_921); } else { - _1341 = -_1299; + _947 = -_905; } - if ((_1337 <= 0.0f) || (_1341 < 0.0f)) + if ((_943 <= 0.0f) || (_947 < 0.0f)) { discard; } - float3 _1366 = _1071_camera_pos.xyz + (_1290 * _1341); - float3 _1371 = normalize(_1366 - v_center); - float _1377 = _1371.x; - float _1383 = _1371.y; - float _1390 = _1371.z; - float _1392 = ((v_rot_row0.x * _1377) + (v_rot_row1.x * _1383)) + (v_rot_row2.x * _1390); - float _1409 = ((v_rot_row0.y * _1377) + (v_rot_row1.y * _1383)) + (v_rot_row2.y * _1390); - float _1426 = ((v_rot_row0.z * _1377) + (v_rot_row1.z * _1383)) + (v_rot_row2.z * _1390); - float3 _1477 = v_base_color.xyz * ((_1409 > 0.0f) ? 1.0f : 0.64999997615814208984375f); - float3 _1487 = lerp(_1477, _1477 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, fwidth(_1392) * 1.5f, abs(_1392)), max(1.0f - smoothstep(0.0f, fwidth(_1409) * 1.5f, abs(_1409)), 1.0f - smoothstep(0.0f, fwidth(_1426) * 1.5f, abs(_1426)))).xxx); - float4 _1495 = float4(_1366, 1.0f); - float4 _1496 = mul(_1495, _1071_view_proj); - gl_FragDepth = _1496.z / _1496.w; - if (_1071_flags.x == 1) + float3 _972 = _707_camera_pos.xyz + (_896 * _947); + float3 _977 = normalize(_972 - v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((v_rot_row0.x * _983) + (v_rot_row1.x * _989)) + (v_rot_row2.x * _996); + float _1015 = ((v_rot_row0.y * _983) + (v_rot_row1.y * _989)) + (v_rot_row2.y * _996); + float _1032 = ((v_rot_row0.z * _983) + (v_rot_row1.z * _989)) + (v_rot_row2.z * _996); + float3 _1083 = v_base_color.xyz * ((_1015 > 0.0f) ? 1.0f : 0.64999997615814208984375f); + float3 _1093 = lerp(_1083, _1083 * 0.3499999940395355224609375f, max(1.0f - smoothstep(0.0f, fwidth(_998) * 1.5f, abs(_998)), max(1.0f - smoothstep(0.0f, fwidth(_1015) * 1.5f, abs(_1015)), 1.0f - smoothstep(0.0f, fwidth(_1032) * 1.5f, abs(_1032)))).xxx); + float4 _1101 = float4(_972, 1.0f); + float4 _1102 = mul(_1101, _707_view_proj); + gl_FragDepth = _1102.z / _1102.w; + if (_707_flags.x == 1) { - float _1528 = clamp(mul(_1495, _1071_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); - out_color = float4(_1528, _1528, _1528, 1.0f); + float _1134 = clamp(mul(_1101, _707_view).z * (-0.0199999995529651641845703125f), 0.0f, 1.0f); + out_color = float4(_1134, _1134, _1134, 1.0f); return; } - if (_1071_flags.x == 2) + if (_707_flags.x == 2) { - float4 param = _1071_cascade_far_view_z; - float param_1 = -mul(_1495, _1071_view).z; - int _1556 = selectShadowCascade(param, param_1); - float4 _1566 = mul(_1495, _1071_cascade_matrices[_1556]); - float3 _1573 = _1566.xyz / _1566.w.xxx; - float3 _1590 = float3((_1573.x * 0.5f) + 0.5f, ((_1573.y * _1071_shadow_params.x) * 0.5f) + 0.5f, _1573.z); - bool _1595 = any(bool3(_1590.x < 0.0f.xxx.x, _1590.y < 0.0f.xxx.y, _1590.z < 0.0f.xxx.z)); - bool _1602; - if (!_1595) + float _1155 = -mul(_1101, _707_view).z; + int cascade = 2; + if (_1155 < _707_cascade_far_view_z.x) { - _1602 = any(bool3(_1590.x > 1.0f.xxx.x, _1590.y > 1.0f.xxx.y, _1590.z > 1.0f.xxx.z)); + cascade = 0; } else { - _1602 = _1595; + if (_1155 < _707_cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1179 = mul(_1101, _707_cascade_matrices[cascade]); + float3 _1186 = _1179.xyz / _1179.w.xxx; + float3 _1203 = float3((_1186.x * 0.5f) + 0.5f, ((_1186.y * _707_cascade_far_view_z.w) * 0.5f) + 0.5f, _1186.z); + bool _1207 = any(bool3(_1203.x < 0.0f.xxx.x, _1203.y < 0.0f.xxx.y, _1203.z < 0.0f.xxx.z)); + bool _1214; + if (!_1207) + { + _1214 = any(bool3(_1203.x > 1.0f.xxx.x, _1203.y > 1.0f.xxx.y, _1203.z > 1.0f.xxx.z)); + } + else + { + _1214 = _1207; } float3 tint = 1.0f.xxx; - if (!_1602) + if (!_1214) { - int param_2 = _1556; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0f, 0.4000000059604644775390625f, 0.4000000059604644775390625f); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625f, 1.0f, 0.4000000059604644775390625f); + } + else + { + tint = float3(0.4000000059604644775390625f, 0.4000000059604644775390625f, 1.0f); + } + } } out_color = float4(tint, 1.0f); return; } - if (_1071_flags.x == 3) + if (_707_flags.x == 3) { - out_color = float4((normalize(mul(float4(_1377, _1383, _1390, 0.0f), _1071_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); + out_color = float4((normalize(mul(float4(_983, _989, _996, 0.0f), _707_view).xyz) * 0.5f) + 0.5f.xxx, 1.0f); return; } - uint _1653_dummy_parameter; - float4 _1661 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1653_dummy_parameter))), 0.0f); - float _1662 = _1661.x; - if (_1071_flags.x == 4) + uint _1276_dummy_parameter; + float4 _1284 = tex_ao.SampleLevel(smp_ao, gl_FragCoord.xy / float2(int2(spvTextureSize(tex_ao, uint(0), _1276_dummy_parameter))), 0.0f); + float _1285 = _1284.x; + if (_707_flags.x == 4) { - out_color = float4(_1662, _1662, _1662, 1.0f); + out_color = float4(_1285, _1285, _1285, 1.0f); return; } - float3 param_3 = _1366; - float3 param_4 = _1371; - float param_5 = -mul(_1495, _1071_view).z; - float3 _1710 = normalize(_1071_camera_pos.xyz - _1366); - float3 param_6 = _1371; - float3 param_7 = _1710; - float3 param_8 = normalize(_1071_sun_dir_world.xyz); - float3 param_9 = _1071_sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5); - float3 param_10 = _1487; - float param_11 = v_material.x; - float param_12 = v_material.y; - bool param_13 = _1071_ibl_params.y > 0.5f; - float3 param_14 = _1371; - float3 param_15 = _1710; - float3 param_16 = _1487; - float param_17 = v_material.x; - float param_18 = v_material.y; - float param_19 = _1071_sun_color.w; - float4 param_20[9]; - param_20[0] = _1071_sh[0]; - param_20[1] = _1071_sh[1]; - param_20[2] = _1071_sh[2]; - param_20[3] = _1071_sh[3]; - param_20[4] = _1071_sh[4]; - param_20[5] = _1071_sh[5]; - param_20[6] = _1071_sh[6]; - param_20[7] = _1071_sh[7]; - param_20[8] = _1071_sh[8]; - float param_21 = _1071_ibl_params.x; - float _1790 = v_base_color.w * _1337; - out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1662)) * _1790, _1790); + float3 param = _972; + float3 param_1 = _977; + float param_2 = -mul(_1101, _707_view).z; + float3 _1333 = normalize(_707_camera_pos.xyz - _972); + float3 param_3 = _977; + float3 param_4 = _1333; + float3 param_5 = normalize(_707_sun_dir_world.xyz); + float3 param_6 = _707_sun_color.xyz * sampleShadowCascaded(param, param_1, param_2); + float3 param_7 = _1093; + float param_8 = v_material.x; + float param_9 = v_material.y; + bool param_10 = _707_ibl_params.y > 0.5f; + float3 param_11 = _977; + float3 param_12 = _1333; + float3 param_13 = _1093; + float param_14 = v_material.x; + float param_15 = v_material.y; + float param_16 = _707_sun_color.w; + float4 param_17[9]; + param_17[0] = _707_sh[0]; + param_17[1] = _707_sh[1]; + param_17[2] = _707_sh[2]; + param_17[3] = _707_sh[3]; + param_17[4] = _707_sh[4]; + param_17[5] = _707_sh[5]; + param_17[6] = _707_sh[6]; + param_17[7] = _707_sh[7]; + param_17[8] = _707_sh[8]; + float param_18 = _707_ibl_params.x; + float _1412 = v_base_color.w * _943; + out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1285)) * _1412, _1412); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) @@ -2566,1234 +2075,960 @@ static const uint8_t sphere_vs_source_hlsl5[2863] = { return stage_output; } */ -static const uint8_t sphere_fs_source_hlsl5[19628] = { +static const uint8_t sphere_fs_source_hlsl5[15240] = { 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x20, 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x62,0x31,0x29,0x0a,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20, - 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c, - 0x61,0x67,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, - 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, - 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, - 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x78,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a, - 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x33,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62, - 0x69,0x61,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, - 0x65,0x74,0x28,0x63,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, - 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61, - 0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68, - 0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74, - 0x28,0x63,0x33,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, - 0x63,0x34,0x31,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72, - 0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20,0x72,0x65, - 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e,0x53,0x74,0x61, - 0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3a,0x20, - 0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30,0x29,0x3b,0x0a,0x54,0x65, - 0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, - 0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, - 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65,0x67, - 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, - 0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, - 0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65, - 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, - 0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, - 0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, - 0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, - 0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a, - 0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x32,0x29,0x3b,0x0a,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69, - 0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, - 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3a,0x20,0x54, - 0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f, - 0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x3a,0x20, - 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e, - 0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3a,0x20, - 0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e, - 0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, - 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x33,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x31,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x34,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52, - 0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70, - 0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, - 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45, - 0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x20,0x3a, + 0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37, + 0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x70,0x61,0x63, + 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x6e,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73, + 0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f, + 0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, + 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3a,0x20, + 0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d, + 0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31, + 0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x39,0x5d,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, + 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c, + 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66, + 0x66,0x73,0x65,0x74,0x28,0x63,0x33,0x34,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73, + 0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x30, + 0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x3a,0x20,0x72,0x65, + 0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x33,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70, + 0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20, + 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x33,0x29,0x3b,0x0a, + 0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63, + 0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x31,0x29,0x3b, + 0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x3a,0x20,0x72,0x65,0x67, + 0x69,0x73,0x74,0x65,0x72,0x28,0x73,0x31,0x29,0x3b,0x0a,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69, + 0x73,0x74,0x65,0x72,0x28,0x74,0x32,0x29,0x3b,0x0a,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x73, + 0x32,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x3b, + 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x73,0x74,0x61, + 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e, + 0x74,0x65,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x73,0x74,0x61,0x74, + 0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f, + 0x72,0x6f,0x77,0x30,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b,0x0a, + 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x73, + 0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d, + 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74, + 0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70, + 0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78, + 0x79,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69, + 0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x32,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74, + 0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, + 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, + 0x4f,0x52,0x44,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, + 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x3a,0x20,0x54,0x45, + 0x58,0x43,0x4f,0x4f,0x52,0x44,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69, 0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3a, - 0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, - 0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, - 0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, - 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, - 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72, - 0x67,0x65,0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3a,0x20,0x53, - 0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x75,0x69,0x6e, - 0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a, - 0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x4c,0x65, - 0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69,0x6e,0x74,0x20,0x50,0x61, - 0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x32, - 0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54,0x65,0x78,0x2e,0x47,0x65, - 0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73,0x28,0x4c,0x65,0x76,0x65, - 0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72,0x65,0x74,0x2e,0x79,0x2c, - 0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, - 0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x69,0x6e,0x74,0x20, - 0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x66,0x61,0x72,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b,0x20, - 0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, - 0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61, - 0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, - 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, - 0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30, - 0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37, - 0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c, - 0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31, - 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, - 0x30,0x66,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31, - 0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x2c,0x20, - 0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39,0x32, - 0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x36,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f, + 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72, + 0x69,0x61,0x6c,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44,0x37,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46, + 0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3a,0x20,0x53,0x56,0x5f,0x50,0x6f, + 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, + 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f, + 0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53, + 0x56,0x5f,0x54,0x61,0x72,0x67,0x65,0x74,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74, + 0x68,0x20,0x3a,0x20,0x53,0x56,0x5f,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x7d,0x3b, + 0x0a,0x0a,0x75,0x69,0x6e,0x74,0x32,0x20,0x73,0x70,0x76,0x54,0x65,0x78,0x74,0x75, + 0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x54,0x65,0x78,0x2c,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x6f,0x75,0x74,0x20,0x75,0x69, + 0x6e,0x74,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x75,0x69,0x6e,0x74,0x32,0x20,0x72,0x65,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x54, + 0x65,0x78,0x2e,0x47,0x65,0x74,0x44,0x69,0x6d,0x65,0x6e,0x73,0x69,0x6f,0x6e,0x73, + 0x28,0x4c,0x65,0x76,0x65,0x6c,0x2c,0x20,0x72,0x65,0x74,0x2e,0x78,0x2c,0x20,0x72, + 0x65,0x74,0x2e,0x79,0x2c,0x20,0x50,0x61,0x72,0x61,0x6d,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x74,0x3b,0x0a,0x7d,0x0a, 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, - 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65, - 0x78,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72, - 0x69,0x73,0x6f,0x6e,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x65,0x66, - 0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x74,0x65,0x78,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73, - 0x6d,0x70,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c, - 0x61,0x79,0x65,0x72,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x2e,0x78,0x79,0x7a, - 0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50, - 0x43,0x46,0x28,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x41,0x72,0x72,0x61, - 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x53, - 0x61,0x6d,0x70,0x6c,0x65,0x72,0x43,0x6f,0x6d,0x70,0x61,0x72,0x69,0x73,0x6f,0x6e, - 0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x2c,0x20,0x69,0x6e,0x74,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c, - 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62, - 0x69,0x61,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x63,0x61,0x6c,0x65, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65, - 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x31,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x32,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a, - 0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x5f,0x36,0x32,0x35,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74, - 0x5f,0x75,0x76,0x2e,0x78,0x79,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2f, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32,0x35,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e, - 0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x36,0x33,0x37,0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x78,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x78,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x34,0x20,0x3d, - 0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x29, - 0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36, - 0x33,0x30,0x20,0x2d,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20, - 0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73, - 0x69,0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x35,0x2e, - 0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x36, - 0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x36,0x32,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x66,0x20, - 0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x36,0x34,0x20,0x3d,0x20,0x5f,0x36,0x36,0x32,0x20,0x2d,0x20, - 0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x36,0x37,0x30,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x66,0x29, - 0x20,0x2d,0x20,0x5f,0x36,0x36,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x37,0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66, - 0x29,0x20,0x2d,0x20,0x5f,0x36,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x39,0x20,0x3d,0x20,0x34,0x2e,0x30,0x66,0x20, - 0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x39,0x20, - 0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x36,0x35,0x38,0x29,0x20, - 0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x39,0x20, - 0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x36,0x36,0x34,0x29, - 0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d,0x35,0x2e, - 0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36, - 0x33,0x37,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x30,0x29,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x37,0x29,0x20,0x2f, - 0x20,0x5f,0x36,0x37,0x35,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x39,0x20,0x3d,0x20, - 0x35,0x2e,0x30,0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37, - 0x30,0x39,0x20,0x2d,0x20,0x36,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x33,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30, - 0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x33,0x20, - 0x2d,0x20,0x32,0x38,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x31,0x39,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30, - 0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e, - 0x30,0x66,0x29,0x20,0x2d,0x20,0x5f,0x37,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x32,0x37,0x20,0x3d,0x20,0x34,0x2e,0x30, - 0x66,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x32, - 0x37,0x20,0x2d,0x20,0x35,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x30, - 0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x32, - 0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x66,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31, - 0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20,0x28,0x28,0x28,0x2d, - 0x35,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x66,0x20,0x2a,0x20, - 0x5f,0x36,0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2b, - 0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34,0x34,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x66,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20,0x3d, - 0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f, - 0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36, - 0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37, - 0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x34,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38, - 0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20, - 0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x34,0x36, - 0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78, - 0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x37,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x35, - 0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36, - 0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38, - 0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x66,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, - 0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38,0x36,0x20,0x3d,0x20,0x63,0x6c, - 0x61,0x6d,0x70,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20, - 0x2f,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x5d,0x2c,0x20,0x30,0x2e,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30, - 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x30,0x39,0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f, - 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c, - 0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x33,0x2e,0x30,0x66,0x20,0x2a, - 0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x66,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36, - 0x31,0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x66, - 0x29,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30, - 0x66,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x30, - 0x39,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78, - 0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63, - 0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x33,0x36,0x20,0x3d, - 0x20,0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31, - 0x32,0x38,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x33, - 0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28, - 0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20, - 0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e, - 0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, - 0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x31,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35, - 0x37,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x36,0x34, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x35,0x37, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3e,0x20, - 0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x37, + 0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x6c,0x69,0x67,0x68,0x74, + 0x5f,0x75,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x62,0x69,0x61,0x73,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x32, + 0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20, + 0x2d,0x20,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75, + 0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38, + 0x31,0x32,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x32, + 0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2b,0x20, + 0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61, + 0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20, + 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76, + 0x2e,0x78,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29, + 0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34, + 0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20, + 0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20, + 0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77, + 0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c, + 0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68, + 0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38, + 0x34,0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32, + 0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c, + 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a, + 0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x43,0x6d,0x70,0x28, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x2e,0x78,0x79,0x7a,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31,0x31,0x31,0x31,0x31, + 0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39,0x39,0x36,0x35,0x38, + 0x32,0x30,0x33,0x31,0x32,0x35,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78,0x79,0x7a, + 0x20,0x2f,0x20,0x5f,0x37,0x31,0x37,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x37,0x34,0x32,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x78,0x20, + 0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20, + 0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d,0x20,0x61, + 0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x32,0x2e,0x78,0x20, + 0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x37, + 0x34,0x32,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e, + 0x79,0x2c,0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66, + 0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x37,0x34,0x32,0x2e,0x78,0x20,0x3e,0x20, + 0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x34,0x32, + 0x2e,0x79,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c, + 0x20,0x5f,0x37,0x34,0x32,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x5f,0x31,0x31,0x36,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x31,0x37,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x30,0x35, - 0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31, - 0x37,0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x34,0x2e,0x78,0x79,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x37,0x39,0x20, - 0x3d,0x20,0x28,0x2d,0x5f,0x31,0x31,0x37,0x34,0x29,0x2e,0x78,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x38,0x32,0x20,0x3d,0x20, - 0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x31,0x37,0x36,0x2e, - 0x78,0x20,0x3c,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x31, - 0x37,0x36,0x2e,0x79,0x20,0x3c,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x79,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x39,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x38,0x32, + 0x5f,0x37,0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6c, + 0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31, + 0x38,0x39,0x39,0x38,0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31, + 0x37,0x31,0x38,0x37,0x35,0x66,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38, + 0x34,0x34,0x31,0x31,0x36,0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x66,0x2c,0x20,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x63,0x66,0x20,0x3d, + 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34, + 0x32,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x20,0x2d,0x20, + 0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x70, + 0x63,0x66,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20, + 0x70,0x63,0x66,0x2c,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x69,0x6e,0x28,0x5f, + 0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20,0x2a, + 0x20,0x31,0x30,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, + 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78, 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x39,0x30,0x20,0x3d,0x20,0x28, - 0x31,0x2e,0x30,0x66,0x20,0x2b,0x20,0x5f,0x31,0x31,0x37,0x34,0x29,0x2e,0x78,0x78, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20, - 0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x32,0x28,0x5f,0x31,0x31,0x37, - 0x36,0x2e,0x78,0x20,0x3e,0x20,0x5f,0x31,0x31,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f, - 0x31,0x31,0x37,0x36,0x2e,0x79,0x20,0x3e,0x20,0x5f,0x31,0x31,0x39,0x30,0x2e,0x79, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c, - 0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x5f,0x31,0x31,0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x32,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x31,0x39,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70, - 0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61, - 0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50, - 0x43,0x46,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, - 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, - 0x61,0x64,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x77,0x6f, - 0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32, - 0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39, - 0x20,0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x39,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32, - 0x31,0x39,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f, - 0x31,0x32,0x33,0x39,0x20,0x3d,0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69, + 0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f, - 0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39, - 0x20,0x2d,0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x32,0x35,0x32,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x2c,0x20,0x5f,0x31,0x32, - 0x33,0x39,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, - 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, - 0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x35,0x32,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72, - 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x37,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, - 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61, - 0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x29,0x2c,0x20,0x28, - 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x20, - 0x2f,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31, - 0x39,0x5d,0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73, - 0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68, - 0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f, - 0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29, - 0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2f,0x20,0x28,0x28,0x33,0x2e, - 0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33,0x32, - 0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53, - 0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x35,0x20,0x3d,0x20,0x61,0x6c,0x70, - 0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x32,0x20,0x3d,0x20,0x31,0x2e,0x30, - 0x66,0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, - 0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35, - 0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a, - 0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20, - 0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36, - 0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x29,0x20,0x2b,0x20,0x39, - 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31, - 0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38, - 0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c, - 0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f, - 0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x31,0x20,0x3d, - 0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x35,0x20, - 0x3d,0x20,0x5f,0x31,0x39,0x31,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28, - 0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x66,0x30,0x29,0x20, - 0x2a,0x20,0x28,0x28,0x5f,0x31,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x39,0x35,0x29, - 0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4c,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69, - 0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, - 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x6d,0x61,0x78, - 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, - 0x32,0x35,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56, - 0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x32,0x33,0x39,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67, - 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30, - 0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31, - 0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x33,0x39,0x20,0x2a,0x20,0x5f, - 0x32,0x33,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, - 0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38, + 0x35,0x38,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20, + 0x5f,0x38,0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30, + 0x31,0x34,0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35, + 0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20, + 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61, + 0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, + 0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x20,0x2f,0x20,0x28,0x5f,0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47, + 0x47,0x58,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68, + 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x36,0x20, + 0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30,0x37,0x20,0x2d, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x66,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37,0x20, + 0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30, + 0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x66,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, + 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, + 0x61,0x74,0x65,0x64,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39, + 0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x36, + 0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x31,0x32,0x39,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x66,0x20, + 0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73, + 0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20, + 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29, + 0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, + 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, + 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x66,0x29,0x3b,0x0a,0x7d,0x0a, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, + 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x31,0x36,0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x76,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x36,0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f, + 0x31,0x36,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20, + 0x2d,0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a, + 0x20,0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f, + 0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x2c,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x4c,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x75, + 0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38, + 0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x6d,0x61, + 0x78,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30, + 0x34,0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34, + 0x33,0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32, + 0x31,0x33,0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39, - 0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33, - 0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d, - 0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a, + 0x32,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56, + 0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37, + 0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36, + 0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70, + 0x35,0x20,0x3d,0x20,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f, + 0x31,0x39,0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, + 0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39, + 0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34, + 0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e, + 0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e, + 0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31,0x2e, + 0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x5f,0x32,0x34,0x34,0x29,0x20,0x2a, + 0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72, + 0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33, + 0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66, + 0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20, + 0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, + 0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c, + 0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74, + 0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29, + 0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29, + 0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, + 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x4e,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73, + 0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32, + 0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30, + 0x32,0x33,0x34,0x33,0x37,0x35,0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20, + 0x2b,0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, + 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, + 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a, + 0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a, + 0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31, + 0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66, + 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, + 0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39, + 0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35, + 0x37,0x38,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20, + 0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e, + 0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35, + 0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38, + 0x31,0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37, + 0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32, + 0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30, + 0x66,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78, + 0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34, + 0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x66, + 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, + 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x33,0x39, + 0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, + 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65, + 0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, + 0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78, + 0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f, + 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36,0x20,0x3d,0x20,0x63,0x6c, + 0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35, + 0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35, + 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x31,0x36,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70, 0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39, 0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e, 0x78,0x78,0x78,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32,0x37,0x30,0x20, - 0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c, - 0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x20,0x2d,0x20,0x5f,0x32,0x37,0x30,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x66, - 0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20, - 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x30,0x2e, - 0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30, - 0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20, - 0x2b,0x20,0x28,0x5f,0x32,0x37,0x30,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69, - 0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20, - 0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69, - 0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e, - 0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x31, - 0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72, - 0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69, - 0x61,0x6e,0x63,0x65,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x29,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x32,0x34,0x20,0x3d, - 0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30,0x36, - 0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37,0x35, - 0x66,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29, - 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b, - 0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36, - 0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36, - 0x38,0x37,0x35,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d, - 0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33, - 0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x66,0x29,0x20,0x2a,0x20,0x4e,0x2e, - 0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, - 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66, - 0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29, - 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, - 0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35, - 0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36, - 0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x66,0x20,0x2a,0x20,0x28, - 0x28,0x28,0x33,0x2e,0x30,0x66,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20, - 0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28, - 0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x66,0x29,0x20,0x2a, - 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, - 0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38, - 0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35,0x66,0x20,0x2a,0x20,0x28,0x28,0x4e, - 0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79, - 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32,0x34,0x3b,0x0a,0x7d,0x0a,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x49,0x62,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72, - 0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43, - 0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44, - 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, - 0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f, - 0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f, - 0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37, - 0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36, - 0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30, - 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x34,0x34,0x31,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x30,0x2e,0x30,0x33,0x39, - 0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33, - 0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x66,0x2e,0x78,0x78,0x78,0x2c,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x6d,0x65,0x74,0x61,0x6c, - 0x6c,0x69,0x63,0x2e,0x78,0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x30, - 0x35,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74, - 0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72, - 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x5f,0x34,0x33,0x31,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, - 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28, - 0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x20,0x2d,0x20,0x28, - 0x5f,0x34,0x34,0x31,0x20,0x2b,0x20,0x28,0x28,0x6d,0x61,0x78,0x28,0x28,0x31,0x2e, - 0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2e, - 0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2d,0x20,0x5f,0x34,0x34, - 0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30, - 0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x34,0x33,0x31,0x29,0x2c, - 0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30, - 0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a, - 0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x6d, - 0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68, - 0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66, - 0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x33,0x31,0x38,0x33,0x30, - 0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35, - 0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29,0x20,0x2b,0x20,0x28,0x74,0x65, - 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e,0x53,0x61,0x6d,0x70, - 0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d, - 0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d, - 0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28, - 0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f,0x35,0x30,0x35,0x2e,0x78,0x29,0x20,0x2b, - 0x20,0x5f,0x35,0x30,0x35,0x2e,0x79,0x2e,0x78,0x78,0x78,0x29,0x29,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, - 0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x62,0x6f,0x6f,0x6c, - 0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65, - 0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b, - 0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x43,0x75,0x62,0x65,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, - 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74, - 0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, - 0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74, - 0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, - 0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65, - 0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74, - 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e, - 0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61, - 0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x5b, - 0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d, - 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76, - 0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70, - 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x73,0x6d,0x70,0x5f, - 0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d, - 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e, - 0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, - 0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, - 0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65, - 0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x35,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, - 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x39, - 0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x35,0x2c,0x20,0x5f,0x31, - 0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, - 0x20,0x2a,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x31,0x35,0x20,0x3d,0x20,0x28, - 0x5f,0x31,0x32,0x39,0x39,0x20,0x2a,0x20,0x5f,0x31,0x32,0x39,0x39,0x29,0x20,0x2d, - 0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x35,0x2c,0x20,0x5f,0x31,0x32, - 0x39,0x35,0x29,0x20,0x2d,0x20,0x5f,0x31,0x33,0x30,0x38,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x35,0x20,0x3d,0x20, - 0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f, - 0x31,0x33,0x30,0x38,0x20,0x2d,0x20,0x5f,0x31,0x33,0x31,0x35,0x29,0x29,0x20,0x2d, - 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x3d,0x20,0x66,0x77,0x69, - 0x64,0x74,0x68,0x28,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x30,0x20,0x3d,0x20,0x6d,0x61, - 0x78,0x28,0x5f,0x31,0x33,0x32,0x38,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39, - 0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38,0x33, - 0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33, - 0x37,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, - 0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x33,0x33,0x30,0x2c,0x20,0x5f,0x31, - 0x33,0x33,0x30,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x34,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x31,0x35,0x20,0x3e,0x3d,0x20,0x30, - 0x2e,0x30,0x66,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x33,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x31,0x32, - 0x39,0x39,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31,0x33,0x31,0x35, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x33,0x34,0x31,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f, - 0x31,0x33,0x33,0x37,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x7c,0x7c, - 0x20,0x28,0x5f,0x31,0x33,0x34,0x31,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x29,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x64, - 0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x36,0x36,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a, - 0x20,0x5f,0x31,0x33,0x34,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x37,0x31,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d, - 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x33,0x36,0x36,0x20,0x2d,0x20,0x76,0x5f, - 0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x37,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31, - 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x33,0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x2e,0x79,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x30,0x20,0x3d, - 0x20,0x5f,0x31,0x33,0x37,0x31,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x32,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f, - 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31,0x33, - 0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, - 0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b,0x20, - 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x20,0x2a,0x20, - 0x5f,0x31,0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x34,0x30,0x39,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f, - 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x37,0x37, - 0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e, - 0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b,0x20,0x28,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31, - 0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x34,0x32,0x36,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f, - 0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x37,0x37,0x29,0x20, - 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20, - 0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72, - 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x39, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x34,0x30, - 0x39,0x20,0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x66, - 0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35, - 0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x38,0x37, - 0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x34,0x37,0x37,0x2c,0x20,0x5f, - 0x31,0x34,0x37,0x37,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39, - 0x39,0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33, - 0x37,0x35,0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, - 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c, - 0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x33,0x39,0x32,0x29,0x20,0x2a, - 0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x33,0x39,0x32, - 0x29,0x29,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73, - 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20, - 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x34,0x30,0x39,0x29,0x20,0x2a,0x20, - 0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34,0x30,0x39,0x29, - 0x29,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, - 0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66,0x77,0x69,0x64,0x74, - 0x68,0x28,0x5f,0x31,0x34,0x32,0x36,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x66,0x2c, - 0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34,0x32,0x36,0x29,0x29,0x29,0x29,0x2e,0x78, - 0x78,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x5f,0x31,0x34,0x39,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, - 0x31,0x33,0x36,0x36,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x39,0x36,0x20,0x3d,0x20, - 0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x39,0x35,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20, - 0x5f,0x31,0x34,0x39,0x36,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x34,0x39,0x36,0x2e, - 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x35,0x32,0x38,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70, - 0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x39,0x35,0x2c,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e, - 0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31, - 0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x66,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20,0x5f, - 0x31,0x35,0x32,0x38,0x2c,0x20,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20,0x31,0x2e,0x30, - 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65, - 0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x39,0x35,0x2c, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x35, - 0x36,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x35,0x36,0x36,0x20,0x3d,0x20, - 0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x39,0x35,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65, - 0x73,0x5b,0x5f,0x31,0x35,0x35,0x36,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x37,0x33,0x20, - 0x3d,0x20,0x5f,0x31,0x35,0x36,0x36,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31, - 0x35,0x36,0x36,0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x30,0x20, - 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x35,0x37,0x33,0x2e, - 0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66, - 0x2c,0x20,0x28,0x28,0x5f,0x31,0x35,0x37,0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30, - 0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x35,0x37,0x33,0x2e,0x7a,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x35,0x39, - 0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f,0x31, - 0x35,0x39,0x30,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x39,0x30,0x2e,0x79,0x20,0x3c,0x20,0x30,0x2e, - 0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x35,0x39,0x30,0x2e, - 0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x31,0x36,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x21,0x5f,0x31,0x35,0x39,0x35,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x36,0x30,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c, - 0x33,0x28,0x5f,0x31,0x35,0x39,0x30,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66, - 0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x35,0x39,0x30,0x2e,0x79,0x20, - 0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31, - 0x35,0x39,0x30,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78, - 0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x36,0x30,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20, - 0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x36,0x30,0x32,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74, - 0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20, - 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x37,0x37,0x2c,0x20,0x5f,0x31,0x33,0x38, - 0x33,0x2c,0x20,0x5f,0x31,0x33,0x39,0x30,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a, - 0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66, - 0x2e,0x78,0x78,0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x36,0x35, - 0x33,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31, - 0x36,0x36,0x31,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d, - 0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c, - 0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79, - 0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73, - 0x70,0x76,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65, - 0x78,0x5f,0x61,0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f, - 0x31,0x36,0x35,0x33,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x65,0x74,0x65,0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36,0x36,0x32,0x20, - 0x3d,0x20,0x5f,0x31,0x36,0x36,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69, - 0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78, - 0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x36,0x36,0x32,0x2c,0x20,0x5f, - 0x31,0x36,0x36,0x32,0x2c,0x20,0x5f,0x31,0x36,0x36,0x32,0x2c,0x20,0x31,0x2e,0x30, - 0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x36,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31,0x34,0x39,0x35, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x37,0x31, - 0x30,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20, - 0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31, - 0x37,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61,0x6c, - 0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x64,0x69, - 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20, - 0x5f,0x31,0x34,0x38,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, - 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x76, - 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20, - 0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f, - 0x31,0x37,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74, - 0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x5f,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f, - 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73, - 0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68, - 0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b, - 0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x35, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b, - 0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x36,0x5d, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x37, - 0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x37,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x38,0x5d, - 0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x5b,0x39, + 0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72, + 0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28, + 0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75, + 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x31,0x2e,0x30,0x66,0x2e,0x78, + 0x78,0x78,0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x6d, + 0x61,0x78,0x28,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68, + 0x6e,0x65,0x73,0x73,0x29,0x2e,0x78,0x78,0x78,0x2c,0x20,0x5f,0x34,0x31,0x36,0x29, + 0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x28,0x6d, + 0x61,0x78,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20, + 0x5f,0x34,0x30,0x36,0x29,0x2c,0x20,0x35,0x2e,0x30,0x66,0x29,0x29,0x29,0x29,0x20, + 0x2a,0x20,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, + 0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x29,0x20,0x2a,0x20,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65, + 0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29, + 0x2c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x29,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34, + 0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x66,0x2e,0x78,0x78,0x78,0x29, + 0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d, + 0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66, + 0x6c,0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x2e,0x78,0x79, + 0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36,0x20,0x2a,0x20,0x5f,0x34,0x38, + 0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x5f,0x34,0x38,0x32,0x2e,0x79,0x2e,0x78,0x78, + 0x78,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e, + 0x74,0x28,0x62,0x6f,0x6f,0x6c,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x65,0x74,0x61, + 0x6c,0x6c,0x69,0x63,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x72,0x6f,0x75,0x67, + 0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x66,0x6c,0x61, + 0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72, + 0x65,0x43,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65, + 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x53,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70, + 0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x54,0x65,0x78,0x74,0x75,0x72,0x65, + 0x32,0x44,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x53,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x5f,0x31,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x6d,0x61, + 0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73, + 0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61, + 0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, + 0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x31,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x5f,0x69,0x62,0x6c,0x5f,0x70, + 0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x35,0x5b,0x39,0x5d,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d, + 0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, + 0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x5f,0x31, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66,0x72,0x61, + 0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20,0x3d,0x20,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, + 0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x31, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70, + 0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x30, + 0x35,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x38, + 0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x39,0x31,0x34,0x20,0x3d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x2a, + 0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x31,0x20,0x3d,0x20,0x28,0x5f,0x39,0x30, + 0x35,0x20,0x2a,0x20,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74, + 0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x39,0x30,0x31,0x29,0x20,0x2d,0x20,0x5f, + 0x39,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x33,0x31,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x6d,0x61,0x78,0x28, + 0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32, + 0x31,0x29,0x29,0x20,0x2d,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d, + 0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20, + 0x6d,0x61,0x78,0x28,0x5f,0x39,0x33,0x34,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37,0x30,0x37,0x38,0x37,0x38, + 0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35,0x65,0x2d,0x30,0x37,0x66, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34, + 0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33, + 0x36,0x2c,0x20,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, + 0x20,0x28,0x5f,0x39,0x32,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30,0x66,0x29,0x0a, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39, + 0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d,0x20,0x73, + 0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x2d, + 0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34,0x33,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30, + 0x66,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39,0x34,0x37,0x20,0x3c,0x20,0x30,0x2e, + 0x30,0x66,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x37, + 0x32,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f, + 0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20, + 0x2a,0x20,0x5f,0x39,0x34,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x5f,0x39,0x37,0x37,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x76,0x5f,0x63,0x65, + 0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x78,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x39,0x20,0x3d, + 0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x7a, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x38, + 0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e, + 0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72, + 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32, + 0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x28,0x28, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, + 0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x79,0x20,0x2a,0x20, + 0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28,0x28,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20, + 0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20, + 0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f, + 0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31,0x35,0x20, + 0x3e,0x20,0x30,0x2e,0x30,0x66,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x66,0x20,0x3a, + 0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31, + 0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d, + 0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30, + 0x38,0x33,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34, + 0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35, + 0x66,0x2c,0x20,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d, + 0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e, + 0x35,0x66,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x39,0x39,0x38,0x29,0x29,0x2c,0x20, + 0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74, + 0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66,0x77,0x69,0x64, + 0x74,0x68,0x28,0x5f,0x31,0x30,0x31,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x66, + 0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31, + 0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70, + 0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x66,0x2c,0x20,0x61,0x62,0x73, + 0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29,0x29,0x2e,0x78,0x78,0x78,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x30, + 0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x37,0x32,0x2c, + 0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x20,0x5f,0x31,0x31,0x30,0x32,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28,0x5f, + 0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x70,0x72,0x6f,0x6a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e, + 0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x33, + 0x34,0x20,0x3d,0x20,0x63,0x6c,0x61,0x6d,0x70,0x28,0x6d,0x75,0x6c,0x28,0x5f,0x31, + 0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e, + 0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39, + 0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30, + 0x33,0x31,0x32,0x35,0x66,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x2c,0x20,0x31,0x2e, + 0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31, + 0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x5f,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x20,0x5f,0x31,0x31,0x35,0x35,0x20,0x3d,0x20,0x2d,0x6d,0x75,0x6c,0x28,0x5f,0x31, + 0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e, + 0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, + 0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x37,0x39,0x20,0x3d,0x20,0x6d,0x75,0x6c,0x28, + 0x5f,0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73, + 0x63,0x61,0x64,0x65,0x5d,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x38,0x36,0x20,0x3d,0x20,0x5f, + 0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x37,0x39, + 0x2e,0x77,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x30,0x33,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x78,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2c,0x20,0x28, + 0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, + 0x30,0x2e,0x35,0x66,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36,0x2e,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x32, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f,0x6c,0x33,0x28,0x5f, + 0x31,0x32,0x30,0x33,0x2e,0x78,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33,0x2e,0x79,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33, + 0x2e,0x7a,0x20,0x3c,0x20,0x30,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x7a,0x29, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, + 0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69, + 0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x62,0x6f,0x6f, + 0x6c,0x33,0x28,0x5f,0x31,0x32,0x30,0x33,0x2e,0x78,0x20,0x3e,0x20,0x31,0x2e,0x30, + 0x66,0x2e,0x78,0x78,0x78,0x2e,0x78,0x2c,0x20,0x5f,0x31,0x32,0x30,0x33,0x2e,0x79, + 0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x2e,0x79,0x2c,0x20,0x5f, + 0x31,0x32,0x30,0x33,0x2e,0x7a,0x20,0x3e,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78, + 0x78,0x2e,0x7a,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74, + 0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x2e,0x78,0x78,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x31,0x34,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e, + 0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30, + 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, + 0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x2c,0x20,0x30, + 0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34, + 0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, + 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, + 0x30,0x36,0x32,0x35,0x66,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x66,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75, + 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, + 0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37, + 0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, + 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28, + 0x28,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x6d,0x75,0x6c,0x28,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38,0x39, + 0x2c,0x20,0x5f,0x39,0x39,0x36,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x2c,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x76,0x69,0x65,0x77,0x29,0x2e,0x78,0x79,0x7a,0x29,0x20,0x2a, + 0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78, + 0x78,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32,0x37,0x36,0x5f,0x64, + 0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65,0x72,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x38,0x34, + 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65, + 0x4c,0x65,0x76,0x65,0x6c,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x73,0x70,0x76,0x54, + 0x65,0x78,0x74,0x75,0x72,0x65,0x53,0x69,0x7a,0x65,0x28,0x74,0x65,0x78,0x5f,0x61, + 0x6f,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x30,0x29,0x2c,0x20,0x5f,0x31,0x32,0x37, + 0x36,0x5f,0x64,0x75,0x6d,0x6d,0x79,0x5f,0x70,0x61,0x72,0x61,0x6d,0x65,0x74,0x65, + 0x72,0x29,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x66,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f, + 0x31,0x32,0x38,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x5f,0x37,0x30,0x37,0x5f,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, + 0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35, + 0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39,0x37,0x32,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x2d,0x6d, + 0x75,0x6c,0x28,0x5f,0x31,0x31,0x30,0x31,0x2c,0x20,0x5f,0x37,0x30,0x37,0x5f,0x76, + 0x69,0x65,0x77,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x63,0x61,0x6d,0x65,0x72,0x61, + 0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x6e,0x6f, + 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e, + 0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75,0x6e,0x5f,0x63, + 0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28, + 0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f, + 0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61, + 0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x20, + 0x3e,0x20,0x30,0x2e,0x35,0x66,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34, + 0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x35,0x20,0x3d,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c, + 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x75, + 0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x30,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x5f,0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f, + 0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68, + 0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x37, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x73,0x68,0x5b,0x38,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x5f,0x69,0x62,0x6c,0x5f,0x70, 0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x37,0x39,0x30,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x31,0x33,0x33, - 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f, - 0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36, - 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x32,0x20,0x3d,0x20,0x76,0x5f,0x62,0x61,0x73, + 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, + 0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65, + 0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61, + 0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72, 0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62, - 0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c, - 0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73, - 0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78, - 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x36,0x32,0x29,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x37,0x39,0x30,0x2c,0x20,0x5f,0x31,0x37,0x39,0x30,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74, - 0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c, - 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67, - 0x43,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20, - 0x2f,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63, - 0x65,0x6e,0x74,0x65,0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, - 0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, - 0x30,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, - 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x32,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, - 0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69, - 0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43, - 0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72, - 0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, - 0x67,0x44,0x65,0x70,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65, - 0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69, + 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a, + 0x20,0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x31,0x32, + 0x2c,0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49, + 0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20, + 0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70, + 0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61, + 0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72, + 0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f, + 0x6f,0x72,0x64,0x2e,0x77,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2f,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x77,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, + 0x74,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72, + 0x6f,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, + 0x72,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x3d,0x20, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69, + 0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20, + 0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f, + 0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x73,0x74,0x61, + 0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x6d,0x61,0x74, + 0x65,0x72,0x69,0x61,0x6c,0x20,0x3d,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e, + 0x70,0x75,0x74,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73, + 0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f, + 0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65, + 0x70,0x74,0x68,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70, + 0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75, + 0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, + 0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, }; /* #include @@ -4027,10 +3262,7 @@ static const uint8_t sphere_vs_source_metal_macos[1693] = { float4x4 view_proj; float4x4 view; float4 cascade_far_view_z; - float4 cascade_texel_world; - float4 cascade_depth_bias; - float4 shadow_params; - float4x4 cascade_matrices[4]; + float4x4 cascade_matrices[3]; float4 sh[9]; float4 ibl_params; }; @@ -4054,224 +3286,105 @@ static const uint8_t sphere_vs_source_metal_macos[1693] = { }; static inline __attribute__((always_inline)) - int selectShadowCascade(thread const float4& far_view_z, thread const float& view_z) + float sampleShadowPCF(thread const int& cascade, thread const float3& light_uv, thread const float& bias0, depth2d_array tex_shadow, sampler smp_shadow) { - int cascade = 3; - for (int i = 0; i < 3; i++) - { - if (view_z < far_view_z[i]) - { - cascade = i; - break; - } - } - return cascade; + float _529 = float(cascade); + float _534 = light_uv.z - bias0; + float _550 = light_uv.x - 0.00048828125; + float _554 = light_uv.y - 0.00048828125; + float4 _557 = float4(_550, _554, _529, _534); + float4 _573 = float4(light_uv.x, _554, _529, _534); + float _584 = light_uv.x + 0.00048828125; + float4 _591 = float4(_584, _554, _529, _534); + float4 _607 = float4(_550, light_uv.y, _529, _534); + float4 _621 = float4(light_uv.xy, _529, _534); + float4 _637 = float4(_584, light_uv.y, _529, _534); + float _652 = light_uv.y + 0.00048828125; + float4 _655 = float4(_550, _652, _529, _534); + float4 _671 = float4(light_uv.x, _652, _529, _534); + float4 _689 = float4(_584, _652, _529, _534); + return ((((((((tex_shadow.sample_compare(smp_shadow, _557.xy, uint(rint(_557.z)), _534) + tex_shadow.sample_compare(smp_shadow, _573.xy, uint(rint(_573.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _591.xy, uint(rint(_591.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _607.xy, uint(rint(_607.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _621.xy, uint(rint(_621.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _637.xy, uint(rint(_637.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _655.xy, uint(rint(_655.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _671.xy, uint(rint(_671.z)), _534)) + tex_shadow.sample_compare(smp_shadow, _689.xy, uint(rint(_689.z)), _534)) * 0.111111111938953399658203125; } static inline __attribute__((always_inline)) - float3 shadowCascadeTint(thread const int& cascade) + float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) { - if (cascade == 0) + float4 _717 = _707.cascade_matrices[cascade] * float4(world_pos, 1.0); + float3 _724 = _717.xyz / float3(_717.w); + float3 _742 = float3((_724.x * 0.5) + 0.5, ((_724.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _724.z); + bool _746 = any(_742 < float3(0.0)); + bool _753; + if (!_746) { - return float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); - } - if (cascade == 1) - { - return float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); - } - if (cascade == 2) - { - return float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); - } - return float3(1.0, 0.89999997615814208984375, 0.300000011920928955078125); - } - - static inline __attribute__((always_inline)) - float sampleShadowTap(depth2d_array tex, sampler smp, thread const float2& uv, thread const float& layer, thread const float& ref_z) - { - float4 _605 = float4(uv, layer, ref_z); - return tex.sample_compare(smp, _605.xy, uint(rint(_605.z)), ref_z); - } - - static inline __attribute__((always_inline)) - float sampleShadowPCF(depth2d_array tex, sampler smp, thread const int& cascade, thread const float3& light_uv, thread const float& bias0, thread const float& scale, thread const float& inv_size) - { - float _615 = float(cascade); - float _620 = light_uv.z - bias0; - float2 _625 = light_uv.xy * (1.0 / inv_size); - float2 _630 = floor(_625 + float2(0.5)); - float _637 = (_625.x + 0.5) - _630.x; - float _644 = (_625.y + 0.5) - _630.y; - float2 _649 = (_630 - float2(0.5)) * inv_size; - float _653 = inv_size * scale; - float _656 = 5.0 * _637; - float _658 = _656 - 6.0; - float _662 = 11.0 * _637; - float _664 = _662 - 28.0; - float _670 = (-17.0) - _662; - float _675 = (-1.0) - _656; - float _679 = 4.0 * _637; - float _683 = ((_679 - 5.0) / _658) - 3.0; - float _691 = ((_679 - 16.0) / _664) - 1.0; - float _700 = (((-5.0) - (7.0 * _637)) / _670) + 1.0; - float _706 = ((-_637) / _675) + 3.0; - float _709 = 5.0 * _644; - float _710 = _709 - 6.0; - float _713 = 11.0 * _644; - float _714 = _713 - 28.0; - float _719 = (-17.0) - _713; - float _724 = (-1.0) - _709; - float _727 = 4.0 * _644; - float _731 = ((_727 - 5.0) / _710) - 3.0; - float _738 = ((_727 - 16.0) / _714) - 1.0; - float _746 = (((-5.0) - (7.0 * _644)) / _719) + 1.0; - float _752 = ((-_644) / _724) + 3.0; - float sum = 0.0; - float2 param = _649 + (float2(_683, _731) * _653); - float param_1 = _615; - float param_2 = _620; - sum += ((_658 * _710) * sampleShadowTap(tex, smp, param, param_1, param_2)); - float2 param_3 = _649 + (float2(_691, _731) * _653); - float param_4 = _615; - float param_5 = _620; - sum += ((_664 * _710) * sampleShadowTap(tex, smp, param_3, param_4, param_5)); - float2 param_6 = _649 + (float2(_700, _731) * _653); - float param_7 = _615; - float param_8 = _620; - sum += ((_670 * _710) * sampleShadowTap(tex, smp, param_6, param_7, param_8)); - float2 param_9 = _649 + (float2(_706, _731) * _653); - float param_10 = _615; - float param_11 = _620; - sum += ((_675 * _710) * sampleShadowTap(tex, smp, param_9, param_10, param_11)); - float2 param_12 = _649 + (float2(_683, _738) * _653); - float param_13 = _615; - float param_14 = _620; - sum += ((_658 * _714) * sampleShadowTap(tex, smp, param_12, param_13, param_14)); - float2 param_15 = _649 + (float2(_691, _738) * _653); - float param_16 = _615; - float param_17 = _620; - sum += ((_664 * _714) * sampleShadowTap(tex, smp, param_15, param_16, param_17)); - float2 param_18 = _649 + (float2(_700, _738) * _653); - float param_19 = _615; - float param_20 = _620; - sum += ((_670 * _714) * sampleShadowTap(tex, smp, param_18, param_19, param_20)); - float2 param_21 = _649 + (float2(_706, _738) * _653); - float param_22 = _615; - float param_23 = _620; - sum += ((_675 * _714) * sampleShadowTap(tex, smp, param_21, param_22, param_23)); - float2 param_24 = _649 + (float2(_683, _746) * _653); - float param_25 = _615; - float param_26 = _620; - sum += ((_658 * _719) * sampleShadowTap(tex, smp, param_24, param_25, param_26)); - float2 param_27 = _649 + (float2(_691, _746) * _653); - float param_28 = _615; - float param_29 = _620; - sum += ((_664 * _719) * sampleShadowTap(tex, smp, param_27, param_28, param_29)); - float2 param_30 = _649 + (float2(_700, _746) * _653); - float param_31 = _615; - float param_32 = _620; - sum += ((_670 * _719) * sampleShadowTap(tex, smp, param_30, param_31, param_32)); - float2 param_33 = _649 + (float2(_706, _746) * _653); - float param_34 = _615; - float param_35 = _620; - sum += ((_675 * _719) * sampleShadowTap(tex, smp, param_33, param_34, param_35)); - float2 param_36 = _649 + (float2(_683, _752) * _653); - float param_37 = _615; - float param_38 = _620; - sum += ((_658 * _724) * sampleShadowTap(tex, smp, param_36, param_37, param_38)); - float2 param_39 = _649 + (float2(_691, _752) * _653); - float param_40 = _615; - float param_41 = _620; - sum += ((_664 * _724) * sampleShadowTap(tex, smp, param_39, param_40, param_41)); - float2 param_42 = _649 + (float2(_700, _752) * _653); - float param_43 = _615; - float param_44 = _620; - sum += ((_670 * _724) * sampleShadowTap(tex, smp, param_42, param_43, param_44)); - float2 param_45 = _649 + (float2(_706, _752) * _653); - float param_46 = _615; - float param_47 = _620; - float _1056 = sum; - float _1057 = _1056 + ((_675 * _724) * sampleShadowTap(tex, smp, param_45, param_46, param_47)); - sum = _1057; - return _1057 * 0.000369822490029036998748779296875; - } - - static inline __attribute__((always_inline)) - float sampleCascade(thread const int& cascade, thread const float3& world_pos, thread const float3& world_normal, constant ub_pass& _1071, depth2d_array tex_shadow, sampler smp_shadow) - { - float _1086 = fast::clamp(_1071.cascade_texel_world.x / _1071.cascade_texel_world[cascade], 0.25, 1.0); - float _1095 = fast::max(dot(world_normal, fast::normalize(_1071.sun_dir_world.xyz)), 0.0); - float _1105 = 3.0 * _1086; - float4 _1128 = _1071.cascade_matrices[cascade] * float4(world_pos + (world_normal * ((((_1105 + 0.5) * 1.41420996189117431640625) * sqrt(fast::max(1.0 - (_1095 * _1095), 0.0))) * _1071.cascade_texel_world[cascade])), 1.0); - float3 _1136 = _1128.xyz / float3(_1128.w); - float _1153 = _1136.z; - float3 _1154 = float3((_1136.x * 0.5) + 0.5, ((_1136.y * _1071.shadow_params.x) * 0.5) + 0.5, _1153); - bool _1157 = _1153 < 0.0; - bool _1164; - if (!_1157) - { - _1164 = _1153 > 1.0; + _753 = any(_742 > float3(1.0)); } else { - _1164 = _1157; + _753 = _746; } - if (_1164) - { - return 1.0; - } - float _1174 = (_1105 + 1.0) * _1071.shadow_params.y; - float2 _1176 = _1154.xy; - bool _1182 = any(_1176 < float2(-_1174)); - bool _1193; - if (!_1182) - { - _1193 = any(_1176 > float2(1.0 + _1174)); - } - else - { - _1193 = _1182; - } - if (_1193) + if (_753) { return 1.0; } int param = cascade; - float3 param_1 = _1154; - float param_2 = _1071.cascade_depth_bias[cascade]; - float param_3 = _1086; - float param_4 = _1071.shadow_params.y; - return sampleShadowPCF(tex_shadow, smp_shadow, param, param_1, param_2, param_3, param_4); + float3 param_1 = _742; + float param_2 = mix(0.0040000001899898052215576171875, 0.0007999999797903001308441162109375, fast::max(dot(world_normal, fast::normalize(_707.sun_dir_world.xyz)), 0.0)); + float pcf = sampleShadowPCF(param, param_1, param_2, tex_shadow, smp_shadow); + if (cascade == 2) + { + float2 _785 = _742.xy; + float2 _790 = fast::min(_785, float2(1.0) - _785); + pcf = mix(1.0, pcf, fast::clamp(fast::min(_790.x, _790.y) * 10.0, 0.0, 1.0)); + } + return pcf; } static inline __attribute__((always_inline)) - float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, constant ub_pass& _1071, depth2d_array tex_shadow, sampler smp_shadow) + float sampleShadowCascaded(thread const float3& world_pos, thread const float3& world_normal, thread const float& view_z, depth2d_array tex_shadow, sampler smp_shadow, constant ub_pass& _707) { - float4 param = _1071.cascade_far_view_z; - float param_1 = view_z; - int _1219 = selectShadowCascade(param, param_1); - int param_2 = _1219; - float3 param_3 = world_pos; - float3 param_4 = world_normal; - float shadow = sampleCascade(param_2, param_3, param_4, _1071, tex_shadow, smp_shadow); - if (_1219 < 3) + int cascade = 2; + if (view_z < _707.cascade_far_view_z.x) { - float _1239; - if (_1219 == 0) + cascade = 0; + } + else + { + if (view_z < _707.cascade_far_view_z.y) { - _1239 = 0.0; + cascade = 1; + } + } + int param = cascade; + float3 param_1 = world_pos; + float3 param_2 = world_normal; + float shadow = sampleCascade(param, param_1, param_2, tex_shadow, smp_shadow, _707); + if (cascade < 2) + { + float _835; + if (cascade == 0) + { + _835 = _707.cascade_far_view_z.x; } else { - _1239 = _1071.cascade_far_view_z[_1219 - 1]; + _835 = _707.cascade_far_view_z.y; } - float _1252 = mix(_1071.cascade_far_view_z[_1219], _1239, 0.100000001490116119384765625); - if (view_z > _1252) + float _847; + if (cascade == 0) { - int param_5 = _1219 + 1; - float3 param_6 = world_pos; - float3 param_7 = world_normal; - shadow = mix(shadow, sampleCascade(param_5, param_6, param_7, _1071, tex_shadow, smp_shadow), (view_z - _1252) / (_1071.cascade_far_view_z[_1219] - _1252)); + _847 = 0.0; + } + else + { + _847 = _707.cascade_far_view_z.x; + } + float _858 = mix(_835, _847, 0.100000001490116119384765625); + if (view_z > _858) + { + int param_3 = cascade + 1; + float3 param_4 = world_pos; + float3 param_5 = world_normal; + shadow = mix(shadow, sampleCascade(param_3, param_4, param_5, tex_shadow, smp_shadow, _707), (view_z - _858) / (_835 - _858)); } } return shadow; @@ -4280,61 +3393,61 @@ static const uint8_t sphere_vs_source_metal_macos[1693] = { static inline __attribute__((always_inline)) float pbrDistributionGGX(thread const float& n_dot_h, thread const float& alpha) { - float _133 = alpha * alpha; - float _142 = ((n_dot_h * n_dot_h) * (_133 - 1.0)) + 1.0; - return _133 / ((3.1415927410125732421875 * _142) * _142); + float _107 = alpha * alpha; + float _116 = ((n_dot_h * n_dot_h) * (_107 - 1.0)) + 1.0; + return _107 / ((3.1415927410125732421875 * _116) * _116); } static inline __attribute__((always_inline)) float pbrVisibilitySmithCorrelated(thread const float& n_dot_v, thread const float& n_dot_l, thread const float& alpha) { - float _155 = alpha * alpha; - float _162 = 1.0 - _155; - return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _162) + _155)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _162) + _155))) + 9.9999997473787516355514526367188e-06); + float _129 = alpha * alpha; + float _136 = 1.0 - _129; + return 0.5 / (((n_dot_l * sqrt(((n_dot_v * n_dot_v) * _136) + _129)) + (n_dot_v * sqrt(((n_dot_l * n_dot_l) * _136) + _129))) + 9.9999997473787516355514526367188e-06); } static inline __attribute__((always_inline)) float3 pbrFresnelSchlick(thread const float& v_dot_h, thread const float3& f0) { - float _191 = 1.0 - v_dot_h; - float _195 = _191 * _191; - return f0 + ((float3(1.0) - f0) * ((_195 * _195) * _191)); + float _165 = 1.0 - v_dot_h; + float _169 = _165 * _165; + return f0 + ((float3(1.0) - f0) * ((_169 * _169) * _165)); } static inline __attribute__((always_inline)) float3 brdf_evaluate(thread const float3& N, thread const float3& V, thread const float3& L, thread const float3& sun_radiance, thread const float3& base_color, thread const float& metallic, thread const float& roughness) { - float _214 = fast::max(dot(N, L), 0.0); - float3 _225 = fast::normalize(V + L); - float _239 = fast::max(roughness, 0.04500000178813934326171875); - float _243 = _239 * _239; - float param = fast::max(dot(N, _225), 0.0); - float param_1 = _243; + float _188 = fast::max(dot(N, L), 0.0); + float3 _199 = fast::normalize(V + L); + float _213 = fast::max(roughness, 0.04500000178813934326171875); + float _217 = _213 * _213; + float param = fast::max(dot(N, _199), 0.0); + float param_1 = _217; float param_2 = fast::max(dot(N, V), 9.9999997473787516355514526367188e-05); - float param_3 = _214; - float param_4 = _243; - float param_5 = fast::max(dot(V, _225), 0.0); + float param_3 = _188; + float param_4 = _217; + float param_5 = fast::max(dot(V, _199), 0.0); float3 param_6 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); - float3 _270 = pbrFresnelSchlick(param_5, param_6); - return ((((((float3(1.0) - _270) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_270 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _214; + float3 _244 = pbrFresnelSchlick(param_5, param_6); + return ((((((float3(1.0) - _244) * (1.0 - metallic)) * base_color) * float3(0.3183098733425140380859375)) + (_244 * (pbrDistributionGGX(param, param_1) * pbrVisibilitySmithCorrelated(param_2, param_3, param_4)))) * sun_radiance) * _188; } static inline __attribute__((always_inline)) float3 pbrEvaluateShIrradiance(thread const float3& N, thread const spvUnsafeArray& sh) { - float3 _424 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); - return _424; + float3 _399 = ((((((((sh[0].xyz * 0.2820948064327239990234375) + (sh[1].xyz * ((-0.48860251903533935546875) * N.y))) + (sh[2].xyz * (0.48860251903533935546875 * N.z))) + (sh[3].xyz * ((-0.48860251903533935546875) * N.x))) + (sh[4].xyz * ((1.09254848957061767578125 * N.x) * N.y))) + (sh[5].xyz * (((-1.09254848957061767578125) * N.y) * N.z))) + (sh[6].xyz * (0.3153915703296661376953125 * (((3.0 * N.z) * N.z) - 1.0)))) + (sh[7].xyz * (((-1.09254848957061767578125) * N.x) * N.z))) + (sh[8].xyz * (0.546274244785308837890625 * ((N.x * N.x) - (N.y * N.y)))); + return _399; } static inline __attribute__((always_inline)) float3 pbrEvaluateIbl(thread const float3& N_world, thread const float3& V_world, thread const float3& base_color, thread const float& metallic, thread const float& roughness, thread const spvUnsafeArray& sh, texturecube tex_spec_cube, sampler smp_spec_cube, texture2d tex_brdf_lut, sampler smp_brdf_lut, thread const float& max_lod) { - float _431 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); - float3 _441 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); + float _406 = fast::clamp(dot(N_world, V_world), 9.9999997473787516355514526367188e-05, 1.0); + float3 _416 = mix(float3(0.039999999105930328369140625), base_color, float3(metallic)); float3 param = N_world; spvUnsafeArray param_1 = sh; - float4 _505 = tex_brdf_lut.sample(smp_brdf_lut, float2(_431, roughness)); - return (((((float3(1.0) - (_441 + ((fast::max(float3(1.0 - roughness), _441) - _441) * powr(fast::max(0.0, 1.0 - _431), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_441 * _505.x) + float3(_505.y))); + float4 _482 = tex_brdf_lut.sample(smp_brdf_lut, float2(_406, roughness)); + return (((((float3(1.0) - (_416 + ((fast::max(float3(1.0 - roughness), _416) - _416) * powr(fast::max(0.0, 1.0 - _406), 5.0)))) * (1.0 - metallic)) * base_color) * fast::max(pbrEvaluateShIrradiance(param, param_1), float3(0.0))) * float3(0.3183098733425140380859375)) + (tex_spec_cube.sample(smp_spec_cube, reflect(-V_world, N_world), level(roughness * max_lod)).xyz * ((_416 * _482.x) + float3(_482.y))); } static inline __attribute__((always_inline)) @@ -4355,125 +3468,148 @@ static const uint8_t sphere_vs_source_metal_macos[1693] = { return result; } - fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _1071 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) + fragment main0_out main0(main0_in in [[stage_in]], constant ub_pass& _707 [[buffer(1)]], depth2d_array tex_shadow [[texture(0)]], texturecube tex_ibl_spec [[texture(1)]], texture2d tex_brdf_lut [[texture(2)]], texture2d tex_ao [[texture(3)]], sampler smp_shadow [[sampler(0)]], sampler smp_ibl_spec [[sampler(1)]], sampler smp_brdf_lut [[sampler(2)]], sampler smp_ao [[sampler(3)]], float4 gl_FragCoord [[position]]) { main0_out out = {}; - float3 _1290 = fast::normalize(in.v_world_pos_proxy - _1071.camera_pos.xyz); - float3 _1295 = _1071.camera_pos.xyz - in.v_center; - float _1299 = dot(_1295, _1290); - float _1308 = in.v_radius * in.v_radius; - float _1315 = (_1299 * _1299) - (dot(_1295, _1295) - _1308); - float _1325 = sqrt(fast::max(0.0, _1308 - _1315)) - in.v_radius; - float _1328 = fwidth(_1325); - float _1330 = fast::max(_1328, 9.9999999747524270787835121154785e-07); - float _1337 = 1.0 - smoothstep(-_1330, _1330, _1325); - float _1341; - if (_1315 >= 0.0) + float3 _896 = fast::normalize(in.v_world_pos_proxy - _707.camera_pos.xyz); + float3 _901 = _707.camera_pos.xyz - in.v_center; + float _905 = dot(_901, _896); + float _914 = in.v_radius * in.v_radius; + float _921 = (_905 * _905) - (dot(_901, _901) - _914); + float _931 = sqrt(fast::max(0.0, _914 - _921)) - in.v_radius; + float _934 = fwidth(_931); + float _936 = fast::max(_934, 9.9999999747524270787835121154785e-07); + float _943 = 1.0 - smoothstep(-_936, _936, _931); + float _947; + if (_921 >= 0.0) { - _1341 = (-_1299) - sqrt(_1315); + _947 = (-_905) - sqrt(_921); } else { - _1341 = -_1299; + _947 = -_905; } - if ((_1337 <= 0.0) || (_1341 < 0.0)) + if ((_943 <= 0.0) || (_947 < 0.0)) { discard_fragment(); } - float3 _1366 = _1071.camera_pos.xyz + (_1290 * _1341); - float3 _1371 = fast::normalize(_1366 - in.v_center); - float _1377 = _1371.x; - float _1383 = _1371.y; - float _1390 = _1371.z; - float _1392 = ((in.v_rot_row0.x * _1377) + (in.v_rot_row1.x * _1383)) + (in.v_rot_row2.x * _1390); - float _1409 = ((in.v_rot_row0.y * _1377) + (in.v_rot_row1.y * _1383)) + (in.v_rot_row2.y * _1390); - float _1426 = ((in.v_rot_row0.z * _1377) + (in.v_rot_row1.z * _1383)) + (in.v_rot_row2.z * _1390); - float3 _1477 = in.v_base_color.xyz * ((_1409 > 0.0) ? 1.0 : 0.64999997615814208984375); - float3 _1487 = mix(_1477, _1477 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, fwidth(_1392) * 1.5, abs(_1392)), fast::max(1.0 - smoothstep(0.0, fwidth(_1409) * 1.5, abs(_1409)), 1.0 - smoothstep(0.0, fwidth(_1426) * 1.5, abs(_1426)))))); - float4 _1495 = float4(_1366, 1.0); - float4 _1496 = _1071.view_proj * _1495; - out.gl_FragDepth = _1496.z / _1496.w; - if (_1071.flags.x == 1) + float3 _972 = _707.camera_pos.xyz + (_896 * _947); + float3 _977 = fast::normalize(_972 - in.v_center); + float _983 = _977.x; + float _989 = _977.y; + float _996 = _977.z; + float _998 = ((in.v_rot_row0.x * _983) + (in.v_rot_row1.x * _989)) + (in.v_rot_row2.x * _996); + float _1015 = ((in.v_rot_row0.y * _983) + (in.v_rot_row1.y * _989)) + (in.v_rot_row2.y * _996); + float _1032 = ((in.v_rot_row0.z * _983) + (in.v_rot_row1.z * _989)) + (in.v_rot_row2.z * _996); + float3 _1083 = in.v_base_color.xyz * ((_1015 > 0.0) ? 1.0 : 0.64999997615814208984375); + float3 _1093 = mix(_1083, _1083 * 0.3499999940395355224609375, float3(fast::max(1.0 - smoothstep(0.0, fwidth(_998) * 1.5, abs(_998)), fast::max(1.0 - smoothstep(0.0, fwidth(_1015) * 1.5, abs(_1015)), 1.0 - smoothstep(0.0, fwidth(_1032) * 1.5, abs(_1032)))))); + float4 _1101 = float4(_972, 1.0); + float4 _1102 = _707.view_proj * _1101; + out.gl_FragDepth = _1102.z / _1102.w; + if (_707.flags.x == 1) { - float _1528 = fast::clamp((_1071.view * _1495).z * (-0.0199999995529651641845703125), 0.0, 1.0); - out.out_color = float4(_1528, _1528, _1528, 1.0); + float _1134 = fast::clamp((_707.view * _1101).z * (-0.0199999995529651641845703125), 0.0, 1.0); + out.out_color = float4(_1134, _1134, _1134, 1.0); return out; } - if (_1071.flags.x == 2) + if (_707.flags.x == 2) { - float4 param = _1071.cascade_far_view_z; - float param_1 = -(_1071.view * _1495).z; - int _1556 = selectShadowCascade(param, param_1); - float4 _1566 = _1071.cascade_matrices[_1556] * _1495; - float3 _1573 = _1566.xyz / float3(_1566.w); - float3 _1590 = float3((_1573.x * 0.5) + 0.5, ((_1573.y * _1071.shadow_params.x) * 0.5) + 0.5, _1573.z); - bool _1595 = any(_1590 < float3(0.0)); - bool _1602; - if (!_1595) + float _1155 = -(_707.view * _1101).z; + int cascade = 2; + if (_1155 < _707.cascade_far_view_z.x) { - _1602 = any(_1590 > float3(1.0)); + cascade = 0; } else { - _1602 = _1595; + if (_1155 < _707.cascade_far_view_z.y) + { + cascade = 1; + } + } + float4 _1179 = _707.cascade_matrices[cascade] * _1101; + float3 _1186 = _1179.xyz / float3(_1179.w); + float3 _1203 = float3((_1186.x * 0.5) + 0.5, ((_1186.y * _707.cascade_far_view_z.w) * 0.5) + 0.5, _1186.z); + bool _1207 = any(_1203 < float3(0.0)); + bool _1214; + if (!_1207) + { + _1214 = any(_1203 > float3(1.0)); + } + else + { + _1214 = _1207; } float3 tint = float3(1.0); - if (!_1602) + if (!_1214) { - int param_2 = _1556; - tint = shadowCascadeTint(param_2); + if (cascade == 0) + { + tint = float3(1.0, 0.4000000059604644775390625, 0.4000000059604644775390625); + } + else + { + if (cascade == 1) + { + tint = float3(0.4000000059604644775390625, 1.0, 0.4000000059604644775390625); + } + else + { + tint = float3(0.4000000059604644775390625, 0.4000000059604644775390625, 1.0); + } + } } out.out_color = float4(tint, 1.0); return out; } - if (_1071.flags.x == 3) + if (_707.flags.x == 3) { - out.out_color = float4((fast::normalize((_1071.view * float4(_1377, _1383, _1390, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); + out.out_color = float4((fast::normalize((_707.view * float4(_983, _989, _996, 0.0)).xyz) * 0.5) + float3(0.5), 1.0); return out; } - float4 _1661 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); - float _1662 = _1661.x; - if (_1071.flags.x == 4) + float4 _1284 = tex_ao.sample(smp_ao, (gl_FragCoord.xy / float2(int2(tex_ao.get_width(), tex_ao.get_height()))), level(0.0)); + float _1285 = _1284.x; + if (_707.flags.x == 4) { - out.out_color = float4(_1662, _1662, _1662, 1.0); + out.out_color = float4(_1285, _1285, _1285, 1.0); return out; } - float3 param_3 = _1366; - float3 param_4 = _1371; - float param_5 = -(_1071.view * _1495).z; - float3 _1710 = fast::normalize(_1071.camera_pos.xyz - _1366); - float3 param_6 = _1371; - float3 param_7 = _1710; - float3 param_8 = fast::normalize(_1071.sun_dir_world.xyz); - float3 param_9 = _1071.sun_color.xyz * sampleShadowCascaded(param_3, param_4, param_5, _1071, tex_shadow, smp_shadow); - float3 param_10 = _1487; - float param_11 = in.v_material.x; - float param_12 = in.v_material.y; - bool param_13 = _1071.ibl_params.y > 0.5; - float3 param_14 = _1371; - float3 param_15 = _1710; - float3 param_16 = _1487; - float param_17 = in.v_material.x; - float param_18 = in.v_material.y; - float param_19 = _1071.sun_color.w; - spvUnsafeArray param_20; - param_20[0] = _1071.sh[0]; - param_20[1] = _1071.sh[1]; - param_20[2] = _1071.sh[2]; - param_20[3] = _1071.sh[3]; - param_20[4] = _1071.sh[4]; - param_20[5] = _1071.sh[5]; - param_20[6] = _1071.sh[6]; - param_20[7] = _1071.sh[7]; - param_20[8] = _1071.sh[8]; - float param_21 = _1071.ibl_params.x; - float _1790 = in.v_base_color.w * _1337; - out.out_color = float4((brdf_evaluate(param_6, param_7, param_8, param_9, param_10, param_11, param_12) + (pbrEvaluateAmbient(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_21) * _1662)) * _1790, _1790); + float3 param = _972; + float3 param_1 = _977; + float param_2 = -(_707.view * _1101).z; + float3 _1333 = fast::normalize(_707.camera_pos.xyz - _972); + float3 param_3 = _977; + float3 param_4 = _1333; + float3 param_5 = fast::normalize(_707.sun_dir_world.xyz); + float3 param_6 = _707.sun_color.xyz * sampleShadowCascaded(param, param_1, param_2, tex_shadow, smp_shadow, _707); + float3 param_7 = _1093; + float param_8 = in.v_material.x; + float param_9 = in.v_material.y; + bool param_10 = _707.ibl_params.y > 0.5; + float3 param_11 = _977; + float3 param_12 = _1333; + float3 param_13 = _1093; + float param_14 = in.v_material.x; + float param_15 = in.v_material.y; + float param_16 = _707.sun_color.w; + spvUnsafeArray param_17; + param_17[0] = _707.sh[0]; + param_17[1] = _707.sh[1]; + param_17[2] = _707.sh[2]; + param_17[3] = _707.sh[3]; + param_17[4] = _707.sh[4]; + param_17[5] = _707.sh[5]; + param_17[6] = _707.sh[6]; + param_17[7] = _707.sh[7]; + param_17[8] = _707.sh[8]; + float param_18 = _707.ibl_params.x; + float _1412 = in.v_base_color.w * _943; + out.out_color = float4((brdf_evaluate(param_3, param_4, param_5, param_6, param_7, param_8, param_9) + (pbrEvaluateAmbient(param_10, param_11, param_12, param_13, param_14, param_15, param_16, param_17, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, param_18) * _1285)) * _1412, _1412); return out; } */ -static const uint8_t sphere_fs_source_metal_macos[20716] = { +static const uint8_t sphere_fs_source_metal_macos[16701] = { 0x23,0x70,0x72,0x61,0x67,0x6d,0x61,0x20,0x63,0x6c,0x61,0x6e,0x67,0x20,0x64,0x69, 0x61,0x67,0x6e,0x6f,0x73,0x74,0x69,0x63,0x20,0x69,0x67,0x6e,0x6f,0x72,0x65,0x64, 0x20,0x22,0x2d,0x57,0x6d,0x69,0x73,0x73,0x69,0x6e,0x67,0x2d,0x70,0x72,0x6f,0x74, @@ -4549,1226 +3685,975 @@ static const uint8_t sphere_fs_source_metal_macos[20716] = { 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61, 0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64, - 0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69,0x61,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74, - 0x72,0x69,0x63,0x65,0x73,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61, - 0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b, - 0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65, - 0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70,0x74,0x68,0x28,0x61,0x6e,0x79,0x29, - 0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d, - 0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, - 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, - 0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x20,0x5b,0x5b,0x75,0x73, - 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, - 0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f, - 0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x63,0x61,0x73,0x63, + 0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x33,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x68,0x5b,0x39, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x69,0x62, + 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, + 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75,0x74,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f,0x6c,0x6f,0x72,0x28,0x30,0x29, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x5b,0x5b,0x64,0x65,0x70, + 0x74,0x68,0x28,0x61,0x6e,0x79,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73, + 0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x5b,0x5b, + 0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29, 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x20, - 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x34,0x29,0x2c,0x20,0x66, - 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75, - 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, - 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76, - 0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73, - 0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, - 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28, - 0x6c,0x6f,0x63,0x6e,0x37,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x69,0x6e,0x74,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x26,0x20,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69, - 0x65,0x77,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6f,0x72,0x20,0x28,0x69,0x6e,0x74,0x20,0x69,0x20,0x3d,0x20,0x30,0x3b, - 0x20,0x69,0x20,0x3c,0x20,0x33,0x3b,0x20,0x69,0x2b,0x2b,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77, - 0x5f,0x7a,0x5b,0x69,0x5d,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73, - 0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x69,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x72,0x65,0x61,0x6b,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, - 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, - 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, - 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63, - 0x61,0x64,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e, - 0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34, - 0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30, - 0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35, - 0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, - 0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34, - 0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e, - 0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, - 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30, - 0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39, - 0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30, - 0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32, - 0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x38,0x39,0x39,0x39,0x39,0x39,0x39,0x37, - 0x36,0x31,0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x2c, - 0x20,0x30,0x2e,0x33,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x31,0x39,0x32,0x30,0x39, - 0x32,0x38,0x39,0x35,0x35,0x30,0x37,0x38,0x31,0x32,0x35,0x29,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77, - 0x54,0x61,0x70,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, - 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x26,0x20, - 0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x30,0x35,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x28,0x75,0x76,0x2c,0x20,0x6c,0x61,0x79,0x65,0x72,0x2c,0x20, - 0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x74,0x65,0x78,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f, - 0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x2c,0x20,0x5f,0x36,0x30,0x35,0x2e, + 0x6f,0x61,0x74,0x20,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x20,0x5b,0x5b,0x75, + 0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x32,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74, + 0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, + 0x28,0x6c,0x6f,0x63,0x6e,0x33,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x31,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f, + 0x63,0x6e,0x34,0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, + 0x6f,0x77,0x32,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x35, + 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x36,0x29, + 0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x20, + 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x37,0x29,0x2c,0x20,0x66, + 0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69, + 0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69, + 0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69, + 0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61, + 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x68, + 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73, + 0x30,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x35,0x32,0x39,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x33,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68, + 0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73,0x30,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x30,0x20,0x3d, + 0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20,0x2d,0x20,0x30,0x2e, + 0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x35,0x34,0x20,0x3d,0x20,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x20,0x2d,0x20,0x30,0x2e,0x30,0x30,0x30, + 0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x35,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x34,0x28,0x5f,0x35,0x35,0x30,0x2c,0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f, + 0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x37,0x33,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c, + 0x20,0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33, + 0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35, + 0x38,0x34,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x20, + 0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x39,0x31, + 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20, + 0x5f,0x35,0x35,0x34,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x30,0x37,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35, + 0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x32,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x34,0x28,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79,0x2c, + 0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x33,0x37,0x20,0x3d,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x6c,0x69,0x67, + 0x68,0x74,0x5f,0x75,0x76,0x2e,0x79,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f, + 0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x36,0x35,0x32,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e, + 0x79,0x20,0x2b,0x20,0x30,0x2e,0x30,0x30,0x30,0x34,0x38,0x38,0x32,0x38,0x31,0x32, + 0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36, + 0x35,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x35,0x30, + 0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35, + 0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x36,0x37,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x6c,0x69, + 0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x2c,0x20,0x5f,0x36,0x35,0x32,0x2c,0x20, + 0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x36,0x38,0x39,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x35,0x38,0x34,0x2c,0x20,0x5f,0x36,0x35,0x32, + 0x2c,0x20,0x5f,0x35,0x32,0x39,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28, + 0x28,0x28,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f, + 0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x35,0x35,0x37,0x2e,0x78,0x79,0x2c, + 0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x35,0x37,0x2e, + 0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x35,0x37,0x33,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x35,0x37,0x33,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x35,0x39,0x31,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x35,0x39,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x30,0x37,0x2e, 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, - 0x30,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x72,0x65,0x66,0x5f,0x7a,0x29,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, - 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, - 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, - 0x6f,0x77,0x50,0x43,0x46,0x28,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72, - 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74,0x26,0x20,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, - 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x6c,0x69,0x67, - 0x68,0x74,0x5f,0x75,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x62,0x69,0x61,0x73,0x30, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x26,0x20,0x73,0x63,0x61,0x6c,0x65,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x69,0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x31,0x35,0x20,0x3d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x32,0x30,0x20,0x3d,0x20,0x6c, - 0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x7a,0x20,0x2d,0x20,0x62,0x69,0x61,0x73, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x36, - 0x32,0x35,0x20,0x3d,0x20,0x6c,0x69,0x67,0x68,0x74,0x5f,0x75,0x76,0x2e,0x78,0x79, - 0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2f,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x5f,0x36,0x33,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x5f,0x36,0x32, - 0x35,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x33,0x37, - 0x20,0x3d,0x20,0x28,0x5f,0x36,0x32,0x35,0x2e,0x78,0x20,0x2b,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2d,0x20,0x5f,0x36,0x33,0x30,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x34,0x34,0x20,0x3d,0x20,0x28,0x5f,0x36, - 0x32,0x35,0x2e,0x79,0x20,0x2b,0x20,0x30,0x2e,0x35,0x29,0x20,0x2d,0x20,0x5f,0x36, - 0x33,0x30,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x3d,0x20,0x28,0x5f,0x36,0x33,0x30,0x20,0x2d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x69, - 0x6e,0x76,0x5f,0x73,0x69,0x7a,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x35,0x33,0x20,0x3d,0x20,0x69,0x6e,0x76,0x5f,0x73,0x69, - 0x7a,0x65,0x20,0x2a,0x20,0x73,0x63,0x61,0x6c,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x35,0x36,0x20,0x3d,0x20,0x35,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x35,0x38,0x20,0x3d,0x20,0x5f,0x36,0x35,0x36,0x20,0x2d, - 0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x36,0x36,0x32,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36, - 0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36, - 0x36,0x34,0x20,0x3d,0x20,0x5f,0x36,0x36,0x32,0x20,0x2d,0x20,0x32,0x38,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37,0x30, - 0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x36, - 0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, - 0x35,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x36,0x35, - 0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x37, - 0x39,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x33,0x37,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x33,0x20,0x3d, - 0x20,0x28,0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x35,0x2e,0x30,0x29,0x20,0x2f, - 0x20,0x5f,0x36,0x35,0x38,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x39,0x31,0x20,0x3d,0x20,0x28, - 0x28,0x5f,0x36,0x37,0x39,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29,0x20,0x2f,0x20, - 0x5f,0x36,0x36,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x30,0x20,0x3d,0x20,0x28,0x28, - 0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30,0x20,0x2a,0x20, - 0x5f,0x36,0x33,0x37,0x29,0x29,0x20,0x2f,0x20,0x5f,0x36,0x37,0x30,0x29,0x20,0x2b, - 0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x30,0x36,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x33,0x37,0x29,0x20, - 0x2f,0x20,0x5f,0x36,0x37,0x35,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x30,0x39,0x20,0x3d,0x20, - 0x35,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x31,0x30,0x20,0x3d,0x20,0x5f,0x37,0x30, - 0x39,0x20,0x2d,0x20,0x36,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x31,0x33,0x20,0x3d,0x20,0x31,0x31,0x2e,0x30,0x20,0x2a, - 0x20,0x5f,0x36,0x34,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x31,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x33,0x20,0x2d,0x20,0x32, - 0x38,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x37,0x31,0x39,0x20,0x3d,0x20,0x28,0x2d,0x31,0x37,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20, - 0x5f,0x37,0x30,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x37,0x32,0x37,0x20,0x3d,0x20,0x34,0x2e,0x30,0x20,0x2a,0x20,0x5f,0x36,0x34, - 0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33, - 0x31,0x20,0x3d,0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x35,0x2e,0x30, - 0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2d,0x20,0x33,0x2e,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x38,0x20, - 0x3d,0x20,0x28,0x28,0x5f,0x37,0x32,0x37,0x20,0x2d,0x20,0x31,0x36,0x2e,0x30,0x29, - 0x20,0x2f,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, - 0x20,0x28,0x28,0x28,0x2d,0x35,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x37,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x36,0x34,0x34,0x29,0x29,0x20,0x2f,0x20,0x5f,0x37,0x31,0x39, - 0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x37,0x35,0x32,0x20,0x3d,0x20,0x28,0x28,0x2d,0x5f,0x36,0x34, - 0x34,0x29,0x20,0x2f,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2b,0x20,0x33,0x2e,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x75,0x6d,0x20, - 0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b, - 0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f, - 0x37,0x33,0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36, - 0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37, - 0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70, - 0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c, - 0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28, - 0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x33, - 0x31,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f, - 0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x30,0x29,0x20,0x2a,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65, - 0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x31,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x31,0x37,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x31,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x33,0x38,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x32,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d, - 0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31, - 0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x33,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x34,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20, - 0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x20,0x3d,0x20,0x5f,0x36, - 0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x36,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38, - 0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x34,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x37,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20, - 0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20, - 0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x38,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x20,0x3d,0x20,0x5f, - 0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20, - 0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70, - 0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x38,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x39,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x20,0x3d, - 0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37,0x34,0x36,0x29,0x20,0x2a,0x20,0x5f,0x36, - 0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x31,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x33,0x32,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f, - 0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61, - 0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x32,0x29,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x33,0x33,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x36,0x2c,0x20,0x5f,0x37,0x34,0x36, - 0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x20,0x3d,0x20, - 0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x35,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36, - 0x37,0x35,0x20,0x2a,0x20,0x5f,0x37,0x31,0x39,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78, - 0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x35,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x36,0x20,0x3d,0x20,0x5f,0x36,0x34, - 0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x36,0x38,0x33, - 0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x33,0x37,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x20,0x3d, - 0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b, - 0x3d,0x20,0x28,0x28,0x5f,0x36,0x35,0x38,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29, - 0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54, - 0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x33,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x37,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39, - 0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x28,0x5f,0x36,0x39,0x31,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20, - 0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x30,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x34,0x31,0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28,0x5f,0x36,0x36,0x34,0x20,0x2a, - 0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53, - 0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20,0x73,0x6d, - 0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x39,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x31,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x32,0x20,0x3d,0x20,0x5f,0x36,0x34,0x39,0x20,0x2b,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37,0x30,0x30,0x2c,0x20,0x5f,0x37, - 0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x20, - 0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x34,0x20,0x3d,0x20,0x5f,0x36,0x32, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x2b,0x3d,0x20,0x28,0x28, - 0x5f,0x36,0x37,0x30,0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73, - 0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74, - 0x65,0x78,0x2c,0x20,0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x33,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x20,0x3d,0x20,0x5f, - 0x36,0x34,0x39,0x20,0x2b,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x37, - 0x30,0x36,0x2c,0x20,0x5f,0x37,0x35,0x32,0x29,0x20,0x2a,0x20,0x5f,0x36,0x35,0x33, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x34,0x36,0x20,0x3d,0x20,0x5f,0x36,0x31,0x35,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x37, - 0x20,0x3d,0x20,0x5f,0x36,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x3d,0x20,0x73,0x75,0x6d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x35,0x37,0x20, - 0x3d,0x20,0x5f,0x31,0x30,0x35,0x36,0x20,0x2b,0x20,0x28,0x28,0x5f,0x36,0x37,0x35, - 0x20,0x2a,0x20,0x5f,0x37,0x32,0x34,0x29,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x54,0x61,0x70,0x28,0x74,0x65,0x78,0x2c,0x20, - 0x73,0x6d,0x70,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x35,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x34,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x37,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x75,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x35,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x5f,0x31,0x30,0x35,0x37,0x20,0x2a,0x20,0x30,0x2e,0x30,0x30,0x30,0x33,0x36, - 0x39,0x38,0x32,0x32,0x34,0x39,0x30,0x30,0x32,0x39,0x30,0x33,0x36,0x39,0x39,0x38, - 0x37,0x34,0x38,0x37,0x37,0x39,0x32,0x39,0x36,0x38,0x37,0x35,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f, - 0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c, - 0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69, - 0x6e,0x74,0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73, - 0x26,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64, - 0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, - 0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x38,0x36,0x20, - 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65, - 0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x20,0x2f,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74,0x65,0x78,0x65,0x6c,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x2c,0x20, - 0x30,0x2e,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x39,0x35,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c, - 0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79, - 0x7a,0x29,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x30,0x35,0x20,0x3d,0x20,0x33,0x2e,0x30, - 0x20,0x2a,0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x32,0x38,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69, - 0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x20, - 0x2b,0x20,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x20, - 0x2a,0x20,0x28,0x28,0x28,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x34,0x31,0x34,0x32,0x30,0x39,0x39,0x36,0x31, - 0x38,0x39,0x31,0x31,0x37,0x34,0x33,0x31,0x36,0x34,0x30,0x36,0x32,0x35,0x29,0x20, - 0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x28,0x5f,0x31,0x30,0x39,0x35,0x20,0x2a,0x20, - 0x5f,0x31,0x30,0x39,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x74, - 0x65,0x78,0x65,0x6c,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5b,0x63,0x61,0x73,0x63,0x61, - 0x64,0x65,0x5d,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x33,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x32,0x38,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x5f,0x31,0x31,0x32,0x38,0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x33,0x36,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x5f,0x31,0x31,0x35,0x34,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x28,0x5f,0x31,0x31,0x33,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x33,0x36, - 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x35,0x33,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x35,0x37, - 0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3c,0x20,0x30,0x2e,0x30,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x31,0x31,0x36,0x34,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x31,0x35,0x37,0x29,0x0a, - 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x33,0x20,0x3e,0x20,0x31,0x2e, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x5f,0x31,0x31,0x36,0x34,0x20,0x3d,0x20,0x5f,0x31,0x31,0x35,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31, - 0x36,0x34,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x31,0x37,0x34,0x20,0x3d,0x20,0x28,0x5f,0x31,0x31,0x30,0x35,0x20,0x2b,0x20,0x31, - 0x2e,0x30,0x29,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x31,0x31,0x37,0x36,0x20,0x3d,0x20, - 0x5f,0x31,0x31,0x35,0x34,0x2e,0x78,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, - 0x6f,0x6c,0x20,0x5f,0x31,0x31,0x38,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f, - 0x31,0x31,0x37,0x36,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x2d,0x5f, - 0x31,0x31,0x37,0x34,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x31,0x39,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x21,0x5f,0x31,0x31,0x38,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31,0x39,0x33,0x20,0x3d,0x20,0x61,0x6e, - 0x79,0x28,0x5f,0x31,0x31,0x37,0x36,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x31,0x2e,0x30,0x20,0x2b,0x20,0x5f,0x31,0x31,0x37,0x34,0x29,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x31, - 0x39,0x33,0x20,0x3d,0x20,0x5f,0x31,0x31,0x38,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x39,0x33,0x29, - 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d, - 0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d, - 0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f, - 0x31,0x31,0x35,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x64,0x65,0x70,0x74,0x68,0x5f,0x62,0x69, - 0x61,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x38,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x73,0x68,0x61,0x64,0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x61, - 0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x50,0x43,0x46,0x28,0x74,0x65, - 0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29, - 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, - 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, - 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, - 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68, - 0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2c,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72, - 0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68, - 0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x32, - 0x31,0x39,0x20,0x3d,0x20,0x73,0x65,0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f, - 0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x32,0x31, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f, - 0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43, - 0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31,0x39,0x20, - 0x3c,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x33,0x39,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x32,0x31, - 0x39,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31, - 0x32,0x33,0x39,0x20,0x3d,0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73, - 0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x32,0x33,0x39,0x20,0x3d,0x20, - 0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, - 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x20,0x2d, - 0x20,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x35,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63, - 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, - 0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x2c,0x20,0x5f,0x31,0x32,0x33,0x39,0x2c, - 0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34,0x39,0x30,0x31, - 0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x76,0x69,0x65, - 0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d, - 0x20,0x5f,0x31,0x32,0x31,0x39,0x20,0x2b,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70, - 0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, - 0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x68,0x61,0x64,0x6f, - 0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20, - 0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f, - 0x73,0x68,0x61,0x64,0x6f,0x77,0x29,0x2c,0x20,0x28,0x76,0x69,0x65,0x77,0x5f,0x7a, - 0x20,0x2d,0x20,0x5f,0x31,0x32,0x35,0x32,0x29,0x20,0x2f,0x20,0x28,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76, - 0x69,0x65,0x77,0x5f,0x7a,0x5b,0x5f,0x31,0x32,0x31,0x39,0x5d,0x20,0x2d,0x20,0x5f, - 0x31,0x32,0x35,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, - 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, - 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e, - 0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c, - 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x20,0x3d,0x20,0x61, - 0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x20,0x3d,0x20,0x28, - 0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74, - 0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x33,0x33,0x20,0x2d,0x20,0x31,0x2e, - 0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x33,0x33,0x20,0x2f,0x20,0x28,0x28,0x33, - 0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31,0x30,0x31,0x32,0x35,0x37,0x33, - 0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x34,0x32,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, - 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, - 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, - 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74, - 0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x74,0x68,0x72,0x65, - 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35, - 0x35,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70,0x68, - 0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, - 0x32,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x31,0x35,0x35,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x30,0x2e,0x35,0x20,0x2f, - 0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x73,0x71, - 0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x6e, - 0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20, - 0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x6e,0x5f,0x64,0x6f, - 0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64, - 0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x36,0x32,0x29,0x20,0x2b,0x20,0x5f,0x31,0x35,0x35,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33, - 0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33, - 0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, + 0x30,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x32,0x31,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x32,0x31,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63, + 0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x5f,0x36,0x33,0x37,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74, + 0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x33,0x37,0x2e,0x7a,0x29,0x29,0x2c,0x20, + 0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61, + 0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f, + 0x36,0x35,0x35,0x2e,0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e, + 0x74,0x28,0x5f,0x36,0x35,0x35,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34, + 0x29,0x29,0x20,0x2b,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73, + 0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x37,0x31,0x2e, + 0x78,0x79,0x2c,0x20,0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36, + 0x37,0x31,0x2e,0x7a,0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2b, + 0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2e,0x73,0x61,0x6d,0x70, + 0x6c,0x65,0x5f,0x63,0x6f,0x6d,0x70,0x61,0x72,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x5f,0x36,0x38,0x39,0x2e,0x78,0x79,0x2c,0x20, + 0x75,0x69,0x6e,0x74,0x28,0x72,0x69,0x6e,0x74,0x28,0x5f,0x36,0x38,0x39,0x2e,0x7a, + 0x29,0x29,0x2c,0x20,0x5f,0x35,0x33,0x34,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x31, + 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x39,0x33,0x38,0x39,0x35,0x33,0x33,0x39, + 0x39,0x36,0x35,0x38,0x32,0x30,0x33,0x31,0x32,0x35,0x3b,0x0a,0x7d,0x0a,0x0a,0x73, 0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61, 0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61, 0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68, - 0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x31,0x20,0x3d,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x39,0x35,0x20,0x3d,0x20,0x5f,0x31, - 0x39,0x31,0x20,0x2a,0x20,0x5f,0x31,0x39,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b,0x20,0x28,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x28,0x5f,0x31,0x39,0x35,0x20,0x2a,0x20,0x5f,0x31,0x39,0x35,0x29,0x20, - 0x2a,0x20,0x5f,0x31,0x39,0x31,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, + 0x74,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x69,0x6e,0x74, + 0x26,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x64,0x65, + 0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73, + 0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70, + 0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x37,0x31,0x37,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72, + 0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5d,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x5f,0x37,0x32,0x34,0x20,0x3d,0x20,0x5f,0x37,0x31,0x37,0x2e,0x78, + 0x79,0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x37,0x31,0x37, + 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, + 0x5f,0x37,0x34,0x32,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28,0x5f, + 0x37,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x30, + 0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x37,0x32,0x34,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29, + 0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x37,0x32,0x34,0x2e,0x7a,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x37,0x34,0x36,0x20,0x3d, + 0x20,0x61,0x6e,0x79,0x28,0x5f,0x37,0x34,0x32,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f, + 0x6f,0x6c,0x20,0x5f,0x37,0x35,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x21,0x5f,0x37,0x34,0x36,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x61,0x6e,0x79, + 0x28,0x5f,0x37,0x34,0x32,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, + 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x37,0x35,0x33,0x20,0x3d,0x20,0x5f,0x37,0x34,0x36,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x35,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x31,0x2e,0x30,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20, + 0x3d,0x20,0x5f,0x37,0x34,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x30,0x2e,0x30,0x30,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x38,0x39,0x39,0x38, + 0x39,0x38,0x30,0x35,0x32,0x32,0x31,0x35,0x35,0x37,0x36,0x31,0x37,0x31,0x38,0x37, + 0x35,0x2c,0x20,0x30,0x2e,0x30,0x30,0x30,0x37,0x39,0x39,0x39,0x39,0x39,0x39,0x37, + 0x39,0x37,0x39,0x30,0x33,0x30,0x30,0x31,0x33,0x30,0x38,0x34,0x34,0x31,0x31,0x36, + 0x32,0x31,0x30,0x39,0x33,0x37,0x35,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69, + 0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x29,0x2c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x70,0x63,0x66,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64, + 0x6f,0x77,0x50,0x43,0x46,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74, + 0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x32,0x20,0x5f,0x37,0x38,0x35,0x20,0x3d,0x20,0x5f,0x37,0x34,0x32,0x2e,0x78, + 0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x20,0x5f,0x37,0x39,0x30,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d, + 0x69,0x6e,0x28,0x5f,0x37,0x38,0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, + 0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x37,0x38,0x35,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x70,0x63,0x66,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28, + 0x31,0x2e,0x30,0x2c,0x20,0x70,0x63,0x66,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a, + 0x63,0x6c,0x61,0x6d,0x70,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x69,0x6e,0x28, + 0x5f,0x37,0x39,0x30,0x2e,0x78,0x2c,0x20,0x5f,0x37,0x39,0x30,0x2e,0x79,0x29,0x20, + 0x2a,0x20,0x31,0x30,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6e,0x20,0x70,0x63,0x66,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61, 0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74, 0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73, - 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x74, + 0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x70,0x6f,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f, + 0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76,0x69,0x65,0x77, + 0x5f,0x7a,0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61, + 0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e, + 0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37,0x30,0x37,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x20,0x3d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63, + 0x61,0x64,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3c,0x20,0x32,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x33,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d, + 0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20, + 0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x33,0x35,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61, + 0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x20,0x5f,0x38,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d, + 0x20,0x30,0x2e,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x5f,0x38,0x34,0x37,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63, + 0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f, + 0x7a,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x38,0x35, + 0x38,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x38,0x33,0x35,0x2c,0x20,0x5f,0x38, + 0x34,0x37,0x2c,0x20,0x30,0x2e,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x31,0x34, + 0x39,0x30,0x31,0x31,0x36,0x31,0x31,0x39,0x33,0x38,0x34,0x37,0x36,0x35,0x36,0x32, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, + 0x76,0x69,0x65,0x77,0x5f,0x7a,0x20,0x3e,0x20,0x5f,0x38,0x35,0x38,0x29,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33, + 0x20,0x3d,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x2b,0x20,0x31,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x77,0x6f,0x72, + 0x6c,0x64,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x35,0x20,0x3d,0x20,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x6e,0x6f,0x72,0x6d,0x61, + 0x6c,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73, + 0x68,0x61,0x64,0x6f,0x77,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x43,0x61,0x73,0x63,0x61,0x64, + 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78, + 0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61, + 0x64,0x6f,0x77,0x2c,0x20,0x5f,0x37,0x30,0x37,0x29,0x2c,0x20,0x28,0x76,0x69,0x65, + 0x77,0x5f,0x7a,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x20,0x2f,0x20,0x28,0x5f, + 0x38,0x33,0x35,0x20,0x2d,0x20,0x5f,0x38,0x35,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x68,0x61,0x64,0x6f,0x77,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69, + 0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f, + 0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, + 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x61,0x6c,0x70,0x68,0x61, + 0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x30,0x37,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20,0x2a,0x20,0x61,0x6c,0x70, + 0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, + 0x31,0x36,0x20,0x3d,0x20,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x20,0x2a, + 0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x68,0x29,0x20,0x2a,0x20,0x28,0x5f,0x31,0x30, + 0x37,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x20,0x2b,0x20,0x31,0x2e,0x30,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x31,0x30,0x37, + 0x20,0x2f,0x20,0x28,0x28,0x33,0x2e,0x31,0x34,0x31,0x35,0x39,0x32,0x37,0x34,0x31, + 0x30,0x31,0x32,0x35,0x37,0x33,0x32,0x34,0x32,0x31,0x38,0x37,0x35,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x36,0x29,0x20,0x2a,0x20,0x5f,0x31,0x31,0x36,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69, + 0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65, + 0x64,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x2c,0x20,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x2c,0x20,0x74, + 0x74,0x26,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, + 0x61,0x6c,0x70,0x68,0x61,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x32,0x39,0x20,0x3d,0x20,0x61,0x6c,0x70,0x68,0x61,0x20, + 0x2a,0x20,0x61,0x6c,0x70,0x68,0x61,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x33,0x36,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20, + 0x5f,0x31,0x32,0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, + 0x20,0x30,0x2e,0x35,0x20,0x2f,0x20,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f, + 0x6c,0x20,0x2a,0x20,0x73,0x71,0x72,0x74,0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74, + 0x5f,0x76,0x20,0x2a,0x20,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20,0x5f,0x31,0x32,0x39,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x76,0x20,0x2a,0x20,0x73,0x71,0x72,0x74, + 0x28,0x28,0x28,0x6e,0x5f,0x64,0x6f,0x74,0x5f,0x6c,0x20,0x2a,0x20,0x6e,0x5f,0x64, + 0x6f,0x74,0x5f,0x6c,0x29,0x20,0x2a,0x20,0x5f,0x31,0x33,0x36,0x29,0x20,0x2b,0x20, + 0x5f,0x31,0x32,0x39,0x29,0x29,0x29,0x20,0x2b,0x20,0x39,0x2e,0x39,0x39,0x39,0x39, + 0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35, + 0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x36,0x29, + 0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69, + 0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f, + 0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29, + 0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73, + 0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x76, + 0x5f,0x64,0x6f,0x74,0x5f,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x66,0x30,0x29, + 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x35,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x76,0x5f,0x64,0x6f,0x74,0x5f, + 0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x36, + 0x39,0x20,0x3d,0x20,0x5f,0x31,0x36,0x35,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x66,0x30,0x20,0x2b, + 0x20,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d, + 0x20,0x66,0x30,0x29,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x36,0x39,0x20,0x2a,0x20, + 0x5f,0x31,0x36,0x39,0x29,0x20,0x2a,0x20,0x5f,0x31,0x36,0x35,0x29,0x29,0x3b,0x0a, + 0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65, + 0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28, + 0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c, + 0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x26,0x20,0x4c,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x73,0x75,0x6e,0x5f, - 0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62, - 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, - 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d, - 0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75, - 0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, - 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x4c,0x29,0x2c,0x20, - 0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x5f,0x32,0x32,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20,0x2b,0x20,0x4c,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x33,0x39,0x20,0x3d, - 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x72,0x6f,0x75,0x67,0x68, - 0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34,0x35,0x30,0x30,0x30,0x30,0x30, - 0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33,0x32,0x36,0x31,0x37,0x31,0x38, - 0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x32,0x34,0x33,0x20,0x3d,0x20,0x5f,0x32,0x33,0x39,0x20,0x2a,0x20,0x5f,0x32,0x33, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64, - 0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d, + 0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x0a,0x7b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x38,0x38,0x20,0x3d, 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e, - 0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, - 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, - 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20, - 0x3d,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x32,0x34,0x33, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28, - 0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x32,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31, - 0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32, - 0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x32, - 0x37,0x30,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72,0x65,0x73,0x6e,0x65,0x6c,0x53, - 0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65, - 0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f,0x32,0x37,0x30,0x29,0x20,0x2a, - 0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63, - 0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29, - 0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33, - 0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38, - 0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x5f,0x32,0x37,0x30,0x20, - 0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74,0x72,0x69,0x62,0x75,0x74,0x69, - 0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62,0x72,0x56,0x69,0x73,0x69,0x62, - 0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68,0x43,0x6f,0x72,0x72,0x65,0x6c, - 0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x29,0x29, - 0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72,0x61,0x64,0x69,0x61,0x6e,0x63, - 0x65,0x29,0x20,0x2a,0x20,0x5f,0x32,0x31,0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74, - 0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74, - 0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79, - 0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49, - 0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x74,0x68,0x72,0x65,0x61,0x64, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73, - 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x29,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x32,0x34,0x20, - 0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x73,0x68,0x5b,0x30,0x5d,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38,0x32,0x30,0x39,0x34,0x38,0x30, - 0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39,0x30,0x32,0x33,0x34,0x33,0x37, - 0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39, - 0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20, - 0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x32, - 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x34,0x38,0x38,0x36,0x30, - 0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38, - 0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, - 0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e, - 0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33, - 0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x29, - 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, - 0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37, - 0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x20,0x2a,0x20,0x4e, - 0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b,0x20,0x28, - 0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d, - 0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31, - 0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79, - 0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68, - 0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x33,0x31,0x35, - 0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36,0x36,0x36,0x31,0x33,0x37,0x36, - 0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x28,0x33,0x2e,0x30,0x20, - 0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2d,0x20, - 0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x37,0x5d, - 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32, - 0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37, - 0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e, - 0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x38,0x5d,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34,0x36,0x32,0x37,0x34,0x32,0x34, - 0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37,0x38,0x39,0x30,0x36,0x32,0x35, - 0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20, - 0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x5f,0x34,0x32, - 0x34,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c, - 0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f, - 0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65, - 0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61, - 0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f, - 0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f, - 0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, - 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, - 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, - 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c, - 0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, - 0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65, - 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32, - 0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, - 0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, - 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x33,0x31,0x20,0x3d,0x20,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64,0x6f,0x74,0x28,0x4e,0x5f,0x77, - 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20, - 0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35, - 0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38, - 0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34,0x34,0x31,0x20,0x3d,0x20,0x6d, + 0x2c,0x20,0x4c,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x39,0x39,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x56,0x20, + 0x2b,0x20,0x4c,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x32,0x31,0x33,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x30,0x2e,0x30,0x34, + 0x35,0x30,0x30,0x30,0x30,0x30,0x31,0x37,0x38,0x38,0x31,0x33,0x39,0x33,0x34,0x33, + 0x32,0x36,0x31,0x37,0x31,0x38,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x32,0x31,0x37,0x20,0x3d,0x20,0x5f,0x32,0x31,0x33, + 0x20,0x2a,0x20,0x5f,0x32,0x31,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a, + 0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x5f,0x31,0x39,0x39, + 0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x32,0x31, + 0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x64,0x6f,0x74,0x28,0x4e,0x2c,0x20,0x56,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39, + 0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35, + 0x35,0x35,0x31,0x34,0x35,0x32,0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30, + 0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31,0x38,0x38,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20, + 0x3d,0x20,0x5f,0x32,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74, + 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x64,0x6f,0x74,0x28,0x56,0x2c,0x20,0x5f,0x31,0x39, + 0x39,0x29,0x2c,0x20,0x30,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d, 0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x33,0x39,0x39, 0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33,0x30,0x33,0x32,0x38,0x33,0x36, 0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20,0x62,0x61,0x73,0x65,0x5f,0x63, 0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x6d,0x65,0x74, 0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f, - 0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61, - 0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20, - 0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x73,0x68,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x35,0x30,0x35, - 0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2e, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x34,0x33,0x31, - 0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x28,0x5f,0x34, - 0x34,0x31,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x72,0x6f, - 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20,0x5f,0x34,0x34,0x31,0x29,0x20, - 0x2d,0x20,0x5f,0x34,0x34,0x31,0x29,0x20,0x2a,0x20,0x70,0x6f,0x77,0x72,0x28,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x5f,0x34,0x33,0x31,0x29,0x2c,0x20,0x35,0x2e,0x30,0x29,0x29, - 0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65,0x74,0x61, - 0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, - 0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x53,0x68,0x49,0x72, - 0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35, - 0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b, - 0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2e, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f, - 0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c,0x65,0x63,0x74,0x28,0x2d,0x56, - 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x29, - 0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, - 0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x29,0x2e,0x78,0x79, - 0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x34,0x31,0x20,0x2a,0x20,0x5f,0x35,0x30, - 0x35,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x35, - 0x30,0x35,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, + 0x61,0x74,0x33,0x20,0x5f,0x32,0x34,0x34,0x20,0x3d,0x20,0x70,0x62,0x72,0x46,0x72, + 0x65,0x73,0x6e,0x65,0x6c,0x53,0x63,0x68,0x6c,0x69,0x63,0x6b,0x28,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x28,0x28,0x28,0x28,0x28, + 0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x20,0x2d,0x20,0x5f, + 0x32,0x34,0x34,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x6d,0x65, + 0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62,0x61,0x73,0x65,0x5f, + 0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38,0x37,0x33,0x33,0x34,0x32,0x35,0x31, + 0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33,0x37,0x35,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x5f,0x32,0x34,0x34,0x20,0x2a,0x20,0x28,0x70,0x62,0x72,0x44,0x69,0x73,0x74, + 0x72,0x69,0x62,0x75,0x74,0x69,0x6f,0x6e,0x47,0x47,0x58,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x20,0x2a,0x20,0x70,0x62, + 0x72,0x56,0x69,0x73,0x69,0x62,0x69,0x6c,0x69,0x74,0x79,0x53,0x6d,0x69,0x74,0x68, + 0x43,0x6f,0x72,0x72,0x65,0x6c,0x61,0x74,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x34,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x73,0x75,0x6e,0x5f,0x72, + 0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x29,0x20,0x2a,0x20,0x5f,0x31,0x38,0x38,0x3b, + 0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e, + 0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28, + 0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29, + 0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, + 0x61,0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28, + 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x26,0x20,0x4e,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72, + 0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20, + 0x73,0x68,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x5f,0x33,0x39,0x39,0x20,0x3d,0x20,0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, + 0x73,0x68,0x5b,0x30,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x30,0x2e,0x32,0x38, + 0x32,0x30,0x39,0x34,0x38,0x30,0x36,0x34,0x33,0x32,0x37,0x32,0x33,0x39,0x39,0x39, + 0x30,0x32,0x33,0x34,0x33,0x37,0x35,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x31, + 0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38, + 0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34, + 0x36,0x38,0x37,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x29,0x29,0x20,0x2b, + 0x20,0x28,0x73,0x68,0x5b,0x32,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30, + 0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30,0x33,0x35,0x33,0x33,0x39, + 0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29, + 0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x33,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a, + 0x20,0x28,0x28,0x2d,0x30,0x2e,0x34,0x38,0x38,0x36,0x30,0x32,0x35,0x31,0x39,0x30, + 0x33,0x35,0x33,0x33,0x39,0x33,0x35,0x35,0x34,0x36,0x38,0x37,0x35,0x29,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x34,0x5d, + 0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x31,0x2e,0x30,0x39,0x32,0x35,0x34, + 0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31, + 0x32,0x35,0x20,0x2a,0x20,0x4e,0x2e,0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29, + 0x29,0x29,0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x35,0x5d,0x2e,0x78,0x79,0x7a,0x20, + 0x2a,0x20,0x28,0x28,0x28,0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38, + 0x39,0x35,0x37,0x30,0x36,0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29, + 0x20,0x2a,0x20,0x4e,0x2e,0x79,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x73,0x68,0x5b,0x36,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20, + 0x28,0x30,0x2e,0x33,0x31,0x35,0x33,0x39,0x31,0x35,0x37,0x30,0x33,0x32,0x39,0x36, + 0x36,0x36,0x31,0x33,0x37,0x36,0x39,0x35,0x33,0x31,0x32,0x35,0x20,0x2a,0x20,0x28, + 0x28,0x28,0x33,0x2e,0x30,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x20,0x2a,0x20,0x4e, + 0x2e,0x7a,0x29,0x20,0x2d,0x20,0x31,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2b,0x20, + 0x28,0x73,0x68,0x5b,0x37,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x28, + 0x2d,0x31,0x2e,0x30,0x39,0x32,0x35,0x34,0x38,0x34,0x38,0x39,0x35,0x37,0x30,0x36, + 0x31,0x37,0x36,0x37,0x35,0x37,0x38,0x31,0x32,0x35,0x29,0x20,0x2a,0x20,0x4e,0x2e, + 0x78,0x29,0x20,0x2a,0x20,0x4e,0x2e,0x7a,0x29,0x29,0x29,0x20,0x2b,0x20,0x28,0x73, + 0x68,0x5b,0x38,0x5d,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x30,0x2e,0x35,0x34, + 0x36,0x32,0x37,0x34,0x32,0x34,0x34,0x37,0x38,0x35,0x33,0x30,0x38,0x38,0x33,0x37, + 0x38,0x39,0x30,0x36,0x32,0x35,0x20,0x2a,0x20,0x28,0x28,0x4e,0x2e,0x78,0x20,0x2a, + 0x20,0x4e,0x2e,0x78,0x29,0x20,0x2d,0x20,0x28,0x4e,0x2e,0x79,0x20,0x2a,0x20,0x4e, + 0x2e,0x79,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, + 0x72,0x6e,0x20,0x5f,0x33,0x39,0x39,0x3b,0x0a,0x7d,0x0a,0x0a,0x73,0x74,0x61,0x74, 0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20,0x5f,0x5f,0x61,0x74,0x74,0x72, 0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61,0x6c,0x77,0x61,0x79,0x73,0x5f, 0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65, - 0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, - 0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, - 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20, - 0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68, - 0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74, + 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x74, 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72, - 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26, - 0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65, + 0x74,0x33,0x26,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72, + 0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x26,0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61, + 0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65, 0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20, - 0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x2c,0x20,0x74, - 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55, + 0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64, + 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, + 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26, + 0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73, + 0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65, + 0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74, + 0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x34,0x30,0x36, + 0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x64, + 0x6f,0x74,0x28,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x56,0x5f,0x77,0x6f, + 0x72,0x6c,0x64,0x29,0x2c,0x20,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34, + 0x37,0x33,0x37,0x38,0x37,0x35,0x31,0x36,0x33,0x35,0x35,0x35,0x31,0x34,0x35,0x32, + 0x36,0x33,0x36,0x37,0x31,0x38,0x38,0x65,0x2d,0x30,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x34, + 0x31,0x36,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28, + 0x30,0x2e,0x30,0x33,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x31,0x30,0x35,0x39,0x33, + 0x30,0x33,0x32,0x38,0x33,0x36,0x39,0x31,0x34,0x30,0x36,0x32,0x35,0x29,0x2c,0x20, + 0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2c,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20, + 0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, + 0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x20,0x5f,0x34,0x38,0x32,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64, + 0x66,0x5f,0x6c,0x75,0x74,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x32,0x28,0x5f,0x34,0x30,0x36,0x2c,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73, + 0x73,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29, + 0x20,0x2d,0x20,0x28,0x5f,0x34,0x31,0x36,0x20,0x2b,0x20,0x28,0x28,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e, + 0x30,0x20,0x2d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x29,0x2c,0x20, + 0x5f,0x34,0x31,0x36,0x29,0x20,0x2d,0x20,0x5f,0x34,0x31,0x36,0x29,0x20,0x2a,0x20, + 0x70,0x6f,0x77,0x72,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30, + 0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x34,0x30,0x36,0x29,0x2c, + 0x20,0x35,0x2e,0x30,0x29,0x29,0x29,0x29,0x20,0x2a,0x20,0x28,0x31,0x2e,0x30,0x20, + 0x2d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x29,0x29,0x20,0x2a,0x20,0x62, + 0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x29,0x20,0x2a,0x20,0x66,0x61,0x73, + 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61, + 0x74,0x65,0x53,0x68,0x49,0x72,0x72,0x61,0x64,0x69,0x61,0x6e,0x63,0x65,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x29,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30,0x29,0x29,0x29,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x33,0x31,0x38,0x33,0x30,0x39,0x38, + 0x37,0x33,0x33,0x34,0x32,0x35,0x31,0x34,0x30,0x33,0x38,0x30,0x38,0x35,0x39,0x33, + 0x37,0x35,0x29,0x29,0x20,0x2b,0x20,0x28,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, + 0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x72,0x65,0x66,0x6c, + 0x65,0x63,0x74,0x28,0x2d,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2c,0x20,0x4e,0x5f, + 0x77,0x6f,0x72,0x6c,0x64,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c,0x28,0x72,0x6f, + 0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x20,0x2a,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f, + 0x64,0x29,0x29,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x34,0x31,0x36, + 0x20,0x2a,0x20,0x5f,0x34,0x38,0x32,0x2e,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x5f,0x34,0x38,0x32,0x2e,0x79,0x29,0x29,0x29,0x3b,0x0a,0x7d, + 0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x20, + 0x5f,0x5f,0x61,0x74,0x74,0x72,0x69,0x62,0x75,0x74,0x65,0x5f,0x5f,0x28,0x28,0x61, + 0x6c,0x77,0x61,0x79,0x73,0x5f,0x69,0x6e,0x6c,0x69,0x6e,0x65,0x29,0x29,0x0a,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x74,0x68,0x72,0x65,0x61,0x64,0x20, + 0x63,0x6f,0x6e,0x73,0x74,0x20,0x62,0x6f,0x6f,0x6c,0x26,0x20,0x69,0x62,0x6c,0x45, + 0x6e,0x61,0x62,0x6c,0x65,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63, + 0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x4e,0x5f,0x77, + 0x6f,0x72,0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e, + 0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x56,0x5f,0x77,0x6f,0x72, + 0x6c,0x64,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x26,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69, + 0x63,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73, + 0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x26,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e, + 0x67,0x74,0x68,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79, + 0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c, + 0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f, + 0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62, + 0x65,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, + 0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62, + 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, + 0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74, + 0x68,0x72,0x65,0x61,0x64,0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x26,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20, + 0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66, + 0x6c,0x61,0x74,0x5f,0x73,0x74,0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64, + 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e, + 0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, + 0x20,0x56,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65, + 0x73,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55, 0x6e,0x73,0x61,0x66,0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x2c,0x20,0x39,0x3e,0x26,0x20,0x73,0x68,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75, - 0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c, - 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62, - 0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x74,0x68,0x72,0x65,0x61,0x64,0x20, - 0x63,0x6f,0x6e,0x73,0x74,0x20,0x66,0x6c,0x6f,0x61,0x74,0x26,0x20,0x6d,0x61,0x78, - 0x5f,0x6c,0x6f,0x64,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x2a,0x20,0x66,0x6c,0x61,0x74,0x5f,0x73,0x74, - 0x72,0x65,0x6e,0x67,0x74,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28, - 0x69,0x62,0x6c,0x45,0x6e,0x61,0x62,0x6c,0x65,0x64,0x29,0x0a,0x20,0x20,0x20,0x20, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x4e,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x56,0x5f,0x77,0x6f,0x72, - 0x6c,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x20,0x3d,0x20,0x62,0x61,0x73, - 0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d, - 0x20,0x6d,0x65,0x74,0x61,0x6c,0x6c,0x69,0x63,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34, - 0x20,0x3d,0x20,0x72,0x6f,0x75,0x67,0x68,0x6e,0x65,0x73,0x73,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65,0x41, - 0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x73,0x68,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f,0x6c,0x6f,0x64,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x20,0x3d,0x20, - 0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74,0x65,0x49,0x62,0x6c,0x28,0x70, - 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65, - 0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63,0x5f,0x63,0x75,0x62,0x65,0x2c, - 0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73, - 0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65,0x73,0x75,0x6c,0x74,0x3b,0x0a, - 0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e, - 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e, - 0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f, - 0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75, - 0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x31,0x30,0x37,0x31,0x20,0x5b,0x5b, - 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x64,0x65,0x70, - 0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74, - 0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20, - 0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x74, - 0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78,0x74,0x75, - 0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f, - 0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x33,0x29,0x5d, - 0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28, - 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20,0x5b,0x5b,0x73,0x61,0x6d, - 0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, - 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, - 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, - 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x20,0x5b, - 0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f, - 0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74, - 0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x30,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x69,0x6e, - 0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73,0x5f,0x70,0x72,0x6f, - 0x78,0x79,0x20,0x2d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72, - 0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x32,0x39,0x35,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e, - 0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32, - 0x39,0x39,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x31,0x32,0x39,0x35,0x2c,0x20, - 0x5f,0x31,0x32,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x33,0x30,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72, - 0x61,0x64,0x69,0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64, - 0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, - 0x31,0x33,0x31,0x35,0x20,0x3d,0x20,0x28,0x5f,0x31,0x32,0x39,0x39,0x20,0x2a,0x20, - 0x5f,0x31,0x32,0x39,0x39,0x29,0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x31, - 0x32,0x39,0x35,0x2c,0x20,0x5f,0x31,0x32,0x39,0x35,0x29,0x20,0x2d,0x20,0x5f,0x31, - 0x33,0x30,0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x33,0x32,0x35,0x20,0x3d,0x20,0x73,0x71,0x72,0x74,0x28,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30,0x2c,0x20,0x5f,0x31,0x33,0x30, - 0x38,0x20,0x2d,0x20,0x5f,0x31,0x33,0x31,0x35,0x29,0x29,0x20,0x2d,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x32,0x38,0x20,0x3d,0x20,0x66,0x77,0x69, - 0x64,0x74,0x68,0x28,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x33,0x30,0x20,0x3d,0x20,0x66,0x61, - 0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x31,0x33,0x32,0x38,0x2c,0x20,0x39, + 0x34,0x2c,0x20,0x39,0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20, + 0x73,0x68,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x20,0x3d,0x20,0x6d,0x61,0x78,0x5f, + 0x6c,0x6f,0x64,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x73, + 0x75,0x6c,0x74,0x20,0x3d,0x20,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75,0x61,0x74, + 0x65,0x49,0x62,0x6c,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x35,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x70,0x65, + 0x63,0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x70,0x65,0x63, + 0x5f,0x63,0x75,0x62,0x65,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, + 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, + 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x72,0x65, + 0x73,0x75,0x6c,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e, + 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x20,0x69,0x6e,0x20,0x5b,0x5b, + 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d,0x2c,0x20,0x63,0x6f,0x6e,0x73, + 0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x70,0x61,0x73,0x73,0x26,0x20,0x5f,0x37, + 0x30,0x37,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x64,0x65,0x70,0x74,0x68,0x32,0x64,0x5f,0x61,0x72,0x72,0x61,0x79,0x3c, + 0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64,0x6f, + 0x77,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x30,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x63,0x75,0x62,0x65,0x3c,0x66,0x6c, + 0x6f,0x61,0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65, + 0x63,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x31,0x29,0x5d,0x5d, + 0x2c,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61, + 0x74,0x3e,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75,0x74,0x20, + 0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x32,0x29,0x5d,0x5d,0x2c,0x20, + 0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e, + 0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72, + 0x65,0x28,0x33,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20, + 0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x20,0x5b,0x5b,0x73,0x61,0x6d, + 0x70,0x6c,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c, + 0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x20, + 0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20, + 0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x32, + 0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d,0x70, + 0x5f,0x61,0x6f,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28,0x33,0x29, + 0x5d,0x5d,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x46,0x72, + 0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69, + 0x6f,0x6e,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, + 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x38,0x39,0x36,0x20, + 0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a, + 0x65,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x5f,0x70,0x6f,0x73, + 0x5f,0x70,0x72,0x6f,0x78,0x79,0x20,0x2d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x30,0x31,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73, + 0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74, + 0x65,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x30,0x35,0x20,0x3d,0x20,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f, + 0x38,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69, + 0x75,0x73,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73, + 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x32,0x31, + 0x20,0x3d,0x20,0x28,0x5f,0x39,0x30,0x35,0x20,0x2a,0x20,0x5f,0x39,0x30,0x35,0x29, + 0x20,0x2d,0x20,0x28,0x64,0x6f,0x74,0x28,0x5f,0x39,0x30,0x31,0x2c,0x20,0x5f,0x39, + 0x30,0x31,0x29,0x20,0x2d,0x20,0x5f,0x39,0x31,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x31,0x20,0x3d,0x20,0x73,0x71, + 0x72,0x74,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x30,0x2e,0x30, + 0x2c,0x20,0x5f,0x39,0x31,0x34,0x20,0x2d,0x20,0x5f,0x39,0x32,0x31,0x29,0x29,0x20, + 0x2d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x61,0x64,0x69,0x75,0x73,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x34,0x20,0x3d,0x20, + 0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20, + 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x33,0x36,0x20,0x3d,0x20,0x66, + 0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78,0x28,0x5f,0x39,0x33,0x34,0x2c,0x20,0x39, 0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x37,0x34,0x37,0x35,0x32,0x34,0x32,0x37, 0x30,0x37,0x38,0x37,0x38,0x33,0x35,0x31,0x32,0x31,0x31,0x35,0x34,0x37,0x38,0x35, 0x65,0x2d,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x31,0x33,0x33,0x37,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, - 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x31,0x33,0x33,0x30, - 0x2c,0x20,0x5f,0x31,0x33,0x33,0x30,0x2c,0x20,0x5f,0x31,0x33,0x32,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x34,0x31, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x33,0x31,0x35,0x20, - 0x3e,0x3d,0x20,0x30,0x2e,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x31,0x33,0x34,0x31,0x20,0x3d,0x20,0x28,0x2d, - 0x5f,0x31,0x32,0x39,0x39,0x29,0x20,0x2d,0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x31, - 0x33,0x31,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20, - 0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x5f,0x31,0x33,0x34,0x31,0x20,0x3d,0x20,0x2d,0x5f,0x31,0x32,0x39, - 0x39,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20, - 0x28,0x28,0x5f,0x31,0x33,0x33,0x37,0x20,0x3c,0x3d,0x20,0x30,0x2e,0x30,0x29,0x20, - 0x7c,0x7c,0x20,0x28,0x5f,0x31,0x33,0x34,0x31,0x20,0x3c,0x20,0x30,0x2e,0x30,0x29, + 0x20,0x5f,0x39,0x34,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d, + 0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x2d,0x5f,0x39,0x33,0x36,0x2c,0x20, + 0x5f,0x39,0x33,0x36,0x2c,0x20,0x5f,0x39,0x33,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x34,0x37,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x39,0x32,0x31,0x20,0x3e,0x3d,0x20,0x30,0x2e,0x30, 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d,0x65,0x6e,0x74, - 0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, - 0x7a,0x20,0x2b,0x20,0x28,0x5f,0x31,0x32,0x39,0x30,0x20,0x2a,0x20,0x5f,0x31,0x33, - 0x34,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x33,0x37,0x31,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f, - 0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x33,0x36,0x36,0x20,0x2d,0x20, - 0x69,0x6e,0x2e,0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x37,0x37,0x20,0x3d,0x20, - 0x5f,0x31,0x33,0x37,0x31,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x31,0x33,0x38,0x33,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31, - 0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31, - 0x33,0x39,0x30,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x2e,0x7a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x33,0x39,0x32,0x20,0x3d, - 0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30, - 0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31,0x33,0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x69, - 0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x78,0x20,0x2a, - 0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76, - 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x31, - 0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x5f,0x31,0x34,0x30,0x39,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72, - 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x37, - 0x37,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72, - 0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x38,0x33,0x29,0x29,0x20, - 0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32, - 0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x33,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x32,0x36,0x20,0x3d,0x20,0x28, + 0x5f,0x39,0x34,0x37,0x20,0x3d,0x20,0x28,0x2d,0x5f,0x39,0x30,0x35,0x29,0x20,0x2d, + 0x20,0x73,0x71,0x72,0x74,0x28,0x5f,0x39,0x32,0x31,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x5f,0x39,0x34,0x37,0x20,0x3d, + 0x20,0x2d,0x5f,0x39,0x30,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x28,0x5f,0x39,0x34,0x33,0x20,0x3c,0x3d,0x20,0x30, + 0x2e,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28,0x5f,0x39,0x34,0x37,0x20,0x3c,0x20,0x30, + 0x2e,0x30,0x29,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x64,0x69,0x73,0x63,0x61,0x72,0x64,0x5f,0x66,0x72,0x61,0x67,0x6d, + 0x65,0x6e,0x74,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x39,0x37,0x32,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78, + 0x79,0x7a,0x20,0x2b,0x20,0x28,0x5f,0x38,0x39,0x36,0x20,0x2a,0x20,0x5f,0x39,0x34, + 0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, + 0x39,0x37,0x37,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d, + 0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x39,0x37,0x32,0x20,0x2d,0x20,0x69,0x6e,0x2e, + 0x76,0x5f,0x63,0x65,0x6e,0x74,0x65,0x72,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x38,0x33,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37, + 0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39, + 0x38,0x39,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x36,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x37,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, + 0x5f,0x39,0x39,0x38,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f, + 0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29, + 0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x31,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28, + 0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x78,0x20, + 0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x5f,0x31,0x30,0x31,0x35,0x20,0x3d,0x20,0x28,0x28,0x69,0x6e,0x2e, + 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x79,0x20,0x2a,0x20,0x5f, + 0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x31,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x38,0x39,0x29,0x29, + 0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77, + 0x32,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x30,0x33,0x32,0x20,0x3d,0x20,0x28, 0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x30,0x2e,0x7a, - 0x20,0x2a,0x20,0x5f,0x31,0x33,0x37,0x37,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e, - 0x76,0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f, - 0x31,0x33,0x38,0x33,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72, - 0x6f,0x74,0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x31,0x33,0x39, - 0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f, - 0x31,0x34,0x37,0x37,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f, - 0x31,0x34,0x30,0x39,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e, - 0x30,0x20,0x3a,0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31, - 0x35,0x38,0x31,0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x34,0x38,0x37, - 0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x34,0x37,0x37,0x2c,0x20,0x5f,0x31, - 0x34,0x37,0x37,0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39, - 0x34,0x30,0x33,0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37, - 0x35,0x2c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a, - 0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68, - 0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68, - 0x28,0x5f,0x31,0x33,0x39,0x32,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61, - 0x62,0x73,0x28,0x5f,0x31,0x33,0x39,0x32,0x29,0x29,0x2c,0x20,0x66,0x61,0x73,0x74, - 0x3a,0x3a,0x6d,0x61,0x78,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f, - 0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64, - 0x74,0x68,0x28,0x5f,0x31,0x34,0x30,0x39,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c, - 0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34,0x30,0x39,0x29,0x29,0x2c,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30, - 0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x34,0x32,0x36, - 0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x34, - 0x32,0x36,0x29,0x29,0x29,0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x39,0x35,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x5f,0x31,0x33,0x36,0x36,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x34,0x39, - 0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70, - 0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74, - 0x68,0x20,0x3d,0x20,0x5f,0x31,0x34,0x39,0x36,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31, - 0x34,0x39,0x36,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20, - 0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x35,0x32,0x38,0x20,0x3d,0x20,0x66, - 0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61,0x6d,0x70,0x28,0x28,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x29,0x2e, - 0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30,0x31,0x39,0x39,0x39,0x39,0x39,0x39, - 0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36,0x34,0x31,0x38,0x34,0x35,0x37,0x30, - 0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e,0x30,0x2c,0x20,0x31,0x2e,0x30,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75, - 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20,0x5f,0x31,0x35,0x32,0x38,0x2c,0x20,0x5f, - 0x31,0x35,0x32,0x38,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x32, - 0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, - 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d, - 0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, - 0x5f,0x31,0x34,0x39,0x35,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x69,0x6e,0x74,0x20,0x5f,0x31,0x35,0x35,0x36,0x20,0x3d,0x20,0x73,0x65, - 0x6c,0x65,0x63,0x74,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64, - 0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x35,0x36,0x36,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73, - 0x5b,0x5f,0x31,0x35,0x35,0x36,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x3b, + 0x20,0x2a,0x20,0x5f,0x39,0x38,0x33,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76, + 0x5f,0x72,0x6f,0x74,0x5f,0x72,0x6f,0x77,0x31,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39, + 0x38,0x39,0x29,0x29,0x20,0x2b,0x20,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x72,0x6f,0x74, + 0x5f,0x72,0x6f,0x77,0x32,0x2e,0x7a,0x20,0x2a,0x20,0x5f,0x39,0x39,0x36,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x38, + 0x33,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x28,0x28,0x5f,0x31,0x30,0x31, + 0x35,0x20,0x3e,0x20,0x30,0x2e,0x30,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a, + 0x20,0x30,0x2e,0x36,0x34,0x39,0x39,0x39,0x39,0x39,0x37,0x36,0x31,0x35,0x38,0x31, + 0x34,0x32,0x30,0x38,0x39,0x38,0x34,0x33,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x30,0x39,0x33,0x20,0x3d,0x20, + 0x6d,0x69,0x78,0x28,0x5f,0x31,0x30,0x38,0x33,0x2c,0x20,0x5f,0x31,0x30,0x38,0x33, + 0x20,0x2a,0x20,0x30,0x2e,0x33,0x34,0x39,0x39,0x39,0x39,0x39,0x39,0x34,0x30,0x33, + 0x39,0x35,0x33,0x35,0x35,0x32,0x32,0x34,0x36,0x30,0x39,0x33,0x37,0x35,0x2c,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, + 0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x39, + 0x39,0x38,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f, + 0x39,0x39,0x38,0x29,0x29,0x2c,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6d,0x61,0x78, + 0x28,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65, + 0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66,0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31, + 0x30,0x31,0x35,0x29,0x20,0x2a,0x20,0x31,0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28, + 0x5f,0x31,0x30,0x31,0x35,0x29,0x29,0x2c,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x73, + 0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20,0x66, + 0x77,0x69,0x64,0x74,0x68,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x20,0x2a,0x20,0x31, + 0x2e,0x35,0x2c,0x20,0x61,0x62,0x73,0x28,0x5f,0x31,0x30,0x33,0x32,0x29,0x29,0x29, + 0x29,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, + 0x5f,0x31,0x31,0x30,0x31,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f, + 0x39,0x37,0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31,0x30,0x32,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x2a,0x20,0x5f, + 0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c, + 0x5f,0x46,0x72,0x61,0x67,0x44,0x65,0x70,0x74,0x68,0x20,0x3d,0x20,0x5f,0x31,0x31, + 0x30,0x32,0x2e,0x7a,0x20,0x2f,0x20,0x5f,0x31,0x31,0x30,0x32,0x2e,0x77,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61, + 0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f, + 0x31,0x31,0x33,0x34,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x63,0x6c,0x61, + 0x6d,0x70,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, + 0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x20,0x2a,0x20,0x28,0x2d,0x30,0x2e,0x30, + 0x31,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x35,0x35,0x32,0x39,0x36,0x35,0x31,0x36, + 0x34,0x31,0x38,0x34,0x35,0x37,0x30,0x33,0x31,0x32,0x35,0x29,0x2c,0x20,0x30,0x2e, + 0x30,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x5f, + 0x31,0x31,0x33,0x34,0x2c,0x20,0x5f,0x31,0x31,0x33,0x34,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72, + 0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e, + 0x78,0x20,0x3d,0x3d,0x20,0x32,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x31,0x35, + 0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20, + 0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20, + 0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20, + 0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61, + 0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a, + 0x2e,0x78,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x20,0x3d,0x20,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x31,0x35,0x35,0x20,0x3c,0x20, + 0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66,0x61,0x72, + 0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x79,0x29,0x0a,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x63,0x61,0x73,0x63,0x61,0x64,0x65, + 0x20,0x3d,0x20,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x31, + 0x37,0x39,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64, + 0x65,0x5f,0x6d,0x61,0x74,0x72,0x69,0x63,0x65,0x73,0x5b,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x5d,0x20,0x2a,0x20,0x5f,0x31,0x31,0x30,0x31,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x31,0x38, + 0x36,0x20,0x3d,0x20,0x5f,0x31,0x31,0x37,0x39,0x2e,0x78,0x79,0x7a,0x20,0x2f,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x31,0x37,0x39,0x2e,0x77,0x29,0x3b, 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x5f,0x31,0x35,0x37,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x36,0x36,0x2e,0x78,0x79, - 0x7a,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x5f,0x31,0x35,0x36,0x36, - 0x2e,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x5f,0x31,0x35,0x39,0x30,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x28,0x28,0x5f,0x31,0x35,0x37,0x33,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x35,0x37, - 0x33,0x2e,0x79,0x20,0x2a,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x61,0x64, - 0x6f,0x77,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x29,0x20,0x2a,0x20,0x30, - 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x35,0x37,0x33, + 0x5f,0x31,0x32,0x30,0x33,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x28, + 0x5f,0x31,0x31,0x38,0x36,0x2e,0x78,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, + 0x20,0x30,0x2e,0x35,0x2c,0x20,0x28,0x28,0x5f,0x31,0x31,0x38,0x36,0x2e,0x79,0x20, + 0x2a,0x20,0x5f,0x37,0x30,0x37,0x2e,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x5f,0x66, + 0x61,0x72,0x5f,0x76,0x69,0x65,0x77,0x5f,0x7a,0x2e,0x77,0x29,0x20,0x2a,0x20,0x30, + 0x2e,0x35,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x2c,0x20,0x5f,0x31,0x31,0x38,0x36, 0x2e,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f, - 0x6c,0x20,0x5f,0x31,0x35,0x39,0x35,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, - 0x35,0x39,0x30,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30, + 0x6c,0x20,0x5f,0x31,0x32,0x30,0x37,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, + 0x32,0x30,0x33,0x20,0x3c,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x30, 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x31,0x36,0x30,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x35,0x39,0x35,0x29,0x0a,0x20,0x20,0x20,0x20, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x30,0x37,0x29,0x0a,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x5f,0x31,0x36,0x30,0x32,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, - 0x35,0x39,0x30,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, + 0x20,0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x61,0x6e,0x79,0x28,0x5f,0x31, + 0x32,0x30,0x33,0x20,0x3e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30, 0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, - 0x20,0x5f,0x31,0x36,0x30,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x39,0x35,0x3b,0x0a, + 0x20,0x5f,0x31,0x32,0x31,0x34,0x20,0x3d,0x20,0x5f,0x31,0x32,0x30,0x37,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20, 0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x36,0x30,0x32,0x29, + 0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x21,0x5f,0x31,0x32,0x31,0x34,0x29, 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x6e,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x20,0x3d,0x20,0x5f,0x31,0x35,0x35,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x73, - 0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x54,0x69,0x6e,0x74, - 0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61, + 0x64,0x65,0x20,0x3d,0x3d,0x20,0x30,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x28,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30, + 0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36, + 0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65, + 0x6c,0x73,0x65,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x69,0x66,0x20,0x28,0x63,0x61,0x73,0x63,0x61,0x64,0x65,0x20,0x3d,0x3d, + 0x20,0x31,0x29,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30, + 0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30, + 0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30,0x2c,0x20,0x30,0x2e,0x34,0x30,0x30,0x30, + 0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33, + 0x39,0x30,0x36,0x32,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x65,0x6c,0x73,0x65,0x0a,0x20, + 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x74,0x69,0x6e,0x74,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x33,0x28,0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36, + 0x30,0x34,0x36,0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20, + 0x30,0x2e,0x34,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x35,0x39,0x36,0x30,0x34,0x36, + 0x34,0x34,0x37,0x37,0x35,0x33,0x39,0x30,0x36,0x32,0x35,0x2c,0x20,0x31,0x2e,0x30, + 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20, + 0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x74,0x69,0x6e,0x74, + 0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20, + 0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, + 0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37,0x30,0x37,0x2e,0x66, + 0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20, + 0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f, + 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x34,0x28,0x28,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69, + 0x7a,0x65,0x28,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20, + 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x39,0x38,0x33,0x2c,0x20,0x5f,0x39,0x38, + 0x39,0x2c,0x20,0x5f,0x39,0x39,0x36,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78, + 0x79,0x7a,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x33,0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f, - 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x69,0x66, - 0x20,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20, - 0x3d,0x3d,0x20,0x33,0x29,0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x66,0x61,0x73,0x74, - 0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x28,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x28,0x5f,0x31,0x33,0x37,0x37,0x2c,0x20,0x5f,0x31,0x33,0x38,0x33,0x2c,0x20,0x5f, - 0x31,0x33,0x39,0x30,0x2c,0x20,0x30,0x2e,0x30,0x29,0x29,0x2e,0x78,0x79,0x7a,0x29, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x28,0x30,0x2e,0x35,0x29,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x31,0x36,0x36,0x31,0x20,0x3d,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f, - 0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61,0x6f,0x2c,0x20, - 0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79, - 0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74,0x32,0x28,0x74, - 0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64,0x74,0x68,0x28, - 0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x68,0x65, - 0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65,0x76,0x65,0x6c, - 0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x20,0x5f,0x31,0x36,0x36,0x32,0x20,0x3d,0x20,0x5f,0x31,0x36,0x36,0x31,0x2e, - 0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29,0x0a,0x20, - 0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x5f,0x31,0x36,0x36,0x32,0x2c,0x20,0x5f,0x31,0x36,0x36,0x32, - 0x2c,0x20,0x5f,0x31,0x36,0x36,0x32,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75, - 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20,0x5f,0x31, - 0x33,0x36,0x36,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x35,0x20,0x3d,0x20,0x2d,0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x76,0x69,0x65, - 0x77,0x20,0x2a,0x20,0x5f,0x31,0x34,0x39,0x35,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x37,0x31,0x30,0x20,0x3d, - 0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65, - 0x28,0x5f,0x31,0x30,0x37,0x31,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f, - 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2d,0x20,0x5f,0x31,0x33,0x36,0x36,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x36,0x20,0x3d,0x20,0x5f,0x31,0x33,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d, - 0x20,0x5f,0x31,0x37,0x31,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x66,0x61,0x73, - 0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64, - 0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61, - 0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, - 0x2c,0x20,0x5f,0x31,0x30,0x37,0x31,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61, - 0x64,0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x29, + 0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x34,0x20,0x5f,0x31,0x32,0x38,0x34,0x20,0x3d,0x20,0x74,0x65,0x78, + 0x5f,0x61,0x6f,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70,0x5f,0x61, + 0x6f,0x2c,0x20,0x28,0x67,0x6c,0x5f,0x46,0x72,0x61,0x67,0x43,0x6f,0x6f,0x72,0x64, + 0x2e,0x78,0x79,0x20,0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x69,0x6e,0x74, + 0x32,0x28,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74,0x5f,0x77,0x69,0x64, + 0x74,0x68,0x28,0x29,0x2c,0x20,0x74,0x65,0x78,0x5f,0x61,0x6f,0x2e,0x67,0x65,0x74, + 0x5f,0x68,0x65,0x69,0x67,0x68,0x74,0x28,0x29,0x29,0x29,0x29,0x2c,0x20,0x6c,0x65, + 0x76,0x65,0x6c,0x28,0x30,0x2e,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x32,0x38,0x35,0x20,0x3d,0x20,0x5f,0x31,0x32, + 0x38,0x34,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x69,0x66,0x20,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x66,0x6c,0x61,0x67,0x73,0x2e,0x78,0x20,0x3d,0x3d,0x20,0x34,0x29, + 0x0a,0x20,0x20,0x20,0x20,0x7b,0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x6f, + 0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x5f,0x31,0x32, + 0x38,0x35,0x2c,0x20,0x5f,0x31,0x32,0x38,0x35,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20, + 0x6f,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x7d,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x20,0x3d,0x20,0x5f,0x39, + 0x37,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x20,0x3d,0x20,0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, + 0x20,0x3d,0x20,0x2d,0x28,0x5f,0x37,0x30,0x37,0x2e,0x76,0x69,0x65,0x77,0x20,0x2a, + 0x20,0x5f,0x31,0x31,0x30,0x31,0x29,0x2e,0x7a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x5f,0x31,0x33,0x33,0x33,0x20,0x3d,0x20,0x66,0x61, + 0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72,0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37, + 0x30,0x37,0x2e,0x63,0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x2e,0x78,0x79, + 0x7a,0x20,0x2d,0x20,0x5f,0x39,0x37,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, + 0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x20,0x3d,0x20, + 0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33,0x33, 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x37,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x31,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, - 0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d, - 0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f, - 0x31,0x30,0x37,0x31,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e, - 0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x20,0x3d,0x20,0x5f, - 0x31,0x33,0x37,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x5f,0x31,0x37,0x31, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d,0x20,0x5f,0x31,0x34,0x38,0x37,0x3b,0x0a, + 0x61,0x6d,0x5f,0x35,0x20,0x3d,0x20,0x66,0x61,0x73,0x74,0x3a,0x3a,0x6e,0x6f,0x72, + 0x6d,0x61,0x6c,0x69,0x7a,0x65,0x28,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f, + 0x64,0x69,0x72,0x5f,0x77,0x6f,0x72,0x6c,0x64,0x2e,0x78,0x79,0x7a,0x29,0x3b,0x0a, + 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x36,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f, + 0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65, + 0x53,0x68,0x61,0x64,0x6f,0x77,0x43,0x61,0x73,0x63,0x61,0x64,0x65,0x64,0x28,0x70, + 0x61,0x72,0x61,0x6d,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x2c,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x32,0x2c,0x20,0x74,0x65,0x78,0x5f,0x73,0x68,0x61,0x64, + 0x6f,0x77,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x73,0x68,0x61,0x64,0x6f,0x77,0x2c,0x20, + 0x5f,0x37,0x30,0x37,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, + 0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x37,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65, + 0x72,0x69,0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, + 0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x39,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76, + 0x5f,0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x62,0x6f,0x6f,0x6c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, + 0x2e,0x79,0x20,0x3e,0x20,0x30,0x2e,0x35,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, + 0x6f,0x61,0x74,0x33,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x20,0x3d,0x20, + 0x5f,0x39,0x37,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x20,0x3d,0x20,0x5f,0x31,0x33,0x33, + 0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x33,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x33,0x20,0x3d,0x20,0x5f,0x31,0x30,0x39,0x33,0x3b,0x0a, 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x31,0x37,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, + 0x31,0x34,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x6d,0x61,0x74,0x65,0x72,0x69, 0x61,0x6c,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f, 0x6d,0x61,0x74,0x65,0x72,0x69,0x61,0x6c,0x2e,0x79,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x20,0x3d, - 0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66, - 0x65,0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39, - 0x3e,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x31, - 0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30, - 0x37,0x31,0x2e,0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x32,0x30,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37, - 0x31,0x2e,0x73,0x68,0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x30,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31, - 0x2e,0x73,0x68,0x5b,0x33,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x32,0x30,0x5b,0x34,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e, - 0x73,0x68,0x5b,0x34,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x32,0x30,0x5b,0x35,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73, - 0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, - 0x32,0x30,0x5b,0x36,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68, - 0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32, - 0x30,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b, - 0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30, - 0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x73,0x68,0x5b,0x38, - 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x32,0x31,0x20,0x3d,0x20,0x5f,0x31,0x30,0x37,0x31,0x2e,0x69,0x62, - 0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x37,0x39,0x30,0x20,0x3d,0x20,0x69,0x6e, - 0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x20, - 0x2a,0x20,0x5f,0x31,0x33,0x33,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76,0x61,0x6c,0x75,0x61, - 0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61, - 0x6d,0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61, - 0x72,0x61,0x6d,0x5f,0x39,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x30,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x32,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c,0x75, - 0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61,0x6d, - 0x5f,0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70, - 0x61,0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, - 0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x70,0x61,0x72, - 0x61,0x6d,0x5f,0x31,0x38,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x39,0x2c, - 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x30,0x2c,0x20,0x74,0x65,0x78,0x5f,0x69, - 0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62,0x6c, - 0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66,0x5f, - 0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c,0x75, - 0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x32,0x31,0x29,0x20,0x2a,0x20,0x5f, - 0x31,0x36,0x36,0x32,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x37,0x39,0x30,0x2c,0x20, - 0x5f,0x31,0x37,0x39,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75, - 0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, + 0x66,0x6c,0x6f,0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x75,0x6e,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, + 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x70,0x76,0x55,0x6e,0x73,0x61,0x66,0x65, + 0x41,0x72,0x72,0x61,0x79,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x34,0x2c,0x20,0x39,0x3e, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x30,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x30,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x31,0x37,0x5b,0x31,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e, + 0x73,0x68,0x5b,0x31,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x31,0x37,0x5b,0x32,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68, + 0x5b,0x32,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31, + 0x37,0x5b,0x33,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x33, + 0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b, + 0x34,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x34,0x5d,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x35,0x5d, + 0x20,0x3d,0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x35,0x5d,0x3b,0x0a,0x20, + 0x20,0x20,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x36,0x5d,0x20,0x3d, + 0x20,0x5f,0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x36,0x5d,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x37,0x5d,0x20,0x3d,0x20,0x5f, + 0x37,0x30,0x37,0x2e,0x73,0x68,0x5b,0x37,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x70, + 0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x5b,0x38,0x5d,0x20,0x3d,0x20,0x5f,0x37,0x30, + 0x37,0x2e,0x73,0x68,0x5b,0x38,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, + 0x61,0x74,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x20,0x3d,0x20,0x5f,0x37, + 0x30,0x37,0x2e,0x69,0x62,0x6c,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x3b, + 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x31,0x34,0x31,0x32, + 0x20,0x3d,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x62,0x61,0x73,0x65,0x5f,0x63,0x6f,0x6c, + 0x6f,0x72,0x2e,0x77,0x20,0x2a,0x20,0x5f,0x39,0x34,0x33,0x3b,0x0a,0x20,0x20,0x20, + 0x20,0x6f,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d, + 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x62,0x72,0x64,0x66,0x5f,0x65,0x76, + 0x61,0x6c,0x75,0x61,0x74,0x65,0x28,0x70,0x61,0x72,0x61,0x6d,0x5f,0x33,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x34,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x35, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x36,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d, + 0x5f,0x37,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x38,0x2c,0x20,0x70,0x61,0x72, + 0x61,0x6d,0x5f,0x39,0x29,0x20,0x2b,0x20,0x28,0x70,0x62,0x72,0x45,0x76,0x61,0x6c, + 0x75,0x61,0x74,0x65,0x41,0x6d,0x62,0x69,0x65,0x6e,0x74,0x28,0x70,0x61,0x72,0x61, + 0x6d,0x5f,0x31,0x30,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x31,0x2c,0x20, + 0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x32,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f, + 0x31,0x33,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x34,0x2c,0x20,0x70,0x61, + 0x72,0x61,0x6d,0x5f,0x31,0x35,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x36, + 0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x37,0x2c,0x20,0x74,0x65,0x78,0x5f, + 0x69,0x62,0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x69,0x62, + 0x6c,0x5f,0x73,0x70,0x65,0x63,0x2c,0x20,0x74,0x65,0x78,0x5f,0x62,0x72,0x64,0x66, + 0x5f,0x6c,0x75,0x74,0x2c,0x20,0x73,0x6d,0x70,0x5f,0x62,0x72,0x64,0x66,0x5f,0x6c, + 0x75,0x74,0x2c,0x20,0x70,0x61,0x72,0x61,0x6d,0x5f,0x31,0x38,0x29,0x20,0x2a,0x20, + 0x5f,0x31,0x32,0x38,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x31,0x34,0x31,0x32,0x2c, + 0x20,0x5f,0x31,0x34,0x31,0x32,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74, + 0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, }; static inline const sg_shader_desc* sphere_impostor_shader_desc(sg_backend backend) { if (backend == SG_BACKEND_GLCORE) { @@ -5790,46 +4675,37 @@ static inline const sg_shader_desc* sphere_impostor_shader_desc(sg_backend backe desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[0].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_1071.sun_dir_world"; + desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "_707.sun_dir_world"; desc.uniform_blocks[1].glsl_uniforms[1].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[1].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_1071.sun_color"; + desc.uniform_blocks[1].glsl_uniforms[1].glsl_name = "_707.sun_color"; desc.uniform_blocks[1].glsl_uniforms[2].type = SG_UNIFORMTYPE_INT4; desc.uniform_blocks[1].glsl_uniforms[2].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_1071.flags"; + desc.uniform_blocks[1].glsl_uniforms[2].glsl_name = "_707.flags"; desc.uniform_blocks[1].glsl_uniforms[3].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[3].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_1071.camera_pos"; + desc.uniform_blocks[1].glsl_uniforms[3].glsl_name = "_707.camera_pos"; desc.uniform_blocks[1].glsl_uniforms[4].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[4].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_1071.view_proj"; + desc.uniform_blocks[1].glsl_uniforms[4].glsl_name = "_707.view_proj"; desc.uniform_blocks[1].glsl_uniforms[5].type = SG_UNIFORMTYPE_MAT4; desc.uniform_blocks[1].glsl_uniforms[5].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_1071.view"; + desc.uniform_blocks[1].glsl_uniforms[5].glsl_name = "_707.view"; desc.uniform_blocks[1].glsl_uniforms[6].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[6].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_1071.cascade_far_view_z"; - desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[7].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_1071.cascade_texel_world"; + desc.uniform_blocks[1].glsl_uniforms[6].glsl_name = "_707.cascade_far_view_z"; + desc.uniform_blocks[1].glsl_uniforms[7].type = SG_UNIFORMTYPE_MAT4; + desc.uniform_blocks[1].glsl_uniforms[7].array_count = 3; + desc.uniform_blocks[1].glsl_uniforms[7].glsl_name = "_707.cascade_matrices"; desc.uniform_blocks[1].glsl_uniforms[8].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[8].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_1071.cascade_depth_bias"; + desc.uniform_blocks[1].glsl_uniforms[8].array_count = 9; + desc.uniform_blocks[1].glsl_uniforms[8].glsl_name = "_707.sh"; desc.uniform_blocks[1].glsl_uniforms[9].type = SG_UNIFORMTYPE_FLOAT4; desc.uniform_blocks[1].glsl_uniforms[9].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_1071.shadow_params"; - desc.uniform_blocks[1].glsl_uniforms[10].type = SG_UNIFORMTYPE_MAT4; - desc.uniform_blocks[1].glsl_uniforms[10].array_count = 4; - desc.uniform_blocks[1].glsl_uniforms[10].glsl_name = "_1071.cascade_matrices"; - desc.uniform_blocks[1].glsl_uniforms[11].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[11].array_count = 9; - desc.uniform_blocks[1].glsl_uniforms[11].glsl_name = "_1071.sh"; - desc.uniform_blocks[1].glsl_uniforms[12].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[12].array_count = 0; - desc.uniform_blocks[1].glsl_uniforms[12].glsl_name = "_1071.ibl_params"; + desc.uniform_blocks[1].glsl_uniforms[9].glsl_name = "_707.ibl_params"; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; desc.uniform_blocks[2].size = 16; @@ -5903,7 +4779,7 @@ static inline const sg_shader_desc* sphere_impostor_shader_desc(sg_backend backe desc.uniform_blocks[0].hlsl_register_b_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].hlsl_register_b_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; @@ -5976,7 +4852,7 @@ static inline const sg_shader_desc* sphere_impostor_shader_desc(sg_backend backe desc.uniform_blocks[0].msl_buffer_n = 0; desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 672; + desc.uniform_blocks[1].size = 560; desc.uniform_blocks[1].msl_buffer_n = 1; desc.uniform_blocks[2].stage = SG_SHADERSTAGE_VERTEX; desc.uniform_blocks[2].layout = SG_UNIFORMLAYOUT_STD140; diff --git a/samples/shaders/generated/world_text.glsl.h b/samples/shaders/generated/world_text.glsl.h deleted file mode 100644 index 9c2511b..0000000 --- a/samples/shaders/generated/world_text.glsl.h +++ /dev/null @@ -1,922 +0,0 @@ -#pragma once -/* - #version:1# (machine generated, don't edit!) - - Generated by sokol-shdc (https://github.com/floooh/sokol-tools) - - Cmdline: - sokol-shdc --input E:/box/box3d/samples/shaders/overlays/world_text.glsl --output E:/box/box3d/samples/shaders/generated/world_text.glsl.h --slang hlsl5:metal_macos:glsl430 - - Overview: - ========= - Shader program: 'prog': - Get shader desc: world_text_prog_shader_desc(sg_query_backend()); - Vertex Shader: vs - Fragment Shader: fs - Attributes: - Bindings: - Uniform block 'ub_frame': - C struct: world_text_ub_frame_t - Bind slot: UB_world_text_ub_frame => 0 - Uniform block 'ub_text_style': - C struct: world_text_ub_text_style_t - Bind slot: UB_world_text_ub_text_style => 1 - Storage buffer 'glyph_instances': - C struct: world_text_glyph_instance_t - Bind slot: VIEW_world_text_glyph_instances => 0 - Readonly: true - Texture 'tex_sdf': - Image type: SG_IMAGETYPE_2D - Sample type: SG_IMAGESAMPLETYPE_FLOAT - Multisampled: false - Bind slot: VIEW_world_text_tex_sdf => 1 - Sampler 'smp_sdf': - Type: SG_SAMPLERTYPE_FILTERING - Bind slot: SMP_world_text_smp_sdf => 0 -*/ -#if !defined(SOKOL_GFX_INCLUDED) -#error "Please include sokol_gfx.h before world_text.glsl.h" -#endif -#if !defined(SOKOL_SHDC_ALIGN) -#if defined(_MSC_VER) -#define SOKOL_SHDC_ALIGN(a) __declspec(align(a)) -#else -#define SOKOL_SHDC_ALIGN(a) __attribute__((aligned(a))) -#endif -#endif -#define UB_world_text_ub_frame (0) -#define UB_world_text_ub_text_style (1) -#define VIEW_world_text_glyph_instances (0) -#define VIEW_world_text_tex_sdf (1) -#define SMP_world_text_smp_sdf (0) -#pragma pack(push,1) -SOKOL_SHDC_ALIGN(16) typedef struct world_text_ub_frame_t { - Mat4 view; - Mat4 proj; - Mat4 view_proj; - Mat4 inv_view_proj; - Vec4 camera_pos; - Vec4 viewport; -} world_text_ub_frame_t; -#pragma pack(pop) -#pragma pack(push,1) -SOKOL_SHDC_ALIGN(16) typedef struct world_text_ub_text_style_t { - Vec4 style_params; - Vec4 halo_params; -} world_text_ub_text_style_t; -#pragma pack(pop) -#pragma pack(push,1) -SOKOL_SHDC_ALIGN(16) typedef struct world_text_glyph_instance_t { - Vec4 anchor; - Vec4 rect; - Vec4 uv; - Vec4 color; -} world_text_glyph_instance_t; -#pragma pack(pop) -/* - #version 430 - - struct glyph_instance - { - vec4 anchor; - vec4 rect; - vec4 uv; - vec4 color; - }; - - layout(binding = 0, std430) readonly buffer glyph_instances - { - glyph_instance instances[]; - } _15; - - uniform vec4 ub_frame[18]; - layout(location = 0) out vec2 v_uv; - layout(location = 1) flat out vec4 v_color; - - void main() - { - bool _46 = gl_VertexID == 2; - bool _50 = gl_VertexID == 4; - vec2 _75 = (vec2((((gl_VertexID == 1) || _46) || _50) ? 1.0 : (-1.0), ((_46 || _50) || (gl_VertexID == 5)) ? 1.0 : (-1.0)) * 0.5) + vec2(0.5); - vec4 _92 = mat4(ub_frame[8], ub_frame[9], ub_frame[10], ub_frame[11]) * vec4(_15.instances[gl_InstanceID].anchor.xyz, 1.0); - float _99 = _92.w; - vec2 _123 = _15.instances[gl_InstanceID].rect.xy + (_75 * _15.instances[gl_InstanceID].rect.zw); - gl_Position = vec4(((((floor(((((_92.xy / vec2(_99)) * 0.5) + vec2(0.5)) * ub_frame[17].xy) + vec2(0.5)) + vec2(_123.x, -_123.y)) * ub_frame[17].zw) * 2.0) - vec2(1.0)) * _99, _92.z, _99); - v_uv = mix(_15.instances[gl_InstanceID].uv.xy, _15.instances[gl_InstanceID].uv.zw, _75); - v_color = _15.instances[gl_InstanceID].color; - } - -*/ -static const uint8_t world_text_vs_source_glsl430[1132] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x73,0x74, - 0x72,0x75,0x63,0x74,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74,0x61, - 0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x61, - 0x6e,0x63,0x68,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20, - 0x72,0x65,0x63,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x75, - 0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x62,0x69, - 0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x2c,0x20,0x73,0x74,0x64,0x34,0x33, - 0x30,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x62,0x75,0x66,0x66, - 0x65,0x72,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x73,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69, - 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, - 0x73,0x5b,0x5d,0x3b,0x0a,0x7d,0x20,0x5f,0x31,0x35,0x3b,0x0a,0x0a,0x75,0x6e,0x69, - 0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, - 0x6d,0x65,0x5b,0x31,0x38,0x5d,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74, - 0x20,0x76,0x65,0x63,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f, - 0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29, - 0x20,0x66,0x6c,0x61,0x74,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x76, - 0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61, - 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x34,0x36,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, - 0x44,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c, - 0x20,0x5f,0x35,0x30,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78, - 0x49,0x44,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63, - 0x32,0x20,0x5f,0x37,0x35,0x20,0x3d,0x20,0x28,0x76,0x65,0x63,0x32,0x28,0x28,0x28, - 0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x20,0x3d,0x3d,0x20, - 0x31,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35, - 0x30,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30, - 0x29,0x2c,0x20,0x28,0x28,0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29, - 0x20,0x7c,0x7c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44, - 0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x20,0x3a,0x20, - 0x28,0x2d,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b, - 0x20,0x76,0x65,0x63,0x32,0x28,0x30,0x2e,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x65,0x63,0x34,0x20,0x5f,0x39,0x32,0x20,0x3d,0x20,0x6d,0x61,0x74,0x34,0x28, - 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x38,0x5d,0x2c,0x20,0x75,0x62,0x5f, - 0x66,0x72,0x61,0x6d,0x65,0x5b,0x39,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61, - 0x6d,0x65,0x5b,0x31,0x30,0x5d,0x2c,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65, - 0x5b,0x31,0x31,0x5d,0x29,0x20,0x2a,0x20,0x76,0x65,0x63,0x34,0x28,0x5f,0x31,0x35, - 0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x61,0x6e,0x63,0x68,0x6f,0x72, - 0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x20,0x3d,0x20,0x5f,0x39,0x32,0x2e, - 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x65,0x63,0x32,0x20,0x5f,0x31,0x32,0x33, - 0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73, - 0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e, - 0x72,0x65,0x63,0x74,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x37,0x35,0x20,0x2a, - 0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67, - 0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x72,0x65, - 0x63,0x74,0x2e,0x7a,0x77,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50, - 0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x76,0x65,0x63,0x34,0x28,0x28, - 0x28,0x28,0x28,0x66,0x6c,0x6f,0x6f,0x72,0x28,0x28,0x28,0x28,0x28,0x5f,0x39,0x32, - 0x2e,0x78,0x79,0x20,0x2f,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x39,0x39,0x29,0x29, - 0x20,0x2a,0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, - 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b, - 0x31,0x37,0x5d,0x2e,0x78,0x79,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x30, - 0x2e,0x35,0x29,0x29,0x20,0x2b,0x20,0x76,0x65,0x63,0x32,0x28,0x5f,0x31,0x32,0x33, - 0x2e,0x78,0x2c,0x20,0x2d,0x5f,0x31,0x32,0x33,0x2e,0x79,0x29,0x29,0x20,0x2a,0x20, - 0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x5b,0x31,0x37,0x5d,0x2e,0x7a,0x77,0x29, - 0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x76,0x65,0x63,0x32,0x28,0x31, - 0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x39,0x2c,0x20,0x5f,0x39,0x32,0x2e, - 0x7a,0x2c,0x20,0x5f,0x39,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75, - 0x76,0x20,0x3d,0x20,0x6d,0x69,0x78,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63, - 0x65,0x49,0x44,0x5d,0x2e,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x31,0x35,0x2e, - 0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d,0x2e,0x75,0x76,0x2e,0x7a,0x77,0x2c,0x20, - 0x5f,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65, - 0x73,0x5b,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x5d, - 0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, -}; -/* - #version 430 - - uniform vec4 ub_text_style[2]; - layout(binding = 0) uniform sampler2D tex_sdf_smp_sdf; - - layout(location = 0) in vec2 v_uv; - layout(location = 1) flat in vec4 v_color; - layout(location = 0) out vec4 out_color; - - void main() - { - vec4 _24 = texture(tex_sdf_smp_sdf, v_uv); - float _51 = _24.x * v_color.w; - float _68 = (1.0 - smoothstep(0.0, ub_text_style[0].x * ub_text_style[0].z, -(_24.y - ub_text_style[0].y))) * ub_text_style[1].w; - float _73 = 1.0 - _51; - out_color = vec4((v_color.xyz * _51) + ((ub_text_style[1].xyz * _68) * _73), _51 + (_68 * _73)); - } - -*/ -static const uint8_t world_text_fs_source_glsl430[583] = { - 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x75,0x6e, - 0x69,0x66,0x6f,0x72,0x6d,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x62,0x5f,0x74,0x65, - 0x78,0x74,0x5f,0x73,0x74,0x79,0x6c,0x65,0x5b,0x32,0x5d,0x3b,0x0a,0x6c,0x61,0x79, - 0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x30,0x29, - 0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72, - 0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x64,0x66,0x5f,0x73,0x6d,0x70,0x5f,0x73, - 0x64,0x66,0x3b,0x0a,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61, - 0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63, - 0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, - 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x66,0x6c,0x61, - 0x74,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69, - 0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, - 0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, - 0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76, - 0x65,0x63,0x34,0x20,0x5f,0x32,0x34,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72, - 0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x64,0x66,0x5f,0x73,0x6d,0x70,0x5f,0x73,0x64, - 0x66,0x2c,0x20,0x76,0x5f,0x75,0x76,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34,0x2e,0x78,0x20, - 0x2a,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x28,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30, - 0x2e,0x30,0x2c,0x20,0x75,0x62,0x5f,0x74,0x65,0x78,0x74,0x5f,0x73,0x74,0x79,0x6c, - 0x65,0x5b,0x30,0x5d,0x2e,0x78,0x20,0x2a,0x20,0x75,0x62,0x5f,0x74,0x65,0x78,0x74, - 0x5f,0x73,0x74,0x79,0x6c,0x65,0x5b,0x30,0x5d,0x2e,0x7a,0x2c,0x20,0x2d,0x28,0x5f, - 0x32,0x34,0x2e,0x79,0x20,0x2d,0x20,0x75,0x62,0x5f,0x74,0x65,0x78,0x74,0x5f,0x73, - 0x74,0x79,0x6c,0x65,0x5b,0x30,0x5d,0x2e,0x79,0x29,0x29,0x29,0x20,0x2a,0x20,0x75, - 0x62,0x5f,0x74,0x65,0x78,0x74,0x5f,0x73,0x74,0x79,0x6c,0x65,0x5b,0x31,0x5d,0x2e, - 0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33, - 0x20,0x3d,0x20,0x31,0x2e,0x30,0x20,0x2d,0x20,0x5f,0x35,0x31,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x65, - 0x63,0x34,0x28,0x28,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2b,0x20,0x28,0x28,0x75,0x62,0x5f,0x74,0x65, - 0x78,0x74,0x5f,0x73,0x74,0x79,0x6c,0x65,0x5b,0x31,0x5d,0x2e,0x78,0x79,0x7a,0x20, - 0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x33,0x29,0x2c,0x20,0x5f, - 0x35,0x31,0x20,0x2b,0x20,0x28,0x5f,0x36,0x38,0x20,0x2a,0x20,0x5f,0x37,0x33,0x29, - 0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, -}; -/* - struct glyph_instance - { - float4 anchor; - float4 rect; - float4 uv; - float4 color; - }; - - ByteAddressBuffer _15 : register(t0); - cbuffer ub_frame : register(b0) - { - row_major float4x4 _80_view : packoffset(c0); - row_major float4x4 _80_proj : packoffset(c4); - row_major float4x4 _80_view_proj : packoffset(c8); - row_major float4x4 _80_inv_view_proj : packoffset(c12); - float4 _80_camera_pos : packoffset(c16); - float4 _80_viewport : packoffset(c17); - }; - - - static float4 gl_Position; - static int gl_VertexIndex; - static int gl_InstanceIndex; - static float2 v_uv; - static float4 v_color; - - struct SPIRV_Cross_Input - { - uint gl_VertexIndex : SV_VertexID; - uint gl_InstanceIndex : SV_InstanceID; - }; - - struct SPIRV_Cross_Output - { - float2 v_uv : TEXCOORD0; - nointerpolation float4 v_color : TEXCOORD1; - float4 gl_Position : SV_Position; - }; - - void vert_main() - { - glyph_instance _23; - _23.anchor = asfloat(_15.Load4(gl_InstanceIndex * 64 + 0)); - _23.rect = asfloat(_15.Load4(gl_InstanceIndex * 64 + 16)); - _23.uv = asfloat(_15.Load4(gl_InstanceIndex * 64 + 32)); - _23.color = asfloat(_15.Load4(gl_InstanceIndex * 64 + 48)); - bool _46 = gl_VertexIndex == 2; - bool _50 = gl_VertexIndex == 4; - float2 _75 = (float2((((gl_VertexIndex == 1) || _46) || _50) ? 1.0f : (-1.0f), ((_46 || _50) || (gl_VertexIndex == 5)) ? 1.0f : (-1.0f)) * 0.5f) + 0.5f.xx; - float4 _92 = mul(float4(_23.anchor.xyz, 1.0f), _80_view_proj); - float _99 = _92.w; - float2 _123 = _23.rect.xy + (_75 * _23.rect.zw); - gl_Position = float4(((((floor(((((_92.xy / _99.xx) * 0.5f) + 0.5f.xx) * _80_viewport.xy) + 0.5f.xx) + float2(_123.x, -_123.y)) * _80_viewport.zw) * 2.0f) - 1.0f.xx) * _99, _92.z, _99); - v_uv = lerp(_23.uv.xy, _23.uv.zw, _75); - v_color = _23.color; - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - gl_VertexIndex = int(stage_input.gl_VertexIndex); - gl_InstanceIndex = int(stage_input.gl_InstanceIndex); - vert_main(); - SPIRV_Cross_Output stage_output; - stage_output.gl_Position = gl_Position; - stage_output.v_uv = v_uv; - stage_output.v_color = v_color; - return stage_output; - } -*/ -static const uint8_t world_text_vs_source_hlsl5[2157] = { - 0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x61,0x6e,0x63,0x68,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x72,0x65,0x63,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x3b,0x0a, - 0x0a,0x42,0x79,0x74,0x65,0x41,0x64,0x64,0x72,0x65,0x73,0x73,0x42,0x75,0x66,0x66, - 0x65,0x72,0x20,0x5f,0x31,0x35,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65, - 0x72,0x28,0x74,0x30,0x29,0x3b,0x0a,0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75, - 0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74, - 0x65,0x72,0x28,0x62,0x30,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77, - 0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20, - 0x5f,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f, - 0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72, - 0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78, - 0x34,0x20,0x5f,0x38,0x30,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70,0x61,0x63, - 0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x34,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f,0x72,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x78,0x34,0x20,0x5f,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, - 0x6a,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63, - 0x38,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x6f,0x77,0x5f,0x6d,0x61,0x6a,0x6f, - 0x72,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x5f,0x38,0x30,0x5f,0x69, - 0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20,0x3a,0x20,0x70, - 0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x32,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x30,0x5f,0x63, - 0x61,0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b, - 0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x36,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x38,0x30,0x5f,0x76,0x69,0x65,0x77, - 0x70,0x6f,0x72,0x74,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65, - 0x74,0x28,0x63,0x31,0x37,0x29,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x0a,0x73,0x74,0x61, - 0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f, - 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69, - 0x6e,0x74,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65, - 0x78,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x69,0x6e,0x74,0x20,0x67,0x6c, - 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x3b,0x0a, - 0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f, - 0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75, - 0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49, - 0x6e,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x75,0x69,0x6e,0x74,0x20, - 0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a, - 0x20,0x53,0x56,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x44,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3a,0x20,0x53,0x56,0x5f,0x49,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x49,0x44,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72, - 0x75,0x63,0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x4f,0x75,0x74,0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, - 0x4f,0x52,0x44,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65, - 0x72,0x70,0x6f,0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f, - 0x4f,0x52,0x44,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34, - 0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3a,0x20,0x53, - 0x56,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a, - 0x76,0x6f,0x69,0x64,0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x20,0x5f,0x32,0x33,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, - 0x32,0x33,0x2e,0x61,0x6e,0x63,0x68,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c, - 0x6f,0x61,0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c, - 0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a, - 0x20,0x36,0x34,0x20,0x2b,0x20,0x30,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f, - 0x32,0x33,0x2e,0x72,0x65,0x63,0x74,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61, - 0x74,0x28,0x5f,0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49, - 0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36, - 0x34,0x20,0x2b,0x20,0x31,0x36,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32, - 0x33,0x2e,0x75,0x76,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, - 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b, - 0x20,0x33,0x32,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x5f,0x32,0x33,0x2e,0x63, - 0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x61,0x73,0x66,0x6c,0x6f,0x61,0x74,0x28,0x5f, - 0x31,0x35,0x2e,0x4c,0x6f,0x61,0x64,0x34,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x2a,0x20,0x36,0x34,0x20,0x2b, - 0x20,0x34,0x38,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20, - 0x5f,0x34,0x36,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49, - 0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62, - 0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x30,0x20,0x3d,0x20,0x67,0x6c,0x5f,0x56,0x65,0x72, - 0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x5f,0x37,0x35,0x20,0x3d,0x20, - 0x28,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x28,0x28,0x28,0x67,0x6c,0x5f,0x56,0x65, - 0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20, - 0x7c,0x7c,0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20, - 0x3f,0x20,0x31,0x2e,0x30,0x66,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29, - 0x2c,0x20,0x28,0x28,0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20, - 0x7c,0x7c,0x20,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, - 0x65,0x78,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30,0x66, - 0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x66,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e, - 0x35,0x66,0x29,0x20,0x2b,0x20,0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x32,0x20,0x3d,0x20, - 0x6d,0x75,0x6c,0x28,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x32,0x33,0x2e,0x61, - 0x6e,0x63,0x68,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x66,0x29, - 0x2c,0x20,0x5f,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x29, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x20, - 0x3d,0x20,0x5f,0x39,0x32,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x5f,0x31,0x32,0x33,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x72, - 0x65,0x63,0x74,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x37,0x35,0x20,0x2a,0x20, - 0x5f,0x32,0x33,0x2e,0x72,0x65,0x63,0x74,0x2e,0x7a,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x28,0x28,0x28,0x66,0x6c,0x6f,0x6f,0x72, - 0x28,0x28,0x28,0x28,0x28,0x5f,0x39,0x32,0x2e,0x78,0x79,0x20,0x2f,0x20,0x5f,0x39, - 0x39,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35,0x66,0x29,0x20,0x2b,0x20, - 0x30,0x2e,0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f,0x38,0x30,0x5f,0x76, - 0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x2e,0x78,0x79,0x29,0x20,0x2b,0x20,0x30,0x2e, - 0x35,0x66,0x2e,0x78,0x78,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x31,0x32,0x33,0x2e,0x78,0x2c,0x20,0x2d,0x5f,0x31,0x32,0x33,0x2e,0x79,0x29, - 0x29,0x20,0x2a,0x20,0x5f,0x38,0x30,0x5f,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, - 0x2e,0x7a,0x77,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x66,0x29,0x20,0x2d,0x20,0x31, - 0x2e,0x30,0x66,0x2e,0x78,0x78,0x29,0x20,0x2a,0x20,0x5f,0x39,0x39,0x2c,0x20,0x5f, - 0x39,0x32,0x2e,0x7a,0x2c,0x20,0x5f,0x39,0x39,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x6c,0x65,0x72,0x70,0x28,0x5f,0x32,0x33,0x2e, - 0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x32,0x33,0x2e,0x75,0x76,0x2e,0x7a,0x77, - 0x2c,0x20,0x5f,0x37,0x35,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x3d,0x20,0x5f,0x32,0x33,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20, - 0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x2e,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x49,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x76,0x65,0x72,0x74,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75, - 0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75, - 0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74, - 0x70,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20, - 0x3d,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e, - 0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x76,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74,0x61,0x67, - 0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, -}; -/* - cbuffer ub_text_style : register(b1) - { - float4 _34_style_params : packoffset(c0); - float4 _34_halo_params : packoffset(c1); - }; - - Texture2D tex_sdf : register(t0); - SamplerState smp_sdf : register(s0); - - static float2 v_uv; - static float4 v_color; - static float4 out_color; - - struct SPIRV_Cross_Input - { - float2 v_uv : TEXCOORD0; - nointerpolation float4 v_color : TEXCOORD1; - }; - - struct SPIRV_Cross_Output - { - float4 out_color : SV_Target0; - }; - - void frag_main() - { - float4 _24 = tex_sdf.Sample(smp_sdf, v_uv); - float _51 = _24.x * v_color.w; - float _68 = (1.0f - smoothstep(0.0f, _34_style_params.x * _34_style_params.z, -(_24.y - _34_style_params.y))) * _34_halo_params.w; - float _73 = 1.0f - _51; - out_color = float4((v_color.xyz * _51) + ((_34_halo_params.xyz * _68) * _73), _51 + (_68 * _73)); - } - - SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) - { - v_uv = stage_input.v_uv; - v_color = stage_input.v_color; - frag_main(); - SPIRV_Cross_Output stage_output; - stage_output.out_color = out_color; - return stage_output; - } -*/ -static const uint8_t world_text_fs_source_hlsl5[1071] = { - 0x63,0x62,0x75,0x66,0x66,0x65,0x72,0x20,0x75,0x62,0x5f,0x74,0x65,0x78,0x74,0x5f, - 0x73,0x74,0x79,0x6c,0x65,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72, - 0x28,0x62,0x31,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x5f,0x33,0x34,0x5f,0x73,0x74,0x79,0x6c,0x65,0x5f,0x70,0x61,0x72,0x61, - 0x6d,0x73,0x20,0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28, - 0x63,0x30,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20, - 0x5f,0x33,0x34,0x5f,0x68,0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x20, - 0x3a,0x20,0x70,0x61,0x63,0x6b,0x6f,0x66,0x66,0x73,0x65,0x74,0x28,0x63,0x31,0x29, - 0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x54,0x65,0x78,0x74,0x75,0x72,0x65,0x32,0x44,0x3c, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x3e,0x20,0x74,0x65,0x78,0x5f,0x73,0x64,0x66,0x20, - 0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28,0x74,0x30,0x29,0x3b,0x0a, - 0x53,0x61,0x6d,0x70,0x6c,0x65,0x72,0x53,0x74,0x61,0x74,0x65,0x20,0x73,0x6d,0x70, - 0x5f,0x73,0x64,0x66,0x20,0x3a,0x20,0x72,0x65,0x67,0x69,0x73,0x74,0x65,0x72,0x28, - 0x73,0x30,0x29,0x3b,0x0a,0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x3b,0x0a,0x73,0x74,0x61,0x74,0x69,0x63, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b, - 0x0a,0x73,0x74,0x61,0x74,0x69,0x63,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f, - 0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63, - 0x74,0x20,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x49,0x6e, - 0x70,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x76,0x5f,0x75,0x76,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, - 0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6e,0x6f,0x69,0x6e,0x74,0x65,0x72,0x70,0x6f, - 0x6c,0x61,0x74,0x69,0x6f,0x6e,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x54,0x45,0x58,0x43,0x4f,0x4f,0x52,0x44, - 0x31,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x53,0x50, - 0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74, - 0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x6f,0x75, - 0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3a,0x20,0x53,0x56,0x5f,0x54,0x61,0x72, - 0x67,0x65,0x74,0x30,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x66, - 0x72,0x61,0x67,0x5f,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x34,0x20,0x3d,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x64,0x66,0x2e,0x53,0x61,0x6d,0x70,0x6c,0x65,0x28,0x73,0x6d,0x70, - 0x5f,0x73,0x64,0x66,0x2c,0x20,0x76,0x5f,0x75,0x76,0x29,0x3b,0x0a,0x20,0x20,0x20, - 0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x31,0x20,0x3d,0x20,0x5f,0x32,0x34, - 0x2e,0x78,0x20,0x2a,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20, - 0x28,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74, - 0x65,0x70,0x28,0x30,0x2e,0x30,0x66,0x2c,0x20,0x5f,0x33,0x34,0x5f,0x73,0x74,0x79, - 0x6c,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78,0x20,0x2a,0x20,0x5f,0x33, - 0x34,0x5f,0x73,0x74,0x79,0x6c,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x7a, - 0x2c,0x20,0x2d,0x28,0x5f,0x32,0x34,0x2e,0x79,0x20,0x2d,0x20,0x5f,0x33,0x34,0x5f, - 0x73,0x74,0x79,0x6c,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x79,0x29,0x29, - 0x29,0x20,0x2a,0x20,0x5f,0x33,0x34,0x5f,0x68,0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x20,0x5f,0x37,0x33,0x20,0x3d,0x20,0x31,0x2e,0x30,0x66,0x20,0x2d,0x20,0x5f,0x35, - 0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72, - 0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x76,0x5f,0x63,0x6f,0x6c, - 0x6f,0x72,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2b,0x20, - 0x28,0x28,0x5f,0x33,0x34,0x5f,0x68,0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72,0x61,0x6d, - 0x73,0x2e,0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f, - 0x37,0x33,0x29,0x2c,0x20,0x5f,0x35,0x31,0x20,0x2b,0x20,0x28,0x5f,0x36,0x38,0x20, - 0x2a,0x20,0x5f,0x37,0x33,0x29,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x53,0x50,0x49,0x52, - 0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x6d, - 0x61,0x69,0x6e,0x28,0x53,0x50,0x49,0x52,0x56,0x5f,0x43,0x72,0x6f,0x73,0x73,0x5f, - 0x49,0x6e,0x70,0x75,0x74,0x20,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75, - 0x74,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20, - 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76, - 0x3b,0x0a,0x20,0x20,0x20,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20, - 0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x70,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x6d,0x61, - 0x69,0x6e,0x28,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x53,0x50,0x49,0x52,0x56,0x5f, - 0x43,0x72,0x6f,0x73,0x73,0x5f,0x4f,0x75,0x74,0x70,0x75,0x74,0x20,0x73,0x74,0x61, - 0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x73, - 0x74,0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x2e,0x6f,0x75,0x74,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x73,0x74, - 0x61,0x67,0x65,0x5f,0x6f,0x75,0x74,0x70,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x00, -}; -/* - #include - #include - - using namespace metal; - - struct glyph_instance - { - float4 anchor; - float4 rect; - float4 uv; - float4 color; - }; - - struct glyph_instances - { - glyph_instance instances[1]; - }; - - struct ub_frame - { - float4x4 view; - float4x4 proj; - float4x4 view_proj; - float4x4 inv_view_proj; - float4 camera_pos; - float4 viewport; - }; - - struct main0_out - { - float2 v_uv [[user(locn0)]]; - float4 v_color [[user(locn1)]]; - float4 gl_Position [[position]]; - }; - - vertex main0_out main0(constant ub_frame& _80 [[buffer(0)]], const device glyph_instances& _15 [[buffer(8)]], uint gl_InstanceIndex [[instance_id]], uint gl_VertexIndex [[vertex_id]]) - { - main0_out out = {}; - bool _46 = int(gl_VertexIndex) == 2; - bool _50 = int(gl_VertexIndex) == 4; - float2 _75 = (float2((((int(gl_VertexIndex) == 1) || _46) || _50) ? 1.0 : (-1.0), ((_46 || _50) || (int(gl_VertexIndex) == 5)) ? 1.0 : (-1.0)) * 0.5) + float2(0.5); - float4 _92 = _80.view_proj * float4(_15.instances[int(gl_InstanceIndex)].anchor.xyz, 1.0); - float _99 = _92.w; - float2 _123 = _15.instances[int(gl_InstanceIndex)].rect.xy + (_75 * _15.instances[int(gl_InstanceIndex)].rect.zw); - out.gl_Position = float4(((((floor(((((_92.xy / float2(_99)) * 0.5) + float2(0.5)) * _80.viewport.xy) + float2(0.5)) + float2(_123.x, -_123.y)) * _80.viewport.zw) * 2.0) - float2(1.0)) * _99, _92.z, _99); - out.v_uv = mix(_15.instances[int(gl_InstanceIndex)].uv.xy, _15.instances[int(gl_InstanceIndex)].uv.zw, _75); - out.v_color = _15.instances[int(gl_InstanceIndex)].color; - return out; - } - -*/ -static const uint8_t world_text_vs_source_metal_macos[1618] = { - 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, - 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, - 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, - 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x67, - 0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x61,0x6e,0x63,0x68,0x6f, - 0x72,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x72,0x65, - 0x63,0x74,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x75, - 0x76,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x6f, - 0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20, - 0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x0a, - 0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74, - 0x61,0x6e,0x63,0x65,0x20,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x31, - 0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75,0x62, - 0x5f,0x66,0x72,0x61,0x6d,0x65,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20, - 0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x78,0x34,0x20,0x76,0x69,0x65,0x77, - 0x5f,0x70,0x72,0x6f,0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x78,0x34,0x20,0x69,0x6e,0x76,0x5f,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f, - 0x6a,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x63,0x61, - 0x6d,0x65,0x72,0x61,0x5f,0x70,0x6f,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x34,0x20,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74,0x3b,0x0a,0x7d, - 0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f, - 0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x20,0x76,0x5f,0x75,0x76,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63, - 0x6e,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72, - 0x28,0x6c,0x6f,0x63,0x6e,0x31,0x29,0x5d,0x5d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66, - 0x6c,0x6f,0x61,0x74,0x34,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, - 0x6e,0x20,0x5b,0x5b,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x5d,0x5d,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x76,0x65,0x72,0x74,0x65,0x78,0x20,0x6d,0x61,0x69,0x6e,0x30, - 0x5f,0x6f,0x75,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x63,0x6f,0x6e,0x73,0x74, - 0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x66,0x72,0x61,0x6d,0x65,0x26,0x20,0x5f,0x38, - 0x30,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x30,0x29,0x5d,0x5d,0x2c, - 0x20,0x63,0x6f,0x6e,0x73,0x74,0x20,0x64,0x65,0x76,0x69,0x63,0x65,0x20,0x67,0x6c, - 0x79,0x70,0x68,0x5f,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x26,0x20,0x5f, - 0x31,0x35,0x20,0x5b,0x5b,0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x38,0x29,0x5d,0x5d, - 0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x69,0x6e,0x73,0x74,0x61,0x6e, - 0x63,0x65,0x5f,0x69,0x64,0x5d,0x5d,0x2c,0x20,0x75,0x69,0x6e,0x74,0x20,0x67,0x6c, - 0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x20,0x5b,0x5b,0x76, - 0x65,0x72,0x74,0x65,0x78,0x5f,0x69,0x64,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20, - 0x20,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20, - 0x3d,0x20,0x7b,0x7d,0x3b,0x0a,0x20,0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f, - 0x34,0x36,0x20,0x3d,0x20,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74, - 0x65,0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x32,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x62,0x6f,0x6f,0x6c,0x20,0x5f,0x35,0x30,0x20,0x3d,0x20,0x69,0x6e, - 0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64,0x65,0x78, - 0x29,0x20,0x3d,0x3d,0x20,0x34,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x32,0x20,0x5f,0x37,0x35,0x20,0x3d,0x20,0x28,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x28,0x28,0x28,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65, - 0x78,0x49,0x6e,0x64,0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x31,0x29,0x20,0x7c,0x7c, - 0x20,0x5f,0x34,0x36,0x29,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20,0x3f,0x20, - 0x31,0x2e,0x30,0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x2c,0x20,0x28,0x28, - 0x5f,0x34,0x36,0x20,0x7c,0x7c,0x20,0x5f,0x35,0x30,0x29,0x20,0x7c,0x7c,0x20,0x28, - 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x56,0x65,0x72,0x74,0x65,0x78,0x49,0x6e,0x64, - 0x65,0x78,0x29,0x20,0x3d,0x3d,0x20,0x35,0x29,0x29,0x20,0x3f,0x20,0x31,0x2e,0x30, - 0x20,0x3a,0x20,0x28,0x2d,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x30,0x2e,0x35, - 0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30,0x2e,0x35,0x29,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x39,0x32,0x20, - 0x3d,0x20,0x5f,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x5f,0x70,0x72,0x6f,0x6a,0x20, - 0x2a,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x61,0x6e, - 0x63,0x68,0x6f,0x72,0x2e,0x78,0x79,0x7a,0x2c,0x20,0x31,0x2e,0x30,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x39,0x39,0x20,0x3d,0x20, - 0x5f,0x39,0x32,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x32,0x20,0x5f,0x31,0x32,0x33,0x20,0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73, - 0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e, - 0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x72,0x65, - 0x63,0x74,0x2e,0x78,0x79,0x20,0x2b,0x20,0x28,0x5f,0x37,0x35,0x20,0x2a,0x20,0x5f, - 0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74, - 0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65, - 0x78,0x29,0x5d,0x2e,0x72,0x65,0x63,0x74,0x2e,0x7a,0x77,0x29,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x6f,0x75,0x74,0x2e,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f, - 0x6e,0x20,0x3d,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x28,0x28,0x28,0x28,0x28,0x66, - 0x6c,0x6f,0x6f,0x72,0x28,0x28,0x28,0x28,0x28,0x5f,0x39,0x32,0x2e,0x78,0x79,0x20, - 0x2f,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x5f,0x39,0x39,0x29,0x29,0x20,0x2a, - 0x20,0x30,0x2e,0x35,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28,0x30, - 0x2e,0x35,0x29,0x29,0x20,0x2a,0x20,0x5f,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x70, - 0x6f,0x72,0x74,0x2e,0x78,0x79,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32, - 0x28,0x30,0x2e,0x35,0x29,0x29,0x20,0x2b,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x28, - 0x5f,0x31,0x32,0x33,0x2e,0x78,0x2c,0x20,0x2d,0x5f,0x31,0x32,0x33,0x2e,0x79,0x29, - 0x29,0x20,0x2a,0x20,0x5f,0x38,0x30,0x2e,0x76,0x69,0x65,0x77,0x70,0x6f,0x72,0x74, - 0x2e,0x7a,0x77,0x29,0x20,0x2a,0x20,0x32,0x2e,0x30,0x29,0x20,0x2d,0x20,0x66,0x6c, - 0x6f,0x61,0x74,0x32,0x28,0x31,0x2e,0x30,0x29,0x29,0x20,0x2a,0x20,0x5f,0x39,0x39, - 0x2c,0x20,0x5f,0x39,0x32,0x2e,0x7a,0x2c,0x20,0x5f,0x39,0x39,0x29,0x3b,0x0a,0x20, - 0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x75,0x76,0x20,0x3d,0x20,0x6d,0x69, - 0x78,0x28,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, - 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, - 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x75,0x76,0x2e,0x78,0x79,0x2c,0x20,0x5f,0x31, - 0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b,0x69,0x6e,0x74,0x28, - 0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49,0x6e,0x64,0x65,0x78, - 0x29,0x5d,0x2e,0x75,0x76,0x2e,0x7a,0x77,0x2c,0x20,0x5f,0x37,0x35,0x29,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x6f,0x75,0x74,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20, - 0x3d,0x20,0x5f,0x31,0x35,0x2e,0x69,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x73,0x5b, - 0x69,0x6e,0x74,0x28,0x67,0x6c,0x5f,0x49,0x6e,0x73,0x74,0x61,0x6e,0x63,0x65,0x49, - 0x6e,0x64,0x65,0x78,0x29,0x5d,0x2e,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e,0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a, - 0x0a,0x00, -}; -/* - #include - #include - - using namespace metal; - - struct ub_text_style - { - float4 style_params; - float4 halo_params; - }; - - struct main0_out - { - float4 out_color [[color(0)]]; - }; - - struct main0_in - { - float2 v_uv [[user(locn0)]]; - float4 v_color [[user(locn1), flat]]; - }; - - fragment main0_out main0(main0_in in [[stage_in]], constant ub_text_style& _34 [[buffer(1)]], texture2d tex_sdf [[texture(0)]], sampler smp_sdf [[sampler(0)]]) - { - main0_out out = {}; - float4 _24 = tex_sdf.sample(smp_sdf, in.v_uv); - float _51 = _24.x * in.v_color.w; - float _68 = (1.0 - smoothstep(0.0, _34.style_params.x * _34.style_params.z, -(_24.y - _34.style_params.y))) * _34.halo_params.w; - float _73 = 1.0 - _51; - out.out_color = float4((in.v_color.xyz * _51) + ((_34.halo_params.xyz * _68) * _73), _51 + (_68 * _73)); - return out; - } - -*/ -static const uint8_t world_text_fs_source_metal_macos[874] = { - 0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65,0x20,0x3c,0x6d,0x65,0x74,0x61,0x6c,0x5f, - 0x73,0x74,0x64,0x6c,0x69,0x62,0x3e,0x0a,0x23,0x69,0x6e,0x63,0x6c,0x75,0x64,0x65, - 0x20,0x3c,0x73,0x69,0x6d,0x64,0x2f,0x73,0x69,0x6d,0x64,0x2e,0x68,0x3e,0x0a,0x0a, - 0x75,0x73,0x69,0x6e,0x67,0x20,0x6e,0x61,0x6d,0x65,0x73,0x70,0x61,0x63,0x65,0x20, - 0x6d,0x65,0x74,0x61,0x6c,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x75, - 0x62,0x5f,0x74,0x65,0x78,0x74,0x5f,0x73,0x74,0x79,0x6c,0x65,0x0a,0x7b,0x0a,0x20, - 0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x73,0x74,0x79,0x6c,0x65,0x5f, - 0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61, - 0x74,0x34,0x20,0x68,0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x3b,0x0a, - 0x7d,0x3b,0x0a,0x0a,0x73,0x74,0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30, - 0x5f,0x6f,0x75,0x74,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74, - 0x34,0x20,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x63,0x6f, - 0x6c,0x6f,0x72,0x28,0x30,0x29,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x73,0x74, - 0x72,0x75,0x63,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e,0x0a,0x7b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x32,0x20,0x76,0x5f,0x75,0x76,0x20, - 0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x30,0x29,0x5d,0x5d,0x3b, - 0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x76,0x5f,0x63,0x6f, - 0x6c,0x6f,0x72,0x20,0x5b,0x5b,0x75,0x73,0x65,0x72,0x28,0x6c,0x6f,0x63,0x6e,0x31, - 0x29,0x2c,0x20,0x66,0x6c,0x61,0x74,0x5d,0x5d,0x3b,0x0a,0x7d,0x3b,0x0a,0x0a,0x66, - 0x72,0x61,0x67,0x6d,0x65,0x6e,0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x6f,0x75, - 0x74,0x20,0x6d,0x61,0x69,0x6e,0x30,0x28,0x6d,0x61,0x69,0x6e,0x30,0x5f,0x69,0x6e, - 0x20,0x69,0x6e,0x20,0x5b,0x5b,0x73,0x74,0x61,0x67,0x65,0x5f,0x69,0x6e,0x5d,0x5d, - 0x2c,0x20,0x63,0x6f,0x6e,0x73,0x74,0x61,0x6e,0x74,0x20,0x75,0x62,0x5f,0x74,0x65, - 0x78,0x74,0x5f,0x73,0x74,0x79,0x6c,0x65,0x26,0x20,0x5f,0x33,0x34,0x20,0x5b,0x5b, - 0x62,0x75,0x66,0x66,0x65,0x72,0x28,0x31,0x29,0x5d,0x5d,0x2c,0x20,0x74,0x65,0x78, - 0x74,0x75,0x72,0x65,0x32,0x64,0x3c,0x66,0x6c,0x6f,0x61,0x74,0x3e,0x20,0x74,0x65, - 0x78,0x5f,0x73,0x64,0x66,0x20,0x5b,0x5b,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28, - 0x30,0x29,0x5d,0x5d,0x2c,0x20,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x20,0x73,0x6d, - 0x70,0x5f,0x73,0x64,0x66,0x20,0x5b,0x5b,0x73,0x61,0x6d,0x70,0x6c,0x65,0x72,0x28, - 0x30,0x29,0x5d,0x5d,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x6d,0x61,0x69,0x6e, - 0x30,0x5f,0x6f,0x75,0x74,0x20,0x6f,0x75,0x74,0x20,0x3d,0x20,0x7b,0x7d,0x3b,0x0a, - 0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x34,0x20,0x5f,0x32,0x34,0x20,0x3d, - 0x20,0x74,0x65,0x78,0x5f,0x73,0x64,0x66,0x2e,0x73,0x61,0x6d,0x70,0x6c,0x65,0x28, - 0x73,0x6d,0x70,0x5f,0x73,0x64,0x66,0x2c,0x20,0x69,0x6e,0x2e,0x76,0x5f,0x75,0x76, - 0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x35,0x31, - 0x20,0x3d,0x20,0x5f,0x32,0x34,0x2e,0x78,0x20,0x2a,0x20,0x69,0x6e,0x2e,0x76,0x5f, - 0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x77,0x3b,0x0a,0x20,0x20,0x20,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x20,0x5f,0x36,0x38,0x20,0x3d,0x20,0x28,0x31,0x2e,0x30,0x20,0x2d,0x20, - 0x73,0x6d,0x6f,0x6f,0x74,0x68,0x73,0x74,0x65,0x70,0x28,0x30,0x2e,0x30,0x2c,0x20, - 0x5f,0x33,0x34,0x2e,0x73,0x74,0x79,0x6c,0x65,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73, - 0x2e,0x78,0x20,0x2a,0x20,0x5f,0x33,0x34,0x2e,0x73,0x74,0x79,0x6c,0x65,0x5f,0x70, - 0x61,0x72,0x61,0x6d,0x73,0x2e,0x7a,0x2c,0x20,0x2d,0x28,0x5f,0x32,0x34,0x2e,0x79, - 0x20,0x2d,0x20,0x5f,0x33,0x34,0x2e,0x73,0x74,0x79,0x6c,0x65,0x5f,0x70,0x61,0x72, - 0x61,0x6d,0x73,0x2e,0x79,0x29,0x29,0x29,0x20,0x2a,0x20,0x5f,0x33,0x34,0x2e,0x68, - 0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x77,0x3b,0x0a,0x20,0x20, - 0x20,0x20,0x66,0x6c,0x6f,0x61,0x74,0x20,0x5f,0x37,0x33,0x20,0x3d,0x20,0x31,0x2e, - 0x30,0x20,0x2d,0x20,0x5f,0x35,0x31,0x3b,0x0a,0x20,0x20,0x20,0x20,0x6f,0x75,0x74, - 0x2e,0x6f,0x75,0x74,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x66,0x6c,0x6f, - 0x61,0x74,0x34,0x28,0x28,0x69,0x6e,0x2e,0x76,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x2e, - 0x78,0x79,0x7a,0x20,0x2a,0x20,0x5f,0x35,0x31,0x29,0x20,0x2b,0x20,0x28,0x28,0x5f, - 0x33,0x34,0x2e,0x68,0x61,0x6c,0x6f,0x5f,0x70,0x61,0x72,0x61,0x6d,0x73,0x2e,0x78, - 0x79,0x7a,0x20,0x2a,0x20,0x5f,0x36,0x38,0x29,0x20,0x2a,0x20,0x5f,0x37,0x33,0x29, - 0x2c,0x20,0x5f,0x35,0x31,0x20,0x2b,0x20,0x28,0x5f,0x36,0x38,0x20,0x2a,0x20,0x5f, - 0x37,0x33,0x29,0x29,0x3b,0x0a,0x20,0x20,0x20,0x20,0x72,0x65,0x74,0x75,0x72,0x6e, - 0x20,0x6f,0x75,0x74,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, -}; -static inline const sg_shader_desc* world_text_prog_shader_desc(sg_backend backend) { - if (backend == SG_BACKEND_GLCORE) { - static sg_shader_desc desc; - static bool valid; - if (!valid) { - valid = true; - desc.vertex_func.source = (const char*)world_text_vs_source_glsl430; - desc.vertex_func.entry = "main"; - desc.fragment_func.source = (const char*)world_text_fs_source_glsl430; - desc.fragment_func.entry = "main"; - desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; - desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[0].size = 288; - desc.uniform_blocks[0].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[0].glsl_uniforms[0].array_count = 18; - desc.uniform_blocks[0].glsl_uniforms[0].glsl_name = "ub_frame"; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].glsl_uniforms[0].type = SG_UNIFORMTYPE_FLOAT4; - desc.uniform_blocks[1].glsl_uniforms[0].array_count = 2; - desc.uniform_blocks[1].glsl_uniforms[0].glsl_name = "ub_text_style"; - desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; - desc.views[0].storage_buffer.readonly = true; - desc.views[0].storage_buffer.glsl_binding_n = 0; - desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; - desc.views[1].texture.image_type = SG_IMAGETYPE_2D; - desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; - desc.views[1].texture.multisampled = false; - desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; - desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.texture_sampler_pairs[0].view_slot = 1; - desc.texture_sampler_pairs[0].sampler_slot = 0; - desc.texture_sampler_pairs[0].glsl_name = "tex_sdf_smp_sdf"; - desc.label = "world_text_prog_shader"; - } - return &desc; - } - if (backend == SG_BACKEND_D3D11) { - static sg_shader_desc desc; - static bool valid; - if (!valid) { - valid = true; - desc.vertex_func.source = (const char*)world_text_vs_source_hlsl5; - desc.vertex_func.d3d11_target = "vs_5_0"; - desc.vertex_func.entry = "main"; - desc.fragment_func.source = (const char*)world_text_fs_source_hlsl5; - desc.fragment_func.d3d11_target = "ps_5_0"; - desc.fragment_func.entry = "main"; - desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; - desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[0].size = 288; - desc.uniform_blocks[0].hlsl_register_b_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].hlsl_register_b_n = 1; - desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; - desc.views[0].storage_buffer.readonly = true; - desc.views[0].storage_buffer.hlsl_register_t_n = 0; - desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; - desc.views[1].texture.image_type = SG_IMAGETYPE_2D; - desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; - desc.views[1].texture.multisampled = false; - desc.views[1].texture.hlsl_register_t_n = 0; - desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; - desc.samplers[0].hlsl_register_s_n = 0; - desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.texture_sampler_pairs[0].view_slot = 1; - desc.texture_sampler_pairs[0].sampler_slot = 0; - desc.label = "world_text_prog_shader"; - } - return &desc; - } - if (backend == SG_BACKEND_METAL_MACOS) { - static sg_shader_desc desc; - static bool valid; - if (!valid) { - valid = true; - desc.vertex_func.source = (const char*)world_text_vs_source_metal_macos; - desc.vertex_func.entry = "main0"; - desc.fragment_func.source = (const char*)world_text_fs_source_metal_macos; - desc.fragment_func.entry = "main0"; - desc.uniform_blocks[0].stage = SG_SHADERSTAGE_VERTEX; - desc.uniform_blocks[0].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[0].size = 288; - desc.uniform_blocks[0].msl_buffer_n = 0; - desc.uniform_blocks[1].stage = SG_SHADERSTAGE_FRAGMENT; - desc.uniform_blocks[1].layout = SG_UNIFORMLAYOUT_STD140; - desc.uniform_blocks[1].size = 32; - desc.uniform_blocks[1].msl_buffer_n = 1; - desc.views[0].storage_buffer.stage = SG_SHADERSTAGE_VERTEX; - desc.views[0].storage_buffer.readonly = true; - desc.views[0].storage_buffer.msl_buffer_n = 8; - desc.views[1].texture.stage = SG_SHADERSTAGE_FRAGMENT; - desc.views[1].texture.image_type = SG_IMAGETYPE_2D; - desc.views[1].texture.sample_type = SG_IMAGESAMPLETYPE_FLOAT; - desc.views[1].texture.multisampled = false; - desc.views[1].texture.msl_texture_n = 0; - desc.samplers[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.samplers[0].sampler_type = SG_SAMPLERTYPE_FILTERING; - desc.samplers[0].msl_sampler_n = 0; - desc.texture_sampler_pairs[0].stage = SG_SHADERSTAGE_FRAGMENT; - desc.texture_sampler_pairs[0].view_slot = 1; - desc.texture_sampler_pairs[0].sampler_slot = 0; - desc.label = "world_text_prog_shader"; - } - return &desc; - } - return 0; -} diff --git a/samples/shaders/overlays/world_text.glsl b/samples/shaders/overlays/world_text.glsl deleted file mode 100644 index b371f29..0000000 --- a/samples/shaders/overlays/world_text.glsl +++ /dev/null @@ -1,144 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -// World-space text shader. Glyph coverage plus a distance field halo, the two -// channels of one atlas baked at the size labels draw at. -// -// One instance per glyph. Per-instance data (label anchor, pen rect, atlas -// UVs, color) lives in a storage buffer indexed by -// gl_InstanceIndex, the VS expands six vertices per instance from -// gl_VertexIndex with no VBO/IBO bound, same scheme as line.glsl and -// point.glsl. Quad corner order matches point.glsl: -// -// 0 -> (-1, -1) 3 -> (-1, -1) -// 1 -> (+1, -1) 4 -> (+1, +1) -// 2 -> (+1, +1) 5 -> (-1, +1) -// -// Glyphs are screen-aligned, not world-oriented: the anchor projects to -// clip space and the quad expands in pixels around it. Labels stay readable -// from any camera angle, which world-oriented text does not. -// -// Labels hold one pixel height whatever their distance, so a readout stays -// legible across a scene the way the ImGui labels this replaced did. They -// also ignore scene depth: a label names a thing, and a name you cannot read -// because a wall moved in front of it is worse than one that floats. -// -// The halo is why the field is still here. A rasterized bitmap gives the crisp -// body a distance field cannot at these sizes, but knows nothing about what -// lies outside a glyph, and the fading pad needs exactly that. One fetch reads -// both. The alternative in a UI draw list is re-emitting the whole string four -// times, and that only ever buys a hard outline. - -#pragma sokol @module world_text - -#pragma sokol @ctype mat4 Mat4 -#pragma sokol @ctype vec4 Vec4 - -#pragma sokol @vs vs - -layout(binding = 0)uniform ub_frame -{ - mat4 view; - mat4 proj; - mat4 view_proj; - mat4 inv_view_proj; - vec4 camera_pos; // .xyz = pos, .w = time - vec4 viewport; // .xy = size px, .zw = 1/size -}; - -struct glyph_instance -{ - vec4 anchor; // .xyz = label world anchor, .w unused - vec4 rect; // .xy = pen offset in pixels, .zw = glyph size in pixels - vec4 uv; // .xy = atlas uv min, .zw = atlas uv max - vec4 color; // linear RGBA, not premultiplied -}; - -layout(binding = 0) readonly buffer glyph_instances -{ - glyph_instance instances[]; -}; - -out vec2 v_uv; -flat out vec4 v_color; - -void main() -{ - glyph_instance inst = instances[gl_InstanceIndex]; - - int index = gl_VertexIndex; - float corner_x = ((index == 1)||(index == 2)||(index == 4)) ? 1.0 : -1.0; - float corner_y = ((index == 2)||(index == 4)||(index == 5)) ? 1.0 : -1.0; - vec2 corner = vec2(corner_x, corner_y) * 0.5 + 0.5; // 0..1 across the glyph cell - - vec4 clip_c = view_proj * vec4(inst.anchor.xyz, 1.0); - - // Snap the anchor to a whole pixel. Every glyph in a label then shares one - // pixel phase, so the horizontal strokes they have in common land on the - // grid together instead of each smearing by its own fraction of a pixel. - vec2 anchor_px = ((clip_c.xy / clip_c.w) * 0.5 + 0.5) * viewport.xy; - anchor_px = floor(anchor_px + 0.5); - - // Pen space runs Y down like the atlas and like the glyph metrics that - // produced the rect, clip space runs Y up, so flip on the way out. The rect - // is already whole pixels, so with a snapped anchor the quad covers its - // atlas cell one texel to one pixel. - vec2 pen_px = inst.rect.xy + corner * inst.rect.zw; - vec2 pos_px = anchor_px + vec2(pen_px.x, -pen_px.y); - vec2 pos_ndc = pos_px * viewport.zw * 2.0 - 1.0; - - // Back through the divide the rasterizer is about to do, so the snapped - // pixel position survives and depth / clipping stay as projected. - gl_Position = vec4(pos_ndc * clip_c.w, clip_c.z, clip_c.w); - v_uv = mix(inst.uv.xy, inst.uv.zw, corner); - v_color = inst.color; -} -#pragma sokol @end - -#pragma sokol @fs fs - -// Bindings are disjoint across storage buffers and textures for the whole -// program, so the glyph buffer's binding=0 in the VS pushes the atlas up. -#pragma sokol @image_sample_type tex_sdf float -layout(binding = 1)uniform texture2D tex_sdf; - -#pragma sokol @sampler_type smp_sdf filtering -layout(binding = 0)uniform sampler smp_sdf; - -layout(binding = 1)uniform ub_text_style -{ - vec4 style_params; // .x = halo width in pixels, .y = on-edge value, .z = distance per pixel, .w = reserved - vec4 halo_params; // .rgb = halo color, .a = halo strength at the glyph edge -}; - -in vec2 v_uv; -flat in vec4 v_color; -out vec4 out_color; - -void main() -{ - // R is glyph coverage, G a signed distance positive inside the glyph and - // biased by the on-edge value the atlas was baked with. - vec2 tap = texture(sampler2D(tex_sdf, smp_sdf), v_uv).rg; - float d = tap.g - style_params.y; - - // The body is the rasterizer's own coverage, sampled one texel to one pixel, - // so it needs no reconstruction here. That is the whole reason for the - // second channel: a distance field has to infer coverage from a smoothstep, - // and at label sizes that ramp is a large part of a stem. - float glyph = tap.r * v_color.a; - - // The halo fades outward from the glyph edge instead of ending at a fixed - // offset. A hard ring reads as a sticker outline and, worse, fills the - // counter of an o at label sizes, where the ring closes in from both - // sides. A falloff leaves the middle of the counter mostly clear. - float halo = (1.0 - smoothstep(0.0, style_params.x * style_params.z, -d)) * halo_params.a; - - // Glyph over halo, emitted premultiplied to match the blend state. - float alpha = glyph + halo * (1.0 - glyph); - vec3 rgb = v_color.rgb * glyph + halo_params.rgb * halo * (1.0 - glyph); - out_color = vec4(rgb, alpha); -} -#pragma sokol @end - -#pragma sokol @program prog vs fs diff --git a/samples/shaders/shapes/capsule.glsl b/samples/shaders/shapes/capsule.glsl index fcd148e..bad9bf5 100644 --- a/samples/shaders/shapes/capsule.glsl +++ b/samples/shaders/shapes/capsule.glsl @@ -131,7 +131,6 @@ void main() #pragma sokol @fs fs #pragma sokol @include ../common/pbr.glsl -#pragma sokol @include ../common/shadow_cascade.glsl layout( binding = 1 ) uniform ub_pass { @@ -141,11 +140,8 @@ layout( binding = 1 ) uniform ub_pass vec4 camera_pos; // .xyz = camera world pos, .w unused mat4 view_proj; // for reverse-Z gl_FragDepth mat4 view; // for view-space depth debug mode + cascade selection - vec4 cascade_far_view_z; // far view-space Z per cascade - vec4 cascade_texel_world; // one shadow texel in world units per cascade - vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade - vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV - mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved }; @@ -172,59 +168,75 @@ layout( binding = 4 ) uniform texture2D tex_ao; #pragma sokol @sampler_type smp_ao filtering layout( binding = 3 ) uniform sampler smp_ao; -#pragma sokol @include ../common/shadow_pcf.glsl +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} -// Normal-offset shadows, see cube.glsl for the longer note. float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) { - float texel_world = cascade_texel_world[cascade]; - float depth_bias = cascade_depth_bias[cascade]; - - // Shrink the kernel in the coarser cascades so the penumbra keeps a - // constant world width. See cube.glsl for the longer note. - float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 ); - - // Slide the lookup along the surface far enough to clear the whole - // scaled 7x7 footprint, growing toward grazing light. - float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); - float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) ); - float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world; - - vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 ); + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; // Backend-dependent Y orientation, see cube.glsl for the longer note. - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); - if ( light_uv.z < 0.0 || light_uv.z > 1.0 ) + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) { return 1.0; } - // The white border dissolves the XY boundary, only reject past the - // kernel's reach. See cube.glsl for the longer note. - float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y; - if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) ) + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) { - return 1.0; + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); } - return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y ); + return pcf; } float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) { - int cascade = selectShadowCascade( cascade_far_view_z, view_z ); + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; float shadow = sampleCascade( cascade, world_pos, world_normal ); // Blend the last 10% of each cascade's range with the next cascade // to hide the polygonal step where they meet. See cube.glsl for the // longer note. - if ( cascade < SHADOW_CASCADE_COUNT - 1 ) + if ( cascade < 2 ) { - float far_z = cascade_far_view_z[cascade]; - float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1]; + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; float blend_start = mix( far_z, near_z, 0.1 ); if ( view_z > blend_start ) { @@ -414,16 +426,25 @@ void main() if ( flags.x == 2 ) { float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z; - int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg ); + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); vec3 tint = vec3( 1.0 ); if ( !oob ) { - tint = shadowCascadeTint( cascade ); + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); } out_color = vec4( tint, 1.0 ); return; diff --git a/samples/shaders/shapes/cube.glsl b/samples/shaders/shapes/cube.glsl index c88b685..759d544 100644 --- a/samples/shaders/shapes/cube.glsl +++ b/samples/shaders/shapes/cube.glsl @@ -24,7 +24,7 @@ // debug_view_mode (ub_pass.flags.x) selects the output: // 0 = Lambert + ambient * shadow factor. // 1 = view-space distance from camera as grayscale. -// 2 = cascade-index tint (one color per cascade, white = UV +// 2 = cascade-index tint (red/green/blue = cascade 0/1/2, white = UV // out of bounds on the chosen cascade, i.e. unsampled). // // UBO bindings are stage-specific in sokol-shdc. @@ -101,22 +101,18 @@ void main() #pragma sokol @fs fs #pragma sokol @include ../common/pbr.glsl -#pragma sokol @include ../common/shadow_cascade.glsl layout( binding = 1 ) uniform ub_pass { - vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting - vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) - ivec4 flags; // .x = debug_view_mode - vec4 cascade_far_view_z; // far view-space Z per cascade - vec4 cascade_texel_world; // one shadow texel in world units per cascade - vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade - vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV - mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade - mat4 view; // IBL: world->view rotation for view->world n_view transform - vec4 camera_pos_world; // IBL: world camera pos for V_world derivation - vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) - vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved + vec4 sun_dir_view; // .xyz = view-space dir TO sun (normalized), for direct lighting + vec4 sun_color; // .rgb = color, .a = ambient strength (flat-ambient fallback) + ivec4 flags; // .x = debug_view_mode + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade + mat4 view; // IBL: world->view rotation for view->world n_view transform + vec4 camera_pos_world; // IBL: world camera pos for V_world derivation + vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) + vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved }; // binding=1 (not 0): sokol-shdc enforces disjoint binding numbers between @@ -154,96 +150,113 @@ flat in vec4 v_base_color; flat in vec4 v_material; out vec4 out_color; -// The comparison sampler returns 0..1 per tap (0 = occluded, 1 = lit). -// Kernel details and the X3570 unrolling note live in the include. -#pragma sokol @include ../common/shadow_pcf.glsl - -// Normal-offset shadows. A depth bias pushes the comparison back along -// the light, which detaches contact shadows and can never win at a -// silhouette where the stored depth gradient is effectively infinite. -// Moving the lookup sideways along the surface normal instead reads a -// well-behaved part of the map and leaves the compared depth alone, so -// contacts stay welded to the ground. -float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal, float n_dot_l ) +// 3x3 PCF over a 1-texel radius. The comparison sampler returns 0..1 +// per tap (0 = occluded, 1 = lit). Uniform 1/9 weighting. +// +// Manually unrolled: the HLSL compiler emits warning X3570 ("gradient +// instruction used in a loop with varying iteration") on the looped +// version because texture uses implicit derivatives. Unrolling here +// keeps cross-compilation clean on the D3D11 backend. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) { - float texel_world = cascade_texel_world[cascade]; - float depth_bias = cascade_depth_bias[cascade]; + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} - // Shrink the kernel in the coarser cascades so the penumbra keeps a - // constant world width instead of going crisp to blurry at every - // boundary. The floor leaves the taps about two texels apart, close - // enough that the hardware 2x2 compare still overlaps them. - float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 ); - - // Sine of the angle between surface and light. Zero facing the light - // where no offset is wanted, growing toward grazing. The offset has to - // clear the whole filter, not one texel, or the outer ring of the - // kernel self-shadows into a texel-quantized comb along the - // terminator. 3 texels is the scaled 7x7 half-width, plus the sampling - // snap, and the root two reaches the kernel's corner tap. - float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) ); - float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world; - - vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 ); +float sampleCascade( int cascade, vec3 world_pos, float n_dot_l ) +{ + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; // UV.y orientation is BACKEND-DEPENDENT. D3D11/Metal/WebGPU sample // render targets with V = 0 at the top (NDC.y = +1 -> texture row 0), // they need UV.y = 0.5 - NDC.y * 0.5. OpenGL samples with V = 0 at // the bottom (NDC.y = +1 -> top row N-1), it needs the textbook - // UV.y = NDC.y * 0.5 + 0.5. Renderer side sets the sign to -1 on - // D3D11/Metal/WGPU and +1 on glcore so a single multiply + // UV.y = NDC.y * 0.5 + 0.5. Renderer side sets cascade_far_view_z.w + // to -1 on D3D11/Metal/WGPU and +1 on glcore so a single multiply // here picks the right convention. - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); - if ( light_uv.z < 0.0 || light_uv.z > 1.0 ) + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) { return 1.0; } - // No hard XY bounds test. The sampler's white border makes taps past - // the edge compare lit, so the boundary dissolves across the kernel - // rather than flipping whole pixels between sampled and lit as the - // texel snap steps the map. Rejecting only what lies beyond the - // kernel's reach is exact and spares nine taps for everything well - // outside the cascade. - // - // The 3 * scale here and in the normal offset above both encode the - // 7x7 kernel's three-texel radius. Widen the kernel and both have to - // grow, or the outer ring self-shadows along the terminator. - float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y; - if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) ) + // Slope-scaled bias: tan(angle to light) = sqrt(1 - n.l^2) / n.l. + // Constant texel-step factor keeps the bias roughly the same world + // size across cascades (each cascade's depth range scales with its + // bounding sphere, bias scales with it via the texel step). + float ndl = clamp( n_dot_l, 0.001, 1.0 ); + float tanAngle = sqrt( 1.0 - ndl * ndl ) / ndl; + float texelDepthStep = 0.001; + float bias = clamp( texelDepthStep * tanAngle, 0.0005, 0.05 ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // Cascade 2 is the last cascade, sampleShadowCascaded's view-z blend + // has nothing to blend into beyond it. On flat ground at glancing sun + // angles PCF inside the cascade reads slightly below 1.0 (bias slop + // across a 3x3 kernel that covers ~5 cm of world per texel here), while + // fragments outside the cascade's spatial sphere fall through to the + // OOB return of 1.0. Without smoothing, cascade 2's UV boundary reads + // as a hexagonal polygon on the ground. Fade PCF toward 1.0 over the + // outer 10% of UV space to hide the seam. + if ( cascade == 2 ) { - return 1.0; + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); } - return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y ); + return pcf; } // n_dot_l is the (clamped) dot of the surface normal with the sun // direction, passed in by the caller in whichever space is convenient -// (rotation-invariant, same value in view and world space). The normal -// itself must be world space, it steers the normal offset. -float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float n_dot_l, float view_z ) +// (rotation-invariant, same value in view and world space). +float sampleShadowCascaded( vec3 world_pos, float n_dot_l, float view_z ) { - int cascade = selectShadowCascade( cascade_far_view_z, view_z ); + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + { + cascade = 0; + } + else if ( view_z < cascade_far_view_z.y ) + { + cascade = 1; + } - float shadow = sampleCascade( cascade, world_pos, world_normal, n_dot_l ); + float shadow = sampleCascade( cascade, world_pos, n_dot_l ); // Blend the last 10% of each cascade's range with the next cascade. - // Texel density jumps by roughly 2.5x at every boundary, so even with - // matched bias the penumbra width changes there. Without the blend - // that reads as a polygonal step on the ground. - if ( cascade < SHADOW_CASCADE_COUNT - 1 ) + // Each cascade uses the same slope-scaled bias in shadow-UV units, + // but cascades cover very different world extents (cascade 0 ~= 1 m, + // cascade 2 ~= 25 m+), so PCF response on flat receivers differs + // slightly per cascade, without this blend the boundary reads as a + // polygonal step on the ground at glancing sun angles. + if ( cascade < 2 ) { - float far_z = cascade_far_view_z[cascade]; - float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1]; + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; float blend_start = mix( far_z, near_z, 0.1 ); if ( view_z > blend_start ) { float alpha = ( view_z - blend_start ) / ( far_z - blend_start ); - shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, world_normal, n_dot_l ), alpha ); + shadow = mix( shadow, sampleCascade( cascade + 1, world_pos, n_dot_l ), alpha ); } } @@ -263,14 +276,14 @@ void main() // GL's dFdy points in +view_y (screen origin is lower-left), while HLSL // ddy and Metal dfdy point in -view_y (screen origin is upper-left). // sokol-shdc cross-compiles dFdy->ddy/dfdy without a sign flip, so the raw - // value's screen direction depends on the backend. shadow_params.x + // value's screen direction depends on the backend. cascade_far_view_z.w // is +1 on glcore/gles3 and -1 on D3D11/Metal/WGPU (same flag used by // the shadow UV.y remap below), negating it gives a multiplier that // canonicalizes dFdy to the -view_y direction on every backend. With // canonical dy, cross(dy, dx) = (-view_y) x (+view_x) = +view_z, which // points toward the camera (out of the screen), the correct outward // normal for a back-culled front face. - vec3 dy = dFdy( v_view_pos ) * ( -shadow_params.x ); + vec3 dy = dFdy( v_view_pos ) * ( -cascade_far_view_z.w ); vec3 n_view = normalize( cross( dy, dx ) ); float view_z = -v_view_pos.z; @@ -286,17 +299,36 @@ void main() // Debug view : shadow cascades if ( flags.x == 2 ) { - int cascade = selectShadowCascade( cascade_far_view_z, view_z ); + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + { + cascade = 0; + } + else if ( view_z < cascade_far_view_z.y ) + { + cascade = 1; + } vec4 light_clip = cascade_matrices[cascade] * vec4( v_world_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); vec3 tint = vec3( 1.0 ); if ( !oob ) { - tint = shadowCascadeTint( cascade ); + if ( cascade == 0 ) + { + tint = vec3( 1.0, 0.4, 0.4 ); + } + else if ( cascade == 1 ) + { + tint = vec3( 0.4, 1.0, 0.4 ); + } + else + { + tint = vec3( 0.4, 0.4, 1.0 ); + } } out_color = vec4( tint, 1.0 ); return; @@ -324,25 +356,23 @@ void main() return; } - // The shadow normal offset and IBL both need a world-space N. view is - // the world->view matrix, its 3x3 is orthonormal (camera rotation), so - // transpose(mat3(view)) takes view-space -> world-space without - // inverse cost. Stays clear of the D3D11 cross-product handedness trap - // that forced n_view to be computed in view space. Only rotate here, - // no derivatives. - mat3 view_to_world = transpose( mat3( view ) ); - vec3 N_world = normalize( view_to_world * n_view ); - // dot(n, L) is rotation-invariant. Same value with view-space or world-space // normals + sun directions. Use the view-space pair for direct light. vec3 L = normalize( sun_dir_view.xyz ); float n_dot_l = max( dot( n_view, L ), 0.0 ); - float shadow = sampleShadowCascaded( v_world_pos, N_world, n_dot_l, view_z ); + float shadow = sampleShadowCascaded( v_world_pos, n_dot_l, view_z ); // Camera sits at origin in view space, so V_view = normalize(-v_view_pos). vec3 V_view = normalize( -v_view_pos ); vec3 direct = brdf_evaluate( n_view, V_view, L, sun_color.rgb * shadow, v_base_color.rgb, v_material.x, v_material.y ); + // IBL needs world-space N and V. view is the world->view matrix, its + // 3x3 is orthonormal (camera rotation), so transpose(mat3(view)) + // takes view-space -> world-space without inverse cost. Stays clear + // of the D3D11 cross-product handedness trap that forced n_view to + // be computed in view space. Only rotate here, no derivatives. + mat3 view_to_world = transpose( mat3( view ) ); + vec3 N_world = normalize( view_to_world * n_view ); vec3 V_world = normalize( camera_pos_world.xyz - v_world_pos ); vec3 ambient = pbrEvaluateAmbient( ibl_params.y > 0.5, N_world, V_world, v_base_color.rgb, v_material.x, v_material.y, sun_color.a, sh, tex_ibl_spec, smp_ibl_spec, tex_brdf_lut, smp_brdf_lut, ibl_params.x ); diff --git a/samples/shaders/shapes/geom.glsl b/samples/shaders/shapes/geom.glsl index fed1141..fca8c3c 100644 --- a/samples/shaders/shapes/geom.glsl +++ b/samples/shaders/shapes/geom.glsl @@ -101,7 +101,6 @@ void main() #pragma sokol @fs fs #pragma sokol @include ../common/pbr.glsl -#pragma sokol @include ../common/shadow_cascade.glsl layout( binding = 1 ) uniform ub_pass { @@ -111,11 +110,8 @@ layout( binding = 1 ) uniform ub_pass vec4 camera_pos; // .xyz = camera world pos, .w unused vec4 grid_offset; // .xy = origin wrapped to grid period (lines), .zw = full origin (axes) mat4 view; // for view-space depth debug mode + cascade selection - vec4 cascade_far_view_z; // far view-space Z per cascade - vec4 cascade_texel_world; // one shadow texel in world units per cascade - vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade - vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV - mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved }; @@ -142,59 +138,75 @@ layout( binding = 4 ) uniform texture2D tex_ao; #pragma sokol @sampler_type smp_ao filtering layout( binding = 3 ) uniform sampler smp_ao; -#pragma sokol @include ../common/shadow_pcf.glsl +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} -// Normal-offset shadows, see cube.glsl for the longer note. float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) { - float texel_world = cascade_texel_world[cascade]; - float depth_bias = cascade_depth_bias[cascade]; - - // Shrink the kernel in the coarser cascades so the penumbra keeps a - // constant world width. See cube.glsl for the longer note. - float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 ); - - // Slide the lookup along the surface far enough to clear the whole - // scaled 7x7 footprint, growing toward grazing light. - float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); - float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) ); - float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world; - - vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 ); + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; // Backend-dependent Y orientation, see cube.glsl for the longer note. - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); - if ( light_uv.z < 0.0 || light_uv.z > 1.0 ) + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) { return 1.0; } - // The white border dissolves the XY boundary, only reject past the - // kernel's reach. See cube.glsl for the longer note. - float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y; - if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) ) + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) { - return 1.0; + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); } - return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y ); + return pcf; } float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) { - int cascade = selectShadowCascade( cascade_far_view_z, view_z ); + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; float shadow = sampleCascade( cascade, world_pos, world_normal ); // Blend the last 10% of each cascade's range with the next cascade // to hide the polygonal step where they meet. See cube.glsl for the // longer note. - if ( cascade < SHADOW_CASCADE_COUNT - 1 ) + if ( cascade < 2 ) { - float far_z = cascade_far_view_z[cascade]; - float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1]; + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; float blend_start = mix( far_z, near_z, 0.1 ); if ( view_z > blend_start ) { @@ -236,16 +248,25 @@ void main() { // v_view_pos is actually world_pos forwarded from the VS. float view_z_dbg = -( view * vec4( v_view_pos, 1.0 ) ).z; - int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg ); + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; vec4 light_clip = cascade_matrices[cascade] * vec4( v_view_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); vec3 tint = vec3( 1.0 ); if ( !oob ) { - tint = shadowCascadeTint( cascade ); + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); } out_color = vec4( tint, 1.0 ); return; diff --git a/samples/shaders/shapes/shadow_caster_capsule.glsl b/samples/shaders/shapes/shadow_caster_capsule.glsl index efd5190..be6cb62 100644 --- a/samples/shaders/shapes/shadow_caster_capsule.glsl +++ b/samples/shaders/shapes/shadow_caster_capsule.glsl @@ -1,18 +1,27 @@ // SPDX-FileCopyrightText: 2026 Erin Catto // SPDX-License-Identifier: MIT -// Shadow caster for capsules. See shadow_caster_sphere.glsl for why the -// analytic surface is worth the fill cost and what `depth_greater` rests -// on. +// Shadow caster for capsules. As with the sphere caster, we substitute +// a low-poly proxy mesh for the analytic impostor. The proxy is a +// 12-slice cylinder with two hemispherical caps. Vertices are authored in +// a "unit-capsule" coordinate frame where each component carries enough +// information to scale independently by halfLength and radius. // -// Rasterizes the same OBB the lit capsule impostor uses, half-extents -// (halfLength + radius, radius, radius) about the local +X axis. +// Each vertex is encoded as two attributes: +// in_axis, direction along the long axis (vec3). Scaled by halfLength. +// For body verts: (+/-1, 0, 0). For cap verts: same as the +// attached cap (i.e., (+1,0,0) for +X cap, (-1,0,0) for -X). +// in_radial, radial offset (vec3). Scaled by radius. For body verts: +// (0, cos theta, sin theta). For cap verts: an extension of the +// hemisphere parameterization that includes the cap's +// axial bulge, e.g. for +X cap at latitude alpha: in_radial = +// (sin alpha, cos alpha cos beta, cos alpha sin beta). // -// Only the entry point matters here, not the normal, so this is a -// cheaper intersection than the lit shader's. The capsule is the union -// of a finite cylinder and two cap spheres, and the entry into a union -// is the nearest entry across its parts, so the hemisphere-rejection -// the lit shader needs for correct normals is unnecessary. +// The world position is then +// world = center + R * (in_axis * halfLength + in_radial * radius) +// where R is the capsule's rotation. Since rotation is orthonormal and +// halfLength/radius are scalars, the encoding scales linearly and +// produces a true capsule for any (halfLength, radius) pair. // // `@module shadow_capsule` namespaces the generated symbols. @@ -51,14 +60,8 @@ layout( binding = 0 ) readonly buffer instances instance items[]; }; -in vec3 in_pos; // unit-cube corner, half-extent 0.5 - -out vec3 v_world_pos_proxy; - -flat out vec3 v_center; -flat out float v_half_length; -flat out float v_radius; -flat out vec3 v_axis_x_world; +in vec3 in_axis; // axis-direction component, scaled by halfLength +in vec3 in_radial; // radial component, scaled by radius void main() { @@ -67,120 +70,16 @@ void main() float halfLength = inst.params.x; float radius = inst.params.y; - vec3 obj_pos = vec3( in_pos.x * 2.0 * ( halfLength + radius ), in_pos.y * 2.0 * radius, in_pos.z * 2.0 * radius ); - vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, obj_pos ), dot( inst.xform_row1.xyz, obj_pos ), - dot( inst.xform_row2.xyz, obj_pos ) ); - - v_world_pos_proxy = world_pos; - v_center = center; - v_half_length = halfLength; - v_radius = radius; - // Local +X in world is the first column of R. - v_axis_x_world = vec3( inst.xform_row0.x, inst.xform_row1.x, inst.xform_row2.x ); - + vec3 local_pos = in_axis * halfLength + in_radial * radius; + vec3 world_pos = center + vec3( dot( inst.xform_row0.xyz, local_pos ), dot( inst.xform_row1.xyz, local_pos ), + dot( inst.xform_row2.xyz, local_pos ) ); gl_Position = light_view_proj * vec4( world_pos, 1.0 ); } #pragma sokol @end #pragma sokol @fs fs - -// UBOs are per-stage in sokol-shdc, so this is a second block rather -// than a reuse of the VS ub_frame. -layout( binding = 1 ) uniform ub_pass -{ - vec4 light_dir; // .xyz = world-space direction light travels (normalized) - vec4 depth_row; // depth row of the light view-proj, world position to clip depth -}; - -in vec3 v_world_pos_proxy; - -flat in vec3 v_center; -flat in float v_half_length; -flat in float v_radius; -flat in vec3 v_axis_x_world; - -layout( depth_greater ) out float gl_FragDepth; - void main() { - vec3 ro = v_world_pos_proxy; - vec3 rd = light_dir.xyz; - - vec3 pa = v_center - v_half_length * v_axis_x_world; - vec3 pb = v_center + v_half_length * v_axis_x_world; - - // Ray-cylinder, Quilez closed form. - // Reference: https://iquilezles.org/articles/intersectors/ - vec3 ba = pb - pa; - vec3 oa = ro - pa; - float baba = dot( ba, ba ); - float bard = dot( ba, rd ); - float baoa = dot( ba, oa ); - float rdoa = dot( rd, oa ); - float oaoa = dot( oa, oa ); - - float a_c = baba - bard * bard; - float b_c = baba * rdoa - baoa * bard; - float c_c = baba * oaoa - baoa * baoa - v_radius * v_radius * baba; - float h_c = b_c * b_c - a_c * c_c; - - float t = -1.0; - - // Entry into each part, clamped forward rather than rejected. The - // proxy faces are tangent to the surface along a line, and rounding - // there puts the origin a hair inside, which drives the near root - // negative. Treating that as a miss punches a dashed hole straight - // down the middle of the shadow. A part whose far root is behind us - // too is a genuine miss, which is what the end faces need: they sit - // beyond one cap and the other cap is legitimately behind. - // - // a_c collapses when the ray runs along the axis, the caps cover - // that case. baba collapses when halfLength is zero, and the axial - // range test rejects the body for free. - if ( h_c >= 0.0 && a_c > 1e-8 ) - { - float q = sqrt( h_c ); - if ( -b_c + q >= 0.0 ) - { - float t_body = max( ( -b_c - q ) / a_c, 0.0 ); - float y = baoa + t_body * bard; - if ( y > 0.0 && y < baba ) - { - t = t_body; - } - } - } - - // Cap spheres at both ends. - for ( int i = 0; i < 2; ++i ) - { - vec3 p = ( i == 0 ) ? pa : pb; - vec3 oc = ro - p; - float b = dot( oc, rd ); - float c = dot( oc, oc ) - v_radius * v_radius; - float h = b * b - c; - if ( h >= 0.0 ) - { - float q = sqrt( h ); - if ( -b + q >= 0.0 ) - { - float tc = max( -b - q, 0.0 ); - if ( t < 0.0 || tc < t ) - { - t = tc; - } - } - } - } - - if ( t < 0.0 ) - { - // OBB corner, the ray clears the capsule. - discard; - } - - // Orthographic light, so the clip w is 1 and the divide drops out. - gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) ); } #pragma sokol @end diff --git a/samples/shaders/shapes/shadow_caster_sphere.glsl b/samples/shaders/shapes/shadow_caster_sphere.glsl index 1ff69a4..f3738e7 100644 --- a/samples/shaders/shapes/shadow_caster_sphere.glsl +++ b/samples/shaders/shapes/shadow_caster_sphere.glsl @@ -1,36 +1,17 @@ // SPDX-FileCopyrightText: 2026 Erin Catto // SPDX-License-Identifier: MIT -// Shadow caster for spheres. Rasterizes the same bounding cube the lit -// impostor uses and ray-casts the exact sphere, so caster and receiver -// agree on where the surface is and bias only has to cover projection -// and PCF slope. An inscribed proxy mesh falls short of the true surface -// by a couple percent of the radius, and that gap has to be paid for -// with extra depth bias. +// Shadow caster for spheres. The lit sphere pipeline ray-casts an +// analytic sphere from a bounding-cube proxy, but we can't afford to +// write gl_FragDepth in a depth-only shadow pass (early-Z killed, high +// shadow-map resolution makes the cost prohibitive). Instead the shadow +// pipeline rasterizes a low-poly icosphere proxy (subdiv-1, 42 verts, 80 +// tris) generated at InitRenderer and stored in dedicated icosphere vbuf/ibuf. // -// The light is directional, so every ray is parallel: the origin is the -// proxy fragment's world position and the direction is the direction -// light travels. Under an orthographic projection depth is linear in -// distance along that direction, so marching forward from the proxy -// face can only push depth away from the light. Hence -// `layout(depth_greater)`, which lets the hardware keep early-Z -// rejection despite the gl_FragDepth write. The promise rests on the -// pipeline culling back faces, so the rasterized surface is always the -// light-facing one. -// -// Depth is rebuilt from the projection's depth row rather than advanced -// from gl_FragCoord.z, which would be one madd instead of a dot4. D3D11 -// rejects a pixel shader that both reads SV_Position and writes -// conservative depth unless the position input is declared -// noperspective centroid or sample, and neither GLSL nor SPIRV-Cross -// gives us a way to qualify it. The two agree to within rounding: the -// only place they can disagree is the single point where the proxy face -// is tangent to the surface. -// -// Per-instance reads from the same sphere instance buffer the lit -// pipeline uses. The rotation rows are ignored (a sphere is -// rotation-invariant) and only the center (xform_row*.w) and radius -// (params.x) participate. +// Per-vertex: in_pos is a unit-sphere position (length == 1). Per-instance +// reads from the same sphere instance buffer the lit pipeline uses, the +// rotation rows are ignored (a sphere is rotation-invariant) and only +// the center (xform_row*.w) and radius (params.x) participate. // // `@module shadow_sphere` namespaces the generated symbols. @@ -69,70 +50,21 @@ layout( binding = 0 ) readonly buffer instances instance items[]; }; -in vec3 in_pos; // unit-cube corner, half-extent 0.5 - -out vec3 v_world_pos_proxy; - -flat out vec3 v_center; -flat out float v_radius; +in vec3 in_pos; // unit-icosphere vertex (length == 1) void main() { instance inst = items[inst_base.x + gl_InstanceIndex]; vec3 center = vec3( inst.xform_row0.w, inst.xform_row1.w, inst.xform_row2.w ); float radius = inst.params.x; - - // Half-extent 0.5 scaled by 2*radius gives a cube exactly enclosing - // the sphere. Rotation is skipped, a sphere is rotation-invariant. - vec3 world_pos = center + ( 2.0 * radius ) * in_pos; - - v_world_pos_proxy = world_pos; - v_center = center; - v_radius = radius; - + vec3 world_pos = center + radius * in_pos; gl_Position = light_view_proj * vec4( world_pos, 1.0 ); } #pragma sokol @end #pragma sokol @fs fs - -// UBOs are per-stage in sokol-shdc, so this is a second block rather -// than a reuse of the VS ub_frame. -layout( binding = 1 ) uniform ub_pass -{ - vec4 light_dir; // .xyz = world-space direction light travels (normalized) - vec4 depth_row; // depth row of the light view-proj, world position to clip depth -}; - -in vec3 v_world_pos_proxy; - -flat in vec3 v_center; -flat in float v_radius; - -layout( depth_greater ) out float gl_FragDepth; - void main() { - vec3 ro = v_world_pos_proxy; - vec3 rd = light_dir.xyz; - - // Ray-sphere, near root. Reference: https://iquilezles.org/articles/intersectors/ - vec3 oc = ro - v_center; - float b = dot( oc, rd ); - float c = dot( oc, oc ) - v_radius * v_radius; - float h = b * b - c; - if ( h < 0.0 ) - { - // Cube corner, the ray clears the sphere. - discard; - } - - // Non-negative because the proxy face is tangent to the sphere at - // worst, never inside it. - float t = max( -b - sqrt( h ), 0.0 ); - - // Orthographic light, so the clip w is 1 and the divide drops out. - gl_FragDepth = dot( depth_row, vec4( ro + t * rd, 1.0 ) ); } #pragma sokol @end diff --git a/samples/shaders/shapes/sphere.glsl b/samples/shaders/shapes/sphere.glsl index c1f1606..64cc2e8 100644 --- a/samples/shaders/shapes/sphere.glsl +++ b/samples/shaders/shapes/sphere.glsl @@ -128,7 +128,6 @@ void main() #pragma sokol @fs fs #pragma sokol @include ../common/pbr.glsl -#pragma sokol @include ../common/shadow_cascade.glsl layout( binding = 1 ) uniform ub_pass { @@ -138,11 +137,8 @@ layout( binding = 1 ) uniform ub_pass vec4 camera_pos; // .xyz = camera world pos, .w unused mat4 view_proj; // for reverse-Z gl_FragDepth mat4 view; // for view-space depth debug mode + cascade selection - vec4 cascade_far_view_z; // far view-space Z per cascade - vec4 cascade_texel_world; // one shadow texel in world units per cascade - vec4 cascade_depth_bias; // residual comparison bias in shadow clip-Z per cascade - vec4 shadow_params; // .x = UV.y sign, .y = one texel in UV - mat4 cascade_matrices[SHADOW_CASCADE_COUNT]; // light-space view-proj per cascade + vec4 cascade_far_view_z; // .xyz = far view-space Z per cascade + mat4 cascade_matrices[3]; // light-space view-proj per cascade vec4 sh[9]; // IBL diffuse SH coefficients (band 0..2, RGB in .xyz) vec4 ibl_params; // .x = prefilter cube max_lod, .y = IBL enable (1=IBL, 0=flat ambient), .zw reserved }; @@ -169,59 +165,75 @@ layout( binding = 4 ) uniform texture2D tex_ao; #pragma sokol @sampler_type smp_ao filtering layout( binding = 3 ) uniform sampler smp_ao; -#pragma sokol @include ../common/shadow_pcf.glsl +// 3x3 PCF over a 1-texel radius. Manually unrolled, see cube.glsl for +// the X3570 rationale. +float sampleShadowPCF( int cascade, vec3 light_uv, float bias ) +{ + float t = 1.0 / 2048.0; + float ly = float( cascade ); + float rz = light_uv.z - bias; + vec2 c = light_uv.xy; + float s = 0.0; + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y - t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x - t, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x, c.y + t, ly, rz ) ); + s += texture( sampler2DArrayShadow( tex_shadow, smp_shadow ), vec4( c.x + t, c.y + t, ly, rz ) ); + return s / 9.0; +} -// Normal-offset shadows, see cube.glsl for the longer note. float sampleCascade( int cascade, vec3 world_pos, vec3 world_normal ) { - float texel_world = cascade_texel_world[cascade]; - float depth_bias = cascade_depth_bias[cascade]; - - // Shrink the kernel in the coarser cascades so the penumbra keeps a - // constant world width. See cube.glsl for the longer note. - float scale = clamp( cascade_texel_world.x / texel_world, 0.25, 1.0 ); - - // Slide the lookup along the surface far enough to clear the whole - // scaled 7x7 footprint, growing toward grazing light. - float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); - float sin_theta = sqrt( max( 1.0 - n_dot_l * n_dot_l, 0.0 ) ); - float offset = ( 3.0 * scale + 0.5 ) * 1.41421 * sin_theta * texel_world; - - vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos + world_normal * offset, 1.0 ); + vec4 light_clip = cascade_matrices[cascade] * vec4( world_pos, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; // Backend-dependent Y orientation, see cube.glsl for the longer note. - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); - if ( light_uv.z < 0.0 || light_uv.z > 1.0 ) + if ( any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ) ) { return 1.0; } - // The white border dissolves the XY boundary, only reject past the - // kernel's reach. See cube.glsl for the longer note. - float reach = ( 3.0 * scale + 1.0 ) * shadow_params.y; - if ( any( lessThan( light_uv.xy, vec2( -reach ) ) ) || any( greaterThan( light_uv.xy, vec2( 1.0 + reach ) ) ) ) + float n_dot_l = max( dot( world_normal, normalize( sun_dir_world.xyz ) ), 0.0 ); + float bias = mix( 0.0040, 0.0008, n_dot_l ); + + float pcf = sampleShadowPCF( cascade, light_uv, bias ); + + // See cube.glsl for the longer note. Cascade 2 has no fallback at its + // UV boundary, so fade PCF toward 1.0 over the outer 10% to hide the + // polygonal seam where cascade 2's spatial extent ends on the ground. + if ( cascade == 2 ) { - return 1.0; + vec2 edge = min( light_uv.xy, 1.0 - light_uv.xy ); + float fade = clamp( min( edge.x, edge.y ) * 10.0, 0.0, 1.0 ); + pcf = mix( 1.0, pcf, fade ); } - return sampleShadowPCF( tex_shadow, smp_shadow, cascade, light_uv, depth_bias, scale, shadow_params.y ); + return pcf; } float sampleShadowCascaded( vec3 world_pos, vec3 world_normal, float view_z ) { - int cascade = selectShadowCascade( cascade_far_view_z, view_z ); + int cascade = 2; + if ( view_z < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z < cascade_far_view_z.y ) + cascade = 1; float shadow = sampleCascade( cascade, world_pos, world_normal ); // Blend the last 10% of each cascade's range with the next cascade // to hide the polygonal step where they meet. See cube.glsl for the // longer note. - if ( cascade < SHADOW_CASCADE_COUNT - 1 ) + if ( cascade < 2 ) { - float far_z = cascade_far_view_z[cascade]; - float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z[cascade - 1]; + float far_z = ( cascade == 0 ) ? cascade_far_view_z.x : cascade_far_view_z.y; + float near_z = ( cascade == 0 ) ? 0.0 : cascade_far_view_z.x; float blend_start = mix( far_z, near_z, 0.1 ); if ( view_z > blend_start ) { @@ -343,16 +355,25 @@ void main() if ( flags.x == 2 ) { float view_z_dbg = -( view * vec4( hit_world, 1.0 ) ).z; - int cascade = selectShadowCascade( cascade_far_view_z, view_z_dbg ); + int cascade = 2; + if ( view_z_dbg < cascade_far_view_z.x ) + cascade = 0; + else if ( view_z_dbg < cascade_far_view_z.y ) + cascade = 1; vec4 light_clip = cascade_matrices[cascade] * vec4( hit_world, 1.0 ); vec3 light_ndc = light_clip.xyz / light_clip.w; - float ny = light_ndc.y * shadow_params.x; + float ny = light_ndc.y * cascade_far_view_z.w; vec3 light_uv = vec3( light_ndc.x * 0.5 + 0.5, ny * 0.5 + 0.5, light_ndc.z ); bool oob = any( lessThan( light_uv, vec3( 0.0 ) ) ) || any( greaterThan( light_uv, vec3( 1.0 ) ) ); vec3 tint = vec3( 1.0 ); if ( !oob ) { - tint = shadowCascadeTint( cascade ); + if ( cascade == 0 ) + tint = vec3( 1.0, 0.4, 0.4 ); + else if ( cascade == 1 ) + tint = vec3( 0.4, 1.0, 0.4 ); + else + tint = vec3( 0.4, 0.4, 1.0 ); } out_color = vec4( tint, 1.0 ); return; diff --git a/samples/stb_truetype.h b/samples/stb_truetype.h deleted file mode 100644 index 90a5c2e..0000000 --- a/samples/stb_truetype.h +++ /dev/null @@ -1,5079 +0,0 @@ -// stb_truetype.h - v1.26 - public domain -// authored from 2009-2021 by Sean Barrett / RAD Game Tools -// -// ======================================================================= -// -// NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES -// -// This library does no range checking of the offsets found in the file, -// meaning an attacker can use it to read arbitrary memory. -// -// ======================================================================= -// -// This library processes TrueType files: -// parse files -// extract glyph metrics -// extract glyph shapes -// render glyphs to one-channel bitmaps with antialiasing (box filter) -// render glyphs to one-channel SDF bitmaps (signed-distance field/function) -// -// Todo: -// non-MS cmaps -// crashproof on bad data -// hinting? (no longer patented) -// cleartype-style AA? -// optimize: use simple memory allocator for intermediates -// optimize: build edge-list directly from curves -// optimize: rasterize directly from curves? -// -// ADDITIONAL CONTRIBUTORS -// -// Mikko Mononen: compound shape support, more cmap formats -// Tor Andersson: kerning, subpixel rendering -// Dougall Johnson: OpenType / Type 2 font handling -// Daniel Ribeiro Maciel: basic GPOS-based kerning -// -// Misc other: -// Ryan Gordon -// Simon Glass -// github:IntellectualKitty -// Imanol Celaya -// Daniel Ribeiro Maciel -// -// Bug/warning reports/fixes: -// "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe -// Cass Everitt Martins Mozeiko github:aloucks -// stoiko (Haemimont Games) Cap Petschulat github:oyvindjam -// Brian Hook Omar Cornut github:vassvik -// Walter van Niftrik Ryan Griege -// David Gow Peter LaValle -// David Given Sergey Popov -// Ivan-Assen Ivanov Giumo X. Clanjor -// Anthony Pesch Higor Euripedes -// Johan Duparc Thomas Fields -// Hou Qiming Derek Vinyard -// Rob Loach Cort Stratton -// Kenney Phillis Jr. Brian Costabile -// Ken Voskuil (kaesve) Yakov Galka -// -// VERSION HISTORY -// -// 1.26 (2021-08-28) fix broken rasterizer -// 1.25 (2021-07-11) many fixes -// 1.24 (2020-02-05) fix warning -// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) -// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined -// 1.21 (2019-02-25) fix warning -// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() -// 1.19 (2018-02-11) GPOS kerning, STBTT_fmod -// 1.18 (2018-01-29) add missing function -// 1.17 (2017-07-23) make more arguments const; doc fix -// 1.16 (2017-07-12) SDF support -// 1.15 (2017-03-03) make more arguments const -// 1.14 (2017-01-16) num-fonts-in-TTC function -// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts -// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual -// 1.11 (2016-04-02) fix unused-variable warning -// 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef -// 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use allocation userdata properly -// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges -// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; -// variant PackFontRanges to pack and render in separate phases; -// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); -// fixed an assert() bug in the new rasterizer -// replace assert() with STBTT_assert() in new rasterizer -// -// Full history can be found at the end of this file. -// -// LICENSE -// -// See end of file for license information. -// -// USAGE -// -// Include this file in whatever places need to refer to it. In ONE C/C++ -// file, write: -// #define STB_TRUETYPE_IMPLEMENTATION -// before the #include of this file. This expands out the actual -// implementation into that C/C++ file. -// -// To make the implementation private to the file that generates the implementation, -// #define STBTT_STATIC -// -// Simple 3D API (don't ship this, but it's fine for tools and quick start) -// stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture -// stbtt_GetBakedQuad() -- compute quad to draw for a given char -// -// Improved 3D API (more shippable): -// #include "stb_rect_pack.h" -- optional, but you really want it -// stbtt_PackBegin() -// stbtt_PackSetOversampling() -- for improved quality on small fonts -// stbtt_PackFontRanges() -- pack and renders -// stbtt_PackEnd() -// stbtt_GetPackedQuad() -// -// "Load" a font file from a memory buffer (you have to keep the buffer loaded) -// stbtt_InitFont() -// stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections -// stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections -// -// Render a unicode codepoint to a bitmap -// stbtt_GetCodepointBitmap() -- allocates and returns a bitmap -// stbtt_MakeCodepointBitmap() -- renders into bitmap you provide -// stbtt_GetCodepointBitmapBox() -- how big the bitmap must be -// -// Character advance/positioning -// stbtt_GetCodepointHMetrics() -// stbtt_GetFontVMetrics() -// stbtt_GetFontVMetricsOS2() -// stbtt_GetCodepointKernAdvance() -// -// Starting with version 1.06, the rasterizer was replaced with a new, -// faster and generally-more-precise rasterizer. The new rasterizer more -// accurately measures pixel coverage for anti-aliasing, except in the case -// where multiple shapes overlap, in which case it overestimates the AA pixel -// coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If -// this turns out to be a problem, you can re-enable the old rasterizer with -// #define STBTT_RASTERIZER_VERSION 1 -// which will incur about a 15% speed hit. -// -// ADDITIONAL DOCUMENTATION -// -// Immediately after this block comment are a series of sample programs. -// -// After the sample programs is the "header file" section. This section -// includes documentation for each API function. -// -// Some important concepts to understand to use this library: -// -// Codepoint -// Characters are defined by unicode codepoints, e.g. 65 is -// uppercase A, 231 is lowercase c with a cedilla, 0x7e30 is -// the hiragana for "ma". -// -// Glyph -// A visual character shape (every codepoint is rendered as -// some glyph) -// -// Glyph index -// A font-specific integer ID representing a glyph -// -// Baseline -// Glyph shapes are defined relative to a baseline, which is the -// bottom of uppercase characters. Characters extend both above -// and below the baseline. -// -// Current Point -// As you draw text to the screen, you keep track of a "current point" -// which is the origin of each character. The current point's vertical -// position is the baseline. Even "baked fonts" use this model. -// -// Vertical Font Metrics -// The vertical qualities of the font, used to vertically position -// and space the characters. See docs for stbtt_GetFontVMetrics. -// -// Font Size in Pixels or Points -// The preferred interface for specifying font sizes in stb_truetype -// is to specify how tall the font's vertical extent should be in pixels. -// If that sounds good enough, skip the next paragraph. -// -// Most font APIs instead use "points", which are a common typographic -// measurement for describing font size, defined as 72 points per inch. -// stb_truetype provides a point API for compatibility. However, true -// "per inch" conventions don't make much sense on computer displays -// since different monitors have different number of pixels per -// inch. For example, Windows traditionally uses a convention that -// there are 96 pixels per inch, thus making 'inch' measurements have -// nothing to do with inches, and thus effectively defining a point to -// be 1.333 pixels. Additionally, the TrueType font data provides -// an explicit scale factor to scale a given font's glyphs to points, -// but the author has observed that this scale factor is often wrong -// for non-commercial fonts, thus making fonts scaled in points -// according to the TrueType spec incoherently sized in practice. -// -// DETAILED USAGE: -// -// Scale: -// Select how high you want the font to be, in points or pixels. -// Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute -// a scale factor SF that will be used by all other functions. -// -// Baseline: -// You need to select a y-coordinate that is the baseline of where -// your text will appear. Call GetFontBoundingBox to get the baseline-relative -// bounding box for all characters. SF*-y0 will be the distance in pixels -// that the worst-case character could extend above the baseline, so if -// you want the top edge of characters to appear at the top of the -// screen where y=0, then you would set the baseline to SF*-y0. -// -// Current point: -// Set the current point where the first character will appear. The -// first character could extend left of the current point; this is font -// dependent. You can either choose a current point that is the leftmost -// point and hope, or add some padding, or check the bounding box or -// left-side-bearing of the first character to be displayed and set -// the current point based on that. -// -// Displaying a character: -// Compute the bounding box of the character. It will contain signed values -// relative to . I.e. if it returns x0,y0,x1,y1, -// then the character should be displayed in the rectangle from -// to = 32 && *text < 128) { - stbtt_aligned_quad q; - stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9 - glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0); - glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0); - glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1); - glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1); - } - ++text; - } - glEnd(); -} -#endif -// -// -////////////////////////////////////////////////////////////////////////////// -// -// Complete program (this compiles): get a single bitmap, print as ASCII art -// -#if 0 -#include -#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation -#include "stb_truetype.h" - -char ttf_buffer[1<<25]; - -int main(int argc, char **argv) -{ - stbtt_fontinfo font; - unsigned char *bitmap; - int w,h,i,j,c = (argc > 1 ? atoi(argv[1]) : 'a'), s = (argc > 2 ? atoi(argv[2]) : 20); - - fread(ttf_buffer, 1, 1<<25, fopen(argc > 3 ? argv[3] : "c:/windows/fonts/arialbd.ttf", "rb")); - - stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer,0)); - bitmap = stbtt_GetCodepointBitmap(&font, 0,stbtt_ScaleForPixelHeight(&font, s), c, &w, &h, 0,0); - - for (j=0; j < h; ++j) { - for (i=0; i < w; ++i) - putchar(" .:ioVM@"[bitmap[j*w+i]>>5]); - putchar('\n'); - } - return 0; -} -#endif -// -// Output: -// -// .ii. -// @@@@@@. -// V@Mio@@o -// :i. V@V -// :oM@@M -// :@@@MM@M -// @@o o@M -// :@@. M@M -// @@@o@@@@ -// :M@@V:@@. -// -////////////////////////////////////////////////////////////////////////////// -// -// Complete program: print "Hello World!" banner, with bugs -// -#if 0 -char buffer[24<<20]; -unsigned char screen[20][79]; - -int main(int arg, char **argv) -{ - stbtt_fontinfo font; - int i,j,ascent,baseline,ch=0; - float scale, xpos=2; // leave a little padding in case the character extends left - char *text = "Heljo World!"; // intentionally misspelled to show 'lj' brokenness - - fread(buffer, 1, 1000000, fopen("c:/windows/fonts/arialbd.ttf", "rb")); - stbtt_InitFont(&font, buffer, 0); - - scale = stbtt_ScaleForPixelHeight(&font, 15); - stbtt_GetFontVMetrics(&font, &ascent,0,0); - baseline = (int) (ascent*scale); - - while (text[ch]) { - int advance,lsb,x0,y0,x1,y1; - float x_shift = xpos - (float) floor(xpos); - stbtt_GetCodepointHMetrics(&font, text[ch], &advance, &lsb); - stbtt_GetCodepointBitmapBoxSubpixel(&font, text[ch], scale,scale,x_shift,0, &x0,&y0,&x1,&y1); - stbtt_MakeCodepointBitmapSubpixel(&font, &screen[baseline + y0][(int) xpos + x0], x1-x0,y1-y0, 79, scale,scale,x_shift,0, text[ch]); - // note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong - // because this API is really for baking character bitmaps into textures. if you want to render - // a sequence of characters, you really need to render each bitmap to a temp buffer, then - // "alpha blend" that into the working buffer - xpos += (advance * scale); - if (text[ch+1]) - xpos += scale*stbtt_GetCodepointKernAdvance(&font, text[ch],text[ch+1]); - ++ch; - } - - for (j=0; j < 20; ++j) { - for (i=0; i < 78; ++i) - putchar(" .:ioVM@"[screen[j][i]>>5]); - putchar('\n'); - } - - return 0; -} -#endif - - -////////////////////////////////////////////////////////////////////////////// -////////////////////////////////////////////////////////////////////////////// -//// -//// INTEGRATION WITH YOUR CODEBASE -//// -//// The following sections allow you to supply alternate definitions -//// of C library functions used by stb_truetype, e.g. if you don't -//// link with the C runtime library. - -#ifdef STB_TRUETYPE_IMPLEMENTATION - // #define your own (u)stbtt_int8/16/32 before including to override this - #ifndef stbtt_uint8 - typedef unsigned char stbtt_uint8; - typedef signed char stbtt_int8; - typedef unsigned short stbtt_uint16; - typedef signed short stbtt_int16; - typedef unsigned int stbtt_uint32; - typedef signed int stbtt_int32; - #endif - - typedef char stbtt__check_size32[sizeof(stbtt_int32)==4 ? 1 : -1]; - typedef char stbtt__check_size16[sizeof(stbtt_int16)==2 ? 1 : -1]; - - // e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h - #ifndef STBTT_ifloor - #include - #define STBTT_ifloor(x) ((int) floor(x)) - #define STBTT_iceil(x) ((int) ceil(x)) - #endif - - #ifndef STBTT_sqrt - #include - #define STBTT_sqrt(x) sqrt(x) - #define STBTT_pow(x,y) pow(x,y) - #endif - - #ifndef STBTT_fmod - #include - #define STBTT_fmod(x,y) fmod(x,y) - #endif - - #ifndef STBTT_cos - #include - #define STBTT_cos(x) cos(x) - #define STBTT_acos(x) acos(x) - #endif - - #ifndef STBTT_fabs - #include - #define STBTT_fabs(x) fabs(x) - #endif - - // #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h - #ifndef STBTT_malloc - #include - #define STBTT_malloc(x,u) ((void)(u),malloc(x)) - #define STBTT_free(x,u) ((void)(u),free(x)) - #endif - - #ifndef STBTT_assert - #include - #define STBTT_assert(x) assert(x) - #endif - - #ifndef STBTT_strlen - #include - #define STBTT_strlen(x) strlen(x) - #endif - - #ifndef STBTT_memcpy - #include - #define STBTT_memcpy memcpy - #define STBTT_memset memset - #endif -#endif - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -//// -//// INTERFACE -//// -//// - -#ifndef __STB_INCLUDE_STB_TRUETYPE_H__ -#define __STB_INCLUDE_STB_TRUETYPE_H__ - -#ifdef STBTT_STATIC -#define STBTT_DEF static -#else -#define STBTT_DEF extern -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// private structure -typedef struct -{ - unsigned char *data; - int cursor; - int size; -} stbtt__buf; - -////////////////////////////////////////////////////////////////////////////// -// -// TEXTURE BAKING API -// -// If you use this API, you only have to call two functions ever. -// - -typedef struct -{ - unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap - float xoff,yoff,xadvance; -} stbtt_bakedchar; - -STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, // font location (use offset=0 for plain .ttf) - float pixel_height, // height of font in pixels - unsigned char *pixels, int pw, int ph, // bitmap to be filled in - int first_char, int num_chars, // characters to bake - stbtt_bakedchar *chardata); // you allocate this, it's num_chars long -// if return is positive, the first unused row of the bitmap -// if return is negative, returns the negative of the number of characters that fit -// if return is 0, no characters fit and no rows were used -// This uses a very crappy packing. - -typedef struct -{ - float x0,y0,s0,t0; // top-left - float x1,y1,s1,t1; // bottom-right -} stbtt_aligned_quad; - -STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, // same data as above - int char_index, // character to display - float *xpos, float *ypos, // pointers to current position in screen pixel space - stbtt_aligned_quad *q, // output: quad to draw - int opengl_fillrule); // true if opengl fill rule; false if DX9 or earlier -// Call GetBakedQuad with char_index = 'character - first_char', and it -// creates the quad you need to draw and advances the current position. -// -// The coordinate system used assumes y increases downwards. -// -// Characters will extend both above and below the current position; -// see discussion of "BASELINE" above. -// -// It's inefficient; you might want to c&p it and optimize it. - -STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap); -// Query the font vertical metrics without having to create a font first. - - -////////////////////////////////////////////////////////////////////////////// -// -// NEW TEXTURE BAKING API -// -// This provides options for packing multiple fonts into one atlas, not -// perfectly but better than nothing. - -typedef struct -{ - unsigned short x0,y0,x1,y1; // coordinates of bbox in bitmap - float xoff,yoff,xadvance; - float xoff2,yoff2; -} stbtt_packedchar; - -typedef struct stbtt_pack_context stbtt_pack_context; -typedef struct stbtt_fontinfo stbtt_fontinfo; -#ifndef STB_RECT_PACK_VERSION -typedef struct stbrp_rect stbrp_rect; -#endif - -STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int width, int height, int stride_in_bytes, int padding, void *alloc_context); -// Initializes a packing context stored in the passed-in stbtt_pack_context. -// Future calls using this context will pack characters into the bitmap passed -// in here: a 1-channel bitmap that is width * height. stride_in_bytes is -// the distance from one row to the next (or 0 to mean they are packed tightly -// together). "padding" is the amount of padding to leave between each -// character (normally you want '1' for bitmaps you'll use as textures with -// bilinear filtering). -// -// Returns 0 on failure, 1 on success. - -STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc); -// Cleans up the packing context and frees all memory. - -#define STBTT_POINT_SIZE(x) (-(x)) - -STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_char_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range); -// Creates character bitmaps from the font_index'th font found in fontdata (use -// font_index=0 if you don't know what that is). It creates num_chars_in_range -// bitmaps for characters with unicode values starting at first_unicode_char_in_range -// and increasing. Data for how to render them is stored in chardata_for_range; -// pass these to stbtt_GetPackedQuad to get back renderable quads. -// -// font_size is the full height of the character from ascender to descender, -// as computed by stbtt_ScaleForPixelHeight. To use a point size as computed -// by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE() -// and pass that result as 'font_size': -// ..., 20 , ... // font max minus min y is 20 pixels tall -// ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall - -typedef struct -{ - float font_size; - int first_unicode_codepoint_in_range; // if non-zero, then the chars are continuous, and this is the first codepoint - int *array_of_unicode_codepoints; // if non-zero, then this is an array of unicode codepoints - int num_chars; - stbtt_packedchar *chardata_for_range; // output - unsigned char h_oversample, v_oversample; // don't set these, they're used internally -} stbtt_pack_range; - -STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges); -// Creates character bitmaps from multiple ranges of characters stored in -// ranges. This will usually create a better-packed bitmap than multiple -// calls to stbtt_PackFontRange. Note that you can call this multiple -// times within a single PackBegin/PackEnd. - -STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample); -// Oversampling a font increases the quality by allowing higher-quality subpixel -// positioning, and is especially valuable at smaller text sizes. -// -// This function sets the amount of oversampling for all following calls to -// stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given -// pack context. The default (no oversampling) is achieved by h_oversample=1 -// and v_oversample=1. The total number of pixels required is -// h_oversample*v_oversample larger than the default; for example, 2x2 -// oversampling requires 4x the storage of 1x1. For best results, render -// oversampled textures with bilinear filtering. Look at the readme in -// stb/tests/oversample for information about oversampled fonts -// -// To use with PackFontRangesGather etc., you must set it before calls -// call to PackFontRangesGatherRects. - -STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip); -// If skip != 0, this tells stb_truetype to skip any codepoints for which -// there is no corresponding glyph. If skip=0, which is the default, then -// codepoints without a glyph recived the font's "missing character" glyph, -// typically an empty box by convention. - -STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, // same data as above - int char_index, // character to display - float *xpos, float *ypos, // pointers to current position in screen pixel space - stbtt_aligned_quad *q, // output: quad to draw - int align_to_integer); - -STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); -STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects); -STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects); -// Calling these functions in sequence is roughly equivalent to calling -// stbtt_PackFontRanges(). If you more control over the packing of multiple -// fonts, or if you want to pack custom data into a font texture, take a look -// at the source to of stbtt_PackFontRanges() and create a custom version -// using these functions, e.g. call GatherRects multiple times, -// building up a single array of rects, then call PackRects once, -// then call RenderIntoRects repeatedly. This may result in a -// better packing than calling PackFontRanges multiple times -// (or it may not). - -// this is an opaque structure that you shouldn't mess with which holds -// all the context needed from PackBegin to PackEnd. -struct stbtt_pack_context { - void *user_allocator_context; - void *pack_info; - int width; - int height; - int stride_in_bytes; - int padding; - int skip_missing; - unsigned int h_oversample, v_oversample; - unsigned char *pixels; - void *nodes; -}; - -////////////////////////////////////////////////////////////////////////////// -// -// FONT LOADING -// -// - -STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data); -// This function will determine the number of fonts in a font file. TrueType -// collection (.ttc) files may contain multiple fonts, while TrueType font -// (.ttf) files only contain one font. The number of fonts can be used for -// indexing with the previous function where the index is between zero and one -// less than the total fonts. If an error occurs, -1 is returned. - -STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index); -// Each .ttf/.ttc file may have more than one font. Each font has a sequential -// index number starting from 0. Call this function to get the font offset for -// a given index; it returns -1 if the index is out of range. A regular .ttf -// file will only define one font and it always be at offset 0, so it will -// return '0' for index 0, and -1 for all other indices. - -// The following structure is defined publicly so you can declare one on -// the stack or as a global or etc, but you should treat it as opaque. -struct stbtt_fontinfo -{ - void * userdata; - unsigned char * data; // pointer to .ttf file - int fontstart; // offset of start of font - - int numGlyphs; // number of glyphs, needed for range checking - - int loca,head,glyf,hhea,hmtx,kern,gpos,svg; // table locations as offset from start of .ttf - int index_map; // a cmap mapping for our chosen character encoding - int indexToLocFormat; // format needed to map from glyph index to glyph - - stbtt__buf cff; // cff font data - stbtt__buf charstrings; // the charstring index - stbtt__buf gsubrs; // global charstring subroutines index - stbtt__buf subrs; // private charstring subroutines index - stbtt__buf fontdicts; // array of font dicts - stbtt__buf fdselect; // map from glyph to fontdict -}; - -STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset); -// Given an offset into the file that defines a font, this function builds -// the necessary cached info for the rest of the system. You must allocate -// the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't -// need to do anything special to free it, because the contents are pure -// value data with no additional data structures. Returns 0 on failure. - - -////////////////////////////////////////////////////////////////////////////// -// -// CHARACTER TO GLYPH-INDEX CONVERSIOn - -STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint); -// If you're going to perform multiple operations on the same character -// and you want a speed-up, call this function with the character you're -// going to process, then use glyph-based functions instead of the -// codepoint-based functions. -// Returns 0 if the character codepoint is not defined in the font. - - -////////////////////////////////////////////////////////////////////////////// -// -// CHARACTER PROPERTIES -// - -STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float pixels); -// computes a scale factor to produce a font whose "height" is 'pixels' tall. -// Height is measured as the distance from the highest ascender to the lowest -// descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics -// and computing: -// scale = pixels / (ascent - descent) -// so if you prefer to measure height by the ascent only, use a similar calculation. - -STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels); -// computes a scale factor to produce a font whose EM size is mapped to -// 'pixels' tall. This is probably what traditional APIs compute, but -// I'm not positive. - -STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap); -// ascent is the coordinate above the baseline the font extends; descent -// is the coordinate below the baseline the font extends (i.e. it is typically negative) -// lineGap is the spacing between one row's descent and the next row's ascent... -// so you should advance the vertical position by "*ascent - *descent + *lineGap" -// these are expressed in unscaled coordinates, so you must multiply by -// the scale factor for a given size - -STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap); -// analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2 -// table (specific to MS/Windows TTF files). -// -// Returns 1 on success (table present), 0 on failure. - -STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1); -// the bounding box around all possible characters - -STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing); -// leftSideBearing is the offset from the current horizontal position to the left edge of the character -// advanceWidth is the offset from the current horizontal position to the next horizontal position -// these are expressed in unscaled coordinates - -STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2); -// an additional amount to add to the 'advance' value between ch1 and ch2 - -STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1); -// Gets the bounding box of the visible part of the glyph, in unscaled coordinates - -STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing); -STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2); -STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); -// as above, but takes one or more glyph indices for greater efficiency - -typedef struct stbtt_kerningentry -{ - int glyph1; // use stbtt_FindGlyphIndex - int glyph2; - int advance; -} stbtt_kerningentry; - -STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info); -STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length); -// Retrieves a complete list of all of the kerning pairs provided by the font -// stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. -// The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) - -////////////////////////////////////////////////////////////////////////////// -// -// GLYPH SHAPES (you probably don't need these, but they have to go before -// the bitmaps for C declaration-order reasons) -// - -#ifndef STBTT_vmove // you can predefine these to use different values (but why?) - enum { - STBTT_vmove=1, - STBTT_vline, - STBTT_vcurve, - STBTT_vcubic - }; -#endif - -#ifndef stbtt_vertex // you can predefine this to use different values - // (we share this with other code at RAD) - #define stbtt_vertex_type short // can't use stbtt_int16 because that's not visible in the header file - typedef struct - { - stbtt_vertex_type x,y,cx,cy,cx1,cy1; - unsigned char type,padding; - } stbtt_vertex; -#endif - -STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index); -// returns non-zero if nothing is drawn for this glyph - -STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices); -STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **vertices); -// returns # of vertices and fills *vertices with the pointer to them -// these are expressed in "unscaled" coordinates -// -// The shape is a series of contours. Each one starts with -// a STBTT_moveto, then consists of a series of mixed -// STBTT_lineto and STBTT_curveto segments. A lineto -// draws a line from previous endpoint to its x,y; a curveto -// draws a quadratic bezier from previous endpoint to -// its x,y, using cx,cy as the bezier control point. - -STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices); -// frees the data allocated above - -STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl); -STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg); -STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg); -// fills svg with the character's SVG data. -// returns data size or 0 if SVG not found. - -////////////////////////////////////////////////////////////////////////////// -// -// BITMAP RENDERING -// - -STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata); -// frees the bitmap allocated below - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff); -// allocates a large-enough single-channel 8bpp bitmap and renders the -// specified character/glyph at the specified scale into it, with -// antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque). -// *width & *height are filled out with the width & height of the bitmap, -// which is stored left-to-right, top-to-bottom. -// -// xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff); -// the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel -// shift for the character - -STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint); -// the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap -// in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap -// is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the -// width and height and positioning info for it first. - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint); -// same as stbtt_MakeCodepointBitmap, but you can specify a subpixel -// shift for the character - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint); -// same as stbtt_MakeCodepointBitmapSubpixel, but prefiltering -// is performed (see stbtt_PackSetOversampling) - -STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); -// get the bbox of the bitmap centered around the glyph origin; so the -// bitmap width is ix1-ix0, height is iy1-iy0, and location to place -// the bitmap top left is (leftSideBearing*scale,iy0). -// (Note that the bitmap uses y-increases-down, but the shape uses -// y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.) - -STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); -// same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel -// shift for the character - -// the following functions are equivalent to the above functions, but operate -// on glyph indices instead of Unicode codepoints (for efficiency) -STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph); -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph); -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int glyph); -STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1); -STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1); - - -// @TODO: don't expose this structure -typedef struct -{ - int w,h,stride; - unsigned char *pixels; -} stbtt__bitmap; - -// rasterize a shape with quadratic beziers into a bitmap -STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, // 1-channel bitmap to draw into - float flatness_in_pixels, // allowable error of curve in pixels - stbtt_vertex *vertices, // array of vertices defining shape - int num_verts, // number of vertices in above array - float scale_x, float scale_y, // scale applied to input vertices - float shift_x, float shift_y, // translation applied to input vertices - int x_off, int y_off, // another translation applied to input - int invert, // if non-zero, vertically flip shape - void *userdata); // context for to STBTT_MALLOC - -////////////////////////////////////////////////////////////////////////////// -// -// Signed Distance Function (or Field) rendering - -STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata); -// frees the SDF bitmap allocated below - -STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); -STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff); -// These functions compute a discretized SDF field for a single character, suitable for storing -// in a single-channel texture, sampling with bilinear filtering, and testing against -// larger than some threshold to produce scalable fonts. -// info -- the font -// scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap -// glyph/codepoint -- the character to generate the SDF for -// padding -- extra "pixels" around the character which are filled with the distance to the character (not 0), -// which allows effects like bit outlines -// onedge_value -- value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character) -// pixel_dist_scale -- what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale) -// if positive, > onedge_value is inside; if negative, < onedge_value is inside -// width,height -- output height & width of the SDF bitmap (including padding) -// xoff,yoff -- output origin of the character -// return value -- a 2D array of bytes 0..255, width*height in size -// -// pixel_dist_scale & onedge_value are a scale & bias that allows you to make -// optimal use of the limited 0..255 for your application, trading off precision -// and special effects. SDF values outside the range 0..255 are clamped to 0..255. -// -// Example: -// scale = stbtt_ScaleForPixelHeight(22) -// padding = 5 -// onedge_value = 180 -// pixel_dist_scale = 180/5.0 = 36.0 -// -// This will create an SDF bitmap in which the character is about 22 pixels -// high but the whole bitmap is about 22+5+5=32 pixels high. To produce a filled -// shape, sample the SDF at each pixel and fill the pixel if the SDF value -// is greater than or equal to 180/255. (You'll actually want to antialias, -// which is beyond the scope of this example.) Additionally, you can compute -// offset outlines (e.g. to stroke the character border inside & outside, -// or only outside). For example, to fill outside the character up to 3 SDF -// pixels, you would compare against (180-36.0*3)/255 = 72/255. The above -// choice of variables maps a range from 5 pixels outside the shape to -// 2 pixels inside the shape to 0..255; this is intended primarily for apply -// outside effects only (the interior range is needed to allow proper -// antialiasing of the font at *smaller* sizes) -// -// The function computes the SDF analytically at each SDF pixel, not by e.g. -// building a higher-res bitmap and approximating it. In theory the quality -// should be as high as possible for an SDF of this size & representation, but -// unclear if this is true in practice (perhaps building a higher-res bitmap -// and computing from that can allow drop-out prevention). -// -// The algorithm has not been optimized at all, so expect it to be slow -// if computing lots of characters or very large sizes. - - - -////////////////////////////////////////////////////////////////////////////// -// -// Finding the right font... -// -// You should really just solve this offline, keep your own tables -// of what font is what, and don't try to get it out of the .ttf file. -// That's because getting it out of the .ttf file is really hard, because -// the names in the file can appear in many possible encodings, in many -// possible languages, and e.g. if you need a case-insensitive comparison, -// the details of that depend on the encoding & language in a complex way -// (actually underspecified in truetype, but also gigantic). -// -// But you can use the provided functions in two possible ways: -// stbtt_FindMatchingFont() will use *case-sensitive* comparisons on -// unicode-encoded names to try to find the font you want; -// you can run this before calling stbtt_InitFont() -// -// stbtt_GetFontNameString() lets you get any of the various strings -// from the file yourself and do your own comparisons on them. -// You have to have called stbtt_InitFont() first. - - -STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags); -// returns the offset (not index) of the font that matches, or -1 if none -// if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". -// if you use any other flag, use a font name like "Arial"; this checks -// the 'macStyle' header field; i don't know if fonts set this consistently -#define STBTT_MACSTYLE_DONTCARE 0 -#define STBTT_MACSTYLE_BOLD 1 -#define STBTT_MACSTYLE_ITALIC 2 -#define STBTT_MACSTYLE_UNDERSCORE 4 -#define STBTT_MACSTYLE_NONE 8 // <= not same as 0, this makes us check the bitfield is 0 - -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2); -// returns 1/0 whether the first string interpreted as utf8 is identical to -// the second string interpreted as big-endian utf16... useful for strings from next func - -STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID); -// returns the string (which may be big-endian double byte, e.g. for unicode) -// and puts the length in bytes in *length. -// -// some of the values for the IDs are below; for more see the truetype spec: -// http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html -// http://www.microsoft.com/typography/otspec/name.htm - -enum { // platformID - STBTT_PLATFORM_ID_UNICODE =0, - STBTT_PLATFORM_ID_MAC =1, - STBTT_PLATFORM_ID_ISO =2, - STBTT_PLATFORM_ID_MICROSOFT =3 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_UNICODE - STBTT_UNICODE_EID_UNICODE_1_0 =0, - STBTT_UNICODE_EID_UNICODE_1_1 =1, - STBTT_UNICODE_EID_ISO_10646 =2, - STBTT_UNICODE_EID_UNICODE_2_0_BMP=3, - STBTT_UNICODE_EID_UNICODE_2_0_FULL=4 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_MICROSOFT - STBTT_MS_EID_SYMBOL =0, - STBTT_MS_EID_UNICODE_BMP =1, - STBTT_MS_EID_SHIFTJIS =2, - STBTT_MS_EID_UNICODE_FULL =10 -}; - -enum { // encodingID for STBTT_PLATFORM_ID_MAC; same as Script Manager codes - STBTT_MAC_EID_ROMAN =0, STBTT_MAC_EID_ARABIC =4, - STBTT_MAC_EID_JAPANESE =1, STBTT_MAC_EID_HEBREW =5, - STBTT_MAC_EID_CHINESE_TRAD =2, STBTT_MAC_EID_GREEK =6, - STBTT_MAC_EID_KOREAN =3, STBTT_MAC_EID_RUSSIAN =7 -}; - -enum { // languageID for STBTT_PLATFORM_ID_MICROSOFT; same as LCID... - // problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs - STBTT_MS_LANG_ENGLISH =0x0409, STBTT_MS_LANG_ITALIAN =0x0410, - STBTT_MS_LANG_CHINESE =0x0804, STBTT_MS_LANG_JAPANESE =0x0411, - STBTT_MS_LANG_DUTCH =0x0413, STBTT_MS_LANG_KOREAN =0x0412, - STBTT_MS_LANG_FRENCH =0x040c, STBTT_MS_LANG_RUSSIAN =0x0419, - STBTT_MS_LANG_GERMAN =0x0407, STBTT_MS_LANG_SPANISH =0x0409, - STBTT_MS_LANG_HEBREW =0x040d, STBTT_MS_LANG_SWEDISH =0x041D -}; - -enum { // languageID for STBTT_PLATFORM_ID_MAC - STBTT_MAC_LANG_ENGLISH =0 , STBTT_MAC_LANG_JAPANESE =11, - STBTT_MAC_LANG_ARABIC =12, STBTT_MAC_LANG_KOREAN =23, - STBTT_MAC_LANG_DUTCH =4 , STBTT_MAC_LANG_RUSSIAN =32, - STBTT_MAC_LANG_FRENCH =1 , STBTT_MAC_LANG_SPANISH =6 , - STBTT_MAC_LANG_GERMAN =2 , STBTT_MAC_LANG_SWEDISH =5 , - STBTT_MAC_LANG_HEBREW =10, STBTT_MAC_LANG_CHINESE_SIMPLIFIED =33, - STBTT_MAC_LANG_ITALIAN =3 , STBTT_MAC_LANG_CHINESE_TRAD =19 -}; - -#ifdef __cplusplus -} -#endif - -#endif // __STB_INCLUDE_STB_TRUETYPE_H__ - -/////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////// -//// -//// IMPLEMENTATION -//// -//// - -#ifdef STB_TRUETYPE_IMPLEMENTATION - -#ifndef STBTT_MAX_OVERSAMPLE -#define STBTT_MAX_OVERSAMPLE 8 -#endif - -#if STBTT_MAX_OVERSAMPLE > 255 -#error "STBTT_MAX_OVERSAMPLE cannot be > 255" -#endif - -typedef int stbtt__test_oversample_pow2[(STBTT_MAX_OVERSAMPLE & (STBTT_MAX_OVERSAMPLE-1)) == 0 ? 1 : -1]; - -#ifndef STBTT_RASTERIZER_VERSION -#define STBTT_RASTERIZER_VERSION 2 -#endif - -#ifdef _MSC_VER -#define STBTT__NOTUSED(v) (void)(v) -#else -#define STBTT__NOTUSED(v) (void)sizeof(v) -#endif - -////////////////////////////////////////////////////////////////////////// -// -// stbtt__buf helpers to parse data from file -// - -static stbtt_uint8 stbtt__buf_get8(stbtt__buf *b) -{ - if (b->cursor >= b->size) - return 0; - return b->data[b->cursor++]; -} - -static stbtt_uint8 stbtt__buf_peek8(stbtt__buf *b) -{ - if (b->cursor >= b->size) - return 0; - return b->data[b->cursor]; -} - -static void stbtt__buf_seek(stbtt__buf *b, int o) -{ - STBTT_assert(!(o > b->size || o < 0)); - b->cursor = (o > b->size || o < 0) ? b->size : o; -} - -static void stbtt__buf_skip(stbtt__buf *b, int o) -{ - stbtt__buf_seek(b, b->cursor + o); -} - -static stbtt_uint32 stbtt__buf_get(stbtt__buf *b, int n) -{ - stbtt_uint32 v = 0; - int i; - STBTT_assert(n >= 1 && n <= 4); - for (i = 0; i < n; i++) - v = (v << 8) | stbtt__buf_get8(b); - return v; -} - -static stbtt__buf stbtt__new_buf(const void *p, size_t size) -{ - stbtt__buf r; - STBTT_assert(size < 0x40000000); - r.data = (stbtt_uint8*) p; - r.size = (int) size; - r.cursor = 0; - return r; -} - -#define stbtt__buf_get16(b) stbtt__buf_get((b), 2) -#define stbtt__buf_get32(b) stbtt__buf_get((b), 4) - -static stbtt__buf stbtt__buf_range(const stbtt__buf *b, int o, int s) -{ - stbtt__buf r = stbtt__new_buf(NULL, 0); - if (o < 0 || s < 0 || o > b->size || s > b->size - o) return r; - r.data = b->data + o; - r.size = s; - return r; -} - -static stbtt__buf stbtt__cff_get_index(stbtt__buf *b) -{ - int count, start, offsize; - start = b->cursor; - count = stbtt__buf_get16(b); - if (count) { - offsize = stbtt__buf_get8(b); - STBTT_assert(offsize >= 1 && offsize <= 4); - stbtt__buf_skip(b, offsize * count); - stbtt__buf_skip(b, stbtt__buf_get(b, offsize) - 1); - } - return stbtt__buf_range(b, start, b->cursor - start); -} - -static stbtt_uint32 stbtt__cff_int(stbtt__buf *b) -{ - int b0 = stbtt__buf_get8(b); - if (b0 >= 32 && b0 <= 246) return b0 - 139; - else if (b0 >= 247 && b0 <= 250) return (b0 - 247)*256 + stbtt__buf_get8(b) + 108; - else if (b0 >= 251 && b0 <= 254) return -(b0 - 251)*256 - stbtt__buf_get8(b) - 108; - else if (b0 == 28) return stbtt__buf_get16(b); - else if (b0 == 29) return stbtt__buf_get32(b); - STBTT_assert(0); - return 0; -} - -static void stbtt__cff_skip_operand(stbtt__buf *b) { - int v, b0 = stbtt__buf_peek8(b); - STBTT_assert(b0 >= 28); - if (b0 == 30) { - stbtt__buf_skip(b, 1); - while (b->cursor < b->size) { - v = stbtt__buf_get8(b); - if ((v & 0xF) == 0xF || (v >> 4) == 0xF) - break; - } - } else { - stbtt__cff_int(b); - } -} - -static stbtt__buf stbtt__dict_get(stbtt__buf *b, int key) -{ - stbtt__buf_seek(b, 0); - while (b->cursor < b->size) { - int start = b->cursor, end, op; - while (stbtt__buf_peek8(b) >= 28) - stbtt__cff_skip_operand(b); - end = b->cursor; - op = stbtt__buf_get8(b); - if (op == 12) op = stbtt__buf_get8(b) | 0x100; - if (op == key) return stbtt__buf_range(b, start, end-start); - } - return stbtt__buf_range(b, 0, 0); -} - -static void stbtt__dict_get_ints(stbtt__buf *b, int key, int outcount, stbtt_uint32 *out) -{ - int i; - stbtt__buf operands = stbtt__dict_get(b, key); - for (i = 0; i < outcount && operands.cursor < operands.size; i++) - out[i] = stbtt__cff_int(&operands); -} - -static int stbtt__cff_index_count(stbtt__buf *b) -{ - stbtt__buf_seek(b, 0); - return stbtt__buf_get16(b); -} - -static stbtt__buf stbtt__cff_index_get(stbtt__buf b, int i) -{ - int count, offsize, start, end; - stbtt__buf_seek(&b, 0); - count = stbtt__buf_get16(&b); - offsize = stbtt__buf_get8(&b); - STBTT_assert(i >= 0 && i < count); - STBTT_assert(offsize >= 1 && offsize <= 4); - stbtt__buf_skip(&b, i*offsize); - start = stbtt__buf_get(&b, offsize); - end = stbtt__buf_get(&b, offsize); - return stbtt__buf_range(&b, 2+(count+1)*offsize+start, end - start); -} - -////////////////////////////////////////////////////////////////////////// -// -// accessors to parse data from file -// - -// on platforms that don't allow misaligned reads, if we want to allow -// truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE - -#define ttBYTE(p) (* (stbtt_uint8 *) (p)) -#define ttCHAR(p) (* (stbtt_int8 *) (p)) -#define ttFixed(p) ttLONG(p) - -static stbtt_uint16 ttUSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } -static stbtt_int16 ttSHORT(stbtt_uint8 *p) { return p[0]*256 + p[1]; } -static stbtt_uint32 ttULONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } -static stbtt_int32 ttLONG(stbtt_uint8 *p) { return (p[0]<<24) + (p[1]<<16) + (p[2]<<8) + p[3]; } - -#define stbtt_tag4(p,c0,c1,c2,c3) ((p)[0] == (c0) && (p)[1] == (c1) && (p)[2] == (c2) && (p)[3] == (c3)) -#define stbtt_tag(p,str) stbtt_tag4(p,str[0],str[1],str[2],str[3]) - -static int stbtt__isfont(stbtt_uint8 *font) -{ - // check the version number - if (stbtt_tag4(font, '1',0,0,0)) return 1; // TrueType 1 - if (stbtt_tag(font, "typ1")) return 1; // TrueType with type 1 font -- we don't support this! - if (stbtt_tag(font, "OTTO")) return 1; // OpenType with CFF - if (stbtt_tag4(font, 0,1,0,0)) return 1; // OpenType 1.0 - if (stbtt_tag(font, "true")) return 1; // Apple specification for TrueType fonts - return 0; -} - -// @OPTIMIZE: binary search -static stbtt_uint32 stbtt__find_table(stbtt_uint8 *data, stbtt_uint32 fontstart, const char *tag) -{ - stbtt_int32 num_tables = ttUSHORT(data+fontstart+4); - stbtt_uint32 tabledir = fontstart + 12; - stbtt_int32 i; - for (i=0; i < num_tables; ++i) { - stbtt_uint32 loc = tabledir + 16*i; - if (stbtt_tag(data+loc+0, tag)) - return ttULONG(data+loc+8); - } - return 0; -} - -static int stbtt_GetFontOffsetForIndex_internal(unsigned char *font_collection, int index) -{ - // if it's just a font, there's only one valid index - if (stbtt__isfont(font_collection)) - return index == 0 ? 0 : -1; - - // check if it's a TTC - if (stbtt_tag(font_collection, "ttcf")) { - // version 1? - if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { - stbtt_int32 n = ttLONG(font_collection+8); - if (index >= n) - return -1; - return ttULONG(font_collection+12+index*4); - } - } - return -1; -} - -static int stbtt_GetNumberOfFonts_internal(unsigned char *font_collection) -{ - // if it's just a font, there's only one valid font - if (stbtt__isfont(font_collection)) - return 1; - - // check if it's a TTC - if (stbtt_tag(font_collection, "ttcf")) { - // version 1? - if (ttULONG(font_collection+4) == 0x00010000 || ttULONG(font_collection+4) == 0x00020000) { - return ttLONG(font_collection+8); - } - } - return 0; -} - -static stbtt__buf stbtt__get_subrs(stbtt__buf cff, stbtt__buf fontdict) -{ - stbtt_uint32 subrsoff = 0, private_loc[2] = { 0, 0 }; - stbtt__buf pdict; - stbtt__dict_get_ints(&fontdict, 18, 2, private_loc); - if (!private_loc[1] || !private_loc[0]) return stbtt__new_buf(NULL, 0); - pdict = stbtt__buf_range(&cff, private_loc[1], private_loc[0]); - stbtt__dict_get_ints(&pdict, 19, 1, &subrsoff); - if (!subrsoff) return stbtt__new_buf(NULL, 0); - stbtt__buf_seek(&cff, private_loc[1]+subrsoff); - return stbtt__cff_get_index(&cff); -} - -// since most people won't use this, find this table the first time it's needed -static int stbtt__get_svg(stbtt_fontinfo *info) -{ - stbtt_uint32 t; - if (info->svg < 0) { - t = stbtt__find_table(info->data, info->fontstart, "SVG "); - if (t) { - stbtt_uint32 offset = ttULONG(info->data + t + 2); - info->svg = t + offset; - } else { - info->svg = 0; - } - } - return info->svg; -} - -static int stbtt_InitFont_internal(stbtt_fontinfo *info, unsigned char *data, int fontstart) -{ - stbtt_uint32 cmap, t; - stbtt_int32 i,numTables; - - info->data = data; - info->fontstart = fontstart; - info->cff = stbtt__new_buf(NULL, 0); - - cmap = stbtt__find_table(data, fontstart, "cmap"); // required - info->loca = stbtt__find_table(data, fontstart, "loca"); // required - info->head = stbtt__find_table(data, fontstart, "head"); // required - info->glyf = stbtt__find_table(data, fontstart, "glyf"); // required - info->hhea = stbtt__find_table(data, fontstart, "hhea"); // required - info->hmtx = stbtt__find_table(data, fontstart, "hmtx"); // required - info->kern = stbtt__find_table(data, fontstart, "kern"); // not required - info->gpos = stbtt__find_table(data, fontstart, "GPOS"); // not required - - if (!cmap || !info->head || !info->hhea || !info->hmtx) - return 0; - if (info->glyf) { - // required for truetype - if (!info->loca) return 0; - } else { - // initialization for CFF / Type2 fonts (OTF) - stbtt__buf b, topdict, topdictidx; - stbtt_uint32 cstype = 2, charstrings = 0, fdarrayoff = 0, fdselectoff = 0; - stbtt_uint32 cff; - - cff = stbtt__find_table(data, fontstart, "CFF "); - if (!cff) return 0; - - info->fontdicts = stbtt__new_buf(NULL, 0); - info->fdselect = stbtt__new_buf(NULL, 0); - - // @TODO this should use size from table (not 512MB) - info->cff = stbtt__new_buf(data+cff, 512*1024*1024); - b = info->cff; - - // read the header - stbtt__buf_skip(&b, 2); - stbtt__buf_seek(&b, stbtt__buf_get8(&b)); // hdrsize - - // @TODO the name INDEX could list multiple fonts, - // but we just use the first one. - stbtt__cff_get_index(&b); // name INDEX - topdictidx = stbtt__cff_get_index(&b); - topdict = stbtt__cff_index_get(topdictidx, 0); - stbtt__cff_get_index(&b); // string INDEX - info->gsubrs = stbtt__cff_get_index(&b); - - stbtt__dict_get_ints(&topdict, 17, 1, &charstrings); - stbtt__dict_get_ints(&topdict, 0x100 | 6, 1, &cstype); - stbtt__dict_get_ints(&topdict, 0x100 | 36, 1, &fdarrayoff); - stbtt__dict_get_ints(&topdict, 0x100 | 37, 1, &fdselectoff); - info->subrs = stbtt__get_subrs(b, topdict); - - // we only support Type 2 charstrings - if (cstype != 2) return 0; - if (charstrings == 0) return 0; - - if (fdarrayoff) { - // looks like a CID font - if (!fdselectoff) return 0; - stbtt__buf_seek(&b, fdarrayoff); - info->fontdicts = stbtt__cff_get_index(&b); - info->fdselect = stbtt__buf_range(&b, fdselectoff, b.size-fdselectoff); - } - - stbtt__buf_seek(&b, charstrings); - info->charstrings = stbtt__cff_get_index(&b); - } - - t = stbtt__find_table(data, fontstart, "maxp"); - if (t) - info->numGlyphs = ttUSHORT(data+t+4); - else - info->numGlyphs = 0xffff; - - info->svg = -1; - - // find a cmap encoding table we understand *now* to avoid searching - // later. (todo: could make this installable) - // the same regardless of glyph. - numTables = ttUSHORT(data + cmap + 2); - info->index_map = 0; - for (i=0; i < numTables; ++i) { - stbtt_uint32 encoding_record = cmap + 4 + 8 * i; - // find an encoding we understand: - switch(ttUSHORT(data+encoding_record)) { - case STBTT_PLATFORM_ID_MICROSOFT: - switch (ttUSHORT(data+encoding_record+2)) { - case STBTT_MS_EID_UNICODE_BMP: - case STBTT_MS_EID_UNICODE_FULL: - // MS/Unicode - info->index_map = cmap + ttULONG(data+encoding_record+4); - break; - } - break; - case STBTT_PLATFORM_ID_UNICODE: - // Mac/iOS has these - // all the encodingIDs are unicode, so we don't bother to check it - info->index_map = cmap + ttULONG(data+encoding_record+4); - break; - } - } - if (info->index_map == 0) - return 0; - - info->indexToLocFormat = ttUSHORT(data+info->head + 50); - return 1; -} - -STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codepoint) -{ - stbtt_uint8 *data = info->data; - stbtt_uint32 index_map = info->index_map; - - stbtt_uint16 format = ttUSHORT(data + index_map + 0); - if (format == 0) { // apple byte encoding - stbtt_int32 bytes = ttUSHORT(data + index_map + 2); - if (unicode_codepoint < bytes-6) - return ttBYTE(data + index_map + 6 + unicode_codepoint); - return 0; - } else if (format == 6) { - stbtt_uint32 first = ttUSHORT(data + index_map + 6); - stbtt_uint32 count = ttUSHORT(data + index_map + 8); - if ((stbtt_uint32) unicode_codepoint >= first && (stbtt_uint32) unicode_codepoint < first+count) - return ttUSHORT(data + index_map + 10 + (unicode_codepoint - first)*2); - return 0; - } else if (format == 2) { - STBTT_assert(0); // @TODO: high-byte mapping for japanese/chinese/korean - return 0; - } else if (format == 4) { // standard mapping for windows fonts: binary search collection of ranges - stbtt_uint16 segcount = ttUSHORT(data+index_map+6) >> 1; - stbtt_uint16 searchRange = ttUSHORT(data+index_map+8) >> 1; - stbtt_uint16 entrySelector = ttUSHORT(data+index_map+10); - stbtt_uint16 rangeShift = ttUSHORT(data+index_map+12) >> 1; - - // do a binary search of the segments - stbtt_uint32 endCount = index_map + 14; - stbtt_uint32 search = endCount; - - if (unicode_codepoint > 0xffff) - return 0; - - // they lie from endCount .. endCount + segCount - // but searchRange is the nearest power of two, so... - if (unicode_codepoint >= ttUSHORT(data + search + rangeShift*2)) - search += rangeShift*2; - - // now decrement to bias correctly to find smallest - search -= 2; - while (entrySelector) { - stbtt_uint16 end; - searchRange >>= 1; - end = ttUSHORT(data + search + searchRange*2); - if (unicode_codepoint > end) - search += searchRange*2; - --entrySelector; - } - search += 2; - - { - stbtt_uint16 offset, start, last; - stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1); - - start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item); - last = ttUSHORT(data + endCount + 2*item); - if (unicode_codepoint < start || unicode_codepoint > last) - return 0; - - offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item); - if (offset == 0) - return (stbtt_uint16) (unicode_codepoint + ttSHORT(data + index_map + 14 + segcount*4 + 2 + 2*item)); - - return ttUSHORT(data + offset + (unicode_codepoint-start)*2 + index_map + 14 + segcount*6 + 2 + 2*item); - } - } else if (format == 12 || format == 13) { - stbtt_uint32 ngroups = ttULONG(data+index_map+12); - stbtt_int32 low,high; - low = 0; high = (stbtt_int32)ngroups; - // Binary search the right group. - while (low < high) { - stbtt_int32 mid = low + ((high-low) >> 1); // rounds down, so low <= mid < high - stbtt_uint32 start_char = ttULONG(data+index_map+16+mid*12); - stbtt_uint32 end_char = ttULONG(data+index_map+16+mid*12+4); - if ((stbtt_uint32) unicode_codepoint < start_char) - high = mid; - else if ((stbtt_uint32) unicode_codepoint > end_char) - low = mid+1; - else { - stbtt_uint32 start_glyph = ttULONG(data+index_map+16+mid*12+8); - if (format == 12) - return start_glyph + unicode_codepoint-start_char; - else // format == 13 - return start_glyph; - } - } - return 0; // not found - } - // @TODO - STBTT_assert(0); - return 0; -} - -STBTT_DEF int stbtt_GetCodepointShape(const stbtt_fontinfo *info, int unicode_codepoint, stbtt_vertex **vertices) -{ - return stbtt_GetGlyphShape(info, stbtt_FindGlyphIndex(info, unicode_codepoint), vertices); -} - -static void stbtt_setvertex(stbtt_vertex *v, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy) -{ - v->type = type; - v->x = (stbtt_int16) x; - v->y = (stbtt_int16) y; - v->cx = (stbtt_int16) cx; - v->cy = (stbtt_int16) cy; -} - -static int stbtt__GetGlyfOffset(const stbtt_fontinfo *info, int glyph_index) -{ - int g1,g2; - - STBTT_assert(!info->cff.size); - - if (glyph_index >= info->numGlyphs) return -1; // glyph index out of range - if (info->indexToLocFormat >= 2) return -1; // unknown index->glyph map format - - if (info->indexToLocFormat == 0) { - g1 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2) * 2; - g2 = info->glyf + ttUSHORT(info->data + info->loca + glyph_index * 2 + 2) * 2; - } else { - g1 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4); - g2 = info->glyf + ttULONG (info->data + info->loca + glyph_index * 4 + 4); - } - - return g1==g2 ? -1 : g1; // if length is 0, return -1 -} - -static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1); - -STBTT_DEF int stbtt_GetGlyphBox(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) -{ - if (info->cff.size) { - stbtt__GetGlyphInfoT2(info, glyph_index, x0, y0, x1, y1); - } else { - int g = stbtt__GetGlyfOffset(info, glyph_index); - if (g < 0) return 0; - - if (x0) *x0 = ttSHORT(info->data + g + 2); - if (y0) *y0 = ttSHORT(info->data + g + 4); - if (x1) *x1 = ttSHORT(info->data + g + 6); - if (y1) *y1 = ttSHORT(info->data + g + 8); - } - return 1; -} - -STBTT_DEF int stbtt_GetCodepointBox(const stbtt_fontinfo *info, int codepoint, int *x0, int *y0, int *x1, int *y1) -{ - return stbtt_GetGlyphBox(info, stbtt_FindGlyphIndex(info,codepoint), x0,y0,x1,y1); -} - -STBTT_DEF int stbtt_IsGlyphEmpty(const stbtt_fontinfo *info, int glyph_index) -{ - stbtt_int16 numberOfContours; - int g; - if (info->cff.size) - return stbtt__GetGlyphInfoT2(info, glyph_index, NULL, NULL, NULL, NULL) == 0; - g = stbtt__GetGlyfOffset(info, glyph_index); - if (g < 0) return 1; - numberOfContours = ttSHORT(info->data + g); - return numberOfContours == 0; -} - -static int stbtt__close_shape(stbtt_vertex *vertices, int num_vertices, int was_off, int start_off, - stbtt_int32 sx, stbtt_int32 sy, stbtt_int32 scx, stbtt_int32 scy, stbtt_int32 cx, stbtt_int32 cy) -{ - if (start_off) { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+scx)>>1, (cy+scy)>>1, cx,cy); - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, sx,sy,scx,scy); - } else { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve,sx,sy,cx,cy); - else - stbtt_setvertex(&vertices[num_vertices++], STBTT_vline,sx,sy,0,0); - } - return num_vertices; -} - -static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - stbtt_int16 numberOfContours; - stbtt_uint8 *endPtsOfContours; - stbtt_uint8 *data = info->data; - stbtt_vertex *vertices=0; - int num_vertices=0; - int g = stbtt__GetGlyfOffset(info, glyph_index); - - *pvertices = NULL; - - if (g < 0) return 0; - - numberOfContours = ttSHORT(data + g); - - if (numberOfContours > 0) { - stbtt_uint8 flags=0,flagcount; - stbtt_int32 ins, i,j=0,m,n, next_move, was_off=0, off, start_off=0; - stbtt_int32 x,y,cx,cy,sx,sy, scx,scy; - stbtt_uint8 *points; - endPtsOfContours = (data + g + 10); - ins = ttUSHORT(data + g + 10 + numberOfContours * 2); - points = data + g + 10 + numberOfContours * 2 + 2 + ins; - - n = 1+ttUSHORT(endPtsOfContours + numberOfContours*2-2); - - m = n + 2*numberOfContours; // a loose bound on how many vertices we might need - vertices = (stbtt_vertex *) STBTT_malloc(m * sizeof(vertices[0]), info->userdata); - if (vertices == 0) - return 0; - - next_move = 0; - flagcount=0; - - // in first pass, we load uninterpreted data into the allocated array - // above, shifted to the end of the array so we won't overwrite it when - // we create our final data starting from the front - - off = m - n; // starting offset for uninterpreted data, regardless of how m ends up being calculated - - // first load flags - - for (i=0; i < n; ++i) { - if (flagcount == 0) { - flags = *points++; - if (flags & 8) - flagcount = *points++; - } else - --flagcount; - vertices[off+i].type = flags; - } - - // now load x coordinates - x=0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - if (flags & 2) { - stbtt_int16 dx = *points++; - x += (flags & 16) ? dx : -dx; // ??? - } else { - if (!(flags & 16)) { - x = x + (stbtt_int16) (points[0]*256 + points[1]); - points += 2; - } - } - vertices[off+i].x = (stbtt_int16) x; - } - - // now load y coordinates - y=0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - if (flags & 4) { - stbtt_int16 dy = *points++; - y += (flags & 32) ? dy : -dy; // ??? - } else { - if (!(flags & 32)) { - y = y + (stbtt_int16) (points[0]*256 + points[1]); - points += 2; - } - } - vertices[off+i].y = (stbtt_int16) y; - } - - // now convert them to our format - num_vertices=0; - sx = sy = cx = cy = scx = scy = 0; - for (i=0; i < n; ++i) { - flags = vertices[off+i].type; - x = (stbtt_int16) vertices[off+i].x; - y = (stbtt_int16) vertices[off+i].y; - - if (next_move == i) { - if (i != 0) - num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); - - // now start the new one - start_off = !(flags & 1); - if (start_off) { - // if we start off with an off-curve point, then when we need to find a point on the curve - // where we can start, and we need to save some state for when we wraparound. - scx = x; - scy = y; - if (!(vertices[off+i+1].type & 1)) { - // next point is also a curve point, so interpolate an on-point curve - sx = (x + (stbtt_int32) vertices[off+i+1].x) >> 1; - sy = (y + (stbtt_int32) vertices[off+i+1].y) >> 1; - } else { - // otherwise just use the next point as our start point - sx = (stbtt_int32) vertices[off+i+1].x; - sy = (stbtt_int32) vertices[off+i+1].y; - ++i; // we're using point i+1 as the starting point, so skip it - } - } else { - sx = x; - sy = y; - } - stbtt_setvertex(&vertices[num_vertices++], STBTT_vmove,sx,sy,0,0); - was_off = 0; - next_move = 1 + ttUSHORT(endPtsOfContours+j*2); - ++j; - } else { - if (!(flags & 1)) { // if it's a curve - if (was_off) // two off-curve control points in a row means interpolate an on-curve midpoint - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, (cx+x)>>1, (cy+y)>>1, cx, cy); - cx = x; - cy = y; - was_off = 1; - } else { - if (was_off) - stbtt_setvertex(&vertices[num_vertices++], STBTT_vcurve, x,y, cx, cy); - else - stbtt_setvertex(&vertices[num_vertices++], STBTT_vline, x,y,0,0); - was_off = 0; - } - } - } - num_vertices = stbtt__close_shape(vertices, num_vertices, was_off, start_off, sx,sy,scx,scy,cx,cy); - } else if (numberOfContours < 0) { - // Compound shapes. - int more = 1; - stbtt_uint8 *comp = data + g + 10; - num_vertices = 0; - vertices = 0; - while (more) { - stbtt_uint16 flags, gidx; - int comp_num_verts = 0, i; - stbtt_vertex *comp_verts = 0, *tmp = 0; - float mtx[6] = {1,0,0,1,0,0}, m, n; - - flags = ttSHORT(comp); comp+=2; - gidx = ttSHORT(comp); comp+=2; - - if (flags & 2) { // XY values - if (flags & 1) { // shorts - mtx[4] = ttSHORT(comp); comp+=2; - mtx[5] = ttSHORT(comp); comp+=2; - } else { - mtx[4] = ttCHAR(comp); comp+=1; - mtx[5] = ttCHAR(comp); comp+=1; - } - } - else { - // @TODO handle matching point - STBTT_assert(0); - } - if (flags & (1<<3)) { // WE_HAVE_A_SCALE - mtx[0] = mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = mtx[2] = 0; - } else if (flags & (1<<6)) { // WE_HAVE_AN_X_AND_YSCALE - mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = mtx[2] = 0; - mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - } else if (flags & (1<<7)) { // WE_HAVE_A_TWO_BY_TWO - mtx[0] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[1] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[2] = ttSHORT(comp)/16384.0f; comp+=2; - mtx[3] = ttSHORT(comp)/16384.0f; comp+=2; - } - - // Find transformation scales. - m = (float) STBTT_sqrt(mtx[0]*mtx[0] + mtx[1]*mtx[1]); - n = (float) STBTT_sqrt(mtx[2]*mtx[2] + mtx[3]*mtx[3]); - - // Get indexed glyph. - comp_num_verts = stbtt_GetGlyphShape(info, gidx, &comp_verts); - if (comp_num_verts > 0) { - // Transform vertices. - for (i = 0; i < comp_num_verts; ++i) { - stbtt_vertex* v = &comp_verts[i]; - stbtt_vertex_type x,y; - x=v->x; y=v->y; - v->x = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); - v->y = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); - x=v->cx; y=v->cy; - v->cx = (stbtt_vertex_type)(m * (mtx[0]*x + mtx[2]*y + mtx[4])); - v->cy = (stbtt_vertex_type)(n * (mtx[1]*x + mtx[3]*y + mtx[5])); - } - // Append vertices. - tmp = (stbtt_vertex*)STBTT_malloc((num_vertices+comp_num_verts)*sizeof(stbtt_vertex), info->userdata); - if (!tmp) { - if (vertices) STBTT_free(vertices, info->userdata); - if (comp_verts) STBTT_free(comp_verts, info->userdata); - return 0; - } - if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex)); - STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex)); - if (vertices) STBTT_free(vertices, info->userdata); - vertices = tmp; - STBTT_free(comp_verts, info->userdata); - num_vertices += comp_num_verts; - } - // More components ? - more = flags & (1<<5); - } - } else { - // numberOfCounters == 0, do nothing - } - - *pvertices = vertices; - return num_vertices; -} - -typedef struct -{ - int bounds; - int started; - float first_x, first_y; - float x, y; - stbtt_int32 min_x, max_x, min_y, max_y; - - stbtt_vertex *pvertices; - int num_vertices; -} stbtt__csctx; - -#define STBTT__CSCTX_INIT(bounds) {bounds,0, 0,0, 0,0, 0,0,0,0, NULL, 0} - -static void stbtt__track_vertex(stbtt__csctx *c, stbtt_int32 x, stbtt_int32 y) -{ - if (x > c->max_x || !c->started) c->max_x = x; - if (y > c->max_y || !c->started) c->max_y = y; - if (x < c->min_x || !c->started) c->min_x = x; - if (y < c->min_y || !c->started) c->min_y = y; - c->started = 1; -} - -static void stbtt__csctx_v(stbtt__csctx *c, stbtt_uint8 type, stbtt_int32 x, stbtt_int32 y, stbtt_int32 cx, stbtt_int32 cy, stbtt_int32 cx1, stbtt_int32 cy1) -{ - if (c->bounds) { - stbtt__track_vertex(c, x, y); - if (type == STBTT_vcubic) { - stbtt__track_vertex(c, cx, cy); - stbtt__track_vertex(c, cx1, cy1); - } - } else { - stbtt_setvertex(&c->pvertices[c->num_vertices], type, x, y, cx, cy); - c->pvertices[c->num_vertices].cx1 = (stbtt_int16) cx1; - c->pvertices[c->num_vertices].cy1 = (stbtt_int16) cy1; - } - c->num_vertices++; -} - -static void stbtt__csctx_close_shape(stbtt__csctx *ctx) -{ - if (ctx->first_x != ctx->x || ctx->first_y != ctx->y) - stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->first_x, (int)ctx->first_y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rmove_to(stbtt__csctx *ctx, float dx, float dy) -{ - stbtt__csctx_close_shape(ctx); - ctx->first_x = ctx->x = ctx->x + dx; - ctx->first_y = ctx->y = ctx->y + dy; - stbtt__csctx_v(ctx, STBTT_vmove, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rline_to(stbtt__csctx *ctx, float dx, float dy) -{ - ctx->x += dx; - ctx->y += dy; - stbtt__csctx_v(ctx, STBTT_vline, (int)ctx->x, (int)ctx->y, 0, 0, 0, 0); -} - -static void stbtt__csctx_rccurve_to(stbtt__csctx *ctx, float dx1, float dy1, float dx2, float dy2, float dx3, float dy3) -{ - float cx1 = ctx->x + dx1; - float cy1 = ctx->y + dy1; - float cx2 = cx1 + dx2; - float cy2 = cy1 + dy2; - ctx->x = cx2 + dx3; - ctx->y = cy2 + dy3; - stbtt__csctx_v(ctx, STBTT_vcubic, (int)ctx->x, (int)ctx->y, (int)cx1, (int)cy1, (int)cx2, (int)cy2); -} - -static stbtt__buf stbtt__get_subr(stbtt__buf idx, int n) -{ - int count = stbtt__cff_index_count(&idx); - int bias = 107; - if (count >= 33900) - bias = 32768; - else if (count >= 1240) - bias = 1131; - n += bias; - if (n < 0 || n >= count) - return stbtt__new_buf(NULL, 0); - return stbtt__cff_index_get(idx, n); -} - -static stbtt__buf stbtt__cid_get_glyph_subrs(const stbtt_fontinfo *info, int glyph_index) -{ - stbtt__buf fdselect = info->fdselect; - int nranges, start, end, v, fmt, fdselector = -1, i; - - stbtt__buf_seek(&fdselect, 0); - fmt = stbtt__buf_get8(&fdselect); - if (fmt == 0) { - // untested - stbtt__buf_skip(&fdselect, glyph_index); - fdselector = stbtt__buf_get8(&fdselect); - } else if (fmt == 3) { - nranges = stbtt__buf_get16(&fdselect); - start = stbtt__buf_get16(&fdselect); - for (i = 0; i < nranges; i++) { - v = stbtt__buf_get8(&fdselect); - end = stbtt__buf_get16(&fdselect); - if (glyph_index >= start && glyph_index < end) { - fdselector = v; - break; - } - start = end; - } - } - if (fdselector == -1) stbtt__new_buf(NULL, 0); - return stbtt__get_subrs(info->cff, stbtt__cff_index_get(info->fontdicts, fdselector)); -} - -static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, stbtt__csctx *c) -{ - int in_header = 1, maskbits = 0, subr_stack_height = 0, sp = 0, v, i, b0; - int has_subrs = 0, clear_stack; - float s[48]; - stbtt__buf subr_stack[10], subrs = info->subrs, b; - float f; - -#define STBTT__CSERR(s) (0) - - // this currently ignores the initial width value, which isn't needed if we have hmtx - b = stbtt__cff_index_get(info->charstrings, glyph_index); - while (b.cursor < b.size) { - i = 0; - clear_stack = 1; - b0 = stbtt__buf_get8(&b); - switch (b0) { - // @TODO implement hinting - case 0x13: // hintmask - case 0x14: // cntrmask - if (in_header) - maskbits += (sp / 2); // implicit "vstem" - in_header = 0; - stbtt__buf_skip(&b, (maskbits + 7) / 8); - break; - - case 0x01: // hstem - case 0x03: // vstem - case 0x12: // hstemhm - case 0x17: // vstemhm - maskbits += (sp / 2); - break; - - case 0x15: // rmoveto - in_header = 0; - if (sp < 2) return STBTT__CSERR("rmoveto stack"); - stbtt__csctx_rmove_to(c, s[sp-2], s[sp-1]); - break; - case 0x04: // vmoveto - in_header = 0; - if (sp < 1) return STBTT__CSERR("vmoveto stack"); - stbtt__csctx_rmove_to(c, 0, s[sp-1]); - break; - case 0x16: // hmoveto - in_header = 0; - if (sp < 1) return STBTT__CSERR("hmoveto stack"); - stbtt__csctx_rmove_to(c, s[sp-1], 0); - break; - - case 0x05: // rlineto - if (sp < 2) return STBTT__CSERR("rlineto stack"); - for (; i + 1 < sp; i += 2) - stbtt__csctx_rline_to(c, s[i], s[i+1]); - break; - - // hlineto/vlineto and vhcurveto/hvcurveto alternate horizontal and vertical - // starting from a different place. - - case 0x07: // vlineto - if (sp < 1) return STBTT__CSERR("vlineto stack"); - goto vlineto; - case 0x06: // hlineto - if (sp < 1) return STBTT__CSERR("hlineto stack"); - for (;;) { - if (i >= sp) break; - stbtt__csctx_rline_to(c, s[i], 0); - i++; - vlineto: - if (i >= sp) break; - stbtt__csctx_rline_to(c, 0, s[i]); - i++; - } - break; - - case 0x1F: // hvcurveto - if (sp < 4) return STBTT__CSERR("hvcurveto stack"); - goto hvcurveto; - case 0x1E: // vhcurveto - if (sp < 4) return STBTT__CSERR("vhcurveto stack"); - for (;;) { - if (i + 3 >= sp) break; - stbtt__csctx_rccurve_to(c, 0, s[i], s[i+1], s[i+2], s[i+3], (sp - i == 5) ? s[i + 4] : 0.0f); - i += 4; - hvcurveto: - if (i + 3 >= sp) break; - stbtt__csctx_rccurve_to(c, s[i], 0, s[i+1], s[i+2], (sp - i == 5) ? s[i+4] : 0.0f, s[i+3]); - i += 4; - } - break; - - case 0x08: // rrcurveto - if (sp < 6) return STBTT__CSERR("rcurveline stack"); - for (; i + 5 < sp; i += 6) - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - break; - - case 0x18: // rcurveline - if (sp < 8) return STBTT__CSERR("rcurveline stack"); - for (; i + 5 < sp - 2; i += 6) - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - if (i + 1 >= sp) return STBTT__CSERR("rcurveline stack"); - stbtt__csctx_rline_to(c, s[i], s[i+1]); - break; - - case 0x19: // rlinecurve - if (sp < 8) return STBTT__CSERR("rlinecurve stack"); - for (; i + 1 < sp - 6; i += 2) - stbtt__csctx_rline_to(c, s[i], s[i+1]); - if (i + 5 >= sp) return STBTT__CSERR("rlinecurve stack"); - stbtt__csctx_rccurve_to(c, s[i], s[i+1], s[i+2], s[i+3], s[i+4], s[i+5]); - break; - - case 0x1A: // vvcurveto - case 0x1B: // hhcurveto - if (sp < 4) return STBTT__CSERR("(vv|hh)curveto stack"); - f = 0.0; - if (sp & 1) { f = s[i]; i++; } - for (; i + 3 < sp; i += 4) { - if (b0 == 0x1B) - stbtt__csctx_rccurve_to(c, s[i], f, s[i+1], s[i+2], s[i+3], 0.0); - else - stbtt__csctx_rccurve_to(c, f, s[i], s[i+1], s[i+2], 0.0, s[i+3]); - f = 0.0; - } - break; - - case 0x0A: // callsubr - if (!has_subrs) { - if (info->fdselect.size) - subrs = stbtt__cid_get_glyph_subrs(info, glyph_index); - has_subrs = 1; - } - // FALLTHROUGH - case 0x1D: // callgsubr - if (sp < 1) return STBTT__CSERR("call(g|)subr stack"); - v = (int) s[--sp]; - if (subr_stack_height >= 10) return STBTT__CSERR("recursion limit"); - subr_stack[subr_stack_height++] = b; - b = stbtt__get_subr(b0 == 0x0A ? subrs : info->gsubrs, v); - if (b.size == 0) return STBTT__CSERR("subr not found"); - b.cursor = 0; - clear_stack = 0; - break; - - case 0x0B: // return - if (subr_stack_height <= 0) return STBTT__CSERR("return outside subr"); - b = subr_stack[--subr_stack_height]; - clear_stack = 0; - break; - - case 0x0E: // endchar - stbtt__csctx_close_shape(c); - return 1; - - case 0x0C: { // two-byte escape - float dx1, dx2, dx3, dx4, dx5, dx6, dy1, dy2, dy3, dy4, dy5, dy6; - float dx, dy; - int b1 = stbtt__buf_get8(&b); - switch (b1) { - // @TODO These "flex" implementations ignore the flex-depth and resolution, - // and always draw beziers. - case 0x22: // hflex - if (sp < 7) return STBTT__CSERR("hflex stack"); - dx1 = s[0]; - dx2 = s[1]; - dy2 = s[2]; - dx3 = s[3]; - dx4 = s[4]; - dx5 = s[5]; - dx6 = s[6]; - stbtt__csctx_rccurve_to(c, dx1, 0, dx2, dy2, dx3, 0); - stbtt__csctx_rccurve_to(c, dx4, 0, dx5, -dy2, dx6, 0); - break; - - case 0x23: // flex - if (sp < 13) return STBTT__CSERR("flex stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dy3 = s[5]; - dx4 = s[6]; - dy4 = s[7]; - dx5 = s[8]; - dy5 = s[9]; - dx6 = s[10]; - dy6 = s[11]; - //fd is s[12] - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); - stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); - break; - - case 0x24: // hflex1 - if (sp < 9) return STBTT__CSERR("hflex1 stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dx4 = s[5]; - dx5 = s[6]; - dy5 = s[7]; - dx6 = s[8]; - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, 0); - stbtt__csctx_rccurve_to(c, dx4, 0, dx5, dy5, dx6, -(dy1+dy2+dy5)); - break; - - case 0x25: // flex1 - if (sp < 11) return STBTT__CSERR("flex1 stack"); - dx1 = s[0]; - dy1 = s[1]; - dx2 = s[2]; - dy2 = s[3]; - dx3 = s[4]; - dy3 = s[5]; - dx4 = s[6]; - dy4 = s[7]; - dx5 = s[8]; - dy5 = s[9]; - dx6 = dy6 = s[10]; - dx = dx1+dx2+dx3+dx4+dx5; - dy = dy1+dy2+dy3+dy4+dy5; - if (STBTT_fabs(dx) > STBTT_fabs(dy)) - dy6 = -dy; - else - dx6 = -dx; - stbtt__csctx_rccurve_to(c, dx1, dy1, dx2, dy2, dx3, dy3); - stbtt__csctx_rccurve_to(c, dx4, dy4, dx5, dy5, dx6, dy6); - break; - - default: - return STBTT__CSERR("unimplemented"); - } - } break; - - default: - if (b0 != 255 && b0 != 28 && b0 < 32) - return STBTT__CSERR("reserved operator"); - - // push immediate - if (b0 == 255) { - f = (float)(stbtt_int32)stbtt__buf_get32(&b) / 0x10000; - } else { - stbtt__buf_skip(&b, -1); - f = (float)(stbtt_int16)stbtt__cff_int(&b); - } - if (sp >= 48) return STBTT__CSERR("push stack overflow"); - s[sp++] = f; - clear_stack = 0; - break; - } - if (clear_stack) sp = 0; - } - return STBTT__CSERR("no endchar"); - -#undef STBTT__CSERR -} - -static int stbtt__GetGlyphShapeT2(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - // runs the charstring twice, once to count and once to output (to avoid realloc) - stbtt__csctx count_ctx = STBTT__CSCTX_INIT(1); - stbtt__csctx output_ctx = STBTT__CSCTX_INIT(0); - if (stbtt__run_charstring(info, glyph_index, &count_ctx)) { - *pvertices = (stbtt_vertex*)STBTT_malloc(count_ctx.num_vertices*sizeof(stbtt_vertex), info->userdata); - output_ctx.pvertices = *pvertices; - if (stbtt__run_charstring(info, glyph_index, &output_ctx)) { - STBTT_assert(output_ctx.num_vertices == count_ctx.num_vertices); - return output_ctx.num_vertices; - } - } - *pvertices = NULL; - return 0; -} - -static int stbtt__GetGlyphInfoT2(const stbtt_fontinfo *info, int glyph_index, int *x0, int *y0, int *x1, int *y1) -{ - stbtt__csctx c = STBTT__CSCTX_INIT(1); - int r = stbtt__run_charstring(info, glyph_index, &c); - if (x0) *x0 = r ? c.min_x : 0; - if (y0) *y0 = r ? c.min_y : 0; - if (x1) *x1 = r ? c.max_x : 0; - if (y1) *y1 = r ? c.max_y : 0; - return r ? c.num_vertices : 0; -} - -STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, stbtt_vertex **pvertices) -{ - if (!info->cff.size) - return stbtt__GetGlyphShapeTT(info, glyph_index, pvertices); - else - return stbtt__GetGlyphShapeT2(info, glyph_index, pvertices); -} - -STBTT_DEF void stbtt_GetGlyphHMetrics(const stbtt_fontinfo *info, int glyph_index, int *advanceWidth, int *leftSideBearing) -{ - stbtt_uint16 numOfLongHorMetrics = ttUSHORT(info->data+info->hhea + 34); - if (glyph_index < numOfLongHorMetrics) { - if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*glyph_index); - if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*glyph_index + 2); - } else { - if (advanceWidth) *advanceWidth = ttSHORT(info->data + info->hmtx + 4*(numOfLongHorMetrics-1)); - if (leftSideBearing) *leftSideBearing = ttSHORT(info->data + info->hmtx + 4*numOfLongHorMetrics + 2*(glyph_index - numOfLongHorMetrics)); - } -} - -STBTT_DEF int stbtt_GetKerningTableLength(const stbtt_fontinfo *info) -{ - stbtt_uint8 *data = info->data + info->kern; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - return ttUSHORT(data+10); -} - -STBTT_DEF int stbtt_GetKerningTable(const stbtt_fontinfo *info, stbtt_kerningentry* table, int table_length) -{ - stbtt_uint8 *data = info->data + info->kern; - int k, length; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - length = ttUSHORT(data+10); - if (table_length < length) - length = table_length; - - for (k = 0; k < length; k++) - { - table[k].glyph1 = ttUSHORT(data+18+(k*6)); - table[k].glyph2 = ttUSHORT(data+20+(k*6)); - table[k].advance = ttSHORT(data+22+(k*6)); - } - - return length; -} - -static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) -{ - stbtt_uint8 *data = info->data + info->kern; - stbtt_uint32 needle, straw; - int l, r, m; - - // we only look at the first table. it must be 'horizontal' and format 0. - if (!info->kern) - return 0; - if (ttUSHORT(data+2) < 1) // number of tables, need at least 1 - return 0; - if (ttUSHORT(data+8) != 1) // horizontal flag must be set in format - return 0; - - l = 0; - r = ttUSHORT(data+10) - 1; - needle = glyph1 << 16 | glyph2; - while (l <= r) { - m = (l + r) >> 1; - straw = ttULONG(data+18+(m*6)); // note: unaligned read - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else - return ttSHORT(data+22+(m*6)); - } - return 0; -} - -static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph) -{ - stbtt_uint16 coverageFormat = ttUSHORT(coverageTable); - switch (coverageFormat) { - case 1: { - stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2); - - // Binary search. - stbtt_int32 l=0, r=glyphCount-1, m; - int straw, needle=glyph; - while (l <= r) { - stbtt_uint8 *glyphArray = coverageTable + 4; - stbtt_uint16 glyphID; - m = (l + r) >> 1; - glyphID = ttUSHORT(glyphArray + 2 * m); - straw = glyphID; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - return m; - } - } - break; - } - - case 2: { - stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2); - stbtt_uint8 *rangeArray = coverageTable + 4; - - // Binary search. - stbtt_int32 l=0, r=rangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *rangeRecord; - m = (l + r) >> 1; - rangeRecord = rangeArray + 6 * m; - strawStart = ttUSHORT(rangeRecord); - strawEnd = ttUSHORT(rangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else { - stbtt_uint16 startCoverageIndex = ttUSHORT(rangeRecord + 4); - return startCoverageIndex + glyph - strawStart; - } - } - break; - } - - default: return -1; // unsupported - } - - return -1; -} - -static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph) -{ - stbtt_uint16 classDefFormat = ttUSHORT(classDefTable); - switch (classDefFormat) - { - case 1: { - stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2); - stbtt_uint16 glyphCount = ttUSHORT(classDefTable + 4); - stbtt_uint8 *classDef1ValueArray = classDefTable + 6; - - if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount) - return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID)); - break; - } - - case 2: { - stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2); - stbtt_uint8 *classRangeRecords = classDefTable + 4; - - // Binary search. - stbtt_int32 l=0, r=classRangeCount-1, m; - int strawStart, strawEnd, needle=glyph; - while (l <= r) { - stbtt_uint8 *classRangeRecord; - m = (l + r) >> 1; - classRangeRecord = classRangeRecords + 6 * m; - strawStart = ttUSHORT(classRangeRecord); - strawEnd = ttUSHORT(classRangeRecord + 2); - if (needle < strawStart) - r = m - 1; - else if (needle > strawEnd) - l = m + 1; - else - return (stbtt_int32)ttUSHORT(classRangeRecord + 4); - } - break; - } - - default: - return -1; // Unsupported definition type, return an error. - } - - // "All glyphs not assigned to a class fall into class 0". (OpenType spec) - return 0; -} - -// Define to STBTT_assert(x) if you want to break on unimplemented formats. -#define STBTT_GPOS_TODO_assert(x) - -static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, int glyph1, int glyph2) -{ - stbtt_uint16 lookupListOffset; - stbtt_uint8 *lookupList; - stbtt_uint16 lookupCount; - stbtt_uint8 *data; - stbtt_int32 i, sti; - - if (!info->gpos) return 0; - - data = info->data + info->gpos; - - if (ttUSHORT(data+0) != 1) return 0; // Major version 1 - if (ttUSHORT(data+2) != 0) return 0; // Minor version 0 - - lookupListOffset = ttUSHORT(data+8); - lookupList = data + lookupListOffset; - lookupCount = ttUSHORT(lookupList); - - for (i=0; i= pairSetCount) return 0; - - needle=glyph2; - r=pairValueCount-1; - l=0; - - // Binary search. - while (l <= r) { - stbtt_uint16 secondGlyph; - stbtt_uint8 *pairValue; - m = (l + r) >> 1; - pairValue = pairValueArray + (2 + valueRecordPairSizeInBytes) * m; - secondGlyph = ttUSHORT(pairValue); - straw = secondGlyph; - if (needle < straw) - r = m - 1; - else if (needle > straw) - l = m + 1; - else { - stbtt_int16 xAdvance = ttSHORT(pairValue + 2); - return xAdvance; - } - } - } else - return 0; - break; - } - - case 2: { - stbtt_uint16 valueFormat1 = ttUSHORT(table + 4); - stbtt_uint16 valueFormat2 = ttUSHORT(table + 6); - if (valueFormat1 == 4 && valueFormat2 == 0) { // Support more formats? - stbtt_uint16 classDef1Offset = ttUSHORT(table + 8); - stbtt_uint16 classDef2Offset = ttUSHORT(table + 10); - int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1); - int glyph2class = stbtt__GetGlyphClass(table + classDef2Offset, glyph2); - - stbtt_uint16 class1Count = ttUSHORT(table + 12); - stbtt_uint16 class2Count = ttUSHORT(table + 14); - stbtt_uint8 *class1Records, *class2Records; - stbtt_int16 xAdvance; - - if (glyph1class < 0 || glyph1class >= class1Count) return 0; // malformed - if (glyph2class < 0 || glyph2class >= class2Count) return 0; // malformed - - class1Records = table + 16; - class2Records = class1Records + 2 * (glyph1class * class2Count); - xAdvance = ttSHORT(class2Records + 2 * glyph2class); - return xAdvance; - } else - return 0; - break; - } - - default: - return 0; // Unsupported position format - } - } - } - - return 0; -} - -STBTT_DEF int stbtt_GetGlyphKernAdvance(const stbtt_fontinfo *info, int g1, int g2) -{ - int xAdvance = 0; - - if (info->gpos) - xAdvance += stbtt__GetGlyphGPOSInfoAdvance(info, g1, g2); - else if (info->kern) - xAdvance += stbtt__GetGlyphKernInfoAdvance(info, g1, g2); - - return xAdvance; -} - -STBTT_DEF int stbtt_GetCodepointKernAdvance(const stbtt_fontinfo *info, int ch1, int ch2) -{ - if (!info->kern && !info->gpos) // if no kerning table, don't waste time looking up both codepoint->glyphs - return 0; - return stbtt_GetGlyphKernAdvance(info, stbtt_FindGlyphIndex(info,ch1), stbtt_FindGlyphIndex(info,ch2)); -} - -STBTT_DEF void stbtt_GetCodepointHMetrics(const stbtt_fontinfo *info, int codepoint, int *advanceWidth, int *leftSideBearing) -{ - stbtt_GetGlyphHMetrics(info, stbtt_FindGlyphIndex(info,codepoint), advanceWidth, leftSideBearing); -} - -STBTT_DEF void stbtt_GetFontVMetrics(const stbtt_fontinfo *info, int *ascent, int *descent, int *lineGap) -{ - if (ascent ) *ascent = ttSHORT(info->data+info->hhea + 4); - if (descent) *descent = ttSHORT(info->data+info->hhea + 6); - if (lineGap) *lineGap = ttSHORT(info->data+info->hhea + 8); -} - -STBTT_DEF int stbtt_GetFontVMetricsOS2(const stbtt_fontinfo *info, int *typoAscent, int *typoDescent, int *typoLineGap) -{ - int tab = stbtt__find_table(info->data, info->fontstart, "OS/2"); - if (!tab) - return 0; - if (typoAscent ) *typoAscent = ttSHORT(info->data+tab + 68); - if (typoDescent) *typoDescent = ttSHORT(info->data+tab + 70); - if (typoLineGap) *typoLineGap = ttSHORT(info->data+tab + 72); - return 1; -} - -STBTT_DEF void stbtt_GetFontBoundingBox(const stbtt_fontinfo *info, int *x0, int *y0, int *x1, int *y1) -{ - *x0 = ttSHORT(info->data + info->head + 36); - *y0 = ttSHORT(info->data + info->head + 38); - *x1 = ttSHORT(info->data + info->head + 40); - *y1 = ttSHORT(info->data + info->head + 42); -} - -STBTT_DEF float stbtt_ScaleForPixelHeight(const stbtt_fontinfo *info, float height) -{ - int fheight = ttSHORT(info->data + info->hhea + 4) - ttSHORT(info->data + info->hhea + 6); - return (float) height / fheight; -} - -STBTT_DEF float stbtt_ScaleForMappingEmToPixels(const stbtt_fontinfo *info, float pixels) -{ - int unitsPerEm = ttUSHORT(info->data + info->head + 18); - return pixels / unitsPerEm; -} - -STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *v) -{ - STBTT_free(v, info->userdata); -} - -STBTT_DEF stbtt_uint8 *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl) -{ - int i; - stbtt_uint8 *data = info->data; - stbtt_uint8 *svg_doc_list = data + stbtt__get_svg((stbtt_fontinfo *) info); - - int numEntries = ttUSHORT(svg_doc_list); - stbtt_uint8 *svg_docs = svg_doc_list + 2; - - for(i=0; i= ttUSHORT(svg_doc)) && (gl <= ttUSHORT(svg_doc + 2))) - return svg_doc; - } - return 0; -} - -STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg) -{ - stbtt_uint8 *data = info->data; - stbtt_uint8 *svg_doc; - - if (info->svg == 0) - return 0; - - svg_doc = stbtt_FindSVGDoc(info, gl); - if (svg_doc != NULL) { - *svg = (char *) data + info->svg + ttULONG(svg_doc + 4); - return ttULONG(svg_doc + 8); - } else { - return 0; - } -} - -STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg) -{ - return stbtt_GetGlyphSVG(info, stbtt_FindGlyphIndex(info, unicode_codepoint), svg); -} - -////////////////////////////////////////////////////////////////////////////// -// -// antialiasing software rasterizer -// - -STBTT_DEF void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y,float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - int x0=0,y0=0,x1,y1; // =0 suppresses compiler warning - if (!stbtt_GetGlyphBox(font, glyph, &x0,&y0,&x1,&y1)) { - // e.g. space character - if (ix0) *ix0 = 0; - if (iy0) *iy0 = 0; - if (ix1) *ix1 = 0; - if (iy1) *iy1 = 0; - } else { - // move to integral bboxes (treating pixels as little squares, what pixels get touched)? - if (ix0) *ix0 = STBTT_ifloor( x0 * scale_x + shift_x); - if (iy0) *iy0 = STBTT_ifloor(-y1 * scale_y + shift_y); - if (ix1) *ix1 = STBTT_iceil ( x1 * scale_x + shift_x); - if (iy1) *iy1 = STBTT_iceil (-y0 * scale_y + shift_y); - } -} - -STBTT_DEF void stbtt_GetGlyphBitmapBox(const stbtt_fontinfo *font, int glyph, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetGlyphBitmapBoxSubpixel(font, glyph, scale_x, scale_y,0.0f,0.0f, ix0, iy0, ix1, iy1); -} - -STBTT_DEF void stbtt_GetCodepointBitmapBoxSubpixel(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, float shift_x, float shift_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetGlyphBitmapBoxSubpixel(font, stbtt_FindGlyphIndex(font,codepoint), scale_x, scale_y,shift_x,shift_y, ix0,iy0,ix1,iy1); -} - -STBTT_DEF void stbtt_GetCodepointBitmapBox(const stbtt_fontinfo *font, int codepoint, float scale_x, float scale_y, int *ix0, int *iy0, int *ix1, int *iy1) -{ - stbtt_GetCodepointBitmapBoxSubpixel(font, codepoint, scale_x, scale_y,0.0f,0.0f, ix0,iy0,ix1,iy1); -} - -////////////////////////////////////////////////////////////////////////////// -// -// Rasterizer - -typedef struct stbtt__hheap_chunk -{ - struct stbtt__hheap_chunk *next; -} stbtt__hheap_chunk; - -typedef struct stbtt__hheap -{ - struct stbtt__hheap_chunk *head; - void *first_free; - int num_remaining_in_head_chunk; -} stbtt__hheap; - -static void *stbtt__hheap_alloc(stbtt__hheap *hh, size_t size, void *userdata) -{ - if (hh->first_free) { - void *p = hh->first_free; - hh->first_free = * (void **) p; - return p; - } else { - if (hh->num_remaining_in_head_chunk == 0) { - int count = (size < 32 ? 2000 : size < 128 ? 800 : 100); - stbtt__hheap_chunk *c = (stbtt__hheap_chunk *) STBTT_malloc(sizeof(stbtt__hheap_chunk) + size * count, userdata); - if (c == NULL) - return NULL; - c->next = hh->head; - hh->head = c; - hh->num_remaining_in_head_chunk = count; - } - --hh->num_remaining_in_head_chunk; - return (char *) (hh->head) + sizeof(stbtt__hheap_chunk) + size * hh->num_remaining_in_head_chunk; - } -} - -static void stbtt__hheap_free(stbtt__hheap *hh, void *p) -{ - *(void **) p = hh->first_free; - hh->first_free = p; -} - -static void stbtt__hheap_cleanup(stbtt__hheap *hh, void *userdata) -{ - stbtt__hheap_chunk *c = hh->head; - while (c) { - stbtt__hheap_chunk *n = c->next; - STBTT_free(c, userdata); - c = n; - } -} - -typedef struct stbtt__edge { - float x0,y0, x1,y1; - int invert; -} stbtt__edge; - - -typedef struct stbtt__active_edge -{ - struct stbtt__active_edge *next; - #if STBTT_RASTERIZER_VERSION==1 - int x,dx; - float ey; - int direction; - #elif STBTT_RASTERIZER_VERSION==2 - float fx,fdx,fdy; - float direction; - float sy; - float ey; - #else - #error "Unrecognized value of STBTT_RASTERIZER_VERSION" - #endif -} stbtt__active_edge; - -#if STBTT_RASTERIZER_VERSION == 1 -#define STBTT_FIXSHIFT 10 -#define STBTT_FIX (1 << STBTT_FIXSHIFT) -#define STBTT_FIXMASK (STBTT_FIX-1) - -static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) -{ - stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); - float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); - STBTT_assert(z != NULL); - if (!z) return z; - - // round dx down to avoid overshooting - if (dxdy < 0) - z->dx = -STBTT_ifloor(STBTT_FIX * -dxdy); - else - z->dx = STBTT_ifloor(STBTT_FIX * dxdy); - - z->x = STBTT_ifloor(STBTT_FIX * e->x0 + z->dx * (start_point - e->y0)); // use z->dx so when we offset later it's by the same amount - z->x -= off_x * STBTT_FIX; - - z->ey = e->y1; - z->next = 0; - z->direction = e->invert ? 1 : -1; - return z; -} -#elif STBTT_RASTERIZER_VERSION == 2 -static stbtt__active_edge *stbtt__new_active(stbtt__hheap *hh, stbtt__edge *e, int off_x, float start_point, void *userdata) -{ - stbtt__active_edge *z = (stbtt__active_edge *) stbtt__hheap_alloc(hh, sizeof(*z), userdata); - float dxdy = (e->x1 - e->x0) / (e->y1 - e->y0); - STBTT_assert(z != NULL); - //STBTT_assert(e->y0 <= start_point); - if (!z) return z; - z->fdx = dxdy; - z->fdy = dxdy != 0.0f ? (1.0f/dxdy) : 0.0f; - z->fx = e->x0 + dxdy * (start_point - e->y0); - z->fx -= off_x; - z->direction = e->invert ? 1.0f : -1.0f; - z->sy = e->y0; - z->ey = e->y1; - z->next = 0; - return z; -} -#else -#error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - -#if STBTT_RASTERIZER_VERSION == 1 -// note: this routine clips fills that extend off the edges... ideally this -// wouldn't happen, but it could happen if the truetype glyph bounding boxes -// are wrong, or if the user supplies a too-small bitmap -static void stbtt__fill_active_edges(unsigned char *scanline, int len, stbtt__active_edge *e, int max_weight) -{ - // non-zero winding fill - int x0=0, w=0; - - while (e) { - if (w == 0) { - // if we're currently at zero, we need to record the edge start point - x0 = e->x; w += e->direction; - } else { - int x1 = e->x; w += e->direction; - // if we went to zero, we need to draw - if (w == 0) { - int i = x0 >> STBTT_FIXSHIFT; - int j = x1 >> STBTT_FIXSHIFT; - - if (i < len && j >= 0) { - if (i == j) { - // x0,x1 are the same pixel, so compute combined coverage - scanline[i] = scanline[i] + (stbtt_uint8) ((x1 - x0) * max_weight >> STBTT_FIXSHIFT); - } else { - if (i >= 0) // add antialiasing for x0 - scanline[i] = scanline[i] + (stbtt_uint8) (((STBTT_FIX - (x0 & STBTT_FIXMASK)) * max_weight) >> STBTT_FIXSHIFT); - else - i = -1; // clip - - if (j < len) // add antialiasing for x1 - scanline[j] = scanline[j] + (stbtt_uint8) (((x1 & STBTT_FIXMASK) * max_weight) >> STBTT_FIXSHIFT); - else - j = len; // clip - - for (++i; i < j; ++i) // fill pixels between x0 and x1 - scanline[i] = scanline[i] + (stbtt_uint8) max_weight; - } - } - } - } - - e = e->next; - } -} - -static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) -{ - stbtt__hheap hh = { 0, 0, 0 }; - stbtt__active_edge *active = NULL; - int y,j=0; - int max_weight = (255 / vsubsample); // weight per vertical scanline - int s; // vertical subsample index - unsigned char scanline_data[512], *scanline; - - if (result->w > 512) - scanline = (unsigned char *) STBTT_malloc(result->w, userdata); - else - scanline = scanline_data; - - y = off_y * vsubsample; - e[n].y0 = (off_y + result->h) * (float) vsubsample + 1; - - while (j < result->h) { - STBTT_memset(scanline, 0, result->w); - for (s=0; s < vsubsample; ++s) { - // find center of pixel for this scanline - float scan_y = y + 0.5f; - stbtt__active_edge **step = &active; - - // update all active edges; - // remove all active edges that terminate before the center of this scanline - while (*step) { - stbtt__active_edge * z = *step; - if (z->ey <= scan_y) { - *step = z->next; // delete from list - STBTT_assert(z->direction); - z->direction = 0; - stbtt__hheap_free(&hh, z); - } else { - z->x += z->dx; // advance to position for current scanline - step = &((*step)->next); // advance through list - } - } - - // resort the list if needed - for(;;) { - int changed=0; - step = &active; - while (*step && (*step)->next) { - if ((*step)->x > (*step)->next->x) { - stbtt__active_edge *t = *step; - stbtt__active_edge *q = t->next; - - t->next = q->next; - q->next = t; - *step = q; - changed = 1; - } - step = &(*step)->next; - } - if (!changed) break; - } - - // insert all edges that start before the center of this scanline -- omit ones that also end on this scanline - while (e->y0 <= scan_y) { - if (e->y1 > scan_y) { - stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y, userdata); - if (z != NULL) { - // find insertion point - if (active == NULL) - active = z; - else if (z->x < active->x) { - // insert at front - z->next = active; - active = z; - } else { - // find thing to insert AFTER - stbtt__active_edge *p = active; - while (p->next && p->next->x < z->x) - p = p->next; - // at this point, p->next->x is NOT < z->x - z->next = p->next; - p->next = z; - } - } - } - ++e; - } - - // now process all active edges in XOR fashion - if (active) - stbtt__fill_active_edges(scanline, result->w, active, max_weight); - - ++y; - } - STBTT_memcpy(result->pixels + j * result->stride, scanline, result->w); - ++j; - } - - stbtt__hheap_cleanup(&hh, userdata); - - if (scanline != scanline_data) - STBTT_free(scanline, userdata); -} - -#elif STBTT_RASTERIZER_VERSION == 2 - -// the edge passed in here does not cross the vertical line at x or the vertical line at x+1 -// (i.e. it has already been clipped to those) -static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edge *e, float x0, float y0, float x1, float y1) -{ - if (y0 == y1) return; - STBTT_assert(y0 < y1); - STBTT_assert(e->sy <= e->ey); - if (y0 > e->ey) return; - if (y1 < e->sy) return; - if (y0 < e->sy) { - x0 += (x1-x0) * (e->sy - y0) / (y1-y0); - y0 = e->sy; - } - if (y1 > e->ey) { - x1 += (x1-x0) * (e->ey - y1) / (y1-y0); - y1 = e->ey; - } - - if (x0 == x) - STBTT_assert(x1 <= x+1); - else if (x0 == x+1) - STBTT_assert(x1 >= x); - else if (x0 <= x) - STBTT_assert(x1 <= x); - else if (x0 >= x+1) - STBTT_assert(x1 >= x+1); - else - STBTT_assert(x1 >= x && x1 <= x+1); - - if (x0 <= x && x1 <= x) - scanline[x] += e->direction * (y1-y0); - else if (x0 >= x+1 && x1 >= x+1) - ; - else { - STBTT_assert(x0 >= x && x0 <= x+1 && x1 >= x && x1 <= x+1); - scanline[x] += e->direction * (y1-y0) * (1-((x0-x)+(x1-x))/2); // coverage = 1 - average x position - } -} - -static float stbtt__sized_trapezoid_area(float height, float top_width, float bottom_width) -{ - STBTT_assert(top_width >= 0); - STBTT_assert(bottom_width >= 0); - return (top_width + bottom_width) / 2.0f * height; -} - -static float stbtt__position_trapezoid_area(float height, float tx0, float tx1, float bx0, float bx1) -{ - return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0); -} - -static float stbtt__sized_triangle_area(float height, float width) -{ - return height * width / 2; -} - -static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top) -{ - float y_bottom = y_top+1; - - while (e) { - // brute force every pixel - - // compute intersection points with top & bottom - STBTT_assert(e->ey >= y_top); - - if (e->fdx == 0) { - float x0 = e->fx; - if (x0 < len) { - if (x0 >= 0) { - stbtt__handle_clipped_edge(scanline,(int) x0,e, x0,y_top, x0,y_bottom); - stbtt__handle_clipped_edge(scanline_fill-1,(int) x0+1,e, x0,y_top, x0,y_bottom); - } else { - stbtt__handle_clipped_edge(scanline_fill-1,0,e, x0,y_top, x0,y_bottom); - } - } - } else { - float x0 = e->fx; - float dx = e->fdx; - float xb = x0 + dx; - float x_top, x_bottom; - float sy0,sy1; - float dy = e->fdy; - STBTT_assert(e->sy <= y_bottom && e->ey >= y_top); - - // compute endpoints of line segment clipped to this scanline (if the - // line segment starts on this scanline. x0 is the intersection of the - // line with y_top, but that may be off the line segment. - if (e->sy > y_top) { - x_top = x0 + dx * (e->sy - y_top); - sy0 = e->sy; - } else { - x_top = x0; - sy0 = y_top; - } - if (e->ey < y_bottom) { - x_bottom = x0 + dx * (e->ey - y_top); - sy1 = e->ey; - } else { - x_bottom = xb; - sy1 = y_bottom; - } - - if (x_top >= 0 && x_bottom >= 0 && x_top < len && x_bottom < len) { - // from here on, we don't have to range check x values - - if ((int) x_top == (int) x_bottom) { - float height; - // simple case, only spans one pixel - int x = (int) x_top; - height = (sy1 - sy0) * e->direction; - STBTT_assert(x >= 0 && x < len); - scanline[x] += stbtt__position_trapezoid_area(height, x_top, x+1.0f, x_bottom, x+1.0f); - scanline_fill[x] += height; // everything right of this pixel is filled - } else { - int x,x1,x2; - float y_crossing, y_final, step, sign, area; - // covers 2+ pixels - if (x_top > x_bottom) { - // flip scanline vertically; signed area is the same - float t; - sy0 = y_bottom - (sy0 - y_top); - sy1 = y_bottom - (sy1 - y_top); - t = sy0, sy0 = sy1, sy1 = t; - t = x_bottom, x_bottom = x_top, x_top = t; - dx = -dx; - dy = -dy; - t = x0, x0 = xb, xb = t; - } - STBTT_assert(dy >= 0); - STBTT_assert(dx >= 0); - - x1 = (int) x_top; - x2 = (int) x_bottom; - // compute intersection with y axis at x1+1 - y_crossing = y_top + dy * (x1+1 - x0); - - // compute intersection with y axis at x2 - y_final = y_top + dy * (x2 - x0); - - // x1 x_top x2 x_bottom - // y_top +------|-----+------------+------------+--------|---+------------+ - // | | | | | | - // | | | | | | - // sy0 | Txxxxx|............|............|............|............| - // y_crossing | *xxxxx.......|............|............|............| - // | | xxxxx..|............|............|............| - // | | /- xx*xxxx........|............|............| - // | | dy < | xxxxxx..|............|............| - // y_final | | \- | xx*xxx.........|............| - // sy1 | | | | xxxxxB...|............| - // | | | | | | - // | | | | | | - // y_bottom +------------+------------+------------+------------+------------+ - // - // goal is to measure the area covered by '.' in each pixel - - // if x2 is right at the right edge of x1, y_crossing can blow up, github #1057 - // @TODO: maybe test against sy1 rather than y_bottom? - if (y_crossing > y_bottom) - y_crossing = y_bottom; - - sign = e->direction; - - // area of the rectangle covered from sy0..y_crossing - area = sign * (y_crossing-sy0); - - // area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing) - scanline[x1] += stbtt__sized_triangle_area(area, x1+1 - x_top); - - // check if final y_crossing is blown up; no test case for this - if (y_final > y_bottom) { - y_final = y_bottom; - dy = (y_final - y_crossing ) / (x2 - (x1+1)); // if denom=0, y_final = y_crossing, so y_final <= y_bottom - } - - // in second pixel, area covered by line segment found in first pixel - // is always a rectangle 1 wide * the height of that line segment; this - // is exactly what the variable 'area' stores. it also gets a contribution - // from the line segment within it. the THIRD pixel will get the first - // pixel's rectangle contribution, the second pixel's rectangle contribution, - // and its own contribution. the 'own contribution' is the same in every pixel except - // the leftmost and rightmost, a trapezoid that slides down in each pixel. - // the second pixel's contribution to the third pixel will be the - // rectangle 1 wide times the height change in the second pixel, which is dy. - - step = sign * dy * 1; // dy is dy/dx, change in y for every 1 change in x, - // which multiplied by 1-pixel-width is how much pixel area changes for each step in x - // so the area advances by 'step' every time - - for (x = x1+1; x < x2; ++x) { - scanline[x] += area + step/2; // area of trapezoid is 1*step/2 - area += step; - } - STBTT_assert(STBTT_fabs(area) <= 1.01f); // accumulated error from area += step unless we round step down - STBTT_assert(sy1 > y_final-0.01f); - - // area covered in the last pixel is the rectangle from all the pixels to the left, - // plus the trapezoid filled by the line segment in this pixel all the way to the right edge - scanline[x2] += area + sign * stbtt__position_trapezoid_area(sy1-y_final, (float) x2, x2+1.0f, x_bottom, x2+1.0f); - - // the rest of the line is filled based on the total height of the line segment in this pixel - scanline_fill[x2] += sign * (sy1-sy0); - } - } else { - // if edge goes outside of box we're drawing, we require - // clipping logic. since this does not match the intended use - // of this library, we use a different, very slow brute - // force implementation - // note though that this does happen some of the time because - // x_top and x_bottom can be extrapolated at the top & bottom of - // the shape and actually lie outside the bounding box - int x; - for (x=0; x < len; ++x) { - // cases: - // - // there can be up to two intersections with the pixel. any intersection - // with left or right edges can be handled by splitting into two (or three) - // regions. intersections with top & bottom do not necessitate case-wise logic. - // - // the old way of doing this found the intersections with the left & right edges, - // then used some simple logic to produce up to three segments in sorted order - // from top-to-bottom. however, this had a problem: if an x edge was epsilon - // across the x border, then the corresponding y position might not be distinct - // from the other y segment, and it might ignored as an empty segment. to avoid - // that, we need to explicitly produce segments based on x positions. - - // rename variables to clearly-defined pairs - float y0 = y_top; - float x1 = (float) (x); - float x2 = (float) (x+1); - float x3 = xb; - float y3 = y_bottom; - - // x = e->x + e->dx * (y-y_top) - // (y-y_top) = (x - e->x) / e->dx - // y = (x - e->x) / e->dx + y_top - float y1 = (x - x0) / dx + y_top; - float y2 = (x+1 - x0) / dx + y_top; - - if (x0 < x1 && x3 > x2) { // three segments descending down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else if (x3 < x1 && x0 > x2) { // three segments descending down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x0 < x1 && x3 > x1) { // two segments across x, down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x3 < x1 && x0 > x1) { // two segments across x, down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x1,y1); - stbtt__handle_clipped_edge(scanline,x,e, x1,y1, x3,y3); - } else if (x0 < x2 && x3 > x2) { // two segments across x+1, down-right - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else if (x3 < x2 && x0 > x2) { // two segments across x+1, down-left - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x2,y2); - stbtt__handle_clipped_edge(scanline,x,e, x2,y2, x3,y3); - } else { // one segment - stbtt__handle_clipped_edge(scanline,x,e, x0,y0, x3,y3); - } - } - } - } - e = e->next; - } -} - -// directly AA rasterize edges w/o supersampling -static void stbtt__rasterize_sorted_edges(stbtt__bitmap *result, stbtt__edge *e, int n, int vsubsample, int off_x, int off_y, void *userdata) -{ - stbtt__hheap hh = { 0, 0, 0 }; - stbtt__active_edge *active = NULL; - int y,j=0, i; - float scanline_data[129], *scanline, *scanline2; - - STBTT__NOTUSED(vsubsample); - - if (result->w > 64) - scanline = (float *) STBTT_malloc((result->w*2+1) * sizeof(float), userdata); - else - scanline = scanline_data; - - scanline2 = scanline + result->w; - - y = off_y; - e[n].y0 = (float) (off_y + result->h) + 1; - - while (j < result->h) { - // find center of pixel for this scanline - float scan_y_top = y + 0.0f; - float scan_y_bottom = y + 1.0f; - stbtt__active_edge **step = &active; - - STBTT_memset(scanline , 0, result->w*sizeof(scanline[0])); - STBTT_memset(scanline2, 0, (result->w+1)*sizeof(scanline[0])); - - // update all active edges; - // remove all active edges that terminate before the top of this scanline - while (*step) { - stbtt__active_edge * z = *step; - if (z->ey <= scan_y_top) { - *step = z->next; // delete from list - STBTT_assert(z->direction); - z->direction = 0; - stbtt__hheap_free(&hh, z); - } else { - step = &((*step)->next); // advance through list - } - } - - // insert all edges that start before the bottom of this scanline - while (e->y0 <= scan_y_bottom) { - if (e->y0 != e->y1) { - stbtt__active_edge *z = stbtt__new_active(&hh, e, off_x, scan_y_top, userdata); - if (z != NULL) { - if (j == 0 && off_y != 0) { - if (z->ey < scan_y_top) { - // this can happen due to subpixel positioning and some kind of fp rounding error i think - z->ey = scan_y_top; - } - } - STBTT_assert(z->ey >= scan_y_top); // if we get really unlucky a tiny bit of an edge can be out of bounds - // insert at front - z->next = active; - active = z; - } - } - ++e; - } - - // now process all active edges - if (active) - stbtt__fill_active_edges_new(scanline, scanline2+1, result->w, active, scan_y_top); - - { - float sum = 0; - for (i=0; i < result->w; ++i) { - float k; - int m; - sum += scanline2[i]; - k = scanline[i] + sum; - k = (float) STBTT_fabs(k)*255 + 0.5f; - m = (int) k; - if (m > 255) m = 255; - result->pixels[j*result->stride + i] = (unsigned char) m; - } - } - // advance all the edges - step = &active; - while (*step) { - stbtt__active_edge *z = *step; - z->fx += z->fdx; // advance to position for current scanline - step = &((*step)->next); // advance through list - } - - ++y; - ++j; - } - - stbtt__hheap_cleanup(&hh, userdata); - - if (scanline != scanline_data) - STBTT_free(scanline, userdata); -} -#else -#error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - -#define STBTT__COMPARE(a,b) ((a)->y0 < (b)->y0) - -static void stbtt__sort_edges_ins_sort(stbtt__edge *p, int n) -{ - int i,j; - for (i=1; i < n; ++i) { - stbtt__edge t = p[i], *a = &t; - j = i; - while (j > 0) { - stbtt__edge *b = &p[j-1]; - int c = STBTT__COMPARE(a,b); - if (!c) break; - p[j] = p[j-1]; - --j; - } - if (i != j) - p[j] = t; - } -} - -static void stbtt__sort_edges_quicksort(stbtt__edge *p, int n) -{ - /* threshold for transitioning to insertion sort */ - while (n > 12) { - stbtt__edge t; - int c01,c12,c,m,i,j; - - /* compute median of three */ - m = n >> 1; - c01 = STBTT__COMPARE(&p[0],&p[m]); - c12 = STBTT__COMPARE(&p[m],&p[n-1]); - /* if 0 >= mid >= end, or 0 < mid < end, then use mid */ - if (c01 != c12) { - /* otherwise, we'll need to swap something else to middle */ - int z; - c = STBTT__COMPARE(&p[0],&p[n-1]); - /* 0>mid && midn => n; 0 0 */ - /* 0n: 0>n => 0; 0 n */ - z = (c == c12) ? 0 : n-1; - t = p[z]; - p[z] = p[m]; - p[m] = t; - } - /* now p[m] is the median-of-three */ - /* swap it to the beginning so it won't move around */ - t = p[0]; - p[0] = p[m]; - p[m] = t; - - /* partition loop */ - i=1; - j=n-1; - for(;;) { - /* handling of equality is crucial here */ - /* for sentinels & efficiency with duplicates */ - for (;;++i) { - if (!STBTT__COMPARE(&p[i], &p[0])) break; - } - for (;;--j) { - if (!STBTT__COMPARE(&p[0], &p[j])) break; - } - /* make sure we haven't crossed */ - if (i >= j) break; - t = p[i]; - p[i] = p[j]; - p[j] = t; - - ++i; - --j; - } - /* recurse on smaller side, iterate on larger */ - if (j < (n-i)) { - stbtt__sort_edges_quicksort(p,j); - p = p+i; - n = n-i; - } else { - stbtt__sort_edges_quicksort(p+i, n-i); - n = j; - } - } -} - -static void stbtt__sort_edges(stbtt__edge *p, int n) -{ - stbtt__sort_edges_quicksort(p, n); - stbtt__sort_edges_ins_sort(p, n); -} - -typedef struct -{ - float x,y; -} stbtt__point; - -static void stbtt__rasterize(stbtt__bitmap *result, stbtt__point *pts, int *wcount, int windings, float scale_x, float scale_y, float shift_x, float shift_y, int off_x, int off_y, int invert, void *userdata) -{ - float y_scale_inv = invert ? -scale_y : scale_y; - stbtt__edge *e; - int n,i,j,k,m; -#if STBTT_RASTERIZER_VERSION == 1 - int vsubsample = result->h < 8 ? 15 : 5; -#elif STBTT_RASTERIZER_VERSION == 2 - int vsubsample = 1; -#else - #error "Unrecognized value of STBTT_RASTERIZER_VERSION" -#endif - // vsubsample should divide 255 evenly; otherwise we won't reach full opacity - - // now we have to blow out the windings into explicit edge lists - n = 0; - for (i=0; i < windings; ++i) - n += wcount[i]; - - e = (stbtt__edge *) STBTT_malloc(sizeof(*e) * (n+1), userdata); // add an extra one as a sentinel - if (e == 0) return; - n = 0; - - m=0; - for (i=0; i < windings; ++i) { - stbtt__point *p = pts + m; - m += wcount[i]; - j = wcount[i]-1; - for (k=0; k < wcount[i]; j=k++) { - int a=k,b=j; - // skip the edge if horizontal - if (p[j].y == p[k].y) - continue; - // add edge from j to k to the list - e[n].invert = 0; - if (invert ? p[j].y > p[k].y : p[j].y < p[k].y) { - e[n].invert = 1; - a=j,b=k; - } - e[n].x0 = p[a].x * scale_x + shift_x; - e[n].y0 = (p[a].y * y_scale_inv + shift_y) * vsubsample; - e[n].x1 = p[b].x * scale_x + shift_x; - e[n].y1 = (p[b].y * y_scale_inv + shift_y) * vsubsample; - ++n; - } - } - - // now sort the edges by their highest point (should snap to integer, and then by x) - //STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); - stbtt__sort_edges(e, n); - - // now, traverse the scanlines and find the intersections on each scanline, use xor winding rule - stbtt__rasterize_sorted_edges(result, e, n, vsubsample, off_x, off_y, userdata); - - STBTT_free(e, userdata); -} - -static void stbtt__add_point(stbtt__point *points, int n, float x, float y) -{ - if (!points) return; // during first pass, it's unallocated - points[n].x = x; - points[n].y = y; -} - -// tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching -static int stbtt__tesselate_curve(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float objspace_flatness_squared, int n) -{ - // midpoint - float mx = (x0 + 2*x1 + x2)/4; - float my = (y0 + 2*y1 + y2)/4; - // versus directly drawn line - float dx = (x0+x2)/2 - mx; - float dy = (y0+y2)/2 - my; - if (n > 16) // 65536 segments on one curve better be enough! - return 1; - if (dx*dx+dy*dy > objspace_flatness_squared) { // half-pixel error allowed... need to be smaller if AA - stbtt__tesselate_curve(points, num_points, x0,y0, (x0+x1)/2.0f,(y0+y1)/2.0f, mx,my, objspace_flatness_squared,n+1); - stbtt__tesselate_curve(points, num_points, mx,my, (x1+x2)/2.0f,(y1+y2)/2.0f, x2,y2, objspace_flatness_squared,n+1); - } else { - stbtt__add_point(points, *num_points,x2,y2); - *num_points = *num_points+1; - } - return 1; -} - -static void stbtt__tesselate_cubic(stbtt__point *points, int *num_points, float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float objspace_flatness_squared, int n) -{ - // @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough - float dx0 = x1-x0; - float dy0 = y1-y0; - float dx1 = x2-x1; - float dy1 = y2-y1; - float dx2 = x3-x2; - float dy2 = y3-y2; - float dx = x3-x0; - float dy = y3-y0; - float longlen = (float) (STBTT_sqrt(dx0*dx0+dy0*dy0)+STBTT_sqrt(dx1*dx1+dy1*dy1)+STBTT_sqrt(dx2*dx2+dy2*dy2)); - float shortlen = (float) STBTT_sqrt(dx*dx+dy*dy); - float flatness_squared = longlen*longlen-shortlen*shortlen; - - if (n > 16) // 65536 segments on one curve better be enough! - return; - - if (flatness_squared > objspace_flatness_squared) { - float x01 = (x0+x1)/2; - float y01 = (y0+y1)/2; - float x12 = (x1+x2)/2; - float y12 = (y1+y2)/2; - float x23 = (x2+x3)/2; - float y23 = (y2+y3)/2; - - float xa = (x01+x12)/2; - float ya = (y01+y12)/2; - float xb = (x12+x23)/2; - float yb = (y12+y23)/2; - - float mx = (xa+xb)/2; - float my = (ya+yb)/2; - - stbtt__tesselate_cubic(points, num_points, x0,y0, x01,y01, xa,ya, mx,my, objspace_flatness_squared,n+1); - stbtt__tesselate_cubic(points, num_points, mx,my, xb,yb, x23,y23, x3,y3, objspace_flatness_squared,n+1); - } else { - stbtt__add_point(points, *num_points,x3,y3); - *num_points = *num_points+1; - } -} - -// returns number of contours -static stbtt__point *stbtt_FlattenCurves(stbtt_vertex *vertices, int num_verts, float objspace_flatness, int **contour_lengths, int *num_contours, void *userdata) -{ - stbtt__point *points=0; - int num_points=0; - - float objspace_flatness_squared = objspace_flatness * objspace_flatness; - int i,n=0,start=0, pass; - - // count how many "moves" there are to get the contour count - for (i=0; i < num_verts; ++i) - if (vertices[i].type == STBTT_vmove) - ++n; - - *num_contours = n; - if (n == 0) return 0; - - *contour_lengths = (int *) STBTT_malloc(sizeof(**contour_lengths) * n, userdata); - - if (*contour_lengths == 0) { - *num_contours = 0; - return 0; - } - - // make two passes through the points so we don't need to realloc - for (pass=0; pass < 2; ++pass) { - float x=0,y=0; - if (pass == 1) { - points = (stbtt__point *) STBTT_malloc(num_points * sizeof(points[0]), userdata); - if (points == NULL) goto error; - } - num_points = 0; - n= -1; - for (i=0; i < num_verts; ++i) { - switch (vertices[i].type) { - case STBTT_vmove: - // start the next contour - if (n >= 0) - (*contour_lengths)[n] = num_points - start; - ++n; - start = num_points; - - x = vertices[i].x, y = vertices[i].y; - stbtt__add_point(points, num_points++, x,y); - break; - case STBTT_vline: - x = vertices[i].x, y = vertices[i].y; - stbtt__add_point(points, num_points++, x, y); - break; - case STBTT_vcurve: - stbtt__tesselate_curve(points, &num_points, x,y, - vertices[i].cx, vertices[i].cy, - vertices[i].x, vertices[i].y, - objspace_flatness_squared, 0); - x = vertices[i].x, y = vertices[i].y; - break; - case STBTT_vcubic: - stbtt__tesselate_cubic(points, &num_points, x,y, - vertices[i].cx, vertices[i].cy, - vertices[i].cx1, vertices[i].cy1, - vertices[i].x, vertices[i].y, - objspace_flatness_squared, 0); - x = vertices[i].x, y = vertices[i].y; - break; - } - } - (*contour_lengths)[n] = num_points - start; - } - - return points; -error: - STBTT_free(points, userdata); - STBTT_free(*contour_lengths, userdata); - *contour_lengths = 0; - *num_contours = 0; - return NULL; -} - -STBTT_DEF void stbtt_Rasterize(stbtt__bitmap *result, float flatness_in_pixels, stbtt_vertex *vertices, int num_verts, float scale_x, float scale_y, float shift_x, float shift_y, int x_off, int y_off, int invert, void *userdata) -{ - float scale = scale_x > scale_y ? scale_y : scale_x; - int winding_count = 0; - int *winding_lengths = NULL; - stbtt__point *windings = stbtt_FlattenCurves(vertices, num_verts, flatness_in_pixels / scale, &winding_lengths, &winding_count, userdata); - if (windings) { - stbtt__rasterize(result, windings, winding_lengths, winding_count, scale_x, scale_y, shift_x, shift_y, x_off, y_off, invert, userdata); - STBTT_free(winding_lengths, userdata); - STBTT_free(windings, userdata); - } -} - -STBTT_DEF void stbtt_FreeBitmap(unsigned char *bitmap, void *userdata) -{ - STBTT_free(bitmap, userdata); -} - -STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int glyph, int *width, int *height, int *xoff, int *yoff) -{ - int ix0,iy0,ix1,iy1; - stbtt__bitmap gbm; - stbtt_vertex *vertices; - int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); - - if (scale_x == 0) scale_x = scale_y; - if (scale_y == 0) { - if (scale_x == 0) { - STBTT_free(vertices, info->userdata); - return NULL; - } - scale_y = scale_x; - } - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,&ix1,&iy1); - - // now we get the size - gbm.w = (ix1 - ix0); - gbm.h = (iy1 - iy0); - gbm.pixels = NULL; // in case we error - - if (width ) *width = gbm.w; - if (height) *height = gbm.h; - if (xoff ) *xoff = ix0; - if (yoff ) *yoff = iy0; - - if (gbm.w && gbm.h) { - gbm.pixels = (unsigned char *) STBTT_malloc(gbm.w * gbm.h, info->userdata); - if (gbm.pixels) { - gbm.stride = gbm.w; - - stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1, info->userdata); - } - } - STBTT_free(vertices, info->userdata); - return gbm.pixels; -} - -STBTT_DEF unsigned char *stbtt_GetGlyphBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int glyph, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y, 0.0f, 0.0f, glyph, width, height, xoff, yoff); -} - -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int glyph) -{ - int ix0,iy0; - stbtt_vertex *vertices; - int num_verts = stbtt_GetGlyphShape(info, glyph, &vertices); - stbtt__bitmap gbm; - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale_x, scale_y, shift_x, shift_y, &ix0,&iy0,0,0); - gbm.pixels = output; - gbm.w = out_w; - gbm.h = out_h; - gbm.stride = out_stride; - - if (gbm.w && gbm.h) - stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0,iy0, 1, info->userdata); - - STBTT_free(vertices, info->userdata); -} - -STBTT_DEF void stbtt_MakeGlyphBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int glyph) -{ - stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, glyph); -} - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmapSubpixel(const stbtt_fontinfo *info, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphBitmapSubpixel(info, scale_x, scale_y,shift_x,shift_y, stbtt_FindGlyphIndex(info,codepoint), width,height,xoff,yoff); -} - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int oversample_x, int oversample_y, float *sub_x, float *sub_y, int codepoint) -{ - stbtt_MakeGlyphBitmapSubpixelPrefilter(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, oversample_x, oversample_y, sub_x, sub_y, stbtt_FindGlyphIndex(info,codepoint)); -} - -STBTT_DEF void stbtt_MakeCodepointBitmapSubpixel(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int codepoint) -{ - stbtt_MakeGlyphBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, shift_x, shift_y, stbtt_FindGlyphIndex(info,codepoint)); -} - -STBTT_DEF unsigned char *stbtt_GetCodepointBitmap(const stbtt_fontinfo *info, float scale_x, float scale_y, int codepoint, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetCodepointBitmapSubpixel(info, scale_x, scale_y, 0.0f,0.0f, codepoint, width,height,xoff,yoff); -} - -STBTT_DEF void stbtt_MakeCodepointBitmap(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, int codepoint) -{ - stbtt_MakeCodepointBitmapSubpixel(info, output, out_w, out_h, out_stride, scale_x, scale_y, 0.0f,0.0f, codepoint); -} - -////////////////////////////////////////////////////////////////////////////// -// -// bitmap baking -// -// This is SUPER-CRAPPY packing to keep source code small - -static int stbtt_BakeFontBitmap_internal(unsigned char *data, int offset, // font location (use offset=0 for plain .ttf) - float pixel_height, // height of font in pixels - unsigned char *pixels, int pw, int ph, // bitmap to be filled in - int first_char, int num_chars, // characters to bake - stbtt_bakedchar *chardata) -{ - float scale; - int x,y,bottom_y, i; - stbtt_fontinfo f; - f.userdata = NULL; - if (!stbtt_InitFont(&f, data, offset)) - return -1; - STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels - x=y=1; - bottom_y = 1; - - scale = stbtt_ScaleForPixelHeight(&f, pixel_height); - - for (i=0; i < num_chars; ++i) { - int advance, lsb, x0,y0,x1,y1,gw,gh; - int g = stbtt_FindGlyphIndex(&f, first_char + i); - stbtt_GetGlyphHMetrics(&f, g, &advance, &lsb); - stbtt_GetGlyphBitmapBox(&f, g, scale,scale, &x0,&y0,&x1,&y1); - gw = x1-x0; - gh = y1-y0; - if (x + gw + 1 >= pw) - y = bottom_y, x = 1; // advance to next row - if (y + gh + 1 >= ph) // check if it fits vertically AFTER potentially moving to next row - return -i; - STBTT_assert(x+gw < pw); - STBTT_assert(y+gh < ph); - stbtt_MakeGlyphBitmap(&f, pixels+x+y*pw, gw,gh,pw, scale,scale, g); - chardata[i].x0 = (stbtt_int16) x; - chardata[i].y0 = (stbtt_int16) y; - chardata[i].x1 = (stbtt_int16) (x + gw); - chardata[i].y1 = (stbtt_int16) (y + gh); - chardata[i].xadvance = scale * advance; - chardata[i].xoff = (float) x0; - chardata[i].yoff = (float) y0; - x = x + gw + 1; - if (y+gh+1 > bottom_y) - bottom_y = y+gh+1; - } - return bottom_y; -} - -STBTT_DEF void stbtt_GetBakedQuad(const stbtt_bakedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int opengl_fillrule) -{ - float d3d_bias = opengl_fillrule ? 0 : -0.5f; - float ipw = 1.0f / pw, iph = 1.0f / ph; - const stbtt_bakedchar *b = chardata + char_index; - int round_x = STBTT_ifloor((*xpos + b->xoff) + 0.5f); - int round_y = STBTT_ifloor((*ypos + b->yoff) + 0.5f); - - q->x0 = round_x + d3d_bias; - q->y0 = round_y + d3d_bias; - q->x1 = round_x + b->x1 - b->x0 + d3d_bias; - q->y1 = round_y + b->y1 - b->y0 + d3d_bias; - - q->s0 = b->x0 * ipw; - q->t0 = b->y0 * iph; - q->s1 = b->x1 * ipw; - q->t1 = b->y1 * iph; - - *xpos += b->xadvance; -} - -////////////////////////////////////////////////////////////////////////////// -// -// rectangle packing replacement routines if you don't have stb_rect_pack.h -// - -#ifndef STB_RECT_PACK_VERSION - -typedef int stbrp_coord; - -//////////////////////////////////////////////////////////////////////////////////// -// // -// // -// COMPILER WARNING ?!?!? // -// // -// // -// if you get a compile warning due to these symbols being defined more than // -// once, move #include "stb_rect_pack.h" before #include "stb_truetype.h" // -// // -//////////////////////////////////////////////////////////////////////////////////// - -typedef struct -{ - int width,height; - int x,y,bottom_y; -} stbrp_context; - -typedef struct -{ - unsigned char x; -} stbrp_node; - -struct stbrp_rect -{ - stbrp_coord x,y; - int id,w,h,was_packed; -}; - -static void stbrp_init_target(stbrp_context *con, int pw, int ph, stbrp_node *nodes, int num_nodes) -{ - con->width = pw; - con->height = ph; - con->x = 0; - con->y = 0; - con->bottom_y = 0; - STBTT__NOTUSED(nodes); - STBTT__NOTUSED(num_nodes); -} - -static void stbrp_pack_rects(stbrp_context *con, stbrp_rect *rects, int num_rects) -{ - int i; - for (i=0; i < num_rects; ++i) { - if (con->x + rects[i].w > con->width) { - con->x = 0; - con->y = con->bottom_y; - } - if (con->y + rects[i].h > con->height) - break; - rects[i].x = con->x; - rects[i].y = con->y; - rects[i].was_packed = 1; - con->x += rects[i].w; - if (con->y + rects[i].h > con->bottom_y) - con->bottom_y = con->y + rects[i].h; - } - for ( ; i < num_rects; ++i) - rects[i].was_packed = 0; -} -#endif - -////////////////////////////////////////////////////////////////////////////// -// -// bitmap baking -// -// This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If -// stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy. - -STBTT_DEF int stbtt_PackBegin(stbtt_pack_context *spc, unsigned char *pixels, int pw, int ph, int stride_in_bytes, int padding, void *alloc_context) -{ - stbrp_context *context = (stbrp_context *) STBTT_malloc(sizeof(*context) ,alloc_context); - int num_nodes = pw - padding; - stbrp_node *nodes = (stbrp_node *) STBTT_malloc(sizeof(*nodes ) * num_nodes,alloc_context); - - if (context == NULL || nodes == NULL) { - if (context != NULL) STBTT_free(context, alloc_context); - if (nodes != NULL) STBTT_free(nodes , alloc_context); - return 0; - } - - spc->user_allocator_context = alloc_context; - spc->width = pw; - spc->height = ph; - spc->pixels = pixels; - spc->pack_info = context; - spc->nodes = nodes; - spc->padding = padding; - spc->stride_in_bytes = stride_in_bytes != 0 ? stride_in_bytes : pw; - spc->h_oversample = 1; - spc->v_oversample = 1; - spc->skip_missing = 0; - - stbrp_init_target(context, pw-padding, ph-padding, nodes, num_nodes); - - if (pixels) - STBTT_memset(pixels, 0, pw*ph); // background of 0 around pixels - - return 1; -} - -STBTT_DEF void stbtt_PackEnd (stbtt_pack_context *spc) -{ - STBTT_free(spc->nodes , spc->user_allocator_context); - STBTT_free(spc->pack_info, spc->user_allocator_context); -} - -STBTT_DEF void stbtt_PackSetOversampling(stbtt_pack_context *spc, unsigned int h_oversample, unsigned int v_oversample) -{ - STBTT_assert(h_oversample <= STBTT_MAX_OVERSAMPLE); - STBTT_assert(v_oversample <= STBTT_MAX_OVERSAMPLE); - if (h_oversample <= STBTT_MAX_OVERSAMPLE) - spc->h_oversample = h_oversample; - if (v_oversample <= STBTT_MAX_OVERSAMPLE) - spc->v_oversample = v_oversample; -} - -STBTT_DEF void stbtt_PackSetSkipMissingCodepoints(stbtt_pack_context *spc, int skip) -{ - spc->skip_missing = skip; -} - -#define STBTT__OVER_MASK (STBTT_MAX_OVERSAMPLE-1) - -static void stbtt__h_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) -{ - unsigned char buffer[STBTT_MAX_OVERSAMPLE]; - int safe_w = w - kernel_width; - int j; - STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); // suppress bogus warning from VS2013 -analyze - for (j=0; j < h; ++j) { - int i; - unsigned int total; - STBTT_memset(buffer, 0, kernel_width); - - total = 0; - - // make kernel_width a constant in common cases so compiler can optimize out the divide - switch (kernel_width) { - case 2: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 2); - } - break; - case 3: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 3); - } - break; - case 4: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 4); - } - break; - case 5: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / 5); - } - break; - default: - for (i=0; i <= safe_w; ++i) { - total += pixels[i] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i]; - pixels[i] = (unsigned char) (total / kernel_width); - } - break; - } - - for (; i < w; ++i) { - STBTT_assert(pixels[i] == 0); - total -= buffer[i & STBTT__OVER_MASK]; - pixels[i] = (unsigned char) (total / kernel_width); - } - - pixels += stride_in_bytes; - } -} - -static void stbtt__v_prefilter(unsigned char *pixels, int w, int h, int stride_in_bytes, unsigned int kernel_width) -{ - unsigned char buffer[STBTT_MAX_OVERSAMPLE]; - int safe_h = h - kernel_width; - int j; - STBTT_memset(buffer, 0, STBTT_MAX_OVERSAMPLE); // suppress bogus warning from VS2013 -analyze - for (j=0; j < w; ++j) { - int i; - unsigned int total; - STBTT_memset(buffer, 0, kernel_width); - - total = 0; - - // make kernel_width a constant in common cases so compiler can optimize out the divide - switch (kernel_width) { - case 2: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 2); - } - break; - case 3: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 3); - } - break; - case 4: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 4); - } - break; - case 5: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / 5); - } - break; - default: - for (i=0; i <= safe_h; ++i) { - total += pixels[i*stride_in_bytes] - buffer[i & STBTT__OVER_MASK]; - buffer[(i+kernel_width) & STBTT__OVER_MASK] = pixels[i*stride_in_bytes]; - pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); - } - break; - } - - for (; i < h; ++i) { - STBTT_assert(pixels[i*stride_in_bytes] == 0); - total -= buffer[i & STBTT__OVER_MASK]; - pixels[i*stride_in_bytes] = (unsigned char) (total / kernel_width); - } - - pixels += 1; - } -} - -static float stbtt__oversample_shift(int oversample) -{ - if (!oversample) - return 0.0f; - - // The prefilter is a box filter of width "oversample", - // which shifts phase by (oversample - 1)/2 pixels in - // oversampled space. We want to shift in the opposite - // direction to counter this. - return (float)-(oversample - 1) / (2.0f * (float)oversample); -} - -// rects array must be big enough to accommodate all characters in the given ranges -STBTT_DEF int stbtt_PackFontRangesGatherRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) -{ - int i,j,k; - int missing_glyph_added = 0; - - k=0; - for (i=0; i < num_ranges; ++i) { - float fh = ranges[i].font_size; - float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); - ranges[i].h_oversample = (unsigned char) spc->h_oversample; - ranges[i].v_oversample = (unsigned char) spc->v_oversample; - for (j=0; j < ranges[i].num_chars; ++j) { - int x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; - int glyph = stbtt_FindGlyphIndex(info, codepoint); - if (glyph == 0 && (spc->skip_missing || missing_glyph_added)) { - rects[k].w = rects[k].h = 0; - } else { - stbtt_GetGlyphBitmapBoxSubpixel(info,glyph, - scale * spc->h_oversample, - scale * spc->v_oversample, - 0,0, - &x0,&y0,&x1,&y1); - rects[k].w = (stbrp_coord) (x1-x0 + spc->padding + spc->h_oversample-1); - rects[k].h = (stbrp_coord) (y1-y0 + spc->padding + spc->v_oversample-1); - if (glyph == 0) - missing_glyph_added = 1; - } - ++k; - } - } - - return k; -} - -STBTT_DEF void stbtt_MakeGlyphBitmapSubpixelPrefilter(const stbtt_fontinfo *info, unsigned char *output, int out_w, int out_h, int out_stride, float scale_x, float scale_y, float shift_x, float shift_y, int prefilter_x, int prefilter_y, float *sub_x, float *sub_y, int glyph) -{ - stbtt_MakeGlyphBitmapSubpixel(info, - output, - out_w - (prefilter_x - 1), - out_h - (prefilter_y - 1), - out_stride, - scale_x, - scale_y, - shift_x, - shift_y, - glyph); - - if (prefilter_x > 1) - stbtt__h_prefilter(output, out_w, out_h, out_stride, prefilter_x); - - if (prefilter_y > 1) - stbtt__v_prefilter(output, out_w, out_h, out_stride, prefilter_y); - - *sub_x = stbtt__oversample_shift(prefilter_x); - *sub_y = stbtt__oversample_shift(prefilter_y); -} - -// rects array must be big enough to accommodate all characters in the given ranges -STBTT_DEF int stbtt_PackFontRangesRenderIntoRects(stbtt_pack_context *spc, const stbtt_fontinfo *info, stbtt_pack_range *ranges, int num_ranges, stbrp_rect *rects) -{ - int i,j,k, missing_glyph = -1, return_value = 1; - - // save current values - int old_h_over = spc->h_oversample; - int old_v_over = spc->v_oversample; - - k = 0; - for (i=0; i < num_ranges; ++i) { - float fh = ranges[i].font_size; - float scale = fh > 0 ? stbtt_ScaleForPixelHeight(info, fh) : stbtt_ScaleForMappingEmToPixels(info, -fh); - float recip_h,recip_v,sub_x,sub_y; - spc->h_oversample = ranges[i].h_oversample; - spc->v_oversample = ranges[i].v_oversample; - recip_h = 1.0f / spc->h_oversample; - recip_v = 1.0f / spc->v_oversample; - sub_x = stbtt__oversample_shift(spc->h_oversample); - sub_y = stbtt__oversample_shift(spc->v_oversample); - for (j=0; j < ranges[i].num_chars; ++j) { - stbrp_rect *r = &rects[k]; - if (r->was_packed && r->w != 0 && r->h != 0) { - stbtt_packedchar *bc = &ranges[i].chardata_for_range[j]; - int advance, lsb, x0,y0,x1,y1; - int codepoint = ranges[i].array_of_unicode_codepoints == NULL ? ranges[i].first_unicode_codepoint_in_range + j : ranges[i].array_of_unicode_codepoints[j]; - int glyph = stbtt_FindGlyphIndex(info, codepoint); - stbrp_coord pad = (stbrp_coord) spc->padding; - - // pad on left and top - r->x += pad; - r->y += pad; - r->w -= pad; - r->h -= pad; - stbtt_GetGlyphHMetrics(info, glyph, &advance, &lsb); - stbtt_GetGlyphBitmapBox(info, glyph, - scale * spc->h_oversample, - scale * spc->v_oversample, - &x0,&y0,&x1,&y1); - stbtt_MakeGlyphBitmapSubpixel(info, - spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w - spc->h_oversample+1, - r->h - spc->v_oversample+1, - spc->stride_in_bytes, - scale * spc->h_oversample, - scale * spc->v_oversample, - 0,0, - glyph); - - if (spc->h_oversample > 1) - stbtt__h_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w, r->h, spc->stride_in_bytes, - spc->h_oversample); - - if (spc->v_oversample > 1) - stbtt__v_prefilter(spc->pixels + r->x + r->y*spc->stride_in_bytes, - r->w, r->h, spc->stride_in_bytes, - spc->v_oversample); - - bc->x0 = (stbtt_int16) r->x; - bc->y0 = (stbtt_int16) r->y; - bc->x1 = (stbtt_int16) (r->x + r->w); - bc->y1 = (stbtt_int16) (r->y + r->h); - bc->xadvance = scale * advance; - bc->xoff = (float) x0 * recip_h + sub_x; - bc->yoff = (float) y0 * recip_v + sub_y; - bc->xoff2 = (x0 + r->w) * recip_h + sub_x; - bc->yoff2 = (y0 + r->h) * recip_v + sub_y; - - if (glyph == 0) - missing_glyph = j; - } else if (spc->skip_missing) { - return_value = 0; - } else if (r->was_packed && r->w == 0 && r->h == 0 && missing_glyph >= 0) { - ranges[i].chardata_for_range[j] = ranges[i].chardata_for_range[missing_glyph]; - } else { - return_value = 0; // if any fail, report failure - } - - ++k; - } - } - - // restore original values - spc->h_oversample = old_h_over; - spc->v_oversample = old_v_over; - - return return_value; -} - -STBTT_DEF void stbtt_PackFontRangesPackRects(stbtt_pack_context *spc, stbrp_rect *rects, int num_rects) -{ - stbrp_pack_rects((stbrp_context *) spc->pack_info, rects, num_rects); -} - -STBTT_DEF int stbtt_PackFontRanges(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, stbtt_pack_range *ranges, int num_ranges) -{ - stbtt_fontinfo info; - int i,j,n, return_value = 1; - //stbrp_context *context = (stbrp_context *) spc->pack_info; - stbrp_rect *rects; - - // flag all characters as NOT packed - for (i=0; i < num_ranges; ++i) - for (j=0; j < ranges[i].num_chars; ++j) - ranges[i].chardata_for_range[j].x0 = - ranges[i].chardata_for_range[j].y0 = - ranges[i].chardata_for_range[j].x1 = - ranges[i].chardata_for_range[j].y1 = 0; - - n = 0; - for (i=0; i < num_ranges; ++i) - n += ranges[i].num_chars; - - rects = (stbrp_rect *) STBTT_malloc(sizeof(*rects) * n, spc->user_allocator_context); - if (rects == NULL) - return 0; - - info.userdata = spc->user_allocator_context; - stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata,font_index)); - - n = stbtt_PackFontRangesGatherRects(spc, &info, ranges, num_ranges, rects); - - stbtt_PackFontRangesPackRects(spc, rects, n); - - return_value = stbtt_PackFontRangesRenderIntoRects(spc, &info, ranges, num_ranges, rects); - - STBTT_free(rects, spc->user_allocator_context); - return return_value; -} - -STBTT_DEF int stbtt_PackFontRange(stbtt_pack_context *spc, const unsigned char *fontdata, int font_index, float font_size, - int first_unicode_codepoint_in_range, int num_chars_in_range, stbtt_packedchar *chardata_for_range) -{ - stbtt_pack_range range; - range.first_unicode_codepoint_in_range = first_unicode_codepoint_in_range; - range.array_of_unicode_codepoints = NULL; - range.num_chars = num_chars_in_range; - range.chardata_for_range = chardata_for_range; - range.font_size = font_size; - return stbtt_PackFontRanges(spc, fontdata, font_index, &range, 1); -} - -STBTT_DEF void stbtt_GetScaledFontVMetrics(const unsigned char *fontdata, int index, float size, float *ascent, float *descent, float *lineGap) -{ - int i_ascent, i_descent, i_lineGap; - float scale; - stbtt_fontinfo info; - stbtt_InitFont(&info, fontdata, stbtt_GetFontOffsetForIndex(fontdata, index)); - scale = size > 0 ? stbtt_ScaleForPixelHeight(&info, size) : stbtt_ScaleForMappingEmToPixels(&info, -size); - stbtt_GetFontVMetrics(&info, &i_ascent, &i_descent, &i_lineGap); - *ascent = (float) i_ascent * scale; - *descent = (float) i_descent * scale; - *lineGap = (float) i_lineGap * scale; -} - -STBTT_DEF void stbtt_GetPackedQuad(const stbtt_packedchar *chardata, int pw, int ph, int char_index, float *xpos, float *ypos, stbtt_aligned_quad *q, int align_to_integer) -{ - float ipw = 1.0f / pw, iph = 1.0f / ph; - const stbtt_packedchar *b = chardata + char_index; - - if (align_to_integer) { - float x = (float) STBTT_ifloor((*xpos + b->xoff) + 0.5f); - float y = (float) STBTT_ifloor((*ypos + b->yoff) + 0.5f); - q->x0 = x; - q->y0 = y; - q->x1 = x + b->xoff2 - b->xoff; - q->y1 = y + b->yoff2 - b->yoff; - } else { - q->x0 = *xpos + b->xoff; - q->y0 = *ypos + b->yoff; - q->x1 = *xpos + b->xoff2; - q->y1 = *ypos + b->yoff2; - } - - q->s0 = b->x0 * ipw; - q->t0 = b->y0 * iph; - q->s1 = b->x1 * ipw; - q->t1 = b->y1 * iph; - - *xpos += b->xadvance; -} - -////////////////////////////////////////////////////////////////////////////// -// -// sdf computation -// - -#define STBTT_min(a,b) ((a) < (b) ? (a) : (b)) -#define STBTT_max(a,b) ((a) < (b) ? (b) : (a)) - -static int stbtt__ray_intersect_bezier(float orig[2], float ray[2], float q0[2], float q1[2], float q2[2], float hits[2][2]) -{ - float q0perp = q0[1]*ray[0] - q0[0]*ray[1]; - float q1perp = q1[1]*ray[0] - q1[0]*ray[1]; - float q2perp = q2[1]*ray[0] - q2[0]*ray[1]; - float roperp = orig[1]*ray[0] - orig[0]*ray[1]; - - float a = q0perp - 2*q1perp + q2perp; - float b = q1perp - q0perp; - float c = q0perp - roperp; - - float s0 = 0., s1 = 0.; - int num_s = 0; - - if (a != 0.0) { - float discr = b*b - a*c; - if (discr > 0.0) { - float rcpna = -1 / a; - float d = (float) STBTT_sqrt(discr); - s0 = (b+d) * rcpna; - s1 = (b-d) * rcpna; - if (s0 >= 0.0 && s0 <= 1.0) - num_s = 1; - if (d > 0.0 && s1 >= 0.0 && s1 <= 1.0) { - if (num_s == 0) s0 = s1; - ++num_s; - } - } - } else { - // 2*b*s + c = 0 - // s = -c / (2*b) - s0 = c / (-2 * b); - if (s0 >= 0.0 && s0 <= 1.0) - num_s = 1; - } - - if (num_s == 0) - return 0; - else { - float rcp_len2 = 1 / (ray[0]*ray[0] + ray[1]*ray[1]); - float rayn_x = ray[0] * rcp_len2, rayn_y = ray[1] * rcp_len2; - - float q0d = q0[0]*rayn_x + q0[1]*rayn_y; - float q1d = q1[0]*rayn_x + q1[1]*rayn_y; - float q2d = q2[0]*rayn_x + q2[1]*rayn_y; - float rod = orig[0]*rayn_x + orig[1]*rayn_y; - - float q10d = q1d - q0d; - float q20d = q2d - q0d; - float q0rd = q0d - rod; - - hits[0][0] = q0rd + s0*(2.0f - 2.0f*s0)*q10d + s0*s0*q20d; - hits[0][1] = a*s0+b; - - if (num_s > 1) { - hits[1][0] = q0rd + s1*(2.0f - 2.0f*s1)*q10d + s1*s1*q20d; - hits[1][1] = a*s1+b; - return 2; - } else { - return 1; - } - } -} - -static int equal(float *a, float *b) -{ - return (a[0] == b[0] && a[1] == b[1]); -} - -static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex *verts) -{ - int i; - float orig[2], ray[2] = { 1, 0 }; - float y_frac; - int winding = 0; - - // make sure y never passes through a vertex of the shape - y_frac = (float) STBTT_fmod(y, 1.0f); - if (y_frac < 0.01f) - y += 0.01f; - else if (y_frac > 0.99f) - y -= 0.01f; - - orig[0] = x; - orig[1] = y; - - // test a ray from (-infinity,y) to (x,y) - for (i=0; i < nverts; ++i) { - if (verts[i].type == STBTT_vline) { - int x0 = (int) verts[i-1].x, y0 = (int) verts[i-1].y; - int x1 = (int) verts[i ].x, y1 = (int) verts[i ].y; - if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { - float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; - if (x_inter < x) - winding += (y0 < y1) ? 1 : -1; - } - } - if (verts[i].type == STBTT_vcurve) { - int x0 = (int) verts[i-1].x , y0 = (int) verts[i-1].y ; - int x1 = (int) verts[i ].cx, y1 = (int) verts[i ].cy; - int x2 = (int) verts[i ].x , y2 = (int) verts[i ].y ; - int ax = STBTT_min(x0,STBTT_min(x1,x2)), ay = STBTT_min(y0,STBTT_min(y1,y2)); - int by = STBTT_max(y0,STBTT_max(y1,y2)); - if (y > ay && y < by && x > ax) { - float q0[2],q1[2],q2[2]; - float hits[2][2]; - q0[0] = (float)x0; - q0[1] = (float)y0; - q1[0] = (float)x1; - q1[1] = (float)y1; - q2[0] = (float)x2; - q2[1] = (float)y2; - if (equal(q0,q1) || equal(q1,q2)) { - x0 = (int)verts[i-1].x; - y0 = (int)verts[i-1].y; - x1 = (int)verts[i ].x; - y1 = (int)verts[i ].y; - if (y > STBTT_min(y0,y1) && y < STBTT_max(y0,y1) && x > STBTT_min(x0,x1)) { - float x_inter = (y - y0) / (y1 - y0) * (x1-x0) + x0; - if (x_inter < x) - winding += (y0 < y1) ? 1 : -1; - } - } else { - int num_hits = stbtt__ray_intersect_bezier(orig, ray, q0, q1, q2, hits); - if (num_hits >= 1) - if (hits[0][0] < 0) - winding += (hits[0][1] < 0 ? -1 : 1); - if (num_hits >= 2) - if (hits[1][0] < 0) - winding += (hits[1][1] < 0 ? -1 : 1); - } - } - } - } - return winding; -} - -static float stbtt__cuberoot( float x ) -{ - if (x<0) - return -(float) STBTT_pow(-x,1.0f/3.0f); - else - return (float) STBTT_pow( x,1.0f/3.0f); -} - -// x^3 + a*x^2 + b*x + c = 0 -static int stbtt__solve_cubic(float a, float b, float c, float* r) -{ - float s = -a / 3; - float p = b - a*a / 3; - float q = a * (2*a*a - 9*b) / 27 + c; - float p3 = p*p*p; - float d = q*q + 4*p3 / 27; - if (d >= 0) { - float z = (float) STBTT_sqrt(d); - float u = (-q + z) / 2; - float v = (-q - z) / 2; - u = stbtt__cuberoot(u); - v = stbtt__cuberoot(v); - r[0] = s + u + v; - return 1; - } else { - float u = (float) STBTT_sqrt(-p/3); - float v = (float) STBTT_acos(-STBTT_sqrt(-27/p3) * q / 2) / 3; // p3 must be negative, since d is negative - float m = (float) STBTT_cos(v); - float n = (float) STBTT_cos(v-3.141592/2)*1.732050808f; - r[0] = s + u * 2 * m; - r[1] = s - u * (m + n); - r[2] = s - u * (m - n); - - //STBTT_assert( STBTT_fabs(((r[0]+a)*r[0]+b)*r[0]+c) < 0.05f); // these asserts may not be safe at all scales, though they're in bezier t parameter units so maybe? - //STBTT_assert( STBTT_fabs(((r[1]+a)*r[1]+b)*r[1]+c) < 0.05f); - //STBTT_assert( STBTT_fabs(((r[2]+a)*r[2]+b)*r[2]+c) < 0.05f); - return 3; - } -} - -STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float scale, int glyph, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) -{ - float scale_x = scale, scale_y = scale; - int ix0,iy0,ix1,iy1; - int w,h; - unsigned char *data; - - if (scale == 0) return NULL; - - stbtt_GetGlyphBitmapBoxSubpixel(info, glyph, scale, scale, 0.0f,0.0f, &ix0,&iy0,&ix1,&iy1); - - // if empty, return NULL - if (ix0 == ix1 || iy0 == iy1) - return NULL; - - ix0 -= padding; - iy0 -= padding; - ix1 += padding; - iy1 += padding; - - w = (ix1 - ix0); - h = (iy1 - iy0); - - if (width ) *width = w; - if (height) *height = h; - if (xoff ) *xoff = ix0; - if (yoff ) *yoff = iy0; - - // invert for y-downwards bitmaps - scale_y = -scale_y; - - { - // distance from singular values (in the same units as the pixel grid) - const float eps = 1./1024, eps2 = eps*eps; - int x,y,i,j; - float *precompute; - stbtt_vertex *verts; - int num_verts = stbtt_GetGlyphShape(info, glyph, &verts); - data = (unsigned char *) STBTT_malloc(w * h, info->userdata); - precompute = (float *) STBTT_malloc(num_verts * sizeof(float), info->userdata); - - for (i=0,j=num_verts-1; i < num_verts; j=i++) { - if (verts[i].type == STBTT_vline) { - float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; - float x1 = verts[j].x*scale_x, y1 = verts[j].y*scale_y; - float dist = (float) STBTT_sqrt((x1-x0)*(x1-x0) + (y1-y0)*(y1-y0)); - precompute[i] = (dist < eps) ? 0.0f : 1.0f / dist; - } else if (verts[i].type == STBTT_vcurve) { - float x2 = verts[j].x *scale_x, y2 = verts[j].y *scale_y; - float x1 = verts[i].cx*scale_x, y1 = verts[i].cy*scale_y; - float x0 = verts[i].x *scale_x, y0 = verts[i].y *scale_y; - float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; - float len2 = bx*bx + by*by; - if (len2 >= eps2) - precompute[i] = 1.0f / len2; - else - precompute[i] = 0.0f; - } else - precompute[i] = 0.0f; - } - - for (y=iy0; y < iy1; ++y) { - for (x=ix0; x < ix1; ++x) { - float val; - float min_dist = 999999.0f; - float sx = (float) x + 0.5f; - float sy = (float) y + 0.5f; - float x_gspace = (sx / scale_x); - float y_gspace = (sy / scale_y); - - int winding = stbtt__compute_crossings_x(x_gspace, y_gspace, num_verts, verts); // @OPTIMIZE: this could just be a rasterization, but needs to be line vs. non-tesselated curves so a new path - - for (i=0; i < num_verts; ++i) { - float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y; - - if (verts[i].type == STBTT_vline && precompute[i] != 0.0f) { - float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y; - - float dist,dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); - if (dist2 < min_dist*min_dist) - min_dist = (float) STBTT_sqrt(dist2); - - // coarse culling against bbox - //if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist && - // sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist) - dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i]; - STBTT_assert(i != 0); - if (dist < min_dist) { - // check position along line - // x' = x0 + t*(x1-x0), y' = y0 + t*(y1-y0) - // minimize (x'-sx)*(x'-sx)+(y'-sy)*(y'-sy) - float dx = x1-x0, dy = y1-y0; - float px = x0-sx, py = y0-sy; - // minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy - // derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve - float t = -(px*dx + py*dy) / (dx*dx + dy*dy); - if (t >= 0.0f && t <= 1.0f) - min_dist = dist; - } - } else if (verts[i].type == STBTT_vcurve) { - float x2 = verts[i-1].x *scale_x, y2 = verts[i-1].y *scale_y; - float x1 = verts[i ].cx*scale_x, y1 = verts[i ].cy*scale_y; - float box_x0 = STBTT_min(STBTT_min(x0,x1),x2); - float box_y0 = STBTT_min(STBTT_min(y0,y1),y2); - float box_x1 = STBTT_max(STBTT_max(x0,x1),x2); - float box_y1 = STBTT_max(STBTT_max(y0,y1),y2); - // coarse culling against bbox to avoid computing cubic unnecessarily - if (sx > box_x0-min_dist && sx < box_x1+min_dist && sy > box_y0-min_dist && sy < box_y1+min_dist) { - int num=0; - float ax = x1-x0, ay = y1-y0; - float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2; - float mx = x0 - sx, my = y0 - sy; - float res[3] = {0.f,0.f,0.f}; - float px,py,t,it,dist2; - float a_inv = precompute[i]; - if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula - float a = 3*(ax*bx + ay*by); - float b = 2*(ax*ax + ay*ay) + (mx*bx+my*by); - float c = mx*ax+my*ay; - if (STBTT_fabs(a) < eps2) { // if a is 0, it's linear - if (STBTT_fabs(b) >= eps2) { - res[num++] = -c/b; - } - } else { - float discriminant = b*b - 4*a*c; - if (discriminant < 0) - num = 0; - else { - float root = (float) STBTT_sqrt(discriminant); - res[0] = (-b - root)/(2*a); - res[1] = (-b + root)/(2*a); - num = 2; // don't bother distinguishing 1-solution case, as code below will still work - } - } - } else { - float b = 3*(ax*bx + ay*by) * a_inv; // could precompute this as it doesn't depend on sample point - float c = (2*(ax*ax + ay*ay) + (mx*bx+my*by)) * a_inv; - float d = (mx*ax+my*ay) * a_inv; - num = stbtt__solve_cubic(b, c, d, res); - } - dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy); - if (dist2 < min_dist*min_dist) - min_dist = (float) STBTT_sqrt(dist2); - - if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) { - t = res[0], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - if (num >= 2 && res[1] >= 0.0f && res[1] <= 1.0f) { - t = res[1], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - if (num >= 3 && res[2] >= 0.0f && res[2] <= 1.0f) { - t = res[2], it = 1.0f - t; - px = it*it*x0 + 2*t*it*x1 + t*t*x2; - py = it*it*y0 + 2*t*it*y1 + t*t*y2; - dist2 = (px-sx)*(px-sx) + (py-sy)*(py-sy); - if (dist2 < min_dist * min_dist) - min_dist = (float) STBTT_sqrt(dist2); - } - } - } - } - if (winding == 0) - min_dist = -min_dist; // if outside the shape, value is negative - val = onedge_value + pixel_dist_scale * min_dist; - if (val < 0) - val = 0; - else if (val > 255) - val = 255; - data[(y-iy0)*w+(x-ix0)] = (unsigned char) val; - } - } - STBTT_free(precompute, info->userdata); - STBTT_free(verts, info->userdata); - } - return data; -} - -STBTT_DEF unsigned char * stbtt_GetCodepointSDF(const stbtt_fontinfo *info, float scale, int codepoint, int padding, unsigned char onedge_value, float pixel_dist_scale, int *width, int *height, int *xoff, int *yoff) -{ - return stbtt_GetGlyphSDF(info, scale, stbtt_FindGlyphIndex(info, codepoint), padding, onedge_value, pixel_dist_scale, width, height, xoff, yoff); -} - -STBTT_DEF void stbtt_FreeSDF(unsigned char *bitmap, void *userdata) -{ - STBTT_free(bitmap, userdata); -} - -////////////////////////////////////////////////////////////////////////////// -// -// font name matching -- recommended not to use this -// - -// check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string -static stbtt_int32 stbtt__CompareUTF8toUTF16_bigendian_prefix(stbtt_uint8 *s1, stbtt_int32 len1, stbtt_uint8 *s2, stbtt_int32 len2) -{ - stbtt_int32 i=0; - - // convert utf16 to utf8 and compare the results while converting - while (len2) { - stbtt_uint16 ch = s2[0]*256 + s2[1]; - if (ch < 0x80) { - if (i >= len1) return -1; - if (s1[i++] != ch) return -1; - } else if (ch < 0x800) { - if (i+1 >= len1) return -1; - if (s1[i++] != 0xc0 + (ch >> 6)) return -1; - if (s1[i++] != 0x80 + (ch & 0x3f)) return -1; - } else if (ch >= 0xd800 && ch < 0xdc00) { - stbtt_uint32 c; - stbtt_uint16 ch2 = s2[2]*256 + s2[3]; - if (i+3 >= len1) return -1; - c = ((ch - 0xd800) << 10) + (ch2 - 0xdc00) + 0x10000; - if (s1[i++] != 0xf0 + (c >> 18)) return -1; - if (s1[i++] != 0x80 + ((c >> 12) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((c ) & 0x3f)) return -1; - s2 += 2; // plus another 2 below - len2 -= 2; - } else if (ch >= 0xdc00 && ch < 0xe000) { - return -1; - } else { - if (i+2 >= len1) return -1; - if (s1[i++] != 0xe0 + (ch >> 12)) return -1; - if (s1[i++] != 0x80 + ((ch >> 6) & 0x3f)) return -1; - if (s1[i++] != 0x80 + ((ch ) & 0x3f)) return -1; - } - s2 += 2; - len2 -= 2; - } - return i; -} - -static int stbtt_CompareUTF8toUTF16_bigendian_internal(char *s1, int len1, char *s2, int len2) -{ - return len1 == stbtt__CompareUTF8toUTF16_bigendian_prefix((stbtt_uint8*) s1, len1, (stbtt_uint8*) s2, len2); -} - -// returns results in whatever encoding you request... but note that 2-byte encodings -// will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare -STBTT_DEF const char *stbtt_GetFontNameString(const stbtt_fontinfo *font, int *length, int platformID, int encodingID, int languageID, int nameID) -{ - stbtt_int32 i,count,stringOffset; - stbtt_uint8 *fc = font->data; - stbtt_uint32 offset = font->fontstart; - stbtt_uint32 nm = stbtt__find_table(fc, offset, "name"); - if (!nm) return NULL; - - count = ttUSHORT(fc+nm+2); - stringOffset = nm + ttUSHORT(fc+nm+4); - for (i=0; i < count; ++i) { - stbtt_uint32 loc = nm + 6 + 12 * i; - if (platformID == ttUSHORT(fc+loc+0) && encodingID == ttUSHORT(fc+loc+2) - && languageID == ttUSHORT(fc+loc+4) && nameID == ttUSHORT(fc+loc+6)) { - *length = ttUSHORT(fc+loc+8); - return (const char *) (fc+stringOffset+ttUSHORT(fc+loc+10)); - } - } - return NULL; -} - -static int stbtt__matchpair(stbtt_uint8 *fc, stbtt_uint32 nm, stbtt_uint8 *name, stbtt_int32 nlen, stbtt_int32 target_id, stbtt_int32 next_id) -{ - stbtt_int32 i; - stbtt_int32 count = ttUSHORT(fc+nm+2); - stbtt_int32 stringOffset = nm + ttUSHORT(fc+nm+4); - - for (i=0; i < count; ++i) { - stbtt_uint32 loc = nm + 6 + 12 * i; - stbtt_int32 id = ttUSHORT(fc+loc+6); - if (id == target_id) { - // find the encoding - stbtt_int32 platform = ttUSHORT(fc+loc+0), encoding = ttUSHORT(fc+loc+2), language = ttUSHORT(fc+loc+4); - - // is this a Unicode encoding? - if (platform == 0 || (platform == 3 && encoding == 1) || (platform == 3 && encoding == 10)) { - stbtt_int32 slen = ttUSHORT(fc+loc+8); - stbtt_int32 off = ttUSHORT(fc+loc+10); - - // check if there's a prefix match - stbtt_int32 matchlen = stbtt__CompareUTF8toUTF16_bigendian_prefix(name, nlen, fc+stringOffset+off,slen); - if (matchlen >= 0) { - // check for target_id+1 immediately following, with same encoding & language - if (i+1 < count && ttUSHORT(fc+loc+12+6) == next_id && ttUSHORT(fc+loc+12) == platform && ttUSHORT(fc+loc+12+2) == encoding && ttUSHORT(fc+loc+12+4) == language) { - slen = ttUSHORT(fc+loc+12+8); - off = ttUSHORT(fc+loc+12+10); - if (slen == 0) { - if (matchlen == nlen) - return 1; - } else if (matchlen < nlen && name[matchlen] == ' ') { - ++matchlen; - if (stbtt_CompareUTF8toUTF16_bigendian_internal((char*) (name+matchlen), nlen-matchlen, (char*)(fc+stringOffset+off),slen)) - return 1; - } - } else { - // if nothing immediately following - if (matchlen == nlen) - return 1; - } - } - } - - // @TODO handle other encodings - } - } - return 0; -} - -static int stbtt__matches(stbtt_uint8 *fc, stbtt_uint32 offset, stbtt_uint8 *name, stbtt_int32 flags) -{ - stbtt_int32 nlen = (stbtt_int32) STBTT_strlen((char *) name); - stbtt_uint32 nm,hd; - if (!stbtt__isfont(fc+offset)) return 0; - - // check italics/bold/underline flags in macStyle... - if (flags) { - hd = stbtt__find_table(fc, offset, "head"); - if ((ttUSHORT(fc+hd+44) & 7) != (flags & 7)) return 0; - } - - nm = stbtt__find_table(fc, offset, "name"); - if (!nm) return 0; - - if (flags) { - // if we checked the macStyle flags, then just check the family and ignore the subfamily - if (stbtt__matchpair(fc, nm, name, nlen, 16, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, -1)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; - } else { - if (stbtt__matchpair(fc, nm, name, nlen, 16, 17)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 1, 2)) return 1; - if (stbtt__matchpair(fc, nm, name, nlen, 3, -1)) return 1; - } - - return 0; -} - -static int stbtt_FindMatchingFont_internal(unsigned char *font_collection, char *name_utf8, stbtt_int32 flags) -{ - stbtt_int32 i; - for (i=0;;++i) { - stbtt_int32 off = stbtt_GetFontOffsetForIndex(font_collection, i); - if (off < 0) return off; - if (stbtt__matches((stbtt_uint8 *) font_collection, off, (stbtt_uint8*) name_utf8, flags)) - return off; - } -} - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-qual" -#endif - -STBTT_DEF int stbtt_BakeFontBitmap(const unsigned char *data, int offset, - float pixel_height, unsigned char *pixels, int pw, int ph, - int first_char, int num_chars, stbtt_bakedchar *chardata) -{ - return stbtt_BakeFontBitmap_internal((unsigned char *) data, offset, pixel_height, pixels, pw, ph, first_char, num_chars, chardata); -} - -STBTT_DEF int stbtt_GetFontOffsetForIndex(const unsigned char *data, int index) -{ - return stbtt_GetFontOffsetForIndex_internal((unsigned char *) data, index); -} - -STBTT_DEF int stbtt_GetNumberOfFonts(const unsigned char *data) -{ - return stbtt_GetNumberOfFonts_internal((unsigned char *) data); -} - -STBTT_DEF int stbtt_InitFont(stbtt_fontinfo *info, const unsigned char *data, int offset) -{ - return stbtt_InitFont_internal(info, (unsigned char *) data, offset); -} - -STBTT_DEF int stbtt_FindMatchingFont(const unsigned char *fontdata, const char *name, int flags) -{ - return stbtt_FindMatchingFont_internal((unsigned char *) fontdata, (char *) name, flags); -} - -STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const char *s2, int len2) -{ - return stbtt_CompareUTF8toUTF16_bigendian_internal((char *) s1, len1, (char *) s2, len2); -} - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - -#endif // STB_TRUETYPE_IMPLEMENTATION - - -// FULL VERSION HISTORY -// -// 1.25 (2021-07-11) many fixes -// 1.24 (2020-02-05) fix warning -// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) -// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined -// 1.21 (2019-02-25) fix warning -// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() -// 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod -// 1.18 (2018-01-29) add missing function -// 1.17 (2017-07-23) make more arguments const; doc fix -// 1.16 (2017-07-12) SDF support -// 1.15 (2017-03-03) make more arguments const -// 1.14 (2017-01-16) num-fonts-in-TTC function -// 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts -// 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual -// 1.11 (2016-04-02) fix unused-variable warning -// 1.10 (2016-04-02) allow user-defined fabs() replacement -// fix memory leak if fontsize=0.0 -// fix warning from duplicate typedef -// 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use alloc userdata for PackFontRanges -// 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges -// 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; -// allow PackFontRanges to pack and render in separate phases; -// fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); -// fixed an assert() bug in the new rasterizer -// replace assert() with STBTT_assert() in new rasterizer -// 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine) -// also more precise AA rasterizer, except if shapes overlap -// remove need for STBTT_sort -// 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC -// 1.04 (2015-04-15) typo in example -// 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes -// 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ -// 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match -// non-oversampled; STBTT_POINT_SIZE for packed case only -// 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling -// 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg) -// 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID -// 0.8b (2014-07-07) fix a warning -// 0.8 (2014-05-25) fix a few more warnings -// 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back -// 0.6c (2012-07-24) improve documentation -// 0.6b (2012-07-20) fix a few more warnings -// 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels, -// stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty -// 0.5 (2011-12-09) bugfixes: -// subpixel glyph renderer computed wrong bounding box -// first vertex of shape can be off-curve (FreeSans) -// 0.4b (2011-12-03) fixed an error in the font baking example -// 0.4 (2011-12-01) kerning, subpixel rendering (tor) -// bugfixes for: -// codepoint-to-glyph conversion using table fmt=12 -// codepoint-to-glyph conversion using table fmt=4 -// stbtt_GetBakedQuad with non-square texture (Zer) -// updated Hello World! sample to use kerning and subpixel -// fixed some warnings -// 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM) -// userdata, malloc-from-userdata, non-zero fill (stb) -// 0.2 (2009-03-11) Fix unsigned/signed char warnings -// 0.1 (2009-03-09) First public release -// - -/* ------------------------------------------------------------------------------- -This software is available under 2 licenses -- choose whichever you prefer. ------------------------------------------------------------------------------- -ALTERNATIVE A - MIT License -Copyright (c) 2017 Sean Barrett -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. ------------------------------------------------------------------------------- -ALTERNATIVE B - Public Domain (www.unlicense.org) -This is free and unencumbered software released into the public domain. -Anyone is free to copy, modify, publish, use, compile, sell, or distribute this -software, either in source code form or as a compiled binary, for any purpose, -commercial or non-commercial, and by any means. -In jurisdictions that recognize copyright laws, the author or authors of this -software dedicate any and all copyright interest in the software to the public -domain. We make this dedication for the benefit of the public at large and to -the detriment of our heirs and successors. We intend this dedication to be an -overt act of relinquishment in perpetuity of all present and future rights to -this software under copyright law. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -*/ diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index f5c323f..c33e6dc 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -5,14 +5,8 @@ set(BOX3D_SHARED_FILES benchmarks.h determinism.c determinism.h - ghost_collisions.c - ghost_collisions.h - ghost_oracle.c - ghost_oracle.h human.c human.h - mesh_drop.c - mesh_drop.h overflow_color.c overflow_color.h stability.c @@ -27,20 +21,7 @@ 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) -# The SAT benchmark calls internal functions that a shared Box3D does not export -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/shared/benchmarks.c b/shared/benchmarks.c index bed4079..e2ce39c 100644 --- a/shared/benchmarks.c +++ b/shared/benchmarks.c @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-FileCopyrightText: 2022 Erin Catto // SPDX-License-Identifier: MIT #include "benchmarks.h" @@ -102,7 +102,7 @@ void CreateLargePyramid( b3WorldId worldId ) { b3World_EnableSleeping( worldId, false ); - int baseCount = BENCHMARK_DEBUG ? 20 : 100; + int baseCount = BENCHMARK_DEBUG ? 20 : 90; { b3BodyDef bodyDef = b3DefaultBodyDef(); @@ -676,15 +676,19 @@ void CreateWasher( b3WorldId worldId ) struct { b3MeshData* meshData; - b3HeightFieldData* heightField; } g_treeData; -static void CreateTrees( b3WorldId worldId, int scale, bool useHeightField ) +static void CreateTrees( b3WorldId worldId, int scale ) { memset( &g_treeData, 0, sizeof( g_treeData ) ); // float tilt = 0.15f * B3_PI; float tilt = 0.0f * B3_PI; + b3BodyDef bodyDef = b3DefaultBodyDef(); + bodyDef.position = (b3Pos){ 0.0f, 0.0f, 0.0f }; + bodyDef.rotation = b3MakeQuatFromAxisAngle( (b3Vec3){ 1.0f, 0.0f, 0.0 }, tilt ); + b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); + int xCount = scale * 150; // int zCount = BENCHMARK_DEBUG ? 100 : 400; int zCount = scale * 200; @@ -694,59 +698,9 @@ static void CreateTrees( b3WorldId worldId, int scale, bool useHeightField ) float rowHz = 0.05f; float columnHz = 0.1f; - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 0.0f, 0.0f, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( (b3Vec3){ 1.0f, 0.0f, 0.0 }, tilt ); - if ( useHeightField ) - { - b3Vec3 corner = { -0.5f * cellWidth * xCount, 0.0f, -0.5f * cellWidth * zCount }; - corner = b3RotateVector( bodyDef.rotation, corner ); - bodyDef.position = (b3Pos){ corner.x, corner.y, corner.z }; - } - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - + g_treeData.meshData = b3CreateWaveMesh( xCount, zCount, cellWidth, amplitude, rowHz, columnHz ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - - if ( useHeightField ) - { - int countX = xCount + 1; - int countZ = zCount + 1; - float* heights = malloc( countX * countZ * sizeof( float ) ); - uint8_t* materialIndices = calloc( xCount * zCount, sizeof( uint8_t ) ); - - float omegaX = 2.0f * B3_PI * columnHz * cellWidth; - float omegaZ = 2.0f * B3_PI * rowHz * cellWidth; - for ( int iz = 0; iz < countZ; ++iz ) - { - float sz = b3ComputeCosSin( omegaZ * iz ).sine; - for ( int ix = 0; ix < countX; ++ix ) - { - float sx = b3ComputeCosSin( omegaX * ix ).sine; - heights[iz * countX + ix] = sx * sz; - } - } - - b3HeightFieldDef hfDef = { 0 }; - hfDef.heights = heights; - hfDef.materialIndices = materialIndices; - hfDef.scale = (b3Vec3){ cellWidth, amplitude, cellWidth }; - hfDef.countX = countX; - hfDef.countZ = countZ; - hfDef.globalMinimumHeight = -1.0f; - hfDef.globalMaximumHeight = 1.0f; - hfDef.clockwiseWinding = false; - - g_treeData.heightField = b3CreateHeightField( &hfDef ); - free( heights ); - free( materialIndices ); - - b3CreateHeightFieldShape( groundId, &shapeDef, g_treeData.heightField ); - } - else - { - g_treeData.meshData = b3CreateWaveMesh( xCount, zCount, cellWidth, amplitude, rowHz, columnHz ); - b3CreateMeshShape( groundId, &shapeDef, g_treeData.meshData, b3Vec3_one ); - } + b3CreateMeshShape( groundId, &shapeDef, g_treeData.meshData, b3Vec3_one ); bodyDef.type = b3_dynamicBody; bodyDef.sleepThreshold = 0.2f; @@ -795,7 +749,7 @@ static void CreateTrees( b3WorldId worldId, int scale, bool useHeightField ) float velocityScale = 0.5f + ( 0.5f * bodyIndex ) / bodyCount; b3Body_ApplyMassFromShapes( bodyId ); - b3Pos center = b3Body_GetWorldCenter( bodyId ); + b3Pos center = b3Body_GetWorldCenterOfMass( bodyId ); b3Vec3 omega = { 0.0f, 0.0f, velocityScale * angularVelocity }; b3Vec3 v = b3Cross( omega, b3SubPos( center, bodyDef.position ) ); b3Body_SetAngularVelocity( bodyId, omega ); @@ -813,120 +767,25 @@ static void CreateTrees( b3WorldId worldId, int scale, bool useHeightField ) void CreateTrees25( b3WorldId worldId ) { - CreateTrees( worldId, 4, false ); + CreateTrees( worldId, 4 ); } void CreateTrees50( b3WorldId worldId ) { - CreateTrees( worldId, 2, false ); + CreateTrees( worldId, 2 ); } void CreateTrees100( b3WorldId worldId ) { - CreateTrees( worldId, 1, false ); -} - -void CreateTrees25HeightField( b3WorldId worldId ) -{ - CreateTrees( worldId, 4, true ); -} - -void CreateTrees50HeightField( b3WorldId worldId ) -{ - CreateTrees( worldId, 2, true ); -} - -void CreateTrees100HeightField( b3WorldId worldId ) -{ - CreateTrees( worldId, 1, true ); + CreateTrees( worldId, 1 ); } void DestroyTrees( void ) { - if ( g_treeData.meshData != NULL ) - { - b3DestroyMesh( g_treeData.meshData ); - } - - if ( g_treeData.heightField != NULL ) - { - b3DestroyHeightField( g_treeData.heightField ); - } - + b3DestroyMesh( g_treeData.meshData ); memset( &g_treeData, 0, sizeof( g_treeData ) ); } -struct -{ - b3MeshData* meshData; -} g_meshDropData; - -void CreateMeshDropBenchmark( b3WorldId worldId ) -{ - memset( &g_meshDropData, 0, sizeof( g_meshDropData ) ); - - int meshGridCount = 120; - int borderCount = 10; - float cellWidth = 1.0f; - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - float rowHz = 0.1f; - float columnHz = 0.2f; - float groundAmplitude = 0.5f; - - g_meshDropData.meshData = - b3CreateWaveMesh( meshGridCount, meshGridCount, cellWidth, groundAmplitude, rowHz, columnHz ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.filter.categoryBits = 1; - b3CreateMeshShape( groundId, &shapeDef, g_meshDropData.meshData, b3Vec3_one ); - } - - { - b3BoxHull box = b3MakeBoxHull( 0.02f, 0.2f, 0.04f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = 0.1f; - - // Don't allow shapes to collide with each other. - shapeDef.filter.categoryBits = 2; - shapeDef.filter.maskBits = 1; - - g_randomSeed = 3963634789; - - int gridCount = BENCHMARK_DEBUG ? 20 : 100; - float spacing = cellWidth * ( meshGridCount - 2 * borderCount ) / gridCount; - float offset = 0.5f * spacing * ( 1 - gridCount ); - - for ( int i = 0; i < gridCount; ++i ) - { - for ( int j = 0; j < gridCount; ++j ) - { - b3Vec3 linearVelocity = RandomVec3Uniform( -1.0f, 1.0f ); - b3Vec3 angularVelocity = RandomVec3Uniform( -5.0f, 5.0f ); - - bodyDef.position = (b3Pos){ offset + spacing * i, 5.0f, offset + spacing * j }; - bodyDef.linearVelocity = linearVelocity; - bodyDef.angularVelocity = angularVelocity; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - } - } - } -} - -void DestroyMeshDropBenchmark( void ) -{ - b3DestroyMesh( g_meshDropData.meshData ); - memset( &g_meshDropData, 0, sizeof( g_meshDropData ) ); -} - struct JunkyardData { b3BodyId pusherId; @@ -1010,22 +869,6 @@ void CreateJunkyard( b3WorldId worldId ) b3DestroyHull( hull ); } -void GetJunkyardCapacity(b3Capacity* capacity) -{ -#ifdef NDEBUG - capacity->staticShapeCount = 16; - capacity->dynamicShapeCount = 20 * 20 * 24 + 1; - capacity->staticBodyCount = 16; - capacity->dynamicBodyCount = 20 * 20 * 24 + 1; - capacity->contactCount = 250 * 1024; -#else - capacity->staticShapeCount = 16; - capacity->dynamicShapeCount = 20 * 20 * 2 + 1; - capacity->staticBodyCount = 16; - capacity->dynamicBodyCount = 20 * 20 * 2 + 1; -#endif -} - void StepJunkyard( b3WorldId worldId, int stepCount ) { (void)worldId; @@ -1040,646 +883,3 @@ void StepJunkyard( b3WorldId worldId, int stepCount ) b3WorldTransform target = { .p = targetPos, .q = b3Quat_identity }; b3Body_SetTargetTransform( g_junkyardData.pusherId, target, timeStep, false ); } - -// Huge pile of large convexes, ported from PEEL. Each convex is the hull of 32 random points on a -// sphere. A fixed LCG seed makes the hull identical across runs so results compare directly. - -void GetConvexPileCapacity( b3Capacity* capacity ) -{ -#ifdef NDEBUG - capacity->dynamicShapeCount = 5120; - capacity->dynamicBodyCount = 5120; - capacity->contactCount = 64 * 1024; -#endif -} - -void CreateConvexPile( b3WorldId worldId ) -{ - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 250.0f, 1.0f, 250.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); - } - - int countX = 8; - int countZ = 8; - int layers = BENCHMARK_DEBUG ? 10 : 80; - float amplitude = 2.0f; - float scatter = 2.0f * amplitude; - - b3HullData* convex = b3CreateComplexHull( amplitude ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - // Grid tall enough to collapse into a pile - for ( int layer = 0; layer < layers; ++layer ) - { - for ( int z = 0; z < countZ; ++z ) - { - for ( int x = 0; x < countX; ++x ) - { - float posX = ( (float)x - 0.5f * (float)countX ) * scatter; - float posZ = ( (float)z - 0.5f * (float)countZ ) * scatter; - float posY = amplitude + 2.0f * amplitude * (float)layer; - - bodyDef.position = (b3Pos){ posX, posY, posZ }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, convex ); - } - } - } - - b3DestroyHull( convex ); -} - -#define SPINNER_SEGMENT_COUNT 90 - -typedef struct -{ - b3MeshData* cylinderMesh; - b3JointId spinnerId; -} SpinnerData; - -static SpinnerData g_spinnerData; - -// An inward facing cylinder capped on both ends, axis along z. Every triangle is wound so its -// normal points at the axis, which is what holds the contents in. The caps do the same job along -// the axis that the 2D loop had for free. -static b3MeshData* CreateInwardCylinderMesh( float radius, float halfDepth, float yCenter, int segmentCount ) -{ - int vertexCount = 2 * segmentCount + 2; - int triangleCount = 4 * segmentCount; - - b3Vec3* vertices = malloc( vertexCount * sizeof( b3Vec3 ) ); - int* indices = malloc( 3 * triangleCount * sizeof( int ) ); - - for ( int i = 0; i < segmentCount; ++i ) - { - float angle = 2.0f * B3_PI * (float)i / (float)segmentCount; - b3CosSin cs = b3ComputeCosSin( angle ); - float x = radius * cs.cosine; - float y = radius * cs.sine + yCenter; - vertices[2 * i + 0] = (b3Vec3){ x, y, -halfDepth }; - vertices[2 * i + 1] = (b3Vec3){ x, y, halfDepth }; - } - - int centerNegative = 2 * segmentCount; - int centerPositive = 2 * segmentCount + 1; - vertices[centerNegative] = (b3Vec3){ 0.0f, yCenter, -halfDepth }; - vertices[centerPositive] = (b3Vec3){ 0.0f, yCenter, halfDepth }; - - int index = 0; - for ( int i = 0; i < segmentCount; ++i ) - { - int j = ( i + 1 ) % segmentCount; - - // Wall, normal towards the axis - indices[index++] = 2 * i + 0; - indices[index++] = 2 * i + 1; - indices[index++] = 2 * j + 1; - - indices[index++] = 2 * i + 0; - indices[index++] = 2 * j + 1; - indices[index++] = 2 * j + 0; - - // Near cap, normal towards positive z - indices[index++] = centerNegative; - indices[index++] = 2 * i + 0; - indices[index++] = 2 * j + 0; - - // Far cap, normal towards negative z - indices[index++] = centerPositive; - indices[index++] = 2 * j + 1; - indices[index++] = 2 * i + 1; - } - - assert( index == 3 * triangleCount ); - - b3MeshDef meshDef = { 0 }; - meshDef.vertices = vertices; - meshDef.vertexCount = vertexCount; - meshDef.indices = indices; - meshDef.triangleCount = triangleCount; - meshDef.identifyEdges = true; - - b3MeshData* meshData = b3CreateMesh( &meshDef, NULL, 0 ); - - free( vertices ); - free( indices ); - - return meshData; -} - -void GetSpinnerCapacity( b3Capacity* capacity ) -{ - capacity->staticShapeCount = 4; - capacity->staticBodyCount = 4; - capacity->dynamicShapeCount = 2000; - capacity->dynamicBodyCount = 2000; - capacity->contactCount = 20000; -} - -// A paddle on a motor churning a pile of small shapes inside a closed cylinder. The cylinder axis -// is z so the cross section matches the 2D benchmark and the hinge, which turns about the local -// frame z axis, lines up with it. The paddle circle is internally tangent to the cylinder at the -// bottom, so the tip scrapes the floor. -void CreateSpinner( b3WorldId worldId ) -{ - g_spinnerData = (SpinnerData){ 0 }; - - float radius = 12.0f; - float halfDepth = 1.0f; - float yCenter = radius; - - b3BodyId groundId; - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - groundId = b3CreateBody( worldId, &bodyDef ); - - g_spinnerData.cylinderMesh = CreateInwardCylinderMesh( radius, halfDepth, yCenter, SPINNER_SEGMENT_COUNT ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.1f; - b3CreateMeshShape( groundId, &shapeDef, g_spinnerData.cylinderMesh, b3Vec3_one ); - } - - { - float halfLength = 0.5f * radius; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, yCenter - halfLength, 0.0f }; - bodyDef.enableSleep = false; - - b3BodyId spinnerId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull paddle = b3MakeBoxHull( 0.3f, halfLength + 0.1f, halfDepth + 0.1f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - b3CreateHullShape( spinnerId, &shapeDef, &paddle.base ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = groundId; - jointDef.base.bodyIdB = spinnerId; - jointDef.base.localFrameA.p = (b3Vec3){ 0.0f, yCenter - halfLength, 0.0f }; - jointDef.enableMotor = true; - jointDef.motorSpeed = 8.0f; - jointDef.maxMotorTorque = FLT_MAX; - - g_spinnerData.spinnerId = b3CreateRevoluteJoint( worldId, &jointDef ); - } - - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.2f }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.1f; - shapeDef.baseMaterial.restitution = 0.1f; - shapeDef.density = 0.25f; - - int bodyCount = BENCHMARK_DEBUG ? 500 : 1500; - - // The grid starts low where the cylinder is narrow, so the span has to fit the chord there - float spacing = 0.55f; - float yStart = 2.0f; - float chordHalfWidth = sqrtf( radius * radius - ( yCenter - yStart ) * ( yCenter - yStart ) ); - float xLimit = chordHalfWidth - 2.0f * spacing; - float zLimit = halfDepth - 2.0f * sphere.radius; - - float x = -xLimit; - float y = yStart; - float z = -zLimit; - - for ( int i = 0; i < bodyCount; ++i ) - { - bodyDef.position = (b3Pos){ x, y, z }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - z += spacing; - - if ( z > zLimit ) - { - z = -zLimit; - x += spacing; - - if ( x > xLimit ) - { - x = -xLimit; - y += spacing; - } - } - } -} - -void DestroySpinner( void ) -{ - if ( g_spinnerData.cylinderMesh != NULL ) - { - b3DestroyMesh( g_spinnerData.cylinderMesh ); - g_spinnerData.cylinderMesh = NULL; - } -} - -// The motor is unbounded, so a healthy run holds the commanded speed and the angle advances -// steadily. A stalling solver shows up here before it shows up in the step time. -float GetSpinnerAngle( void ) -{ - if ( b3Joint_IsValid( g_spinnerData.spinnerId ) == false ) - { - return 0.0f; - } - - return b3RevoluteJoint_GetAngle( g_spinnerData.spinnerId ); -} - -#define SLEEP_PYRAMID_COUNT 10 - -typedef struct -{ - b3BodyId bodyIdA[SLEEP_PYRAMID_COUNT]; - b3BodyId bodyIdB[SLEEP_PYRAMID_COUNT]; -} SleepData; - -static SleepData g_sleepData; - -// Reports two bodies that are certain to share a touching contact, so the filter joint below -// always lands inside one island. -static void CreateSleepPyramid( b3WorldId worldId, int baseCount, float extent, float centerX, b3BodyId* bodyIdA, - b3BodyId* bodyIdB ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.sleepThreshold = 1.0f; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( extent, extent, extent ); - - for ( int i = 0; i < baseCount; ++i ) - { - float y = ( 2.0f * i + 1.0f ) * extent; - - for ( int j = i; j < baseCount; ++j ) - { - float x = ( i + 1.0f ) * extent + 2.0f * ( j - i ) * extent + centerX; - bodyDef.position = (b3Pos){ x, y, 0.0f }; - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - if ( i == 0 && j == 0 ) - { - *bodyIdA = bodyId; - } - else if ( i == 1 && j == 1 ) - { - // Rests on the base body above, so the pair always has a touching contact - *bodyIdB = bodyId; - } - } - } -} - -void GetSleepCapacity( b3Capacity* capacity ) -{ - capacity->staticShapeCount = 4; - capacity->staticBodyCount = 4; - capacity->dynamicShapeCount = 2200; - capacity->dynamicBodyCount = 2200; - capacity->contactCount = 12000; -} - -// Stress tests waking and sleeping. Each pyramid settles into its own island and the step below -// wakes one of them again, so the island splitter never gets to rest. -void CreateSleep( b3WorldId worldId ) -{ - g_sleepData = (SleepData){ 0 }; - - int baseCount = BENCHMARK_DEBUG ? 8 : 20; - float extent = 0.5f; - - float baseWidth = 2.0f * extent * baseCount; - float pitch = baseWidth + 8.0f * extent; - float span = pitch * ( SLEEP_PYRAMID_COUNT - 1 ); - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 0.5f * span + baseWidth, 1.0f, 4.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - g_groundShapeId = b3CreateHullShape( groundId, &shapeDef, &box.base ); - } - - for ( int i = 0; i < SLEEP_PYRAMID_COUNT; ++i ) - { - float centerX = -0.5f * span + i * pitch - 0.5f * baseWidth; - CreateSleepPyramid( worldId, baseCount, extent, centerX, g_sleepData.bodyIdA + i, g_sleepData.bodyIdB + i ); - } -} - -void StepSleep( b3WorldId worldId, int stepCount ) -{ - (void)stepCount; - - for ( int i = 0; i < SLEEP_PYRAMID_COUNT; ++i ) - { - if ( b3Body_IsAwake( g_sleepData.bodyIdA[i] ) == false ) - { - // Creating and destroying a joint engages the island splitter - b3FilterJointDef jointDef = b3DefaultFilterJointDef(); - jointDef.base.bodyIdA = g_sleepData.bodyIdA[i]; - jointDef.base.bodyIdB = g_sleepData.bodyIdB[i]; - b3JointId jointId = b3CreateFilterJoint( worldId, &jointDef ); - - // This wakes the island - b3DestroyJoint( jointId, true ); - - // Only one per step - break; - } - } -} - -#define VILLAGE_TILE_WIDTH 4 -#define VILLAGE_CAST_RADIUS 0.05f -#define VILLAGE_CAST_HEIGHT 10.0f -#define VILLAGE_CAST_LENGTH 12.0f - -#if BENCHMARK_DEBUG -#define VILLAGE_GRID 10 -#define VILLAGE_BODY_GRID 10 -#else -#define VILLAGE_GRID 100 -#define VILLAGE_BODY_GRID 70 -#endif - -// One cast per meter across the full span -#define VILLAGE_MAX_CASTS ( VILLAGE_GRID * VILLAGE_TILE_WIDTH + 1 ) - -typedef struct VillageData -{ - b3CompoundData* compound; - b3Quat rotation; - float halfSpan; - b3Vec3 castTranslation; - int castCount; - VillageCast casts[VILLAGE_MAX_CASTS]; -} VillageData; - -static VillageData g_villageData; - -void GetVillageCapacity( b3Capacity* capacity ) -{ - int bodyCount = VILLAGE_BODY_GRID * VILLAGE_BODY_GRID; - capacity->staticShapeCount = 1; - capacity->staticBodyCount = 1; - capacity->dynamicShapeCount = bodyCount; - capacity->dynamicBodyCount = bodyCount; - capacity->contactCount = 4 * bodyCount; -} - -void CreateVillage( b3WorldId worldId ) -{ - memset( &g_villageData, 0, sizeof( g_villageData ) ); - g_randomSeed = 2718281828; - - int gridCount = VILLAGE_GRID; - float tileWidth = VILLAGE_TILE_WIDTH; - float halfSpan = 0.5f * tileWidth * gridCount; - g_villageData.halfSpan = halfSpan; - - { - int tileCount = gridCount * gridCount; - int propCapacity = tileCount / 8 + 1; - - b3CompoundHullDef* hulls = malloc( tileCount * sizeof( b3CompoundHullDef ) ); - b3CompoundMeshDef* meshes = malloc( tileCount * sizeof( b3CompoundMeshDef ) ); - b3CompoundCapsuleDef* capsules = malloc( propCapacity * sizeof( b3CompoundCapsuleDef ) ); - b3CompoundSphereDef* spheres = malloc( propCapacity * sizeof( b3CompoundSphereDef ) ); - - b3SurfaceMaterial material = b3DefaultSurfaceMaterial(); - b3BoxHull tile = b3MakeBoxHull( 0.5f * tileWidth, 0.5f, 0.5f * tileWidth ); - - // A wave patch replaces a sparse set of tiles so the compound carries mesh children - b3MeshData* wave = b3CreateWaveMesh( 8, 8, tileWidth / 8.0f, 0.25f, 0.25f, 0.25f ); - - int hullCount = 0; - int meshCount = 0; - int capsuleCount = 0; - int sphereCount = 0; - - for ( int i = 0; i < gridCount; ++i ) - { - float x = -halfSpan + ( i + 0.5f ) * tileWidth; - - for ( int j = 0; j < gridCount; ++j ) - { - float z = -halfSpan + ( j + 0.5f ) * tileWidth; - - if ( i % 16 == 8 && j % 16 == 8 ) - { - meshes[meshCount] = (b3CompoundMeshDef){ - .meshData = wave, - .transform = { { x, 0.0f, z }, b3Quat_identity }, - .scale = b3Vec3_one, - .materials = &material, - .materialCount = 1, - }; - meshCount += 1; - continue; - } - - hulls[hullCount] = (b3CompoundHullDef){ - .hull = &tile.base, - .transform = { { x, -0.5f, z }, b3Quat_identity }, - .material = material, - }; - hullCount += 1; - - int tileIndex = i * gridCount + j; - if ( tileIndex % 8 != 0 ) - { - continue; - } - - if ( ( tileIndex / 8 ) & 1 ) - { - float radius = 0.25f; - capsules[capsuleCount] = (b3CompoundCapsuleDef){ - .capsule = { { x - 1.0f, radius, z }, { x + 1.0f, radius, z }, radius }, - .material = material, - }; - capsuleCount += 1; - } - else - { - float radius = 0.5f; - spheres[sphereCount] = (b3CompoundSphereDef){ - .sphere = { { x, radius, z }, radius }, - .material = material, - }; - sphereCount += 1; - } - } - } - - b3CompoundDef def = { - .capsules = capsules, - .capsuleCount = capsuleCount, - .hulls = hulls, - .hullCount = hullCount, - .meshes = meshes, - .meshCount = meshCount, - .spheres = spheres, - .sphereCount = sphereCount, - }; - - g_villageData.compound = b3CreateCompound( &def ); - - // The compound clones its inputs - b3DestroyMesh( wave ); - free( hulls ); - free( meshes ); - free( capsules ); - free( spheres ); - - // Rotated so broad-phase lookups transform into the compound frame - g_villageData.rotation = b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, -1.15f * B3_PI ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.rotation = g_villageData.rotation; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( groundId, &shapeDef, g_villageData.compound ); - } - - { - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.3f }; - b3Capsule capsule = { { -0.3f, 0.0f, 0.0f }, { 0.3f, 0.0f, 0.0f }, 0.2f }; - b3BoxHull box = b3MakeCubeHull( 0.3f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - int bodyGrid = VILLAGE_BODY_GRID; - float spacing = 1.6f; - float offset = 0.5f * spacing * ( 1 - bodyGrid ); - - for ( int i = 0; i < bodyGrid; ++i ) - { - for ( int j = 0; j < bodyGrid; ++j ) - { - int index = i * bodyGrid + j; - - bodyDef.position = (b3Pos){ offset + spacing * i, RandomFloatRange( 2.0f, 6.0f ), offset + spacing * j }; - bodyDef.linearVelocity = b3Vec3_zero; - bodyDef.angularVelocity = RandomVec3Uniform( -2.0f, 2.0f ); - - // Fast enough to need continuous collision against the compound - if ( index % 20 == 0 ) - { - bodyDef.position.y = 20.0f; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, -80.0f, 0.0f }; - } - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - switch ( index % 3 ) - { - case 0: - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - break; - case 1: - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - break; - default: - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - break; - } - } - } - } -} - -static float VillageCastCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, - int triangleIndex, int childIndex, void* context ) -{ - (void)shapeId; - (void)userMaterialId; - (void)triangleIndex; - (void)childIndex; - - // Clipping makes each report closer than the last, so the final one is the closest - VillageCast* cast = context; - cast->point = point; - cast->normal = normal; - cast->fraction = fraction; - cast->hit = true; - return fraction; -} - -// A curtain of tilted sphere casts, one per meter, sweeps across the compound once per run. -void StepVillage( b3WorldId worldId, int stepIndex ) -{ - float halfSpan = g_villageData.halfSpan; - float t = (float)( stepIndex % VILLAGE_STEP_COUNT ) / (float)( VILLAGE_STEP_COUNT - 1 ); - float x = -halfSpan + 2.0f * halfSpan * t; - - b3CosSin tilt = b3ComputeCosSin( ( 20.0f / 180.0f ) * B3_PI ); - b3Vec3 localTranslation = { VILLAGE_CAST_LENGTH * tilt.sine, -VILLAGE_CAST_LENGTH * tilt.cosine, 0.0f }; - - // The curtain is laid out in the compound frame - b3Quat q = g_villageData.rotation; - b3Vec3 translation = b3RotateVector( q, localTranslation ); - - b3Vec3 point = b3Vec3_zero; - b3ShapeProxy proxy = { &point, 1, VILLAGE_CAST_RADIUS }; - b3QueryFilter filter = b3DefaultQueryFilter(); - - int castCount = (int)( 2.0f * halfSpan ) + 1; - assert( castCount <= VILLAGE_MAX_CASTS ); - - for ( int i = 0; i < castCount; ++i ) - { - b3Vec3 localOrigin = { x, VILLAGE_CAST_HEIGHT, -halfSpan + (float)i }; - - VillageCast* cast = g_villageData.casts + i; - *cast = (VillageCast){ 0 }; - cast->origin = b3ToPos( b3RotateVector( q, localOrigin ) ); - cast->fraction = 1.0f; - - b3World_CastShape( worldId, cast->origin, &proxy, translation, filter, VillageCastCallback, cast ); - } - - g_villageData.castTranslation = translation; - g_villageData.castCount = castCount; -} - -VillageCurtain GetVillageCurtain( void ) -{ - return (VillageCurtain){ - .casts = g_villageData.casts, - .castCount = g_villageData.castCount, - .translation = g_villageData.castTranslation, - .radius = VILLAGE_CAST_RADIUS, - }; -} - -void DestroyVillage( void ) -{ - b3DestroyCompound( g_villageData.compound ); - memset( &g_villageData, 0, sizeof( g_villageData ) ); -} diff --git a/shared/benchmarks.h b/shared/benchmarks.h index 29f1530..9975e1d 100644 --- a/shared/benchmarks.h +++ b/shared/benchmarks.h @@ -3,7 +3,6 @@ #pragma once #include "box3d/id.h" -#include "box3d/math_functions.h" #include @@ -24,15 +23,9 @@ void ResetGroundShapeId( void ); void CreateTrees25( b3WorldId worldId ); void CreateTrees50( b3WorldId worldId ); void CreateTrees100( b3WorldId worldId ); -void CreateTrees25HeightField( b3WorldId worldId ); -void CreateTrees50HeightField( b3WorldId worldId ); -void CreateTrees100HeightField( b3WorldId worldId ); void DestroyTrees( void ); -void CreateMeshDropBenchmark( b3WorldId worldId ); -void DestroyMeshDropBenchmark( void ); void CreateJointGrid( b3WorldId worldId ); void CreateJunkyard( b3WorldId worldId ); -void GetJunkyardCapacity( b3Capacity* capacity ); void StepJunkyard( b3WorldId worldId, int stepCount ); void CreateLargePyramid( b3WorldId worldId ); void CreateWidePyramid( b3WorldId worldId ); @@ -46,42 +39,9 @@ void CreateLargeWorld( b3WorldId worldId ); void StepLargeWorld( b3WorldId worldId, int stepCount ); void GetWasherCapacity( b3Capacity* capacity ); void CreateWasher( b3WorldId worldId ); -void CreateConvexPile( b3WorldId worldId ); -void GetConvexPileCapacity( b3Capacity* capacity ); -void GetSpinnerCapacity( b3Capacity* capacity ); -void CreateSpinner( b3WorldId worldId ); -void DestroySpinner( void ); -float GetSpinnerAngle( void ); -void GetSleepCapacity( b3Capacity* capacity ); -void CreateSleep( b3WorldId worldId ); -void StepSleep( b3WorldId worldId, int stepCount ); - -#define VILLAGE_STEP_COUNT 600 - -typedef struct VillageCast -{ - b3Pos origin; - b3Pos point; - b3Vec3 normal; - float fraction; - bool hit; -} VillageCast; - -// The sphere casts from the latest village step, for drawing -typedef struct VillageCurtain -{ - const VillageCast* casts; - int castCount; - b3Vec3 translation; - float radius; -} VillageCurtain; - -void GetVillageCapacity( b3Capacity* capacity ); -void CreateVillage( b3WorldId worldId ); -void StepVillage( b3WorldId worldId, int stepIndex ); -void DestroyVillage( void ); -VillageCurtain GetVillageCurtain( void ); +// void CreateSpinner( b3WorldId worldId ); +// float StepSpinner( b3WorldId worldId, int stepCount ); // void CreateSmash( b3WorldId worldId ); // void CreateTumbler( b3WorldId worldId ); diff --git a/shared/determinism.c b/shared/determinism.c index d3e37eb..0034afb 100644 --- a/shared/determinism.c +++ b/shared/determinism.c @@ -4,7 +4,6 @@ #include "determinism.h" #include "human.h" -#include "utils.h" #include "box3d/box3d.h" @@ -123,404 +122,3 @@ void DestroyFallingRagdolls( FallingRagdollData* data ) data->gridMesh = NULL; data->torusMesh = NULL; } - -#define WAVE_PILE_GRID 5 -#define WAVE_PILE_LAYERS 4 - -WavePileData CreateWavePile( b3WorldId worldId ) -{ - WavePileData data = { 0 }; - - g_randomSeed = 52977; - - // Height fields grow from a corner, offset the body to center the patch. - int fieldCount = 21; - b3Vec3 fieldScale = { 1.0f, 0.6f, 1.0f }; - data.heightField = b3CreateWave( fieldCount, fieldCount, fieldScale, 0.08f, 0.06f, false ); - - { - float extent = fieldScale.x * ( fieldCount - 1 ); - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position.x = -0.5f * extent; - bodyDef.position.z = -0.5f * extent; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHeightFieldShape( groundId, &shapeDef, data.heightField ); - } - - b3HullData* rock = b3CreateRock( 0.55f ); - b3BoxHull box = b3MakeBoxHull( 0.45f, 0.3f, 0.55f ); - b3Sphere sphere = { b3Vec3_zero, 0.5f }; - b3Capsule capsule = { { 0.0f, -0.3f, 0.0f }, { 0.0f, 0.3f, 0.0f }, 0.35f }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - // Rolling resistance so the pile sleeps quickly. - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = 0.3f; - - float spacing = 1.7f; - int index = 0; - for ( int layer = 0; layer < WAVE_PILE_LAYERS; ++layer ) - { - for ( int i = 0; i < WAVE_PILE_GRID; ++i ) - { - for ( int j = 0; j < WAVE_PILE_GRID; ++j ) - { - b3Vec3 jitter = RandomVec3Uniform( -0.3f, 0.3f ); - bodyDef.position.x = spacing * ( i - 0.5f * ( WAVE_PILE_GRID - 1 ) ) + jitter.x; - bodyDef.position.y = 2.5f + 1.6f * layer + 0.3f * jitter.y; - bodyDef.position.z = spacing * ( j - 0.5f * ( WAVE_PILE_GRID - 1 ) ) + jitter.z; - bodyDef.rotation = RandomQuat(); - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - data.bodies[index] = bodyId; - - switch ( index % 4 ) - { - case 0: - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - break; - case 1: - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - break; - case 2: - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - break; - default: - b3CreateHullShape( bodyId, &shapeDef, rock ); - break; - } - - index += 1; - } - } - } - - assert( index == WAVE_PILE_BODY_COUNT ); - - // The world keeps its own copy. - b3DestroyHull( rock ); - - return data; -} - -bool UpdateWavePile( b3WorldId worldId, WavePileData* data ) -{ - if ( data->hash == 0 ) - { - if ( b3World_GetAwakeBodyCount( worldId ) == 0 ) - { - data->hash = B3_HASH_INIT; - for ( int i = 0; i < WAVE_PILE_BODY_COUNT; ++i ) - { - b3WorldTransform xf = b3Body_GetTransform( data->bodies[i] ); - data->hash = b3Hash( data->hash, (uint8_t*)&xf, sizeof( b3WorldTransform ) ); - } - - data->sleepStep = data->stepCount; - } - } - - data->stepCount += 1; - - return data->hash != 0; -} - -void DestroyWavePile( WavePileData* data ) -{ - b3DestroyHeightField( data->heightField ); - data->heightField = NULL; -} - -typedef struct QuerySpawnOverlapContext -{ - QuerySpawnData* data; - int count; -} QuerySpawnOverlapContext; - -static bool QuerySpawnOverlapCallback( b3ShapeId shapeId, void* context ) -{ - QuerySpawnOverlapContext* overlap = context; - overlap->count += 1; - overlap->data->queryHitCount += 1; - overlap->data->queryHash = b3Hash( overlap->data->queryHash, (uint8_t*)&shapeId.index1, sizeof( shapeId.index1 ) ); - return true; -} - -static float QuerySpawnCastCallback( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, - int triangleIndex, int childIndex, void* context ) -{ - (void)shapeId, (void)point, (void)normal, (void)userMaterialId, (void)triangleIndex, (void)childIndex; - float* closest = context; - *closest = fraction; - return fraction; -} - -static void QuerySpawnOnce( b3WorldId worldId, QuerySpawnData* data ) -{ - b3QueryFilter filter = b3DefaultQueryFilter(); - - // Ray result decides the spawn position, a miss seeds the cloud near the origin. - b3Pos rayOrigin = RandomPos( (b3Vec3){ -12.0f, -12.0f, -12.0f }, (b3Vec3){ 12.0f, 12.0f, 12.0f } ); - b3Vec3 rayTranslation = b3MulSV( 30.0f, RandomUnitVector() ); - - b3Pos spawnPosition; - b3RayResult ray = b3World_CastRayClosest( worldId, rayOrigin, rayTranslation, filter ); - if ( ray.hit ) - { - data->queryHitCount += 1; - data->queryHash = b3Hash( data->queryHash, (uint8_t*)&ray.fraction, sizeof( ray.fraction ) ); - data->queryHash = b3Hash( data->queryHash, (uint8_t*)&ray.normal, sizeof( ray.normal ) ); - spawnPosition = b3OffsetPos( ray.point, b3MulSV( 1.2f, ray.normal ) ); - } - else - { - spawnPosition = RandomPos( (b3Vec3){ -6.0f, -6.0f, -6.0f }, (b3Vec3){ 6.0f, 6.0f, 6.0f } ); - } - - data->rayOrigin = rayOrigin; - data->rayTranslation = rayTranslation; - data->rayDidHit = ray.hit; - data->rayPoint = ray.hit ? ray.point : b3OffsetPos( rayOrigin, rayTranslation ); - data->rayNormal = ray.hit ? ray.normal : b3Vec3_zero; - - // Overlap count picks the shape type. - b3Vec3 center = RandomVec3Uniform( -10.0f, 10.0f ); - float extent = RandomFloatRange( 1.0f, 4.0f ); - b3AABB aabb; - aabb.lowerBound = (b3Vec3){ center.x - extent, center.y - extent, center.z - extent }; - aabb.upperBound = (b3Vec3){ center.x + extent, center.y + extent, center.z + extent }; - - QuerySpawnOverlapContext overlap = { data, 0 }; - b3World_OverlapAABB( worldId, aabb, filter, QuerySpawnOverlapCallback, &overlap ); - - data->overlapBounds = aabb; - data->overlapCount = overlap.count; - - // Sphere cast fraction sets the spawn size. - float fraction = 1.0f; - b3Vec3 proxyPoint = b3Vec3_zero; - b3ShapeProxy proxy = { &proxyPoint, 1, QUERY_SPAWN_CAST_RADIUS }; - b3World_CastShape( worldId, rayOrigin, &proxy, rayTranslation, filter, QuerySpawnCastCallback, &fraction ); - if ( fraction < 1.0f ) - { - data->queryHitCount += 1; - data->queryHash = b3Hash( data->queryHash, (uint8_t*)&fraction, sizeof( fraction ) ); - } - - data->castFraction = fraction; - - float size = 0.3f + 0.2f * fraction; - - // Damping guarantees everything comes to rest. - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = spawnPosition; - bodyDef.rotation = RandomQuat(); - bodyDef.linearVelocity = RandomVec3Uniform( -0.2f, 0.2f ); - bodyDef.angularVelocity = RandomVec3Uniform( -0.5f, 0.5f ); - bodyDef.linearDamping = 1.0f; - bodyDef.angularDamping = 1.0f; - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.rollingResistance = 0.2f; - - switch ( ( data->spawnCount + overlap.count ) % 3 ) - { - case 0: - { - b3Sphere sphere = { b3Vec3_zero, size }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - break; - } - case 1: - { - b3Capsule capsule = { { 0.0f, -size, 0.0f }, { 0.0f, size, 0.0f }, 0.7f * size }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - break; - } - default: - { - b3BoxHull box = b3MakeBoxHull( size, 0.7f * size, 0.5f * size ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - break; - } - } - - data->bodies[data->spawnCount] = bodyId; - data->spawnCount += 1; - data->lastSpawnPosition = spawnPosition; -} - -QuerySpawnData CreateQuerySpawn( b3WorldId worldId ) -{ - QuerySpawnData data = { 0 }; - - g_randomSeed = 71689; - - // Empty space, motion comes only from spawn velocities and overlap pushes. - b3World_SetGravity( worldId, b3Vec3_zero ); - - return data; -} - -bool UpdateQuerySpawn( b3WorldId worldId, QuerySpawnData* data ) -{ - if ( data->spawnCount < QUERY_SPAWN_COUNT ) - { - QuerySpawnOnce( worldId, data ); - } - else if ( data->hash == 0 && b3World_GetAwakeBodyCount( worldId ) == 0 ) - { - data->hash = B3_HASH_INIT; - for ( int i = 0; i < QUERY_SPAWN_COUNT; ++i ) - { - b3WorldTransform xf = b3Body_GetTransform( data->bodies[i] ); - data->hash = b3Hash( data->hash, (uint8_t*)&xf, sizeof( b3WorldTransform ) ); - } - - data->sleepStep = data->stepCount; - } - - data->stepCount += 1; - - return data->hash != 0; -} - -void DestroyQuerySpawn( QuerySpawnData* data ) -{ - (void)data; -} - -FallingHingeData CreateFallingHinges( b3WorldId worldId ) -{ - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } - - int columnCount = 4; - int rowCount = 20; - int bodyCount = rowCount * columnCount; - - b3BodyId* bodyIds = calloc( bodyCount, sizeof( b3BodyId ) ); - - float h = 0.25f; - b3BoxHull box = b3MakeBoxHull( h, h, h ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.enableLimit = true; - jointDef.lowerAngle = -0.1f * B3_PI; - jointDef.upperAngle = 0.2f * B3_PI; - jointDef.enableSpring = true; - jointDef.hertz = 1.0f; - jointDef.dampingRatio = 1.0f; - jointDef.enableMotor = true; - jointDef.maxMotorTorque = 0.25f; - jointDef.base.localFrameA.p = (b3Vec3){ -h, h, 0.0f }; - jointDef.base.localFrameB.p = (b3Vec3){ -h, -h, 0.0f }; - jointDef.base.constraintHertz = 60.0f; - jointDef.base.constraintDampingRatio = 0.0f; - jointDef.base.drawScale = 0.5f; - - int bodyIndex = 0; - float offset = 0.4f * h; - float dx = 10.0f * h; - float xBase = -0.5f * dx * ( columnCount - 1.0f ); - - for ( int j = 0; j < columnCount; ++j ) - { - float x = xBase + j * dx; - - b3BodyId prevBodyId = b3_nullBodyId; - - for ( int i = 0; i < rowCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - bodyDef.position.x = x + offset * i; - bodyDef.position.y = h + 2.0f * h * i; - - // this tests the deterministic cosine and sine functions - float angle = ( i & 1 ) == 0 ? -0.1f : 0.1f; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, angle ); - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - if ( ( i & 1 ) == 0 ) - { - prevBodyId = bodyId; - } - else - { - jointDef.base.bodyIdA = prevBodyId; - jointDef.base.bodyIdB = bodyId; - b3CreateRevoluteJoint( worldId, &jointDef ); - prevBodyId = b3_nullBodyId; - } - - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - assert( bodyIndex < bodyCount ); - bodyIds[bodyIndex] = bodyId; - - bodyIndex += 1; - } - } - - assert( bodyIndex == bodyCount ); - - FallingHingeData data = { - .bodyIds = bodyIds, - .bodyCount = bodyCount, - .stepCount = 0, - .sleepStep = -1, - .hash = 0, - }; - return data; -} - -bool UpdateFallingHinges( b3WorldId worldId, FallingHingeData* data ) -{ - if ( data->hash == 0 ) - { - b3BodyEvents bodyEvents = b3World_GetBodyEvents( worldId ); - - if ( bodyEvents.moveCount == 0 ) - { - assert( b3World_GetAwakeBodyCount( worldId ) == 0 ); - - data->hash = B3_HASH_INIT; - for ( int i = 0; i < data->bodyCount; ++i ) - { - b3WorldTransform transform = b3Body_GetTransform( data->bodyIds[i] ); - data->hash = b3Hash( data->hash, (uint8_t*)( &transform ), sizeof( b3WorldTransform ) ); - } - - data->sleepStep = data->stepCount; - } - } - - data->stepCount += 1; - - return data->hash != 0; -} - -void DestroyFallingHinges( FallingHingeData* data ) -{ - free( data->bodyIds ); - data->bodyIds = NULL; -} diff --git a/shared/determinism.h b/shared/determinism.h index cb3f5a3..0839fbf 100644 --- a/shared/determinism.h +++ b/shared/determinism.h @@ -36,78 +36,6 @@ FallingRagdollData CreateFallingRagdolls( b3WorldId worldId ); bool UpdateFallingRagdolls( b3WorldId worldId, FallingRagdollData* data ); void DestroyFallingRagdolls( FallingRagdollData* data ); -// Convex pile dropped on a wave height field. Spheres, capsules, boxes, and rocks with -// rolling resistance so the pile sleeps quickly. -#define WAVE_PILE_BODY_COUNT 100 - -typedef struct WavePileData -{ - b3BodyId bodies[WAVE_PILE_BODY_COUNT]; - b3HeightFieldData* heightField; - int stepCount; - int sleepStep; - uint32_t hash; -} WavePileData; - -WavePileData CreateWavePile( b3WorldId worldId ); -bool UpdateWavePile( b3WorldId worldId, WavePileData* data ); -void DestroyWavePile( WavePileData* data ); - -// Query driven spawning in an empty zero gravity world. Each step casts a ray, overlaps an -// AABB, and casts a sphere, then spawns a shape whose position, type, and size depend on the -// query results. Any query divergence cascades into the final state. -#define QUERY_SPAWN_COUNT 50 -#define QUERY_SPAWN_CAST_RADIUS 0.5f - -typedef struct QuerySpawnData -{ - b3BodyId bodies[QUERY_SPAWN_COUNT]; - int spawnCount; - int queryHitCount; - uint32_t queryHash; - int stepCount; - int sleepStep; - uint32_t hash; - - // Last query cycle, recorded for visualization - b3Pos rayOrigin; - b3Vec3 rayTranslation; - b3Pos rayPoint; - b3Vec3 rayNormal; - bool rayDidHit; - b3AABB overlapBounds; - int overlapCount; - float castFraction; - b3Pos lastSpawnPosition; -} QuerySpawnData; - -QuerySpawnData CreateQuerySpawn( b3WorldId worldId ); -bool UpdateQuerySpawn( b3WorldId worldId, QuerySpawnData* data ); -void DestroyQuerySpawn( QuerySpawnData* data ); - -// A grid of short hinged columns that fall and settle. Light enough to step in a unit test -// and it exercises joints, sleeping islands, and island splitting. -#if defined( BOX3D_DOUBLE_PRECISION ) -#define FALLING_HINGE_SLEEP_STEP 277 -#define FALLING_HINGE_HASH 0x97A63BFF -#else -#define FALLING_HINGE_SLEEP_STEP 248 -#define FALLING_HINGE_HASH 0xF4CAB37C -#endif - -typedef struct FallingHingeData -{ - b3BodyId* bodyIds; - int bodyCount; - int stepCount; - int sleepStep; - uint32_t hash; -} FallingHingeData; - -FallingHingeData CreateFallingHinges( b3WorldId worldId ); -bool UpdateFallingHinges( b3WorldId worldId, FallingHingeData* data ); -void DestroyFallingHinges( FallingHingeData* data ); - #ifdef __cplusplus } #endif diff --git a/shared/ghost_collisions.c b/shared/ghost_collisions.c deleted file mode 100644 index 2caf0a0..0000000 --- a/shared/ghost_collisions.c +++ /dev/null @@ -1,896 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "ghost_collisions.h" - -#include "box3d/box3d.h" - -#include -#include -#include -#include - -#define GHOST_HALF_LENGTH 20.0f -#define GHOST_HALF_WIDTH 3.0f -#define GHOST_START_X -16.0f - -// The rail deflects the body sideways and the floor is frictionless, so a narrow floor ends the run off -// the side instead of at the far end -#define GHOST_RAIL_HALF_LENGTH ( 0.5f * GHOST_HALF_LENGTH ) -#define GHOST_RAIL_HALF_WIDTH ( 2.0f * GHOST_HALF_WIDTH ) - -// A run takes about 144 steps, clear of 150 where the 900 step scan would flip between 5 and 6 runs -#define GHOST_RAIL_START_X -5.3f - -// A 34 degree chamfer like the s&box beams -#define GHOST_CHAMFER_WIDTH 0.05f -#define GHOST_CHAMFER_DROP ( GHOST_CHAMFER_WIDTH / 1.5f ) - -#define GHOST_RAIL_SKIRT 0.4f - -// The s&box beam floor at 1/30 m per inch, rounded to whole chamfer cells so a height field grid holds every -// vertex. Beams with chamfered tops over deep pits, the 0.8 m hull always spans a pit. -#define GHOST_BEAM_COUNT 20 -#define GHOST_BEAM_START_X -8.0f -#define GHOST_BEAM_PITCH 0.75f -#define GHOST_BEAM_WIDTH 0.4f -#define GHOST_BEAM_PIT_DEPTH 0.8f - -typedef struct PeelPreset -{ - int columnCount; - float scaleX; - float startZ; -} PeelPreset; - -static const PeelPreset s_peelPresets[GHOST_PEEL_PRESET_COUNT] = { - { 4, 0.1f, -55.0f }, - { 4, 0.1f, -54.0f }, - { 4, 0.01f, -55.0f }, - { 16, 0.01f, -54.0f }, -}; - -const char* g_ghostSceneNames[e_ghostSceneCount] = { - "Flat", "Concave", "Cliff", "Crest", "Bumps", "Internal", "Chamfer", "Rail", "Beams", -}; - -const char* g_ghostBodyNames[e_ghostBodyCount] = { "Box", "H Capsule", "V Capsule", "Sphere", "Cylinder" }; - -const char* g_ghostPeelPresetNames[GHOST_PEEL_PRESET_COUNT] = { - "4.1:-55", - "4.1:-54", - "4.01:-55", - "16.01:-54", -}; - -GhostSettings GetDefaultGhostSettings( void ) -{ - GhostSettings settings = { - .scene = e_ghostFlat, - .body = e_ghostBox, - .peelPreset = 0, - .mirror = false, - .heightField = false, - .cellSize = 0.25f, - .speed = 6.0f, - .yaw = 0.0f, - .friction = 0.0f, - .fixedRotation = false, - .speculative = true, - }; - return settings; -} - -typedef struct MeshBuilder -{ - b3Vec3* vertices; - int vertexCount; - int32_t* indices; - int indexCount; -} MeshBuilder; - -// The profile runs in +x with the solid below it. The mirror flips x in the data and the mesh -// scale flips it back, so the world geometry is the same either way. -static void AddGrid( MeshBuilder* builder, const b3Vec2* points, int pointCount, float halfWidth, int zCount, bool alternate, - bool mirror ) -{ - float sign = mirror ? -1.0f : 1.0f; - int stride = zCount + 1; - int base = builder->vertexCount; - - builder->vertices = realloc( builder->vertices, ( builder->vertexCount + pointCount * stride ) * sizeof( b3Vec3 ) ); - for ( int i = 0; i < pointCount; ++i ) - { - for ( int j = 0; j <= zCount; ++j ) - { - float z = -halfWidth + 2.0f * halfWidth * (float)j / (float)zCount; - builder->vertices[builder->vertexCount++] = (b3Vec3){ sign * points[i].x, points[i].y, z }; - } - } - - int triangleCount = 2 * ( pointCount - 1 ) * zCount; - builder->indices = realloc( builder->indices, ( builder->indexCount + 3 * triangleCount ) * sizeof( int32_t ) ); - for ( int i = 0; i + 1 < pointCount; ++i ) - { - for ( int j = 0; j < zCount; ++j ) - { - int a = base + i * stride + j; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - - int corners[6] = { a, b, c, c, d, a }; - - // Alternate the diagonal like cooked level geometry - if ( alternate && ( ( i + j ) & 1 ) ) - { - int flipped[6] = { a, b, d, b, c, d }; - memcpy( corners, flipped, sizeof( corners ) ); - } - - for ( int k = 0; k < 6; k += 3 ) - { - builder->indices[builder->indexCount++] = corners[k]; - builder->indices[builder->indexCount++] = mirror ? corners[k + 2] : corners[k + 1]; - builder->indices[builder->indexCount++] = mirror ? corners[k + 1] : corners[k + 2]; - } - } - } -} - -static void AddStrip( MeshBuilder* builder, const b3Vec2* profile, int count, float cellSize, float zCell, bool mirror ) -{ - int pointCount = 1; - for ( int k = 0; k + 1 < count; ++k ) - { - b3Vec2 a = profile[k]; - b3Vec2 b = profile[k + 1]; - float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) ); - pointCount += b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) ); - } - - b3Vec2* points = malloc( pointCount * sizeof( b3Vec2 ) ); - int index = 0; - points[index++] = profile[0]; - for ( int k = 0; k + 1 < count; ++k ) - { - b3Vec2 a = profile[k]; - b3Vec2 b = profile[k + 1]; - float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) ); - int n = b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) ); - for ( int s = 1; s <= n; ++s ) - { - float t = (float)s / (float)n; - points[index++] = (b3Vec2){ a.x + t * ( b.x - a.x ), a.y + t * ( b.y - a.y ) }; - } - } - - int zCount = b3MaxInt( 1, (int)ceilf( 2.0f * GHOST_HALF_WIDTH / zCell - 0.01f ) ); - AddGrid( builder, points, pointCount, GHOST_HALF_WIDTH, zCount, true, mirror ); - free( points ); -} - -// The rail cross section is a profile in zy extruded along x. Each quad side is its edge direction along -// the section crossed with x, which is the outward normal for a section traversed with air on the left. -static void AddRail( MeshBuilder* builder, const b3Vec2* section, int count, float halfLength, float cellSize, bool mirror ) -{ - float sign = mirror ? -1.0f : 1.0f; - int xCount = b3MaxInt( 1, (int)ceilf( 2.0f * halfLength / cellSize - 0.01f ) ); - int stride = xCount + 1; - - int pointCount = 1; - for ( int k = 0; k + 1 < count; ++k ) - { - float dz = section[k + 1].x - section[k].x; - float dy = section[k + 1].y - section[k].y; - pointCount += b3MaxInt( 1, (int)ceilf( sqrtf( dz * dz + dy * dy ) / cellSize - 0.01f ) ); - } - - builder->vertices = realloc( builder->vertices, pointCount * stride * sizeof( b3Vec3 ) ); - int index = 0; - for ( int k = 0; k < count; ++k ) - { - int n = 1; - if ( k + 1 < count ) - { - float dz = section[k + 1].x - section[k].x; - float dy = section[k + 1].y - section[k].y; - n = b3MaxInt( 1, (int)ceilf( sqrtf( dz * dz + dy * dy ) / cellSize - 0.01f ) ); - } - - // The last point only closes the final segment - int last = k + 1 < count ? n : 1; - for ( int s = 0; s < last; ++s ) - { - float t = k + 1 < count ? (float)s / (float)n : 0.0f; - b3Vec2 a = section[k]; - b3Vec2 b = k + 1 < count ? section[k + 1] : a; - float z = a.x + t * ( b.x - a.x ); - float y = a.y + t * ( b.y - a.y ); - for ( int j = 0; j <= xCount; ++j ) - { - float x = -halfLength + 2.0f * halfLength * (float)j / (float)xCount; - builder->vertices[index++] = (b3Vec3){ sign * x, y, z }; - } - } - } - - builder->vertexCount = index; - - int triangleCount = 2 * ( pointCount - 1 ) * xCount; - builder->indices = realloc( builder->indices, 3 * triangleCount * sizeof( int32_t ) ); - builder->indexCount = 0; - for ( int i = 0; i + 1 < pointCount; ++i ) - { - for ( int j = 0; j < xCount; ++j ) - { - int a = i * stride + j; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - - int corners[6] = { a, d, c, c, b, a }; - if ( ( i + j ) & 1 ) - { - int flipped[6] = { a, d, b, d, c, b }; - memcpy( corners, flipped, sizeof( corners ) ); - } - - for ( int k = 0; k < 6; k += 3 ) - { - builder->indices[builder->indexCount++] = corners[k]; - builder->indices[builder->indexCount++] = mirror ? corners[k + 2] : corners[k + 1]; - builder->indices[builder->indexCount++] = mirror ? corners[k + 1] : corners[k + 2]; - } - } - } -} - -static float EvaluateRail( float z, float cellZ ) -{ - if ( z < -0.5f * cellZ ) - { - return 0.0f; - } - - return z < 0.5f * cellZ ? GHOST_RAIL_HEIGHT : -GHOST_RAIL_SKIRT; -} - -static void AddMesh( GhostCollisionsData* data, MeshBuilder* builder, bool frictionless ) -{ - b3MeshDef meshDef = { 0 }; - meshDef.vertices = builder->vertices; - meshDef.indices = builder->indices; - meshDef.vertexCount = builder->vertexCount; - meshDef.triangleCount = builder->indexCount / 3; - meshDef.weldVertices = true; - meshDef.weldTolerance = 0.001f; - meshDef.identifyEdges = true; - - b3MeshData* mesh = b3CreateMesh( &meshDef, NULL, 0 ); - data->meshes[data->meshCount++] = mesh; - - b3Vec3 scale = data->settings.mirror ? (b3Vec3){ -1.0f, 1.0f, 1.0f } : b3Vec3_one; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( frictionless ) - { - shapeDef.baseMaterial.friction = 0.0f; - } - b3CreateMeshShape( data->groundId, &shapeDef, mesh, scale ); - - builder->vertexCount = 0; - builder->indexCount = 0; -} - -// The bodies holding height field shapes must go first -static void DestroyGhostGroundData( GhostCollisionsData* data ) -{ - for ( int i = 0; i < data->meshCount; ++i ) - { - b3DestroyMesh( data->meshes[i] ); - data->meshes[i] = NULL; - } - data->meshCount = 0; - - for ( int i = 0; i < data->heightFieldCount; ++i ) - { - b3DestroyHeightField( data->heightFields[i] ); - data->heightFields[i] = NULL; - } - data->heightFieldCount = 0; -} - -static void PushProfile( GhostCollisionsData* data, float x, float y ) -{ - if ( data->profileCount < GHOST_MAX_PROFILE_POINTS ) - { - data->profile[data->profileCount++] = (b3Vec2){ x, y }; - } -} - -// The profile is a function of x, a vertical step has two points at the same x -static float EvaluateProfile( const GhostCollisionsData* data, float x ) -{ - const b3Vec2* profile = data->profile; - int count = data->profileCount; - for ( int k = 0; k + 1 < count; ++k ) - { - if ( x <= profile[k + 1].x ) - { - float dx = profile[k + 1].x - profile[k].x; - float t = dx > 0.0f ? b3ClampFloat( ( x - profile[k].x ) / dx, 0.0f, 1.0f ) : 1.0f; - return profile[k].y + t * ( profile[k + 1].y - profile[k].y ); - } - } - - return profile[count - 1].y; -} - -static int GetCellCount( float length, float cellSize ) -{ - return b3MaxInt( 1, (int)ceilf( length / cellSize - 0.01f ) ); -} - -// Samples the profile on a grid spanning x0 to x1. The mirror samples in reverse and turns the body half -// way around y, so the world geometry is the same either way. All tiles of a scene share one height range -// so their quantized heights line up at a seam. -static void AddHeightField( b3WorldId worldId, GhostCollisionsData* data, float x0, float x1, int cellCountX, float halfWidth, - int cellCountZ, bool frictionless ) -{ - float minHeight = FLT_MAX; - float maxHeight = -FLT_MAX; - for ( int k = 0; k < data->profileCount; ++k ) - { - minHeight = b3MinFloat( minHeight, data->profile[k].y ); - maxHeight = b3MaxFloat( maxHeight, data->profile[k].y ); - } - - bool mirror = data->settings.mirror; - int countX = cellCountX + 1; - int countZ = cellCountZ + 1; - float cellX = ( x1 - x0 ) / (float)cellCountX; - float cellZ = 2.0f * halfWidth / (float)cellCountZ; - - // The mirror turns the body half way around y, which also reverses z - bool rail = data->settings.scene == e_ghostRail; - float* heights = malloc( countX * countZ * sizeof( float ) ); - for ( int row = 0; row < countZ; ++row ) - { - float z = mirror ? halfWidth - cellZ * (float)row : -halfWidth + cellZ * (float)row; - for ( int column = 0; column < countX; ++column ) - { - float x = mirror ? x1 - cellX * (float)column : x0 + cellX * (float)column; - heights[row * countX + column] = rail ? EvaluateRail( z, cellZ ) : EvaluateProfile( data, x ); - } - } - - b3HeightFieldDef def = { 0 }; - def.heights = heights; - def.scale = (b3Vec3){ cellX, 1.0f, cellZ }; - def.countX = countX; - def.countZ = countZ; - def.globalMinimumHeight = minHeight; - def.globalMaximumHeight = maxHeight; - b3HeightFieldData* heightField = b3CreateHeightField( &def ); - free( heights ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - if ( mirror ) - { - bodyDef.position = (b3Pos){ x1, 0.0f, halfWidth }; - bodyDef.rotation = (b3Quat){ { 0.0f, 1.0f, 0.0f }, 0.0f }; - } - else - { - bodyDef.position = (b3Pos){ x0, 0.0f, -halfWidth }; - } - - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - if ( frictionless ) - { - shapeDef.baseMaterial.friction = 0.0f; - } - b3CreateHeightFieldShape( bodyId, &shapeDef, heightField ); - - data->heightFields[data->heightFieldCount] = heightField; - data->heightBodyIds[data->heightFieldCount] = bodyId; - data->heightFieldCount += 1; -} - -void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data ) -{ - if ( B3_IS_NON_NULL( data->groundId ) ) - { - b3DestroyBody( data->groundId ); - } - - for ( int i = 0; i < data->heightFieldCount; ++i ) - { - b3DestroyBody( data->heightBodyIds[i] ); - } - - DestroyGhostGroundData( data ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - data->groundId = b3CreateBody( worldId, &bodyDef ); - - const GhostSettings* settings = &data->settings; - bool rail = settings->scene == e_ghostRail; - float h = rail ? GHOST_RAIL_HALF_LENGTH : GHOST_HALF_LENGTH; - data->profileCount = 0; - data->halfLength = h; - data->halfWidth = rail ? GHOST_RAIL_HALF_WIDTH : GHOST_HALF_WIDTH; - - switch ( settings->scene ) - { - case e_ghostConcave: - { - float slope = 8.0f * B3_PI / 180.0f; - PushProfile( data, -h, h * tanf( slope ) ); - PushProfile( data, 0.0f, 0.0f ); - PushProfile( data, h, 0.0f ); - } - break; - - case e_ghostCliff: - // A height field cannot hold a vertical wall, so there the drop takes one cell - PushProfile( data, -h, 3.0f ); - PushProfile( data, 0.0f, 3.0f ); - PushProfile( data, settings->heightField ? settings->cellSize : 0.0f, 0.0f ); - PushProfile( data, h, 0.0f ); - break; - - case e_ghostCrest: - PushProfile( data, -h, 0.0f ); - PushProfile( data, -10.0f, 0.0f ); - PushProfile( data, 0.0f, 1.0f ); - PushProfile( data, 10.0f, 0.0f ); - PushProfile( data, h, 0.0f ); - break; - - case e_ghostBumps: - // Gentle folds of a few degrees, the range that only flat edge suppression misses - for ( int i = 0; i <= 80; ++i ) - { - float x = -h + 0.5f * (float)i; - float y = x < -10.0f ? 0.0f : 0.05f * ( 1.0f - cosf( B3_PI * x ) ); - PushProfile( data, x, y ); - } - break; - - case e_ghostInternal: - // PEEL's curved mesh: 32 rows 4 m apart, each step up 1.25 times the last, sliding toward +x - for ( int i = 31; i >= 0; --i ) - { - PushProfile( data, 62.0f - 4.0f * (float)i, 1.0f + 0.1f * powf( 1.25f, (float)i ) ); - } - break; - - case e_ghostChamfer: - // Flat tops at y = 0 with a chamfered notch every meter. A body crossing a notch overhangs both - // chamfers while its bottom rests on the convex top edges. - PushProfile( data, -h, 0.0f ); - for ( int i = 0; i < 30; ++i ) - { - float x = -8.0f + (float)i; - PushProfile( data, x, 0.0f ); - PushProfile( data, x + GHOST_CHAMFER_WIDTH, -GHOST_CHAMFER_DROP ); - PushProfile( data, x + 2.0f * GHOST_CHAMFER_WIDTH, -GHOST_CHAMFER_DROP ); - PushProfile( data, x + 3.0f * GHOST_CHAMFER_WIDTH, 0.0f ); - } - PushProfile( data, h, 0.0f ); - break; - - case e_ghostRail: - // Cross section in zy, from the floor up the inner wall, over the top and down the outer skirt - PushProfile( data, -data->halfWidth, 0.0f ); - PushProfile( data, 0.0f, 0.0f ); - PushProfile( data, 0.0f, GHOST_RAIL_HEIGHT ); - PushProfile( data, GHOST_RAIL_THICKNESS, GHOST_RAIL_HEIGHT ); - PushProfile( data, GHOST_RAIL_THICKNESS, -GHOST_RAIL_SKIRT ); - break; - - case e_ghostBeams: - { - // A height field cannot hold the vertical pit walls, so there each wall takes one cell - float wallRun = settings->heightField ? GHOST_CHAMFER_WIDTH : 0.0f; - PushProfile( data, -h, 0.0f ); - for ( int i = 0; i + 1 < GHOST_BEAM_COUNT; ++i ) - { - float pitLeft = GHOST_BEAM_START_X + GHOST_BEAM_PITCH * (float)i + GHOST_BEAM_WIDTH; - float pitRight = GHOST_BEAM_START_X + GHOST_BEAM_PITCH * (float)( i + 1 ); - PushProfile( data, pitLeft - GHOST_CHAMFER_WIDTH, 0.0f ); - PushProfile( data, pitLeft, -GHOST_CHAMFER_DROP ); - PushProfile( data, pitLeft + wallRun, -GHOST_BEAM_PIT_DEPTH ); - PushProfile( data, pitRight - wallRun, -GHOST_BEAM_PIT_DEPTH ); - PushProfile( data, pitRight, -GHOST_CHAMFER_DROP ); - PushProfile( data, pitRight + GHOST_CHAMFER_WIDTH, 0.0f ); - } - PushProfile( data, h, 0.0f ); - } - break; - - default: - PushProfile( data, -h, 0.0f ); - PushProfile( data, h, 0.0f ); - break; - } - - MeshBuilder builder = { 0 }; - float cellSize = settings->cellSize; - bool mirror = settings->mirror; - float groundHalfWidth = data->halfWidth; - int cellCountZ = GetCellCount( 2.0f * groundHalfWidth, cellSize ); - - if ( settings->heightField ) - { - if ( settings->scene == e_ghostInternal ) - { - // One grid line per profile row, as in the mesh - PeelPreset preset = s_peelPresets[settings->peelPreset]; - int zCount = preset.columnCount - 1; - data->halfWidth = 20.0f * preset.scaleX * (float)zCount; - float x0 = data->profile[0].x; - float x1 = data->profile[data->profileCount - 1].x; - AddHeightField( worldId, data, x0, x1, data->profileCount - 1, data->halfWidth, zCount, true ); - - b3BoxHull box = b3MakeOffsetBoxHull( 140.0f, 1.0f, 30.0f, ( b3Vec3 ){ 65.0f, -1.0f, 0.0f } ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( data->groundId, &shapeDef, &box.base ); - } - else if ( settings->scene == e_ghostChamfer || settings->scene == e_ghostBeams ) - { - // One cell per chamfer puts every notch vertex on the grid - AddHeightField( worldId, data, -h, h, GetCellCount( 2.0f * h, GHOST_CHAMFER_WIDTH ), groundHalfWidth, cellCountZ, - false ); - } - else - { - AddHeightField( worldId, data, -h, h, GetCellCount( 2.0f * h, cellSize ), groundHalfWidth, cellCountZ, false ); - } - } - else if ( settings->scene == e_ghostRail ) - { - AddRail( &builder, data->profile, data->profileCount, h, cellSize, mirror ); - AddMesh( data, &builder, false ); - } - else if ( settings->scene == e_ghostInternal ) - { - // The mesh has no friction and the ground plane under it does, as in PEEL - PeelPreset preset = s_peelPresets[settings->peelPreset]; - int zCount = preset.columnCount - 1; - float halfWidth = 20.0f * preset.scaleX * (float)zCount; - AddGrid( &builder, data->profile, data->profileCount, halfWidth, zCount, false, mirror ); - data->halfWidth = halfWidth; - AddMesh( data, &builder, true ); - - b3BoxHull box = b3MakeOffsetBoxHull( 140.0f, 1.0f, 30.0f, ( b3Vec3 ){ 65.0f, -1.0f, 0.0f } ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( data->groundId, &shapeDef, &box.base ); - } - else - { - AddStrip( &builder, data->profile, data->profileCount, cellSize, cellSize, mirror ); - AddMesh( data, &builder, false ); - } - - free( builder.vertices ); - free( builder.indices ); -} - -void LaunchGhostBody( b3WorldId worldId, GhostCollisionsData* data ) -{ - if ( B3_IS_NON_NULL( data->bodyId ) ) - { - b3DestroyBody( data->bodyId ); - } - - const GhostSettings* settings = &data->settings; - - // PEEL drops its bodies from rest, sized in meters rather than tenths - bool peel = settings->scene == e_ghostInternal; - float boxHalf = peel ? 1.0f : 0.2f; - float capsuleRadius = peel ? 1.0f : 0.2f; - float capsuleHalf = peel ? 2.0f : 0.4f; - float sphereRadius = peel ? 1.0f : 0.25f; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.enableContactRecycling = false; - b3Quat yaw = b3MakeQuatFromAxisAngle( b3Vec3_axisY, settings->yaw * B3_PI / 180.0f ); - - if ( peel ) - { - bodyDef.position = (b3Pos){ s_peelPresets[settings->peelPreset].startZ, 80.0f, 0.0f }; - bodyDef.rotation = yaw; - } - else if ( settings->scene == e_ghostRail ) - { - // Dropped across the rail top, pitched so a box face sweeps into the rail edge at an angle. The real - // contact is edge on edge and perpendicular to the rail, a face normal there leans along the rail - // and catches the body. Found in the Conveyor Circuit sample. - b3Quat pitch = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 60.0f * B3_PI / 180.0f ); - bodyDef.position = (b3Pos){ GHOST_RAIL_START_X, GHOST_RAIL_HEIGHT + 0.45f, -0.15f }; - bodyDef.rotation = b3MulQuat( pitch, yaw ); - bodyDef.linearVelocity = (b3Vec3){ settings->speed, 0.0f, 0.0f }; - } - else - { - int segment = 0; - for ( int k = 0; k + 1 < data->profileCount; ++k ) - { - if ( data->profile[k].x <= GHOST_START_X && GHOST_START_X < data->profile[k + 1].x ) - { - segment = k; - break; - } - } - - b3Vec2 a = data->profile[segment]; - b3Vec2 b = data->profile[segment + 1]; - float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) ); - b3Vec2 d = { ( b.x - a.x ) / length, ( b.y - a.y ) / length }; - b3Vec2 n = { -d.y, d.x }; - float y = a.y + ( GHOST_START_X - a.x ) * d.y / d.x; - - float lift = boxHalf; - if ( settings->body == e_ghostSphere ) - { - lift = sphereRadius; - } - else if ( settings->body == e_ghostVCapsule ) - { - lift = capsuleHalf + capsuleRadius; - } - lift += 0.01f; - - bodyDef.position = (b3Pos){ GHOST_START_X + lift * n.x, y + lift * n.y, 0.0f }; - b3Quat slope = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, atan2f( d.y, d.x ) ); - bodyDef.rotation = b3MulQuat( slope, yaw ); - bodyDef.linearVelocity = (b3Vec3){ settings->speed * d.x, settings->speed * d.y, 0.0f }; - } - - bodyDef.motionLocks.angularX = settings->fixedRotation; - bodyDef.motionLocks.angularY = settings->fixedRotation; - bodyDef.motionLocks.angularZ = settings->fixedRotation; - bodyDef.enableSleep = false; - bodyDef.name = "slider"; - data->bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = settings->friction; - shapeDef.enableSpeculativeContact = settings->speculative; - - switch ( settings->body ) - { - case e_ghostBox: - { - b3BoxHull box = peel ? b3MakeBoxHull( 1.0f, 1.0f, 1.0f ) : b3MakeBoxHull( 0.4f, 0.2f, 0.4f ); - data->shapeId = b3CreateHullShape( data->bodyId, &shapeDef, &box.base ); - } - break; - - case e_ghostHCapsule: - { - b3Capsule capsule = { { 0.0f, 0.0f, -capsuleHalf }, { 0.0f, 0.0f, capsuleHalf }, capsuleRadius }; - data->shapeId = b3CreateCapsuleShape( data->bodyId, &shapeDef, &capsule ); - } - break; - - case e_ghostVCapsule: - { - b3Capsule capsule = { { 0.0f, -capsuleHalf, 0.0f }, { 0.0f, capsuleHalf, 0.0f }, capsuleRadius }; - data->shapeId = b3CreateCapsuleShape( data->bodyId, &shapeDef, &capsule ); - } - break; - - case e_ghostSphere: - { - b3Sphere sphere = { b3Vec3_zero, sphereRadius }; - data->shapeId = b3CreateSphereShape( data->bodyId, &shapeDef, &sphere ); - } - break; - - default: - data->shapeId = b3CreateHullShape( data->bodyId, &shapeDef, peel ? data->peelCylinder : data->cylinder ); - break; - } - - data->contactBounds = b3Shape_GetAABB( data->shapeId ); - data->runGhostCount = 0; - data->runSteps = 0; -} - -GhostCollisionsData CreateGhostCollisions( b3WorldId worldId, GhostSettings settings ) -{ - GhostCollisionsData data = { 0 }; - data.settings = settings; - data.cylinder = b3CreateCylinder( 0.4f, 0.4f, -0.2f, 16 ); - data.peelCylinder = b3CreateCylinder( 2.0f, 1.0f, -1.0f, 16 ); - data.groundId = b3_nullBodyId; - data.bodyId = b3_nullBodyId; - data.shapeId = b3_nullShapeId; - - CreateGhostGround( worldId, &data ); - LaunchGhostBody( worldId, &data ); - return data; -} - -static float SegmentAngle( const GhostCollisionsData* data, int k ) -{ - b3Vec2 a = data->profile[k]; - b3Vec2 b = data->profile[k + 1]; - return atan2f( b.x - a.x, a.y - b.y ); -} - -// The normal points from the ground to the body. A hull face can be the reference face, so any -// normal within the span of face normals under the body is valid. At a side edge of the ground the -// normal may also lean off that side, perpendicular to the edge. -static bool IsGhost( const GhostCollisionsData* data, b3Vec3 normal, float xMin, float xMax, float zMin, float zMax ) -{ - float tolerance = 5.0f * B3_PI / 180.0f; - float sinTolerance = sinf( tolerance ); - if ( b3AbsFloat( normal.z ) > sinTolerance ) - { - // The manifold must reach the side it leans off - float margin = 0.05f; - bool atSide = normal.z < 0.0f ? zMin < -data->halfWidth + margin : zMax > data->halfWidth - margin; - if ( atSide == false ) - { - return true; - } - } - - // A normal leaning off a side has a short projection, which leaves little room to lean along the edge - float planarLength = sqrtf( normal.x * normal.x + normal.y * normal.y ); - if ( planarLength < sinTolerance ) - { - return false; - } - - GhostBody body = data->settings.body; - bool chamferScene = data->settings.scene == e_ghostChamfer || data->settings.scene == e_ghostBeams; - bool chamferHull = chamferScene && ( body == e_ghostBox || body == e_ghostCylinder ); - - float lower = B3_PI; - float upper = -B3_PI; - int segmentCount = data->profileCount - 1; - for ( int k = 0; k < segmentCount; ++k ) - { - float x0 = b3MinFloat( data->profile[k].x, data->profile[k + 1].x ); - float x1 = b3MaxFloat( data->profile[k].x, data->profile[k + 1].x ); - if ( x1 < xMin || xMax < x0 ) - { - continue; - } - - // A flat hull bottom resting on the top edges must keep its own normal, so for a hull only the tops - // count. A round body's normal comes from the closest ground feature, which can be a top edge. - if ( chamferHull && ( data->profile[k].y < 0.0f || data->profile[k + 1].y < 0.0f ) ) - { - continue; - } - - float angle = SegmentAngle( data, k ); - lower = b3MinFloat( lower, angle ); - upper = b3MaxFloat( upper, angle ); - } - - float angle = atan2f( normal.y, normal.x ); - float deviation = b3MaxFloat( lower - angle, angle - upper ); - if ( deviation <= 0.0f ) - { - return false; - } - - // Measure the lean outside the span in 3D so a steep side normal is not over counted - return deviation > 0.5f * B3_PI || planarLength * sinf( deviation ) > sinTolerance; -} - -int UpdateGhostCollisions( b3WorldId worldId, GhostCollisionsData* data, GhostReport* reports, int capacity ) -{ - b3Pos center = b3Body_GetWorldCenter( data->bodyId ); - bool done = center.x > data->halfLength - 1.0f || center.y < -3.0f; - if ( data->settings.scene == e_ghostInternal ) - { - // Run out onto the ground plane, or give up on a body knocked off the side - done = center.x > 100.0f || center.y < -3.0f || data->runSteps > 900; - } - - if ( done ) - { - data->runCount += 1; - LaunchGhostBody( worldId, data ); - center = b3Body_GetWorldCenter( data->bodyId ); - } - - data->runSteps += 1; - - b3AABB bounds = data->contactBounds; - float xMin = (float)bounds.lowerBound.x - 0.1f; - float xMax = (float)bounds.upperBound.x + 0.1f; - data->contactBounds = b3Shape_GetAABB( data->shapeId ); - - int ghostCount = 0; - b3ContactData contacts[8]; - int contactCount = b3Body_GetContactData( data->bodyId, contacts, 8 ); - for ( int i = 0; i < contactCount; ++i ) - { - bool bodyIsA = B3_ID_EQUALS( contacts[i].shapeIdA, data->shapeId ); - b3ShapeId otherId = bodyIsA ? contacts[i].shapeIdB : contacts[i].shapeIdA; - b3ShapeType otherType = b3Shape_GetType( otherId ); - if ( otherType != b3_meshShape && otherType != b3_heightShape ) - { - continue; - } - - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - const b3Manifold* manifold = contacts[i].manifolds + j; - - // Speculative points that never pushed are harmless - float impulse = 0.0f; - for ( int k = 0; k < manifold->pointCount; ++k ) - { - impulse += manifold->points[k].totalNormalImpulse; - } - - if ( manifold->pointCount == 0 || impulse <= 0.0f ) - { - continue; - } - - float zMin = FLT_MAX; - float zMax = -FLT_MAX; - for ( int k = 0; k < manifold->pointCount; ++k ) - { - b3Vec3 anchor = bodyIsA ? manifold->points[k].anchorA : manifold->points[k].anchorB; - float z = (float)center.z + anchor.z; - zMin = b3MinFloat( zMin, z ); - zMax = b3MaxFloat( zMax, z ); - } - - b3Vec3 normal = bodyIsA ? b3Neg( manifold->normal ) : manifold->normal; - if ( data->settings.scene == e_ghostRail ) - { - // The rail is the same all along x, so no valid normal leans along it - if ( b3AbsFloat( normal.x ) <= sinf( 5.0f * B3_PI / 180.0f ) ) - { - continue; - } - } - else if ( IsGhost( data, normal, xMin, xMax, zMin, zMax ) == false ) - { - continue; - } - - if ( ghostCount < capacity ) - { - b3Vec3 anchor = bodyIsA ? manifold->points[0].anchorA : manifold->points[0].anchorB; - reports[ghostCount] = (GhostReport){ - .point = b3OffsetPos( center, anchor ), - .normal = normal, - .separation = manifold->points[0].separation, - .impulse = impulse, - }; - } - - ghostCount += 1; - } - } - - data->runGhostCount += ghostCount; - data->ghostCount += ghostCount; - return ghostCount; -} - -void DestroyGhostCollisions( GhostCollisionsData* data ) -{ - DestroyGhostGroundData( data ); - b3DestroyHull( data->cylinder ); - b3DestroyHull( data->peelCylinder ); - data->cylinder = NULL; - data->peelCylinder = NULL; -} diff --git a/shared/ghost_collisions.h b/shared/ghost_collisions.h deleted file mode 100644 index 8c6448a..0000000 --- a/shared/ghost_collisions.h +++ /dev/null @@ -1,147 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT -#pragma once - -#include "box3d/collision.h" -#include "box3d/id.h" -#include "box3d/math_functions.h" - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Ghost collision scenes, shared by the Mesh / Ghost Collisions sample and the headless ghost scan. -// Each ground is a profile in the xy-plane extruded along z and finely tessellated, so a sliding -// body crosses many internal edges. A manifold that pushes on the body is a ghost when its normal -// points outside the span of face normals under the body. Those are the ones that block or launch -// a body. - -// A conveyor side rail along x, the floor is on the -z side -#define GHOST_RAIL_HEIGHT 0.35f -#define GHOST_RAIL_THICKNESS 0.08f - -// The beam ghost depends on how the body phases with the pits, at the default speed the box misses it -#define GHOST_BEAM_SPEED 8.0f - -typedef enum GhostScene -{ - e_ghostFlat, - e_ghostConcave, - e_ghostCliff, - e_ghostCrest, - e_ghostBumps, - e_ghostInternal, - e_ghostChamfer, - e_ghostRail, - e_ghostBeams, - e_ghostSceneCount -} GhostScene; - -typedef enum GhostBody -{ - e_ghostBox, - e_ghostHCapsule, - e_ghostVCapsule, - e_ghostSphere, - e_ghostCylinder, - e_ghostBodyCount -} GhostBody; - -// Mesh variants of the PEEL InternalEdges presets -#define GHOST_PEEL_PRESET_COUNT 4 - -// Chamfer has the longest profile -#define GHOST_MAX_PROFILE_POINTS 128 - -extern const char* g_ghostSceneNames[e_ghostSceneCount]; -extern const char* g_ghostBodyNames[e_ghostBodyCount]; -extern const char* g_ghostPeelPresetNames[GHOST_PEEL_PRESET_COUNT]; - -typedef struct GhostSettings -{ - GhostScene scene; - GhostBody body; - int peelPreset; - bool mirror; - - // Build the ground from height fields instead of meshes. Each height field is its own shape. - bool heightField; - - float cellSize; - float speed; - - // Degrees - float yaw; - - float friction; - bool fixedRotation; - bool speculative; -} GhostSettings; - -GhostSettings GetDefaultGhostSettings( void ); - -typedef struct GhostReport -{ - b3Pos point; - b3Vec3 normal; - float separation; - float impulse; -} GhostReport; - -typedef struct GhostCollisionsData -{ - GhostSettings settings; - b3Vec2 profile[GHOST_MAX_PROFILE_POINTS]; - int profileCount; - - // The ground spans x in [-halfLength, halfLength] and z in [-halfWidth, halfWidth] - float halfLength; - float halfWidth; - b3MeshData* meshes[2]; - int meshCount; - - // A height field shape has no local transform, so each one gets its own static body - b3HeightFieldData* heightFields[2]; - b3BodyId heightBodyIds[2]; - int heightFieldCount; - b3HullData* cylinder; - b3HullData* peelCylinder; - b3BodyId groundId; - b3BodyId bodyId; - b3ShapeId shapeId; - - // Body bounds at the start of the step, where the contacts were computed. A fast body can cross a fold - // within a step, so the bounds after the step can miss the face a contact came from. - b3AABB contactBounds; - - // Steps in the current run - int runSteps; - - // Completed runs, each ending when the body reaches the end or falls off - int runCount; - - int runGhostCount; - int ghostCount; -} GhostCollisionsData; - -// Creates the ground and launches the body -GhostCollisionsData CreateGhostCollisions( b3WorldId worldId, GhostSettings settings ); - -// Rebuild the ground after a scene, preset, mirror, height field or cell size change. Relaunch after this. -void CreateGhostGround( b3WorldId worldId, GhostCollisionsData* data ); - -// Launch a new body from the start, after a body, speed, yaw, friction or rotation change -void LaunchGhostBody( b3WorldId worldId, GhostCollisionsData* data ); - -// Call after each world step. Relaunches a body that finished its run, then counts the ghost -// manifolds on the body. Returns the ghost count for this step and writes up to capacity reports. -int UpdateGhostCollisions( b3WorldId worldId, GhostCollisionsData* data, GhostReport* reports, int capacity ); - -void DestroyGhostCollisions( GhostCollisionsData* data ); - -#ifdef __cplusplus -} -#endif diff --git a/shared/ghost_oracle.c b/shared/ghost_oracle.c deleted file mode 100644 index 5b257fe..0000000 --- a/shared/ghost_oracle.c +++ /dev/null @@ -1,779 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "ghost_oracle.h" - -#include "ghost_collisions.h" - -#include "box3d/box3d.h" -#include "box3d/constants.h" - -#include -#include -#include - -const char* g_oracleSceneNames[e_oracleSceneCount] = { - "flat", "fan", "crest", "valley", "ridge", "saddle ridge", "rail", "wave", -}; - -// The wave scene is the largest, 169 vertices and 288 triangles -#define ORACLE_MAX_VERTICES 256 -#define ORACLE_MAX_INDICES ( 3 * 512 ) -#define ORACLE_MAX_MANIFOLDS 128 - -typedef struct OracleBuilder -{ - b3Vec3 vertices[ORACLE_MAX_VERTICES]; - int32_t indices[ORACLE_MAX_INDICES]; - int vertexCount; - int indexCount; -} OracleBuilder; - -static int AddVertex( OracleBuilder* builder, b3Vec3 vertex ) -{ - B3_ASSERT( builder->vertexCount < ORACLE_MAX_VERTICES ); - if ( builder->vertexCount == ORACLE_MAX_VERTICES ) - { - return 0; - } - - builder->vertices[builder->vertexCount] = vertex; - return builder->vertexCount++; -} - -// Winds the triangle to face the given direction -static void AddTriangle( OracleBuilder* builder, int a, int b, int c, b3Vec3 facing ) -{ - B3_ASSERT( builder->indexCount + 3 <= ORACLE_MAX_INDICES ); - if ( builder->indexCount + 3 > ORACLE_MAX_INDICES ) - { - return; - } - - b3Vec3 va = builder->vertices[a]; - b3Vec3 normal = b3Cross( b3Sub( builder->vertices[b], va ), b3Sub( builder->vertices[c], va ) ); - if ( b3Dot( normal, facing ) < 0.0f ) - { - int temp = b; - b = c; - c = temp; - } - - builder->indices[builder->indexCount++] = a; - builder->indices[builder->indexCount++] = b; - builder->indices[builder->indexCount++] = c; -} - -typedef float OracleHeightFcn( float x, float z ); - -// Up facing grid with alternating diagonals -static void BuildGrid( OracleBuilder* builder, int countX, int countZ, float cellSize, OracleHeightFcn* height ) -{ - float x0 = -0.5f * cellSize * countX; - float z0 = -0.5f * cellSize * countZ; - int base = builder->vertexCount; - for ( int k = 0; k <= countZ; ++k ) - { - for ( int i = 0; i <= countX; ++i ) - { - float x = x0 + cellSize * i; - float z = z0 + cellSize * k; - AddVertex( builder, (b3Vec3){ x, height( x, z ), z } ); - } - } - - int stride = countX + 1; - for ( int k = 0; k < countZ; ++k ) - { - for ( int i = 0; i < countX; ++i ) - { - int a = base + k * stride + i; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - if ( ( i + k ) & 1 ) - { - AddTriangle( builder, a, d, b, b3Vec3_axisY ); - AddTriangle( builder, b, d, c, b3Vec3_axisY ); - } - else - { - AddTriangle( builder, a, d, c, b3Vec3_axisY ); - AddTriangle( builder, a, c, b, b3Vec3_axisY ); - } - } - } -} - -static float FlatHeight( float x, float z ) -{ - (void)x; - (void)z; - return 0.0f; -} - -static float CrestHeight( float x, float z ) -{ - (void)z; - return -0.26795f * fabsf( x ); -} - -static float ValleyHeight( float x, float z ) -{ - (void)z; - return 0.26795f * fabsf( x ); -} - -static float RidgeHeight( float x, float z ) -{ - (void)z; - return -fabsf( x ); -} - -// libm trig differs in the last bit between platforms, which would make each a different mesh -static float WaveHeight( float x, float z ) -{ - float s1 = b3ComputeCosSin( 2.3f * x + 0.4f ).sine; - float c1 = b3ComputeCosSin( 1.7f * z ).cosine; - float s2 = b3ComputeCosSin( 4.1f * z - 1.3f * x ).sine; - return 0.12f * s1 * c1 + 0.05f * s2; -} - -static void BuildFan( OracleBuilder* builder ) -{ - int center = AddVertex( builder, b3Vec3_zero ); - for ( int i = 0; i < 6; ++i ) - { - b3CosSin cs = b3ComputeCosSin( ( i + 0.5f ) * B3_PI / 3.0f ); - AddVertex( builder, (b3Vec3){ 2.0f * cs.cosine, 0.0f, 2.0f * cs.sine } ); - } - - for ( int i = 0; i < 6; ++i ) - { - AddTriangle( builder, center, 1 + i, 1 + ( i + 1 ) % 6, b3Vec3_axisY ); - } -} - -// A ridge along x running into a rising wall, so the ridge end is a saddle vertex -static void BuildSaddleRidge( OracleBuilder* builder ) -{ - float xs[3] = { -2.0f, 0.0f, 1.0f }; - float crests[3] = { -0.004f, 0.0f, 0.3f }; - float sides[3] = { -0.7f, -0.7f, -0.4f }; - for ( int i = 0; i < 3; ++i ) - { - AddVertex( builder, (b3Vec3){ xs[i], sides[i], -1.0f } ); - AddVertex( builder, (b3Vec3){ xs[i], crests[i], 0.0f } ); - AddVertex( builder, (b3Vec3){ xs[i], sides[i], 1.0f } ); - } - - for ( int i = 0; i < 2; ++i ) - { - for ( int k = 0; k < 2; ++k ) - { - int a = 3 * i + k; - AddTriangle( builder, a, a + 1, a + 3, b3Vec3_axisY ); - AddTriangle( builder, a + 3, a + 1, a + 4, b3Vec3_axisY ); - } - } -} - -// A wall facing -z meeting a narrow top at a convex edge, like a conveyor side rail -static void BuildRail( OracleBuilder* builder ) -{ - float sectionZ[4] = { 0.0f, 0.0f, GHOST_RAIL_THICKNESS, GHOST_RAIL_THICKNESS }; - float sectionY[4] = { 0.0f, GHOST_RAIL_HEIGHT, GHOST_RAIL_HEIGHT, 0.0f }; - int columns = 5; - for ( int row = 0; row < 4; ++row ) - { - for ( int column = 0; column < columns; ++column ) - { - AddVertex( builder, (b3Vec3){ -0.5f + 0.25f * column, sectionY[row], sectionZ[row] } ); - } - } - - b3Vec3 facings[3] = { { 0.0f, 0.0f, -1.0f }, b3Vec3_axisY, b3Vec3_axisZ }; - for ( int row = 0; row < 3; ++row ) - { - for ( int column = 0; column < columns - 1; ++column ) - { - int a = columns * row + column; - int b = a + 1; - int c = a + columns + 1; - int d = a + columns; - if ( ( row + column ) & 1 ) - { - AddTriangle( builder, a, d, b, facings[row] ); - AddTriangle( builder, d, c, b, facings[row] ); - } - else - { - AddTriangle( builder, a, d, c, facings[row] ); - AddTriangle( builder, c, b, a, facings[row] ); - } - } - } -} - -b3MeshData* CreateOracleMesh( OracleScene scene ) -{ - static OracleBuilder builder; - builder.vertexCount = 0; - builder.indexCount = 0; - - switch ( scene ) - { - case e_oracleFlat: - BuildGrid( &builder, 6, 6, 0.5f, FlatHeight ); - break; - case e_oracleFan: - BuildFan( &builder ); - break; - case e_oracleCrest: - BuildGrid( &builder, 8, 4, 0.5f, CrestHeight ); - break; - case e_oracleValley: - BuildGrid( &builder, 8, 4, 0.5f, ValleyHeight ); - break; - case e_oracleRidge: - BuildGrid( &builder, 6, 4, 0.5f, RidgeHeight ); - break; - case e_oracleSaddleRidge: - BuildSaddleRidge( &builder ); - break; - case e_oracleRail: - BuildRail( &builder ); - break; - case e_oracleWave: - BuildGrid( &builder, 12, 12, 0.25f, WaveHeight ); - break; - default: - return NULL; - } - - b3MeshDef def = { 0 }; - def.vertices = builder.vertices; - def.stride = sizeof( b3Vec3 ); - def.vertexCount = builder.vertexCount; - def.indices = builder.indices; - def.triangleCount = builder.indexCount / 3; - def.weldVertices = true; - def.weldTolerance = 0.001f; - def.identifyEdges = true; - return b3CreateMesh( &def, NULL, 0 ); -} - -// Local state and 24 bits per draw, which the global 15 bit generator in utils.h does not give -typedef struct OracleRandom -{ - uint32_t state; -} OracleRandom; - -static float RandomUnit( OracleRandom* random ) -{ - uint32_t x = random->state; - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - random->state = x; - return (float)( x >> 8 ) / 16777216.0f; -} - -static float RandomRange( OracleRandom* random, float lower, float upper ) -{ - return lower + ( upper - lower ) * RandomUnit( random ); -} - -static b3Vec3 RandomDirection( OracleRandom* random ) -{ - for ( int i = 0; i < 16; ++i ) - { - b3Vec3 v = { RandomRange( random, -1.0f, 1.0f ), RandomRange( random, -1.0f, 1.0f ), - RandomRange( random, -1.0f, 1.0f ) }; - float lengthSquared = b3LengthSquared( v ); - if ( 0.01f < lengthSquared && lengthSquared <= 1.0f ) - { - return b3MulSV( 1.0f / sqrtf( lengthSquared ), v ); - } - } - - return b3Vec3_axisY; -} - -// Direction within the given angle of the axis -static b3Vec3 RandomTilt( OracleRandom* random, b3Vec3 axis, float maxAngle ) -{ - b3Vec3 perp = b3Cross( axis, RandomDirection( random ) ); - float length = b3Length( perp ); - if ( length < 1.0e-4f ) - { - return axis; - } - - perp = b3MulSV( 1.0f / length, perp ); - b3CosSin cs = b3ComputeCosSin( RandomRange( random, 0.0f, maxAngle ) ); - return b3Add( b3MulSV( cs.cosine, axis ), b3MulSV( cs.sine, perp ) ); -} - -static bool CollectPair( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ) -{ - OracleReference* reference = context; - - // A truncated union would misjudge the pose - B3_ASSERT( reference->pairCount < ORACLE_MAX_TRIANGLES ); - if ( reference->pairCount == ORACLE_MAX_TRIANGLES ) - { - return false; - } - - OraclePair* pair = reference->pairs + reference->pairCount; - *pair = (OraclePair){ 0 }; - pair->triangleIndex = triangleIndex; - pair->vertices[0] = a; - pair->vertices[1] = b; - pair->vertices[2] = c; - pair->faceNormal = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) ); - pair->owned = true; - pair->dominatedBy = -1; - reference->pairCount += 1; - return true; -} - -// From Real-time Collision Detection, p141 -static b3Vec3 ClosestPointOnTriangle( b3Vec3 p, b3Vec3 a, b3Vec3 b, b3Vec3 c ) -{ - b3Vec3 ab = b3Sub( b, a ); - b3Vec3 ac = b3Sub( c, a ); - b3Vec3 ap = b3Sub( p, a ); - float d1 = b3Dot( ab, ap ); - float d2 = b3Dot( ac, ap ); - if ( d1 <= 0.0f && d2 <= 0.0f ) - { - return a; - } - - b3Vec3 bp = b3Sub( p, b ); - float d3 = b3Dot( ab, bp ); - float d4 = b3Dot( ac, bp ); - if ( d3 >= 0.0f && d4 <= d3 ) - { - return b; - } - - float vc = d1 * d4 - d3 * d2; - if ( vc <= 0.0f && d1 >= 0.0f && d3 <= 0.0f ) - { - return b3MulAdd( a, d1 / ( d1 - d3 ), ab ); - } - - b3Vec3 cp = b3Sub( p, c ); - float d5 = b3Dot( ab, cp ); - float d6 = b3Dot( ac, cp ); - if ( d6 >= 0.0f && d5 <= d6 ) - { - return c; - } - - float vb = d5 * d2 - d1 * d6; - if ( vb <= 0.0f && d2 >= 0.0f && d6 <= 0.0f ) - { - return b3MulAdd( a, d2 / ( d2 - d6 ), ac ); - } - - float va = d3 * d6 - d5 * d4; - if ( va <= 0.0f && ( d4 - d3 ) >= 0.0f && ( d5 - d6 ) >= 0.0f ) - { - float w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) ); - return b3MulAdd( b, w, b3Sub( c, b ) ); - } - - float denom = 1.0f / ( va + vb + vc ); - float v = vb * denom; - float w = vc * denom; - return b3Add( a, b3Add( b3MulSV( v, ab ), b3MulSV( w, ac ) ) ); -} - -// The closest pair of each nearby triangle and the union distance -static float ComputePairs( OracleReference* reference, const b3MeshData* mesh, const b3HullData* hull, b3Transform transform ) -{ - reference->pairCount = 0; - - b3AABB bounds = b3ComputeHullAABB( hull, transform ); - // Collided points can be well past the speculative distance and the proximal test looks around them - float margin = 0.25f; - bounds.lowerBound = b3Sub( bounds.lowerBound, (b3Vec3){ margin, margin, margin } ); - bounds.upperBound = b3Add( bounds.upperBound, (b3Vec3){ margin, margin, margin } ); - - b3Mesh meshShape = { .data = (b3MeshData*)mesh, .scale = b3Vec3_one }; - b3QueryMesh( &meshShape, bounds, CollectPair, reference ); - - float minDistance = FLT_MAX; - for ( int i = 0; i < reference->pairCount; ++i ) - { - OraclePair* pair = reference->pairs + i; - b3DistanceInput input = { 0 }; - input.proxyA = (b3ShapeProxy){ pair->vertices, 3, 0.0f }; - input.proxyB = (b3ShapeProxy){ b3GetHullPoints( hull ), hull->vertexCount, 0.0f }; - input.transform = transform; - input.useRadii = false; - b3SimplexCache cache = { 0 }; - b3DistanceOutput output = b3ShapeDistance( &input, &cache, NULL, 0 ); - pair->meshPoint = output.pointA; - pair->hullPoint = output.pointB; - pair->normal = output.normal; - pair->distance = output.distance; - - if ( output.distance < minDistance ) - { - minDistance = output.distance; - reference->closestMeshPoint = output.pointA; - reference->closestHullPoint = output.pointB; - } - } - - reference->distance = minDistance; - return minDistance; -} - -#define ORACLE_CONTAIN_TOLERANCE 1.0e-4f - -static bool TriangleContains( const OraclePair* pair, b3Vec3 point ) -{ - b3Vec3 closest = ClosestPointOnTriangle( point, pair->vertices[0], pair->vertices[1], pair->vertices[2] ); - return b3DistanceSquared( closest, point ) < ORACLE_CONTAIN_TOLERANCE * ORACLE_CONTAIN_TOLERANCE; -} - -// A closest pair is a contact of the union unless a closer triangle also contains its mesh point -static void ComputeOwnership( OracleReference* reference ) -{ - // Ties along shared features differ only by GJK round off - float tieTolerance = 0.02f * B3_LINEAR_SLOP; - - for ( int i = 0; i < reference->pairCount; ++i ) - { - OraclePair* pair = reference->pairs + i; - pair->owned = true; - pair->dominatedBy = -1; - for ( int j = 0; j < reference->pairCount; ++j ) - { - const OraclePair* other = reference->pairs + j; - if ( j == i || other->distance >= pair->distance - tieTolerance ) - { - continue; - } - - if ( TriangleContains( other, pair->meshPoint ) ) - { - pair->owned = false; - pair->dominatedBy = other->triangleIndex; - break; - } - } - } -} - -// On success the reference holds the closest pairs of the returned pose -static bool MakeOraclePose( OracleReference* reference, const b3MeshData* mesh, OracleScene scene, int index, b3BoxHull* box, - b3Transform* transform ) -{ - OracleRandom random = { 0x9E3779B9u ^ ( 2654435761u * (uint32_t)( index + 1 ) ) ^ ( 40503u * (uint32_t)scene ) }; - for ( int i = 0; i < 4; ++i ) - { - RandomUnit( &random ); - } - - const b3Vec3* vertices = b3GetMeshVertices( mesh ); - const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh ); - int triangleIndex = (int)( RandomUnit( &random ) * mesh->triangleCount ); - triangleIndex = triangleIndex < mesh->triangleCount ? triangleIndex : mesh->triangleCount - 1; - b3Vec3 a = vertices[triangles[triangleIndex].index1]; - b3Vec3 b = vertices[triangles[triangleIndex].index2]; - b3Vec3 c = vertices[triangles[triangleIndex].index3]; - b3Vec3 faceNormal = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) ); - - float u = RandomUnit( &random ); - float v = RandomUnit( &random ); - if ( u + v > 1.0f ) - { - u = 1.0f - u; - v = 1.0f - v; - } - - b3Vec3 target = b3Add( a, b3Add( b3MulSV( u, b3Sub( b, a ) ), b3MulSV( v, b3Sub( c, a ) ) ) ); - - float hx = RandomRange( &random, 0.05f, 0.4f ); - float hy = RandomRange( &random, 0.05f, 0.4f ); - float hz = RandomRange( &random, 0.05f, 0.4f ); - *box = b3MakeBoxHull( hx, hy, hz ); - - // Half the boxes rest nearly flat on the face, where parallel faces make ties - b3Quat rotation; - if ( RandomUnit( &random ) < 0.5f ) - { - b3Vec3 up = RandomTilt( &random, faceNormal, 0.2f ); - b3Quat align = b3ComputeQuatBetweenUnitVectors( b3Vec3_axisY, up ); - b3Quat yaw = b3MakeQuatFromAxisAngle( b3Vec3_axisY, RandomRange( &random, -B3_PI, B3_PI ) ); - rotation = b3MulQuat( align, yaw ); - } - else - { - b3Vec3 axis = RandomDirection( &random ); - rotation = b3MakeQuatFromAxisAngle( axis, RandomRange( &random, -B3_PI, B3_PI ) ); - } - - b3Vec3 approach = RandomTilt( &random, faceNormal, 1.0f ); - - // Put the hull support point against the target - const b3Vec3* hullPoints = b3GetHullPoints( &box->base ); - b3Vec3 localDirection = b3InvRotateVector( rotation, b3Neg( approach ) ); - b3Vec3 support = hullPoints[0]; - for ( int i = 1; i < box->base.vertexCount; ++i ) - { - if ( b3Dot( hullPoints[i], localDirection ) > b3Dot( support, localDirection ) ) - { - support = hullPoints[i]; - } - } - - float linearSlop = B3_LINEAR_SLOP; - float gap = linearSlop * ( 0.2f + 3.4f * RandomUnit( &random ) * RandomUnit( &random ) ); - b3Transform pose = { b3Sub( target, b3RotateVector( rotation, support ) ), rotation }; - pose.p = b3MulAdd( pose.p, gap, approach ); - - for ( int iteration = 0; iteration < 20; ++iteration ) - { - *transform = pose; - - float distance = ComputePairs( reference, mesh, &box->base, pose ); - if ( reference->pairCount == 0 ) - { - return false; - } - - if ( distance <= 0.0f ) - { - pose.p = b3MulAdd( pose.p, 2.0f * linearSlop, approach ); - continue; - } - - if ( b3AbsFloat( distance - gap ) < 0.05f * linearSlop ) - { - return true; - } - - b3Vec3 direction = b3Normalize( b3Sub( reference->closestHullPoint, reference->closestMeshPoint ) ); - pose.p = b3MulAdd( pose.p, gap - distance, direction ); - } - - *transform = pose; - float distance = ComputePairs( reference, mesh, &box->base, pose ); - return reference->pairCount > 0 && ORACLE_MIN_DISTANCE <= distance && distance <= B3_SPECULATIVE_DISTANCE; -} - -// Smallest squared sine between the normal and the face normal of a triangle that contains the mesh -// point and faces the normal. FLT_MAX if there is no such triangle. -static float FacingSineSquared( const OracleReference* reference, b3Vec3 meshPoint, b3Vec3 normal ) -{ - float best = FLT_MAX; - for ( int i = 0; i < reference->pairCount; ++i ) - { - const OraclePair* pair = reference->pairs + i; - if ( b3Dot( pair->faceNormal, normal ) <= 0.0f || TriangleContains( pair, meshPoint ) == false ) - { - continue; - } - - best = b3MinFloat( best, b3LengthSquared( b3Cross( pair->faceNormal, normal ) ) ); - } - - return best; -} - -// The mesh point is the closest union point to a point a little way out along the normal -static bool IsProximalNormal( const OracleReference* reference, b3Vec3 meshPoint, b3Vec3 normal, float sinTolerance ) -{ - float probeDistance = 0.01f; - b3Vec3 probe = b3MulAdd( meshPoint, probeDistance, normal ); - float bestDistanceSquared = FLT_MAX; - b3Vec3 best = meshPoint; - for ( int i = 0; i < reference->pairCount; ++i ) - { - const OraclePair* pair = reference->pairs + i; - b3Vec3 closest = ClosestPointOnTriangle( probe, pair->vertices[0], pair->vertices[1], pair->vertices[2] ); - float distanceSquared = b3DistanceSquared( closest, probe ); - if ( distanceSquared < bestDistanceSquared ) - { - bestDistanceSquared = distanceSquared; - best = closest; - } - } - - float offset = sinTolerance * probeDistance; - return b3DistanceSquared( best, meshPoint ) < offset * offset; -} - -// Collides the hull and judges every manifold against the reference -static void JudgeCollision( OracleResult* result, const OracleReference* reference, const b3MeshData* mesh, - const b3HullData* hull, b3Transform transform, bool handleGhosts ) -{ - result->pointCount = 0; - result->ghostCount = 0; - result->missed = false; - - b3Manifold manifolds[ORACLE_MAX_MANIFOLDS]; - b3Mesh meshShape = { .data = (b3MeshData*)mesh, .scale = b3Vec3_one }; - int manifoldCount = - b3CollideMeshAndHull( manifolds, ORACLE_MAX_MANIFOLDS, &meshShape, hull, transform, true, handleGhosts ); - B3_ASSERT( manifoldCount < ORACLE_MAX_MANIFOLDS ); - - // Clustering merges manifolds whose normals are within about 5 degrees - float sinTolerance = 0.1f; - float minSeparation = FLT_MAX; - for ( int i = 0; i < manifoldCount; ++i ) - { - const b3Manifold* manifold = manifolds + i; - int firstPoint = result->pointCount; - for ( int j = 0; j < manifold->pointCount; ++j ) - { - B3_ASSERT( result->pointCount < ORACLE_MAX_POINTS ); - if ( result->pointCount == ORACLE_MAX_POINTS ) - { - break; - } - - const b3ManifoldPoint* manifoldPoint = manifold->points + j; - OraclePoint* point = result->points + result->pointCount; - point->point = manifoldPoint->anchorA; - point->meshPoint = manifoldPoint->anchorA; - point->normal = manifold->normal; - point->separation = manifoldPoint->separation + B3_MESH_REST_OFFSET; - point->triangleIndex = manifoldPoint->triangleIndex; - point->verdict = e_oracleGhost; - result->pointCount += 1; - - minSeparation = b3MinFloat( minSeparation, point->separation ); - - const OraclePair* pair = NULL; - for ( int k = 0; k < reference->pairCount; ++k ) - { - if ( reference->pairs[k].triangleIndex == point->triangleIndex ) - { - pair = reference->pairs + k; - break; - } - } - - // The reference bounds contain the collider bounds, so every collided triangle has a pair - B3_ASSERT( pair != NULL ); - if ( pair == NULL ) - { - continue; - } - - b3Vec3 meshPoint = - ClosestPointOnTriangle( point->point, pair->vertices[0], pair->vertices[1], pair->vertices[2] ); - point->meshPoint = meshPoint; - - // A proximal normal also has to be in front of a face here, or an inverted face normal would pass - float sineSquared = FacingSineSquared( reference, meshPoint, point->normal ); - if ( sineSquared < sinTolerance * sinTolerance ) - { - point->verdict = e_oracleFace; - } - else if ( sineSquared < FLT_MAX && IsProximalNormal( reference, meshPoint, point->normal, sinTolerance ) ) - { - point->verdict = e_oracleFeature; - } - } - - float deepest = FLT_MAX; - for ( int j = firstPoint; j < result->pointCount; ++j ) - { - deepest = b3MinFloat( deepest, result->points[j].separation ); - } - - bool valid = false; - for ( int j = firstPoint; j < result->pointCount; ++j ) - { - const OraclePoint* point = result->points + j; - if ( point->separation <= deepest + B3_LINEAR_SLOP && point->verdict != e_oracleGhost ) - { - valid = true; - break; - } - } - - for ( int j = firstPoint; j < result->pointCount && valid; ++j ) - { - OraclePoint* point = result->points + j; - point->verdict = point->verdict == e_oracleGhost ? e_oracleShared : point->verdict; - } - - if ( valid == false && result->pointCount > firstPoint ) - { - result->ghostCount += 1; - } - } - - // The union closest pair has to be represented. SAT separation is a lower bound on distance. - float linearSlop = B3_LINEAR_SLOP; - float distance = reference->distance; - if ( distance < B3_SPECULATIVE_DISTANCE - linearSlop && minSeparation > distance + linearSlop ) - { - result->missed = true; - } -} - -bool EvaluateOraclePose( OraclePose* pose, const b3MeshData* mesh, OracleScene scene, int index ) -{ - if ( MakeOraclePose( &pose->reference, mesh, scene, index, &pose->box, &pose->transform ) == false ) - { - return false; - } - - B3_ASSERT( pose->reference.distance >= ORACLE_MIN_DISTANCE ); - ComputeOwnership( &pose->reference ); - - const b3HullData* hull = &pose->box.base; - JudgeCollision( &pose->raw, &pose->reference, mesh, hull, pose->transform, false ); - JudgeCollision( &pose->handled, &pose->reference, mesh, hull, pose->transform, true ); - return true; -} - -bool IsOracleCullingMiss( const OraclePose* pose ) -{ - return pose->handled.missed && pose->raw.missed == false; -} - -OracleScan ScanGhostOracle( const b3MeshData* mesh, OracleScene scene, int poseCount ) -{ - static OraclePose pose; - OracleScan scan = { 0 }; - scan.firstGhost = -1; - scan.firstMissed = -1; - - for ( int i = 0; i < poseCount; ++i ) - { - if ( EvaluateOraclePose( &pose, mesh, scene, i ) == false ) - { - continue; - } - - scan.validCount += 1; - scan.rawGhostPoses += pose.raw.ghostCount > 0 ? 1 : 0; - - if ( pose.handled.ghostCount > 0 ) - { - scan.ghostPoses += 1; - scan.firstGhost = scan.firstGhost < 0 ? i : scan.firstGhost; - } - - if ( IsOracleCullingMiss( &pose ) ) - { - scan.missedPoses += 1; - scan.firstMissed = scan.firstMissed < 0 ? i : scan.firstMissed; - } - } - - return scan; -} diff --git a/shared/ghost_oracle.h b/shared/ghost_oracle.h deleted file mode 100644 index 04b3a50..0000000 --- a/shared/ghost_oracle.h +++ /dev/null @@ -1,168 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT -#pragma once - -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Separated-pose oracle for mesh ghost handling. With the hull clear of the mesh the union of the -// triangles is the reference surface, and none of the Voronoi logic under test is needed to judge a -// contact against it. -// -// A normal is valid at a mesh location when the union has it there: the face normal of a triangle -// containing the location, or a proximal normal, meaning the location is the closest union point to a -// point a little way out along the normal. That second test gives the convex edge wedge and the vertex -// cone exactly, and nothing at a concave crease beyond the two face normals. A manifold shares one normal -// across its points, so it is a ghost when the normal is valid at none of its points within linear slop of -// its deepest. -// -// The contacts the union itself has are the local minima of the distance between the hull and the -// union. A triangle's closest pair (GJK) is one unless a triangle that also contains its mesh point is -// closer to the hull. The distance to a triangle is convex over the triangle, so that test is exact. The -// union closest pair must be represented by a collided point, otherwise the contact was missed. - -typedef enum OracleScene -{ - e_oracleFlat, - e_oracleFan, - e_oracleCrest, - e_oracleValley, - e_oracleRidge, - e_oracleSaddleRidge, - e_oracleRail, - e_oracleWave, - e_oracleSceneCount -} OracleScene; - -extern const char* g_oracleSceneNames[e_oracleSceneCount]; - -#define ORACLE_MAX_TRIANGLES 256 -#define ORACLE_MAX_POINTS 128 - -// Poses per scene in the unit test, and in the sample scan so the two report the same counts -#define ORACLE_SCAN_POSES 500 - -typedef enum OracleVerdict -{ - // Face normal of a triangle containing the point - e_oracleFace, - - // Proximal normal at an edge or vertex - e_oracleFeature, - - // Not valid here, but valid at a deep point of the same manifold - e_oracleShared, - - // Point of a manifold whose normal is valid at none of its deep points - e_oracleGhost, -} OracleVerdict; - -typedef struct OraclePair -{ - int triangleIndex; - b3Vec3 vertices[3]; - b3Vec3 faceNormal; - b3Vec3 meshPoint; - b3Vec3 hullPoint; - b3Vec3 normal; - float distance; - bool owned; - - // Triangle index of a closer triangle containing the mesh point, or -1 - int dominatedBy; -} OraclePair; - -// The union of the triangles near the hull. Depends only on the pose, not on the collider. -typedef struct OracleReference -{ - // Distance between the hull and the mesh - float distance; - b3Vec3 closestMeshPoint; - b3Vec3 closestHullPoint; - - OraclePair pairs[ORACLE_MAX_TRIANGLES]; - int pairCount; -} OracleReference; - -typedef struct OraclePoint -{ - b3Vec3 point; - - // Closest point on the point's triangle - b3Vec3 meshPoint; - b3Vec3 normal; - - // Geometric separation, without the mesh rest offset the collider subtracts - float separation; - int triangleIndex; - OracleVerdict verdict; -} OraclePoint; - -// The collider output judged against the reference -typedef struct OracleResult -{ - OraclePoint points[ORACLE_MAX_POINTS]; - int pointCount; - - // Ghost manifolds - int ghostCount; - - // The union closest pair has no collided point - bool missed; -} OracleResult; - -typedef struct OraclePose -{ - b3BoxHull box; - b3Transform transform; - OracleReference reference; - - // Collided without and with ghost handling - OracleResult raw; - OracleResult handled; -} OraclePose; - -typedef struct OracleScan -{ - // Separated poses - int validCount; - - // Poses with a ghost manifold, without and with ghost handling - int rawGhostPoses; - int ghostPoses; - - // Poses where ghost handling lost the closest pair - int missedPoses; - - // Pose indices, -1 for none - int firstGhost; - int firstMissed; -} OracleScan; - -// The poses keep the hull separated by at least this much, where the closest direction is well defined -#define ORACLE_MIN_DISTANCE ( 0.1f * B3_LINEAR_SLOP ) - -// Caller destroys with b3DestroyMesh -b3MeshData* CreateOracleMesh( OracleScene scene ); - -// Deterministic random box and pose for the scene and index, separated from the mesh by -// [ORACLE_MIN_DISTANCE, B3_SPECULATIVE_DISTANCE], collided and judged with and without ghost handling. -// Returns false if no separated pose was found, in which case the reference and results mean nothing. -bool EvaluateOraclePose( OraclePose* pose, const b3MeshData* mesh, OracleScene scene, int index ); - -// A miss counts against ghost handling only when the collider represents the closest pair without it -bool IsOracleCullingMiss( const OraclePose* pose ); - -// Poses [0, poseCount) of the scene -OracleScan ScanGhostOracle( const b3MeshData* mesh, OracleScene scene, int poseCount ); - -#ifdef __cplusplus -} -#endif diff --git a/shared/human.c b/shared/human.c index 1e37931..e6d3964 100644 --- a/shared/human.c +++ b/shared/human.c @@ -36,7 +36,8 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bodyDef.userData = userData; b3ShapeDef shapeDef = b3DefaultShapeDef(); - float defaultDensity = shapeDef.density; + // shapeDef.friction = 0.2f; + shapeDef.baseMaterial.rollingResistance = 0.2f; b3HexColor shirtColor = b3_colorMediumTurquoise; b3HexColor pantColor = b3_colorDodgerBlue; @@ -45,20 +46,19 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio { Bone* bone = human->bones + bone_pelvis; + bone->parentIndex = -1; bodyDef.name = "pelvis"; - bone->referenceFrame = (b3Transform){ { 0.000000f, 0.996219f, -0.023868f }, { { 1.000000f, 0.000000f, 0.000000f }, 0.000000f } }; + bone->referenceFrame = (b3Transform){ { 0.0f, 0.932087f, -0.051708f }, { { 0.739169f, 0.0f, 0.0f }, 0.673520f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.07f, 0.0f, -0.08f }, { -0.07f, 0.0f, -0.08f }, 0.13f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? pantColor : 0; - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.040000f, 0.000001f, 0.000000f }, { -0.040000f, -0.000001f, 0.000000f }, 0.150000f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); } @@ -67,74 +67,117 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bone->parentIndex = bone_pelvis; bodyDef.name = "spine_01"; - bone->referenceFrame = (b3Transform){ { 0.000000f, 1.017288f, -0.024882f }, { { 1.000000f, 0.000000f, 0.000000f }, 0.000000f } }; + bone->referenceFrame = (b3Transform){ { 0.0f, 1.113505f, -0.03481f }, { { 0.739973f, 0.0f, 0.0f }, 0.672637f } }; + bodyDef.rotation = bone->referenceFrame.q; + bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); + // bodyDef.type = b3_staticBody; + bone->bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + + b3Capsule capsule = { { 0.06f, -0.0f, -0.052264f }, { -0.06f, 0.0f, -0.052264f }, 0.12f }; + shapeDef.filter.groupIndex = -groupIndex; + shapeDef.baseMaterial.customColor = colorize ? shirtColor : 0; + b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); + + bone->jointType = b3_sphericalJoint; + bone->localFrameA = (b3Transform){ { 0.000000, 0.000000, -0.182204 }, { { -0.999999, 0.000000, -0.000000 }, 0.001194 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.000000, -0.007736 }, { { -1.000000, 0.000000, -0.000000 }, 0.000000 } }; + bone->swingLimit = 25.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -15.0f * B3_DEG_TO_RAD, 15.0f * B3_DEG_TO_RAD }; + } + + { + Bone* bone = human->bones + bone_spine_02; + bone->parentIndex = bone_spine_01; + + // bodyDef.name = "spine_02"; + bone->referenceFrame = (b3Transform){ { 0.0f, 1.194336f, -0.027087f }, { { 0.703611f, 0.0f, 0.0f }, 0.710586f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); - shapeDef.filter.groupIndex = -groupIndex; + b3Capsule capsule = { { 0.08f, -0.015133f, -0.091801f }, { -0.08f, -0.015133f, -0.091801f }, 0.10f }; + shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? shirtColor : 0; - - shapeDef.baseMaterial.friction = 0.5f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.029876f, -0.146581f, 0.006260f }, { -0.029876f, -0.146574f, 0.006260f }, 0.145663f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { 0.000000f, -0.021069f, 0.001014f }, { { -0.642737f, 0.000000f, 0.000000f }, -0.766087f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.707107f, 0.000000f, 0.000000f }, -0.707107f } }; - bone->swingLimit = 35.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -17.5f * B3_DEG_TO_RAD, 17.5f * B3_DEG_TO_RAD }; + bone->localFrameA = + (b3Transform){ { 0.000000, -0.000000, -0.088935 }, { { -0.998619, -0.000000, 0.000000 }, -0.052540 } }; + bone->localFrameB = (b3Transform){ { -0.000000, 0.000000, -0.008199 }, { { -1.000000, 0.000000, -0.000000 }, 0.000000 } }; + bone->swingLimit = 25.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -15.0f * B3_DEG_TO_RAD, 15.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_spine_03; - bone->parentIndex = bone_spine_01; + bone->parentIndex = bone_spine_02; bodyDef.name = "spine_03"; - bone->referenceFrame = (b3Transform){ { 0.000000f, 1.267766f, -0.022320f }, { { 1.000000f, 0.000000f, 0.000000f }, 0.000000f } }; + bone->referenceFrame = + (b3Transform){ { -0.0f, 1.31043f, -0.028232f }, { { 0.669856f, 0.000001f, -0.000001f }, 0.742491f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.11f, -0.039753f, -0.13f }, { -0.11f, -0.039753f, -0.13f }, 0.145f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? shirtColor : 0; - - shapeDef.baseMaterial.friction = 0.5f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.063996f, -0.117434f, -0.040199f }, { -0.063996f, -0.117432f, -0.040199f }, 0.165004f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { 0.000000f, -0.250478f, -0.002562f }, { { -0.642766f, 0.000000f, 0.000000f }, -0.766063f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.707107f, 0.000000f, 0.000000f }, -0.707107f } }; - bone->swingLimit = 35.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -17.5f * B3_DEG_TO_RAD, 17.5f * B3_DEG_TO_RAD }; + bone->localFrameA = + (b3Transform){ { -0.000000, 0.000000, -0.124298 }, { { -0.998921, 0.000001, -0.000001 }, -0.046434 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.000000, 0.000000 }, { { -1.000000, 0.000000, -0.000001 }, 0.000000 } }; + bone->swingLimit = 15.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -10.0f * B3_DEG_TO_RAD, 10.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_neck; bone->parentIndex = bone_spine_03; - bodyDef.name = "neck_01"; - bone->referenceFrame = (b3Transform){ { 0.000000f, 1.498783f, 0.024462f }, { { 0.987879f, 0.000000f, 0.000000f }, 0.155228f } }; + bodyDef.name = "neck"; + bone->referenceFrame = (b3Transform){ { 0.0f, 1.575582f, -0.055837f }, { { 0.879922f, 0.0f, 0.0f }, 0.475118f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { -0.000001f, -0.0f, -0.02f }, { 0.0f, -0.005f, -0.08f }, 0.07f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? skinColor : 0; - - shapeDef.baseMaterial.friction = 0.2f; - shapeDef.baseMaterial.rollingResistance = 0.05f; - b3Capsule head = { { 0.000000f, -0.212340f, 0.000000f }, { 0.000000f, -0.087340f, 0.000000f }, 0.110000f }; - b3CreateCapsuleShape( bone->bodyId, &shapeDef, &head ); + b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { 0.000000f, -0.231017f, -0.046781f }, { { -0.516157f, -0.000002f, 0.000003f }, -0.856494f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.707108f, -0.000002f, 0.000002f }, -0.707106f } }; - bone->swingLimit = 30.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -17.5f * B3_DEG_TO_RAD, 17.5f * B3_DEG_TO_RAD }; + bone->localFrameA = (b3Transform){ { 0.000001, -0.000259, -0.266585 }, { { -0.942192, -0.000001, 0.000000 }, 0.335074 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.000000, 0.000000 }, { { -1.000000, 0.000000, -0.000001 }, 0.000000 } }; + bone->swingLimit = 45.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -15.0f * B3_DEG_TO_RAD, 15.0f * B3_DEG_TO_RAD }; + bone->jointFriction = 0.8f; + } + + { + Bone* bone = human->bones + bone_head; + bone->parentIndex = bone_neck; + + bodyDef.name = "head"; + bone->referenceFrame = (b3Transform){ { 0.0f, 1.653348f, -0.003241f }, { { 0.750288f, 0.0f, 0.0f }, 0.661111f } }; + bodyDef.rotation = bone->referenceFrame.q; + bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); + bone->bodyId = b3CreateBody( worldId, &bodyDef ); + + b3Capsule capsule = { { -0.000001f, 0.016892f, -0.05869f }, { 0.0f, -0.003629f, -0.115072f }, 0.0975f }; + shapeDef.filter.groupIndex = 0; + shapeDef.baseMaterial.customColor = colorize ? skinColor : 0; + b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); + + bone->jointType = b3_sphericalJoint; + bone->localFrameA = + (b3Transform){ { 0.000000, 0.001321, -0.093873 }, { { -0.974301, -0.000000, -0.000000 }, -0.225251 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.001268, -0.005104 }, { { -1.000000, 0.000000, -0.00000 }, 0.000000 } }; + bone->swingLimit = 15.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -15.0f * B3_DEG_TO_RAD, 15.0f * B3_DEG_TO_RAD }; + bone->jointFriction = 0.4f; } { @@ -142,24 +185,22 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bone->parentIndex = bone_pelvis; bodyDef.name = "thigh_l"; - bone->referenceFrame = (b3Transform){ { 0.092175f, 0.971562f, -0.011177f }, { { 0.471412f, 0.529510f, -0.499888f }, -0.497495f } }; + bone->referenceFrame = + (b3Transform){ { 0.090416f, 0.986104f, -0.035090f }, { { -0.703287f, -0.070715f, 0.053866f }, 0.705327f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.023719f, 0.006008f, -0.039068f }, { -0.064492f, -0.004664f, -0.424718f }, 0.09f }; shapeDef.filter.groupIndex = -groupIndex; shapeDef.baseMaterial.customColor = colorize ? pantColor : 0; - - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { -0.047269f, 0.000001f, 0.000000f }, { -0.379769f, 0.000005f, 0.000000f }, 0.091539f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { 0.092175f, 0.024656f, -0.012691f }, { { -0.460186f, -0.365368f, -0.637662f }, 0.498118f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.499997f, -0.500003f, 0.500002f }, 0.499998f } }; - bone->swingLimit = 30.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -10.0f * B3_DEG_TO_RAD, 10.0f * B3_DEG_TO_RAD }; + bone->localFrameA = (b3Transform){ { 0.05f, 0.011537f, -0.055325f }, { { -0.714896, -0.022305, -0.698361 }, -0.026790 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.002064, 0.758987, 0.017046 }, 0.650880 } }; + bone->swingLimit = 10.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -60.0f * B3_DEG_TO_RAD, 40.0f * B3_DEG_TO_RAD }; } { @@ -167,28 +208,21 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bone->parentIndex = bone_thigh_l; bodyDef.name = "calf_l"; - bone->referenceFrame = (b3Transform){ { 0.118720f, 0.534541f, -0.035362f }, { { 0.521188f, 0.480597f, -0.546380f }, -0.445935f } }; + bone->referenceFrame = + (b3Transform){ { 0.101198f, 0.527027f, -0.037374f }, { { -0.653328f, -0.066860f, 0.058582f }, 0.751838f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.001778f, 0.0f, 0.009841f }, { -0.078577f, 0.014707f, -0.41816f }, 0.075f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? pantColor : 0; - - shapeDef.baseMaterial.friction = 0.1f; - shapeDef.baseMaterial.rollingResistance = 0.0f; - b3Capsule shin = { { -0.445000f, 0.000001f, 0.000000f }, { 0.005000f, -0.000001f, 0.000000f }, 0.080000f }; - b3CreateCapsuleShape( bone->bodyId, &shapeDef, &shin ); - - shapeDef.density = 0.5f * defaultDensity; - b3Capsule foot = { { -0.456371f, 0.129321f, 0.000013f }, { -0.359977f, 0.014394f, 0.000013f }, 0.070000f }; - b3CreateCapsuleShape( bone->bodyId, &shapeDef, &foot ); - shapeDef.density = defaultDensity; + b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_revoluteJoint; - bone->localFrameA = (b3Transform){ { -0.438494f, -0.000175f, 0.000000f }, { { 0.344866f, -0.938652f, 0.000002f }, -0.000008f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.008182f, -0.999967f, 0.000001f }, -0.000007f } }; - bone->twistLimit = (b3Vec2){ -30.0f * B3_DEG_TO_RAD, 30.0f * B3_DEG_TO_RAD }; + bone->localFrameA = (b3Transform){ { -0.069989, 0.000253, -0.453844 }, { { -0.000677, 0.760087, 0.105674 }, 0.641171 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.044589, 0.765540, 0.053368 }, 0.639619 } }; + bone->twistLimit = (b3Vec2){ -5.0f * B3_DEG_TO_RAD, 45.0f * B3_DEG_TO_RAD }; } { @@ -196,24 +230,22 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bone->parentIndex = bone_pelvis; bodyDef.name = "thigh_r"; - bone->referenceFrame = (b3Transform){ { -0.092175f, 0.971562f, -0.011177f }, { { -0.497495f, 0.499888f, 0.529510f }, -0.471412f } }; + bone->referenceFrame = + (b3Transform){ { -0.090416f, 0.986104f, -0.03509f }, { { -0.703287f, 0.070715f, -0.053865f }, 0.705326f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { -0.023719f, 0.006008f, -0.039068f }, { 0.064492f, -0.004664f, -0.424718f }, 0.09f }; shapeDef.filter.groupIndex = -groupIndex; shapeDef.baseMaterial.customColor = colorize ? pantColor : 0; - - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.047269f, -0.000001f, 0.000000f }, { 0.379769f, -0.000005f, 0.000000f }, 0.092587f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { -0.092175f, 0.024656f, -0.012691f }, { { 0.380666f, 0.491846f, 0.488644f }, -0.611889f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.500002f, 0.499998f, -0.499998f }, 0.500002f } }; - bone->swingLimit = 30.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -10.0f * B3_DEG_TO_RAD, 10.0f * B3_DEG_TO_RAD }; + bone->localFrameA = (b3Transform){ { -0.05, 0.011537, -0.055326 }, { { -0.039089, -0.714094, 0.043177 }, 0.697623 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { 0.758805, -0.019886, -0.651012 }, -0.001759 } }; + bone->swingLimit = 10.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -30.0f * B3_DEG_TO_RAD, 60.0f * B3_DEG_TO_RAD }; } { @@ -221,132 +253,115 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio bone->parentIndex = bone_thigh_r; bodyDef.name = "calf_r"; - bone->referenceFrame = (b3Transform){ { -0.118720f, 0.534541f, -0.035362f }, { { -0.445935f, 0.546380f, 0.480597f }, -0.521188f } }; + bone->referenceFrame = + (b3Transform){ { -0.101198f, 0.527027f, -0.037373f }, { { -0.653327f, 0.06686f, -0.058582f }, 0.751839f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { -0.001820f, 0.0f, 0.010071f }, { 0.077883f, 0.014825f, -0.418047f }, 0.075f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? pantColor : 0; - - shapeDef.baseMaterial.friction = 0.1f; - shapeDef.baseMaterial.rollingResistance = 0.0f; - b3Capsule shin = { { 0.445000f, -0.000002f, 0.000003f }, { -0.005000f, 0.000000f, 0.000003f }, 0.080000f }; - b3CreateCapsuleShape( bone->bodyId, &shapeDef, &shin ); - - shapeDef.density = 0.5f * defaultDensity; - b3Capsule foot = { { 0.369113f, -0.006830f, 0.000017f }, { 0.465507f, -0.121757f, 0.000017f }, 0.070000f }; - b3CreateCapsuleShape( bone->bodyId, &shapeDef, &foot ); - shapeDef.density = defaultDensity; + b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_revoluteJoint; - bone->localFrameA = (b3Transform){ { 0.438494f, 0.000175f, 0.000000f }, { { 0.000007f, 0.000005f, -0.344860f }, -0.938654f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { 0.000006f, 0.000005f, 0.008188f }, -0.999966f } }; - bone->twistLimit = (b3Vec2){ -30.0f * B3_DEG_TO_RAD, 30.0f * B3_DEG_TO_RAD }; + bone->localFrameA = (b3Transform){ { 0.069988, 0.000253, -0.453844 }, { { 0.760086, -0.000675, -0.641171 }, -0.105676 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { 0.765540, -0.044589, -0.639619 }, -0.053368 } }; + bone->twistLimit = (b3Vec2){ -45.0f * B3_DEG_TO_RAD, 5.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_upper_arm_l; bone->parentIndex = bone_spine_03; - bodyDef.name = "upperarm_l"; - bone->referenceFrame = (b3Transform){ { 0.185817f, 1.443630f, 0.031306f }, { { 0.560220f, -0.307179f, 0.366233f }, -0.676512f } }; + bodyDef.name = "upper_arm_l"; + bone->referenceFrame = + (b3Transform){ { 0.20378f, 1.484275f, -0.115897f }, { { 0.143082f, 0.695980f, -0.690130f }, 0.13733f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { -0.091118f, 0.037775f, 0.229719f }, 0.075f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? shirtColor : 0; - - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.296038f, 0.004386f, -0.000794f }, { -0.016086f, 0.004384f, -0.016127f }, 0.065000f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { 0.185817f, -0.175865f, -0.053625f }, { { -0.559466f, -0.213784f, -0.670199f }, 0.438323f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.500953f, -0.502617f, -0.509318f }, -0.486844f } }; - bone->swingLimit = 45.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -20.0f * B3_DEG_TO_RAD, 20.0f * B3_DEG_TO_RAD }; - bone->jointFriction = 0.8f; + bone->localFrameA = (b3Transform){ { 0.203780, -0.069369, -0.181921 }, { { -0.278486, 0.445600, -0.097014 }, 0.845266 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.000000, 0.000000 }, { { -0.201396, -0.001586, 0.901850 }, 0.382234 } }; + bone->swingLimit = 60.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -5.0f * B3_DEG_TO_RAD, 5.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_lower_arm_l; bone->parentIndex = bone_upper_arm_l; - bodyDef.name = "lowerarm_l"; - bone->referenceFrame = (b3Transform){ { 0.347683f, 1.193455f, 0.029378f }, { { 0.406736f, -0.493012f, 0.089135f }, -0.763911f } }; + bodyDef.name = "lower_arm_l"; + bone->referenceFrame = + (b3Transform){ { 0.305614f, 1.242908f, -0.117599f }, { { 0.165048f, 0.563437f, -0.802002f }, 0.109959f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { -0.142406f, 0.039392f, 0.261092f }, 0.05f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? skinColor : 0; - - shapeDef.baseMaterial.friction = 0.3f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { 0.312329f, -0.008256f, -0.016454f }, { 0.033153f, 0.008259f, -0.002741f }, 0.060000f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_revoluteJoint; - bone->localFrameA = (b3Transform){ { 0.297979f, 0.000361f, 0.000000f }, { { 0.916726f, 0.399352f, 0.000839f }, -0.011456f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { 0.999922f, -0.003857f, 0.004659f }, -0.010908f } }; - bone->twistLimit = (b3Vec2){ -35.0f * B3_DEG_TO_RAD, 35.0f * B3_DEG_TO_RAD }; - bone->jointFriction = 0.06f; + bone->localFrameA = (b3Transform){ { -0.095482, 0.039584, 0.240723 }, { { 0.512487, -0.180629, 0.839474 }, 0.003742 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { 0.503803, -0.029831, 0.858168 }, 0.094017 } }; + bone->twistLimit = (b3Vec2){ -5.0f * B3_DEG_TO_RAD, 60.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_upper_arm_r; bone->parentIndex = bone_spine_03; - bodyDef.name = "upperarm_r"; - bone->referenceFrame = (b3Transform){ { -0.185817f, 1.443630f, 0.031306f }, { { 0.676512f, 0.366233f, 0.307179f }, 0.560220f } }; + bodyDef.name = "upper_arm_r"; + bone->referenceFrame = + (b3Transform){ { -0.20378f, 1.484276f, -0.115899f }, { { 0.143083f, -0.695978f, 0.690132f }, 0.137329f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { 0.091118f, 0.037775f, 0.229718f }, 0.075f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? shirtColor : 0; - - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { -0.300237f, -0.000001f, -0.000319f }, { 0.011887f, 0.000001f, 0.015013f }, 0.065000f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_sphericalJoint; - bone->localFrameA = (b3Transform){ { -0.185817f, -0.175865f, -0.053625f }, { { 0.213793f, 0.559449f, 0.438334f }, -0.670204f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.509319f, 0.486843f, 0.500954f }, -0.502617f } }; - bone->swingLimit = 45.0f * B3_DEG_TO_RAD; - bone->twistLimit = (b3Vec2){ -20.0f * B3_DEG_TO_RAD, 20.0f * B3_DEG_TO_RAD }; - bone->jointFriction = 0.8f; + bone->localFrameA = + (b3Transform){ { -0.203779, -0.069371, -0.181922 }, { { -0.253621, -0.414842, 0.106962 }, 0.867261 } }; + bone->localFrameB = (b3Transform){ { 0.000000, 0.000000, 0.000000 }, { { -0.201397, 0.001587, -0.901850 }, 0.382233 } }; + bone->swingLimit = 60.0f * B3_DEG_TO_RAD; + bone->twistLimit = (b3Vec2){ -5.0f * B3_DEG_TO_RAD, 5.0f * B3_DEG_TO_RAD }; } { Bone* bone = human->bones + bone_lower_arm_r; bone->parentIndex = bone_upper_arm_r; - bodyDef.name = "lowerarm_r"; - bone->referenceFrame = (b3Transform){ { -0.347683f, 1.193455f, 0.029378f }, { { 0.763911f, 0.089135f, 0.493012f }, 0.406736f } }; + bodyDef.name = "lower_arm_r"; + bone->referenceFrame = + (b3Transform){ { -0.305614f, 1.242907f, -0.117599f }, { { 0.165048f, -0.563437f, 0.802002f }, 0.109959f } }; bodyDef.rotation = bone->referenceFrame.q; bodyDef.position = b3OffsetPos( position, bone->referenceFrame.p ); bone->bodyId = b3CreateBody( worldId, &bodyDef ); + b3Capsule capsule = { { 0.0f, 0.0f, 0.0f }, { 0.142406f, 0.039392f, 0.261092f }, 0.05f }; shapeDef.filter.groupIndex = 0; shapeDef.baseMaterial.customColor = colorize ? skinColor : 0; - - shapeDef.baseMaterial.friction = 0.3f; - shapeDef.baseMaterial.rollingResistance = 0.1f; - b3Capsule capsule = { { -0.312649f, -0.000003f, 0.016471f }, { -0.032986f, 0.000000f, 0.002732f }, 0.060000f }; b3CreateCapsuleShape( bone->bodyId, &shapeDef, &capsule ); bone->jointType = b3_revoluteJoint; - bone->localFrameA = (b3Transform){ { -0.297979f, -0.000361f, 0.000000f }, { { -0.405444f, 0.914059f, 0.010541f }, 0.000852f } }; - bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.002794f, 0.999936f, 0.010042f }, 0.004364f } }; - bone->twistLimit = (b3Vec2){ -35.0f * B3_DEG_TO_RAD, 35.0f * B3_DEG_TO_RAD }; - bone->jointFriction = 0.06f; + bone->localFrameA = (b3Transform){ { 0.095484, 0.039585, 0.240723 }, { { -0.180627, 0.512487, -0.003744 }, -0.839474 } }; + bone->localFrameB = (b3Transform){ { 0.0f, 0.0f, 0.0f }, { { -0.029831, 0.503803, -0.094017 }, -0.858169 } }; + bone->twistLimit = (b3Vec2){ -60.0f * B3_DEG_TO_RAD, 5.0f * B3_DEG_TO_RAD }; } + // float dampingRatio = 0.9f; for ( int i = 1; i < bone_count; ++i ) { Bone* bone = human->bones + i; @@ -397,17 +412,11 @@ void CreateHuman( Human* human, b3WorldId worldId, b3Pos position, float frictio } // Disable some collisions - human->filterJointCount = 0; b3FilterJointDef filterDef = b3DefaultFilterJointDef(); filterDef.base.bodyIdA = human->bones[bone_thigh_l].bodyId; filterDef.base.bodyIdB = human->bones[bone_thigh_r].bodyId; - human->filterJoints[human->filterJointCount++] = b3CreateFilterJoint( worldId, &filterDef ); - filterDef.base.bodyIdA = human->bones[bone_neck].bodyId; - filterDef.base.bodyIdB = human->bones[bone_upper_arm_l].bodyId; - human->filterJoints[human->filterJointCount++] = b3CreateFilterJoint( worldId, &filterDef ); - filterDef.base.bodyIdA = human->bones[bone_neck].bodyId; - filterDef.base.bodyIdB = human->bones[bone_upper_arm_r].bodyId; - human->filterJoints[human->filterJointCount++] = b3CreateFilterJoint( worldId, &filterDef ); + human->filterJoints[0] = b3CreateFilterJoint( worldId, &filterDef ); + human->filterJointCount = 1; human->isSpawned = true; } diff --git a/shared/human.h b/shared/human.h index 8ca2742..b966a2a 100644 --- a/shared/human.h +++ b/shared/human.h @@ -9,8 +9,10 @@ typedef enum BoneId { bone_pelvis, bone_spine_01, + bone_spine_02, bone_spine_03, bone_neck, + bone_head, bone_thigh_l, bone_calf_l, bone_thigh_r, @@ -38,7 +40,7 @@ typedef struct Bone int parentIndex; } Bone; -#define FILTER_JOINT_COUNT 9 +#define FILTER_JOINT_COUNT 8 // This must be zero initialized typedef struct Human diff --git a/shared/mesh_drop.c b/shared/mesh_drop.c deleted file mode 100644 index 0abdc7b..0000000 --- a/shared/mesh_drop.c +++ /dev/null @@ -1,393 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "mesh_drop.h" - -#include "box3d/box3d.h" - -#include -#include - -#define WAVE_COUNT 40 -#define WAVE_CELL_WIDTH 1.0f -#define WAVE_ROW_FREQUENCY 0.1f -#define WAVE_COLUMN_FREQUENCY 0.2f -#define WAVE_AMPLITUDE 0.5f - -// Bumps about 20 cm across, close to the curvature of the bodies, on cells a few times smaller. The cell -// width is a power of two so the mesh builder steps to the same vertices the depth tracker computes. -#define ROUGH_WAVE_COUNT 640 -#define ROUGH_CELL_WIDTH 0.03125f -#define ROUGH_ROW_FREQUENCY 4.7f -#define ROUGH_COLUMN_FREQUENCY 5.9f -#define ROUGH_AMPLITUDE 0.015f -#define DROP_SPACING 0.5f -#define DROP_HEIGHT 5.0f -#define BODY_RADIUS 0.05f -#define CAPSULE_HALF_LENGTH 0.2f - -const char* g_meshDropShapeNames[e_meshDropShapeCount] = { "box", "capsule", "cylinder", "sphere" }; - -const float g_meshDropDepthLevels[MESH_DROP_DEPTH_LEVEL_COUNT] = { 4.0f, 8.0f, 16.0f, 32.0f }; - -// Same XorShift32 and mapping as the samples, but with local state so worlds can run on many threads -static float RandomFloatRange( uint32_t* state, float lo, float hi ) -{ - uint32_t x = *state; - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - *state = x; - - int i = (int)( x % 32768 ); - float r = (float)( i & 32767 ) / 32767.0f; - return ( hi - lo ) * r + lo; -} - -static b3Vec3 RandomVec3Uniform( uint32_t* state, float lo, float hi ) -{ - b3Vec3 v; - v.x = RandomFloatRange( state, lo, hi ); - v.y = RandomFloatRange( state, lo, hi ); - v.z = RandomFloatRange( state, lo, hi ); - return v; -} - -static uint32_t HashSeed( uint32_t x ) -{ - x ^= x >> 16; - x *= 0x7feb352du; - x ^= x >> 15; - x *= 0x846ca68bu; - x ^= x >> 16; - return x != 0 ? x : 1; -} - -typedef struct WaveGrid -{ - int count; - float cellWidth; - float rowFrequency; - float columnFrequency; -} WaveGrid; - -static WaveGrid GetWaveGrid( bool rough ) -{ - _Static_assert( ROUGH_WAVE_COUNT <= MESH_DROP_MAX_WAVE_COUNT && WAVE_COUNT <= MESH_DROP_MAX_WAVE_COUNT, - "wave count exceeds the depth tracker tables" ); - - if ( rough ) - { - return (WaveGrid){ ROUGH_WAVE_COUNT, ROUGH_CELL_WIDTH, ROUGH_ROW_FREQUENCY, ROUGH_COLUMN_FREQUENCY }; - } - - return (WaveGrid){ WAVE_COUNT, WAVE_CELL_WIDTH, WAVE_ROW_FREQUENCY, WAVE_COLUMN_FREQUENCY }; -} - -static b3BoxHull MakeDropBox( void ) -{ - // The soft contact solver cannot always resolve a smaller box at 4 sub-steps, and its size gets - // close to the time of impact tolerances - return b3MakeBoxHull( 0.02f, 0.2f, 0.04f ); -} - -MeshDropSettings GetDefaultMeshDropSettings( void ) -{ - MeshDropSettings settings = { - .shape = e_meshDropBox, - .amplitude = WAVE_AMPLITUDE, - .rough = false, - .collide = false, - .soloIndex = -1, - }; - return settings; -} - -float GetMeshDropDefaultAmplitude( bool rough ) -{ - return rough ? ROUGH_AMPLITUDE : WAVE_AMPLITUDE; -} - -uint32_t GetMeshDropSeed( uint32_t baseSeed, int generation ) -{ - return HashSeed( HashSeed( baseSeed ) + (uint32_t)generation ); -} - -int GetMeshDropStepLimit( MeshDropShape shape ) -{ - return shape == e_meshDropCapsule ? 3000 : 1000; -} - -float GetMeshDropTunnelHeight( void ) -{ - return -2.0f; -} - -b3MeshData* CreateMeshDropMesh( MeshDropSettings settings ) -{ - WaveGrid grid = GetWaveGrid( settings.rough ); - return b3CreateWaveMesh( grid.count, grid.count, grid.cellWidth, settings.amplitude, grid.rowFrequency, - grid.columnFrequency ); -} - -b3HullData* CreateMeshDropCylinder( void ) -{ - return b3CreateCylinder( 0.4f, BODY_RADIUS, 0.0f, 6 ); -} - -b3BodyId CreateMeshDropGround( b3WorldId worldId, const b3MeshData* mesh, MeshDropSettings settings ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.filter.categoryBits = 1; - b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one ); - - WaveGrid grid = GetWaveGrid( settings.rough ); - float extent = 0.5f * grid.count * grid.cellWidth; - float halfHeight = 1.0f; - - b3Transform transforms[4] = { - { { 0.0f, halfHeight, -extent }, b3Quat_identity }, - { { 0.0f, halfHeight, extent }, b3Quat_identity }, - { { -extent, halfHeight, 0.0f }, b3Quat_identity }, - { { extent, halfHeight, 0.0f }, b3Quat_identity }, - }; - - for ( int i = 0; i < 4; ++i ) - { - float hx = i < 2 ? extent : 0.1f; - float hz = i < 2 ? 0.1f : extent; - b3BoxHull wallBox = b3MakeTransformedBoxHull( hx, halfHeight, hz, transforms[i] ); - b3CreateHullShape( groundId, &shapeDef, &wallBox.base ); - } - - return groundId; -} - -void CreateMeshDropBodies( b3WorldId worldId, MeshDropSettings settings, uint32_t seed, const b3HullData* cylinder, - b3BodyId* bodies ) -{ - b3BoxHull box = MakeDropBox(); - b3Capsule capsule = { { 0.0f, -CAPSULE_HALF_LENGTH, 0.0f }, { 0.0f, CAPSULE_HALF_LENGTH, 0.0f }, BODY_RADIUS }; - b3Sphere sphere = { b3Vec3_zero, BODY_RADIUS }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - bool round = settings.shape == e_meshDropCapsule || settings.shape == e_meshDropSphere; - shapeDef.baseMaterial.rollingResistance = round ? 0.4f : 0.1f; - - if ( settings.collide == false ) - { - shapeDef.filter.categoryBits = 2; - shapeDef.filter.maskBits = 1; - } - - uint32_t state = seed; - int index = 0; - for ( int i = 0; i < MESH_DROP_GRID_COUNT; ++i ) - { - for ( int j = 0; j < MESH_DROP_GRID_COUNT; ++j ) - { - // Draw for every body so a solo body gets the same velocity it has in the full drop - b3Vec3 linearVelocity = RandomVec3Uniform( &state, -1.0f, 1.0f ); - b3Vec3 angularVelocity = RandomVec3Uniform( &state, -5.0f, 5.0f ); - - if ( settings.soloIndex >= 0 && settings.soloIndex != index ) - { - bodies[index] = b3_nullBodyId; - index += 1; - continue; - } - - bodyDef.position = (b3Pos){ DROP_SPACING * ( i - 0.5f * MESH_DROP_GRID_COUNT ), DROP_HEIGHT, - DROP_SPACING * ( j - 0.5f * MESH_DROP_GRID_COUNT ) }; - bodyDef.linearVelocity = linearVelocity; - bodyDef.angularVelocity = angularVelocity; - bodyDef.userData = (void*)(intptr_t)( index + 1 ); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - switch ( settings.shape ) - { - case e_meshDropBox: - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - break; - case e_meshDropCapsule: - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - break; - case e_meshDropCylinder: - b3CreateHullShape( bodyId, &shapeDef, cylinder ); - break; - default: - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - break; - } - - bodies[index] = bodyId; - index += 1; - } - } -} - -int GetMeshDropBodyIndex( void* userData ) -{ - intptr_t value = (intptr_t)userData; - return 1 <= value && value <= MESH_DROP_BODY_COUNT ? (int)value - 1 : -1; -} - -void ResetMeshDropDepth( MeshDropDepth* depth, MeshDropSettings settings, const b3HullData* cylinder ) -{ - // Same heights as b3CreateWaveMesh - WaveGrid grid = GetWaveGrid( settings.rough ); - float omegaZ = 2.0f * B3_PI * grid.rowFrequency * grid.cellWidth; - float omegaX = 2.0f * B3_PI * grid.columnFrequency * grid.cellWidth; - for ( int i = 0; i <= grid.count; ++i ) - { - depth->rowHeights[i] = b3ComputeCosSin( omegaX * i ).sine; - depth->columnHeights[i] = b3ComputeCosSin( omegaZ * i ).sine; - } - - depth->waveCount = grid.count; - depth->cellWidth = grid.cellWidth; - depth->waveAmplitude = settings.amplitude; - depth->amplitude = fabsf( settings.amplitude ); - depth->probeCount = 0; - depth->radius = 0.0f; - - switch ( settings.shape ) - { - case e_meshDropBox: - case e_meshDropCylinder: - { - b3BoxHull box = MakeDropBox(); - const b3HullData* hull = settings.shape == e_meshDropBox ? &box.base : cylinder; - const b3Vec3* points = b3GetHullPoints( hull ); - int count = hull->vertexCount < MESH_DROP_MAX_PROBES ? hull->vertexCount : MESH_DROP_MAX_PROBES; - for ( int i = 0; i < count; ++i ) - { - depth->probes[i] = points[i]; - } - depth->probeCount = count; - } - break; - - case e_meshDropCapsule: - depth->probes[0] = (b3Vec3){ 0.0f, -CAPSULE_HALF_LENGTH, 0.0f }; - depth->probes[1] = (b3Vec3){ 0.0f, CAPSULE_HALF_LENGTH, 0.0f }; - depth->probeCount = 2; - depth->radius = BODY_RADIUS; - break; - - default: - depth->probes[0] = b3Vec3_zero; - depth->probeCount = 1; - depth->radius = BODY_RADIUS; - break; - } - - float maxLength = 0.0f; - for ( int i = 0; i < depth->probeCount; ++i ) - { - maxLength = fmaxf( maxLength, b3Length( depth->probes[i] ) ); - } - depth->boundingRadius = maxLength + depth->radius; - - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) - { - depth->bodyDepths[i] = -FLT_MAX; - } - - depth->maxDepth = -FLT_MAX; - depth->maxIndex = -1; - depth->maxStep = 0; - depth->stepCount = 0; -} - -// Signed distance to the plane of the wave triangle under the point. Exact away from the folds, where -// it reads a little deep on a crest and shallow in a valley. -static float GetWaveDistance( const MeshDropDepth* depth, b3Vec3 p ) -{ - float w = depth->cellWidth; - float origin = -0.5f * depth->waveCount * w; - float u = ( p.x - origin ) / w; - float v = ( p.z - origin ) / w; - int ix = b3ClampInt( (int)floorf( u ), 0, depth->waveCount - 1 ); - int iz = b3ClampInt( (int)floorf( v ), 0, depth->waveCount - 1 ); - - float amplitude = depth->waveAmplitude; - float ha = amplitude * depth->rowHeights[ix] * depth->columnHeights[iz]; - float hb = amplitude * depth->rowHeights[ix] * depth->columnHeights[iz + 1]; - float hc = amplitude * depth->rowHeights[ix + 1] * depth->columnHeights[iz + 1]; - float hd = amplitude * depth->rowHeights[ix + 1] * depth->columnHeights[iz]; - - // The cell diagonal runs from a to c, matching b3CreateWaveMesh - b3Vec3 a = { origin + ix * w, ha, origin + iz * w }; - b3Vec3 ac = { w, hc - ha, w }; - b3Vec3 side = v - iz >= u - ix ? (b3Vec3){ 0.0f, hb - ha, w } : (b3Vec3){ w, hd - ha, 0.0f }; - b3Vec3 normal = b3Normalize( b3Cross( side, ac ) ); - if ( normal.y < 0.0f ) - { - normal = b3Neg( normal ); - } - - return b3Dot( normal, b3Sub( p, a ) ); -} - -void UpdateMeshDropDepth( b3WorldId worldId, MeshDropDepth* depth ) -{ - depth->stepCount += 1; - - b3BodyEvents events = b3World_GetBodyEvents( worldId ); - for ( int i = 0; i < events.moveCount; ++i ) - { - const b3BodyMoveEvent* event = events.moveEvents + i; - int index = GetMeshDropBodyIndex( event->userData ); - if ( index < 0 ) - { - continue; - } - - b3WorldTransform transform = event->transform; - if ( (float)transform.p.y - depth->boundingRadius > depth->amplitude ) - { - continue; - } - - float sink = -FLT_MAX; - for ( int j = 0; j < depth->probeCount; ++j ) - { - b3Pos point = b3TransformWorldPoint( transform, depth->probes[j] ); - b3Vec3 p = { (float)point.x, (float)point.y, (float)point.z }; - sink = fmaxf( sink, depth->radius - GetWaveDistance( depth, p ) ); - } - - if ( sink > depth->bodyDepths[index] ) - { - depth->bodyDepths[index] = sink; - } - - if ( sink > depth->maxDepth ) - { - depth->maxDepth = sink; - depth->maxIndex = index; - depth->maxStep = depth->stepCount; - } - } -} - -void GetMeshDropDepthCounts( const MeshDropDepth* depth, int counts[MESH_DROP_DEPTH_LEVEL_COUNT] ) -{ - for ( int level = 0; level < MESH_DROP_DEPTH_LEVEL_COUNT; ++level ) - { - float threshold = g_meshDropDepthLevels[level] * B3_LINEAR_SLOP; - int count = 0; - for ( int i = 0; i < MESH_DROP_BODY_COUNT; ++i ) - { - count += depth->bodyDepths[i] > threshold ? 1 : 0; - } - counts[level] = count; - } -} diff --git a/shared/mesh_drop.h b/shared/mesh_drop.h deleted file mode 100644 index 8e23a9a..0000000 --- a/shared/mesh_drop.h +++ /dev/null @@ -1,133 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT -#pragma once - -#include "box3d/collision.h" -#include "box3d/id.h" -#include "box3d/math_functions.h" - -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -// Mesh Drop scene, shared by the Continuous / Mesh Drop sample and the headless mesh soak. A generation -// drops a grid of small bodies with random velocities on a wave mesh and steps until they sleep. A body -// that falls out of the world tunneled. The depth tracker measures how far each body sinks into the -// wave, which flags contact trouble far more often than tunnels do. The rough wave has bumps smaller than -// the bodies, so a body touches many triangles with different normals. - -typedef enum MeshDropShape -{ - e_meshDropBox, - e_meshDropCapsule, - e_meshDropCylinder, - e_meshDropSphere, - e_meshDropShapeCount -} MeshDropShape; - -// Bodies per axis. A debug build drops a smaller patch at the same spacing so the samples app stays -// responsive. The soak tools run in release and keep the full grid. -#ifdef NDEBUG -#define MESH_DROP_GRID_COUNT 32 -#else -#define MESH_DROP_GRID_COUNT 16 -#endif - -#define MESH_DROP_BODY_COUNT ( MESH_DROP_GRID_COUNT * MESH_DROP_GRID_COUNT ) -#define MESH_DROP_DEPTH_LEVEL_COUNT 4 - -// Most wave mesh cells along x and z, reached by the rough wave -#define MESH_DROP_MAX_WAVE_COUNT 640 - -// Enough for the cylinder hull -#define MESH_DROP_MAX_PROBES 16 - -extern const char* g_meshDropShapeNames[e_meshDropShapeCount]; - -// Sink depth thresholds in linear slop -extern const float g_meshDropDepthLevels[MESH_DROP_DEPTH_LEVEL_COUNT]; - -typedef struct MeshDropSettings -{ - MeshDropShape shape; - float amplitude; - - // Fine bumps instead of the broad wave. The amplitude should be a few centimeters. - bool rough; - - // Let the bodies collide with each other. Off isolates mesh collision. - bool collide; - - // Create only this grid index, or -1 for all. Without body collision a body moves the same alone. - int soloIndex; -} MeshDropSettings; - -MeshDropSettings GetDefaultMeshDropSettings( void ); - -float GetMeshDropDefaultAmplitude( bool rough ); - -// Hashes the base before adding the generation, so nearby base seeds share no generations -uint32_t GetMeshDropSeed( uint32_t baseSeed, int generation ); - -// Steps a generation may take to fall asleep -int GetMeshDropStepLimit( MeshDropShape shape ); - -// A body below this height tunneled -float GetMeshDropTunnelHeight( void ); - -b3MeshData* CreateMeshDropMesh( MeshDropSettings settings ); -b3HullData* CreateMeshDropCylinder( void ); - -// Creates a static body with the wave mesh and four walls -b3BodyId CreateMeshDropGround( b3WorldId worldId, const b3MeshData* mesh, MeshDropSettings settings ); - -// Creates the bodies of one generation in grid order. Bodies left out by the solo index are null. The -// body user data encodes the grid index, see GetMeshDropBodyIndex. -void CreateMeshDropBodies( b3WorldId worldId, MeshDropSettings settings, uint32_t seed, const b3HullData* cylinder, - b3BodyId* bodies ); - -// Grid index from body user data, or -1 if the body is not part of the drop -int GetMeshDropBodyIndex( void* userData ); - -typedef struct MeshDropDepth -{ - // Wave height factors at the mesh vertices along x and z. A vertex height is their product times - // the wave amplitude. - float rowHeights[MESH_DROP_MAX_WAVE_COUNT + 1]; - float columnHeights[MESH_DROP_MAX_WAVE_COUNT + 1]; - int waveCount; - float cellWidth; - float waveAmplitude; - - // Collision points in the body frame, rounded by the radius - b3Vec3 probes[MESH_DROP_MAX_PROBES]; - int probeCount; - float radius; - float boundingRadius; - float amplitude; - - // Deepest sink of each body so far, positive when inside the wave - float bodyDepths[MESH_DROP_BODY_COUNT]; - - float maxDepth; - int maxIndex; - int maxStep; - int stepCount; -} MeshDropDepth; - -// Starts tracking a new generation -void ResetMeshDropDepth( MeshDropDepth* depth, MeshDropSettings settings, const b3HullData* cylinder ); - -// Call after each world step -void UpdateMeshDropDepth( b3WorldId worldId, MeshDropDepth* depth ); - -// Number of bodies that sank deeper than each depth level -void GetMeshDropDepthCounts( const MeshDropDepth* depth, int counts[MESH_DROP_DEPTH_LEVEL_COUNT] ); - -#ifdef __cplusplus -} -#endif diff --git a/shared/sat_benchmark.c b/shared/sat_benchmark.c deleted file mode 100644 index c20943b..0000000 --- a/shared/sat_benchmark.c +++ /dev/null @@ -1,198 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "sat_benchmark.h" - -#include "utils.h" - -#include "box3d/constants.h" -#include "box3d/math_functions.h" - -#include "manifold.h" -#include "simd.h" - -#include - -const char* GetSatHullName( SatHullType type ) -{ - switch ( type ) - { - case satHull_complex: - return "complex"; - case satHull_rock: - return "rock"; - case satHull_cylinder: - return "cylinder"; - default: - return "unknown"; - } -} - -static b3HullData* CreateSatHull( SatHullType type ) -{ - switch ( type ) - { - case satHull_complex: - return b3CreateComplexHull( 0.5f ); - case satHull_rock: - return b3CreateRock( 0.5f ); - case satHull_cylinder: - return b3CreateCylinder( 1.0f, 0.1f, -0.5f, 32 ); - default: - B3_ASSERT( false ); - return NULL; - } -} - -static float GetBoundingRadius( const b3HullData* hull ) -{ - b3Vec3 center = b3AABB_Center( hull->aabb ); - b3Vec3 extents = b3AABB_Extents( hull->aabb ); - return b3Length( center ) + b3Length( extents ); -} - -SatBenchmarkData* CreateSatBenchmark( SatHullType typeA, SatHullType typeB ) -{ - SatBenchmarkData* data = calloc( 1, sizeof( SatBenchmarkData ) ); - data->hullA = CreateSatHull( typeA ); - data->hullB = CreateSatHull( typeB ); - data->innerRadiusA = data->hullA->innerRadius; - data->innerRadiusB = data->hullB->innerRadius; - - const b3HullData* hullA = data->hullA; - const b3HullData* hullB = data->hullB; - - b3DistanceInput input = { - .proxyA = { b3GetHullPoints( hullA ), hullA->vertexCount, 0.0f }, - .proxyB = { b3GetHullPoints( hullB ), hullB->vertexCount, 0.0f }, - .useRadii = false, - }; - - float target = 0.5f * B3_SPECULATIVE_DISTANCE; - float tolerance = 0.01f * target; - float reach = GetBoundingRadius( hullA ) + GetBoundingRadius( hullB ) + 0.5f; - - data->targetDistance = target; - data->maxPlacementError = 0.0f; - - uint32_t savedSeed = g_randomSeed; - g_randomSeed = 1234; - - for ( int i = 0; i < SAT_PAIR_COUNT; ++i ) - { - b3Quat q = RandomQuat(); - b3Vec3 direction = b3RotateVector( RandomQuat(), b3Vec3_axisX ); - b3Transform transform = { b3MulSV( reach, direction ), q }; - - // Newton iteration, the gradient of distance with respect to the position of B is the - // normal. Distance is 1-Lipschitz so each step lands at or above the target and never overlaps. - b3SimplexCache cache = { 0 }; - float error = 0.0f; - for ( int iteration = 0; iteration < 20; ++iteration ) - { - input.transform = transform; - b3DistanceOutput output = b3ShapeDistance( &input, &cache, NULL, 0 ); - error = output.distance - target; - if ( b3AbsFloat( error ) < tolerance ) - { - break; - } - - transform.p = b3MulSub( transform.p, error, output.normal ); - } - - data->transforms[i] = transform; - data->caches[i] = cache; - data->maxPlacementError = b3MaxFloat( data->maxPlacementError, b3AbsFloat( error ) ); - } - - g_randomSeed = savedSeed; - - return data; -} - -void DestroySatBenchmark( SatBenchmarkData* data ) -{ - b3DestroyHull( data->hullA ); - b3DestroyHull( data->hullB ); - free( data ); -} - -void EnableSatInscribedSphere( SatBenchmarkData* data, bool flag ) -{ - // A hugely negative radius drives the SAT upper bound so high that no candidate is skipped. - // It must stay finite or the bound becomes NaN. - float disabledRadius = -B3_HUGE; - data->hullA->innerRadius = flag ? data->innerRadiusA : disabledRadius; - data->hullB->innerRadius = flag ? data->innerRadiusB : disabledRadius; -} - -SatBenchmarkResult RunSatBenchmark( const SatBenchmarkData* data, int repeatCount, bool warmStartDistance ) -{ - const b3HullData* hullA = data->hullA; - const b3HullData* hullB = data->hullB; - - b3DistanceInput input = { - .proxyA = { b3GetHullPoints( hullA ), hullA->vertexCount, 0.0f }, - .proxyB = { b3GetHullPoints( hullB ), hullB->vertexCount, 0.0f }, - .useRadii = false, - }; - - float distanceSum = 0.0f; - int iterationSum = 0; - - uint64_t ticks = b3GetTicks(); - - for ( int repeat = 0; repeat < repeatCount; ++repeat ) - { - for ( int i = 0; i < SAT_PAIR_COUNT; ++i ) - { - input.transform = data->transforms[i]; - b3SimplexCache cache = warmStartDistance ? data->caches[i] : (b3SimplexCache){ 0 }; - b3DistanceOutput output = b3ShapeDistance( &input, &cache, NULL, 0 ); - distanceSum += output.distance; - iterationSum += output.iterations; - } - } - - float distanceMs = b3GetMillisecondsAndReset( &ticks ); - - float separationSum = 0.0f; - int earlyReturnCount = 0; - - for ( int repeat = 0; repeat < repeatCount; ++repeat ) - { - for ( int i = 0; i < SAT_PAIR_COUNT; ++i ) - { - // Early return enabled to match the manifold path. The placement keeps it from firing. - b3AxisQuery query = b3ComputeSeparatingAxis( hullA, hullB, data->transforms[i], true ); - b3SeparatingAxis axis = b3GetBestAxis( &query ); - separationSum += axis.separation; - earlyReturnCount += query.separatedFeature != b3_invalidAxis ? 1 : 0; - } - } - - float satMs = b3GetMilliseconds( ticks ); - - int queryCount = repeatCount * SAT_PAIR_COUNT; - SatBenchmarkResult result = { - .distanceMs = distanceMs, - .satMs = satMs, - .queryCount = queryCount, - .averageDistance = distanceSum / queryCount, - .averageSeparation = separationSum / queryCount, - .averageIterations = (float)iterationSum / queryCount, - .earlyReturnCount = earlyReturnCount, - }; - return result; -} - -void SetSimdWidth( int width ) -{ - b3SetSIMDWidth( width ); -} - -int GetSimdWidth( void ) -{ - return b3GetSIMDWidth(); -} diff --git a/shared/sat_benchmark.h b/shared/sat_benchmark.h deleted file mode 100644 index 66b2b2d..0000000 --- a/shared/sat_benchmark.h +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT -#pragma once - -#include "box3d/collision.h" - -#include - -// Compares GJK (b3ShapeDistance) against SAT (b3ComputeSeparatingAxis) on hull pairs held -// inside the speculative margin, so neither query can exit early. SAT is internal, so this -// is only available when Box3D is linked statically, see BOX3D_INTERNAL_BENCHMARKS. - -#ifdef __cplusplus -extern "C" -{ -#endif - -typedef enum SatHullType -{ - satHull_complex, - satHull_rock, - satHull_cylinder, - satHull_count -} SatHullType; - -#define SAT_PAIR_COUNT 1000 - -typedef struct SatBenchmarkData -{ - b3HullData* hullA; - b3HullData* hullB; - float innerRadiusA; - float innerRadiusB; - - // Hull A sits at the origin so these are the poses of B in the frame of A - b3Transform transforms[SAT_PAIR_COUNT]; - - // Converged GJK caches for a warm started distance query - b3SimplexCache caches[SAT_PAIR_COUNT]; - - float targetDistance; - float maxPlacementError; -} SatBenchmarkData; - -typedef struct SatBenchmarkResult -{ - float distanceMs; - float satMs; - int queryCount; - float averageDistance; - float averageSeparation; - float averageIterations; - - // Should be zero, otherwise the placement let SAT exit early - int earlyReturnCount; -} SatBenchmarkResult; - -const char* GetSatHullName( SatHullType type ); - -SatBenchmarkData* CreateSatBenchmark( SatHullType typeA, SatHullType typeB ); -void DestroySatBenchmark( SatBenchmarkData* data ); - -// Disabling the inscribed sphere bound makes SAT evaluate every face and edge candidate -void EnableSatInscribedSphere( SatBenchmarkData* data, bool flag ); - -SatBenchmarkResult RunSatBenchmark( const SatBenchmarkData* data, int repeatCount, bool warmStartDistance ); - -void SetSimdWidth( int width ); -int GetSimdWidth( void ); - -#ifdef __cplusplus -} -#endif diff --git a/shared/stability.c b/shared/stability.c index 404f911..395c93e 100644 --- a/shared/stability.c +++ b/shared/stability.c @@ -10,6 +10,8 @@ #include #include +#define MESH_DROP_GRID_COUNT 32 + MeshDropData CreateMeshDrop( b3WorldId worldId, b3Pos origin ) { MeshDropData data = { 0 }; @@ -59,7 +61,6 @@ MeshDropData CreateMeshDrop( b3WorldId worldId, b3Pos origin ) bodyDef.linearVelocity = linearVelocity; bodyDef.angularVelocity = angularVelocity; b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - data.bodies[i * gridCount + j] = bodyId; b3CreateHullShape( bodyId, &shapeDef, &box.base ); } @@ -69,29 +70,6 @@ MeshDropData CreateMeshDrop( b3WorldId worldId, b3Pos origin ) return data; } -bool UpdateMeshDrop( b3WorldId worldId, MeshDropData* data ) -{ - if ( data->hash == 0 ) - { - if ( b3World_GetAwakeBodyCount( worldId ) == 0 ) - { - data->hash = B3_HASH_INIT; - int bodyCount = MESH_DROP_GRID_COUNT * MESH_DROP_GRID_COUNT; - for ( int i = 0; i < bodyCount; ++i ) - { - b3WorldTransform xf = b3Body_GetTransform( data->bodies[i] ); - data->hash = b3Hash( data->hash, (uint8_t*)&xf, sizeof( b3WorldTransform ) ); - } - - data->sleepStep = data->stepCount; - } - } - - data->stepCount += 1; - - return data->hash != 0; -} - void DestroyMeshDrop( MeshDropData* data ) { b3DestroyMesh( data->mesh ); diff --git a/shared/stability.h b/shared/stability.h index f8e105c..cc5e5e5 100644 --- a/shared/stability.h +++ b/shared/stability.h @@ -12,21 +12,12 @@ extern "C" { #endif -#define MESH_DROP_GRID_COUNT 20 - -// Thin fast boxes dropped on a wave mesh. Stresses continuous collision and mesh contact -// stability, and doubles as a determinism scenario via the sleep hash. typedef struct MeshDropData { struct b3MeshData* mesh; - b3BodyId bodies[MESH_DROP_GRID_COUNT * MESH_DROP_GRID_COUNT]; - int stepCount; - int sleepStep; - uint32_t hash; } MeshDropData; MeshDropData CreateMeshDrop( b3WorldId worldId, b3Pos origin ); -bool UpdateMeshDrop( b3WorldId worldId, MeshDropData* data ); void DestroyMeshDrop( MeshDropData* data ); #ifdef __cplusplus diff --git a/shared/utils.c b/shared/utils.c index bdba729..ac19aff 100644 --- a/shared/utils.c +++ b/shared/utils.c @@ -4,8 +4,7 @@ #include "utils.h" #if defined( _WIN64 ) -// Lower-case windows.h intentionally for cross compiling on mingw. -#include +#include #elif defined( __APPLE__ ) #include #elif defined( __linux__ ) diff --git a/shared/utils.h b/shared/utils.h index 5997cbc..f376614 100644 --- a/shared/utils.h +++ b/shared/utils.h @@ -102,13 +102,10 @@ B3_INLINE b3Vec3 RandomUnitVector() float sqrt1MinusU1 = sqrtf( 1.0f - u1 ); float sqrtU1 = sqrtf( u1 ); - b3CosSin cs2 = b3ComputeCosSin( u2 ); - b3CosSin cs3 = b3ComputeCosSin( u3 ); - b3Vec3 v; - v.x = sqrt1MinusU1 * cs2.sine; - v.y = sqrt1MinusU1 * cs2.cosine; - v.z = sqrtU1 * cs3.sine; + v.x = sqrt1MinusU1 * sinf( u2 ); + v.y = sqrt1MinusU1 * cosf( u2 ); + v.z = sqrtU1 * sinf( u3 ); return v; } @@ -125,14 +122,11 @@ B3_INLINE b3Quat RandomQuat() float sqrt1MinusU1 = sqrtf( 1.0f - u1 ); float sqrtU1 = sqrtf( u1 ); - b3CosSin cs2 = b3ComputeCosSin( u2 ); - b3CosSin cs3 = b3ComputeCosSin( u3 ); - b3Quat q; - q.v.x = sqrt1MinusU1 * cs2.sine; - q.v.y = sqrt1MinusU1 * cs2.cosine; - q.v.z = sqrtU1 * cs3.sine; - q.s = sqrtU1 * cs3.cosine; + q.v.x = sqrt1MinusU1 * sinf( u2 ); + q.v.y = sqrt1MinusU1 * cosf( u2 ); + q.v.z = sqrtU1 * sinf( u3 ); + q.s = sqrtU1 * cosf( u3 ); return q; } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eaa22b7..95b0d8b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -19,24 +19,20 @@ set(BOX3D_SOURCE_FILES compound.h constraint_graph.c constraint_graph.h - contact_solver_wide.inl - contact_solver.c - contact_solver.h contact.c contact.h + contact_solver.c + contact_solver.h container.h - convex_manifold_wide.inl convex_manifold.c core.c core.h ctz.h - distance_joint.c distance.c + distance_joint.c dynamic_tree.c - dynamic_tree.h height_field.c hull.c - hull.h id_pool.c id_pool.h island.c @@ -47,28 +43,25 @@ set(BOX3D_SOURCE_FILES manifold.h math_functions.c math_internal.h - mesh_contact.c mesh.c + mesh_contact.c motor_joint.c mover.c - mover_joint.c - name_cache.c - name_cache.h parallel_for.c parallel_for.h parallel_joint.c physics_world.c physics_world.h platform.h - pogo_joint.c prismatic_joint.c qsort.h - rapidhash.h - recording_ops.inl recording.c recording.h - replay.c - replay.h + recording_ops.inl + recording_replay.c + recording_replay.h + world_snapshot.c + world_snapshot.h revolute_joint.c scheduler.c scheduler.h @@ -76,17 +69,12 @@ set(BOX3D_SOURCE_FILES sensor.h shape.c shape.h - simd_avx2.h - simd_neon.h - simd_scalar.h - simd_sse2.h - simd_wide.h simd.c simd.h - solver_set.c - solver_set.h solver.c solver.h + solver_set.c + solver_set.h sphere.c spherical_joint.c table.c @@ -97,10 +85,6 @@ set(BOX3D_SOURCE_FILES verstable.h weld_joint.c wheel_joint.c - wide4.c - wide8.c - world_snapshot.c - world_snapshot.h box3d.natvis ) @@ -123,6 +107,8 @@ 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 +136,13 @@ endif() if (BOX3D_PROFILE) target_compile_definitions(box3d PRIVATE BOX3D_PROFILE) - set(TRACY_ENABLE ON CACHE BOOL "Enable profiling" FORCE) - set(TRACY_MANUAL_LIFETIME ON CACHE BOOL "Enable manual lifetime for Tracy" FORCE) + 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) FetchContent_Declare( tracy GIT_REPOSITORY https://github.com/wolfpld/tracy.git - GIT_TAG v0.14.1 + GIT_TAG v0.13.1 GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) @@ -166,13 +152,14 @@ if (BOX3D_PROFILE) endif() if(BOX3D_VALIDATE) - # Only effective when NDEBUG is undefined, see base.h - message(STATUS "Box3D validation ON (debug builds)") + message(STATUS "Box3D validation ON") target_compile_definitions(box3d PRIVATE BOX3D_VALIDATE) endif() -target_compile_definitions(box3d PRIVATE ${BOX3D_SIMD_DEFINITIONS}) -target_compile_options(box3d PRIVATE ${BOX3D_SIMD_OPTIONS}) +if (BOX3D_DISABLE_SIMD) + message(STATUS "Box3D SIMD disabled") + target_compile_definitions(box3d PRIVATE BOX3D_DISABLE_SIMD) +endif() if (BOX3D_DOUBLE_PRECISION) message(STATUS "Box3D double precision ON") @@ -180,11 +167,8 @@ if (BOX3D_DOUBLE_PRECISION) target_compile_definitions(box3d PUBLIC BOX3D_DOUBLE_PRECISION) endif() -# Enable asserts in release with debug info -target_compile_definitions(box3d PUBLIC "$<$:B3_ENABLE_ASSERT>") - if (MSVC) - message(STATUS "Box3D on MSVC") + message(STATUS "Box3D on MSVC") if (BUILD_SHARED_LIBS) # this is needed by DLL users to import Box3D symbols target_compile_definitions(box3d INTERFACE BOX3D_DLL) @@ -193,38 +177,37 @@ if (MSVC) # Visual Studio won't load the natvis unless it is in the project target_sources(box3d PRIVATE box3d.natvis) - if (CMAKE_GENERATOR MATCHES "Visual Studio") - target_compile_options(box3d PRIVATE /MP) - endif() + # Enable asserts in release with debug info + target_compile_definitions(box3d PUBLIC "$<$:B3_ENABLE_ASSERT>") - 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() + # 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 (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") + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") + target_compile_options(box3d PRIVATE -Wmissing-prototypes) 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 -Wno-unused-value) + target_compile_options(box3d PRIVATE -Wmissing-prototypes -Wall -Wextra -pedantic) elseif (EMSCRIPTEN) message(STATUS "Box3D on Emscripten") + target_compile_options(box3d PRIVATE -msimd128 -msse2) 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}) @@ -256,69 +239,15 @@ install( DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/box3d ) -export( - EXPORT box3dConfig - NAMESPACE box3d:: - FILE "${PROJECT_BINARY_DIR}/box3dConfig.cmake" -) - include(CMakePackageConfigHelpers) write_basic_package_version_file( - "${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/box3dConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) install( - FILES "${PROJECT_BINARY_DIR}/box3dConfigVersion.cmake" + FILES "${CMAKE_CURRENT_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/arena_allocator.c b/src/arena_allocator.c index 8543e57..1de2db5 100644 --- a/src/arena_allocator.c +++ b/src/arena_allocator.c @@ -30,29 +30,30 @@ void* b3StackAlloc( b3Stack* stack, int size, const char* name ) return NULL; } - int alignedSize = ( ( size - 1 ) | ( B3_ALIGNMENT - 1 ) ) + 1; + // ensure allocation is 32 byte aligned to support 256-bit SIMD + int size32 = ( ( size - 1 ) | 0x1F ) + 1; b3StackEntry entry; - entry.size = alignedSize; + entry.size = size32; entry.name = name; - if ( stack->index + alignedSize > stack->capacity ) + if ( stack->index + size32 > stack->capacity ) { // fall back to the heap (undesirable) - entry.data = (char*)b3Alloc( alignedSize ); + entry.data = (char*)b3Alloc( size32 ); entry.usedMalloc = true; - B3_ASSERT( ( (uintptr_t)entry.data & ( B3_ALIGNMENT - 1 ) ) == 0 ); + B3_ASSERT( ( (uintptr_t)entry.data & 0x1F ) == 0 ); } else { entry.data = stack->memory + stack->index; entry.usedMalloc = false; - stack->index += alignedSize; + stack->index += size32; - B3_ASSERT( ( (uintptr_t)entry.data & ( B3_ALIGNMENT - 1 ) ) == 0 ); + B3_ASSERT( ( (uintptr_t)entry.data & 0x1F ) == 0 ); } - stack->allocation += alignedSize; + stack->allocation += size32; if ( stack->allocation > stack->maxAllocation ) { stack->maxAllocation = stack->allocation; diff --git a/src/block_allocator.c b/src/block_allocator.c index b3eeea8..4c1f154 100644 --- a/src/block_allocator.c +++ b/src/block_allocator.c @@ -9,10 +9,6 @@ b3BlockAllocator b3CreateBlockAllocator( int elementSize, int initialCount ) { B3_ASSERT( elementSize >= (int)sizeof( void* ) ); - // The free list stores a pointer inside each element, so the stride must keep every element aligned. - // Blocks come from b3Alloc, so a stride that is a multiple of B3_BLOCK_ALIGNMENT aligns all elements. - elementSize = ( ( elementSize - 1 ) | ( B3_BLOCK_ALIGNMENT - 1 ) ) + 1; - b3BlockAllocator allocator = { 0 }; b3Array_Create( allocator.blocks ); @@ -85,7 +81,6 @@ void b3FreeElement( b3BlockAllocator* allocator, void* element ) B3_ASSERT( allocator != NULL ); B3_ASSERT( element != NULL ); B3_ASSERT( allocator->allocationCount > 0 ); - B3_ASSERT( ( (uintptr_t)element & ( B3_BLOCK_ALIGNMENT - 1 ) ) == 0 ); allocator->allocationCount -= 1; diff --git a/src/block_allocator.h b/src/block_allocator.h index d271304..e9922d0 100644 --- a/src/block_allocator.h +++ b/src/block_allocator.h @@ -9,7 +9,6 @@ #define B3_BLOCK_EXPONENT 8 #define B3_BLOCK_SIZE ( 1 << B3_BLOCK_EXPONENT ) -#define B3_BLOCK_ALIGNMENT 16 typedef struct b3Block { @@ -27,7 +26,7 @@ typedef struct b3BlockAllocator int allocationCount; } b3BlockAllocator; -// Element must be large enough to hold a pointer. The element size is rounded up to B3_BLOCK_ALIGNMENT. +// Element must be large enough to hold a pointer b3BlockAllocator b3CreateBlockAllocator( int elementSize, int initialCount ); void b3DestroyBlockAllocator( b3BlockAllocator* allocator ); diff --git a/src/body.c b/src/body.c index b6049da..aa4e91e 100644 --- a/src/body.c +++ b/src/body.c @@ -20,6 +20,9 @@ #include "box3d/id.h" #include +#include + +_Static_assert( B3_BODY_NAME_LENGTH >= 0, "minimum name length" ); // Get a validated body from a world using an id. b3Body* b3GetBodyFullId( b3World* world, b3BodyId bodyId ) @@ -33,7 +36,7 @@ b3Body* b3GetBodyFullId( b3World* world, b3BodyId bodyId ) b3WorldTransform b3GetBodyTransformQuick( b3World* world, b3Body* body ) { - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, body->localIndex ); return bodySim->transform; } @@ -53,7 +56,7 @@ b3BodyId b3MakeBodyId( b3World* world, int bodyId ) b3BodySim* b3GetBodySim( b3World* world, b3Body* body ) { - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, body->localIndex ); return bodySim; } @@ -62,48 +65,25 @@ b3BodyState* b3GetBodyState( b3World* world, b3Body* body ) { if ( body->setIndex == b3_awakeSet ) { - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); return b3Array_Get( set->bodyStates, body->localIndex ); } return NULL; } -void b3RefreshBodyContactIndices( b3World* world, b3Body* body ) +static void b3SyncBodyFlags( b3World* world, b3Body* body ) { - int encodedBodySimIndex = b3EncodeBodySimIndex( body ); + // Never sync transient flags + uint32_t flags = body->flags & ~b3_bodyTransientFlags; - int contactKey = body->headContactKey; - while ( contactKey != B3_NULL_INDEX ) - { - int edgeIndex = contactKey & 1; - int contactId = contactKey >> 1; - - b3Contact* contact = b3Array_Get( world->contacts, contactId ); - contactKey = contact->edges[edgeIndex].nextKey; - - if ( edgeIndex == 0 ) - { - contact->encodedBodySimA = encodedBodySimIndex; - } - else - { - contact->encodedBodySimB = encodedBodySimIndex; - } - } -} - -void b3SyncBodyFlags( b3World* world, b3Body* body ) -{ b3BodySim* bodySim = b3GetBodySim( world, body ); - - // Preserve the sim only flags: fast for contact recycling, time of impact for debug draw. - bodySim->flags = ( bodySim->flags & ( b3_isFast | b3_hadTimeOfImpact ) ) | ( body->flags & ~b3_bodyTransientFlags ); + bodySim->flags = flags; b3BodyState* bodyState = b3GetBodyState( world, body ); if ( bodyState != NULL ) { - bodyState->flags = body->flags & ~b3_bodyTransientFlags; + bodyState->flags = flags; } } @@ -184,7 +164,6 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) B3_ASSERT( b3IsValidFloat( def->linearDamping ) && def->linearDamping >= 0.0f ); B3_ASSERT( b3IsValidFloat( def->angularDamping ) && def->angularDamping >= 0.0f ); B3_ASSERT( b3IsValidFloat( def->sleepThreshold ) && def->sleepThreshold >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->safetyFactor ) && def->safetyFactor >= 0.0f ); B3_ASSERT( b3IsValidFloat( def->gravityScale ) ); b3World* world = b3GetUnlockedWorldFromId( worldId ); @@ -217,20 +196,20 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) { // new set for a sleeping body in its own island setId = b3AllocId( &world->solverSetIdPool ); - if ( setId == b3GetSolverSetCount( world ) ) + if ( setId == world->solverSets.count ) { // Create a zero initialized solver set. All sub-arrays are also zero initialized. - b3Array_Push( world->sleepingSets, (b3SolverSet){ 0 } ); + b3Array_Push( world->solverSets, (b3SolverSet){ 0 } ); } else { - B3_ASSERT( b3GetSolverSet( world, setId )->setIndex == B3_NULL_INDEX ); + B3_ASSERT( world->solverSets.data[setId].setIndex == B3_NULL_INDEX ); } - b3GetSolverSet( world, setId )->setIndex = setId; + world->solverSets.data[setId].setIndex = setId; } - B3_ASSERT( 0 <= setId && setId < b3GetSolverSetCount( world ) ); + B3_ASSERT( 0 <= setId && setId < world->solverSets.count ); int bodyId = b3AllocId( &world->bodyIdPool ); @@ -242,7 +221,7 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) lockFlags |= def->motionLocks.angularY ? b3_lockAngularY : 0; lockFlags |= def->motionLocks.angularZ ? b3_lockAngularZ : 0; - b3SolverSet* set = b3GetSolverSet( world, setId ); + b3SolverSet* set = b3Array_Get( world->solverSets, setId ); b3BodySim* bodySim = b3Array_Emplace( set->bodySims ); *bodySim = (b3BodySim){ 0 }; bodySim->transform.p = def->position; @@ -254,7 +233,6 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) bodySim->force = b3Vec3_zero; bodySim->torque = b3Vec3_zero; bodySim->invMass = 0.0f; - bodySim->inertia = b3Mat3_zero; bodySim->invInertiaLocal = b3Mat3_zero; bodySim->minExtent = B3_HUGE; bodySim->maxExtent = b3Vec3_zero; @@ -267,7 +245,7 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) bodySim->flags |= def->allowFastRotation ? b3_allowFastRotation : 0; bodySim->flags |= def->type == b3_dynamicBody ? b3_dynamicFlag : 0; bodySim->flags |= def->enableSleep ? b3_enableSleep : 0; - bodySim->flags |= def->enableContactRecycling ? b3_enableContactRecycling : 0; + bodySim->flags |= def->enableContactRecycling ? b3_bodyEnableContactRecycling : 0; if ( setId == b3_awakeSet ) { @@ -278,6 +256,8 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) bodyState->angularVelocity = def->angularVelocity; bodyState->deltaRotation = b3Quat_identity; bodyState->flags = bodySim->flags; + + bodySim->maxAngularVelocity = b3Length( def->angularVelocity ) + 5.0f; } if ( bodyId == world->bodies.count ) @@ -290,6 +270,21 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) } b3Body* body = b3Array_Get( world->bodies, bodyId ); + + if ( def->name ) + { +#if defined( _MSC_VER ) + strncpy_s( body->name, B3_BODY_NAME_LENGTH + 1, def->name, B3_BODY_NAME_LENGTH ); +#else + strncpy( body->name, def->name, B3_BODY_NAME_LENGTH ); + body->name[B3_BODY_NAME_LENGTH] = 0; +#endif + } + else + { + memset( body->name, 0, sizeof( body->name ) ); + } + body->userData = def->userData; body->setIndex = setId; body->localIndex = set->bodySims.count - 1; @@ -307,10 +302,8 @@ b3BodyId b3CreateBody( b3WorldId worldId, const b3BodyDef* def ) body->id = bodyId; body->sleepThreshold = def->sleepThreshold; body->sleepTime = 0.0f; - body->sleepVelocity = 0.0f; - body->safetyFactor = def->safetyFactor; body->mass = 0.0f; - body->nameId = b3AddName( &world->names, def->name ); + body->inertia = b3Mat3_zero; body->type = def->type; body->flags = bodySim->flags; @@ -398,12 +391,6 @@ void b3DestroyBody( b3BodyId bodyId ) { b3Shape* shape = b3Array_Get( world->shapes, shapeId ); - if ( shape->type == b3_compoundShape ) - { - B3_ASSERT( world->compoundShapeCount > 0 ); - world->compoundShapeCount -= 1; - } - if ( shape->sensorIndex != B3_NULL_INDEX ) { b3DestroySensor( world, shape ); @@ -423,7 +410,7 @@ void b3DestroyBody( b3BodyId bodyId ) b3RemoveBodyFromIsland( world, body ); // Remove body sim from solver set that owns it - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); int movedIndex = b3Array_RemoveSwap( set->bodySims, body->localIndex ); if ( movedIndex != B3_NULL_INDEX ) { @@ -433,7 +420,6 @@ void b3DestroyBody( b3BodyId bodyId ) b3Body* movedBody = b3Array_Get( world->bodies, movedId ); B3_ASSERT( movedBody->localIndex == movedIndex ); movedBody->localIndex = body->localIndex; - b3RefreshBodyContactIndices( world, movedBody ); } // Remove body state from awake set @@ -811,130 +797,14 @@ int b3Body_CollideMover( b3BodyId bodyId, b3BodyPlaneResult* bodyPlanes, int pla return resultCount; } -b3BodyTOIResult b3Body_TimeOfImpactMover( b3BodyId bodyId, b3Pos origin, const b3Capsule* mover, b3Vec3 moverTranslation, - b3QueryFilter filter, b3WorldTransform bodyTransform1, b3WorldTransform bodyTransform2 ) -{ - b3BodyTOIResult result = { 0 }; - result.fraction = 1.0f; - - b3World* world = b3GetUnlockedWorld( bodyId.world0 ); - if ( world == NULL ) - { - return result; - } - - b3Transform xf1 = b3ToRelativeTransform( bodyTransform1, origin ); - b3Transform xf2 = b3ToRelativeTransform( bodyTransform2, origin ); - - b3Body* body = b3GetBodyFullId( world, bodyId ); - b3BodySim* bodySim = b3GetBodySim( world, body ); - b3Vec3 localCenter = bodySim->localCenter; - - b3Vec3 capsulePoints[2] = { mover->center1, mover->center2 }; - b3TOIInput input = { 0 }; - input.proxyB = (b3ShapeProxy){ - .points = capsulePoints, - .count = 2, - .radius = mover->radius, - }; - input.sweepA.c1 = b3TransformPoint( xf1, localCenter ); - input.sweepA.c2 = b3TransformPoint( xf2, localCenter ); - input.sweepA.q1 = bodyTransform1.q; - input.sweepA.q2 = bodyTransform2.q; - input.sweepA.localCenter = localCenter; - - input.sweepB.c1 = b3Vec3_zero; - input.sweepB.c2 = moverTranslation; - input.sweepB.q1 = b3Quat_identity; - input.sweepB.q2 = b3Quat_identity; - input.sweepB.localCenter = b3Vec3_zero; - - input.maxFraction = 1.0f; - - int shapeId = body->headShapeId; - while ( shapeId != B3_NULL_INDEX ) - { - b3Shape* shape = b3Array_Get( world->shapes, shapeId ); - shapeId = shape->nextShapeId; - - if ( b3ShouldQueryCollide( &shape->filter, &filter ) == false ) - { - continue; - } - - b3ShapeType type = shape->type; - if ( type != b3_sphereShape && type != b3_capsuleShape && type != b3_hullShape ) - { - continue; - } - - input.proxyA = b3MakeShapeProxy( shape ); - - b3TOIOutput output = b3TimeOfImpact( &input ); - B3_VALIDATE( output.state != b3_toiStateUnknown ); - - // Mimic behavior in b3ContinuousQueryCallback. Ignore shapes that initially overlap. - if (0.0f < output.fraction && output.fraction < result.fraction) - { - input.maxFraction = output.fraction; - - result.point = b3OffsetPos( origin, output.point ); - result.normal = output.normal; - result.fraction = output.fraction; - result.shapeId = (b3ShapeId){ - .index1 = shape->id + 1, - .world0 = world->worldId, - .generation = shape->generation, - }; - } - } - - return result; -} - -// This computes the deviation of the principal inertia values without computing eigenvalues. -// It computes: -// ((I1 - I2)^2 + (I1 - I3)^2 + (I2 - I3)^2) / (I1^2 + I2^2 + I3^2) -// https://en.wikipedia.org/wiki/Cauchy_stress_tensor#Stress_deviator_tensor -static void b3UpdateIsotropicInertia( b3World* world, b3Body* body, b3BodySim* bodySim ) -{ - b3Matrix3 inertia = bodySim->inertia; - float mean = ( inertia.cx.x + inertia.cy.y + inertia.cz.z ) / 3.0f; - float dx = inertia.cx.x - mean; - float dy = inertia.cy.y - mean; - float dz = inertia.cz.z - mean; - float offDiagonal = inertia.cy.x * inertia.cy.x + inertia.cz.x * inertia.cz.x + inertia.cz.y * inertia.cz.y; - - // This is the square of the Frobenius matrix norm. - // https://en.wikipedia.org/wiki/Matrix_norm - float deviation = dx * dx + dy * dy + dz * dz + 2.0f * offDiagonal; - - float tolerance = world->isotropicInertiaTolerance; - - if ( 2.0f * deviation > 3.0f * tolerance * tolerance * mean * mean ) - { - body->flags |= b3_enableGyroscopicTorque; - } - else - { - body->flags &= ~b3_enableGyroscopicTorque; - } - - b3SyncBodyFlags( world, body ); -} - void b3UpdateBodyMassData( b3World* world, b3Body* body ) { b3BodySim* bodySim = b3GetBodySim( world, body ); - // Mass is no longer dirty - body->flags &= ~b3_dirtyMass; - body->flags &= ~b3_enableGyroscopicTorque; - b3SyncBodyFlags( world, body ); - // Compute mass data from shapes. Each shape has its own density. body->mass = 0.0f; - bodySim->inertia = b3Mat3_zero; + body->inertia = b3Mat3_zero; + bodySim->invMass = 0.0f; bodySim->invInertiaLocal = b3Mat3_zero; bodySim->invInertiaWorld = b3Mat3_zero; @@ -1018,19 +888,19 @@ void b3UpdateBodyMassData( b3World* world, b3Body* body ) // Shift to center of mass. This is safe because it can only increase. b3Vec3 offset = b3Sub( localCenter, massData.center ); b3Matrix3 inertia = b3AddMM( massData.inertia, b3Steiner( massData.mass, offset ) ); - bodySim->inertia = b3AddMM( bodySim->inertia, inertia ); + body->inertia = b3AddMM(body->inertia, inertia); } b3StackFree( &world->stack, masses ); masses = NULL; - float det = b3Det( bodySim->inertia ); + float det = b3Det( body->inertia ); B3_ASSERT( det >= 0.0f ); if ( det > 0.0f ) { // This call is faster than b3Invert - bodySim->invInertiaLocal = b3InvertT( bodySim->inertia ); + bodySim->invInertiaLocal = b3InvertT( body->inertia ); b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q ); bodySim->invInertiaWorld = b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) ); @@ -1063,28 +933,65 @@ void b3UpdateBodyMassData( b3World* world, b3Body* body ) shapeId = s->nextShapeId; } - // When the center of mass changes, any cached contact manifold becomes invalid. - int edgeKey = body->headContactKey; - while ( edgeKey != B3_NULL_INDEX ) - { - int contactId = edgeKey >> 1; - int edgeIndex = edgeKey & 1; - - b3Contact* contact = b3Array_Get( world->contacts, contactId ); - contact->flags &= ~b3_relativeTransformValid; - - edgeKey = contact->edges[edgeIndex].nextKey; - } - // Apply fixed rotation if ( ( bodySim->flags & b3_fixedRotation ) == b3_fixedRotation ) { - bodySim->inertia = b3Mat3_zero; + body->inertia = b3Mat3_zero; bodySim->invInertiaLocal = b3Mat3_zero; bodySim->invInertiaWorld = b3Mat3_zero; } +} - b3UpdateIsotropicInertia( world, body, bodySim ); +void b3DumpBody( b3World* world, b3Body* body ) +{ + // int32 bodyIndex = m_islandIndex; + + b3BodySim* sim = b3GetBodySim( world, body ); + b3Vec3 p = b3ToVec3( sim->transform.p ); + b3Quat q = sim->transform.q; + + b3Vec3 v = b3Vec3_zero; + b3Vec3 w = b3Vec3_zero; + b3BodyState* state = b3GetBodyState( world, body ); + if ( state != NULL ) + { + v = state->linearVelocity; + w = state->angularVelocity; + } + + // %.9g is sufficient to save and load the same value using text + // FLT_DECIMAL_DIG == 9 + b3Dump( "{\n" ); + b3Dump( " b3BodyDef bd = b3DefaultBodyDef();\n" ); + if ( body->name[0] != 0 ) + { + b3Dump( " bd.name = \"%s\";\n", body->name ); + } + b3Dump( " bd.type = b3BodyType(%d);\n", body->type ); + b3Dump( " bd.position = {%.9g, %.9g, %.9g};\n", p.x, p.y, p.z ); + b3Dump( " bd.rotation = {{%.9g, %.9g, %.9g}, %.9g};\n", q.v.x, q.v.y, q.v.z, q.s ); + b3Dump( " bd.linearVelocity = {%.9g, %.9g, %.9g};\n", v.x, v.y, v.z ); + b3Dump( " bd.angularVelocity = {%.9g, %.9g, %.9g};\n", w.x, w.y, w.z ); + b3Dump( " bd.linearDamping = %.9g;\n", sim->linearDamping ); + b3Dump( " bd.angularDamping = %.9g;\n", sim->angularDamping ); + b3Dump( " bd.enableSleep = bool(%d);\n", body->flags & b3_enableSleep ); + b3Dump( " bd.isAwake = bool(%d);\n", body->setIndex == b3_awakeSet ); + b3Dump( " bd.gravityScale = %.9g;\n", sim->gravityScale ); + b3Dump( " b3BodyId bodyId = b3CreateBody(m_worldId, &bd);\n" ); + b3Dump( " bodies.push_back(bodyId);\n" ); + b3Dump( "\n" ); + + int shapeIndex = body->headShapeId; + while ( shapeIndex != B3_NULL_INDEX ) + { + b3Dump( " {\n" ); + b3DumpShape( world, shapeIndex ); + b3Dump( " }\n" ); + + b3Shape* shape = b3Array_Get( world->shapes, shapeIndex ); + shapeIndex = shape->nextShapeId; + } + b3Dump( "}\n" ); } b3Pos b3Body_GetPosition( b3BodyId bodyId ) @@ -1177,11 +1084,17 @@ void b3Body_SetTransform( b3BodyId bodyId, b3Pos position, b3Quat rotation ) b3AABB aabb = b3ComputeFatShapeAABB( shape, transform, speculativeDistance ); shape->aabb = aabb; - b3AABB* shapeFatAABB = world->fatAABBs.data + shapeId; - if ( b3AABB_Contains( *shapeFatAABB, aabb ) == false ) + if ( b3AABB_Contains( shape->fatAABB, aabb ) == false ) { - b3AABB fatAABB = b3AABB_Inflate( aabb, shape->aabbMargin ); - *shapeFatAABB = fatAABB; + float margin = shape->aabbMargin; + b3AABB fatAABB; + fatAABB.lowerBound.x = aabb.lowerBound.x - margin; + fatAABB.lowerBound.y = aabb.lowerBound.y - margin; + fatAABB.lowerBound.z = aabb.lowerBound.z - margin; + fatAABB.upperBound.x = aabb.upperBound.x + margin; + fatAABB.upperBound.y = aabb.upperBound.y + margin; + fatAABB.upperBound.z = aabb.upperBound.z + margin; + shape->fatAABB = fatAABB; // The body could be disabled if ( shape->proxyKey != B3_NULL_INDEX ) @@ -1364,7 +1277,7 @@ b3Vec3 b3Body_GetLocalPointVelocity( b3BodyId bodyId, b3Vec3 localPoint ) return b3Vec3_zero; } - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, body->localIndex ); b3Vec3 r = b3RotateVector( bodySim->transform.q, b3Sub( localPoint, bodySim->localCenter ) ); @@ -1382,7 +1295,7 @@ b3Vec3 b3Body_GetWorldPointVelocity( b3BodyId bodyId, b3Pos worldPoint ) return b3Vec3_zero; } - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, body->localIndex ); b3Vec3 r = b3SubPos( worldPoint, bodySim->center ); @@ -1476,7 +1389,7 @@ void b3Body_ApplyLinearImpulse( b3BodyId bodyId, b3Vec3 impulse, b3Pos point, bo if ( body->setIndex == b3_awakeSet ) { int localIndex = body->localIndex; - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodyState* state = b3Array_Get( set->bodyStates, localIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, localIndex ); @@ -1511,7 +1424,7 @@ void b3Body_ApplyLinearImpulseToCenter( b3BodyId bodyId, b3Vec3 impulse, bool wa if ( body->setIndex == b3_awakeSet ) { int localIndex = body->localIndex; - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodyState* state = b3Array_Get( set->bodyStates, localIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, localIndex ); state->linearVelocity = b3MulAdd( state->linearVelocity, bodySim->invMass, impulse ); @@ -1546,7 +1459,7 @@ void b3Body_ApplyAngularImpulse( b3BodyId bodyId, b3Vec3 impulse, bool wake ) if ( body->setIndex == b3_awakeSet ) { int localIndex = body->localIndex; - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodyState* state = b3Array_Get( set->bodyStates, localIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, localIndex ); @@ -1659,7 +1572,7 @@ void b3Body_SetType( b3BodyId bodyId, b3BodyType type ) b3WakeBody( world, body ); // Stage 4: move joints to temporary storage - b3SolverSet* staticSet = b3GetSolverSet( world, b3_staticSet ); + b3SolverSet* staticSet = b3Array_Get( world->solverSets, b3_staticSet ); int jointKey = body->headJointKey; while ( jointKey != B3_NULL_INDEX ) @@ -1689,7 +1602,7 @@ void b3Body_SetType( b3BodyId bodyId, b3BodyType type ) // It is necessary to transfer all joints to the static set // so they can be added to the constraint graph below and acquire consistent colors. - b3SolverSet* jointSourceSet = b3GetSolverSet( world, joint->setIndex ); + b3SolverSet* jointSourceSet = b3Array_Get( world->solverSets, joint->setIndex ); b3TransferJoint( world, staticSet, jointSourceSet, joint ); } @@ -1705,8 +1618,8 @@ void b3Body_SetType( b3BodyId bodyId, b3BodyType type ) body->flags &= ~b3_dynamicFlag; } - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); - b3SolverSet* sourceSet = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); + b3SolverSet* sourceSet = b3Array_Get( world->solverSets, body->setIndex ); b3SolverSet* targetSet = type == b3_staticBody ? staticSet : awakeSet; // Transfer body @@ -1768,7 +1681,7 @@ void b3Body_SetType( b3BodyId bodyId, b3BodyType type ) shapeId = shape->nextShapeId; b3DestroyShapeProxy( shape, &world->broadPhase ); bool forcePairCreation = true; - b3CreateShapeProxy( world, shape, type, transform, forcePairCreation ); + b3CreateShapeProxy( shape, &world->broadPhase, type, transform, forcePairCreation ); } // Relink all joints @@ -1816,14 +1729,27 @@ void b3Body_SetName( b3BodyId bodyId, const char* name ) B3_REC( world, BodySetName, bodyId, name ); b3Body* body = b3GetBodyFullId( world, bodyId ); - body->nameId = b3AddName( &world->names, name ); + + if ( name ) + { +#if defined( _MSC_VER ) + strncpy_s( body->name, B3_BODY_NAME_LENGTH + 1, name, B3_BODY_NAME_LENGTH ); +#else + strncpy( body->name, name, B3_BODY_NAME_LENGTH ); + body->name[B3_BODY_NAME_LENGTH] = 0; +#endif + } + else + { + memset( body->name, 0, sizeof( body->name ) ); + } } const char* b3Body_GetName( b3BodyId bodyId ) { b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); - return b3FindNameWithDefault( &world->names, body->nameId, "" ); + return body->name; } void b3Body_SetUserData( b3BodyId bodyId, void* userData ) @@ -1851,8 +1777,7 @@ b3Matrix3 b3Body_GetLocalRotationalInertia( b3BodyId bodyId ) { b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); - b3BodySim* bodySim = b3GetBodySim( world, body ); - return bodySim->inertia; + return body->inertia; } float b3Body_GetInverseMass( b3BodyId bodyId ) @@ -1871,7 +1796,7 @@ b3Matrix3 b3Body_GetWorldInverseRotationalInertia( b3BodyId bodyId ) return sim->invInertiaWorld; } -b3Vec3 b3Body_GetLocalCenter( b3BodyId bodyId ) +b3Vec3 b3Body_GetLocalCenterOfMass( b3BodyId bodyId ) { b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); @@ -1879,7 +1804,7 @@ b3Vec3 b3Body_GetLocalCenter( b3BodyId bodyId ) return bodySim->localCenter; } -b3Pos b3Body_GetWorldCenter( b3BodyId bodyId ) +b3Pos b3Body_GetWorldCenterOfMass( b3BodyId bodyId ) { b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); @@ -1904,80 +1829,16 @@ void b3Body_SetMassData( b3BodyId bodyId, b3MassData massData ) b3Body* body = b3GetBodyFullId( world, bodyId ); b3BodySim* bodySim = b3GetBodySim( world, body ); - // Mass is no longer dirty - body->flags &= ~b3_dirtyMass; - b3SyncBodyFlags( world, body ); - body->mass = massData.mass; + body->inertia = massData.inertia; bodySim->localCenter = massData.center; - b3Pos oldCenter = bodySim->center; b3Pos center = b3TransformWorldPoint( bodySim->transform, massData.center ); bodySim->center = center; bodySim->center0 = center; + bodySim->invMass = body->mass > 0.0f ? 1.0f / body->mass : 0.0f; - bodySim->inertia = massData.inertia; - - // Update center of mass velocity - b3BodyState* state = b3GetBodyState( world, body ); - if ( state != NULL ) - { - b3Vec3 deltaLinear = b3Cross( state->angularVelocity, b3SubPos( bodySim->center, oldCenter ) ); - state->linearVelocity = b3Add( state->linearVelocity, deltaLinear ); - } - - float det = b3Det( bodySim->inertia ); - B3_ASSERT( det >= 0.0f ); - - if ( det > 0.0f ) - { - // This call is faster than b3Invert - bodySim->invInertiaLocal = b3InvertT( bodySim->inertia ); - - b3Matrix3 rotationMatrix = b3MakeMatrixFromQuat( bodySim->transform.q ); - bodySim->invInertiaWorld = b3MulMM( b3MulMM( rotationMatrix, bodySim->invInertiaLocal ), b3Transpose( rotationMatrix ) ); - } - else - { - bodySim->invInertiaLocal = b3Mat3_zero; - bodySim->invInertiaWorld = b3Mat3_zero; - } - - // Apply fixed rotation - if ( ( bodySim->flags & b3_fixedRotation ) == b3_fixedRotation ) - { - bodySim->inertia = b3Mat3_zero; - bodySim->invInertiaLocal = b3Mat3_zero; - bodySim->invInertiaWorld = b3Mat3_zero; - } - - b3UpdateIsotropicInertia( world, body, bodySim ); - - // Update extents using supplied mass center. - bodySim->minExtent = B3_HUGE; - bodySim->maxExtent = b3Vec3_zero; - int shapeId = body->headShapeId; - while ( shapeId != B3_NULL_INDEX ) - { - const b3Shape* s = b3Array_Get( world->shapes, shapeId ); - b3ShapeExtent extent = b3ComputeShapeExtent( s, massData.center ); - bodySim->minExtent = b3MinFloat( bodySim->minExtent, extent.minExtent ); - bodySim->maxExtent = b3Max( bodySim->maxExtent, extent.maxExtent ); - shapeId = s->nextShapeId; - } - - // When the center of mass changes, any cached contact manifold becomes invalid. - int edgeKey = body->headContactKey; - while ( edgeKey != B3_NULL_INDEX ) - { - int contactId = edgeKey >> 1; - int edgeIndex = edgeKey & 1; - - b3Contact* contact = b3Array_Get( world->contacts, contactId ); - contact->flags &= ~b3_relativeTransformValid; - - edgeKey = contact->edges[edgeIndex].nextKey; - } + bodySim->invInertiaLocal = b3Det( body->inertia ) > 0.0f ? b3InvertT( body->inertia ) : b3Mat3_zero; } b3MassData b3Body_GetMassData( b3BodyId bodyId ) @@ -1985,7 +1846,7 @@ b3MassData b3Body_GetMassData( b3BodyId bodyId ) b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); b3BodySim* bodySim = b3GetBodySim( world, body ); - b3MassData massData = { body->mass, bodySim->localCenter, bodySim->inertia }; + b3MassData massData = { body->mass, bodySim->localCenter, body->inertia }; return massData; } @@ -2151,29 +2012,6 @@ float b3Body_GetSleepThreshold( b3BodyId bodyId ) return body->sleepThreshold; } -void b3Body_SetSafetyFactor( b3BodyId bodyId, float safetyFactor ) -{ - B3_ASSERT( b3IsValidFloat( safetyFactor ) && safetyFactor >= 0.0f ); - - b3World* world = b3GetUnlockedWorld( bodyId.world0 ); - if ( world == NULL ) - { - return; - } - - B3_REC( world, BodySetSafetyFactor, bodyId, safetyFactor ); - - b3Body* body = b3GetBodyFullId( world, bodyId ); - body->safetyFactor = safetyFactor; -} - -float b3Body_GetSafetyFactor( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - return body->safetyFactor; -} - void b3Body_EnableSleep( b3BodyId bodyId, bool enableSleep ) { b3World* world = b3GetUnlockedWorld( bodyId.world0 ); @@ -2232,10 +2070,10 @@ void b3Body_Disable( b3BodyId bodyId ) b3DestroyBodyContacts( world, body, wakeBodies ); // The current solver set of the body - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, body->setIndex ); // Disabled bodies and connected joints are moved to the disabled set - b3SolverSet* disabledSet = b3GetSolverSet( world, b3_disabledSet ); + b3SolverSet* disabledSet = b3Array_Get( world->solverSets, b3_disabledSet ); // Unlink joints and transfer them to the disabled set int jointKey = body->headJointKey; @@ -2253,13 +2091,13 @@ void b3Body_Disable( b3BodyId bodyId ) continue; } - B3_ASSERT( joint->setIndex == set->setIndex || set->setIndex == b3_staticSet || joint->setIndex == b3_staticSet ); + B3_ASSERT( joint->setIndex == set->setIndex || set->setIndex == b3_staticSet ); // Remove joint from island b3UnlinkJoint( world, joint ); // Transfer joint to disabled set - b3SolverSet* jointSet = b3GetSolverSet( world, joint->setIndex ); + b3SolverSet* jointSet = b3Array_Get( world->solverSets, joint->setIndex ); b3TransferJoint( world, disabledSet, jointSet, joint ); } @@ -2300,9 +2138,9 @@ void b3Body_Enable( b3BodyId bodyId ) return; } - b3SolverSet* disabledSet = b3GetSolverSet( world, b3_disabledSet ); + b3SolverSet* disabledSet = b3Array_Get( world->solverSets, b3_disabledSet ); int setId = body->type == b3_staticBody ? b3_staticSet : b3_awakeSet; - b3SolverSet* targetSet = b3GetSolverSet( world, setId ); + b3SolverSet* targetSet = b3Array_Get( world->solverSets, setId ); b3TransferBody( world, targetSet, disabledSet, body ); @@ -2317,7 +2155,7 @@ void b3Body_Enable( b3BodyId bodyId ) b3Shape* shape = b3Array_Get( world->shapes, shapeId ); shapeId = shape->nextShapeId; - b3CreateShapeProxy( world, shape, proxyType, transform, forcePairCreation ); + b3CreateShapeProxy( shape, &world->broadPhase, proxyType, transform, forcePairCreation ); } if ( setId != b3_staticSet ) @@ -2350,7 +2188,7 @@ void b3Body_Enable( b3BodyId bodyId ) // Transfer joint first int jointSetId; - if ( bodyA->type != b3_dynamicBody && bodyB->type != b3_dynamicBody ) + if ( bodyA->setIndex == b3_staticSet && bodyB->setIndex == b3_staticSet ) { jointSetId = b3_staticSet; } @@ -2363,7 +2201,7 @@ void b3Body_Enable( b3BodyId bodyId ) jointSetId = bodyA->setIndex; } - b3SolverSet* jointSet = b3GetSolverSet( world, jointSetId ); + b3SolverSet* jointSet = b3Array_Get( world->solverSets, jointSetId ); b3TransferJoint( world, jointSet, disabledSet, joint ); // Now that the joint is in the correct set, I can link the joint in the island. @@ -2495,37 +2333,6 @@ bool b3Body_IsBullet( b3BodyId bodyId ) return ( body->flags & b3_isBullet ) != 0; } -void b3Body_AllowFastRotation( b3BodyId bodyId, bool flag ) -{ - b3World* world = b3GetUnlockedWorld( bodyId.world0 ); - if ( world == NULL ) - { - return; - } - - B3_REC( world, BodyAllowFastRotation, bodyId, flag ); - - uint32_t newFlag = flag ? b3_allowFastRotation : 0; - - b3Body* body = b3GetBodyFullId( world, bodyId ); - if ( ( body->flags & b3_allowFastRotation ) == newFlag ) - { - return; - } - - body->flags &= ~b3_allowFastRotation; - body->flags |= newFlag; - - b3SyncBodyFlags( world, body ); -} - -bool b3Body_IsFastRotationAllowed( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - return ( body->flags & b3_allowFastRotation ) != 0; -} - void b3Body_EnableContactRecycling( b3BodyId bodyId, bool flag ) { b3World* world = b3GetUnlockedWorld( bodyId.world0 ); @@ -2536,15 +2343,15 @@ void b3Body_EnableContactRecycling( b3BodyId bodyId, bool flag ) B3_REC( world, BodyEnableContactRecycling, bodyId, flag ); - uint32_t newFlag = flag ? b3_enableContactRecycling : 0; + uint32_t newFlag = flag ? b3_bodyEnableContactRecycling : 0; b3Body* body = b3GetBodyFullId( world, bodyId ); - if ( ( body->flags & b3_enableContactRecycling ) == newFlag ) + if ( ( body->flags & b3_bodyEnableContactRecycling ) == newFlag ) { return; } - body->flags &= ~b3_enableContactRecycling; + body->flags &= ~b3_bodyEnableContactRecycling; body->flags |= newFlag; b3SyncBodyFlags( world, body ); @@ -2554,21 +2361,21 @@ bool b3Body_IsContactRecyclingEnabled( b3BodyId bodyId ) { b3World* world = b3GetWorld( bodyId.world0 ); b3Body* body = b3GetBodyFullId( world, bodyId ); - return ( body->flags & b3_enableContactRecycling ) != 0; + return ( body->flags & b3_bodyEnableContactRecycling ) != 0; } -void b3Body_EnableHitEvents( b3BodyId bodyId, bool flag ) +void b3Body_EnableHitEvents( b3BodyId bodyId, bool enableHitEvents ) { b3World* world = b3GetWorld( bodyId.world0 ); - B3_REC( world, BodyEnableHitEvents, bodyId, flag ); + B3_REC( world, BodyEnableHitEvents, bodyId, enableHitEvents ); b3Body* body = b3GetBodyFullId( world, bodyId ); int shapeId = body->headShapeId; while ( shapeId != B3_NULL_INDEX ) { b3Shape* shape = b3Array_Get( world->shapes, shapeId ); - shape->flags = flag ? shape->flags | b3_enableHitEvents : shape->flags & ~b3_enableHitEvents; + shape->enableHitEvents = enableHitEvents; shapeId = shape->nextShapeId; } } @@ -2673,27 +2480,3 @@ bool b3ShouldBodiesCollide( b3World* world, b3Body* bodyA, b3Body* bodyB ) return true; } - -float b3Body_GetMinExtent( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - b3BodySim* bodySim = b3GetBodySim( world, body ); - return bodySim->minExtent; -} - -b3Vec3 b3Body_GetMaxExtent( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - b3BodySim* bodySim = b3GetBodySim( world, body ); - return bodySim->maxExtent; -} - -b3Vec3 b3Body_GetMaxExtentOrigin( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - b3BodySim* bodySim = b3GetBodySim( world, body ); - return b3Add( bodySim->maxExtent, b3Abs( bodySim->localCenter ) ); -} diff --git a/src/body.h b/src/body.h index b03063d..bcba5b7 100644 --- a/src/body.h +++ b/src/body.h @@ -3,8 +3,6 @@ #pragma once -#include "physics_world.h" - #include "box3d/constants.h" #include "box3d/math_functions.h" #include "box3d/types.h" @@ -31,7 +29,7 @@ enum b3BodyFlags // This body has fixed rotation around the z-axis b3_lockAngularZ = 0x00000020, - // This flag is used for debug draw and contact recycling. Only lives on b3BodySim. + // This flag is used for debug draw b3_isFast = 0x00000040, // This dynamic body does a final CCD pass against all body types, but not other bullets @@ -40,15 +38,14 @@ enum b3BodyFlags // This body was speed capped in the current time step b3_isSpeedCapped = 0x00000100, - // This body had a time of impact event in the current time step (body sim only) + // This body had a time of impact event in the current time step b3_hadTimeOfImpact = 0x00000200, // This body has no limit on angular velocity b3_allowFastRotation = 0x00000400, - // This bullet body needs to have its AABB increased. Needed because bullets don't follow - // the standard broad-phase update. - b3_enlargeBulletBounds = 0x00000800, + // This body need's to have its AABB increased + b3_enlargeBounds = 0x00000800, // This body is dynamic so the solver should write to it. // This prevents writing to kinematic bodies that causes a multithreaded sharing @@ -58,13 +55,7 @@ enum b3BodyFlags b3_enableSleep = 0x00002000, - b3_enableContactRecycling = 0x00004000, - - // The user deferred mass computation via the updateBodyMass shape option and mass - // data still hasn't been set. - b3_dirtyMass = 0x00008000, - - b3_enableGyroscopicTorque = 0x00010000, + b3_bodyEnableContactRecycling = 0x00004000, // All lock flags b3_allLocks = b3_lockLinearX | b3_lockLinearY | b3_lockLinearZ | b3_lockAngularX | b3_lockAngularY | b3_lockAngularZ, @@ -73,7 +64,7 @@ enum b3BodyFlags b3_fixedRotation = b3_lockAngularX | b3_lockAngularY | b3_lockAngularZ, // These flags are transient per time step. These may be different across b3Body, b3BodySim, and b3BodyState. - b3_bodyTransientFlags = b3_isSpeedCapped | b3_hadTimeOfImpact, + b3_bodyTransientFlags = b3_isFast | b3_isSpeedCapped | b3_hadTimeOfImpact, }; // Body organizational details that are not used in the solver. @@ -112,10 +103,12 @@ typedef struct b3Body float sleepThreshold; float sleepTime; - float sleepVelocity; - float safetyFactor; + float mass; + // local space inertia + b3Matrix3 inertia; + // this is used to adjust the fellAsleep flag in the body move array int bodyMoveIndex; @@ -123,13 +116,14 @@ typedef struct b3Body // b3BodyFlags uint32_t flags; - uint32_t nameId; b3BodyType type; // This is monotonically advanced when a body is allocated in this slot // Used to check for invalid b3BodyId uint16_t generation; + + char name[B3_BODY_NAME_LENGTH + 1]; } b3Body; // Body State @@ -158,30 +152,28 @@ typedef struct b3Body // according to substep progress. Contacts have reduced stability when anchors are rotated during substeps, especially for // round shapes. // -// 64 bytes +// 56 bytes +// todo_erin measure perf padding to 64 bytes typedef struct b3BodyState { - b3Vec3 linearVelocity; // 12 - float padding1; - + b3Vec3 linearVelocity; // 12 b3Vec3 angularVelocity; // 12 - float padding2; // Using delta position reduces round-off error far from the origin b3Vec3 deltaPosition; // 12 - // b3BodyFlags - // Important flags: locking, dynamic - uint32_t flags; // 4 - // Using delta rotation because I cannot access the full rotation on static bodies in // the solver and must use zero delta rotation for static bodies (c,s) = (1,0) b3Quat deltaRotation; // 16 + + // b3BodyFlags + // Important flags: locking, dynamic + uint32_t flags; // 4 } b3BodyState; // Identity body state, notice the deltaRotation is identity static const b3BodyState b3_identityBodyState = { - { 0.0f, 0.0f, 0.0f }, 0.0f, { 0.0f, 0.0f, 0.0f }, 0.0f, { 0.0f, 0.0f, 0.0f }, 0, { { 0.0f, 0.0f, 0.0f }, 1.0f }, + { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, { { 0.0f, 0.0f, 0.0f }, 1.0f }, 0, }; // Body simulation data used for integration of position and velocity @@ -194,12 +186,6 @@ typedef struct b3BodySim // center of mass position in world space b3Pos center; - // b3BodyFlags - uint32_t flags; - - float minExtent; - b3Vec3 maxExtent; - // previous rotation and COM for TOI b3Quat rotation0; b3Pos center0; @@ -212,20 +198,23 @@ typedef struct b3BodySim float invMass; - // Local space inertia - b3Matrix3 inertia; - // Rotational inertia about the center of mass. The world space inverse inertia tensor // must be updated whenever the body rotation is modified. b3Matrix3 invInertiaLocal; b3Matrix3 invInertiaWorld; + float minExtent; + b3Vec3 maxExtent; + float maxAngularVelocity; float linearDamping; float angularDamping; float gravityScale; // Index of b3Body int bodyId; + + // b3BodyFlags + uint32_t flags; } b3BodySim; // Get a validated body from a world using an id. @@ -248,39 +237,7 @@ bool b3WakeBody( b3World* world, b3Body* body ); bool b3WakeBodyWithLock( b3World* world, b3Body* body ); void b3UpdateBodyMassData( b3World* world, b3Body* body ); -void b3SyncBodyFlags( b3World* world, b3Body* body ); -void b3RefreshBodyContactIndices( b3World* world, b3Body* body ); - -// Encode the body sim index for storage in the contact. -static inline int b3EncodeBodySimIndex( const b3Body* body ) -{ - if ( body->setIndex == b3_awakeSet ) - { - return body->localIndex; - } - - if ( body->setIndex == b3_staticSet ) - { - return -( body->localIndex + 2 ); - } - - return B3_NULL_INDEX; -} - -static inline bool b3IsStaticSimIndex( int encodedBodySimIndex ) -{ - return encodedBodySimIndex < B3_NULL_INDEX; -} - -static inline int b3DecodeAwakeIndex( int encodedBodySimIndex ) -{ - return encodedBodySimIndex >= 0 ? encodedBodySimIndex : B3_NULL_INDEX; -} - -static inline int b3SleepBodySimIndex( int encodedBodySimIndex ) -{ - return encodedBodySimIndex >= 0 ? B3_NULL_INDEX : encodedBodySimIndex; -} +void b3DumpBody( b3World* world, b3Body* body ); // Make a sweep relative to a base position to keep TOI in float precision far from the origin. static inline b3Sweep b3MakeRelativeSweep( const b3BodySim* bodySim, b3Pos base ) diff --git a/src/box3d.natvis b/src/box3d.natvis index 4283388..68d36e1 100644 --- a/src/box3d.natvis +++ b/src/box3d.natvis @@ -83,10 +83,6 @@ - - s: {separation} - - type: {type} diff --git a/src/box3d.pc.in b/src/box3d.pc.in deleted file mode 100644 index 01a507b..0000000 --- a/src/box3d.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -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/broad_phase.c b/src/broad_phase.c index 1f5ce16..a14a1a2 100644 --- a/src/broad_phase.c +++ b/src/broad_phase.c @@ -6,25 +6,28 @@ #include "aabb.h" #include "arena_allocator.h" #include "body.h" -#include "compound.h" #include "contact.h" #include "core.h" -#include "dynamic_tree.h" #include "parallel_for.h" #include "physics_world.h" #include "platform.h" -#include "qsort.h" #include "shape.h" -#include "simd.h" -#include #include void b3CreateBroadPhase( b3BroadPhase* bp, const b3Capacity* capacity ) { _Static_assert( b3_bodyTypeCount == 3, "must be three body types" ); - bp->pairSet = b3CreateSet( b3MaxInt( 32, 2 * capacity->contactCount ) ); + bp->movedProxies[b3_staticBody] = b3CreateBitSet( b3MaxInt( 16, capacity->staticShapeCount ) ); + bp->movedProxies[b3_kinematicBody] = b3CreateBitSet( 16 ); + bp->movedProxies[b3_dynamicBody] = b3CreateBitSet( b3MaxInt( 16, capacity->dynamicShapeCount ) ); + b3Array_Reserve( bp->moveArray, capacity->dynamicShapeCount ); + bp->moveResults = NULL; + bp->movePairs = NULL; + bp->movePairCapacity = 0; + b3AtomicStoreInt( &bp->movePairIndex, 0 ); + bp->pairSet = b3CreateSet( 2 * capacity->contactCount ); int staticCapacity = b3MaxInt( 16, capacity->staticShapeCount ); bp->trees[b3_staticBody] = b3DynamicTree_Create( staticCapacity ); @@ -34,9 +37,6 @@ void b3CreateBroadPhase( b3BroadPhase* bp, const b3Capacity* capacity ) int dynamicCapacity = b3MaxInt( 16, capacity->dynamicShapeCount ); bp->trees[b3_dynamicBody] = b3DynamicTree_Create( dynamicCapacity ); - - bp->movedSiblings = NULL; - bp->crossContext = NULL; } void b3DestroyBroadPhase( b3BroadPhase* bp ) @@ -46,29 +46,63 @@ void b3DestroyBroadPhase( b3BroadPhase* bp ) b3DynamicTree_Destroy( bp->trees + i ); } + for ( int i = 0; i < b3_bodyTypeCount; ++i ) + { + b3DestroyBitSet( &bp->movedProxies[i] ); + } + b3Array_Destroy( bp->moveArray ); b3DestroySet( &bp->pairSet ); + *bp = (b3BroadPhase){ 0 }; + memset( bp, 0, sizeof( b3BroadPhase ) ); } -int b3BroadPhase_CreateProxy( b3BroadPhase* bp, b3BodyType proxyType, b3AABB aabb, uint64_t categoryBits, - int shapeIndex, bool forcePairCreation ) +static void b3UnBufferMove( b3BroadPhase* bp, int proxyKey ) +{ + b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); + int proxyId = B3_PROXY_ID( proxyKey ); + b3BitSet* set = &bp->movedProxies[proxyType]; + + if ( b3GetBit( set, proxyId ) ) + { + b3ClearBit( set, proxyId ); + + // Purge from move buffer. Linear search. + // todo if I can iterate the move set then I don't need the moveArray + int count = bp->moveArray.count; + for ( int i = 0; i < count; ++i ) + { + if ( bp->moveArray.data[i] == proxyKey ) + { + b3Array_RemoveSwap( bp->moveArray, i ); + break; + } + } + } +} + +int b3BroadPhase_CreateProxy( b3BroadPhase* bp, b3BodyType proxyType, b3AABB aabb, uint64_t categoryBits, int shapeIndex, + bool forcePairCreation ) { B3_ASSERT( 0 <= proxyType && proxyType < b3_bodyTypeCount ); - - bool mark = ( proxyType != b3_staticBody || forcePairCreation ); - - int proxyId = b3CreateTreeProxyInternal( bp->trees + proxyType, aabb, categoryBits, shapeIndex, mark ); + int proxyId = b3DynamicTree_CreateProxy( bp->trees + proxyType, aabb, categoryBits, shapeIndex ); int proxyKey = B3_PROXY_KEY( proxyId, proxyType ); + if ( proxyType != b3_staticBody || forcePairCreation ) + { + b3BufferMove( bp, proxyKey ); + } return proxyKey; } void b3BroadPhase_DestroyProxy( b3BroadPhase* bp, int proxyKey ) { + b3UnBufferMove( bp, proxyKey ); + b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); int proxyId = B3_PROXY_ID( proxyKey ); - B3_ASSERT( 0 <= proxyType && proxyType < b3_bodyTypeCount ); + B3_ASSERT( 0 <= proxyType && proxyType <= b3_bodyTypeCount ); b3DynamicTree_DestroyProxy( bp->trees + proxyType, proxyId ); } @@ -77,94 +111,165 @@ void b3BroadPhase_MoveProxy( b3BroadPhase* bp, int proxyKey, b3AABB aabb ) b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); int proxyId = B3_PROXY_ID( proxyKey ); - bool mark = true; - b3DynamicTree_MoveProxyInternal( bp->trees + proxyType, proxyId, aabb, mark ); + b3DynamicTree_MoveProxy( bp->trees + proxyType, proxyId, aabb ); + b3BufferMove( bp, proxyKey ); } -// Gather the sibling pairs with a moved node. This is done serially, it is cache friendly. -static int b3GatherMovedSiblings( const b3DynamicTree* tree, int* pairIndices ) +void b3BroadPhase_EnlargeProxy( b3BroadPhase* bp, int proxyKey, b3AABB aabb ) { - const b3TreeNode* nodes = tree->nodes; - int nodeEnd = tree->nodeEnd; + B3_ASSERT( proxyKey != B3_NULL_INDEX ); + int typeIndex = B3_PROXY_TYPE( proxyKey ); + int proxyId = B3_PROXY_ID( proxyKey ); - int count = 0; + B3_ASSERT( typeIndex != b3_staticBody ); - // Skip the root. - for ( int pair = 2; pair < nodeEnd; pair += 2 ) + b3DynamicTree_EnlargeProxy( bp->trees + typeIndex, proxyId, aabb ); + b3BufferMove( bp, proxyKey ); +} + +typedef struct b3MovePair +{ + int shapeIndexA; + int shapeIndexB; + int childIndex; + b3MovePair* next; + bool heap; +} b3MovePair; + +typedef struct b3MoveResult +{ + b3MovePair* pairList; +} b3MoveResult; + +typedef struct b3QueryPairContext +{ + b3World* world; + b3MoveResult* moveResult; + b3AABB aabb; + b3BodyType queryTreeType; + int queryProxyKey; + int queryShapeIndex; + + int compoundProxyId; + int compoundShapeIndex; +} b3QueryPairContext; + +// This is called from b3DynamicTree::Query when we are gathering pairs. +static bool b3PairQueryCallback( int proxyId, uint64_t userData, void* context ) +{ + b3QueryPairContext* queryContext = (b3QueryPairContext*)context; + b3World* world = queryContext->world; + int shapeIndex; + int childIndex = 0; + + if ( queryContext->compoundShapeIndex == B3_NULL_INDEX ) { - // Push when either sibling moved. - if ( ( nodes[pair].flagIndex | nodes[pair + 1].flagIndex ) & B3_MOVED_NODE ) + // Outer query: userData is a shape index. + shapeIndex = (int)userData; + + // A proxy cannot form a pair with itself. + if ( shapeIndex == queryContext->queryShapeIndex ) { - pairIndices[count++] = pair; + return true; + } + + b3Shape* shape = b3Array_Get( world->shapes, shapeIndex ); + if ( shape->type == b3_compoundShape ) + { + // Query bounds are float world space, so the demoted transform is the matching float frame + b3Transform compoundTransform = b3ToRelativeTransform( b3GetBodyTransform( world, shape->bodyId ), b3Pos_zero ); + b3AABB localAABB = b3AABB_Transform( b3InvertTransform( compoundTransform ), queryContext->aabb ); + + // recurse + queryContext->compoundShapeIndex = shapeIndex; + queryContext->compoundProxyId = proxyId; + + b3DynamicTree_Query( &shape->compound->tree, localAABB, B3_DEFAULT_MASK_BITS, false, b3PairQueryCallback, context ); + queryContext->compoundShapeIndex = B3_NULL_INDEX; + queryContext->compoundProxyId = B3_NULL_INDEX; + return true; + } + } + else + { + // Inner query into a compound shape: userData is the compound child index, not a shape + // index, so do not compare it against queryShapeIndex. + shapeIndex = queryContext->compoundShapeIndex; + proxyId = queryContext->compoundProxyId; + childIndex = (int)userData; + } + + b3BroadPhase* broadPhase = &queryContext->world->broadPhase; + + int proxyKey = B3_PROXY_KEY( proxyId, queryContext->queryTreeType ); + int queryProxyKey = queryContext->queryProxyKey; + + // A proxy cannot form a pair with itself. + B3_ASSERT( proxyKey != queryContext->queryProxyKey ); + + b3BodyType treeType = queryContext->queryTreeType; + b3BodyType queryProxyType = B3_PROXY_TYPE( queryProxyKey ); + + // De-duplication + // It is important to prevent duplicate contacts from being created. Ideally I can prevent duplicates + // early and in the worker. Most of the time the movedProxies bit sets contain dynamic and kinematic + // proxies, but sometimes static proxies are in there too (b3ShapeDef::invokeContactCreation or a + // modified static shape), so we always have to check. + + // Is this proxy also moving? + if ( queryProxyType == b3_dynamicBody ) + { + if ( treeType == b3_dynamicBody && proxyKey < queryProxyKey ) + { + bool moved = b3GetBit( &broadPhase->movedProxies[treeType], proxyId ); + if ( moved ) + { + // Both proxies are moving. Avoid duplicate pairs. + return true; + } + } + } + else + { + B3_ASSERT( treeType == b3_dynamicBody ); + bool moved = b3GetBit( &broadPhase->movedProxies[treeType], proxyId ); + if ( moved ) + { + // Both proxies are moving. Avoid duplicate pairs. + return true; } } - return count; -} + uint64_t pairKey = b3ShapePairKey( shapeIndex, queryContext->queryShapeIndex, childIndex ); + if ( b3ContainsKey( &broadPhase->pairSet, pairKey ) ) + { + // contact exists + return true; + } -#define B3_CANDIDATE_BATCH 32 - -typedef struct b3CandidatePair -{ - int shapeIdA; - int shapeIdB; -} b3CandidatePair; - -typedef struct b3PairContext -{ - b3World* world; - b3Array( uint64_t ) * pairKeys; - b3CandidatePair batch[B3_CANDIDATE_BATCH]; - int batchCount; - - // Compound shapes are static only, so only the static cross pass can meet one. Elsewhere - // this stays false and the batch never reads a shape type. - bool checkCompounds; -} b3PairContext; - -typedef struct b3NodePair -{ - b3TreeNode a; - b3TreeNode b; -} b3NodePair; - -typedef struct b3IndexPair -{ - int a, b; -} b3IndexPair; - -static inline void b3PrefetchHash( b3HashSet* set, uint32_t hash ) -{ - uint32_t capacity = set->capacity; - uint32_t index = hash & ( capacity - 1 ); - b3Prefetch( set->items + index ); -} - -// The shape pair gauntlet. Everything here is a property of the pair, not of a compound child, -// so a compound runs it once for the whole pair. -static bool b3ShouldCreatePair( b3World* world, int shapeIdA, int shapeIdB ) -{ + // Order shapes so that B3_SHAPE_PAIR_KEY works correctly + int shapeIdA = shapeIndex; + int shapeIdB = queryContext->queryShapeIndex; b3Shape* shapeA = b3Array_Get( world->shapes, shapeIdA ); b3Shape* shapeB = b3Array_Get( world->shapes, shapeIdB ); - int bodyIdA = shapeA->bodyId; int bodyIdB = shapeB->bodyId; // Are the shapes on the same body? if ( bodyIdA == bodyIdB ) { - return false; + return true; } // Sensors are handled elsewhere if ( shapeA->sensorIndex != B3_NULL_INDEX || shapeB->sensorIndex != B3_NULL_INDEX ) { - return false; + return true; } if ( b3ShouldShapesCollide( shapeA->filter, shapeB->filter ) == false ) { - return false; + return true; } // Does a joint override collision? @@ -172,456 +277,111 @@ static bool b3ShouldCreatePair( b3World* world, int shapeIdA, int shapeIdB ) b3Body* bodyB = b3Array_Get( world->bodies, bodyIdB ); if ( b3ShouldBodiesCollide( world, bodyA, bodyB ) == false ) { - return false; + return true; } // Custom user filter - if ( ( shapeA->flags & b3_enableCustomFiltering ) || ( shapeB->flags & b3_enableCustomFiltering ) ) + if ( shapeA->enableCustomFiltering || shapeB->enableCustomFiltering ) { - b3CustomFilterFcn* customFilterFcn = world->customFilterFcn; + b3CustomFilterFcn* customFilterFcn = queryContext->world->customFilterFcn; if ( customFilterFcn != NULL ) { b3ShapeId idA = { shapeIdA + 1, world->worldId, shapeA->generation }; b3ShapeId idB = { shapeIdB + 1, world->worldId, shapeB->generation }; - if ( customFilterFcn( idA, idB, world->customFilterContext ) == false ) + bool shouldCollide = customFilterFcn( idA, idB, queryContext->world->customFilterContext ); + if ( shouldCollide == false ) { - return false; + return true; } } } - return true; -} + // todo per thread to eliminate atomic? + int pairIndex = b3AtomicFetchAddInt( &broadPhase->movePairIndex, 1 ); -typedef struct b3CompoundPairContext -{ - b3PairContext* pairContext; - b3HashSet* pairSet; - int compoundShapeId; - int otherShapeId; -} b3CompoundPairContext; - -static bool b3CompoundChildCallback( int proxyId, uint64_t userData, void* context ) -{ - B3_UNUSED( proxyId ); - - b3CompoundPairContext* compoundContext = context; - int childIndex = (int)userData; - - uint64_t key = b3ShapePairKey( compoundContext->compoundShapeId, compoundContext->otherShapeId, childIndex ); - if ( b3ContainsKey( compoundContext->pairSet, key ) == false ) + b3MovePair* pair; + if ( pairIndex < broadPhase->movePairCapacity ) { - b3Array_Push( *compoundContext->pairContext->pairKeys, key ); - } - - return true; -} - -// One of the two shapes is a compound, so the pair becomes one pair per overlapping child. The -// child boxes live in the compound frame, so the other shape's box has to be demoted and pulled -// into that frame first. -static void b3EmitCompoundPairs( b3PairContext* context, int compoundShapeId, int otherShapeId ) -{ - b3World* world = context->world; - - b3Shape* compoundShape = b3Array_Get( world->shapes, compoundShapeId ); - b3Shape* otherShape = b3Array_Get( world->shapes, otherShapeId ); - - int otherProxyKey = otherShape->proxyKey; - B3_ASSERT( otherProxyKey != B3_NULL_INDEX ); - b3AABB otherAABB = - b3DynamicTree_GetAABB( world->broadPhase.trees + B3_PROXY_TYPE( otherProxyKey ), B3_PROXY_ID( otherProxyKey ) ); - - // Query bounds are float world space, so the demoted transform is the matching float frame - b3Transform compoundTransform = - b3ToRelativeTransform( b3GetBodyTransform( world, compoundShape->bodyId ), b3Pos_zero ); - b3AABB localAABB = b3AABB_Transform( b3InvertTransform( compoundTransform ), otherAABB ); - - b3CompoundPairContext compoundContext = { - .pairContext = context, - .pairSet = &world->broadPhase.pairSet, - .compoundShapeId = compoundShapeId, - .otherShapeId = otherShapeId, - }; - - int startCount = context->pairKeys->count; - - b3TreeView view = b3GetCompoundTreeView( compoundShape->compound ); - b3TreeView_Query( &view, localAABB, B3_DEFAULT_MASK_BITS, false, b3CompoundChildCallback, &compoundContext ); - - if ( context->pairKeys->count > startCount && b3ShouldCreatePair( world, compoundShapeId, otherShapeId ) == false ) - { - b3Array_Resize( *context->pairKeys, startCount ); - } -} - -static void b3FlushCandidatePairs( b3PairContext* context ) -{ - b3World* world = context->world; - b3BroadPhase* bp = &world->broadPhase; - - int count1 = context->batchCount; - context->batchCount = 0; - - b3CandidatePair plain[B3_CANDIDATE_BATCH]; - int plainCount = 0; - - if ( context->checkCompounds ) - { - // A compound expands into one pair per child, so its key is not known yet and it cannot - // ride the batched cull below. - const b3Shape* shapes = world->shapes.data; - for ( int i = 0; i < count1; ++i ) - { - b3CandidatePair candidate = context->batch[i]; - bool compoundA = shapes[candidate.shapeIdA].type == b3_compoundShape; - bool compoundB = shapes[candidate.shapeIdB].type == b3_compoundShape; - - if ( compoundA ) - { - // Compound versus compound is not supported - B3_ASSERT( compoundB == false ); - b3EmitCompoundPairs( context, candidate.shapeIdA, candidate.shapeIdB ); - } - else if ( compoundB ) - { - b3EmitCompoundPairs( context, candidate.shapeIdB, candidate.shapeIdA ); - } - else - { - plain[plainCount] = candidate; - plainCount += 1; - } - } + pair = broadPhase->movePairs + pairIndex; + pair->heap = false; } else { - memcpy( plain, context->batch, count1 * sizeof( b3CandidatePair ) ); - plainCount = count1; + // todo experimenting with ignoring this pair if we ran out of space + return true; + // pair = (b3MovePair*)b3Alloc( sizeof( b3MovePair ) ); + // pair->heap = true; } - // Prefetch hash set entries. Less than 1% gain in Box2D but the 3D shape is fatter. - uint64_t keys[B3_CANDIDATE_BATCH]; - uint32_t hashes[B3_CANDIDATE_BATCH]; - for ( int i = 0; i < plainCount; ++i ) - { - keys[i] = b3ShapePairKey( plain[i].shapeIdA, plain[i].shapeIdB, 0 ); - hashes[i] = b3KeyHash( keys[i] ); - b3PrefetchHash( &bp->pairSet, hashes[i] ); - } + pair->shapeIndexA = shapeIdA; + pair->shapeIndexB = shapeIdB; + pair->childIndex = childIndex; + pair->next = queryContext->moveResult->pairList; + queryContext->moveResult->pairList = pair; - // Cull existing pairs. - b3CandidatePair candidates[B3_CANDIDATE_BATCH]; - int count2 = 0; - for ( int i = 0; i < plainCount; ++i ) - { - if ( b3ContainsHashedKey( &bp->pairSet, keys[i], hashes[i] ) == false ) - { - candidates[count2] = plain[i]; - keys[count2] = keys[i]; - count2 += 1; - } - } - - // Prefetch shapes. - const b3Shape* shapes = world->shapes.data; - for ( int i = 0; i < count2; ++i ) - { - b3Prefetch( shapes + candidates[i].shapeIdA ); - b3Prefetch( shapes + candidates[i].shapeIdB ); - } - - // Filter candidates. - for ( int i = 0; i < count2; ++i ) - { - if ( b3ShouldCreatePair( world, candidates[i].shapeIdA, candidates[i].shapeIdB ) ) - { - // The pair passed the gauntlet. A new contact will be created. - b3Array_Push( *context->pairKeys, keys[i] ); - } - } + // continue the query + return true; } -B3_FORCE_INLINE void b3AddCandidatePair( int shapeIdA, int shapeIdB, b3PairContext* context ) +static void b3FindPairsTask( int startIndex, int endIndex, int workerIndex, void* context ) { - // Follow shape index order. - b3CandidatePair* candidate = context->batch + context->batchCount; - candidate->shapeIdA = b3MinInt( shapeIdA, shapeIdB ); - candidate->shapeIdB = b3MaxInt( shapeIdA, shapeIdB ); - context->batchCount += 1; - if ( context->batchCount == B3_CANDIDATE_BATCH ) - { - b3FlushCandidatePairs( context ); - } -} + b3TracyCZoneNC( pair_task, "Pair Task", b3_colorAquamarine, true ); -// Did either move and if so do they overlap? -B3_FORCE_INLINE bool b3TestPair( const b3TreeNode* a, const b3TreeNode* b ) -{ - if ( ( ( a->flagIndex | b->flagIndex ) & B3_MOVED_NODE ) == 0 ) - { - return false; - } + B3_UNUSED( workerIndex ); - return b3OverlapV( &a->aabb, &b->aabb ); -} - -static void b3CollideProxyAndSubtree( const b3TreeNode* proxy, const b3TreeNode* nodes, int pair, - b3PairContext* context ) -{ - uint32_t proxyMark = proxy->flagIndex & B3_MOVED_NODE; - b3AABBV boxv = b3LoadAABBV( &proxy->aabb ); - int shapeId = proxy->shapeIndex; - - int stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - stack[stackCount++] = pair; - - while ( stackCount > 0 ) - { - pair = stack[--stackCount]; - for ( int i = 0; i < 2; ++i ) - { - const b3TreeNode* node = nodes + pair + i; - if ( ( ( node->flagIndex | proxyMark ) & B3_MOVED_NODE ) == 0 ) - { - continue; - } - - if ( b3OverlapNode( boxv, node ) == false ) - { - continue; - } - - if ( b3IsLeaf( node ) ) - { - b3AddCandidatePair( shapeId, node->shapeIndex, context ); - } - else - { - if ( stackCount < B3_TREE_STACK_SIZE ) - { - stack[stackCount++] = b3GetLeftChild( node ); - } - else - { - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); - } - } - } - } -} - -// Helper for b3CollideCrossPairs to avoid code duplication. -B3_FORCE_INLINE void b3VisitPair( const b3TreeNode* arrayA, const b3TreeNode* arrayB, const b3TreeNode* nodeA, - const b3TreeNode* nodeB, b3IndexPair* stack, int* stackCount, b3PairContext* context ) -{ - if ( b3TestPair( nodeA, nodeB ) == false ) - { - return; - } - - bool leafA = b3IsLeaf( nodeA ); - bool leafB = b3IsLeaf( nodeB ); - if ( leafA && leafB ) - { - b3AddCandidatePair( nodeA->shapeIndex, nodeB->shapeIndex, context ); - } - else if ( leafA ) - { - b3CollideProxyAndSubtree( nodeA, arrayB, b3GetLeftChild( nodeB ), context ); - } - else if ( leafB ) - { - b3CollideProxyAndSubtree( nodeB, arrayA, b3GetLeftChild( nodeA ), context ); - } - else - { - if ( *stackCount < B3_TREE_STACK_SIZE ) - { - stack[*stackCount] = - B3_LITERAL( b3IndexPair ){ .a = b3GetLeftChild( nodeA ), .b = b3GetLeftChild( nodeB ) }; - *stackCount += 1; - } - else - { - B3_ASSERT( *stackCount < B3_TREE_STACK_SIZE ); - } - } -} - -// This collides two sub-trees against each other. They can live in the same dynamic tree. -// This can only generate pairs cross sub-tree, but not within a sub-tree. This fact means -// this does not generate duplicate pairs. -// For example consider the full binary tree A (B (D E) C (F G)) -// Colliding children of A (B and C) can give pairs (D,F) (D,G) (E,F) and (E,G). -// Then colliding children of B can give the pair (D,E) and for C (F,G). -// So no duplicates even when used for self-collision. -// Whenever a proxy is moved, the flag is propagated up the hierarchy to the root. So -// self collision gathers all those moved internal nodes and collides their subtrees together. -// See Real-time collision detection section 6.3.2. This is faster than querying every moved -// proxy against the whole tree. Scaling is linear instead of linear * log. -// Many other physics engines do this (Bepu, Rapier, etc). So nothing new here. -static void b3CollideCrossPairs( const b3TreeNode* arrayA, const b3TreeNode* arrayB, const b3TreeNode* subtreeA, - const b3TreeNode* subtreeB, b3PairContext* context ) -{ - b3IndexPair stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - - // Seed the stack. - b3VisitPair( arrayA, arrayB, subtreeA, subtreeB, stack, &stackCount, context ); - - while ( stackCount > 0 ) - { - b3IndexPair pair = stack[--stackCount]; - for ( int i = 0; i < 2; ++i ) - { - for ( int j = 0; j < 2; ++j ) - { - b3VisitPair( arrayA, arrayB, arrayA + pair.a + i, arrayB + pair.b + j, stack, &stackCount, context ); - } - } - } -} - -// This takes moved internal nodes and collides their sub-trees against each other. -static void b3SelfPairsTask( int startIndex, int endIndex, int workerIndex, void* context ) -{ - b3TracyCZoneNC( self_pairs, "Self", b3_colorCoral, true ); - - b3World* world = context; + b3World* world = (b3World*)context; b3BroadPhase* bp = &world->broadPhase; - const b3DynamicTree* tree = bp->trees + b3_dynamicBody; - const b3TreeNode* nodes = tree->nodes; - const int* siblingIndices = bp->movedSiblings; - b3PairContext pairContext = { - .world = world, - .pairKeys = &world->taskContexts.data[workerIndex].pairKeys, - }; + b3QueryPairContext queryContext = { 0 }; + queryContext.world = world; + queryContext.compoundShapeIndex = B3_NULL_INDEX; for ( int i = startIndex; i < endIndex; ++i ) { - int nodeIndex = siblingIndices[i]; - b3CollideCrossPairs( nodes, nodes, nodes + nodeIndex, nodes + nodeIndex + 1, &pairContext ); - } + // Initialize move result for this moved proxy + queryContext.moveResult = bp->moveResults + i; + queryContext.moveResult->pairList = NULL; - b3FlushCandidatePairs( &pairContext ); + int proxyKey = bp->moveArray.data[i]; + b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); - b3TracyCZoneEnd( self_pairs ); -} + int proxyId = B3_PROXY_ID( proxyKey ); + queryContext.queryProxyKey = proxyKey; -#define B3_CROSS_SEED_COUNT 64 -_Static_assert( ( B3_CROSS_SEED_COUNT & ( B3_CROSS_SEED_COUNT - 1 ) ) == 0, "must be power of 2" ); + const b3DynamicTree* baseTree = bp->trees + proxyType; -// This does a serial cross-tree breadth first search until the queue is full. Then it returns -// the queue pairs as seeds for a parallel search. -static int b3GatherCrossSeeds( const b3DynamicTree* treeA, const b3DynamicTree* treeB, b3NodePair* seeds ) -{ - const b3TreeNode* nodesA = treeA->nodes; - const b3TreeNode* nodesB = treeB->nodes; + // We have to query the tree with the fat AABB so that + // we don't fail to create a contact that may touch later. + b3AABB fatAABB = b3DynamicTree_GetAABB( baseTree, proxyId ); + queryContext.queryShapeIndex = (int)b3DynamicTree_GetUserData( baseTree, proxyId ); + queryContext.aabb = fatAABB; - // Breadth-first search from the two roots as one pair. An empty tree has a sentinel root that - // survives nothing. - b3NodePair queue[2 * B3_CROSS_SEED_COUNT]; - int mask = 2 * B3_CROSS_SEED_COUNT - 1; - int head = 0; - int tail = 0; + // Compound shape collision invocation is not supported + B3_VALIDATE( world->shapes.data[queryContext.queryShapeIndex].type != b3_compoundShape ); - const b3TreeNode* rootA = nodesA + B3_ROOT_NODE; - const b3TreeNode* rootB = nodesB + B3_ROOT_NODE; - if ( b3TestPair( rootA, rootB ) ) - { - queue[tail & mask] = B3_LITERAL( b3NodePair ){ .a = *rootA, .b = *rootB }; - tail += 1; - } - - int seedCount = 0; - while ( head < tail && seedCount + ( tail - head ) + 3 < B3_CROSS_SEED_COUNT ) - { - b3NodePair pair = queue[head & mask]; - head += 1; - - if ( b3IsLeaf( &pair.a ) || b3IsLeaf( &pair.b ) ) + // Query trees. Only dynamic proxies collide with kinematic and static proxies. + // Using B3_DEFAULT_MASK_BITS so that b3Filter::groupIndex works. + // consider using bits = groupIndex > 0 ? B3_DEFAULT_MASK_BITS : maskBits + bool requireAllBits = false; + if ( proxyType == b3_dynamicBody ) { - seeds[seedCount++] = pair; - continue; + queryContext.queryTreeType = b3_kinematicBody; + b3DynamicTree_Query( bp->trees + b3_kinematicBody, fatAABB, B3_DEFAULT_MASK_BITS, requireAllBits, b3PairQueryCallback, + &queryContext ); + + queryContext.queryTreeType = b3_staticBody; + b3DynamicTree_Query( bp->trees + b3_staticBody, fatAABB, B3_DEFAULT_MASK_BITS, requireAllBits, b3PairQueryCallback, + &queryContext ); } - const b3TreeNode* a = nodesA + b3GetLeftChild( &pair.a ); - const b3TreeNode* b = nodesB + b3GetLeftChild( &pair.b ); - - // Nodes have two children each, so four combinations. - for ( int i = 0; i < 2; ++i ) - { - for ( int j = 0; j < 2; ++j ) - { - if ( b3TestPair( a + i, b + j ) ) - { - queue[tail & mask] = B3_LITERAL( b3NodePair ){ a[i], b[j] }; - tail += 1; - } - } - } + // All proxies collide with dynamic proxies + // Using B3_DEFAULT_MASK_BITS so that b3Filter::groupIndex works. + queryContext.queryTreeType = b3_dynamicBody; + b3DynamicTree_Query( bp->trees + b3_dynamicBody, fatAABB, B3_DEFAULT_MASK_BITS, requireAllBits, b3PairQueryCallback, + &queryContext ); } - while ( head < tail ) - { - seeds[seedCount] = queue[head & mask]; - seedCount += 1; - head += 1; - } - - return seedCount; -} - -typedef struct b3CrossContext -{ - b3World* world; - b3NodePair seeds[2 * B3_CROSS_SEED_COUNT]; - int staticSeedCount; - int crossMoveCount; - int dynamicMoveCount; - bool checkCompounds; -} b3CrossContext; - -static void b3CrossPairsTask( int startIndex, int endIndex, int workerIndex, void* context ) -{ - b3TracyCZoneNC( cross_pairs, "Cross", b3_colorCoral, true ); - - b3CrossContext* crossContext = context; - b3World* world = crossContext->world; - b3BroadPhase* bp = &world->broadPhase; - const b3TreeNode* staticNodes = bp->trees[b3_staticBody].nodes; - const b3TreeNode* kinematicNodes = bp->trees[b3_kinematicBody].nodes; - const b3TreeNode* dynamicNodes = bp->trees[b3_dynamicBody].nodes; - - b3PairContext pairContext = { - .world = world, - .pairKeys = &world->taskContexts.data[workerIndex].pairKeys, - }; - - // Static seeds come first, so the two passes are contiguous sub-ranges. The batch is drained - // between them because only the static pass can meet a compound. - int staticEnd = b3MinInt( endIndex, crossContext->staticSeedCount ); - - pairContext.checkCompounds = crossContext->checkCompounds; - for ( int i = startIndex; i < staticEnd; ++i ) - { - b3NodePair seed = crossContext->seeds[i]; - b3CollideCrossPairs( dynamicNodes, staticNodes, &seed.a, &seed.b, &pairContext ); - } - b3FlushCandidatePairs( &pairContext ); - - pairContext.checkCompounds = false; - for ( int i = b3MaxInt( startIndex, crossContext->staticSeedCount ); i < endIndex; ++i ) - { - b3NodePair seed = crossContext->seeds[i]; - b3CollideCrossPairs( dynamicNodes, kinematicNodes, &seed.a, &seed.b, &pairContext ); - } - b3FlushCandidatePairs( &pairContext ); - - b3TracyCZoneEnd( cross_pairs ); + b3TracyCZoneEnd( pair_task ); } static void b3UpdateTreesTask( void* context ) @@ -635,156 +395,102 @@ static void b3UpdateTreesTask( void* context ) b3TracyCZoneEnd( tree_task ); } -bool b3BeginPairs( b3World* world ) +void b3UpdateBroadPhasePairs( b3World* world ) { b3BroadPhase* bp = &world->broadPhase; - bool needUpdate = b3HasTreeMoved( bp->trees + b3_staticBody ); - needUpdate = needUpdate || b3NeedsRebuild( bp->trees + b3_kinematicBody ); - needUpdate = needUpdate || b3NeedsRebuild( bp->trees + b3_dynamicBody ); + int moveCount = bp->moveArray.count; - if ( needUpdate == false ) + if ( moveCount == 0 ) { - return false; + return; } - b3TracyCZoneNC( update_pairs, "Find Pairs Setup", b3_colorMediumSlateBlue, true ); + b3TracyCZoneNC( update_pairs, "Pairs", b3_colorMediumSlateBlue, true ); b3Stack* alloc = &world->stack; - for ( int i = 0; i < world->workerCount; ++i ) - { - b3Array_Clear( world->taskContexts.data[i].pairKeys ); - } + // todo these could be in the step context + bp->moveResults = (b3MoveResult*)b3StackAlloc( alloc, moveCount * sizeof( b3MoveResult ), "move results" ); + bp->movePairCapacity = 16 * moveCount; + bp->movePairs = (b3MovePair*)b3StackAlloc( alloc, bp->movePairCapacity * sizeof( b3MovePair ), "move pairs" ); - // Generate pairs by querying the dynamic body tree against itself and against - // the kinematic and static trees. - { - // Get the sibling pairs of the dynamic body tree that have moved. - const b3DynamicTree* dynamicTree = bp->trees + b3_dynamicBody; - int pairCapacity = b3MaxInt( dynamicTree->nodeEnd / 2, 1 ); - bp->movedSiblings = b3StackAlloc( alloc, pairCapacity * sizeof( int ), "moved pairs" ); - int dynamicMoveCount = b3GatherMovedSiblings( dynamicTree, bp->movedSiblings ); + b3AtomicStoreInt( &bp->movePairIndex, 0 ); - b3CrossContext* crossContext = b3StackAlloc( alloc, sizeof( b3CrossContext ), "cross context" ); - bp->crossContext = crossContext; +#ifndef NDEBUG + extern b3AtomicInt b3_probeCount; + b3AtomicStoreInt( &b3_probeCount, 0 ); +#endif - // Get seeds for colliding against the static and kinematic trees. - int staticSeedCount = b3GatherCrossSeeds( dynamicTree, bp->trees + b3_staticBody, crossContext->seeds ); - B3_ASSERT( staticSeedCount <= B3_CROSS_SEED_COUNT ); - int kinematicSeedCount = - b3GatherCrossSeeds( dynamicTree, bp->trees + b3_kinematicBody, crossContext->seeds + staticSeedCount ); - B3_ASSERT( kinematicSeedCount <= B3_CROSS_SEED_COUNT ); - - crossContext->world = world; - crossContext->staticSeedCount = staticSeedCount; - crossContext->crossMoveCount = staticSeedCount + kinematicSeedCount; - crossContext->dynamicMoveCount = dynamicMoveCount; - crossContext->checkCompounds = world->compoundShapeCount > 0; - - // Collide the dynamic body tree against the static and kinematic trees. - b3StageParallelFor( world, b3_taskPairs, &b3CrossPairsTask, crossContext->crossMoveCount, 1, crossContext ); - } - - b3TracyCZoneEnd( update_pairs ); - - return true; -} - -void b3StageSelfPairs( b3World* world ) -{ - // Collide the dynamic body tree against itself. - b3StageParallelFor( world, b3_taskPairs, &b3SelfPairsTask, world->broadPhase.crossContext->dynamicMoveCount, 64, - world ); -} - -void b3EndPairs( b3World* world ) -{ - b3BroadPhase* bp = &world->broadPhase; - b3Stack* alloc = &world->stack; - - b3StackFree( alloc, bp->crossContext ); - bp->crossContext = NULL; - - b3DynamicTree_ClearMoved( bp->trees + b3_staticBody ); + int minRange = 64; + b3ParallelFor( world, b3FindPairsTask, moveCount, minRange, world, "pairs" ); b3TracyCZoneNC( create_contacts, "Create Contacts", b3_colorCoral, true ); - // Update stale trees. - b3StageDeferredTask( world->stepContext, b3_taskTreeRebuild, &b3UpdateTreesTask, world ); - - // Pairs arrive in deterministic order but scrambled relative to body and shape order. - // Sorting them here improves solver performance and makes contact order independent of - // tree structure. - int pairCount = 0; - for ( int i = 0; i < world->workerCount; ++i ) + // Task that can be done in parallel with the narrow-phase + // - rebuild the collision tree for dynamic and kinematic bodies to keep their query performance good + if ( world->taskCount < B3_MAX_TASKS ) { - pairCount += world->taskContexts.data[i].pairKeys.count; + world->userTreeTask = world->enqueueTaskFcn( &b3UpdateTreesTask, world, world->userTaskContext, "rebuild tree" ); + world->taskCount += 1; + world->activeTaskCount += world->userTreeTask == NULL ? 0 : 1; + } + else + { + world->userTreeTask = NULL; + b3UpdateTreesTask( world ); } - uint64_t* pairKeys = b3StackAlloc( alloc, b3MaxInt( pairCount, 1 ) * sizeof( uint64_t ), "pair keys" ); - int keyCount = 0; - for ( int i = 0; i < world->workerCount; ++i ) + // Single-threaded work + // - Clear move flags + // - Create contacts in deterministic order + for ( int i = 0; i < moveCount; ++i ) { - const b3Array( uint64_t )* workerKeys = &world->taskContexts.data[i].pairKeys; - if ( workerKeys->count > 0 ) + b3MoveResult* result = bp->moveResults + i; + b3MovePair* pair = result->pairList; + while ( pair != NULL ) { - memcpy( pairKeys + keyCount, workerKeys->data, workerKeys->count * sizeof( uint64_t ) ); - keyCount += workerKeys->count; + int shapeIdA = pair->shapeIndexA; + int shapeIdB = pair->shapeIndexB; + int childIndex = pair->childIndex; + + b3Shape* shapeA = b3Array_Get( world->shapes, shapeIdA ); + b3Shape* shapeB = b3Array_Get( world->shapes, shapeIdB ); + + b3CreateContact( world, shapeA, shapeB, childIndex ); + + if ( pair->heap ) + { + b3MovePair* temp = pair; + pair = pair->next; + b3Free( temp, sizeof( b3MovePair ) ); + } + else + { + pair = pair->next; + } } } - B3_ASSERT( keyCount == pairCount ); - + // Reset move buffer: clear only the bits that were set this step. + // Invariant: bit set in movedProxies[type] iff proxyKey is present in moveArray. + for ( int i = 0; i < bp->moveArray.count; ++i ) { -#define LESS( i, j ) ( pairKeys[(int)( i )] < pairKeys[(int)( j )] ) -#define SWAP( i, j ) \ - do \ - { \ - uint64_t tmp_ = pairKeys[(int)( i )]; \ - pairKeys[(int)( i )] = pairKeys[(int)( j )]; \ - pairKeys[(int)( j )] = tmp_; \ - } \ - while ( 0 ) - - QSORT( pairCount, LESS, SWAP ); - -#undef LESS -#undef SWAP + int proxyKey = bp->moveArray.data[i]; + b3ClearBit( &bp->movedProxies[B3_PROXY_TYPE( proxyKey )], B3_PROXY_ID( proxyKey ) ); } + b3Array_Clear( bp->moveArray ); - for ( int i = 0; i < keyCount; ++i ) - { - uint64_t key = pairKeys[i]; - - // The traversal is cross subtree and the seeds are disjoint, so a duplicate key means a - // real bug. Trap it in a validation build, and skip rather than double add to the pair - // set, which a later destroy would then remove once. - bool duplicate = i > 0 && key == pairKeys[i - 1]; - B3_VALIDATE( duplicate == false ); - if ( duplicate ) - { - continue; - } - - int shapeIdA = (int)( ( key >> ( 64 - B3_SHAPE_POWER ) ) & B3_SHAPE_MASK ); - int shapeIdB = (int)( ( key >> ( 64 - 2 * B3_SHAPE_POWER ) ) & B3_SHAPE_MASK ); - int childIndex = (int)( key & B3_CHILD_MASK ); - - b3Shape* shapeA = b3Array_Get( world->shapes, shapeIdA ); - b3Shape* shapeB = b3Array_Get( world->shapes, shapeIdB ); - - b3CreateContact( world, shapeA, shapeB, childIndex ); - } - - b3StackFree( alloc, pairKeys ); - - b3StackFree( alloc, bp->movedSiblings ); - bp->movedSiblings = NULL; + b3StackFree( alloc, bp->movePairs ); + bp->movePairs = NULL; + b3StackFree( alloc, bp->moveResults ); + bp->moveResults = NULL; b3ValidateSolverSets( world ); b3TracyCZoneEnd( create_contacts ); + + b3TracyCZoneEnd( update_pairs ); } bool b3BroadPhase_TestOverlap( const b3BroadPhase* bp, int proxyKeyA, int proxyKeyB ) @@ -815,13 +521,13 @@ void b3ValidateBroadPhase( const b3BroadPhase* bp ) // todo validate every shape AABB is contained in tree AABB } -void b3ValidateNoMoved( const b3BroadPhase* bp ) +void b3ValidateNoEnlarged( const b3BroadPhase* bp ) { #if B3_ENABLE_VALIDATION == 1 for ( int j = 0; j < b3_bodyTypeCount; ++j ) { const b3DynamicTree* tree = bp->trees + j; - b3DynamicTree_ValidateNoMoved( tree ); + b3DynamicTree_ValidateNoEnlarged( tree ); } #else B3_UNUSED( bp ); diff --git a/src/broad_phase.h b/src/broad_phase.h index ab981b9..dcd626b 100644 --- a/src/broad_phase.h +++ b/src/broad_phase.h @@ -3,13 +3,16 @@ #pragma once -#include "dynamic_tree.h" +#include "bitset.h" +#include "container.h" #include "table.h" #include "box3d/collision.h" #include "box3d/types.h" typedef struct b3Shape b3Shape; +typedef struct b3MovePair b3MovePair; +typedef struct b3MoveResult b3MoveResult; typedef struct b3Stack b3Stack; typedef struct b3World b3World; @@ -23,13 +26,20 @@ typedef struct b3World b3World; /// It is up to the client to consume the new pairs and to track subsequent overlap. typedef struct b3BroadPhase { - // One tree for each body type. b3DynamicTree trees[b3_bodyTypeCount]; - // The moved siblings gathered from the dynamic body tree. - int* movedSiblings; + // Per body-type bit sets indexed by proxyId, marking proxies moved this step. + // Paired with moveArray which preserves deterministic insertion order for pair queries. + b3BitSet movedProxies[b3_bodyTypeCount]; + b3Array( int ) moveArray; - struct b3CrossContext* crossContext; + // These are the results from the pair query and are used to create new contacts + // in deterministic order. + // todo these could be in the step context + b3MoveResult* moveResults; + b3MovePair* movePairs; + int movePairCapacity; + b3AtomicInt movePairIndex; // Tracks shape pairs that have a b3Contact // todo pairSet can grow quite large on the first time step and remain large @@ -44,27 +54,26 @@ int b3BroadPhase_CreateProxy( b3BroadPhase* bp, b3BodyType proxyType, b3AABB aab void b3BroadPhase_DestroyProxy( b3BroadPhase* bp, int proxyKey ); void b3BroadPhase_MoveProxy( b3BroadPhase* bp, int proxyKey, b3AABB aabb ); +void b3BroadPhase_EnlargeProxy( b3BroadPhase* bp, int proxyKey, b3AABB aabb ); int b3BroadPhase_GetShapeIndex( b3BroadPhase* bp, int proxyKey ); -bool b3BeginPairs( b3World* world ); -void b3StageSelfPairs( b3World* world ); -void b3EndPairs( b3World* world ); +void b3UpdateBroadPhasePairs( b3World* world ); bool b3BroadPhase_TestOverlap( const b3BroadPhase* bp, int proxyKeyA, int proxyKeyB ); void b3ValidateBroadPhase( const b3BroadPhase* bp ); -void b3ValidateNoMoved( const b3BroadPhase* bp ); +void b3ValidateNoEnlarged( const b3BroadPhase* bp ); -static inline void b3BroadPhase_MarkProxyMovedSerial( b3BroadPhase* bp, int proxyKey ) +// This is what triggers new contact pairs to be created +// Warning: this must be called in deterministic order +static inline void b3BufferMove( b3BroadPhase* bp, int queryProxy ) { - b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); - int proxyId = B3_PROXY_ID( proxyKey ); - b3DynamicTree_MarkProxyMovedSerial( bp->trees + proxyType, proxyId ); -} - -static inline void b3BroadPhase_MarkProxyMoved( b3BroadPhase* bp, int proxyKey, b3AABB aabb ) -{ - b3BodyType proxyType = B3_PROXY_TYPE( proxyKey ); - int proxyId = B3_PROXY_ID( proxyKey ); - b3DynamicTree_MarkProxyMoved( bp->trees + proxyType, proxyId, aabb ); + b3BodyType proxyType = B3_PROXY_TYPE( queryProxy ); + int proxyId = B3_PROXY_ID( queryProxy ); + b3BitSet* set = &bp->movedProxies[proxyType]; + if ( b3GetBit( set, proxyId ) == false ) + { + b3SetBitGrow( set, proxyId ); + b3Array_Push( bp->moveArray, queryProxy ); + } } diff --git a/src/capsule.c b/src/capsule.c index 2927740..249e8cb 100644 --- a/src/capsule.c +++ b/src/capsule.c @@ -380,6 +380,6 @@ int b3CollideMoverAndCapsule( b3PlaneResult* result, const b3Capsule* shape, con } b3Plane plane = { normal, totalRadius - distance }; - *result = (b3PlaneResult){ plane, approach.point1, 0, 0, 0 }; + *result = (b3PlaneResult){ plane, approach.point1 }; return 1; } diff --git a/src/compound.c b/src/compound.c index 99a66e2..29da3c6 100644 --- a/src/compound.c +++ b/src/compound.c @@ -3,8 +3,7 @@ #include "compound.h" -#include "dynamic_tree.h" -#include "hull.h" +#include "hull_map.h" #include "math_internal.h" #include "shape.h" @@ -32,25 +31,26 @@ typedef struct b3HullInstance { b3Transform transform; uint32_t hullOffset; - uint16_t materialIndex; - uint16_t padding; + uint32_t materialIndex; } b3HullInstance; -_Static_assert( sizeof( b3HullInstance ) == sizeof( b3Transform ) + sizeof( uint32_t ) + 2 * sizeof( uint16_t ), - "review padding" ); - typedef struct b3MeshInstance { b3Transform transform; b3Vec3 scale; uint32_t meshOffset; - uint32_t materialOffset; - uint32_t materialCount; + uint32_t materialIndices[B3_MAX_COMPOUND_MESH_MATERIALS]; } b3MeshInstance; -_Static_assert( sizeof( b3CompoundCapsule ) == sizeof( b3Capsule ) + 2 * sizeof( uint16_t ), "review padding" ); -_Static_assert( sizeof( b3CompoundSphere ) == sizeof( b3Sphere ) + 2 * sizeof( uint16_t ), "review padding" ); -_Static_assert( sizeof( b3CompoundData ) == sizeof( uint64_t ) + sizeof( b3AABB ) + 16 * sizeof( int ), "review padding" ); +static inline b3TreeNode* b3GetCompoundNodes( b3CompoundData* compound ) +{ + if ( compound->nodeOffset == 0 ) + { + return NULL; + } + + return (b3TreeNode*)( (intptr_t)compound + compound->nodeOffset ); +} const b3SurfaceMaterial* b3GetCompoundMaterials( const b3CompoundData* compound ) { @@ -111,8 +111,10 @@ b3CompoundMesh b3GetCompoundMesh( const b3CompoundData* compound, int index ) result.meshData = (const b3MeshData*)( (intptr_t)compound + meshOffset ); result.transform = meshInstances[index].transform; result.scale = meshInstances[index].scale; - result.materialIndices = (const uint16_t*)( (intptr_t)compound + meshInstances[index].materialOffset ); - result.materialCount = (int)meshInstances[index].materialCount; + for ( int i = 0; i < B3_MAX_COMPOUND_MESH_MATERIALS; ++i ) + { + result.materialIndices[i] = meshInstances[index].materialIndices[i]; + } return result; } @@ -135,13 +137,11 @@ b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex // Capsule? if ( 0 <= childIndex && childIndex < compound->capsuleCount ) { - B3_ASSERT( compound->capsuleOffset > 0 ); - const b3CompoundCapsule* capsules = (const b3CompoundCapsule*)( (intptr_t)compound + compound->capsuleOffset ); + b3CompoundCapsule compoundCapsule = b3GetCompoundCapsule( compound, childIndex ); return (b3ChildShape){ - .capsule = capsules[childIndex].capsule, + .capsule = compoundCapsule.capsule, .transform = b3Transform_identity, - .materialIndices = &capsules[childIndex].materialIndex, - .materialCount = 1, + .materialIndices = { compoundCapsule.materialIndex }, .type = b3_capsuleShape, }; } @@ -150,14 +150,11 @@ b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex // Hull? if ( 0 <= childIndex && childIndex < compound->hullCount ) { - B3_ASSERT( compound->hullOffset > 0 ); - const b3HullInstance* hullInstances = (const b3HullInstance*)( (intptr_t)compound + compound->hullOffset ); - uint32_t hullOffset = hullInstances[childIndex].hullOffset; + b3CompoundHull compoundHull = b3GetCompoundHull( compound, childIndex ); return (b3ChildShape){ - .hull = (const b3HullData*)( (intptr_t)compound + hullOffset ), - .transform = hullInstances[childIndex].transform, - .materialIndices = &hullInstances[childIndex].materialIndex, - .materialCount = 1, + .hull = compoundHull.hull, + .transform = compoundHull.transform, + .materialIndices = { compoundHull.materialIndex }, .type = b3_hullShape, }; } @@ -167,6 +164,8 @@ b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex if ( 0 <= childIndex && childIndex < compound->meshCount ) { b3CompoundMesh compoundMesh = b3GetCompoundMesh( compound, childIndex ); + const int* m = compoundMesh.materialIndices; + _Static_assert( B3_MAX_COMPOUND_MESH_MATERIALS == 4, "too many materials in compound mesh" ); return (b3ChildShape){ .mesh = @@ -175,8 +174,7 @@ b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex .scale = compoundMesh.scale, }, .transform = compoundMesh.transform, - .materialIndices = compoundMesh.materialIndices, - .materialCount = compoundMesh.materialCount, + .materialIndices = { m[0], m[1], m[2], m[3] }, .type = b3_meshShape, }; } @@ -186,13 +184,11 @@ b3ChildShape b3GetCompoundChild( const b3CompoundData* compound, int childIndex // Sphere? { - B3_ASSERT( compound->sphereOffset > 0 ); - const b3CompoundSphere* spheres = (const b3CompoundSphere*)( (intptr_t)compound + compound->sphereOffset ); + b3CompoundSphere compoundSphere = b3GetCompoundSphere( compound, childIndex ); return (b3ChildShape){ - .sphere = spheres[childIndex].sphere, + .sphere = compoundSphere.sphere, .transform = b3Transform_identity, - .materialIndices = &spheres[childIndex].materialIndex, - .materialCount = 1, + .materialIndices = { compoundSphere.materialIndex }, .type = b3_sphereShape, }; } @@ -230,19 +226,13 @@ static bool b3CompareMeshes( const b3MeshData* mesh1, const b3MeshData* mesh2 ) #define FREE_FN b3Free #include "verstable.h" -_Static_assert( sizeof( b3SurfaceMaterial ) == 40, "review padding" ); - static inline uint64_t b3HashMaterial( const b3SurfaceMaterial* material ) { - B3_ASSERT( material->padding == 0 ); - return vt_wyhash( material, sizeof( b3SurfaceMaterial ) ); } static bool b3CompareMaterials( const b3SurfaceMaterial* mat1, const b3SurfaceMaterial* mat2 ) { - B3_ASSERT( mat1->padding == 0 && mat2->padding == 0 ); - if ( mat1 == mat2 ) { return true; @@ -278,15 +268,15 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) // Instances int capsuleCount = def->capsuleCount; - b3CompoundCapsule* capsuleInstances = b3AllocZero( capsuleCount * sizeof( b3CompoundCapsule ) ); + b3CompoundCapsule* capsuleInstances = b3AllocZeroed( capsuleCount * sizeof( b3CompoundCapsule ) ); int hullCount = def->hullCount; - b3HullInstance* hullInstances = b3AllocZero( hullCount * sizeof( b3HullInstance ) ); + b3HullInstance* hullInstances = b3AllocZeroed( hullCount * sizeof( b3HullInstance ) ); int meshCount = def->meshCount; - b3MeshInstance* meshInstances = b3AllocZero( meshCount * sizeof( b3MeshInstance ) ); + b3MeshInstance* meshInstances = b3AllocZeroed( meshCount * sizeof( b3MeshInstance ) ); int sphereCount = def->sphereCount; - b3CompoundSphere* sphereInstances = b3AllocZero( sphereCount * sizeof( b3CompoundSphere ) ); + b3CompoundSphere* sphereInstances = b3AllocZeroed( sphereCount * sizeof( b3CompoundSphere ) ); - // Determine material capacity. + // Determine material capacity int materialCapacity = convexCount; for ( int i = 0; i < def->meshCount; ++i ) { @@ -298,24 +288,20 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) b3MaterialMap materialMap; b3MaterialMap_init( &materialMap ); b3MaterialMap_reserve( &materialMap, materialCapacity ); - b3SurfaceMaterial* materials = b3AllocZero( materialCapacity * sizeof( b3SurfaceMaterial ) ); + b3SurfaceMaterial* materials = b3AllocZeroed( materialCapacity * sizeof( b3SurfaceMaterial ) ); int materialCount = 0; - int meshMaterialTotal = materialCapacity - convexCount; - uint16_t* meshMaterialStaging = b3AllocZero( meshMaterialTotal * sizeof( uint16_t ) ); - int meshMaterialCursor = 0; - for ( int i = 0; i < def->capsuleCount; ++i ) { const b3CompoundCapsuleDef* capsuleDef = def->capsules + i; capsuleInstances[i].capsule = capsuleDef->capsule; - // Look for an existing material. + // Look for an existing material b3MaterialMap_itr materialItr = b3MaterialMap_get_or_insert( &materialMap, &capsuleDef->material, materialCount ); - // Get the shared material index. + // Get the shared material index int materialIndex = materialItr.data->val; - capsuleInstances[i].materialIndex = (uint16_t)materialIndex; + capsuleInstances[i].materialIndex = materialIndex; // Is this a new material? if ( materialIndex == materialCount ) @@ -330,7 +316,7 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) } // Hulls - b3SharedHull* sharedHulls = b3AllocZero( hullCount * sizeof( b3SharedHull ) ); + b3SharedHull* sharedHulls = b3AllocZeroed( hullCount * sizeof( b3SharedHull ) ); int sharedHullCount = 0; if ( hullCount > 0 ) @@ -347,12 +333,12 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) b3DynamicTree_CreateProxy( &tree, aabb, ~0ull, childIndex ); childIndex += 1; - // Look for an existing material. + // Look for an existing material b3MaterialMap_itr materialItr = b3MaterialMap_get_or_insert( &materialMap, &hullDef->material, materialCount ); - // Get the shared material index. + // Get the shared material index int materialIndex = materialItr.data->val; - hullInstances[i].materialIndex = (uint16_t)materialIndex; + hullInstances[i].materialIndex = materialIndex; // Is this a new material? if ( materialIndex == materialCount ) @@ -386,7 +372,7 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) } // Meshes - b3SharedMesh* sharedMeshes = b3AllocZero( meshCount * sizeof( b3SharedMesh ) ); + b3SharedMesh* sharedMeshes = b3AllocZeroed( meshCount * sizeof( b3SharedMesh ) ); int sharedMeshCount = 0; if ( meshCount > 0 ) @@ -407,18 +393,15 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) // No effort to share mesh materials. It would be easier to do if the number of materials was limited. B3_ASSERT( meshData->materialCount == meshDef->materialCount ); - int meshMaterialStart = meshMaterialCursor; - for ( int j = 0; j < meshDef->materialCount; ++j ) { - // Look for an existing material. + // Look for an existing material b3MaterialMap_itr materialItr = b3MaterialMap_get_or_insert( &materialMap, &meshDef->materials[j], materialCount ); - // Get the shared material index. + // Get the shared material index int materialIndex = materialItr.data->val; - meshMaterialStaging[meshMaterialCursor] = (uint16_t)materialIndex; - meshMaterialCursor += 1; + meshInstances[i].materialIndices[j] = materialIndex; // Is this a new material? if ( materialIndex == materialCount ) @@ -428,20 +411,17 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) } } - // Look for an existing matching mesh. + // Look for an existing matching mesh b3MeshMap_itr itr = b3MeshMap_get_or_insert( &meshMap, meshData, sharedMeshCount ); - // Get the shared mesh index. + // Get the shared mesh index int sharedMeshIndex = itr.data->val; - // Create mesh instance. + // Create mesh instance meshInstances[i].transform = def->meshes[i].transform; meshInstances[i].scale = def->meshes[i].scale; - meshInstances[i].materialOffset = (uint32_t)meshMaterialStart; - meshInstances[i].materialCount = (uint32_t)meshDef->materialCount; - - // The offset isn't known yet, so store the index of the shared mesh. + // The offset isn't known yet, so store the index of the shared mesh meshInstances[i].meshOffset = sharedMeshIndex; // Is this a new mesh? @@ -463,12 +443,12 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) const b3CompoundSphereDef* sphereDef = def->spheres + i; sphereInstances[i].sphere = sphereDef->sphere; - // Look for an existing material. + // Look for an existing material b3MaterialMap_itr materialItr = b3MaterialMap_get_or_insert( &materialMap, &sphereDef->material, materialCount ); - // Get the shared material index. + // Get the shared material index int materialIndex = materialItr.data->val; - sphereInstances[i].materialIndex = (uint16_t)materialIndex; + sphereInstances[i].materialIndex = materialIndex; // Is this a new material? if ( materialIndex == materialCount ) @@ -483,67 +463,74 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) } B3_ASSERT( materialCount <= materialCapacity ); - B3_ASSERT( materialCount <= UINT16_MAX ); - B3_ASSERT( tree.proxyCount > 0 ); + B3_ASSERT( tree.nodeCount > 0 ); b3DynamicTree_Rebuild( &tree, true ); - // Tree nodes. The rebuild is dense, so only the live nodes travel. - size_t byteCount = b3AlignUp8( sizeof( b3CompoundData ) ); - int nodeOffset = (int)byteCount; - byteCount += b3AlignUp8( tree.nodeEnd * sizeof( b3TreeNode ) ); - int materialOffset = (int)byteCount; - byteCount += b3AlignUp8( materialCount * sizeof( b3SurfaceMaterial ) ); - int capsuleOffset = (int)byteCount; - byteCount += b3AlignUp8( def->capsuleCount * sizeof( b3CompoundCapsule ) ); + int byteCount = sizeof( b3CompoundData ); + + // Tree nodes - todo 64 byte alignment + int nodeOffset = byteCount; + byteCount += tree.nodeCapacity * sizeof( b3TreeNode ); + + int materialOffset = byteCount; + byteCount += materialCount * sizeof( b3SurfaceMaterial ); + + int capsuleOffset = byteCount; + byteCount += def->capsuleCount * sizeof( b3CompoundCapsule ); // Hull data layout has another level of indirection to allow for tight data packing // 1. hull instance array : hull count array of b3HullInstance with individual hull transforms and offsets // 2. heterogeneous array of shared hull data : each shared hull can have a different byte count, so direct indexing is not // possible - int hullArrayOffset = (int)byteCount; + int hullArrayOffset = byteCount; // Array of hull instances - byteCount += b3AlignUp8( hullCount * sizeof( b3HullInstance ) ); + byteCount += hullCount * sizeof( b3HullInstance ); // Packed shared hull blobs for ( int i = 0; i < sharedHullCount; ++i ) { - sharedHulls[i].hullOffset = (int)byteCount; - byteCount += b3AlignUp8( sharedHulls[i].hull->byteCount ); + sharedHulls[i].hullOffset = byteCount; + byteCount += sharedHulls[i].hull->byteCount; } // Mesh data layout has another level of indirection to allow for tight data packing // 1. mesh instance array : mesh count array of b3MeshInstance with individual mesh transform, scale, and offset // 2. heterogeneous array of shared mesh data : each shared mesh can have a different byte count, so direct indexing is not // possible - int meshArrayOffset = (int)byteCount; + int meshArrayOffset = byteCount; // Array of mesh instances - byteCount += b3AlignUp8( meshCount * sizeof( b3MeshInstance ) ); - - int meshMaterialMapOffset = (int)byteCount; - byteCount += b3AlignUp8( meshMaterialTotal * sizeof( uint16_t ) ); + byteCount += meshCount * sizeof( b3MeshInstance ); // Packed shared mesh blobs for ( int i = 0; i < sharedMeshCount; ++i ) { - sharedMeshes[i].meshOffset = (int)byteCount; - byteCount += b3AlignUp8( sharedMeshes[i].meshData->byteCount ); + sharedMeshes[i].meshOffset = byteCount; + byteCount += sharedMeshes[i].meshData->byteCount; } - int sphereOffset = (int)byteCount; - byteCount += b3AlignUp8( def->sphereCount * sizeof( b3CompoundSphere ) ); + int sphereOffset = byteCount; + byteCount += def->sphereCount * sizeof( b3CompoundSphere ); b3CompoundData* compound = b3Alloc( byteCount ); memset( compound, 0, byteCount ); compound->version = B3_COMPOUND_VERSION; - compound->byteCount = (int)byteCount; + compound->byteCount = byteCount; compound->nodeOffset = nodeOffset; - compound->bounds = b3DynamicTree_GetRootBounds( &tree ); - compound->treeHeight = b3DynamicTree_GetHeight( &tree ); - compound->nodeCount = tree.nodeEnd; + memcpy( &compound->tree, &tree, sizeof( b3DynamicTree ) ); + + // todo clean up this mess + compound->tree.freeList = 0; + compound->tree.leafIndices = NULL; + compound->tree.leafBoxes = NULL; + compound->tree.leafCenters = NULL; + compound->tree.binIndices = NULL; + compound->tree.rebuildCapacity = 0; + + compound->tree.nodes = NULL; compound->materialOffset = materialOffset; compound->materialCount = materialCount; compound->capsuleOffset = capsuleOffset; @@ -556,8 +543,9 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) compound->sphereCount = sphereCount; // Tree nodes - b3TreeNode* nodes = (b3TreeNode*)( (intptr_t)compound + nodeOffset ); - memcpy( nodes, tree.nodes, tree.nodeEnd * sizeof( b3TreeNode ) ); + b3TreeNode* nodes = b3GetCompoundNodes( compound ); + memcpy( nodes, tree.nodes, tree.nodeCapacity * sizeof( b3TreeNode ) ); + compound->tree.nodes = nodes; // Materials B3_ASSERT( materialCount > 0 ); @@ -603,20 +591,11 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) int sharedIndex = meshInstances[i].meshOffset; B3_ASSERT( 0 <= sharedIndex && sharedIndex < sharedMeshCount ); meshInstances[i].meshOffset = sharedMeshes[sharedIndex].meshOffset; - - uint32_t materialStart = meshInstances[i].materialOffset; - meshInstances[i].materialOffset = (uint32_t)meshMaterialMapOffset + materialStart * (uint32_t)sizeof( uint16_t ); } b3MeshInstance* destinationMeshInstances = (b3MeshInstance*)( (intptr_t)compound + meshArrayOffset ); memcpy( destinationMeshInstances, meshInstances, meshCount * sizeof( b3MeshInstance ) ); - if ( meshMaterialTotal > 0 ) - { - uint16_t* destinationMeshMaterials = (uint16_t*)( (intptr_t)compound + meshMaterialMapOffset ); - memcpy( destinationMeshMaterials, meshMaterialStaging, meshMaterialTotal * sizeof( uint16_t ) ); - } - for ( int i = 0; i < sharedMeshCount; ++i ) { int offset = sharedMeshes[i].meshOffset; @@ -642,7 +621,6 @@ b3CompoundData* b3CreateCompound( const b3CompoundDef* def ) b3Free( meshInstances, meshCount * sizeof( b3MeshInstance ) ); b3Free( sphereInstances, sphereCount * sizeof( b3CompoundSphere ) ); b3Free( materials, materialCapacity * sizeof( b3SurfaceMaterial ) ); - b3Free( meshMaterialStaging, meshMaterialTotal * sizeof( uint16_t ) ); b3DynamicTree_Destroy( &tree ); return compound; @@ -653,52 +631,56 @@ void b3DestroyCompound( b3CompoundData* compound ) b3Free( compound, compound->byteCount ); } -const b3CompoundData* b3ValidateCompound( const uint8_t* bytes, int byteCount ) +uint8_t* b3ConvertCompoundToBytes( b3CompoundData* compound ) { - if ( bytes == NULL || byteCount < (int)sizeof( b3CompoundData ) ) - { - return NULL; - } + // scrub this pointer before serialization + compound->tree.nodes = NULL; + return (uint8_t*)compound; +} - const b3CompoundData* compound = (const b3CompoundData*)bytes; +b3CompoundData* b3ConvertBytesToCompound( uint8_t* bytes, int byteCount ) +{ + b3CompoundData* compound = (b3CompoundData*)bytes; if ( compound->version != B3_COMPOUND_VERSION ) { return NULL; } - if ( compound->byteCount != byteCount ) + if ( compound->byteCount < (int)sizeof( b3CompoundData ) ) { return NULL; } - if ( compound->nodeOffset < (int)sizeof( b3CompoundData ) || ( compound->nodeOffset & 7 ) != 0 ) + if ( byteCount != compound->byteCount ) { return NULL; } - if ( compound->nodeCount < 2 ) - { - return NULL; - } - - int64_t nodeEnd = (int64_t)compound->nodeOffset + (int64_t)compound->nodeCount * (int64_t)sizeof( b3TreeNode ); - if ( nodeEnd > byteCount ) + if ( compound->nodeOffset <= 0 ) { return NULL; } + // this mutates the input bytes + compound->tree.nodes = (b3TreeNode*)( (intptr_t)compound + compound->nodeOffset ); return compound; } b3AABB b3ComputeCompoundAABB( const b3CompoundData* shape, b3Transform transform ) { - return b3AABB_Transform( transform, shape->bounds ); + B3_ASSERT( shape->nodeOffset > 0 ); + + const b3TreeNode* nodes = (const b3TreeNode*)( (intptr_t)shape + shape->nodeOffset ); + int root = shape->tree.root; + b3AABB aabb = nodes[root].aabb; + return b3AABB_Transform( transform, aabb ); } struct b3CompoundOverlapContext { const b3CompoundData* compound; - // proxy in the compound frame + // transform of the compound + b3Transform transform; b3ShapeProxy proxy; bool overlap; }; @@ -711,23 +693,25 @@ static bool b3CompoundOverlapCallback( int proxyId, uint64_t userData, void* con struct b3CompoundOverlapContext* overlapContext = context; b3ChildShape child = b3GetCompoundChild( overlapContext->compound, childIndex ); + b3Transform transform = b3MulTransforms( overlapContext->transform, child.transform ); + bool overlap = false; switch ( child.type ) { case b3_capsuleShape: - overlap = b3OverlapCapsule( &child.capsule, child.transform, &overlapContext->proxy ); + overlap = b3OverlapCapsule( &child.capsule, transform, &overlapContext->proxy ); break; case b3_hullShape: - overlap = b3OverlapHull( child.hull, child.transform, &overlapContext->proxy ); + overlap = b3OverlapHull( child.hull, transform, &overlapContext->proxy ); break; case b3_meshShape: - overlap = b3OverlapMesh( &child.mesh, child.transform, &overlapContext->proxy ); + overlap = b3OverlapMesh( &child.mesh, transform, &overlapContext->proxy ); break; case b3_sphereShape: - overlap = b3OverlapSphere( &child.sphere, child.transform, &overlapContext->proxy ); + overlap = b3OverlapSphere( &child.sphere, transform, &overlapContext->proxy ); break; default: @@ -746,26 +730,27 @@ static bool b3CompoundOverlapCallback( int proxyId, uint64_t userData, void* con return true; } -// This is dealing with multiple transforms: -// - the compound shape transform -// - the compound child shape transforms bool b3OverlapCompound( const b3CompoundData* shape, b3Transform shapeTransform, const b3ShapeProxy* proxy ) { - B3_ASSERT( 0 < proxy->count && proxy->count <= B3_MAX_SHAPE_CAST_POINTS ); - - // Use local proxy. - b3Vec3 buffer[B3_MAX_SHAPE_CAST_POINTS]; struct b3CompoundOverlapContext context = { .compound = shape, - .proxy = b3MakeLocalProxy( proxy, shapeTransform, buffer ), + .transform = shapeTransform, + .proxy = *proxy, .overlap = false, }; - b3AABB aabb = b3ComputeProxyAABB( &context.proxy ); + b3AABB aabb = { proxy->points[0], proxy->points[0] }; + for ( int i = 1; i < proxy->count; ++i ) + { + aabb.lowerBound = b3Min( aabb.lowerBound, proxy->points[i] ); + aabb.upperBound = b3Max( aabb.upperBound, proxy->points[i] ); + } - // This query must be in the compound frame. - b3TreeView view = b3GetCompoundTreeView( shape ); - (void)b3TreeView_Query( &view, aabb, ~0ull, false, b3CompoundOverlapCallback, &context ); + b3Vec3 r = { proxy->radius, proxy->radius, proxy->radius }; + aabb.lowerBound = b3Sub( aabb.lowerBound, r ); + aabb.upperBound = b3Add( aabb.upperBound, r ); + + (void)b3DynamicTree_Query( &shape->tree, aabb, ~0ull, false, b3CompoundOverlapCallback, &context ); return context.overlap; } @@ -789,7 +774,6 @@ static float b3CompoundRayCastCallback( const b3RayCastInput* input, int proxyId b3ChildShape child = b3GetCompoundChild( compound, childIndex ); - // Get the input in child local space. b3RayCastInput localInput = *input; localInput.origin = b3InvTransformPoint( child.transform, input->origin ); localInput.translation = b3InvRotateVector( child.transform.q, input->translation ); @@ -811,8 +795,9 @@ static float b3CompoundRayCastCallback( const b3RayCastInput* input, int proxyId case b3_meshShape: { output = b3RayCastMesh( &child.mesh, &localInput ); - B3_ASSERT( 0 <= output.materialIndex && output.materialIndex < child.materialCount ); - output.materialIndex = child.materialIndices[output.materialIndex]; + B3_ASSERT( 0 <= output.materialIndex ); + int childMaterialIndex = b3MinInt( output.materialIndex, B3_MAX_COMPOUND_MESH_MATERIALS - 1 ); + output.materialIndex = child.materialIndices[childMaterialIndex]; } break; @@ -846,8 +831,7 @@ b3CastOutput b3RayCastCompound( const b3CompoundData* shape, const b3RayCastInpu .compound = shape, .output = &result, }; - b3TreeView view = b3GetCompoundTreeView( shape ); - (void)b3TreeView_RayCast( &view, input, ~0ull, false, b3CompoundRayCastCallback, &context ); + (void)b3DynamicTree_RayCast( &shape->tree, input, ~0ull, false, b3CompoundRayCastCallback, &context ); return result; } @@ -863,13 +847,23 @@ static float b3CompoundShapeCastCallback( const b3BoxCastInput* input, int proxy b3ChildShape child = b3GetCompoundChild( compound, childIndex ); - // Get the input in the child local space. - b3ShapeCastInput localInput = { 0 }; - b3Vec3 localPoints[B3_MAX_SHAPE_CAST_POINTS]; - localInput.proxy = b3MakeLocalProxy( &shapeInput->proxy, child.transform, localPoints ); - localInput.translation = b3InvRotateVector( child.transform.q, shapeInput->translation ); + // Rebuild from the carried shape cast input, taking only the advancing fraction from the tree + b3ShapeCastInput localInput = *shapeInput; localInput.maxFraction = input->maxFraction; - localInput.canEncroach = shapeInput->canEncroach; + b3Vec3 localPoints[B3_MAX_SHAPE_CAST_POINTS]; + + localInput.proxy.count = b3MinInt( shapeInput->proxy.count, B3_MAX_SHAPE_CAST_POINTS ); + + b3Transform invTransform = b3InvertTransform( child.transform ); + b3Matrix3 R = b3MakeMatrixFromQuat( invTransform.q ); + + for ( int i = 0; i < localInput.proxy.count; ++i ) + { + localPoints[i] = b3Add( b3MulMV( R, shapeInput->proxy.points[i] ), invTransform.p ); + } + + localInput.proxy.points = localPoints; + localInput.translation = b3MulMV( R, shapeInput->translation ); b3CastOutput output = { 0 }; @@ -888,8 +882,9 @@ static float b3CompoundShapeCastCallback( const b3BoxCastInput* input, int proxy case b3_meshShape: { output = b3ShapeCastMesh( &child.mesh, &localInput ); - B3_ASSERT( 0 <= output.materialIndex && output.materialIndex < child.materialCount ); - output.materialIndex = child.materialIndices[output.materialIndex]; + B3_ASSERT( 0 <= output.materialIndex ); + int childMaterialIndex = b3MinInt( output.materialIndex, B3_MAX_COMPOUND_MESH_MATERIALS - 1 ); + output.materialIndex = child.materialIndices[childMaterialIndex]; } break; @@ -933,8 +928,7 @@ b3CastOutput b3ShapeCastCompound( const b3CompoundData* shape, const b3ShapeCast // The compound tree is in the compound local frame, so the proxy box needs no origin offset b3AABB box = b3MakeAABB( input->proxy.points, input->proxy.count, input->proxy.radius ); b3BoxCastInput treeInput = { box, input->translation, input->maxFraction }; - b3TreeView view = b3GetCompoundTreeView( shape ); - (void)b3TreeView_BoxCast( &view, &treeInput, ~0ull, false, b3CompoundShapeCastCallback, &context ); + (void)b3DynamicTree_BoxCast( &shape->tree, &treeInput, ~0ull, false, b3CompoundShapeCastCallback, &context ); return result; } @@ -960,8 +954,7 @@ void b3QueryCompound( const b3CompoundData* compound, b3AABB aabb, b3CompoundQue .userContext = context, }; - b3TreeView view = b3GetCompoundTreeView( compound ); - b3TreeView_Query( &view, aabb, B3_DEFAULT_MASK_BITS, false, TreeQueryCallbackFcn, &compoundContext ); + b3DynamicTree_Query( &compound->tree, aabb, B3_DEFAULT_MASK_BITS, false, TreeQueryCallbackFcn, &compoundContext ); } #if 0 @@ -1096,8 +1089,7 @@ b3TOIOutput b3CompoundTimeOfImpact(const b3CompoundData* compound, b3Transform t b3AABB localBounds = b3AABB_Transform( b3InvertTransform( context.compoundTransform ), bounds ); context.localSweepBoundsB = localBounds; - b3TreeView view = b3GetCompoundTreeView( compound ); - b3TreeView_Query( &view, aabb, B3_DEFAULT_MASK_BITS, false, TreeQueryCallbackFcn, &compoundContext ); + b3DynamicTree_Query( &compound->tree, aabb, B3_DEFAULT_MASK_BITS, false, TreeQueryCallbackFcn, &compoundContext ); return context.toiOutput; } @@ -1173,10 +1165,6 @@ static bool b3CompoundMoverCallback( int proxyId, uint64_t userData, void* conte { planes[i].plane.normal = b3RotateVector( child.transform.q, planes[i].plane.normal ); planes[i].point = b3TransformPoint( child.transform, planes[i].point ); - - planes[i].childIndex = childIndex; - B3_ASSERT( 0 <= planes[i].materialIndex && planes[i].materialIndex < child.materialCount ); - planes[i].materialIndex = child.materialIndices[planes[i].materialIndex]; } moverContext->planeCount += planeCount; @@ -1202,8 +1190,7 @@ int b3CollideMoverAndCompound( b3PlaneResult* planes, int capacity, const b3Comp aabb.lowerBound = b3Sub( aabb.lowerBound, r ); aabb.upperBound = b3Add( aabb.upperBound, r ); - b3TreeView view = b3GetCompoundTreeView( shape ); - (void)b3TreeView_Query( &view, aabb, ~0ull, false, b3CompoundMoverCallback, &context ); + (void)b3DynamicTree_Query( &shape->tree, aabb, ~0ull, false, b3CompoundMoverCallback, &context ); return context.planeCount; } diff --git a/src/compound.h b/src/compound.h index 68b1cad..1f4d7e5 100644 --- a/src/compound.h +++ b/src/compound.h @@ -3,19 +3,8 @@ #pragma once -#include "dynamic_tree.h" - #include "box3d/types.h" -static inline b3TreeView b3GetCompoundTreeView( const b3CompoundData* compound ) -{ - b3TreeView view = { - .nodes = (const b3TreeNode*)( (intptr_t)compound + compound->nodeOffset ), - .proxies = NULL, - }; - return view; -} - b3TOIOutput b3CompoundTimeOfImpact( const b3CompoundData* compound, b3Transform transform, const b3ShapeProxy* proxy, const b3Sweep* sweep, float maxFraction ); diff --git a/src/constraint_graph.c b/src/constraint_graph.c index 749d0f4..9f06e9e 100644 --- a/src/constraint_graph.c +++ b/src/constraint_graph.c @@ -149,12 +149,12 @@ void b3AddContactToGraph( b3World* world, b3Contact* contact ) b3GraphColor* color = graph->colors + colorIndex; contact->colorIndex = colorIndex; contact->localIndex = isScalar ? color->contacts.count : color->convexContacts.count; - contact->encodedBodySimA = b3EncodeBodySimIndex( bodyA ); - contact->encodedBodySimB = b3EncodeBodySimIndex( bodyB ); + contact->bodySimIndexA = bodyA->type == b3_staticBody ? B3_NULL_INDEX : bodyA->localIndex; + contact->bodySimIndexB = bodyB->type == b3_staticBody ? B3_NULL_INDEX : bodyB->localIndex; if ( isScalar ) { - B3_ASSERT( contact->manifoldCount <= B3_MAX_MANIFOLDS ); + B3_ASSERT( contact->manifoldCount < UINT16_MAX ); b3ContactSpec spec = { .contactId = contact->contactId, .manifoldStart = 0, diff --git a/src/constraint_graph.h b/src/constraint_graph.h index 56bfdff..ab17e9a 100644 --- a/src/constraint_graph.h +++ b/src/constraint_graph.h @@ -50,16 +50,14 @@ typedef struct b3GraphColor b3Array( b3ContactSpec ) contacts; // These are used for convex contacts - void* wideConstraints; + struct b3ContactConstraintWide* wideConstraints; int wideConstraintCount; - void* wideMeshConstraints; - int* wideMeshManifoldStarts; - int wideMeshConstraintCount; - // These are used for mesh and overflow contacts struct b3ManifoldConstraint* manifoldConstraints; + int manifoldConstraintCount; struct b3ContactConstraint* contactConstraints; + int contactConstraintCount; } b3GraphColor; typedef struct b3ConstraintGraph diff --git a/src/contact.c b/src/contact.c index e1d94ff..3486e3c 100644 --- a/src/contact.c +++ b/src/contact.c @@ -5,6 +5,7 @@ #include "algorithm.h" #include "body.h" +#include "compound.h" #include "island.h" #include "manifold.h" #include "physics_world.h" @@ -19,7 +20,7 @@ // The order must reproduce from run to run. This is necessary because the Gauss-Seidel constraint solver is order dependent. // // Creation: -// - Contacts are created using results from the broad-phase pair update +// - Contacts are created using results from b3UpdateBroadPhasePairs // - These results are ordered according to the order of the broad-phase move array // - The move array is ordered according to the shape creation order using a bitset. // - The island/shape/body order is determined by creation order @@ -183,7 +184,7 @@ void b3CreateContact( b3World* world, b3Shape* shapeA, b3Shape* shapeB, int chil setIndex = b3_disabledSet; } - b3SolverSet* set = b3GetFixedSolverSet( world, setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); // Create contact key and contact int contactId = b3AllocId( &world->contactIdPool ); @@ -209,8 +210,12 @@ void b3CreateContact( b3World* world, b3Shape* shapeA, b3Shape* shapeB, int chil contact->shapeIdA = shapeIdA; contact->shapeIdB = shapeIdB; contact->childIndex = childIndex; - contact->encodedBodySimA = b3EncodeBodySimIndex( bodyA ); - contact->encodedBodySimB = b3EncodeBodySimIndex( bodyB ); + + // Both bodies must enable recycling + if ( ( bodyA->flags & b3_bodyEnableContactRecycling ) != 0 && ( bodyB->flags & b3_bodyEnableContactRecycling ) != 0 ) + { + contact->flags |= b3_contactRecycleFlag; + } if ( shapeA->type == b3_meshShape || shapeA->type == b3_heightShape ) { @@ -238,23 +243,11 @@ void b3CreateContact( b3World* world, b3Shape* shapeA, b3Shape* shapeB, int chil B3_ASSERT( shapeA->sensorIndex == B3_NULL_INDEX && shapeB->sensorIndex == B3_NULL_INDEX ); - if ( ( shapeA->flags & b3_enableContactEvents ) || ( shapeB->flags & b3_enableContactEvents ) ) + if ( shapeA->enableContactEvents || shapeB->enableContactEvents ) { contact->flags |= b3_contactEnableContactEvents; } - if ( ( shapeA->flags & b3_enableSpeculative ) && ( shapeB->flags & b3_enableSpeculative ) ) - { - contact->flags |= b3_enableSpeculativePoints; - } - - // Disabling speculative collision also disables recycling. - if ( ( bodyA->flags & b3_enableContactRecycling ) != 0 && ( bodyB->flags & b3_enableContactRecycling ) != 0 && - ( contact->flags & b3_enableSpeculativePoints ) != 0 ) - { - contact->flags |= b3_contactRecycleFlag; - } - // Connect to body A { contact->edges[0].bodyId = shapeA->bodyId; @@ -324,7 +317,7 @@ void b3CreateContact( b3World* world, b3Shape* shapeA, b3Shape* shapeB, int chil b3MaxFloat( b3GetShapeMaterials( shapeA )[0].rollingResistance, b3GetShapeMaterials( shapeB )[0].rollingResistance ) * maxRadius; - if ( ( shapeA->flags & b3_enablePreSolveEvents ) || ( shapeB->flags & b3_enablePreSolveEvents ) ) + if ( shapeA->enablePreSolveEvents || shapeB->enablePreSolveEvents ) { contact->flags |= b3_simEnablePreSolveEvents; } @@ -453,7 +446,7 @@ void b3DestroyContact( b3World* world, b3Contact* contact, bool wakeBodies ) { // contact is non-touching or is sleeping or is a sensor B3_ASSERT( contact->setIndex != b3_awakeSet || ( contact->flags & b3_contactTouchingFlag ) == 0 ); - b3SolverSet* set = b3GetSolverSet( world, contact->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, contact->setIndex ); int localIndex = contact->localIndex; int movedIndex = b3Array_RemoveSwap( set->contactIndices, localIndex ); @@ -487,7 +480,7 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact* b3ContactCache* cache = &contact->convexContact.cache; - int pointCapacity = B3_MAX_MANIFOLD_POINTS; + int pointCapacity = 32; b3LocalManifoldPoint* pointBuffer = (b3LocalManifoldPoint*)b3Bump( &arena, pointCapacity * sizeof( b3LocalManifoldPoint ) ); b3LocalManifold geomManifold = { 0 }; @@ -529,8 +522,7 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact* else { B3_ASSERT( typeB == b3_hullShape ); - b3CollideHullsAtWidth( &geomManifold, pointCapacity, shapeA->hull, shapeB->hull, transformBtoA, &cache->satCache, - world->simdWidth ); + b3CollideHulls( &geomManifold, pointCapacity, shapeA->hull, shapeB->hull, transformBtoA, &cache->satCache ); world->taskContexts.data[workerIndex].satCallCount += 1; world->taskContexts.data[workerIndex].satCacheHitCount += cache->satCache.hit; } @@ -563,7 +555,6 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact* } b3Manifold* manifold = contact->manifolds; - B3_ASSERT( 0 < geomManifold.pointCount && geomManifold.pointCount <= B3_MAX_MANIFOLD_POINTS ); manifold->pointCount = geomManifold.pointCount; b3Matrix3 matrixA = b3MakeMatrixFromQuat( xfA.q ); @@ -581,8 +572,6 @@ static bool b3ComputeConvexManifold( b3World* world, int workerIndex, b3Contact* target->separation = source->separation; target->featureId = b3MakeFeatureId( source->pair ); target->triangleIndex = B3_NULL_INDEX; - target->triangleFeature = b3_featureNone; - target->meshFlags = 0; target->normalVelocity = 0.0f; } @@ -714,14 +703,11 @@ static bool b3UpdateConvexContact( b3World* world, int workerIndex, b3Contact* c b3FreeManifolds( world, contact->manifolds, contact->manifoldCount ); contact->manifolds = NULL; contact->manifoldCount = 0; - - // Invalidate recycling cache. - contact->flags &= ~b3_relativeTransformValid; return false; } } - if ( ( shapeA->flags & b3_enableHitEvents ) || ( shapeB->flags & b3_enableHitEvents ) ) + if ( shapeA->enableHitEvents || shapeB->enableHitEvents ) { contact->flags |= b3_simEnableHitEvent; } @@ -735,9 +721,8 @@ static bool b3UpdateConvexContact( b3World* world, int workerIndex, b3Contact* c // Update the contact manifold and touching status. // Note: do not assume the shape AABBs are overlapping or are valid. -bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Shape* shapeA, b3Vec3 localCenterA, - b3WorldTransform xfA, b3Shape* shapeB, b3Vec3 localCenterB, b3WorldTransform xfB, bool isFast, - b3Arena arena ) +bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Shape* shapeA, b3Vec3 localCenterA, b3WorldTransform xfA, + b3Shape* shapeB, b3Vec3 localCenterB, b3WorldTransform xfB, bool isFast, b3Arena arena ) { bool touching; @@ -754,16 +739,6 @@ bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Sha childShapeA.type = child.type; - // Handle child material for non-meshes. - if ( child.type != b3_meshShape ) - { - B3_ASSERT( 0 <= child.materialIndices[0] && child.materialIndices[0] < shapeA->materialCount ); - const b3SurfaceMaterial* parentMaterials = b3GetShapeMaterials( shapeA ); - childShapeA.material = parentMaterials[child.materialIndices[0]]; - childShapeA.materials = NULL; - childShapeA.materialCount = 1; - } - if ( child.type == b3_capsuleShape ) { childShapeA.capsule = child.capsule; @@ -794,7 +769,7 @@ bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Sha touching = b3ComputeMeshManifolds( world, workerIndex, contact, &childShapeA, child.materialIndices, xfChild, shapeB, xfB, isFast, arena ); - if ( touching && ( ( shapeA->flags & b3_enableHitEvents ) || ( shapeB->flags & b3_enableHitEvents ) ) ) + if ( touching && ( shapeA->enableHitEvents || shapeB->enableHitEvents ) ) { contact->flags |= b3_simEnableHitEvent; } @@ -846,7 +821,7 @@ bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Sha // Compute mesh manifolds touching = b3ComputeMeshManifolds( world, workerIndex, contact, shapeA, NULL, xfA, shapeB, xfB, isFast, arena ); - if ( touching && ( ( shapeA->flags & b3_enableHitEvents ) || ( shapeB->flags & b3_enableHitEvents ) ) ) + if ( touching && ( shapeA->enableHitEvents || shapeB->enableHitEvents ) ) { contact->flags |= b3_simEnableHitEvent; } diff --git a/src/contact.h b/src/contact.h index 5aae9a4..bd5b91a 100644 --- a/src/contact.h +++ b/src/contact.h @@ -9,6 +9,8 @@ #include "box3d/collision.h" #include "box3d/types.h" +#define B3_FORCE_GHOST_COLLISIONS 0 + typedef struct b3Shape b3Shape; typedef struct b3World b3World; @@ -63,11 +65,8 @@ enum b3ContactFlags // This is a mesh contact b3_simMeshContact = 0x00400000, - // Relative transform is cached for contact recycling - b3_relativeTransformValid = 0x00800000, - // Enable speculative contact points - b3_enableSpeculativePoints = 0x01000000, + b3_relativeTransformValid = 0x00800000, }; // A contact edge is used to connect bodies and contacts together @@ -124,14 +123,13 @@ typedef struct b3Contact // Back index into b3World::contacts int contactId; - // Encoded body sim indices to avoid a cache miss accessing the body in the narrow phase. - int encodedBodySimA; - int encodedBodySimB; + // These are transient and cached for improved performance. B3_NULL_INDEX for static bodies. + int bodySimIndexA; + int bodySimIndexB; // b3ContactFlags uint32_t flags; - // todo embed single manifold with ability to allocate overfloat, use union. b3Manifold* manifolds; int manifoldCount; @@ -178,6 +176,5 @@ void b3DestroyContact( b3World* world, b3Contact* contact, bool wakeBodies ); bool b3UpdateContact( b3World* world, int workerIndex, b3Contact* contact, b3Shape* shapeA, b3Vec3 localCenterA, b3WorldTransform xfA, b3Shape* shapeB, b3Vec3 localCenterB, b3WorldTransform xfB, bool isFast, b3Arena arena ); -bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact, const b3Shape* shapeA, - const uint16_t* materialMap, b3WorldTransform xfA, const b3Shape* shapeB, b3WorldTransform xfB, - bool isFast, b3Arena arena ); +bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact, const b3Shape* shapeA, const int* materialMap, + b3WorldTransform xfA, const b3Shape* shapeB, b3WorldTransform xfB, bool isFast, b3Arena arena ); diff --git a/src/contact_solver.c b/src/contact_solver.c index d1714fe..c0f58e0 100644 --- a/src/contact_solver.c +++ b/src/contact_solver.c @@ -10,14 +10,13 @@ #include "math_internal.h" #include "physics_world.h" #include "platform.h" -#include "simd.h" #include "solver_set.h" #if B3_ENABLE_VALIDATION #include "shape.h" #endif -// todo clean this file up because it is only used for overflow now +#define FIXED_ANCHORS 1 // contact separation for sub-stepping // s = s0 + dot(cB + rB - cA - rA, normal) @@ -28,26 +27,30 @@ // s(t) = s0 + dot(cB0 - cA0, normal) + dot(dpB - dpA + rot(dqB, rB0) - rot(dqA, rA0), normal) // s_base = s0 + dot(cB0 - cA0, normal) -// Prepare overflow constraints +// Prepare a mesh constraints void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) { b3TracyCZoneNC( prepare_contact, "Prepare Contact", b3_colorYellow, true ); b3World* world = context->world; b3BodySim* bodySims = context->sims; - b3BodyState* states = context->states; + b3BodyState* bodyStates = context->states; float warmStartScale = world->enableWarmStarting ? 1.0f : 0.0f; - bool anyRestitution = false; - // Used for friction center weighting. - float invTau = 1.0f / B3_SPECULATIVE_DISTANCE; + // Need to use spans in order to find the associated b2Contact, which is per color + b3ContactPrepareSpan* spans = context->contactPrepareSpans; + b3ManifoldConstraint* manifoldBase = context->manifoldConstraints; + b3ContactConstraint* base = context->contactConstraints; - B3_ASSERT( block.blockType == b3_overflowBlock ); - b3GraphColor* overflow = world->constraintGraph.colors + B3_OVERFLOW_INDEX; - b3ContactPrepareSpan* spans = context->overflowSpans; - b3ManifoldConstraint* manifoldBase = overflow->manifoldConstraints; - b3ContactConstraint* base = overflow->contactConstraints; + // Overflow constraints are stored separately + if ( block.blockType == b3_overflowBlock ) + { + b3GraphColor* overflow = world->constraintGraph.colors + B3_OVERFLOW_INDEX; + spans = context->overflowSpans; + manifoldBase = overflow->manifoldConstraints; + base = overflow->contactConstraints; + } int index = block.startIndex; int endIndex = block.startIndex + block.count; @@ -74,51 +77,72 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) int localIndex = index - colorStart; B3_ASSERT( 0 <= localIndex && localIndex < spans[colorIndex].count ); int contactId = specs[localIndex].contactId; - b3Contact* contact = b3Array_Get( world->contacts, contactId ); + b3Contact* contact = b3Array_Get( world->contacts, contactId ); B3_ASSERT( contact->contactId == contactId ); - int indexA = b3DecodeAwakeIndex( contact->encodedBodySimA ); - int indexB = b3DecodeAwakeIndex( contact->encodedBodySimB ); + int indexA = contact->bodySimIndexA; + int indexB = contact->bodySimIndexB; #if B3_ENABLE_VALIDATION + if ( indexA != B3_NULL_INDEX ) { - b3Body* bodyA = b3Array_Get( world->bodies, contact->edges[0].bodyId ); - b3Body* bodyB = b3Array_Get( world->bodies, contact->edges[1].bodyId ); - B3_ASSERT( contact->encodedBodySimA == b3EncodeBodySimIndex( bodyA ) ); - B3_ASSERT( contact->encodedBodySimB == b3EncodeBodySimIndex( bodyB ) ); + b3Body* bodyA = b3Array_Get( world->bodies, contact->edges[0].bodyId ); + B3_ASSERT( indexA == bodyA->localIndex ); + } + + if ( indexB != B3_NULL_INDEX ) + { + b3Body* bodyB = b3Array_Get( world->bodies, contact->edges[1].bodyId ); + B3_ASSERT( indexB == bodyB->localIndex ); } #endif // Body A data float mA; b3Matrix3 iA; + b3Vec3 vA; + b3Vec3 wA; if ( indexA == B3_NULL_INDEX ) { mA = 0.0f; iA = b3Mat3_zero; + vA = b3Vec3_zero; + wA = b3Vec3_zero; } else { b3BodySim* simA = bodySims + indexA; mA = simA->invMass; iA = simA->invInertiaWorld; + + b3BodyState* stateA = bodyStates + indexA; + vA = stateA->linearVelocity; + wA = stateA->angularVelocity; } // Body B data float mB; b3Matrix3 iB; + b3Vec3 vB; + b3Vec3 wB; if ( indexB == B3_NULL_INDEX ) { mB = 0.0f; iB = b3Mat3_zero; + vB = b3Vec3_zero; + wB = b3Vec3_zero; } else { b3BodySim* simB = bodySims + indexB; mB = simB->invMass; iB = simB->invInertiaWorld; + + b3BodyState* stateB = bodyStates + indexB; + vB = stateB->linearVelocity; + wB = stateB->angularVelocity; } int manifoldCount = contact->manifoldCount; @@ -137,32 +161,6 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) contactConstraint->restitution = contact->restitution; contactConstraint->rollingResistance = contact->rollingResistance; - // Only sample contact point normal velocity if needed. - bool haveRestitution = contact->restitution > 0.0f; - bool hitEvents = ( contact->flags & b3_simEnableHitEvent ) != 0; - bool sampleVelocity = haveRestitution || hitEvents; - anyRestitution = anyRestitution || haveRestitution; - - b3Vec3 vA = b3Vec3_zero; - b3Vec3 wA = b3Vec3_zero; - b3Vec3 vB = b3Vec3_zero; - b3Vec3 wB = b3Vec3_zero; - - if ( sampleVelocity ) - { - if ( indexA != B3_NULL_INDEX ) - { - vA = states[indexA].linearVelocity; - wA = states[indexA].angularVelocity; - } - - if ( indexB != B3_NULL_INDEX ) - { - vB = states[indexB].linearVelocity; - wB = states[indexB].angularVelocity; - } - } - b3ManifoldConstraint* manifoldConstraints = manifoldBase + specs[localIndex].manifoldStart; contactConstraint->constraints = manifoldConstraints; @@ -186,7 +184,6 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) b3Vec3 centerA = b3Vec3_zero; b3Vec3 centerB = b3Vec3_zero; - float totalFrictionWeight = 0.0f; for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) { @@ -196,12 +193,10 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) b3ManifoldPoint* mp = manifold->points + pointIndex; cp->rA = mp->anchorA; cp->rB = mp->anchorB; - - float s = mp->separation; - cp->baseSeparation = s - b3Dot( b3Sub( cp->rB, cp->rA ), normal ); + cp->baseSeparation = mp->separation - b3Dot( b3Sub( cp->rB, cp->rA ), normal ); cp->normalImpulse = warmStartScale * mp->normalImpulse; cp->totalNormalImpulse = 0.0f; - cp->restitutionImpulse = 0.0f; + cp->stepNormalImpulse = 0.0f; b3Vec3 rA = cp->rA; b3Vec3 rB = cp->rB; @@ -211,42 +206,20 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) float kNormal = mA + mB + b3Dot( rnA, b3MulMV( iA, rnA ) ) + b3Dot( rnB, b3MulMV( iB, rnB ) ); cp->normalMass = kNormal > 0.0f ? 1.0f / kNormal : 0.0f; - // Only compute the normal velocity terms if needed. - if ( sampleVelocity ) - { - b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); - b3Vec3 vrB = b3Add( vB, b3Cross( wB, rB ) ); - float vn = b3Dot( normal, b3Sub( vrB, vrA ) ); + // Save relative velocity for restitution + b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); + b3Vec3 vrB = b3Add( vB, b3Cross( wB, rB ) ); + cp->relativeVelocity = b3Dot( normal, b3Sub( vrB, vrA ) ); - cp->relativeVelocity = vn; - mp->normalVelocity = hitEvents ? vn : 0.0f; - } - else - { - cp->relativeVelocity = 0.0f; - mp->normalVelocity = 0.0f; - } - - // C0 friction center decay. Needed to prevent spinning top drift (GyroscopicPrecession sample). - // Contacts with separation greater than twice the speculative distance only matter for CCD and - // should not contribute to the friction center. They are not important for jitter reduction. Closer - // points may begin to touch on and off, so the friction center needs to move smoothly. - // Epsilon to avoid a branch below (or divide by zero). Small enough to get washed out normally. - // - // Dirk suggested to weight the points by their normal impulse. This would use the total impulse from - // the previous time step. I suspect this could jump around if the active point set jitters, leading - // to a limit cycle. - float weight = b3ClampFloat( 2.0f - s * invTau, B3_MIN_FRICTION_WEIGHT, 1.0f ); - centerA = b3MulAdd( centerA, weight, rA ); - centerB = b3MulAdd( centerB, weight, rB ); - totalFrictionWeight += weight; + centerA = b3Add( centerA, rA ); + centerB = b3Add( centerB, rB ); } - float invWeight = 1.0f / totalFrictionWeight; - centerA = b3MulSV( invWeight, centerA ); - centerB = b3MulSV( invWeight, centerB ); - constraint->centerA = centerA; - constraint->centerB = centerB; + float invCount = 1.0f / pointCount; + centerA = b3MulSV( invCount, centerA ); + centerB = b3MulSV( invCount, centerB ); + constraint->originA = centerA; + constraint->originB = centerB; for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) { @@ -286,11 +259,6 @@ void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ) colorIndex += 1; } - if ( anyRestitution ) - { - b3AtomicStoreInt( &context->anyRestitution, 1 ); - } - b3TracyCZoneEnd( prepare_contact ); } @@ -298,7 +266,7 @@ void b3WarmStartContacts_Mesh( b3SolverBlock block, b3StepContext* context ) { b3World* world = context->world; b3GraphColor* color = world->constraintGraph.colors + block.colorIndex; - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodyState* states = awakeSet->bodyStates.data; b3ContactConstraint* constraints = color->contactConstraints; @@ -311,10 +279,21 @@ void b3WarmStartContacts_Mesh( b3SolverBlock block, b3StepContext* context ) for ( int constraintIndex = startIndex; constraintIndex < endIndex; ++constraintIndex ) { const b3ContactConstraint* contactConstraint = constraints + constraintIndex; + int indexA = contactConstraint->indexA; + int indexB = contactConstraint->indexB; - b3Vec3 linearImpulse = b3Vec3_zero; - b3Vec3 angularImpulseA = b3Vec3_zero; - b3Vec3 angularImpulseB = b3Vec3_zero; + b3BodyState* stateA = indexA == B3_NULL_INDEX ? &dummyState : states + indexA; + b3BodyState* stateB = indexB == B3_NULL_INDEX ? &dummyState : states + indexB; + + b3Vec3 vA = stateA->linearVelocity; + b3Vec3 wA = stateA->angularVelocity; + b3Vec3 vB = stateB->linearVelocity; + b3Vec3 wB = stateB->angularVelocity; + + float mA = contactConstraint->invMassA; + b3Matrix3 iA = contactConstraint->invIA; + float mB = contactConstraint->invMassB; + b3Matrix3 iB = contactConstraint->invIB; int manifoldCount = contactConstraint->manifoldCount; for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) @@ -323,70 +302,73 @@ void b3WarmStartContacts_Mesh( b3SolverBlock block, b3StepContext* context ) // Normal impulses b3Vec3 normal = constraint->normal; - float totalNormalImpulse = 0.0f; - b3Vec3 momentA = b3Vec3_zero; - b3Vec3 momentB = b3Vec3_zero; - int pointCount = constraint->pointCount; for ( int j = 0; j < pointCount; ++j ) { const b3ManifoldConstraintPoint* cp = constraint->points + j; // fixed anchors - totalNormalImpulse += cp->normalImpulse; - momentA = b3MulAdd( momentA, cp->normalImpulse, cp->rA ); - momentB = b3MulAdd( momentB, cp->normalImpulse, cp->rB ); + b3Vec3 rA = cp->rA; + b3Vec3 rB = cp->rB; + + b3Vec3 impulse = b3MulSV( cp->normalImpulse, normal ); + wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, impulse ) ) ); + vA = b3MulSub( vA, mA, impulse ); + wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, impulse ) ) ); + vB = b3MulAdd( vB, mB, impulse ); } // Central friction - b3Vec3 frictionImpulse = b3MulSV( constraint->frictionImpulse.x, constraint->tangent1 ); - frictionImpulse = b3MulAdd( frictionImpulse, constraint->frictionImpulse.y, constraint->tangent2 ); + { + b3Vec3 rA = constraint->originA; + b3Vec3 rB = constraint->originB; + b3Vec3 impulse = b3MulSV( constraint->frictionImpulse.x, constraint->tangent1 ); + impulse = b3Add( impulse, b3MulSV( constraint->frictionImpulse.y, constraint->tangent2 ) ); - linearImpulse = b3Add( linearImpulse, b3MulAdd( frictionImpulse, totalNormalImpulse, normal ) ); + wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, impulse ) ) ); + vA = b3MulSub( vA, mA, impulse ); + wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, impulse ) ) ); + vB = b3MulAdd( vB, mB, impulse ); + } // Central twist friction - b3Vec3 twistImpulse = b3MulSV( constraint->twistImpulse, normal ); - - b3Vec3 angularA = - b3Add( b3Add( b3Cross( momentA, normal ), b3Cross( constraint->centerA, frictionImpulse ) ), twistImpulse ); - b3Vec3 angularB = - b3Add( b3Add( b3Cross( momentB, normal ), b3Cross( constraint->centerB, frictionImpulse ) ), twistImpulse ); + { + b3Vec3 impulse = b3MulSV( constraint->twistImpulse, constraint->normal ); + wA = b3Sub( wA, b3MulMV( iA, impulse ) ); + wB = b3Add( wB, b3MulMV( iB, impulse ) ); + } // Rolling resistance - angularImpulseA = b3Add( angularImpulseA, b3Add( angularA, constraint->rollingImpulse ) ); - angularImpulseB = b3Add( angularImpulseB, b3Add( angularB, constraint->rollingImpulse ) ); + { + b3Vec3 impulse = constraint->rollingImpulse; + wA = b3Sub( wA, b3MulMV( iA, impulse ) ); + wB = b3Add( wB, b3MulMV( iB, impulse ) ); + } } - int indexA = contactConstraint->indexA; - int indexB = contactConstraint->indexB; - - b3BodyState* stateA = indexA == B3_NULL_INDEX ? &dummyState : states + indexA; - b3BodyState* stateB = indexB == B3_NULL_INDEX ? &dummyState : states + indexB; - if ( stateA->flags & b3_dynamicFlag ) { - stateA->linearVelocity = b3MulSub( stateA->linearVelocity, contactConstraint->invMassA, linearImpulse ); - stateA->angularVelocity = b3Sub( stateA->angularVelocity, b3MulMV( contactConstraint->invIA, angularImpulseA ) ); + stateA->linearVelocity = vA; + stateA->angularVelocity = wA; } if ( stateB->flags & b3_dynamicFlag ) { - stateB->linearVelocity = b3MulAdd( stateB->linearVelocity, contactConstraint->invMassB, linearImpulse ); - stateB->angularVelocity = b3Add( stateB->angularVelocity, b3MulMV( contactConstraint->invIB, angularImpulseB ) ); + stateB->linearVelocity = vB; + stateB->angularVelocity = wB; } } } // Merged normal and friction loops. This is much more stable for the Jenga stack. -// Solve the non-penetration constraints with the soft bias. No friction and no restitution. -void b3PushContacts_Mesh( b3SolverBlock block, b3StepContext* context ) +void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context, bool useBias ) { b3World* world = context->world; b3GraphColor* color = world->constraintGraph.colors + block.colorIndex; b3ContactConstraint* contactConstraints = color->contactConstraints; b3BodyState* states = context->states; - // This is a dummy state to represent a static body because static bodies have no solver body. + // This is a dummy state to represent a static body because static bodies don't have a solver body. b3BodyState dummyState = b3_identityBodyState; // The last block might not be full @@ -421,123 +403,6 @@ void b3PushContacts_Mesh( b3SolverBlock block, b3StepContext* context ) b3Vec3 dp = b3Sub( stateB->deltaPosition, stateA->deltaPosition ); b3Softness softness = contactConstraint->softness; - - for ( int j = 0; j < manifoldCount; ++j ) - { - b3ManifoldConstraint* constraint = contactConstraint->constraints + j; - - int pointCount = constraint->pointCount; - b3Vec3 normal = constraint->normal; - - for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) - { - b3ManifoldConstraintPoint* cp = constraint->points + pointIndex; - - // Fixed anchor points for applying impulses - b3Vec3 rA = cp->rA; - b3Vec3 rB = cp->rB; - - // compute current separation - // this is subject to round-off error if the anchor is far from the body center of mass - b3Vec3 ds = b3Add( dp, b3Sub( b3RotateVector( dqB, rB ), b3RotateVector( dqA, rA ) ) ); - float s = b3Dot( ds, normal ) + cp->baseSeparation; - - float velocityBias; - float massScale; - float impulseScale; - if ( s > 0.0f ) - { - // speculative bias is positive - velocityBias = s * inv_h; - massScale = 1.0f; - impulseScale = 0.0f; - } - else - { - // overlap bias is negative - velocityBias = b3MaxFloat( softness.massScale * softness.biasRate * s, -contactSpeed ); - massScale = softness.massScale; - impulseScale = softness.impulseScale; - } - - // relative normal velocity at contact - b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); - b3Vec3 vrB = b3Add( vB, b3Cross( wB, rB ) ); - float vn = b3Dot( b3Sub( vrB, vrA ), normal ); - - // incremental normal impulse - float deltaImpulse = -cp->normalMass * ( massScale * vn + velocityBias ) - impulseScale * cp->normalImpulse; - - // clamp the accumulated impulse - float newImpulse = b3MaxFloat( cp->normalImpulse + deltaImpulse, 0.0f ); - deltaImpulse = newImpulse - cp->normalImpulse; - cp->normalImpulse = newImpulse; - - // apply normal impulse - b3Vec3 P = b3MulSV( deltaImpulse, normal ); - vA = b3MulSub( vA, mA, P ); - wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, P ) ) ); - - vB = b3MulAdd( vB, mB, P ); - wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, P ) ) ); - } - } - - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = vA; - stateA->angularVelocity = wA; - } - - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = vB; - stateB->angularVelocity = wB; - } - } -} - -// Solve contacts: normal, friction and rolling resistance. -void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) -{ - b3World* world = context->world; - b3GraphColor* color = world->constraintGraph.colors + block.colorIndex; - b3ContactConstraint* contactConstraints = color->contactConstraints; - b3BodyState* states = context->states; - - // This is a dummy state to represent a static body because static bodies have no solver body. - b3BodyState dummyState = b3_identityBodyState; - - // The last block might not be full - int startIndex = block.startIndex; - int endIndex = startIndex + block.count; - - float inv_h = context->inv_h; - - for ( int i = startIndex; i < endIndex; ++i ) - { - b3ContactConstraint* contactConstraint = contactConstraints + i; - int manifoldCount = contactConstraint->manifoldCount; - - int indexA = contactConstraint->indexA; - int indexB = contactConstraint->indexB; - - float mA = contactConstraint->invMassA; - b3Matrix3 iA = contactConstraint->invIA; - float mB = contactConstraint->invMassB; - b3Matrix3 iB = contactConstraint->invIB; - - b3BodyState* stateA = indexA == B3_NULL_INDEX ? &dummyState : states + indexA; - b3Vec3 vA = stateA->linearVelocity; - b3Vec3 wA = stateA->angularVelocity; - b3Quat dqA = stateA->deltaRotation; - - b3BodyState* stateB = indexB == B3_NULL_INDEX ? &dummyState : states + indexB; - b3Vec3 vB = stateB->linearVelocity; - b3Vec3 wB = stateB->angularVelocity; - b3Quat dqB = stateB->deltaRotation; - - b3Vec3 dp = b3Sub( stateB->deltaPosition, stateA->deltaPosition ); float friction = contactConstraint->friction; float rollingResistance = contactConstraint->rollingResistance; @@ -564,8 +429,20 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) b3Vec3 ds = b3Add( dp, b3Sub( b3RotateVector( dqB, rB ), b3RotateVector( dqA, rA ) ) ); float s = b3Dot( ds, normal ) + cp->baseSeparation; - // speculative bias, zero when overlapped - float velocityBias = s > 0.0f ? s * inv_h : 0.0f; + float velocityBias = 0.0f; + float massScale = 1.0f; + float impulseScale = 0.0f; + if ( s > 0.0f ) + { + // speculative bias + velocityBias = s * inv_h; + } + else if ( useBias ) + { + velocityBias = b3MaxFloat( softness.massScale * softness.biasRate * s, -contactSpeed ); + massScale = softness.massScale; + impulseScale = softness.impulseScale; + } // relative normal velocity at contact b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); @@ -573,15 +450,17 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) float vn = b3Dot( b3Sub( vrB, vrA ), normal ); // incremental normal impulse - float deltaImpulse = -cp->normalMass * ( vn + velocityBias ); + float deltaImpulse = -cp->normalMass * ( massScale * vn + velocityBias ) - impulseScale * cp->normalImpulse; // clamp the accumulated impulse float newImpulse = b3MaxFloat( cp->normalImpulse + deltaImpulse, 0.0f ); deltaImpulse = newImpulse - cp->normalImpulse; cp->normalImpulse = newImpulse; cp->totalNormalImpulse += newImpulse; + if ( useBias == false ) cp->stepNormalImpulse += newImpulse; + totalNormalImpulse += newImpulse; - totalTwistLimit += cp->leverArm * newImpulse; + totalTwistLimit += cp->leverArm * cp->normalImpulse; // apply normal impulse b3Vec3 P = b3MulSV( deltaImpulse, normal ); @@ -592,6 +471,13 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, P ) ) ); } + // No friction when applying bias + if ( useBias == true ) + { + // Go to next manifold + continue; + } + // Central twist friction { float twistSpeed = b3Dot( constraint->normal, b3Sub( wB, wA ) ); @@ -631,8 +517,8 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) b3Vec3 tangent2 = constraint->tangent2; // Fixed anchor points for applying impulses - b3Vec3 rA = constraint->centerA; - b3Vec3 rB = constraint->centerB; + b3Vec3 rA = constraint->originA; + b3Vec3 rB = constraint->originB; // Relative tangent velocity at contact b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); @@ -689,129 +575,106 @@ void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ) void b3ApplyRestitution_Mesh( b3SolverBlock block, b3StepContext* context ) { - b3TracyCZoneNC( restitution_mesh, "Restitution Mesh", b3_colorViolet, true ); - b3World* world = context->world; b3GraphColor* color = world->constraintGraph.colors + block.colorIndex; - b3ContactConstraint* contactConstraints = color->contactConstraints; b3BodyState* states = context->states; + b3ContactConstraint* constraints = color->contactConstraints; - float threshold = world->restitutionThreshold; - float inv_h = context->inv_h; - bool propagate = world->enableRestitutionPropagation; - + // This is a dummy state to represent a static body because static bodies don't have a solver body. b3BodyState dummyState = b3_identityBodyState; int startIndex = block.startIndex; int endIndex = startIndex + block.count; - for ( int i = startIndex; i < endIndex; ++i ) + float threshold = context->world->restitutionThreshold; + + for ( int constraintIndex = startIndex; constraintIndex < endIndex; ++constraintIndex ) { - b3ContactConstraint* contactConstraint = contactConstraints + i; + const b3ContactConstraint* contactConstraint = constraints + constraintIndex; float restitution = contactConstraint->restitution; - if ( propagate == false && restitution == 0.0f ) + if ( restitution == 0.0f ) { continue; } - int manifoldCount = contactConstraint->manifoldCount; - int indexA = contactConstraint->indexA; int indexB = contactConstraint->indexB; + b3BodyState* stateA = indexA == B3_NULL_INDEX ? &dummyState : states + indexA; + b3BodyState* stateB = indexB == B3_NULL_INDEX ? &dummyState : states + indexB; + + b3Vec3 vA = stateA->linearVelocity; + b3Vec3 wA = stateA->angularVelocity; + b3Vec3 vB = stateB->linearVelocity; + b3Vec3 wB = stateB->angularVelocity; + float mA = contactConstraint->invMassA; b3Matrix3 iA = contactConstraint->invIA; float mB = contactConstraint->invMassB; b3Matrix3 iB = contactConstraint->invIB; - b3BodyState* stateA = indexA == B3_NULL_INDEX ? &dummyState : states + indexA; - b3Vec3 vA = stateA->linearVelocity; - b3Vec3 wA = stateA->angularVelocity; - b3Quat dqA = stateA->deltaRotation; - - b3BodyState* stateB = indexB == B3_NULL_INDEX ? &dummyState : states + indexB; - b3Vec3 vB = stateB->linearVelocity; - b3Vec3 wB = stateB->angularVelocity; - b3Quat dqB = stateB->deltaRotation; - - b3Vec3 dp = b3Sub( stateB->deltaPosition, stateA->deltaPosition ); - - for ( int j = 0; j < manifoldCount; ++j ) + int manifoldCount = contactConstraint->manifoldCount; + for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) { - b3ManifoldConstraint* constraint = contactConstraint->constraints + j; + b3ManifoldConstraint* cm = contactConstraint->constraints + manifoldIndex; - int pointCount = constraint->pointCount; - b3Vec3 normal = constraint->normal; + b3Vec3 normal = cm->normal; + int pointCount = cm->pointCount; + B3_ASSERT( 0 < pointCount && pointCount <= B3_MAX_MANIFOLD_POINTS ); for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) { - b3ManifoldConstraintPoint* cp = constraint->points + pointIndex; + b3ManifoldConstraintPoint* cp = cm->points + pointIndex; + // If the total normal impulse is zero then there was no collision + // this skips speculative contact points that didn't generate an impulse + // The max normal impulse is used in case there was a collision that moved away within the sub-step + // process + if ( cp->relativeVelocity > -threshold || cp->totalNormalImpulse == 0.0f ) + { + continue; + } + + // fixed anchor points b3Vec3 rA = cp->rA; b3Vec3 rB = cp->rB; - // The total normal impulse is 0 for speculative points. - float compressionImpulse = cp->totalNormalImpulse - cp->restitutionImpulse; - bool armed = restitution > 0.0f && cp->relativeVelocity < -threshold && compressionImpulse > 0.0f; - - float velocityBias; - if ( armed ) - { - velocityBias = restitution * cp->relativeVelocity; - } - else - { - b3Vec3 ds = b3Add( dp, b3Sub( b3RotateVector( dqB, rB ), b3RotateVector( dqA, rA ) ) ); - float s = b3Dot( ds, normal ) + cp->baseSeparation; - - velocityBias = s > 0.0f ? s * inv_h : 0.0f; - } - - b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); + // relative normal velocity at contact b3Vec3 vrB = b3Add( vB, b3Cross( wB, rB ) ); + b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); float vn = b3Dot( b3Sub( vrB, vrA ), normal ); - float impulse = -cp->normalMass * ( vn + velocityBias ); + // compute normal impulse + float impulse = -cp->normalMass * ( vn + restitution * cp->relativeVelocity ); + // clamp the accumulated impulse float newImpulse = b3MaxFloat( cp->normalImpulse + impulse, 0.0f ); impulse = newImpulse - cp->normalImpulse; - - float approachImpulse = b3MinFloat( b3MaxFloat( -cp->normalMass * vn, 0.0f ), b3MaxFloat( impulse, 0.0f ) ); - - if ( armed ) - { - // Poisson kinetic restitution guarantees no energy gain. - float allowance = restitution * ( compressionImpulse + approachImpulse ) - cp->restitutionImpulse; - impulse = b3MinFloat( impulse, approachImpulse + b3MaxFloat( allowance, 0.0f ) ); - } - - cp->normalImpulse += impulse; - cp->restitutionImpulse += impulse - approachImpulse; + cp->normalImpulse = newImpulse; cp->totalNormalImpulse += impulse; + cp->stepNormalImpulse += impulse; + // apply contact impulse b3Vec3 P = b3MulSV( impulse, normal ); vA = b3MulSub( vA, mA, P ); wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, P ) ) ); - vB = b3MulAdd( vB, mB, P ); wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, P ) ) ); } - } - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = vA; - stateA->angularVelocity = wA; - } + if ( stateA->flags & b3_dynamicFlag ) + { + stateA->linearVelocity = vA; + stateA->angularVelocity = wA; + } - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = vB; - stateB->angularVelocity = wB; + if ( stateB->flags & b3_dynamicFlag ) + { + stateB->linearVelocity = vB; + stateB->angularVelocity = wB; + } } } - - b3TracyCZoneEnd( restitution_mesh ); } // Don't need to use spans for colors for this because the constraint to contact association @@ -820,10 +683,17 @@ void b3StoreImpulses_Mesh( b3SolverBlock block, b3StepContext* context, int work { b3World* world = context->world; - B3_ASSERT( block.blockType == b3_overflowBlock ); - b3GraphColor* overflow = world->constraintGraph.colors + B3_OVERFLOW_INDEX; - b3ContactPrepareSpan* spans = context->overflowSpans; - b3ContactConstraint* base = overflow->contactConstraints; + // Mirror b3PrepareContacts_Mesh: the per-color flat arrays and the overflow color + // each have their own (base, spans, manifoldBase). + b3ContactPrepareSpan* spans = context->contactPrepareSpans; + b3ContactConstraint* base = context->contactConstraints; + + if ( block.blockType == b3_overflowBlock ) + { + b3GraphColor* overflow = world->constraintGraph.colors + B3_OVERFLOW_INDEX; + spans = context->overflowSpans; + base = overflow->contactConstraints; + } b3TaskContext* taskContext = world->taskContexts.data + workerIndex; b3BitSet* hitEventBitSet = &taskContext->hitEventBitSet; @@ -887,9 +757,11 @@ void b3StoreImpulses_Mesh( b3SolverBlock block, b3StepContext* context, int work b3ManifoldPoint* mp = manifold->points + pointIndex; mp->normalImpulse = cp->normalImpulse; mp->totalNormalImpulse = cp->totalNormalImpulse; + mp->stepNormalImpulse = cp->stepNormalImpulse; + mp->normalVelocity = cp->relativeVelocity; - if ( checkHitEvents && flagged == false && mp->normalVelocity < negHitThreshold && - mp->totalNormalImpulse > 0.0f ) + if ( checkHitEvents && flagged == false && + mp->normalVelocity < negHitThreshold && mp->totalNormalImpulse > 0.0f ) { b3SetBit( hitEventBitSet, contact->contactId ); hasHitEvents = true; @@ -906,14 +778,1611 @@ void b3StoreImpulses_Mesh( b3SolverBlock block, b3StepContext* context, int work taskContext->hasHitEvents = hasHitEvents; } +#if defined( B3_SIMD_NEON ) + +#include + +// wide float holds 4 numbers +typedef float32x4_t b3FloatW; + +#elif defined( B3_SIMD_SSE2 ) + +#include + +// wide float holds 4 numbers +typedef __m128 b3FloatW; + +#else + +// scalar math +typedef struct b3FloatW +{ + float x, y, z, w; +} b3FloatW; + +#endif + +// Wide vec2 +typedef struct b3Vec2W +{ + b3FloatW x, y; +} b3Vec2W; + +// Wide vec3 +typedef struct b3Vec3W +{ + b3FloatW X, Y, Z; +} b3Vec3W; + +// Wide quaternion +typedef struct b3QuatW +{ + b3Vec3W V; + b3FloatW S; +} b3QuatW; + +// Wide symmetric matrix2 +typedef struct b3SymMatrix2W +{ + b3FloatW cxx, cxy, cyy; +} b3SymMatrix2W; + +// Wide symmetric matrix3 +typedef struct b3SymMatrix3W +{ + b3FloatW cxx, cxy, cxz, cyy, cyz, czz; +} b3SymMatrix3W; + +#if defined( B3_SIMD_NEON ) + +static inline b3FloatW b3ZeroW( void ) +{ + return vdupq_n_f32( 0.0f ); +} + +static inline b3FloatW b3SplatW( float scalar ) +{ + return vdupq_n_f32( scalar ); +} + +static inline b3FloatW b3NegW( b3FloatW a ) +{ + return vnegq_f32( a ); +} + +static inline b3FloatW b3SetW( float a, float b, float c, float d ) +{ + float32_t array[4] = { a, b, c, d }; + return vld1q_f32( array ); +} + +static inline b3FloatW b3AddW( b3FloatW a, b3FloatW b ) +{ + return vaddq_f32( a, b ); +} + +static inline b3FloatW b3SubW( b3FloatW a, b3FloatW b ) +{ + return vsubq_f32( a, b ); +} + +static inline b3FloatW b3MulW( b3FloatW a, b3FloatW b ) +{ + return vmulq_f32( a, b ); +} + +static inline b3FloatW b3DivW( b3FloatW a, b3FloatW b ) +{ + return vdivq_f32( a, b ); +} + +static inline b3FloatW b3SqrtW( b3FloatW a ) +{ + return vsqrtq_f32( a ); +} + +// Cannot use real FMA because it doesn't match the non-SIMD path +static inline b3FloatW b3MulAddW( b3FloatW a, b3FloatW b, b3FloatW c ) +{ + return vaddq_f32( a, vmulq_f32( b, c ) ); +} + +// static inline b3FloatW b3MulSubW( b3FloatW a, b3FloatW b, b3FloatW c ) +//{ +// return vsubq_f32( a, vmulq_f32( b, c ) ); +// } + +static inline b3FloatW b3MinW( b3FloatW a, b3FloatW b ) +{ + return vminq_f32( a, b ); +} + +static inline b3FloatW b3MaxW( b3FloatW a, b3FloatW b ) +{ + return vmaxq_f32( a, b ); +} + +// clamp a to [-b, b] +static inline b3FloatW b3SymClampW( b3FloatW a, b3FloatW b ) +{ + b3FloatW nb = b3NegW( b ); + b3FloatW c = b3MaxW( nb, a ); + return b3MinW( c, b ); +} + +static inline b3FloatW b3OrW( b3FloatW a, b3FloatW b ) +{ + return vreinterpretq_f32_u32( vorrq_u32( vreinterpretq_u32_f32( a ), vreinterpretq_u32_f32( b ) ) ); +} + +static inline b3FloatW b3GreaterThanW( b3FloatW a, b3FloatW b ) +{ + return vreinterpretq_f32_u32( vcgtq_f32( a, b ) ); +} + +static inline b3FloatW b3EqualsW( b3FloatW a, b3FloatW b ) +{ + return vreinterpretq_f32_u32( vceqq_f32( a, b ) ); +} + +static inline bool b3AllZeroW( b3FloatW a ) +{ + // Create a zero vector for comparison + b3FloatW zero = vdupq_n_f32( 0.0f ); + + // Compare the input vector with zero + uint32x4_t cmp_result = vceqq_f32( a, zero ); + +// Check if all comparison results are non-zero using vminvq +#ifdef __ARM_FEATURE_SVE + // ARM v8.2+ has horizontal minimum instruction + return vminvq_u32( cmp_result ) != 0; +#else + // For older ARM architectures, we need to manually check all lanes + return vgetq_lane_u32( cmp_result, 0 ) != 0 && vgetq_lane_u32( cmp_result, 1 ) != 0 && vgetq_lane_u32( cmp_result, 2 ) != 0 && + vgetq_lane_u32( cmp_result, 3 ) != 0; +#endif +} + +// component-wise returns mask ? b : a +static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask ) +{ + uint32x4_t mask32 = vreinterpretq_u32_f32( mask ); + return vbslq_f32( mask32, b, a ); +} + +#elif defined( B3_SIMD_SSE2 ) + +static inline b3FloatW b3ZeroW( void ) +{ + return _mm_setzero_ps(); +} + +static inline b3FloatW b3SplatW( float scalar ) +{ + return _mm_set1_ps( scalar ); +} + +static inline b3FloatW b3NegW( b3FloatW a ) +{ + // Create a mask with the sign bit set for each element + __m128 mask = _mm_set1_ps( -0.0f ); + + // XOR the input with the mask to negate each element + return _mm_xor_ps( a, mask ); +} + +static inline b3FloatW b3SetW( float a, float b, float c, float d ) +{ + return _mm_setr_ps( a, b, c, d ); +} + +static inline b3FloatW b3AddW( b3FloatW a, b3FloatW b ) +{ + return _mm_add_ps( a, b ); +} + +static inline b3FloatW b3SubW( b3FloatW a, b3FloatW b ) +{ + return _mm_sub_ps( a, b ); +} + +static inline b3FloatW b3MulW( b3FloatW a, b3FloatW b ) +{ + return _mm_mul_ps( a, b ); +} + +static inline b3FloatW b3DivW( b3FloatW a, b3FloatW b ) +{ + return _mm_div_ps( a, b ); +} + +static inline b3FloatW b3SqrtW( b3FloatW a ) +{ + return _mm_sqrt_ps( a ); +} + +static inline b3FloatW b3MulAddW( b3FloatW a, b3FloatW b, b3FloatW c ) +{ + return _mm_add_ps( a, _mm_mul_ps( b, c ) ); +} + +// static inline b3FloatW b3MulSubW( b3FloatW a, b3FloatW b, b3FloatW c ) +//{ +// return _mm_sub_ps( a, _mm_mul_ps( b, c ) ); +// } + +static inline b3FloatW b3MinW( b3FloatW a, b3FloatW b ) +{ + return _mm_min_ps( a, b ); +} + +static inline b3FloatW b3MaxW( b3FloatW a, b3FloatW b ) +{ + return _mm_max_ps( a, b ); +} + +// clamp a to [-b, b] +static inline b3FloatW b3SymClampW( b3FloatW a, b3FloatW b ) +{ + b3FloatW nb = b3NegW( b ); + b3FloatW c = b3MaxW( nb, a ); + return b3MinW( c, b ); +} + +static inline b3FloatW b3OrW( b3FloatW a, b3FloatW b ) +{ + return _mm_or_ps( a, b ); +} + +static inline b3FloatW b3GreaterThanW( b3FloatW a, b3FloatW b ) +{ + return _mm_cmpgt_ps( a, b ); +} + +static inline b3FloatW b3EqualsW( b3FloatW a, b3FloatW b ) +{ + return _mm_cmpeq_ps( a, b ); +} + +static inline bool b3AllZeroW( b3FloatW a ) +{ + // Compare each element with zero + b3FloatW zero = _mm_setzero_ps(); + b3FloatW cmp = _mm_cmpeq_ps( a, zero ); + + // Create a mask from the comparison results + int mask = _mm_movemask_ps( cmp ); + + // If all elements are zero, the mask will be 0xF (1111 in binary) + return mask == 0xF; +} + +// component-wise returns mask ? b : a +static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask ) +{ + return _mm_or_ps( _mm_and_ps( mask, b ), _mm_andnot_ps( mask, a ) ); +} + +#else + +static inline b3FloatW b3ZeroW( void ) +{ + return (b3FloatW){ 0.0f, 0.0f, 0.0f, 0.0f }; +} + +static inline b3FloatW b3SplatW( float scalar ) +{ + return (b3FloatW){ scalar, scalar, scalar, scalar }; +} + +static inline b3FloatW b3NegW( b3FloatW a ) +{ + return (b3FloatW){ -a.x, -a.y, -a.z, -a.w }; +} + +static inline b3FloatW b3AddW( b3FloatW a, b3FloatW b ) +{ + return (b3FloatW){ a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w }; +} + +static inline b3FloatW b3SubW( b3FloatW a, b3FloatW b ) +{ + return (b3FloatW){ a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w }; +} + +static inline b3FloatW b3MulW( b3FloatW a, b3FloatW b ) +{ + return (b3FloatW){ a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w }; +} + +static inline b3FloatW b3DivW( b3FloatW a, b3FloatW b ) +{ + return (b3FloatW){ a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w }; +} + +static inline b3FloatW b3SqrtW( b3FloatW a ) +{ + return (b3FloatW){ sqrtf( a.x ), sqrtf( a.y ), sqrtf( a.z ), sqrtf( a.w ) }; +} + +static inline b3FloatW b3MulAddW( b3FloatW a, b3FloatW b, b3FloatW c ) +{ + return (b3FloatW){ a.x + b.x * c.x, a.y + b.y * c.y, a.z + b.z * c.z, a.w + b.w * c.w }; +} + +// static inline b3FloatW b3MulSubW( b3FloatW a, b3FloatW b, b3FloatW c ) +//{ +// return { a.x - b.x * c.x, a.y - b.y * c.y, a.z - b.z * c.z, a.w - b.w * c.w }; +// } + +// static inline b3FloatW b3MinW( b3FloatW a, b3FloatW b ) +//{ +// b3FloatW r; +// r.x = a.x <= b.x ? a.x : b.x; +// r.y = a.y <= b.y ? a.y : b.y; +// r.z = a.z <= b.z ? a.z : b.z; +// r.w = a.w <= b.w ? a.w : b.w; +// return r; +// } + +static inline b3FloatW b3MaxW( b3FloatW a, b3FloatW b ) +{ + b3FloatW r; + r.x = a.x >= b.x ? a.x : b.x; + r.y = a.y >= b.y ? a.y : b.y; + r.z = a.z >= b.z ? a.z : b.z; + r.w = a.w >= b.w ? a.w : b.w; + return r; +} + +// clamp a to [-b, b] +static inline b3FloatW b3SymClampW( b3FloatW a, b3FloatW b ) +{ + b3FloatW r; + r.x = a.x <= b.x ? a.x : b.x; + r.y = a.y <= b.y ? a.y : b.y; + r.z = a.z <= b.z ? a.z : b.z; + r.w = a.w <= b.w ? a.w : b.w; + r.x = r.x <= -b.x ? -b.x : r.x; + r.y = r.y <= -b.y ? -b.y : r.y; + r.z = r.z <= -b.z ? -b.z : r.z; + r.w = r.w <= -b.w ? -b.w : r.w; + return r; +} + +static inline b3FloatW b3OrW( b3FloatW a, b3FloatW b ) +{ + b3FloatW r; + r.x = a.x != 0.0f || b.x != 0.0f ? 1.0f : 0.0f; + r.y = a.y != 0.0f || b.y != 0.0f ? 1.0f : 0.0f; + r.z = a.z != 0.0f || b.z != 0.0f ? 1.0f : 0.0f; + r.w = a.w != 0.0f || b.w != 0.0f ? 1.0f : 0.0f; + return r; +} + +static inline b3FloatW b3GreaterThanW( b3FloatW a, b3FloatW b ) +{ + b3FloatW r; + r.x = a.x > b.x ? 1.0f : 0.0f; + r.y = a.y > b.y ? 1.0f : 0.0f; + r.z = a.z > b.z ? 1.0f : 0.0f; + r.w = a.w > b.w ? 1.0f : 0.0f; + return r; +} + +static inline b3FloatW b3EqualsW( b3FloatW a, b3FloatW b ) +{ + b3FloatW r; + r.x = a.x == b.x ? 1.0f : 0.0f; + r.y = a.y == b.y ? 1.0f : 0.0f; + r.z = a.z == b.z ? 1.0f : 0.0f; + r.w = a.w == b.w ? 1.0f : 0.0f; + return r; +} + +static inline bool b3AllZeroW( b3FloatW a ) +{ + return a.x == 0.0f && a.y == 0.0f && a.z == 0.0f && a.w == 0.0f; +} + +// component-wise returns mask ? b : a +static inline b3FloatW b3BlendW( b3FloatW a, b3FloatW b, b3FloatW mask ) +{ + b3FloatW r; + r.x = mask.x != 0.0f ? b.x : a.x; + r.y = mask.y != 0.0f ? b.y : a.y; + r.z = mask.z != 0.0f ? b.z : a.z; + r.w = mask.w != 0.0f ? b.w : a.w; + return r; +} + +#endif + +// s * a +static inline b3Vec3W b3MulSVW( b3FloatW s, b3Vec3W a ) +{ + return (b3Vec3W){ b3MulW( s, a.X ), b3MulW( s, a.Y ), b3MulW( s, a.Z ) }; +} + +// a - s * b +static inline b3Vec3W b3MulSubSVW( b3Vec3W a, b3FloatW s, b3Vec3W b ) +{ + return (b3Vec3W){ b3SubW( a.X, b3MulW( s, b.X ) ), b3SubW( a.Y, b3MulW( s, b.Y ) ), b3SubW( a.Z, b3MulW( s, b.Z ) ) }; +} + +// a + s * b +static inline b3Vec3W b3MulAddSVW( b3Vec3W a, b3FloatW s, b3Vec3W b ) +{ + return (b3Vec3W){ b3AddW( a.X, b3MulW( s, b.X ) ), b3AddW( a.Y, b3MulW( s, b.Y ) ), b3AddW( a.Z, b3MulW( s, b.Z ) ) }; +} + +// a + b +static inline b3Vec2W b3AddV2W( b3Vec2W a, b3Vec2W b ) +{ + return (b3Vec2W){ + b3AddW( a.x, b.x ), + b3AddW( a.y, b.y ), + }; +} + +// a - b +static inline b3Vec3W b3SubVW( b3Vec3W a, b3Vec3W b ) +{ + return (b3Vec3W){ + b3SubW( a.X, b.X ), + b3SubW( a.Y, b.Y ), + b3SubW( a.Z, b.Z ), + }; +} + +// a + b +static inline b3Vec3W b3AddVW( b3Vec3W a, b3Vec3W b ) +{ + return (b3Vec3W){ + b3AddW( a.X, b.X ), + b3AddW( a.Y, b.Y ), + b3AddW( a.Z, b.Z ), + }; +} + +// m * a +static inline b3Vec2W b3MulMV2W( b3SymMatrix2W m, b3Vec2W a ) +{ + b3Vec2W b = { + b3AddW( b3MulW( m.cxx, a.x ), b3MulW( m.cxy, a.y ) ), + b3AddW( b3MulW( m.cxy, a.x ), b3MulW( m.cyy, a.y ) ), + }; + + return b; +} + +// m * a +static inline b3Vec3W b3MulMVW( b3SymMatrix3W m, b3Vec3W a ) +{ + b3Vec3W b = { + b3AddW( b3MulW( m.cxx, a.X ), b3AddW( b3MulW( m.cxy, a.Y ), b3MulW( m.cxz, a.Z ) ) ), + b3AddW( b3MulW( m.cxy, a.X ), b3AddW( b3MulW( m.cyy, a.Y ), b3MulW( m.cyz, a.Z ) ) ), + b3AddW( b3MulW( m.cxz, a.X ), b3AddW( b3MulW( m.cyz, a.Y ), b3MulW( m.czz, a.Z ) ) ), + }; + + return b; +} + +// a - m * b +static inline b3Vec3W b3MulSubMVW( b3Vec3W a, b3SymMatrix3W m, b3Vec3W b ) +{ + b3Vec3W c = { + b3AddW( b3MulW( m.cxx, b.X ), b3AddW( b3MulW( m.cxy, b.Y ), b3MulW( m.cxz, b.Z ) ) ), + b3AddW( b3MulW( m.cxy, b.X ), b3AddW( b3MulW( m.cyy, b.Y ), b3MulW( m.cyz, b.Z ) ) ), + b3AddW( b3MulW( m.cxz, b.X ), b3AddW( b3MulW( m.cyz, b.Y ), b3MulW( m.czz, b.Z ) ) ), + }; + + return (b3Vec3W){ b3SubW( a.X, c.X ), b3SubW( a.Y, c.Y ), b3SubW( a.Z, c.Z ) }; +} + +// a + m * b +static inline b3Vec3W b3MulAddMVW( b3Vec3W a, b3SymMatrix3W m, b3Vec3W b ) +{ + b3Vec3W c = { + b3AddW( b3MulW( m.cxx, b.X ), b3AddW( b3MulW( m.cxy, b.Y ), b3MulW( m.cxz, b.Z ) ) ), + b3AddW( b3MulW( m.cxy, b.X ), b3AddW( b3MulW( m.cyy, b.Y ), b3MulW( m.cyz, b.Z ) ) ), + b3AddW( b3MulW( m.cxz, b.X ), b3AddW( b3MulW( m.cyz, b.Y ), b3MulW( m.czz, b.Z ) ) ), + }; + + return (b3Vec3W){ b3AddW( a.X, c.X ), b3AddW( a.Y, c.Y ), b3AddW( a.Z, c.Z ) }; +} + +static inline b3FloatW b3DotW( b3Vec3W a, b3Vec3W b ) +{ + return b3AddW( b3AddW( b3MulW( a.X, b.X ), b3MulW( a.Y, b.Y ) ), b3MulW( a.Z, b.Z ) ); +} + +static inline b3Vec3W b3CrossW( b3Vec3W a, b3Vec3W b ) +{ + b3Vec3W c; + c.X = b3SubW( b3MulW( a.Y, b.Z ), b3MulW( a.Z, b.Y ) ); + c.Y = b3SubW( b3MulW( a.Z, b.X ), b3MulW( a.X, b.Z ) ); + c.Z = b3SubW( b3MulW( a.X, b.Y ), b3MulW( a.Y, b.X ) ); + return c; +} + +static inline b3Vec3W b3RotateVectorW( b3QuatW q, b3Vec3W a ) +{ + b3Vec3W t1 = b3CrossW( q.V, a ); + b3Vec3W t2; + t2.X = b3MulAddW( t1.X, q.S, a.X ); + t2.Y = b3MulAddW( t1.Y, q.S, a.Y ); + t2.Z = b3MulAddW( t1.Z, q.S, a.Z ); + b3Vec3W t3 = b3CrossW( q.V, t2 ); + b3FloatW two = b3SplatW( 2.0f ); + b3Vec3W b; + b.X = b3MulAddW( a.X, two, t3.X ); + b.Y = b3MulAddW( a.Y, two, t3.Y ); + b.Z = b3MulAddW( a.Z, two, t3.Z ); + return b; +} + +// Soft contact constraints with sub-stepping support +// Uses fixed anchors for Jacobians for better behavior on rolling shapes (circles & capsules) +// http://mmacklin.com/smallsteps.pdf +// https://box2d.org/files/ErinCatto_SoftConstraints_GDC2011.pdf + +typedef struct b3ContactConstraintPointWide +{ + b3Vec3W anchorAs, anchorBs; + b3FloatW baseSeparations; + b3FloatW normalImpulses; + b3FloatW totalNormalImpulses; + b3FloatW stepNormalImpulses; + b3FloatW normalMasses; + b3FloatW leverArms; + b3FloatW relativeVelocities; +} b3ContactConstraintPointWide; + +// Solves four points +typedef struct b3ContactConstraintWide +{ + // These are base 1 + int indexA[B3_SIMD_WIDTH]; + int indexB[B3_SIMD_WIDTH]; + + b3FloatW invMassA, invMassB; + b3SymMatrix3W invIA, invIB; + b3Vec3W normal; + + // todo test computing the tangents on the fly, at least tangent2 + b3Vec3W tangent1; + b3Vec3W tangent2; + + b3Vec3W originA, originB; + b3FloatW twistMass; + b3FloatW twistImpulse; + b3SymMatrix2W tangentMass; + b3Vec2W frictionImpulse; + b3SymMatrix3W rollingMass; + b3Vec3W rollingImpulse; + b3FloatW friction; + b3FloatW rollingResistance; + b3FloatW tangentVelocity1; + b3FloatW tangentVelocity2; + + b3FloatW biasRate; + b3FloatW massScale; + b3FloatW impulseScale; + b3FloatW restitution; + + b3Manifold* manifolds[B3_SIMD_WIDTH]; + + // todo store the maximum point count per wide constraint + // to make this work I need zero initialization which is too + // expensive for all the wide constraint data. Instead + // the graph color should store the point count as a compact secondary + // transient array with zero initialization. + b3ContactConstraintPointWide points[B3_MAX_MANIFOLD_POINTS]; + +} b3ContactConstraintWide; + +int b3GetWideContactConstraintByteCount( void ) +{ + return sizeof( b3ContactConstraintWide ); +} + +// wide version of b3BodyState +typedef struct b3BodyStateW +{ + b3Vec3W v; + b3Vec3W w; + b3Vec3W dp; + b3QuatW dq; +} b3BodyStateW; + +#if defined( B3_SIMD_SSE2 ) || defined( B3_SIMD_NEON ) + +static b3BodyStateW b3GatherBodies( const b3BodyState* states, int* indices ) +{ + b3BodyState dummy = { 0 }; + dummy.deltaRotation.s = 1.0f; + + // Indices are 0 for null + b3BodyState b1 = indices[0] == 0 ? dummy : states[indices[0] - 1]; + b3BodyState b2 = indices[1] == 0 ? dummy : states[indices[1] - 1]; + b3BodyState b3 = indices[2] == 0 ? dummy : states[indices[2] - 1]; + b3BodyState b4 = indices[3] == 0 ? dummy : states[indices[3] - 1]; + + b3BodyStateW s; + s.v.X = b3SetW( b1.linearVelocity.x, b2.linearVelocity.x, b3.linearVelocity.x, b4.linearVelocity.x ); + s.v.Y = b3SetW( b1.linearVelocity.y, b2.linearVelocity.y, b3.linearVelocity.y, b4.linearVelocity.y ); + s.v.Z = b3SetW( b1.linearVelocity.z, b2.linearVelocity.z, b3.linearVelocity.z, b4.linearVelocity.z ); + + s.w.X = b3SetW( b1.angularVelocity.x, b2.angularVelocity.x, b3.angularVelocity.x, b4.angularVelocity.x ); + s.w.Y = b3SetW( b1.angularVelocity.y, b2.angularVelocity.y, b3.angularVelocity.y, b4.angularVelocity.y ); + s.w.Z = b3SetW( b1.angularVelocity.z, b2.angularVelocity.z, b3.angularVelocity.z, b4.angularVelocity.z ); + + s.dp.X = b3SetW( b1.deltaPosition.x, b2.deltaPosition.x, b3.deltaPosition.x, b4.deltaPosition.x ); + s.dp.Y = b3SetW( b1.deltaPosition.y, b2.deltaPosition.y, b3.deltaPosition.y, b4.deltaPosition.y ); + s.dp.Z = b3SetW( b1.deltaPosition.z, b2.deltaPosition.z, b3.deltaPosition.z, b4.deltaPosition.z ); + + s.dq.V.X = b3SetW( b1.deltaRotation.v.x, b2.deltaRotation.v.x, b3.deltaRotation.v.x, b4.deltaRotation.v.x ); + s.dq.V.Y = b3SetW( b1.deltaRotation.v.y, b2.deltaRotation.v.y, b3.deltaRotation.v.y, b4.deltaRotation.v.y ); + s.dq.V.Z = b3SetW( b1.deltaRotation.v.z, b2.deltaRotation.v.z, b3.deltaRotation.v.z, b4.deltaRotation.v.z ); + s.dq.S = b3SetW( b1.deltaRotation.s, b2.deltaRotation.s, b3.deltaRotation.s, b4.deltaRotation.s ); + return s; +} + +// This writes only the velocities back to the solver bodies +static void b3ScatterBodies( b3BodyState* states, int* indices, const b3BodyStateW* simdBody ) +{ + const float* vx = (const float*)&simdBody->v.X; + const float* vy = (const float*)&simdBody->v.Y; + const float* vz = (const float*)&simdBody->v.Z; + const float* wx = (const float*)&simdBody->w.X; + const float* wy = (const float*)&simdBody->w.Y; + const float* wz = (const float*)&simdBody->w.Z; + + // I don't use any dummy body in the body array because this will lead to multithreaded sharing and the + // associated cache flushing. + + // Warning: indices start at 1 with 0 indicating null + + if ( indices[0] != 0 && ( states[indices[0] - 1].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* s = states + ( indices[0] - 1 ); + + b3Vec3 v = { vx[0], vy[0], vz[0] }; + b3Vec3 w = { wx[0], wy[0], wz[0] }; + + uint32_t flags = s->flags; + if ( flags & b3_allLocks ) + { + v.x = ( flags & b3_lockLinearX ) ? 0.0f : v.x; + v.y = ( flags & b3_lockLinearY ) ? 0.0f : v.y; + v.z = ( flags & b3_lockLinearZ ) ? 0.0f : v.z; + w.x = ( flags & b3_lockAngularX ) ? 0.0f : w.x; + w.y = ( flags & b3_lockAngularY ) ? 0.0f : w.y; + w.z = ( flags & b3_lockAngularZ ) ? 0.0f : w.z; + } + + s->linearVelocity = v; + s->angularVelocity = w; + } + + if ( indices[1] != 0 && ( states[indices[1] - 1].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* s = states + ( indices[1] - 1 ); + + b3Vec3 v = { vx[1], vy[1], vz[1] }; + b3Vec3 w = { wx[1], wy[1], wz[1] }; + + uint32_t flags = s->flags; + if ( flags & b3_allLocks ) + { + v.x = ( flags & b3_lockLinearX ) ? 0.0f : v.x; + v.y = ( flags & b3_lockLinearY ) ? 0.0f : v.y; + v.z = ( flags & b3_lockLinearZ ) ? 0.0f : v.z; + w.x = ( flags & b3_lockAngularX ) ? 0.0f : w.x; + w.y = ( flags & b3_lockAngularY ) ? 0.0f : w.y; + w.z = ( flags & b3_lockAngularZ ) ? 0.0f : w.z; + } + + s->linearVelocity = v; + s->angularVelocity = w; + } + + if ( indices[2] != 0 && ( states[indices[2] - 1].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* s = states + ( indices[2] - 1 ); + + b3Vec3 v = { vx[2], vy[2], vz[2] }; + b3Vec3 w = { wx[2], wy[2], wz[2] }; + + uint32_t flags = s->flags; + if ( flags & b3_allLocks ) + { + v.x = ( flags & b3_lockLinearX ) ? 0.0f : v.x; + v.y = ( flags & b3_lockLinearY ) ? 0.0f : v.y; + v.z = ( flags & b3_lockLinearZ ) ? 0.0f : v.z; + w.x = ( flags & b3_lockAngularX ) ? 0.0f : w.x; + w.y = ( flags & b3_lockAngularY ) ? 0.0f : w.y; + w.z = ( flags & b3_lockAngularZ ) ? 0.0f : w.z; + } + + s->linearVelocity = v; + s->angularVelocity = w; + } + + if ( indices[3] != 0 && ( states[indices[3] - 1].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* s = states + ( indices[3] - 1 ); + + b3Vec3 v = { vx[3], vy[3], vz[3] }; + b3Vec3 w = { wx[3], wy[3], wz[3] }; + + uint32_t flags = s->flags; + if ( flags & b3_allLocks ) + { + v.x = ( flags & b3_lockLinearX ) ? 0.0f : v.x; + v.y = ( flags & b3_lockLinearY ) ? 0.0f : v.y; + v.z = ( flags & b3_lockLinearZ ) ? 0.0f : v.z; + w.x = ( flags & b3_lockAngularX ) ? 0.0f : w.x; + w.y = ( flags & b3_lockAngularY ) ? 0.0f : w.y; + w.z = ( flags & b3_lockAngularZ ) ? 0.0f : w.z; + } + + s->linearVelocity = v; + s->angularVelocity = w; + } +} + +#else // non-simd + +static b3BodyStateW b3GatherBodies( const b3BodyState* states, int* indices ) +{ + b3BodyState identity = b3_identityBodyState; + + b3BodyState s1 = indices[0] == 0 ? identity : states[indices[0] - 1]; + b3BodyState s2 = indices[1] == 0 ? identity : states[indices[1] - 1]; + b3BodyState s3 = indices[2] == 0 ? identity : states[indices[2] - 1]; + b3BodyState s4 = indices[3] == 0 ? identity : states[indices[3] - 1]; + + b3BodyStateW simdBody; + simdBody.v.X = (b3FloatW){ s1.linearVelocity.x, s2.linearVelocity.x, s3.linearVelocity.x, s4.linearVelocity.x }; + simdBody.v.Y = (b3FloatW){ s1.linearVelocity.y, s2.linearVelocity.y, s3.linearVelocity.y, s4.linearVelocity.y }; + simdBody.v.Z = (b3FloatW){ s1.linearVelocity.z, s2.linearVelocity.z, s3.linearVelocity.z, s4.linearVelocity.z }; + simdBody.w.X = (b3FloatW){ s1.angularVelocity.x, s2.angularVelocity.x, s3.angularVelocity.x, s4.angularVelocity.x }; + simdBody.w.Y = (b3FloatW){ s1.angularVelocity.y, s2.angularVelocity.y, s3.angularVelocity.y, s4.angularVelocity.y }; + simdBody.w.Z = (b3FloatW){ s1.angularVelocity.z, s2.angularVelocity.z, s3.angularVelocity.z, s4.angularVelocity.z }; + simdBody.dp.X = (b3FloatW){ s1.deltaPosition.x, s2.deltaPosition.x, s3.deltaPosition.x, s4.deltaPosition.x }; + simdBody.dp.Y = (b3FloatW){ s1.deltaPosition.y, s2.deltaPosition.y, s3.deltaPosition.y, s4.deltaPosition.y }; + simdBody.dp.Z = (b3FloatW){ s1.deltaPosition.z, s2.deltaPosition.z, s3.deltaPosition.z, s4.deltaPosition.z }; + simdBody.dq.V.X = (b3FloatW){ s1.deltaRotation.v.x, s2.deltaRotation.v.x, s3.deltaRotation.v.x, s4.deltaRotation.v.x }; + simdBody.dq.V.Y = (b3FloatW){ s1.deltaRotation.v.y, s2.deltaRotation.v.y, s3.deltaRotation.v.y, s4.deltaRotation.v.y }; + simdBody.dq.V.Z = (b3FloatW){ s1.deltaRotation.v.z, s2.deltaRotation.v.z, s3.deltaRotation.v.z, s4.deltaRotation.v.z }; + simdBody.dq.S = (b3FloatW){ s1.deltaRotation.s, s2.deltaRotation.s, s3.deltaRotation.s, s4.deltaRotation.s }; + + return simdBody; +} + +// This writes only the velocities back to the solver bodies +static void b3ScatterBodies( b3BodyState* states, int* indices, const b3BodyStateW* simdBody ) +{ + int index1 = indices[0] - 1; + if ( index1 != -1 && ( states[index1].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* state = states + index1; + state->linearVelocity.x = simdBody->v.X.x; + state->linearVelocity.y = simdBody->v.Y.x; + state->linearVelocity.z = simdBody->v.Z.x; + state->angularVelocity.x = simdBody->w.X.x; + state->angularVelocity.y = simdBody->w.Y.x; + state->angularVelocity.z = simdBody->w.Z.x; + } + + int index2 = indices[1] - 1; + if ( index2 != -1 && ( states[index2].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* state = states + index2; + state->linearVelocity.x = simdBody->v.X.y; + state->linearVelocity.y = simdBody->v.Y.y; + state->linearVelocity.z = simdBody->v.Z.y; + state->angularVelocity.x = simdBody->w.X.y; + state->angularVelocity.y = simdBody->w.Y.y; + state->angularVelocity.z = simdBody->w.Z.y; + } + + int index3 = indices[2] - 1; + if ( index3 != -1 && ( states[index3].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* state = states + index3; + state->linearVelocity.x = simdBody->v.X.z; + state->linearVelocity.y = simdBody->v.Y.z; + state->linearVelocity.z = simdBody->v.Z.z; + state->angularVelocity.x = simdBody->w.X.z; + state->angularVelocity.y = simdBody->w.Y.z; + state->angularVelocity.z = simdBody->w.Z.z; + } + + int index4 = indices[3] - 1; + if ( index4 != -1 && ( states[index4].flags & b3_dynamicFlag ) != 0 ) + { + b3BodyState* state = states + index4; + state->linearVelocity.x = simdBody->v.X.w; + state->linearVelocity.y = simdBody->v.Y.w; + state->linearVelocity.z = simdBody->v.Z.w; + state->angularVelocity.x = simdBody->w.X.w; + state->angularVelocity.y = simdBody->w.Y.w; + state->angularVelocity.z = simdBody->w.Z.w; + } +} +#endif + +// Prepare convex contact constraints +void b3PrepareContacts_Convex( b3SolverBlock block, b3StepContext* context ) +{ + b3TracyCZoneNC( prepare_contact, "Prepare Contact", b3_colorYellow, true ); + b3World* world = context->world; + b3BodySim* sims = context->sims; + b3BodyState* states = context->states; +#if B3_ENABLE_VALIDATION + b3Body* bodies = world->bodies.data; +#endif + b3WidePrepareSpan* spans = context->widePrepareSpans; + b3ContactConstraintWide* wideBase = context->wideConstraints; + + // Stiffer for static contacts to avoid bodies getting pushed through the ground + b3Softness contactSoftness = context->contactSoftness; + b3Softness staticSoftness = context->staticSoftness; + + float warmStartScale = world->enableWarmStarting ? 1.0f : 0.0f; + + int wideIndex = block.startIndex; + int endWideIndex = block.startIndex + block.count; + + // Find color for start index. Linear search but fast. + int colorIndex = 0; + while ( spans[colorIndex + 1].start <= wideIndex ) + { + colorIndex += 1; + } + + // Loop over block + while ( wideIndex < endWideIndex ) + { + int colorWideStart = spans[colorIndex].start; + int colorWideEndIndex = b3MinInt( spans[colorIndex + 1].start, endWideIndex ); + int colorContactCount = spans[colorIndex].count; + int* contactIds = spans[colorIndex].contacts; + + // Loop over color + for ( ; wideIndex < colorWideEndIndex; ++wideIndex ) + { + b3ContactConstraintWide* constraint = wideBase + wideIndex; + int localWideIndex = wideIndex - colorWideStart; + + for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) + { + int contactIndex = B3_SIMD_WIDTH * localWideIndex + lane; + if ( contactIndex >= colorContactCount ) + { + // Remainder lanes were zeroed in solver setup. + break; + } + + int contactId = contactIds[contactIndex]; + b3Contact* contact = b3Array_Get( world->contacts, contactId ); + B3_ASSERT( contact->manifoldCount == 1 ); + b3Manifold* manifold = contact->manifolds + 0; + + int indexA = contact->bodySimIndexA; + int indexB = contact->bodySimIndexB; + +#if B3_ENABLE_VALIDATION + b3Body* bodyA = bodies + contact->edges[0].bodyId; + int validIndexA = bodyA->setIndex == b3_awakeSet ? bodyA->localIndex : B3_NULL_INDEX; + b3Body* bodyB = bodies + contact->edges[1].bodyId; + int validIndexB = bodyB->setIndex == b3_awakeSet ? bodyB->localIndex : B3_NULL_INDEX; + B3_ASSERT( indexA == validIndexA ); + B3_ASSERT( indexB == validIndexB ); +#endif + + // 0 for null + constraint->indexA[lane] = indexA + 1; + constraint->indexB[lane] = indexB + 1; + constraint->manifolds[lane] = manifold; + + // Body A data + float mA; + b3Matrix3 iA; + b3Vec3 vA; + b3Vec3 wA; + + if ( indexA == B3_NULL_INDEX ) + { + mA = 0.0f; + iA = b3Mat3_zero; + vA = b3Vec3_zero; + wA = b3Vec3_zero; + } + else + { + b3BodySim* simA = sims + indexA; + mA = simA->invMass; + iA = simA->invInertiaWorld; + + b3BodyState* stateA = states + indexA; + vA = stateA->linearVelocity; + wA = stateA->angularVelocity; + } + + // Body B data + float mB; + b3Matrix3 iB; + b3Vec3 vB; + b3Vec3 wB; + + if ( indexB == B3_NULL_INDEX ) + { + mB = 0.0f; + iB = b3Mat3_zero; + vB = b3Vec3_zero; + wB = b3Vec3_zero; + } + else + { + b3BodySim* simB = sims + indexB; + mB = simB->invMass; + iB = simB->invInertiaWorld; + + b3BodyState* stateB = states + indexB; + vB = stateB->linearVelocity; + wB = stateB->angularVelocity; + } + + ( (float*)&constraint->invMassA )[lane] = mA; + ( (float*)&constraint->invMassB )[lane] = mB; + + ( (float*)&constraint->invIA.cxx )[lane] = iA.cx.x; + ( (float*)&constraint->invIA.cxy )[lane] = iA.cx.y; + ( (float*)&constraint->invIA.cxz )[lane] = iA.cx.z; + ( (float*)&constraint->invIA.cyy )[lane] = iA.cy.y; + ( (float*)&constraint->invIA.cyz )[lane] = iA.cy.z; + ( (float*)&constraint->invIA.czz )[lane] = iA.cz.z; + + ( (float*)&constraint->invIB.cxx )[lane] = iB.cx.x; + ( (float*)&constraint->invIB.cxy )[lane] = iB.cx.y; + ( (float*)&constraint->invIB.cxz )[lane] = iB.cx.z; + ( (float*)&constraint->invIB.cyy )[lane] = iB.cy.y; + ( (float*)&constraint->invIB.cyz )[lane] = iB.cy.z; + ( (float*)&constraint->invIB.czz )[lane] = iB.cz.z; + + b3Softness soft = ( indexA == B3_NULL_INDEX || indexB == B3_NULL_INDEX ) ? staticSoftness : contactSoftness; + + b3Vec3 normal = manifold->normal; + ( (float*)&constraint->normal.X )[lane] = normal.x; + ( (float*)&constraint->normal.Y )[lane] = normal.y; + ( (float*)&constraint->normal.Z )[lane] = normal.z; + + b3Vec3 tangent1 = b3Perp( normal ); + ( (float*)&constraint->tangent1.X )[lane] = tangent1.x; + ( (float*)&constraint->tangent1.Y )[lane] = tangent1.y; + ( (float*)&constraint->tangent1.Z )[lane] = tangent1.z; + + b3Vec3 tangent2 = b3Cross( tangent1, normal ); + ( (float*)&constraint->tangent2.X )[lane] = tangent2.x; + ( (float*)&constraint->tangent2.Y )[lane] = tangent2.y; + ( (float*)&constraint->tangent2.Z )[lane] = tangent2.z; + + ( (float*)&constraint->friction )[lane] = contact->friction; + ( (float*)&constraint->restitution )[lane] = contact->restitution; + ( (float*)&constraint->rollingResistance )[lane] = contact->rollingResistance; + + ( (float*)&constraint->tangentVelocity1 )[lane] = b3Dot( contact->tangentVelocity, tangent1 ); + ( (float*)&constraint->tangentVelocity2 )[lane] = b3Dot( contact->tangentVelocity, tangent2 ); + + ( (float*)&constraint->biasRate )[lane] = soft.biasRate; + ( (float*)&constraint->massScale )[lane] = soft.massScale; + ( (float*)&constraint->impulseScale )[lane] = soft.impulseScale; + + int pointCount = manifold->pointCount; + b3Vec3 originA = b3Vec3_zero; + b3Vec3 originB = b3Vec3_zero; + + for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) + { + const b3ManifoldPoint* mp = manifold->points + pointIndex; + b3ContactConstraintPointWide* cp = constraint->points + pointIndex; + + b3Vec3 rA = mp->anchorA; + b3Vec3 rB = mp->anchorB; + originA = b3Add( originA, rA ); + originB = b3Add( originB, rB ); + + ( (float*)&cp->anchorAs.X )[lane] = rA.x; + ( (float*)&cp->anchorAs.Y )[lane] = rA.y; + ( (float*)&cp->anchorAs.Z )[lane] = rA.z; + + ( (float*)&cp->anchorBs.X )[lane] = rB.x; + ( (float*)&cp->anchorBs.Y )[lane] = rB.y; + ( (float*)&cp->anchorBs.Z )[lane] = rB.z; + + float baseSeparation = mp->separation - b3Dot( b3Sub( rB, rA ), normal ); + ( (float*)&cp->baseSeparations )[lane] = baseSeparation; + + ( (float*)&cp->normalImpulses )[lane] = warmStartScale * mp->normalImpulse; + ( (float*)&cp->totalNormalImpulses )[lane] = 0.0f; + ( (float*)&cp->stepNormalImpulses )[lane] = 0.0f; + + b3Vec3 rnA = b3Cross( rA, normal ); + b3Vec3 rnB = b3Cross( rB, normal ); + float kNormal = mA + mB + b3Dot( rnA, b3MulMV( iA, rnA ) ) + b3Dot( rnB, b3MulMV( iB, rnB ) ); + ( (float*)&cp->normalMasses )[lane] = kNormal > 0.0f ? 1.0f / kNormal : 0.0f; + + // Save relative velocity for restitution + b3Vec3 vrA = b3Add( vA, b3Cross( wA, rA ) ); + b3Vec3 vrB = b3Add( vB, b3Cross( wB, rB ) ); + ( (float*)&cp->relativeVelocities )[lane] = b3Dot( normal, b3Sub( vrB, vrA ) ); + } + + float invCount = 1.0f / pointCount; + originA = b3MulSV( invCount, originA ); + originB = b3MulSV( invCount, originB ); + + ( (float*)&constraint->originA.X )[lane] = originA.x; + ( (float*)&constraint->originA.Y )[lane] = originA.y; + ( (float*)&constraint->originA.Z )[lane] = originA.z; + ( (float*)&constraint->originB.X )[lane] = originB.x; + ( (float*)&constraint->originB.Y )[lane] = originB.y; + ( (float*)&constraint->originB.Z )[lane] = originB.z; + + for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) + { + const b3ManifoldPoint* mp = manifold->points + pointIndex; + b3ContactConstraintPointWide* cp = constraint->points + pointIndex; + ( (float*)&cp->leverArms )[lane] = b3Distance( mp->anchorA, originA ); + } + + b3Vec3 rtA1 = b3Cross( originA, tangent1 ); + b3Vec3 rtA2 = b3Cross( originA, tangent2 ); + + b3Vec3 rtB1 = b3Cross( originB, tangent1 ); + b3Vec3 rtB2 = b3Cross( originB, tangent2 ); + + { + b3Matrix2 k; + k.cx.x = mA + mB + b3Dot( rtA1, b3MulMV( iA, rtA1 ) ) + b3Dot( rtB1, b3MulMV( iB, rtB1 ) ); + k.cy.y = mA + mB + b3Dot( rtA2, b3MulMV( iA, rtA2 ) ) + b3Dot( rtB2, b3MulMV( iB, rtB2 ) ); + k.cx.y = k.cy.x = b3Dot( rtA1, b3MulMV( iA, rtA2 ) ) + b3Dot( rtB1, b3MulMV( iB, rtB2 ) ); + b3Matrix2 tangentMass = b3Invert2( k ); + + ( (float*)&constraint->tangentMass.cxx )[lane] = tangentMass.cx.x; + ( (float*)&constraint->tangentMass.cxy )[lane] = tangentMass.cx.y; + ( (float*)&constraint->tangentMass.cyy )[lane] = tangentMass.cy.y; + + ( (float*)&constraint->frictionImpulse.x )[lane] = + warmStartScale * b3Dot( manifold->frictionImpulse, tangent1 ); + ( (float*)&constraint->frictionImpulse.y )[lane] = + warmStartScale * b3Dot( manifold->frictionImpulse, tangent2 ); + } + + { + float k = b3Dot( normal, b3MulMV( b3AddMM( iA, iB ), normal ) ); + ( (float*)&constraint->twistMass )[lane] = k > 0.0f ? 1.0f / k : 0.0f; + ( (float*)&constraint->twistImpulse )[lane] = warmStartScale * manifold->twistImpulse; + } + + { + b3Matrix3 rollingMass = b3InvertMatrix( b3AddMM( iA, iB ) ); + + ( (float*)&constraint->rollingMass.cxx )[lane] = rollingMass.cx.x; + ( (float*)&constraint->rollingMass.cxy )[lane] = rollingMass.cx.y; + ( (float*)&constraint->rollingMass.cxz )[lane] = rollingMass.cx.z; + ( (float*)&constraint->rollingMass.cyy )[lane] = rollingMass.cy.y; + ( (float*)&constraint->rollingMass.cyz )[lane] = rollingMass.cy.z; + ( (float*)&constraint->rollingMass.czz )[lane] = rollingMass.cz.z; + + ( (float*)&constraint->rollingImpulse.X )[lane] = warmStartScale * manifold->rollingImpulse.x; + ( (float*)&constraint->rollingImpulse.Y )[lane] = warmStartScale * manifold->rollingImpulse.y; + ( (float*)&constraint->rollingImpulse.Z )[lane] = warmStartScale * manifold->rollingImpulse.z; + } + + // zero remaining points + for ( int pointIndex = pointCount; pointIndex < B3_MAX_MANIFOLD_POINTS; ++pointIndex ) + { + b3ContactConstraintPointWide* cp = constraint->points + pointIndex; + ( (float*)&cp->anchorAs.X )[lane] = 0.0f; + ( (float*)&cp->anchorAs.Y )[lane] = 0.0f; + ( (float*)&cp->anchorAs.Z )[lane] = 0.0f; + ( (float*)&cp->anchorBs.X )[lane] = 0.0f; + ( (float*)&cp->anchorBs.Y )[lane] = 0.0f; + ( (float*)&cp->anchorBs.Z )[lane] = 0.0f; + ( (float*)&cp->baseSeparations )[lane] = 0.0f; + ( (float*)&cp->normalImpulses )[lane] = 0.0f; + ( (float*)&cp->totalNormalImpulses )[lane] = 0.0f; + ( (float*)&cp->stepNormalImpulses )[lane] = 0.0f; + ( (float*)&cp->normalMasses )[lane] = 0.0f; + ( (float*)&cp->relativeVelocities )[lane] = 0.0f; + ( (float*)&cp->leverArms )[lane] = 0.0f; + } + } + } + + // Advance to next color + colorIndex += 1; + } + + b3TracyCZoneEnd( prepare_contact ); +} + +void b3WarmStartContacts_Convex( b3SolverBlock block, b3StepContext* context ) +{ + b3TracyCZoneNC( warm_start_contact, "Warm Start", b3_colorGreen, true ); + + b3BodyState* states = context->states; + b3ContactConstraintWide* constraints = context->graph->colors[block.colorIndex].wideConstraints; + + for ( int i = block.startIndex; i < block.startIndex + block.count; ++i ) + { + b3ContactConstraintWide* c = constraints + i; + b3BodyStateW bA = b3GatherBodies( states, c->indexA ); + b3BodyStateW bB = b3GatherBodies( states, c->indexB ); + + // Normal impulses + for ( int j = 0; j < B3_MAX_MANIFOLD_POINTS; ++j ) + { + b3ContactConstraintPointWide* cp = c->points + j; + + b3Vec3W rA = cp->anchorAs; + b3Vec3W rB = cp->anchorBs; + + b3Vec3W impulse; + impulse.X = b3MulW( cp->normalImpulses, c->normal.X ); + impulse.Y = b3MulW( cp->normalImpulses, c->normal.Y ); + impulse.Z = b3MulW( cp->normalImpulses, c->normal.Z ); + + bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, impulse ) ); + bA.v = b3MulSubSVW( bA.v, c->invMassA, impulse ); + bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, impulse ) ); + bB.v = b3MulAddSVW( bB.v, c->invMassB, impulse ); + } + + // Central friction + { + b3Vec3W rA = c->originA; + b3Vec3W rB = c->originB; + b3Vec3W impulse = b3MulSVW( c->frictionImpulse.x, c->tangent1 ); + impulse = b3MulAddSVW( impulse, c->frictionImpulse.y, c->tangent2 ); + + bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, impulse ) ); + bA.v = b3MulSubSVW( bA.v, c->invMassA, impulse ); + bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, impulse ) ); + bB.v = b3MulAddSVW( bB.v, c->invMassB, impulse ); + } + + // Central twist friction + { + b3Vec3W impulse = b3MulSVW( c->twistImpulse, c->normal ); + bA.w = b3MulSubMVW( bA.w, c->invIA, impulse ); + bB.w = b3MulAddMVW( bB.w, c->invIB, impulse ); + } + + // Rolling resistance + { + b3Vec3W impulse = c->rollingImpulse; + bA.w = b3MulSubMVW( bA.w, c->invIA, impulse ); + bB.w = b3MulAddMVW( bB.w, c->invIB, impulse ); + } + + b3ScatterBodies( states, c->indexA, &bA ); + b3ScatterBodies( states, c->indexB, &bB ); + } + + b3TracyCZoneEnd( warm_start_contact ); +} + +void b3SolveContacts_Convex( b3SolverBlock block, b3StepContext* context, bool useBias ) +{ + b3TracyCZoneNC( solve_contact, "Solve Contact", b3_colorAliceBlue, true ); + + b3BodyState* states = context->states; + b3ContactConstraintWide* constraints = context->graph->colors[block.colorIndex].wideConstraints; + b3FloatW inv_h = b3SplatW( context->inv_h ); + b3FloatW contactSpeed = b3SplatW( -context->world->contactSpeed ); + b3FloatW oneW = b3SplatW( 1.0f ); + b3FloatW epsilonW = b3SplatW( FLT_EPSILON ); + + for ( int wideIndex = block.startIndex; wideIndex < block.startIndex + block.count; ++wideIndex ) + { + b3ContactConstraintWide* c = constraints + wideIndex; + + b3BodyStateW bA = b3GatherBodies( states, c->indexA ); + b3BodyStateW bB = b3GatherBodies( states, c->indexB ); + + b3FloatW biasRate, massScale, impulseScale; + if ( useBias ) + { + biasRate = b3MulW( c->massScale, c->biasRate ); + massScale = c->massScale; + impulseScale = c->impulseScale; + } + else + { + biasRate = b3ZeroW(); + massScale = oneW; + impulseScale = b3ZeroW(); + } + + b3Vec3W dp = b3SubVW( bB.dp, bA.dp ); + + b3FloatW totalNormalImpulse = b3ZeroW(); + b3FloatW totalTwistLimit = b3ZeroW(); + + // todo_erin use the max point count of the four manifolds + for ( int pointIndex = 0; pointIndex < B3_MAX_MANIFOLD_POINTS; ++pointIndex ) + { + b3ContactConstraintPointWide* cp = c->points + pointIndex; + + // Fixed anchor points for applying impulses + b3Vec3W rA = cp->anchorAs; + b3Vec3W rB = cp->anchorBs; + + // Moving anchors for current separation + // todo speed this up using matrices + b3Vec3W rsA = b3RotateVectorW( bA.dq, rA ); + b3Vec3W rsB = b3RotateVectorW( bB.dq, rB ); + + // compute current separation + // this is subject to round-off error if the anchor is far from the body center of mass + b3Vec3W ds = b3AddVW( dp, b3SubVW( rsB, rsA ) ); + b3FloatW s = b3AddW( b3DotW( c->normal, ds ), cp->baseSeparations ); + + // Apply speculative bias if separation is greater than zero, otherwise apply soft constraint bias + b3FloatW mask = b3GreaterThanW( s, b3ZeroW() ); + b3FloatW specBias = b3MulW( s, inv_h ); + b3FloatW softBias = b3MaxW( b3MulW( biasRate, s ), contactSpeed ); + b3FloatW bias = b3BlendW( softBias, specBias, mask ); + + b3FloatW pointMassScale = b3BlendW( massScale, oneW, mask ); + b3FloatW pointImpulseScale = b3BlendW( impulseScale, b3ZeroW(), mask ); + + // Relative velocity at contact + b3Vec3W vrA = b3AddVW( bA.v, b3CrossW( bA.w, rA ) ); + b3Vec3W vrB = b3AddVW( bB.v, b3CrossW( bB.w, rB ) ); + b3FloatW vn = b3DotW( b3SubVW( vrB, vrA ), c->normal ); + + // Compute normal impulse + b3FloatW negImpulse = b3AddW( b3MulW( cp->normalMasses, b3AddW( b3MulW( pointMassScale, vn ), bias ) ), + b3MulW( pointImpulseScale, cp->normalImpulses ) ); + + // Clamp the accumulated impulse + b3FloatW newImpulse = b3MaxW( b3SubW( cp->normalImpulses, negImpulse ), b3ZeroW() ); + b3FloatW deltaImpulse = b3SubW( newImpulse, cp->normalImpulses ); + cp->normalImpulses = newImpulse; + cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, newImpulse ); + if ( useBias == false ) cp->stepNormalImpulses = b3AddW( cp->stepNormalImpulses, newImpulse ); + + totalNormalImpulse = b3AddW( totalNormalImpulse, newImpulse ); + totalTwistLimit = b3AddW( totalTwistLimit, b3MulW( cp->leverArms, newImpulse ) ); + + // Apply contact impulse + b3Vec3W P = b3MulSVW( deltaImpulse, c->normal ); + bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, P ) ); + bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); + bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, P ) ); + bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); + } + + // No friction when applying bias + if ( useBias == false ) + { + // Rolling resistance + if ( b3AllZeroW( c->rollingResistance ) == false ) + { + // flip A/B order to negate + b3Vec3W deltaImpulse = b3MulMVW( c->rollingMass, b3SubVW( bA.w, bB.w ) ); + b3Vec3W oldImpulse = c->rollingImpulse; + c->rollingImpulse = b3AddVW( oldImpulse, deltaImpulse ); + + b3FloatW maxImpulse = b3MulW( c->rollingResistance, totalNormalImpulse ); + b3FloatW lengthSquared = b3DotW( c->rollingImpulse, c->rollingImpulse ); + + // if ( magSqr > maxLambda * maxLambda + FLT_EPSILON ) + //{ + // c->rollingImpulse *= maxLambda / sqrtf( magSqr ); + // } + + b3FloatW mask = b3GreaterThanW( lengthSquared, b3MulAddW( epsilonW, maxImpulse, maxImpulse ) ); + + // No approximate _mm_rsqrt_ps here to maintain cross-platform determinism + b3FloatW normalize = b3DivW( maxImpulse, b3AddW( b3SqrtW( lengthSquared ), epsilonW ) ); + b3FloatW scale = b3BlendW( oneW, normalize, mask ); + + // Ensure zero rolling resistance yields no impulse + b3FloatW rollingMask = b3GreaterThanW( c->rollingResistance, b3ZeroW() ); + scale = b3BlendW( b3ZeroW(), scale, rollingMask ); + + c->rollingImpulse = b3MulSVW( scale, c->rollingImpulse ); + + deltaImpulse = b3SubVW( c->rollingImpulse, oldImpulse ); + + bA.w = b3MulSubMVW( bA.w, c->invIA, deltaImpulse ); + bB.w = b3MulAddMVW( bB.w, c->invIB, deltaImpulse ); + } + + // Central twist friction + { + b3FloatW twistSpeed = b3DotW( c->normal, b3SubVW( bB.w, bA.w ) ); + b3FloatW maxLambda = b3MulW( c->friction, totalTwistLimit ); + b3FloatW deltaImpulse = b3NegW( b3MulW( c->twistMass, twistSpeed ) ); + b3FloatW oldImpulse = c->twistImpulse; + c->twistImpulse = b3SymClampW( b3AddW( oldImpulse, deltaImpulse ), maxLambda ); + deltaImpulse = b3SubW( c->twistImpulse, oldImpulse ); + + b3Vec3W L = b3MulSVW( deltaImpulse, c->normal ); + bA.w = b3MulSubMVW( bA.w, c->invIA, L ); + bB.w = b3MulAddMVW( bB.w, c->invIB, L ); + } + + // Central friction + { + b3Vec3W tangent1 = c->tangent1; + b3Vec3W tangent2 = c->tangent2; + + // Fixed anchor points for applying impulses + b3Vec3W rA = c->originA; + b3Vec3W rB = c->originB; + + // Relative tangent velocity at contact + b3Vec3W vrA = b3AddVW( bA.v, b3CrossW( bA.w, rA ) ); + b3Vec3W vrB = b3AddVW( bB.v, b3CrossW( bB.w, rB ) ); + b3Vec3W vr = b3SubVW( vrB, vrA ); + b3Vec2W vt = { + b3SubW( b3DotW( vr, tangent1 ), c->tangentVelocity1 ), + b3SubW( b3DotW( vr, tangent2 ), c->tangentVelocity2 ), + }; + + // Incremental tangent impulse + b3Vec2W deltaImpulse = b3MulMV2W( c->tangentMass, vt ); + deltaImpulse = (b3Vec2W){ b3NegW( deltaImpulse.x ), b3NegW( deltaImpulse.y ) }; + b3Vec2W newImpulse = b3AddV2W( c->frictionImpulse, deltaImpulse ); + + b3FloatW friction = c->friction; + b3FloatW maxImpulse = b3MulW( friction, totalNormalImpulse ); + + // Clamp the accumulated impulse + b3FloatW lengthSquared = b3AddW( b3MulW( newImpulse.x, newImpulse.x ), b3MulW( newImpulse.y, newImpulse.y ) ); + + // Max impulse can be zero + b3FloatW mask = b3GreaterThanW( lengthSquared, b3MulW( maxImpulse, maxImpulse ) ); + + // No approximate _mm_rsqrt_ps here to maintain cross-platform determinism. Add epsilon to avoid divide by + // zero. + b3FloatW normalize = b3DivW( maxImpulse, b3AddW( b3SqrtW( lengthSquared ), epsilonW ) ); + b3FloatW scale = b3BlendW( oneW, normalize, mask ); + newImpulse = (b3Vec2W){ + b3MulW( scale, newImpulse.x ), + b3MulW( scale, newImpulse.y ), + }; + + deltaImpulse = (b3Vec2W){ + b3SubW( newImpulse.x, c->frictionImpulse.x ), + b3SubW( newImpulse.y, c->frictionImpulse.y ), + }; + + c->frictionImpulse = newImpulse; + + // Apply delta impulse + b3Vec3W P = b3AddVW( b3MulSVW( deltaImpulse.x, tangent1 ), b3MulSVW( deltaImpulse.y, tangent2 ) ); + bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, P ) ); + bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); + bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, P ) ); + bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); + } + } + + b3ScatterBodies( states, c->indexA, &bA ); + b3ScatterBodies( states, c->indexB, &bB ); + } + + b3TracyCZoneEnd( solve_contact ); +} + +void b3ApplyRestitution_Convex( b3SolverBlock block, b3StepContext* context ) +{ + b3TracyCZoneNC( restitution, "Restitution", b3_colorDodgerBlue, true ); + + b3BodyState* states = context->states; + b3ContactConstraintWide* constraints = context->graph->colors[block.colorIndex].wideConstraints; + b3FloatW threshold = b3SplatW( context->world->restitutionThreshold ); + b3FloatW zero = b3ZeroW(); + + for ( int i = block.startIndex; i < block.startIndex + block.count; ++i ) + { + b3ContactConstraintWide* c = constraints + i; + + if ( b3AllZeroW( c->restitution ) ) + { + // No lanes have restitution. Common case. + continue; + } + + // Single gather for all manifolds + b3BodyStateW bA = b3GatherBodies( states, c->indexA ); + b3BodyStateW bB = b3GatherBodies( states, c->indexB ); + + // Create a mask based on restitution so that lanes with no restitution are not affected + // by the calculations below. + b3FloatW restitutionMask = b3EqualsW( c->restitution, zero ); + + for ( int pointIndex = 0; pointIndex < B3_MAX_MANIFOLD_POINTS; ++pointIndex ) + { + b3ContactConstraintPointWide* cp = c->points + pointIndex; + + // Set effective mass to zero if restitution should not be applied + b3FloatW mask1 = b3GreaterThanW( b3AddW( cp->relativeVelocities, threshold ), zero ); + b3FloatW mask2 = b3EqualsW( cp->totalNormalImpulses, zero ); + b3FloatW mask = b3OrW( b3OrW( mask1, mask2 ), restitutionMask ); + b3FloatW mass = b3BlendW( cp->normalMasses, zero, mask ); + + // Fixed anchors for impulses + b3Vec3W rA = cp->anchorAs; + b3Vec3W rB = cp->anchorBs; + + // Relative velocity at contact + b3Vec3W vrA = b3AddVW( bA.v, b3CrossW( bA.w, rA ) ); + b3Vec3W vrB = b3AddVW( bB.v, b3CrossW( bB.w, rB ) ); + b3FloatW vn = b3DotW( b3SubVW( vrB, vrA ), c->normal ); + + // Compute normal impulse + b3FloatW negImpulse = b3MulW( mass, b3AddW( vn, b3MulW( c->restitution, cp->relativeVelocities ) ) ); + + // Clamp the accumulated impulse + b3FloatW newImpulse = b3MaxW( b3SubW( cp->normalImpulses, negImpulse ), b3ZeroW() ); + b3FloatW deltaImpulse = b3SubW( newImpulse, cp->normalImpulses ); + cp->normalImpulses = newImpulse; + cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, deltaImpulse ); + cp->stepNormalImpulses = b3AddW( cp->stepNormalImpulses, deltaImpulse ); + + // Apply contact impulse + b3Vec3W P = b3MulSVW( deltaImpulse, c->normal ); + bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, P ) ); + bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); + bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, P ) ); + bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); + } + + b3ScatterBodies( states, c->indexA, &bA ); + b3ScatterBodies( states, c->indexB, &bB ); + } + + b3TracyCZoneEnd( restitution ); +} + +// Store impulses by contact constraint +void b3StoreImpulses_Convex( b3SolverBlock block, b3StepContext* context, int workerIndex ) +{ + b3TracyCZoneNC( store_impulses, "Store", b3_colorFireBrick, true ); + + b3World* world = context->world; + b3WidePrepareSpan* spans = context->widePrepareSpans; + const b3ContactConstraintWide* wideBase = context->wideConstraints; + b3TaskContext* taskContext = world->taskContexts.data + workerIndex; + b3BitSet* hitEventBitSet = &taskContext->hitEventBitSet; + bool hasHitEvents = taskContext->hasHitEvents; + float negHitThreshold = -world->hitEventThreshold; + + int wideIndex = block.startIndex; + int endWideIndex = block.startIndex + block.count; + + // Find color for start index + int colorIndex = 0; + while ( spans[colorIndex + 1].start <= wideIndex ) + { + colorIndex += 1; + } + + while ( wideIndex < endWideIndex ) + { + int colorWideStart = spans[colorIndex].start; + int colorWideEndIndex = b3MinInt( spans[colorIndex + 1].start, endWideIndex ); + int colorContactCount = spans[colorIndex].count; + int* contactIds = spans[colorIndex].contacts; + + for ( ; wideIndex < colorWideEndIndex; ++wideIndex ) + { + const b3ContactConstraintWide* c = wideBase + wideIndex; + const float* frictionImpulse1 = (float*)&c->frictionImpulse.x; + const float* frictionImpulse2 = (float*)&c->frictionImpulse.y; + const float* tangent1X = (float*)&c->tangent1.X; + const float* tangent1Y = (float*)&c->tangent1.Y; + const float* tangent1Z = (float*)&c->tangent1.Z; + const float* tangent2X = (float*)&c->tangent2.X; + const float* tangent2Y = (float*)&c->tangent2.Y; + const float* tangent2Z = (float*)&c->tangent2.Z; + const float* twistImpulse = (float*)&c->twistImpulse; + const float* rollingImpulseX = (float*)&c->rollingImpulse.X; + const float* rollingImpulseY = (float*)&c->rollingImpulse.Y; + const float* rollingImpulseZ = (float*)&c->rollingImpulse.Z; + + int localWideIndex = wideIndex - colorWideStart; + + for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) + { + int contactIndex = B3_SIMD_WIDTH * localWideIndex + lane; + if ( contactIndex >= colorContactCount ) + { + break; + } + + b3Manifold* m = c->manifolds[lane]; + if ( m == NULL ) + { + continue; + } + + float f1 = frictionImpulse1[lane]; + float f2 = frictionImpulse2[lane]; + m->frictionImpulse = (b3Vec3){ + f1 * tangent1X[lane] + f2 * tangent2X[lane], + f1 * tangent1Y[lane] + f2 * tangent2Y[lane], + f1 * tangent1Z[lane] + f2 * tangent2Z[lane], + }; + m->twistImpulse = twistImpulse[lane]; + m->rollingImpulse = (b3Vec3){ + rollingImpulseX[lane], + rollingImpulseY[lane], + rollingImpulseZ[lane], + }; + + int pointCount = m->pointCount; + for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) + { + const b3ContactConstraintPointWide* cp = c->points + pointIndex; + const float* normalImpulse = (float*)&cp->normalImpulses; + const float* totalNormalImpulse = (float*)&cp->totalNormalImpulses; + const float* normalVelocity = (float*)&cp->relativeVelocities; + + b3ManifoldPoint* mp = m->points + pointIndex; + mp->normalImpulse = normalImpulse[lane]; + mp->totalNormalImpulse = totalNormalImpulse[lane]; + mp->stepNormalImpulse = ((const float*)&cp->stepNormalImpulses)[lane]; + mp->normalVelocity = normalVelocity[lane]; + } + + int contactId = contactIds[contactIndex]; + b3Contact* contact = b3Array_Get( world->contacts, contactId ); + if ( ( contact->flags & b3_simEnableHitEvent ) != 0 ) + { + for ( int k = 0; k < pointCount; ++k ) + { + b3ManifoldPoint* mp = m->points + k; + + // Need to check total impulse because the point may be speculative and not colliding + if ( mp->normalVelocity < negHitThreshold && mp->totalNormalImpulse > 0.0f ) + { + b3SetBit( hitEventBitSet, contact->contactId ); + hasHitEvents = true; + break; + } + } + } + } + } + + colorIndex += 1; + } + + taskContext->hasHitEvents = hasHitEvents; + + b3TracyCZoneEnd( store_impulses ); +} + void b3PrepareContacts_Overflow( b3StepContext* context ) { b3ConstraintGraph* graph = context->graph; b3GraphColor* color = graph->colors + B3_OVERFLOW_INDEX; - B3_ASSERT( color->contacts.count <= UINT16_MAX ); uint16_t count = (uint16_t)color->contacts.count; - if ( count == 0 ) + if (count == 0) { return; } @@ -949,7 +2418,7 @@ void b3WarmStartContacts_Overflow( b3StepContext* context ) b3WarmStartContacts_Mesh( block, context ); } -void b3PushContacts_Overflow( b3StepContext* context ) +void b3SolveContacts_Overflow( b3StepContext* context, bool useBias ) { b3ConstraintGraph* graph = context->graph; b3GraphColor* color = graph->colors + B3_OVERFLOW_INDEX; @@ -967,28 +2436,7 @@ void b3PushContacts_Overflow( b3StepContext* context ) .colorIndex = B3_OVERFLOW_INDEX, }; - b3PushContacts_Mesh( block, context ); -} - -void b3SolveContacts_Overflow( b3StepContext* context ) -{ - b3ConstraintGraph* graph = context->graph; - b3GraphColor* color = graph->colors + B3_OVERFLOW_INDEX; - - uint16_t count = (uint16_t)color->contacts.count; - if ( count == 0 ) - { - return; - } - - b3SolverBlock block = { - .startIndex = 0, - .count = count, - .blockType = b3_overflowBlock, - .colorIndex = B3_OVERFLOW_INDEX, - }; - - b3SolveContacts_Mesh( block, context ); + b3SolveContacts_Mesh( block, context, useBias ); } void b3ApplyRestitution_Overflow( b3StepContext* context ) @@ -1032,201 +2480,3 @@ void b3StoreImpulses_Overflow( b3StepContext* context ) b3StoreImpulses_Mesh( block, context, 0 ); } - -void b3PrepareContacts_Convex( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3PrepareContacts_ConvexW8( block, context ); - return; - } -#endif - - b3PrepareContacts_ConvexW4( block, context ); -} - -void b3WarmStartContacts_Convex( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3WarmStartContacts_ConvexW8( block, context ); - return; - } -#endif - - b3WarmStartContacts_ConvexW4( block, context ); -} - -void b3PushContacts_Convex( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3PushContacts_ConvexW8( block, context ); - return; - } -#endif - - b3PushContacts_ConvexW4( block, context ); -} - -void b3SolveContacts_Convex( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3SolveContacts_ConvexW8( block, context ); - return; - } -#endif - - b3SolveContacts_ConvexW4( block, context ); -} - -void b3ApplyRestitution_Convex( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3ApplyRestitution_ConvexW8( block, context ); - return; - } -#endif - - b3ApplyRestitution_ConvexW4( block, context ); -} - -void b3StoreImpulses_Convex( b3SolverBlock block, b3StepContext* context, int workerIndex ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3StoreImpulses_ConvexW8( block, context, workerIndex ); - return; - } -#endif - - b3StoreImpulses_ConvexW4( block, context, workerIndex ); -} - -int b3GetWideContactConstraintByteCount( int simdWidth ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( simdWidth == 8 ) - { - return b3GetWideContactConstraintByteCountW8(); - } -#else - B3_UNUSED( simdWidth ); -#endif - - return b3GetWideContactConstraintByteCountW4(); -} - -void b3PrepareContacts_MeshWide( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3PrepareContacts_MeshWideW8( block, context ); - return; - } -#endif - - b3PrepareContacts_MeshWideW4( block, context ); -} - -void b3WarmStartContacts_MeshWide( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3WarmStartContacts_MeshWideW8( block, context ); - return; - } -#endif - - b3WarmStartContacts_MeshWideW4( block, context ); -} - -void b3PushContacts_MeshWide( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3PushContacts_MeshWideW8( block, context ); - return; - } -#endif - - b3PushContacts_MeshWideW4( block, context ); -} - -void b3SolveContacts_MeshWide( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3SolveContacts_MeshWideW8( block, context ); - return; - } -#endif - - b3SolveContacts_MeshWideW4( block, context ); -} - -void b3ApplyRestitution_MeshWide( b3SolverBlock block, b3StepContext* context ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3ApplyRestitution_MeshWideW8( block, context ); - return; - } -#endif - - b3ApplyRestitution_MeshWideW4( block, context ); -} - -void b3StoreImpulses_MeshWide( b3SolverBlock block, b3StepContext* context, int workerIndex ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( context->world->simdWidth == 8 ) - { - b3StoreImpulses_MeshWideW8( block, context, workerIndex ); - return; - } -#endif - - b3StoreImpulses_MeshWideW4( block, context, workerIndex ); -} - -int b3GetWideMeshConstraintByteCount( int simdWidth ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( simdWidth == 8 ) - { - return b3GetWideMeshConstraintByteCountW8(); - } -#else - B3_UNUSED( simdWidth ); -#endif - - return b3GetWideMeshConstraintByteCountW4(); -} - -int b3GetWideMeshManifoldByteCount( int simdWidth ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( simdWidth == 8 ) - { - return b3GetWideMeshManifoldByteCountW8(); - } -#else - B3_UNUSED( simdWidth ); -#endif - - return b3GetWideMeshManifoldByteCountW4(); -} diff --git a/src/contact_solver.h b/src/contact_solver.h index d7773db..547edac 100644 --- a/src/contact_solver.h +++ b/src/contact_solver.h @@ -13,20 +13,20 @@ typedef struct b3ManifoldConstraintPoint float relativeVelocity; float normalImpulse; float totalNormalImpulse; - float restitutionImpulse; + float stepNormalImpulse; float normalMass; float leverArm; } b3ManifoldConstraintPoint; typedef struct b3ManifoldConstraint { - b3ManifoldConstraintPoint points[B3_MAX_MANIFOLD_POINTS]; + // todo use pointer buffer + b3ManifoldConstraintPoint points[4]; int pointCount; b3Vec3 normal; b3Vec3 tangent1; b3Vec3 tangent2; - // Friction centers - b3Vec3 centerA, centerB; + b3Vec3 originA, originB; float twistMass; float twistImpulse; b3Matrix2 tangentMass; @@ -52,69 +52,23 @@ typedef struct b3ContactConstraint int manifoldCount; } b3ContactConstraint; -int b3GetWideContactConstraintByteCount( int simdWidth ); +int b3GetWideContactConstraintByteCount( void ); // Overflow contacts don't fit into the constraint graph coloring void b3PrepareContacts_Overflow( b3StepContext* context ); void b3WarmStartContacts_Overflow( b3StepContext* context ); -void b3PushContacts_Overflow( b3StepContext* context ); -void b3SolveContacts_Overflow( b3StepContext* context ); +void b3SolveContacts_Overflow( b3StepContext* context, bool useBias ); void b3ApplyRestitution_Overflow( b3StepContext* context ); void b3StoreImpulses_Overflow( b3StepContext* context ); void b3PrepareContacts_Mesh( b3SolverBlock block, b3StepContext* context ); void b3WarmStartContacts_Mesh( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_Mesh( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context ); +void b3SolveContacts_Mesh( b3SolverBlock block, b3StepContext* context, bool useBias ); void b3ApplyRestitution_Mesh( b3SolverBlock block, b3StepContext* context ); void b3StoreImpulses_Mesh( b3SolverBlock block, b3StepContext* context, int workerIndex ); void b3PrepareContacts_Convex( b3SolverBlock block, b3StepContext* context ); void b3WarmStartContacts_Convex( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_Convex( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_Convex( b3SolverBlock block, b3StepContext* context ); +void b3SolveContacts_Convex( b3SolverBlock block, b3StepContext* context, bool useBias ); void b3ApplyRestitution_Convex( b3SolverBlock block, b3StepContext* context ); void b3StoreImpulses_Convex( b3SolverBlock block, b3StepContext* context, int workerIndex ); - -void b3PrepareContacts_ConvexW4( b3SolverBlock block, b3StepContext* context ); -void b3WarmStartContacts_ConvexW4( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_ConvexW4( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_ConvexW4( b3SolverBlock block, b3StepContext* context ); -void b3ApplyRestitution_ConvexW4( b3SolverBlock block, b3StepContext* context ); -void b3StoreImpulses_ConvexW4( b3SolverBlock block, b3StepContext* context, int workerIndex ); -int b3GetWideContactConstraintByteCountW4( void ); - -void b3PrepareContacts_ConvexW8( b3SolverBlock block, b3StepContext* context ); -void b3WarmStartContacts_ConvexW8( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_ConvexW8( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_ConvexW8( b3SolverBlock block, b3StepContext* context ); -void b3ApplyRestitution_ConvexW8( b3SolverBlock block, b3StepContext* context ); -void b3StoreImpulses_ConvexW8( b3SolverBlock block, b3StepContext* context, int workerIndex ); -int b3GetWideContactConstraintByteCountW8( void ); - -void b3PrepareContacts_MeshWide( b3SolverBlock block, b3StepContext* context ); -void b3WarmStartContacts_MeshWide( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_MeshWide( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_MeshWide( b3SolverBlock block, b3StepContext* context ); -void b3ApplyRestitution_MeshWide( b3SolverBlock block, b3StepContext* context ); -void b3StoreImpulses_MeshWide( b3SolverBlock block, b3StepContext* context, int workerIndex ); -int b3GetWideMeshConstraintByteCount( int simdWidth ); -int b3GetWideMeshManifoldByteCount( int simdWidth ); - -void b3PrepareContacts_MeshWideW4( b3SolverBlock block, b3StepContext* context ); -void b3WarmStartContacts_MeshWideW4( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_MeshWideW4( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_MeshWideW4( b3SolverBlock block, b3StepContext* context ); -void b3ApplyRestitution_MeshWideW4( b3SolverBlock block, b3StepContext* context ); -void b3StoreImpulses_MeshWideW4( b3SolverBlock block, b3StepContext* context, int workerIndex ); -int b3GetWideMeshConstraintByteCountW4( void ); -int b3GetWideMeshManifoldByteCountW4( void ); - -void b3PrepareContacts_MeshWideW8( b3SolverBlock block, b3StepContext* context ); -void b3WarmStartContacts_MeshWideW8( b3SolverBlock block, b3StepContext* context ); -void b3PushContacts_MeshWideW8( b3SolverBlock block, b3StepContext* context ); -void b3SolveContacts_MeshWideW8( b3SolverBlock block, b3StepContext* context ); -void b3ApplyRestitution_MeshWideW8( b3SolverBlock block, b3StepContext* context ); -void b3StoreImpulses_MeshWideW8( b3SolverBlock block, b3StepContext* context, int workerIndex ); -int b3GetWideMeshConstraintByteCountW8( void ); -int b3GetWideMeshManifoldByteCountW8( void ); diff --git a/src/contact_solver_wide.inl b/src/contact_solver_wide.inl deleted file mode 100644 index 1f685b3..0000000 --- a/src/contact_solver_wide.inl +++ /dev/null @@ -1,1657 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "body.h" -#include "contact_solver.h" -#include "platform.h" -#include "simd.h" -#include "simd_wide.h" - -// Wide vec2 -typedef struct B3_WIDE( b3Vec2 ) -{ - b3FloatW x, y; -} b3Vec2W; - -// Wide quaternion -typedef struct B3_WIDE( b3Quat ) -{ - b3Vec3W V; - b3FloatW S; -} b3QuatW; - -// Wide symmetric matrix2 -typedef struct B3_WIDE( b3SymMatrix2 ) -{ - b3FloatW cxx, cxy, cyy; -} b3SymMatrix2W; - -// Wide symmetric matrix3 -typedef struct B3_WIDE( b3SymMatrix3 ) -{ - b3FloatW cxx, cxy, cxz, cyy, cyz, czz; -} b3SymMatrix3W; - -typedef struct B3_WIDE( b3Matrix3 ) -{ - b3Vec3W cx, cy, cz; -} b3Matrix3W; - -// a + b -static inline b3Vec2W b3AddV2W( b3Vec2W a, b3Vec2W b ) -{ - return (b3Vec2W){ - b3AddW( a.x, b.x ), - b3AddW( a.y, b.y ), - }; -} - -// m * a -static inline b3Vec2W b3MulMV2W( b3SymMatrix2W m, b3Vec2W a ) -{ - b3Vec2W b = { - b3AddW( b3MulW( m.cxx, a.x ), b3MulW( m.cxy, a.y ) ), - b3AddW( b3MulW( m.cxy, a.x ), b3MulW( m.cyy, a.y ) ), - }; - - return b; -} - -// m * a -static inline b3Vec3W b3MulMVW( b3SymMatrix3W m, b3Vec3W a ) -{ - b3Vec3W b = { - b3AddW( b3MulW( m.cxx, a.X ), b3AddW( b3MulW( m.cxy, a.Y ), b3MulW( m.cxz, a.Z ) ) ), - b3AddW( b3MulW( m.cxy, a.X ), b3AddW( b3MulW( m.cyy, a.Y ), b3MulW( m.cyz, a.Z ) ) ), - b3AddW( b3MulW( m.cxz, a.X ), b3AddW( b3MulW( m.cyz, a.Y ), b3MulW( m.czz, a.Z ) ) ), - }; - - return b; -} - -// a - m * b -static inline b3Vec3W b3MulSubMVW( b3Vec3W a, b3SymMatrix3W m, b3Vec3W b ) -{ - b3Vec3W c = { - b3AddW( b3MulW( m.cxx, b.X ), b3AddW( b3MulW( m.cxy, b.Y ), b3MulW( m.cxz, b.Z ) ) ), - b3AddW( b3MulW( m.cxy, b.X ), b3AddW( b3MulW( m.cyy, b.Y ), b3MulW( m.cyz, b.Z ) ) ), - b3AddW( b3MulW( m.cxz, b.X ), b3AddW( b3MulW( m.cyz, b.Y ), b3MulW( m.czz, b.Z ) ) ), - }; - - return (b3Vec3W){ b3SubW( a.X, c.X ), b3SubW( a.Y, c.Y ), b3SubW( a.Z, c.Z ) }; -} - -// a + m * b -static inline b3Vec3W b3MulAddMVW( b3Vec3W a, b3SymMatrix3W m, b3Vec3W b ) -{ - b3Vec3W c = { - b3AddW( b3MulW( m.cxx, b.X ), b3AddW( b3MulW( m.cxy, b.Y ), b3MulW( m.cxz, b.Z ) ) ), - b3AddW( b3MulW( m.cxy, b.X ), b3AddW( b3MulW( m.cyy, b.Y ), b3MulW( m.cyz, b.Z ) ) ), - b3AddW( b3MulW( m.cxz, b.X ), b3AddW( b3MulW( m.cyz, b.Y ), b3MulW( m.czz, b.Z ) ) ), - }; - - return (b3Vec3W){ b3AddW( a.X, c.X ), b3AddW( a.Y, c.Y ), b3AddW( a.Z, c.Z ) }; -} - -static inline b3Vec3W b3MulM3VW( b3Matrix3W m, b3Vec3W a ) -{ - b3Vec3W b = { - b3AddW( b3MulW( m.cx.X, a.X ), b3AddW( b3MulW( m.cy.X, a.Y ), b3MulW( m.cz.X, a.Z ) ) ), - b3AddW( b3MulW( m.cx.Y, a.X ), b3AddW( b3MulW( m.cy.Y, a.Y ), b3MulW( m.cz.Y, a.Z ) ) ), - b3AddW( b3MulW( m.cx.Z, a.X ), b3AddW( b3MulW( m.cy.Z, a.Y ), b3MulW( m.cz.Z, a.Z ) ) ), - }; - - return b; -} - -static inline b3Vec3W b3InvRotateVectorW( b3QuatW q, b3Vec3W a ) -{ - b3Vec3W t = b3CrossW( q.V, a ); - t = (b3Vec3W){ b3AddW( t.X, t.X ), b3AddW( t.Y, t.Y ), b3AddW( t.Z, t.Z ) }; - b3Vec3W u = b3CrossW( q.V, t ); - return (b3Vec3W){ - b3AddW( b3SubW( a.X, b3MulW( q.S, t.X ) ), u.X ), - b3AddW( b3SubW( a.Y, b3MulW( q.S, t.Y ) ), u.Y ), - b3AddW( b3SubW( a.Z, b3MulW( q.S, t.Z ) ), u.Z ), - }; -} - -// Soft contact constraints with sub-stepping support -// Uses fixed anchors for Jacobians for better behavior on rolling shapes (circles & capsules) -// http://mmacklin.com/smallsteps.pdf -// https://box2d.org/files/ErinCatto_SoftConstraints_GDC2011.pdf - -typedef struct B3_WIDE( b3ContactConstraintPoint ) -{ - b3Vec3W anchorAs, anchorBs; - b3FloatW baseSeparations; - b3FloatW normalImpulses; - b3FloatW totalNormalImpulses; - b3FloatW normalMasses; - b3FloatW leverArms; - b3FloatW relativeVelocities; - b3FloatW restitutionImpulses; -} b3ContactConstraintPointWide; - -typedef struct B3_WIDE( b3ContactManifold ) -{ - _Alignas( B3_WIDE_ALIGNMENT ) b3Vec3W normal; - - b3Vec3W tangent1; - b3Vec3W tangent2; - - // Friction centers - b3Vec3W centerA, centerB; - b3FloatW twistMass; - b3FloatW twistImpulse; - b3SymMatrix2W tangentMass; - b3Vec2W frictionImpulse; - b3Vec3W rollingImpulse; - b3FloatW rollingMask; - b3FloatW tangentVelocity1; - b3FloatW tangentVelocity2; - - int pointCount; - - b3ContactConstraintPointWide points[B3_MAX_MANIFOLD_POINTS]; -} b3ContactManifoldWide; - -// Solves one contact per lane -typedef struct B3_WIDE( b3ContactConstraint ) -{ - // These are base 1 - _Alignas( B3_WIDE_ALIGNMENT ) int indexA[B3_SIMD_WIDTH]; - int indexB[B3_SIMD_WIDTH]; - - b3Contact* contacts[B3_SIMD_WIDTH]; - - b3FloatW invMassA, invMassB; - b3SymMatrix3W invIA, invIB; - b3SymMatrix3W rollingMass; - b3FloatW friction; - b3FloatW rollingResistance; - b3FloatW restitution; - - int manifoldCount; -} b3ContactConstraintWide; - -typedef struct B3_WIDE( b3ConvexConstraint ) -{ - b3ContactConstraintWide base; - b3ContactManifoldWide manifold; -} b3ConvexConstraintWide; - -_Static_assert( offsetof( b3ConvexConstraintWide, manifold ) == sizeof( b3ContactConstraintWide ), "wide constraint layout" ); -_Static_assert( sizeof( b3ContactConstraintWide ) % B3_WIDE_ALIGNMENT == 0, "wide constraint layout" ); -_Static_assert( sizeof( b3ContactManifoldWide ) % B3_WIDE_ALIGNMENT == 0, "wide constraint layout" ); - -int B3_WIDE( b3GetWideContactConstraintByteCount )( void ) -{ - return sizeof( b3ConvexConstraintWide ); -} - -int B3_WIDE( b3GetWideMeshConstraintByteCount )( void ) -{ - return sizeof( b3ContactConstraintWide ); -} - -int B3_WIDE( b3GetWideMeshManifoldByteCount )( void ) -{ - return sizeof( b3ContactManifoldWide ); -} - -// wide version of b3BodyState -typedef struct B3_WIDE( b3BodyState ) -{ - b3Vec3W v; - b3Vec3W w; - b3Vec3W dp; - b3QuatW dq; -} b3BodyStateW; - -#if defined( B3_SIMD_NONE ) - -B3_FORCE_INLINE b3BodyStateW b3GatherBodies( const b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices ) -{ - b3BodyState identity = b3_identityBodyState; - - b3BodyState s1 = indices[0] == 0 ? identity : states[indices[0] - 1]; - b3BodyState s2 = indices[1] == 0 ? identity : states[indices[1] - 1]; - b3BodyState s3 = indices[2] == 0 ? identity : states[indices[2] - 1]; - b3BodyState s4 = indices[3] == 0 ? identity : states[indices[3] - 1]; - - b3BodyStateW simdBody; - simdBody.v.X = (b3FloatW){ s1.linearVelocity.x, s2.linearVelocity.x, s3.linearVelocity.x, s4.linearVelocity.x }; - simdBody.v.Y = (b3FloatW){ s1.linearVelocity.y, s2.linearVelocity.y, s3.linearVelocity.y, s4.linearVelocity.y }; - simdBody.v.Z = (b3FloatW){ s1.linearVelocity.z, s2.linearVelocity.z, s3.linearVelocity.z, s4.linearVelocity.z }; - simdBody.w.X = (b3FloatW){ s1.angularVelocity.x, s2.angularVelocity.x, s3.angularVelocity.x, s4.angularVelocity.x }; - simdBody.w.Y = (b3FloatW){ s1.angularVelocity.y, s2.angularVelocity.y, s3.angularVelocity.y, s4.angularVelocity.y }; - simdBody.w.Z = (b3FloatW){ s1.angularVelocity.z, s2.angularVelocity.z, s3.angularVelocity.z, s4.angularVelocity.z }; - simdBody.dp.X = (b3FloatW){ s1.deltaPosition.x, s2.deltaPosition.x, s3.deltaPosition.x, s4.deltaPosition.x }; - simdBody.dp.Y = (b3FloatW){ s1.deltaPosition.y, s2.deltaPosition.y, s3.deltaPosition.y, s4.deltaPosition.y }; - simdBody.dp.Z = (b3FloatW){ s1.deltaPosition.z, s2.deltaPosition.z, s3.deltaPosition.z, s4.deltaPosition.z }; - simdBody.dq.V.X = (b3FloatW){ s1.deltaRotation.v.x, s2.deltaRotation.v.x, s3.deltaRotation.v.x, s4.deltaRotation.v.x }; - simdBody.dq.V.Y = (b3FloatW){ s1.deltaRotation.v.y, s2.deltaRotation.v.y, s3.deltaRotation.v.y, s4.deltaRotation.v.y }; - simdBody.dq.V.Z = (b3FloatW){ s1.deltaRotation.v.z, s2.deltaRotation.v.z, s3.deltaRotation.v.z, s4.deltaRotation.v.z }; - simdBody.dq.S = (b3FloatW){ s1.deltaRotation.s, s2.deltaRotation.s, s3.deltaRotation.s, s4.deltaRotation.s }; - - return simdBody; -} - -// This writes only the velocities back to the solver bodies -B3_FORCE_INLINE void b3ScatterBodies( b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices, - const b3BodyStateW* B3_RESTRICT simdBody ) -{ - int index1 = indices[0] - 1; - if ( index1 != -1 && ( states[index1].flags & b3_dynamicFlag ) != 0 ) - { - b3BodyState* state = states + index1; - state->linearVelocity.x = simdBody->v.X.x; - state->linearVelocity.y = simdBody->v.Y.x; - state->linearVelocity.z = simdBody->v.Z.x; - state->angularVelocity.x = simdBody->w.X.x; - state->angularVelocity.y = simdBody->w.Y.x; - state->angularVelocity.z = simdBody->w.Z.x; - } - - int index2 = indices[1] - 1; - if ( index2 != -1 && ( states[index2].flags & b3_dynamicFlag ) != 0 ) - { - b3BodyState* state = states + index2; - state->linearVelocity.x = simdBody->v.X.y; - state->linearVelocity.y = simdBody->v.Y.y; - state->linearVelocity.z = simdBody->v.Z.y; - state->angularVelocity.x = simdBody->w.X.y; - state->angularVelocity.y = simdBody->w.Y.y; - state->angularVelocity.z = simdBody->w.Z.y; - } - - int index3 = indices[2] - 1; - if ( index3 != -1 && ( states[index3].flags & b3_dynamicFlag ) != 0 ) - { - b3BodyState* state = states + index3; - state->linearVelocity.x = simdBody->v.X.z; - state->linearVelocity.y = simdBody->v.Y.z; - state->linearVelocity.z = simdBody->v.Z.z; - state->angularVelocity.x = simdBody->w.X.z; - state->angularVelocity.y = simdBody->w.Y.z; - state->angularVelocity.z = simdBody->w.Z.z; - } - - int index4 = indices[3] - 1; - if ( index4 != -1 && ( states[index4].flags & b3_dynamicFlag ) != 0 ) - { - b3BodyState* state = states + index4; - state->linearVelocity.x = simdBody->v.X.w; - state->linearVelocity.y = simdBody->v.Y.w; - state->linearVelocity.z = simdBody->v.Z.w; - state->angularVelocity.x = simdBody->w.X.w; - state->angularVelocity.y = simdBody->w.Y.w; - state->angularVelocity.z = simdBody->w.Z.w; - } -} - -#else - -_Static_assert( sizeof( b3BodyState ) == 64, "body state layout" ); -_Static_assert( offsetof( b3BodyState, linearVelocity ) == 0 && offsetof( b3BodyState, angularVelocity ) == 16 && - offsetof( b3BodyState, deltaPosition ) == 32 && offsetof( b3BodyState, deltaRotation ) == 48, - "body state layout" ); - -#if B3_SIMD_WIDTH == 8 - -B3_FORCE_INLINE b3BodyStateW b3GatherBodies( const b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices ) -{ - const float* identity = (const float*)&b3_identityBodyState; - - // Indices are 0 for null - const float* p1 = indices[0] == 0 ? identity : (const float*)( states + indices[0] - 1 ); - const float* p2 = indices[1] == 0 ? identity : (const float*)( states + indices[1] - 1 ); - const float* p3 = indices[2] == 0 ? identity : (const float*)( states + indices[2] - 1 ); - const float* p4 = indices[3] == 0 ? identity : (const float*)( states + indices[3] - 1 ); - const float* p5 = indices[4] == 0 ? identity : (const float*)( states + indices[4] - 1 ); - const float* p6 = indices[5] == 0 ? identity : (const float*)( states + indices[5] - 1 ); - const float* p7 = indices[6] == 0 ? identity : (const float*)( states + indices[6] - 1 ); - const float* p8 = indices[7] == 0 ? identity : (const float*)( states + indices[7] - 1 ); - - b3BodyStateW s; - b3FloatW pad; - - b3TransposeW( b3LoadW( p1 ), b3LoadW( p2 ), b3LoadW( p3 ), b3LoadW( p4 ), b3LoadW( p5 ), b3LoadW( p6 ), b3LoadW( p7 ), - b3LoadW( p8 ), &s.v.X, &s.v.Y, &s.v.Z, &pad, &s.w.X, &s.w.Y, &s.w.Z, &pad ); - b3TransposeW( b3LoadW( p1 + 8 ), b3LoadW( p2 + 8 ), b3LoadW( p3 + 8 ), b3LoadW( p4 + 8 ), b3LoadW( p5 + 8 ), - b3LoadW( p6 + 8 ), b3LoadW( p7 + 8 ), b3LoadW( p8 + 8 ), &s.dp.X, &s.dp.Y, &s.dp.Z, &pad, &s.dq.V.X, &s.dq.V.Y, - &s.dq.V.Z, &s.dq.S ); - - return s; -} - -B3_FORCE_INLINE void b3StoreBodyVelocity( b3BodyState* B3_RESTRICT states, int index, b3FloatW vw ) -{ - // Indices are 0 for null - if ( index == 0 ) - { - return; - } - - b3BodyState* state = states + index - 1; - uint32_t flags = state->flags; - if ( ( flags & b3_dynamicFlag ) == 0 ) - { - return; - } - - b3StoreW( (float*)state, vw ); -} - -// This writes only the velocities back to the solver bodies -B3_FORCE_INLINE void b3ScatterBodies( b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices, - const b3BodyStateW* B3_RESTRICT simdBody ) -{ - // I don't use any dummy body in the body array because this will lead to multithreaded sharing and the - // associated cache flushing. - b3FloatW zero = b3ZeroW(); - b3FloatW vw1, vw2, vw3, vw4, vw5, vw6, vw7, vw8; - b3TransposeW( simdBody->v.X, simdBody->v.Y, simdBody->v.Z, zero, simdBody->w.X, simdBody->w.Y, simdBody->w.Z, zero, &vw1, - &vw2, &vw3, &vw4, &vw5, &vw6, &vw7, &vw8 ); - - b3StoreBodyVelocity( states, indices[0], vw1 ); - b3StoreBodyVelocity( states, indices[1], vw2 ); - b3StoreBodyVelocity( states, indices[2], vw3 ); - b3StoreBodyVelocity( states, indices[3], vw4 ); - b3StoreBodyVelocity( states, indices[4], vw5 ); - b3StoreBodyVelocity( states, indices[5], vw6 ); - b3StoreBodyVelocity( states, indices[6], vw7 ); - b3StoreBodyVelocity( states, indices[7], vw8 ); -} - -#else - -B3_FORCE_INLINE b3BodyStateW b3GatherBodies( const b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices ) -{ - const float* identity = (const float*)&b3_identityBodyState; - - // Indices are 0 for null - const float* p1 = indices[0] == 0 ? identity : (const float*)( states + indices[0] - 1 ); - const float* p2 = indices[1] == 0 ? identity : (const float*)( states + indices[1] - 1 ); - const float* p3 = indices[2] == 0 ? identity : (const float*)( states + indices[2] - 1 ); - const float* p4 = indices[3] == 0 ? identity : (const float*)( states + indices[3] - 1 ); - - b3BodyStateW s; - b3FloatW pad; - b3TransposeW( b3LoadW( p1 ), b3LoadW( p2 ), b3LoadW( p3 ), b3LoadW( p4 ), &s.v.X, &s.v.Y, &s.v.Z, &pad ); - b3TransposeW( b3LoadW( p1 + 4 ), b3LoadW( p2 + 4 ), b3LoadW( p3 + 4 ), b3LoadW( p4 + 4 ), &s.w.X, &s.w.Y, &s.w.Z, &pad ); - b3TransposeW( b3LoadW( p1 + 8 ), b3LoadW( p2 + 8 ), b3LoadW( p3 + 8 ), b3LoadW( p4 + 8 ), &s.dp.X, &s.dp.Y, &s.dp.Z, &pad ); - b3TransposeW( b3LoadW( p1 + 12 ), b3LoadW( p2 + 12 ), b3LoadW( p3 + 12 ), b3LoadW( p4 + 12 ), &s.dq.V.X, &s.dq.V.Y, &s.dq.V.Z, - &s.dq.S ); - return s; -} - -B3_FORCE_INLINE void b3StoreBodyVelocity( b3BodyState* B3_RESTRICT states, int index, b3FloatW v, b3FloatW w ) -{ - // Indices are 0 for null - if ( index == 0 ) - { - return; - } - - b3BodyState* state = states + index - 1; - uint32_t flags = state->flags; - if ( ( flags & b3_dynamicFlag ) == 0 ) - { - return; - } - - b3StoreW( (float*)state, v ); - b3StoreW( (float*)state + 4, w ); -} - -// This writes only the velocities back to the solver bodies -B3_FORCE_INLINE void b3ScatterBodies( b3BodyState* B3_RESTRICT states, const int* B3_RESTRICT indices, - const b3BodyStateW* B3_RESTRICT simdBody ) -{ - // I don't use any dummy body in the body array because this will lead to multithreaded sharing and the - // associated cache flushing. - b3FloatW zero = b3ZeroW(); - b3FloatW v1, v2, v3, v4; - b3TransposeW( simdBody->v.X, simdBody->v.Y, simdBody->v.Z, zero, &v1, &v2, &v3, &v4 ); - b3FloatW w1, w2, w3, w4; - b3TransposeW( simdBody->w.X, simdBody->w.Y, simdBody->w.Z, zero, &w1, &w2, &w3, &w4 ); - - b3StoreBodyVelocity( states, indices[0], v1, w1 ); - b3StoreBodyVelocity( states, indices[1], v2, w2 ); - b3StoreBodyVelocity( states, indices[2], v3, w3 ); - b3StoreBodyVelocity( states, indices[3], v4, w4 ); -} - -#endif - -#endif - -_Static_assert( offsetof( b3ManifoldPoint, anchorA ) == 0, "manifold point layout" ); -_Static_assert( offsetof( b3ManifoldPoint, anchorB ) == 12, "manifold point layout" ); -_Static_assert( offsetof( b3ManifoldPoint, separation ) == 24, "manifold point layout" ); -_Static_assert( offsetof( b3ManifoldPoint, normalImpulse ) == 28, "manifold point layout" ); -_Static_assert( offsetof( b3Manifold, twistImpulse ) == offsetof( b3Manifold, normal ) + 12, "manifold layout" ); -_Static_assert( offsetof( b3Manifold, frictionImpulse ) == offsetof( b3Manifold, normal ) + 16, "manifold layout" ); -_Static_assert( offsetof( b3Manifold, rollingImpulse ) == offsetof( b3Manifold, normal ) + 28, "manifold layout" ); -_Static_assert( offsetof( b3Manifold, pointCount ) == offsetof( b3Manifold, normal ) + 40, "manifold layout" ); -_Static_assert( offsetof( b3Matrix3, cy ) == 12 && offsetof( b3Matrix3, cz ) == 24 && sizeof( b3Matrix3 ) == 36, - "matrix layout" ); - -static const b3Contact b3_zeroContact = { 0 }; -static const b3Manifold b3_zeroManifold = { 0 }; -static const b3BodySim b3_zeroBodySim = { 0 }; - -#if B3_SIMD_WIDTH == 8 -#define B3_GATHER_LANES( wide, lanes, field ) \ - wide = b3SetW( lanes[0]->field, lanes[1]->field, lanes[2]->field, lanes[3]->field, lanes[4]->field, lanes[5]->field, \ - lanes[6]->field, lanes[7]->field ) -#else -#define B3_GATHER_LANES( wide, lanes, field ) wide = b3SetW( lanes[0]->field, lanes[1]->field, lanes[2]->field, lanes[3]->field ) -#endif - -static inline b3SymMatrix3W b3GatherInvInertiaW( const b3BodySim* simLanes[B3_SIMD_WIDTH] ) -{ - const float* i0 = &simLanes[0]->invInertiaWorld.cx.x; - const float* i1 = &simLanes[1]->invInertiaWorld.cx.x; - const float* i2 = &simLanes[2]->invInertiaWorld.cx.x; - const float* i3 = &simLanes[3]->invInertiaWorld.cx.x; -#if B3_SIMD_WIDTH == 8 - const float* i4 = &simLanes[4]->invInertiaWorld.cx.x; - const float* i5 = &simLanes[5]->invInertiaWorld.cx.x; - const float* i6 = &simLanes[6]->invInertiaWorld.cx.x; - const float* i7 = &simLanes[7]->invInertiaWorld.cx.x; -#endif - - b3SymMatrix3W m; - b3FloatW unused; -#if B3_SIMD_WIDTH == 8 - b3TransposeW( b3LoadW( i0 ), b3LoadW( i1 ), b3LoadW( i2 ), b3LoadW( i3 ), b3LoadW( i4 ), b3LoadW( i5 ), b3LoadW( i6 ), - b3LoadW( i7 ), &m.cxx, &m.cxy, &m.cxz, &unused, &m.cyy, &m.cyz, &unused, &unused ); - m.czz = b3SetW( i0[8], i1[8], i2[8], i3[8], i4[8], i5[8], i6[8], i7[8] ); -#else - b3TransposeW( b3LoadW( i0 ), b3LoadW( i1 ), b3LoadW( i2 ), b3LoadW( i3 ), &m.cxx, &m.cxy, &m.cxz, &unused ); - b3TransposeW( b3LoadW( i0 + 4 ), b3LoadW( i1 + 4 ), b3LoadW( i2 + 4 ), b3LoadW( i3 + 4 ), &m.cyy, &m.cyz, &unused, &unused ); - m.czz = b3SetW( i0[8], i1[8], i2[8], i3[8] ); -#endif - return m; -} - -static inline b3SymMatrix3W b3AddSymW( b3SymMatrix3W a, b3SymMatrix3W b ) -{ - return (b3SymMatrix3W){ - b3AddW( a.cxx, b.cxx ), b3AddW( a.cxy, b.cxy ), b3AddW( a.cxz, b.cxz ), - b3AddW( a.cyy, b.cyy ), b3AddW( a.cyz, b.cyz ), b3AddW( a.czz, b.czz ), - }; -} - -static inline b3SymMatrix3W b3InvertSymW( b3SymMatrix3W m ) -{ - b3FloatW cxx = b3SubW( b3MulW( m.cyy, m.czz ), b3MulW( m.cyz, m.cyz ) ); - b3FloatW cxy = b3SubW( b3MulW( m.cxz, m.cyz ), b3MulW( m.cxy, m.czz ) ); - b3FloatW cxz = b3SubW( b3MulW( m.cxy, m.cyz ), b3MulW( m.cxz, m.cyy ) ); - b3FloatW cyy = b3SubW( b3MulW( m.cxx, m.czz ), b3MulW( m.cxz, m.cxz ) ); - b3FloatW cyz = b3SubW( b3MulW( m.cxy, m.cxz ), b3MulW( m.cxx, m.cyz ) ); - b3FloatW czz = b3SubW( b3MulW( m.cxx, m.cyy ), b3MulW( m.cxy, m.cxy ) ); - - b3FloatW det = b3AddW( b3MulW( m.cxx, cxx ), b3AddW( b3MulW( m.cxy, cxy ), b3MulW( m.cxz, cxz ) ) ); - b3FloatW valid = b3GreaterThanW( b3AbsW( det ), b3SplatW( 1000.0f * FLT_MIN ) ); - b3FloatW invDet = b3BlendW( b3ZeroW(), b3DivW( b3SplatW( 1.0f ), det ), valid ); - - return (b3SymMatrix3W){ - b3MulW( invDet, cxx ), b3MulW( invDet, cxy ), b3MulW( invDet, cxz ), - b3MulW( invDet, cyy ), b3MulW( invDet, cyz ), b3MulW( invDet, czz ), - }; -} - -static inline b3Vec3W b3PerpW( b3Vec3W a ) -{ - b3FloatW zero = b3ZeroW(); - b3FloatW half = b3SplatW( 0.5f ); - b3FloatW mask = b3OrW( b3LessThanW( a.X, b3NegW( half ) ), b3GreaterThanW( a.X, half ) ); - - b3Vec3W p; - p.X = b3BlendW( zero, a.Y, mask ); - p.Y = b3BlendW( a.Z, b3NegW( a.X ), mask ); - p.Z = b3BlendW( b3NegW( a.Y ), zero, mask ); - - b3FloatW lengthSquared = b3DotW( p, p ); - b3FloatW valid = b3GreaterThanW( lengthSquared, b3SplatW( 1000.0f * FLT_MIN ) ); - b3FloatW s = b3BlendW( zero, b3DivW( b3SplatW( 1.0f ), b3SqrtW( lengthSquared ) ), valid ); - return b3MulSVW( s, p ); -} -static inline b3FloatW b3IntsToFloatW( const int* v ) -{ -#if B3_SIMD_WIDTH == 8 - return b3SetW( (float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (float)v[5], (float)v[6], (float)v[7] ); -#else - return b3SetW( (float)v[0], (float)v[1], (float)v[2], (float)v[3] ); -#endif -} - -// Get the contiguous manifold array that trails the constraint. -static inline b3ContactManifoldWide* b3GetManifoldsW( b3ContactConstraintWide* c ) -{ - return (b3ContactManifoldWide*)( c + 1 ); -} - -// fixedManifoldCount is 1 to indicate a convex contact with one manifold. -B3_FORCE_INLINE b3ContactConstraintWide* b3GetConstraintW( void* base, const int* manifoldStarts, int index, - int fixedManifoldCount ) -{ - if ( fixedManifoldCount > 0 ) - { - size_t stride = sizeof( b3ContactConstraintWide ) + fixedManifoldCount * sizeof( b3ContactManifoldWide ); - return (b3ContactConstraintWide*)( (uint8_t*)base + index * stride ); - } - - size_t offset = index * sizeof( b3ContactConstraintWide ) + - ( manifoldStarts[index] - manifoldStarts[0] ) * sizeof( b3ContactManifoldWide ); - return (b3ContactConstraintWide*)( (uint8_t*)base + offset ); -} - -B3_FORCE_INLINE b3ContactConstraintWide* b3NextConstraintW( b3ContactConstraintWide* c, int manifoldCount ) -{ - return (b3ContactConstraintWide*)( (uint8_t*)c + sizeof( b3ContactConstraintWide ) + - manifoldCount * sizeof( b3ContactManifoldWide ) ); -} - -// Contact constraint data is stored in a heterogious stream. Constraints followed by an array of constraint manifolds. -// [c1 m11 m12 c2 m21 c3 m31 m32 m33 ... ] -B3_FORCE_INLINE bool b3PrepareConstraintW( b3ContactConstraintWide* c, b3Contact* const* contacts, int manifoldCount, - b3StepContext* context, b3FloatW warmStartScale ) -{ - b3BodySim* sims = context->sims; - b3BodyState* states = context->states; -#if B3_ENABLE_VALIDATION - b3Body* bodies = context->world->bodies.data; -#endif - - b3FloatW zeroW = b3ZeroW(); - b3FloatW oneW = b3SplatW( 1.0f ); - b3FloatW twoW = b3SplatW( 2.0f ); - b3FloatW invTau = b3SplatW( 1.0f / B3_SPECULATIVE_DISTANCE ); - b3FloatW minFrictionWeight = b3SplatW( B3_MIN_FRICTION_WEIGHT ); - b3FloatW minDet = b3SplatW( 1000.0f * FLT_MIN ); - - const b3Contact* contactLanes[B3_SIMD_WIDTH]; - const b3BodySim* simLanesA[B3_SIMD_WIDTH]; - const b3BodySim* simLanesB[B3_SIMD_WIDTH]; - int manifoldCounts[B3_SIMD_WIDTH]; - int hitEventLanes = 0; - int maxManifoldCount = 0; - - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - b3Contact* contact = contacts[lane]; - c->contacts[lane] = contact; - - if ( contact != NULL ) - { - int indexA = b3DecodeAwakeIndex( contact->encodedBodySimA ); - int indexB = b3DecodeAwakeIndex( contact->encodedBodySimB ); - -#if B3_ENABLE_VALIDATION - b3Body* bodyA = bodies + contact->edges[0].bodyId; - b3Body* bodyB = bodies + contact->edges[1].bodyId; - B3_ASSERT( contact->encodedBodySimA == b3EncodeBodySimIndex( bodyA ) ); - B3_ASSERT( contact->encodedBodySimB == b3EncodeBodySimIndex( bodyB ) ); -#endif - - c->indexA[lane] = indexA + 1; - c->indexB[lane] = indexB + 1; - manifoldCounts[lane] = contact->manifoldCount; - - contactLanes[lane] = contact; - simLanesA[lane] = indexA == B3_NULL_INDEX ? &b3_zeroBodySim : sims + indexA; - simLanesB[lane] = indexB == B3_NULL_INDEX ? &b3_zeroBodySim : sims + indexB; - hitEventLanes |= ( contact->flags & b3_simEnableHitEvent ) != 0 ? 1 << lane : 0; - maxManifoldCount = b3MaxInt( maxManifoldCount, contact->manifoldCount ); - } - else - { - c->indexA[lane] = 0; - c->indexB[lane] = 0; - manifoldCounts[lane] = 0; - - contactLanes[lane] = &b3_zeroContact; - simLanesA[lane] = &b3_zeroBodySim; - simLanesB[lane] = &b3_zeroBodySim; - } - } - - B3_VALIDATE( maxManifoldCount == manifoldCount ); - B3_UNUSED( maxManifoldCount ); - c->manifoldCount = manifoldCount; - - b3FloatW mA, mB; - B3_GATHER_LANES( mA, simLanesA, invMass ); - B3_GATHER_LANES( mB, simLanesB, invMass ); - b3SymMatrix3W iA = b3GatherInvInertiaW( simLanesA ); - b3SymMatrix3W iB = b3GatherInvInertiaW( simLanesB ); - c->invMassA = mA; - c->invMassB = mB; - c->invIA = iA; - c->invIB = iB; - - b3Vec3W tangentVelocity; - B3_GATHER_LANES( c->friction, contactLanes, friction ); - B3_GATHER_LANES( c->rollingResistance, contactLanes, rollingResistance ); - B3_GATHER_LANES( c->restitution, contactLanes, restitution ); - B3_GATHER_LANES( tangentVelocity.X, contactLanes, tangentVelocity.x ); - B3_GATHER_LANES( tangentVelocity.Y, contactLanes, tangentVelocity.y ); - B3_GATHER_LANES( tangentVelocity.Z, contactLanes, tangentVelocity.z ); - - b3SymMatrix3W invIAB = b3AddSymW( iA, iB ); - if ( b3AllZeroW( c->rollingResistance ) == false ) - { - c->rollingMass = b3InvertSymW( invIAB ); - } - else - { - c->rollingMass = (b3SymMatrix3W){ zeroW, zeroW, zeroW, zeroW, zeroW, zeroW }; - } - - b3FloatW rollingResistanceMask = b3GreaterThanW( c->rollingResistance, zeroW ); - - b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - const b3Manifold* manifoldLanes[B3_SIMD_WIDTH]; - int activeLanes[B3_SIMD_WIDTH]; - int pointCounts[B3_SIMD_WIDTH]; - int pointCount = 0; - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - if ( manifoldIndex < manifoldCounts[lane] ) - { - const b3Manifold* manifold = contactLanes[lane]->manifolds + manifoldIndex; - manifoldLanes[lane] = manifold; - activeLanes[lane] = 1; - pointCounts[lane] = manifold->pointCount; - } - else - { - manifoldLanes[lane] = &b3_zeroManifold; - activeLanes[lane] = 0; - pointCounts[lane] = 0; - } - - pointCount = b3MaxInt( pointCount, pointCounts[lane] ); - } - - B3_VALIDATE( 0 <= pointCount && pointCount <= B3_MAX_MANIFOLD_POINTS ); - cm->pointCount = pointCount; - cm->rollingMask = b3AndW( rollingResistanceMask, b3GreaterThanW( b3IntsToFloatW( activeLanes ), zeroW ) ); - - b3Vec3W normal, frictionImpulse, rollingImpulse; - b3FloatW twistImpulse; - { - const float* m0 = &manifoldLanes[0]->normal.x; - const float* m1 = &manifoldLanes[1]->normal.x; - const float* m2 = &manifoldLanes[2]->normal.x; - const float* m3 = &manifoldLanes[3]->normal.x; -#if B3_SIMD_WIDTH == 8 - const float* m4 = &manifoldLanes[4]->normal.x; - const float* m5 = &manifoldLanes[5]->normal.x; - const float* m6 = &manifoldLanes[6]->normal.x; - const float* m7 = &manifoldLanes[7]->normal.x; - b3TransposeW( b3LoadW( m0 ), b3LoadW( m1 ), b3LoadW( m2 ), b3LoadW( m3 ), b3LoadW( m4 ), b3LoadW( m5 ), b3LoadW( m6 ), - b3LoadW( m7 ), &normal.X, &normal.Y, &normal.Z, &twistImpulse, &frictionImpulse.X, &frictionImpulse.Y, - &frictionImpulse.Z, &rollingImpulse.X ); - rollingImpulse.Y = b3SetW( m0[8], m1[8], m2[8], m3[8], m4[8], m5[8], m6[8], m7[8] ); - rollingImpulse.Z = b3SetW( m0[9], m1[9], m2[9], m3[9], m4[9], m5[9], m6[9], m7[9] ); -#else - b3TransposeW( b3LoadW( m0 ), b3LoadW( m1 ), b3LoadW( m2 ), b3LoadW( m3 ), &normal.X, &normal.Y, &normal.Z, - &twistImpulse ); - b3TransposeW( b3LoadW( m0 + 4 ), b3LoadW( m1 + 4 ), b3LoadW( m2 + 4 ), b3LoadW( m3 + 4 ), &frictionImpulse.X, - &frictionImpulse.Y, &frictionImpulse.Z, &rollingImpulse.X ); - rollingImpulse.Y = b3SetW( m0[8], m1[8], m2[8], m3[8] ); - rollingImpulse.Z = b3SetW( m0[9], m1[9], m2[9], m3[9] ); -#endif - } - - b3Vec3W tangent1 = b3PerpW( normal ); - b3Vec3W tangent2 = b3CrossW( tangent1, normal ); - cm->normal = normal; - cm->tangent1 = tangent1; - cm->tangent2 = tangent2; - cm->tangentVelocity1 = b3DotW( tangentVelocity, tangent1 ); - cm->tangentVelocity2 = b3DotW( tangentVelocity, tangent2 ); - - cm->twistImpulse = b3MulW( warmStartScale, twistImpulse ); - cm->rollingImpulse.X = b3BlendW( zeroW, b3MulW( warmStartScale, rollingImpulse.X ), cm->rollingMask ); - cm->rollingImpulse.Y = b3BlendW( zeroW, b3MulW( warmStartScale, rollingImpulse.Y ), cm->rollingMask ); - cm->rollingImpulse.Z = b3BlendW( zeroW, b3MulW( warmStartScale, rollingImpulse.Z ), cm->rollingMask ); - cm->frictionImpulse.x = b3MulW( warmStartScale, b3DotW( frictionImpulse, tangent1 ) ); - cm->frictionImpulse.y = b3MulW( warmStartScale, b3DotW( frictionImpulse, tangent2 ) ); - - b3FloatW pointCountW = b3IntsToFloatW( pointCounts ); - - b3Vec3W centerA = { zeroW, zeroW, zeroW }; - b3Vec3W centerB = { zeroW, zeroW, zeroW }; - b3FloatW totalFrictionWeight = zeroW; - - for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - b3FloatW pointMask = b3GreaterThanW( pointCountW, b3SplatW( (float)pointIndex ) ); - - const float* p0 = (const float*)( manifoldLanes[0]->points + pointIndex ); - const float* p1 = (const float*)( manifoldLanes[1]->points + pointIndex ); - const float* p2 = (const float*)( manifoldLanes[2]->points + pointIndex ); - const float* p3 = (const float*)( manifoldLanes[3]->points + pointIndex ); -#if B3_SIMD_WIDTH == 8 - const float* p4 = (const float*)( manifoldLanes[4]->points + pointIndex ); - const float* p5 = (const float*)( manifoldLanes[5]->points + pointIndex ); - const float* p6 = (const float*)( manifoldLanes[6]->points + pointIndex ); - const float* p7 = (const float*)( manifoldLanes[7]->points + pointIndex ); -#endif - - b3Vec3W rA, rB; - b3FloatW separation, normalImpulse; -#if B3_SIMD_WIDTH == 8 - b3TransposeW( b3LoadW( p0 ), b3LoadW( p1 ), b3LoadW( p2 ), b3LoadW( p3 ), b3LoadW( p4 ), b3LoadW( p5 ), b3LoadW( p6 ), - b3LoadW( p7 ), &rA.X, &rA.Y, &rA.Z, &rB.X, &rB.Y, &rB.Z, &separation, &normalImpulse ); -#else - b3TransposeW( b3LoadW( p0 ), b3LoadW( p1 ), b3LoadW( p2 ), b3LoadW( p3 ), &rA.X, &rA.Y, &rA.Z, &rB.X ); - b3TransposeW( b3LoadW( p0 + 4 ), b3LoadW( p1 + 4 ), b3LoadW( p2 + 4 ), b3LoadW( p3 + 4 ), &rB.Y, &rB.Z, &separation, - &normalImpulse ); -#endif - - rA.X = b3BlendW( zeroW, rA.X, pointMask ); - rA.Y = b3BlendW( zeroW, rA.Y, pointMask ); - rA.Z = b3BlendW( zeroW, rA.Z, pointMask ); - rB.X = b3BlendW( zeroW, rB.X, pointMask ); - rB.Y = b3BlendW( zeroW, rB.Y, pointMask ); - rB.Z = b3BlendW( zeroW, rB.Z, pointMask ); - separation = b3BlendW( zeroW, separation, pointMask ); - normalImpulse = b3BlendW( zeroW, normalImpulse, pointMask ); - - // C0 friction center decay. Needed to prevent spinning top drift (GyroscopicPrecession sample). - // See details in b3PrepareContacts_Mesh. This code should stay in sync. - b3FloatW weight = b3MinW( b3MaxW( b3SubW( twoW, b3MulW( separation, invTau ) ), minFrictionWeight ), oneW ); - weight = b3BlendW( zeroW, weight, pointMask ); - centerA = b3MulAddSVW( centerA, weight, rA ); - centerB = b3MulAddSVW( centerB, weight, rB ); - totalFrictionWeight = b3AddW( totalFrictionWeight, weight ); - - cp->anchorAs = rA; - cp->anchorBs = rB; - cp->baseSeparations = b3SubW( separation, b3DotW( b3SubVW( rB, rA ), normal ) ); - cp->normalImpulses = b3MulW( warmStartScale, normalImpulse ); - cp->totalNormalImpulses = zeroW; - cp->relativeVelocities = zeroW; - cp->restitutionImpulses = zeroW; - - b3Vec3W rnA = b3CrossW( rA, normal ); - b3Vec3W rnB = b3CrossW( rB, normal ); - b3FloatW kNormal = b3AddW( mA, mB ); - kNormal = b3AddW( kNormal, b3DotW( rnA, b3MulMVW( iA, rnA ) ) ); - kNormal = b3AddW( kNormal, b3DotW( rnB, b3MulMVW( iB, rnB ) ) ); - b3FloatW valid = b3AndW( b3GreaterThanW( kNormal, zeroW ), pointMask ); - cp->normalMasses = b3BlendW( zeroW, b3DivW( oneW, kNormal ), valid ); - } - - b3FloatW frictionValid = b3GreaterThanW( totalFrictionWeight, zeroW ); - b3FloatW invWeight = b3BlendW( zeroW, b3DivW( oneW, totalFrictionWeight ), frictionValid ); - centerA = b3MulSVW( invWeight, centerA ); - centerB = b3MulSVW( invWeight, centerB ); - cm->centerA = centerA; - cm->centerB = centerB; - - for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - b3FloatW pointMask = b3GreaterThanW( pointCountW, b3SplatW( (float)pointIndex ) ); - b3Vec3W d = b3SubVW( cp->anchorAs, centerA ); - cp->leverArms = b3BlendW( zeroW, b3SqrtW( b3DotW( d, d ) ), pointMask ); - } - - { - b3Vec3W rtA1 = b3CrossW( centerA, tangent1 ); - b3Vec3W rtA2 = b3CrossW( centerA, tangent2 ); - b3Vec3W rtB1 = b3CrossW( centerB, tangent1 ); - b3Vec3W rtB2 = b3CrossW( centerB, tangent2 ); - b3Vec3W iArtA1 = b3MulMVW( iA, rtA1 ); - b3Vec3W iArtA2 = b3MulMVW( iA, rtA2 ); - b3Vec3W iBrtB1 = b3MulMVW( iB, rtB1 ); - b3Vec3W iBrtB2 = b3MulMVW( iB, rtB2 ); - - b3FloatW kxx = b3AddW( b3AddW( b3AddW( mA, mB ), b3DotW( rtA1, iArtA1 ) ), b3DotW( rtB1, iBrtB1 ) ); - b3FloatW kyy = b3AddW( b3AddW( b3AddW( mA, mB ), b3DotW( rtA2, iArtA2 ) ), b3DotW( rtB2, iBrtB2 ) ); - b3FloatW kxy = b3AddW( b3DotW( rtA1, iArtA2 ), b3DotW( rtB1, iBrtB2 ) ); - - b3FloatW det = b3SubW( b3MulW( kxx, kyy ), b3MulW( kxy, kxy ) ); - b3FloatW valid = b3AndW( b3GreaterThanW( b3AbsW( det ), minDet ), frictionValid ); - b3FloatW invDet = b3BlendW( zeroW, b3DivW( oneW, det ), valid ); - cm->tangentMass.cxx = b3MulW( invDet, kyy ); - cm->tangentMass.cxy = b3NegW( b3MulW( invDet, kxy ) ); - cm->tangentMass.cyy = b3MulW( invDet, kxx ); - } - - { - b3FloatW kTwist = b3DotW( normal, b3MulMVW( invIAB, normal ) ); - cm->twistMass = b3BlendW( zeroW, b3DivW( oneW, kTwist ), b3GreaterThanW( kTwist, zeroW ) ); - } - } - - // Only sample contact point normal velocity if needed. - bool haveRestitution = b3AnyTrueW( b3GreaterThanW( c->restitution, zeroW ) ); - if ( hitEventLanes != 0 || haveRestitution ) - { - b3BodyStateW bA = b3GatherBodies( states, c->indexA ); - b3BodyStateW bB = b3GatherBodies( states, c->indexB ); - - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - for ( int pointIndex = 0; pointIndex < cm->pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - - b3Vec3W vrA = b3AddVW( bA.v, b3CrossW( bA.w, cp->anchorAs ) ); - b3Vec3W vrB = b3AddVW( bB.v, b3CrossW( bB.w, cp->anchorBs ) ); - b3FloatW vn = b3DotW( cm->normal, b3SubVW( vrB, vrA ) ); - cp->relativeVelocities = vn; - - if ( hitEventLanes != 0 ) - { - float normalVelocities[B3_SIMD_WIDTH]; - b3StoreW( normalVelocities, vn ); - - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - if ( ( hitEventLanes & ( 1 << lane ) ) == 0 || manifoldIndex >= manifoldCounts[lane] ) - { - continue; - } - - b3Manifold* manifold = c->contacts[lane]->manifolds + manifoldIndex; - if ( pointIndex < manifold->pointCount ) - { - manifold->points[pointIndex].normalVelocity = normalVelocities[lane]; - } - } - } - } - } - } - - return haveRestitution; -} - -void B3_WIDE( b3PrepareContacts_Convex )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( prepare_contact, "Prepare Contact", b3_colorYellow, true ); - - b3World* world = context->world; - b3WidePrepareSpan* spans = context->widePrepareSpans; - void* wideBase = context->wideConstraints; - b3FloatW warmStartScale = world->enableWarmStarting ? b3SplatW( 1.0f ) : b3ZeroW(); - bool anyRestitution = false; - - int wideIndex = block.startIndex; - int endWideIndex = block.startIndex + block.count; - - // Find color for start index. Linear search but fast. - int colorIndex = 0; - while ( spans[colorIndex + 1].start <= wideIndex ) - { - colorIndex += 1; - } - - // Loop over block - while ( wideIndex < endWideIndex ) - { - int colorWideStart = spans[colorIndex].start; - int colorWideEndIndex = b3MinInt( spans[colorIndex + 1].start, endWideIndex ); - int colorContactCount = spans[colorIndex].count; - int* contactIds = spans[colorIndex].contacts; - - // Loop over color - for ( ; wideIndex < colorWideEndIndex; ++wideIndex ) - { - b3ContactConstraintWide* c = b3GetConstraintW( wideBase, NULL, wideIndex, 1 ); - int localWideIndex = wideIndex - colorWideStart; - - b3Contact* contacts[B3_SIMD_WIDTH]; - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - int contactIndex = B3_SIMD_WIDTH * localWideIndex + lane; - if ( contactIndex < colorContactCount ) - { - contacts[lane] = b3Array_Get( world->contacts, contactIds[contactIndex] ); - B3_ASSERT( contacts[lane]->manifoldCount == 1 ); - } - else - { - contacts[lane] = NULL; - } - } - - bool haveRestitution = b3PrepareConstraintW( c, contacts, 1, context, warmStartScale ); - anyRestitution = anyRestitution || haveRestitution; - } - - // Advance to next color - colorIndex += 1; - } - - if ( anyRestitution ) - { - b3AtomicStoreInt( &context->anyRestitution, 1 ); - } - - b3TracyCZoneEnd( prepare_contact ); -} - -void B3_WIDE( b3PrepareContacts_MeshWide )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( prepare_mesh_wide, "Prepare Mesh", b3_colorYellow, true ); - - b3World* world = context->world; - b3MeshPrepareSpan* spans = context->meshPrepareSpans; - void* wideBase = context->wideMeshConstraints; - const int* manifoldStarts = context->wideMeshManifoldStarts; - b3FloatW warmStartScale = world->enableWarmStarting ? b3SplatW( 1.0f ) : b3ZeroW(); - bool anyRestitution = false; - - int wideIndex = block.startIndex; - int endWideIndex = block.startIndex + block.count; - - int colorIndex = 0; - while ( spans[colorIndex + 1].start <= wideIndex ) - { - colorIndex += 1; - } - - while ( wideIndex < endWideIndex ) - { - int colorWideStart = spans[colorIndex].start; - int colorWideEndIndex = b3MinInt( spans[colorIndex + 1].start, endWideIndex ); - int colorContactCount = spans[colorIndex].count; - b3ContactSpec* specs = spans[colorIndex].contacts; - - // This order is used to group contacts with similar manifold counts to keep the lanes full. - const int* order = spans[colorIndex].order; - - for ( ; wideIndex < colorWideEndIndex; ++wideIndex ) - { - b3ContactConstraintWide* c = b3GetConstraintW( wideBase, manifoldStarts, wideIndex, 0 ); - int localWideIndex = wideIndex - colorWideStart; - - b3Contact* contacts[B3_SIMD_WIDTH]; - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - int contactIndex = B3_SIMD_WIDTH * localWideIndex + lane; - if ( contactIndex < colorContactCount ) - { - b3ContactSpec* spec = specs + order[contactIndex]; - b3Contact* contact = b3Array_Get( world->contacts, spec->contactId ); - B3_ASSERT( contact->contactId == spec->contactId ); - B3_ASSERT( contact->manifoldCount == spec->manifoldCount ); - contacts[lane] = contact; - } - else - { - contacts[lane] = NULL; - } - } - - int manifoldCount = manifoldStarts[wideIndex + 1] - manifoldStarts[wideIndex]; - bool haveRestitution = b3PrepareConstraintW( c, contacts, manifoldCount, context, warmStartScale ); - anyRestitution = anyRestitution || haveRestitution; - } - - colorIndex += 1; - } - - if ( anyRestitution ) - { - b3AtomicStoreInt( &context->anyRestitution, 1 ); - } - - b3TracyCZoneEnd( prepare_mesh_wide ); -} - -B3_FORCE_INLINE void b3WarmStartContactsW( b3SolverBlock block, b3StepContext* context, void* base, const int* manifoldStarts, - int fixedManifoldCount ) -{ - b3BodyState* states = context->states; - b3FloatW zeroW = b3ZeroW(); - - b3ContactConstraintWide* c = b3GetConstraintW( base, manifoldStarts, block.startIndex, fixedManifoldCount ); - for ( int i = 0; i < block.count; ++i ) - { - int manifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : c->manifoldCount; - bool anyRolling = b3AllZeroW( c->rollingResistance ) == false; - - b3Vec3W linearImpulse = { zeroW, zeroW, zeroW }; - b3Vec3W angularImpulseA = { zeroW, zeroW, zeroW }; - b3Vec3W angularImpulseB = { zeroW, zeroW, zeroW }; - - const b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - const b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - b3FloatW totalNormalImpulse = zeroW; - b3Vec3W momentA = { zeroW, zeroW, zeroW }; - b3Vec3W momentB = { zeroW, zeroW, zeroW }; - - for ( int pointIndex = 0; pointIndex < cm->pointCount; ++pointIndex ) - { - const b3ContactConstraintPointWide* cp = cm->points + pointIndex; - b3FloatW normalImpulse = cp->normalImpulses; - totalNormalImpulse = b3AddW( totalNormalImpulse, normalImpulse ); - momentA = b3MulAddSVW( momentA, normalImpulse, cp->anchorAs ); - momentB = b3MulAddSVW( momentB, normalImpulse, cp->anchorBs ); - } - - b3Vec3W normal = cm->normal; - b3Vec3W frictionImpulse = b3MulSVW( cm->frictionImpulse.x, cm->tangent1 ); - frictionImpulse = b3MulAddSVW( frictionImpulse, cm->frictionImpulse.y, cm->tangent2 ); - - b3Vec3W linear = b3MulAddSVW( frictionImpulse, totalNormalImpulse, normal ); - - b3Vec3W twistImpulse = b3MulSVW( cm->twistImpulse, normal ); - b3Vec3W angularA = - b3AddVW( b3AddVW( b3CrossW( momentA, normal ), b3CrossW( cm->centerA, frictionImpulse ) ), twistImpulse ); - b3Vec3W angularB = - b3AddVW( b3AddVW( b3CrossW( momentB, normal ), b3CrossW( cm->centerB, frictionImpulse ) ), twistImpulse ); - - if ( anyRolling ) - { - angularA = b3AddVW( angularA, cm->rollingImpulse ); - angularB = b3AddVW( angularB, cm->rollingImpulse ); - } - - linearImpulse = b3AddVW( linearImpulse, linear ); - angularImpulseA = b3AddVW( angularImpulseA, angularA ); - angularImpulseB = b3AddVW( angularImpulseB, angularB ); - } - - b3BodyStateW bA = b3GatherBodies( states, c->indexA ); - b3BodyStateW bB = b3GatherBodies( states, c->indexB ); - - bA.w = b3MulSubMVW( bA.w, c->invIA, angularImpulseA ); - bA.v = b3MulSubSVW( bA.v, c->invMassA, linearImpulse ); - bB.w = b3MulAddMVW( bB.w, c->invIB, angularImpulseB ); - bB.v = b3MulAddSVW( bB.v, c->invMassB, linearImpulse ); - - b3ScatterBodies( states, c->indexA, &bA ); - b3ScatterBodies( states, c->indexB, &bB ); - - c = b3NextConstraintW( c, manifoldCount ); - } -} - -// Solve the non-penetration constraints with the soft bias. No friction and no restitution. -B3_FORCE_INLINE void b3PushContactsW( b3SolverBlock block, b3StepContext* context, void* base, const int* manifoldStarts, - int fixedManifoldCount ) -{ - b3BodyState* states = context->states; - b3FloatW inv_h = b3SplatW( context->inv_h ); - b3FloatW contactSpeed = b3SplatW( -context->world->contactSpeed ); - b3FloatW oneW = b3SplatW( 1.0f ); - b3FloatW zeroW = b3ZeroW(); - - // Stiffer for static contacts to avoid bodies getting pushed through the ground. Selected per - // lane from the null body index instead of stored per constraint. - b3FloatW dynamicBiasRate = b3SplatW( context->contactSoftness.massScale * context->contactSoftness.biasRate ); - b3FloatW dynamicMassScale = b3SplatW( context->contactSoftness.massScale ); - b3FloatW dynamicImpulseScale = b3SplatW( context->contactSoftness.impulseScale ); - b3FloatW staticBiasRate = b3SplatW( context->staticSoftness.massScale * context->staticSoftness.biasRate ); - b3FloatW staticMassScale = b3SplatW( context->staticSoftness.massScale ); - b3FloatW staticImpulseScale = b3SplatW( context->staticSoftness.impulseScale ); - - b3ContactConstraintWide* c = b3GetConstraintW( base, manifoldStarts, block.startIndex, fixedManifoldCount ); - for ( int i = 0; i < block.count; ++i ) - { - int manifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : c->manifoldCount; - b3BodyStateW bA = b3GatherBodies( states, c->indexA ); - b3BodyStateW bB = b3GatherBodies( states, c->indexB ); - - b3FloatW softMask = b3SoftMaskW( c->indexA, c->indexB ); - b3FloatW biasRate = b3BlendW( dynamicBiasRate, staticBiasRate, softMask ); - b3FloatW massScale = b3BlendW( dynamicMassScale, staticMassScale, softMask ); - b3FloatW impulseScale = b3BlendW( dynamicImpulseScale, staticImpulseScale, softMask ); - - b3Vec3W dp = b3SubVW( bB.dp, bA.dp ); - b3FloatW invMass = b3AddW( c->invMassA, c->invMassB ); - - b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - // Convert to normals to local space to reduce transform math. - // Read the normal rather than put on stack to avoid register spills. - b3FloatW normalSeparation = b3DotW( cm->normal, dp ); - b3Vec3W normalA = b3InvRotateVectorW( bA.dq, cm->normal ); - b3Vec3W normalB = b3InvRotateVectorW( bB.dq, cm->normal ); - - b3FloatW linearNormalVelocity = b3DotW( cm->normal, b3SubVW( bB.v, bA.v ) ); - b3FloatW manifoldImpulse = zeroW; - - for ( int pointIndex = 0; pointIndex < cm->pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - - // Fixed anchor points for applying impulses - b3Vec3W rA = cp->anchorAs; - b3Vec3W rB = cp->anchorBs; - - b3FloatW s = b3AddW( b3AddW( normalSeparation, b3SubW( b3DotW( normalB, rB ), b3DotW( normalA, rA ) ) ), - cp->baseSeparations ); - - // Apply speculative bias if separation is greater than zero, otherwise apply soft constraint bias - b3FloatW separated = b3GreaterThanW( s, zeroW ); - - // Speculative bias - positive - b3FloatW specBias = b3MulW( s, inv_h ); - - // Overlap bias - negative - b3FloatW overlapBias = b3MaxW( b3MulW( biasRate, s ), contactSpeed ); - b3FloatW velocityBias = b3BlendW( overlapBias, specBias, separated ); - - b3FloatW pointMassScale = b3BlendW( massScale, oneW, separated ); - b3FloatW pointImpulseScale = b3BlendW( impulseScale, zeroW, separated ); - - b3Vec3W uA = b3CrossW( rA, cm->normal ); - b3Vec3W uB = b3CrossW( rB, cm->normal ); - b3Vec3W gA = b3MulMVW( c->invIA, uA ); - b3Vec3W gB = b3MulMVW( c->invIB, uB ); - - b3FloatW vn = b3AddW( linearNormalVelocity, b3SubW( b3DotW( uB, bB.w ), b3DotW( uA, bA.w ) ) ); - - b3FloatW negImpulse = b3AddW( b3MulW( cp->normalMasses, b3AddW( b3MulW( pointMassScale, vn ), velocityBias ) ), - b3MulW( pointImpulseScale, cp->normalImpulses ) ); - b3FloatW impulse = b3MaxW( b3NegW( negImpulse ), b3NegW( cp->normalImpulses ) ); - cp->normalImpulses = b3AddW( cp->normalImpulses, impulse ); - - linearNormalVelocity = b3MulAddW( linearNormalVelocity, invMass, impulse ); - manifoldImpulse = b3AddW( manifoldImpulse, impulse ); - bA.w = b3MulSubSVW( bA.w, impulse, gA ); - bB.w = b3MulAddSVW( bB.w, impulse, gB ); - } - - b3Vec3W P = b3MulSVW( manifoldImpulse, cm->normal ); - bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); - bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); - } - - b3ScatterBodies( states, c->indexA, &bA ); - b3ScatterBodies( states, c->indexB, &bB ); - - c = b3NextConstraintW( c, manifoldCount ); - } -} - -// Solve the normal constraint, friction, and rolling resistance. -B3_FORCE_INLINE void b3SolveContactsW( b3SolverBlock block, b3StepContext* context, void* base, const int* manifoldStarts, - int fixedManifoldCount ) -{ - b3BodyState* states = context->states; - b3FloatW inv_h = b3SplatW( context->inv_h ); - b3FloatW oneW = b3SplatW( 1.0f ); - b3FloatW zeroW = b3ZeroW(); - b3FloatW epsilonW = b3SplatW( FLT_EPSILON ); - - b3ContactConstraintWide* c = b3GetConstraintW( base, manifoldStarts, block.startIndex, fixedManifoldCount ); - for ( int i = 0; i < block.count; ++i ) - { - int manifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : c->manifoldCount; - b3BodyStateW bA = b3GatherBodies( states, c->indexA ); - b3BodyStateW bB = b3GatherBodies( states, c->indexB ); - - bool anyRolling = b3AllZeroW( c->rollingResistance ) == false; - b3Vec3W dp = b3SubVW( bB.dp, bA.dp ); - b3FloatW invMass = b3AddW( c->invMassA, c->invMassB ); - - b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - // Read the normal rather than put on stack to avoid register spills. - b3FloatW normalSeparation = b3DotW( cm->normal, dp ); - b3Vec3W normalA = b3InvRotateVectorW( bA.dq, cm->normal ); - b3Vec3W normalB = b3InvRotateVectorW( bB.dq, cm->normal ); - - b3Vec3W dv = b3SubVW( bB.v, bA.v ); - b3FloatW linearNormalVelocity = b3DotW( cm->normal, dv ); - b3FloatW linearTangentVelocity1 = b3SubW( b3DotW( cm->tangent1, dv ), cm->tangentVelocity1 ); - b3FloatW linearTangentVelocity2 = b3SubW( b3DotW( cm->tangent2, dv ), cm->tangentVelocity2 ); - b3FloatW manifoldImpulse = zeroW; - - b3FloatW totalNormalImpulse = zeroW; - b3FloatW totalTwistLimit = zeroW; - - // Normal contraints - for ( int pointIndex = 0; pointIndex < cm->pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - - // Fixed anchor points for applying impulses - b3Vec3W rA = cp->anchorAs; - b3Vec3W rB = cp->anchorBs; - - b3FloatW s = b3AddW( b3AddW( normalSeparation, b3SubW( b3DotW( normalB, rB ), b3DotW( normalA, rA ) ) ), - cp->baseSeparations ); - - // Speculative bias, positive if separated and zero if overlapped - b3FloatW velocityBias = b3MaxW( zeroW, b3MulW( s, inv_h ) ); - - b3Vec3W uA = b3CrossW( rA, cm->normal ); - b3Vec3W uB = b3CrossW( rB, cm->normal ); - b3Vec3W gA = b3MulMVW( c->invIA, uA ); - b3Vec3W gB = b3MulMVW( c->invIB, uB ); - - b3FloatW vn = b3AddW( linearNormalVelocity, b3SubW( b3DotW( uB, bB.w ), b3DotW( uA, bA.w ) ) ); - - b3FloatW negImpulse = b3MulW( cp->normalMasses, b3AddW( vn, velocityBias ) ); - b3FloatW impulse = b3MaxW( b3NegW( negImpulse ), b3NegW( cp->normalImpulses ) ); - b3FloatW newImpulse = b3AddW( cp->normalImpulses, impulse ); - cp->normalImpulses = newImpulse; - cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, newImpulse ); - totalNormalImpulse = b3AddW( totalNormalImpulse, newImpulse ); - totalTwistLimit = b3AddW( totalTwistLimit, b3MulW( cp->leverArms, newImpulse ) ); - - linearNormalVelocity = b3MulAddW( linearNormalVelocity, invMass, impulse ); - manifoldImpulse = b3AddW( manifoldImpulse, impulse ); - bA.w = b3MulSubSVW( bA.w, impulse, gA ); - bB.w = b3MulAddSVW( bB.w, impulse, gB ); - } - - // Rolling resistance. After normal constraints because it uses the normal impulse. - if ( anyRolling ) - { - // flip A/B order to negate - b3Vec3W deltaImpulse = b3MulMVW( c->rollingMass, b3SubVW( bA.w, bB.w ) ); - b3Vec3W oldImpulse = cm->rollingImpulse; - cm->rollingImpulse = b3AddVW( oldImpulse, deltaImpulse ); - - b3FloatW maxImpulse = b3MulW( c->rollingResistance, totalNormalImpulse ); - b3FloatW lengthSquared = b3DotW( cm->rollingImpulse, cm->rollingImpulse ); - - // if ( magSqr > maxLambda * maxLambda + FLT_EPSILON ) - //{ - // c->rollingImpulse *= maxLambda / sqrtf( magSqr ); - // } - - b3FloatW mask = b3GreaterThanW( lengthSquared, b3MulAddW( epsilonW, maxImpulse, maxImpulse ) ); - - // No approximate _mm_rsqrt_ps here to maintain cross-platform determinism - b3FloatW normalize = b3DivW( maxImpulse, b3AddW( b3SqrtW( lengthSquared ), epsilonW ) ); - b3FloatW scale = b3BlendW( oneW, normalize, mask ); - - // Blend the result to ensure there are no +/-0 determinism problems, since 0 * -1 == -0. - b3Vec3W scaledImpulse = b3MulSVW( scale, cm->rollingImpulse ); - cm->rollingImpulse.X = b3BlendW( zeroW, scaledImpulse.X, cm->rollingMask ); - cm->rollingImpulse.Y = b3BlendW( zeroW, scaledImpulse.Y, cm->rollingMask ); - cm->rollingImpulse.Z = b3BlendW( zeroW, scaledImpulse.Z, cm->rollingMask ); - - deltaImpulse = b3SubVW( cm->rollingImpulse, oldImpulse ); - - bA.w = b3MulSubMVW( bA.w, c->invIA, deltaImpulse ); - bB.w = b3MulAddMVW( bB.w, c->invIB, deltaImpulse ); - } - - // Central twist friction. Friction goes last to improve stacking stability. - { - b3FloatW twistSpeed = b3DotW( cm->normal, b3SubVW( bB.w, bA.w ) ); - b3FloatW maxLambda = b3MulW( c->friction, totalTwistLimit ); - b3FloatW oldImpulse = cm->twistImpulse; - b3FloatW impulse = b3NegW( b3MulW( cm->twistMass, twistSpeed ) ); - impulse = b3MaxW( b3SubW( b3NegW( maxLambda ), oldImpulse ), b3MinW( impulse, b3SubW( maxLambda, oldImpulse ) ) ); - cm->twistImpulse = b3AddW( oldImpulse, impulse ); - - bA.w = b3MulSubSVW( bA.w, impulse, b3MulMVW( c->invIA, cm->normal ) ); - bB.w = b3MulAddSVW( bB.w, impulse, b3MulMVW( c->invIB, cm->normal ) ); - } - - // Central friction. Friction goes last to improve stacking stability. - { - b3Vec3W tangent1 = cm->tangent1; - b3Vec3W tangent2 = cm->tangent2; - - // Fixed anchor points for applying impulses - b3Vec3W rA = cm->centerA; - b3Vec3W rB = cm->centerB; - - b3Vec3W angularRelativeVelocity = b3SubVW( b3CrossW( bB.w, rB ), b3CrossW( bA.w, rA ) ); - - // Relative tangent velocity at contact - b3Vec2W vt = { - b3AddW( linearTangentVelocity1, b3DotW( angularRelativeVelocity, tangent1 ) ), - b3AddW( linearTangentVelocity2, b3DotW( angularRelativeVelocity, tangent2 ) ), - }; - - // Incremental tangent impulse - b3Vec2W deltaImpulse = b3MulMV2W( cm->tangentMass, vt ); - deltaImpulse = (b3Vec2W){ b3NegW( deltaImpulse.x ), b3NegW( deltaImpulse.y ) }; - b3Vec2W newImpulse = b3AddV2W( cm->frictionImpulse, deltaImpulse ); - - b3FloatW maxImpulse = b3MulW( c->friction, totalNormalImpulse ); - - // Clamp the accumulated impulse - b3FloatW lengthSquared = b3AddW( b3MulW( newImpulse.x, newImpulse.x ), b3MulW( newImpulse.y, newImpulse.y ) ); - - // Max impulse can be zero - b3FloatW mask = b3GreaterThanW( lengthSquared, b3MulW( maxImpulse, maxImpulse ) ); - - // No approximate _mm_rsqrt_ps here to maintain cross-platform determinism. Add epsilon to avoid divide by - // zero. - b3FloatW normalize = b3DivW( maxImpulse, b3AddW( b3SqrtW( lengthSquared ), epsilonW ) ); - b3FloatW scale = b3BlendW( oneW, normalize, mask ); - newImpulse = (b3Vec2W){ - b3MulW( scale, newImpulse.x ), - b3MulW( scale, newImpulse.y ), - }; - - deltaImpulse = (b3Vec2W){ - b3SubW( newImpulse.x, cm->frictionImpulse.x ), - b3SubW( newImpulse.y, cm->frictionImpulse.y ), - }; - - cm->frictionImpulse = newImpulse; - - // Apply delta impulse - b3Vec3W P = b3AddVW( b3MulSVW( deltaImpulse.x, tangent1 ), b3MulSVW( deltaImpulse.y, tangent2 ) ); - bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, P ) ); - bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, P ) ); - - P = b3MulAddSVW( P, manifoldImpulse, cm->normal ); - bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); - bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); - } - } - - b3ScatterBodies( states, c->indexA, &bA ); - b3ScatterBodies( states, c->indexB, &bB ); - - c = b3NextConstraintW( c, manifoldCount ); - } -} - -B3_FORCE_INLINE void b3ApplyRestitutionW( b3SolverBlock block, b3StepContext* context, void* base, const int* manifoldStarts, - int fixedManifoldCount ) -{ - b3BodyState* states = context->states; - b3FloatW inv_h = b3SplatW( context->inv_h ); - b3FloatW negRestitutionThreshold = b3SplatW( -context->world->restitutionThreshold ); - b3FloatW zeroW = b3ZeroW(); - bool propagate = context->world->enableRestitutionPropagation; - - b3ContactConstraintWide* next = b3GetConstraintW( base, manifoldStarts, block.startIndex, fixedManifoldCount ); - for ( int i = 0; i < block.count; ++i ) - { - b3ContactConstraintWide* c = next; - int manifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : c->manifoldCount; - next = b3NextConstraintW( c, manifoldCount ); - - if ( propagate == false && b3AllZeroW( c->restitution ) ) - { - continue; - } - - b3BodyStateW bA = b3GatherBodies( states, c->indexA ); - b3BodyStateW bB = b3GatherBodies( states, c->indexB ); - - b3FloatW restitutionMask = b3GreaterThanW( c->restitution, zeroW ); - b3Vec3W dp = b3SubVW( bB.dp, bA.dp ); - - b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3ContactManifoldWide* cm = manifolds + manifoldIndex; - - b3FloatW normalSeparation = b3DotW( cm->normal, dp ); - b3Vec3W normalA = b3InvRotateVectorW( bA.dq, cm->normal ); - b3Vec3W normalB = b3InvRotateVectorW( bB.dq, cm->normal ); - - // Read the point count rather than put on stack to avoid register spills. - for ( int pointIndex = 0; pointIndex < cm->pointCount; ++pointIndex ) - { - b3ContactConstraintPointWide* cp = cm->points + pointIndex; - - b3Vec3W rA = cp->anchorAs; - b3Vec3W rB = cp->anchorBs; - - b3FloatW s = b3AddW( b3AddW( normalSeparation, b3SubW( b3DotW( normalB, rB ), b3DotW( normalA, rA ) ) ), - cp->baseSeparations ); - - b3FloatW normalMass = propagate ? cp->normalMasses : b3BlendW( zeroW, cp->normalMasses, restitutionMask ); - - b3FloatW compressionImpulse = b3SubW( cp->totalNormalImpulses, cp->restitutionImpulses ); - b3FloatW armed = - b3AndW( b3AndW( restitutionMask, b3LessThanW( cp->relativeVelocities, negRestitutionThreshold ) ), - b3GreaterThanW( compressionImpulse, zeroW ) ); - - b3FloatW specBias = b3MaxW( zeroW, b3MulW( s, inv_h ) ); - b3FloatW velocityBias = b3BlendW( specBias, b3MulW( c->restitution, cp->relativeVelocities ), armed ); - - b3Vec3W vrA = b3AddVW( bA.v, b3CrossW( bA.w, rA ) ); - b3Vec3W vrB = b3AddVW( bB.v, b3CrossW( bB.w, rB ) ); - b3FloatW vn = b3DotW( b3SubVW( vrB, vrA ), cm->normal ); - - b3FloatW negImpulse = b3MulW( normalMass, b3AddW( vn, velocityBias ) ); - - b3FloatW newImpulse = b3MaxW( b3SubW( cp->normalImpulses, negImpulse ), zeroW ); - b3FloatW impulse = b3SubW( newImpulse, cp->normalImpulses ); - - b3FloatW approachImpulse = - b3MinW( b3MaxW( b3NegW( b3MulW( normalMass, vn ) ), zeroW ), b3MaxW( impulse, zeroW ) ); - b3FloatW allowance = - b3SubW( b3MulW( c->restitution, b3AddW( compressionImpulse, approachImpulse ) ), cp->restitutionImpulses ); - b3FloatW maxImpulse = b3AddW( approachImpulse, b3MaxW( allowance, zeroW ) ); - impulse = b3BlendW( impulse, b3MinW( impulse, maxImpulse ), armed ); - - cp->normalImpulses = b3AddW( cp->normalImpulses, impulse ); - cp->restitutionImpulses = b3AddW( cp->restitutionImpulses, b3SubW( impulse, approachImpulse ) ); - cp->totalNormalImpulses = b3AddW( cp->totalNormalImpulses, impulse ); - - b3Vec3W P = b3MulSVW( impulse, cm->normal ); - bA.w = b3MulSubMVW( bA.w, c->invIA, b3CrossW( rA, P ) ); - bA.v = b3MulSubSVW( bA.v, c->invMassA, P ); - bB.w = b3MulAddMVW( bB.w, c->invIB, b3CrossW( rB, P ) ); - bB.v = b3MulAddSVW( bB.v, c->invMassB, P ); - } - } - - b3ScatterBodies( states, c->indexA, &bA ); - b3ScatterBodies( states, c->indexB, &bB ); - } -} - -// Store impulses by contact constraint -B3_FORCE_INLINE void b3StoreImpulsesW( b3SolverBlock block, b3StepContext* context, int workerIndex, void* base, - const int* manifoldStarts, int fixedManifoldCount ) -{ - b3World* world = context->world; - b3TaskContext* taskContext = world->taskContexts.data + workerIndex; - b3BitSet* hitEventBitSet = &taskContext->hitEventBitSet; - bool hasHitEvents = taskContext->hasHitEvents; - float negHitThreshold = -world->hitEventThreshold; - - b3ContactConstraintWide* c = b3GetConstraintW( base, manifoldStarts, block.startIndex, fixedManifoldCount ); - for ( int i = 0; i < block.count; ++i ) - { - int manifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : c->manifoldCount; - const b3ContactManifoldWide* manifolds = b3GetManifoldsW( c ); - - // Pay the cache misses up front. - b3Manifold* laneManifolds[B3_SIMD_WIDTH]; - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - b3Contact* contact = c->contacts[lane]; - laneManifolds[lane] = contact != NULL ? contact->manifolds : NULL; - } - - for ( int lane = 0; lane < B3_SIMD_WIDTH; ++lane ) - { - b3Contact* contact = c->contacts[lane]; - if ( contact == NULL ) - { - continue; - } - - int laneManifoldCount = fixedManifoldCount > 0 ? fixedManifoldCount : contact->manifoldCount; - B3_ASSERT( laneManifoldCount == contact->manifoldCount && laneManifoldCount <= manifoldCount ); - - for ( int manifoldIndex = 0; manifoldIndex < laneManifoldCount; ++manifoldIndex ) - { - const b3ContactManifoldWide* cm = manifolds + manifoldIndex; - b3Manifold* m = laneManifolds[lane] + manifoldIndex; - - const float* frictionImpulse1 = (const float*)&cm->frictionImpulse.x; - const float* frictionImpulse2 = (const float*)&cm->frictionImpulse.y; - const float* tangent1X = (const float*)&cm->tangent1.X; - const float* tangent1Y = (const float*)&cm->tangent1.Y; - const float* tangent1Z = (const float*)&cm->tangent1.Z; - const float* tangent2X = (const float*)&cm->tangent2.X; - const float* tangent2Y = (const float*)&cm->tangent2.Y; - const float* tangent2Z = (const float*)&cm->tangent2.Z; - const float* twistImpulse = (const float*)&cm->twistImpulse; - const float* rollingImpulseX = (const float*)&cm->rollingImpulse.X; - const float* rollingImpulseY = (const float*)&cm->rollingImpulse.Y; - const float* rollingImpulseZ = (const float*)&cm->rollingImpulse.Z; - - float f1 = frictionImpulse1[lane]; - float f2 = frictionImpulse2[lane]; - m->frictionImpulse = (b3Vec3){ - f1 * tangent1X[lane] + f2 * tangent2X[lane], - f1 * tangent1Y[lane] + f2 * tangent2Y[lane], - f1 * tangent1Z[lane] + f2 * tangent2Z[lane], - }; - m->twistImpulse = twistImpulse[lane]; - m->rollingImpulse = (b3Vec3){ - rollingImpulseX[lane], - rollingImpulseY[lane], - rollingImpulseZ[lane], - }; - - int pointCount = m->pointCount; - B3_ASSERT( pointCount <= cm->pointCount ); - for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) - { - const b3ContactConstraintPointWide* cp = cm->points + pointIndex; - const float* normalImpulse = (const float*)&cp->normalImpulses; - const float* totalNormalImpulse = (const float*)&cp->totalNormalImpulses; - - b3ManifoldPoint* mp = m->points + pointIndex; - mp->normalImpulse = normalImpulse[lane]; - mp->totalNormalImpulse = totalNormalImpulse[lane]; - } - } - - if ( ( contact->flags & b3_simEnableHitEvent ) != 0 ) - { - bool flagged = false; - for ( int manifoldIndex = 0; manifoldIndex < laneManifoldCount && flagged == false; ++manifoldIndex ) - { - const b3Manifold* m = contact->manifolds + manifoldIndex; - for ( int pointIndex = 0; pointIndex < m->pointCount; ++pointIndex ) - { - const b3ManifoldPoint* mp = m->points + pointIndex; - - // Need to check total impulse because the point may be speculative and not colliding - if ( mp->normalVelocity < negHitThreshold && mp->totalNormalImpulse > 0.0f ) - { - b3SetBit( hitEventBitSet, contact->contactId ); - hasHitEvents = true; - flagged = true; - break; - } - } - } - } - } - - c = b3NextConstraintW( c, manifoldCount ); - } - - taskContext->hasHitEvents = hasHitEvents; -} - -// These wrappers allow the implementation be shared between convex and mesh contacts. - -void B3_WIDE( b3WarmStartContacts_Convex )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( warm_start_contact, "Warm Start", b3_colorGreen, true ); - b3WarmStartContactsW( block, context, context->graph->colors[block.colorIndex].wideConstraints, NULL, 1 ); - b3TracyCZoneEnd( warm_start_contact ); -} - -void B3_WIDE( b3PushContacts_Convex )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( push_contact, "Push Contact", b3_colorAliceBlue, true ); - b3PushContactsW( block, context, context->graph->colors[block.colorIndex].wideConstraints, NULL, 1 ); - b3TracyCZoneEnd( push_contact ); -} - -void B3_WIDE( b3SolveContacts_Convex )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( solve_contact, "Solve Contact", b3_colorAliceBlue, true ); - b3SolveContactsW( block, context, context->graph->colors[block.colorIndex].wideConstraints, NULL, 1 ); - b3TracyCZoneEnd( solve_contact ); -} - -void B3_WIDE( b3ApplyRestitution_Convex )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( restitution, "Restitution", b3_colorDodgerBlue, true ); - b3ApplyRestitutionW( block, context, context->graph->colors[block.colorIndex].wideConstraints, NULL, 1 ); - b3TracyCZoneEnd( restitution ); -} - -void B3_WIDE( b3StoreImpulses_Convex )( b3SolverBlock block, b3StepContext* context, int workerIndex ) -{ - b3TracyCZoneNC( store_impulses, "Store", b3_colorFireBrick, true ); - b3StoreImpulsesW( block, context, workerIndex, context->wideConstraints, NULL, 1 ); - b3TracyCZoneEnd( store_impulses ); -} - -void B3_WIDE( b3WarmStartContacts_MeshWide )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( warm_start_mesh_wide, "Warm Start Mesh", b3_colorGreen, true ); - b3GraphColor* color = context->graph->colors + block.colorIndex; - b3WarmStartContactsW( block, context, color->wideMeshConstraints, color->wideMeshManifoldStarts, 0 ); - b3TracyCZoneEnd( warm_start_mesh_wide ); -} - -void B3_WIDE( b3PushContacts_MeshWide )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( push_mesh_wide, "Push Mesh", b3_colorAliceBlue, true ); - b3GraphColor* color = context->graph->colors + block.colorIndex; - b3PushContactsW( block, context, color->wideMeshConstraints, color->wideMeshManifoldStarts, 0 ); - b3TracyCZoneEnd( push_mesh_wide ); -} - -void B3_WIDE( b3SolveContacts_MeshWide )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( solve_mesh_wide, "Solve Mesh", b3_colorAliceBlue, true ); - b3GraphColor* color = context->graph->colors + block.colorIndex; - b3SolveContactsW( block, context, color->wideMeshConstraints, color->wideMeshManifoldStarts, 0 ); - b3TracyCZoneEnd( solve_mesh_wide ); -} - -void B3_WIDE( b3ApplyRestitution_MeshWide )( b3SolverBlock block, b3StepContext* context ) -{ - b3TracyCZoneNC( restitution_mesh_wide, "Restitution Mesh", b3_colorDodgerBlue, true ); - b3GraphColor* color = context->graph->colors + block.colorIndex; - b3ApplyRestitutionW( block, context, color->wideMeshConstraints, color->wideMeshManifoldStarts, 0 ); - b3TracyCZoneEnd( restitution_mesh_wide ); -} - -void B3_WIDE( b3StoreImpulses_MeshWide )( b3SolverBlock block, b3StepContext* context, int workerIndex ) -{ - b3TracyCZoneNC( store_mesh_wide, "Store Mesh", b3_colorFireBrick, true ); - b3StoreImpulsesW( block, context, workerIndex, context->wideMeshConstraints, context->wideMeshManifoldStarts, 0 ); - b3TracyCZoneEnd( store_mesh_wide ); -} diff --git a/src/container.h b/src/container.h index 471db1a..2831cb6 100644 --- a/src/container.h +++ b/src/container.h @@ -182,4 +182,3 @@ B3_INLINE int b3RemoveHelper( void* data, int* count, int index, int elementSize #define b3Array_ByteCount( a ) ( ( a ).capacity * (int)sizeof( *( a ).data ) ) b3DeclareArrayNative( int ); -b3DeclareArrayNative( uint64_t ); diff --git a/src/convex_manifold.c b/src/convex_manifold.c index 85337c7..2422567 100644 --- a/src/convex_manifold.c +++ b/src/convex_manifold.c @@ -1,20 +1,42 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto +// SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "manifold.h" - #include "algorithm.h" +#include "manifold.h" #include "shape.h" -#include "simd.h" #include "box3d/base.h" #include "box3d/collision.h" #include "box3d/constants.h" -#include #include #include +static inline bool b3IsMinkowskiFaceIsolated( b3Vec3 a, b3Vec3 b, b3Vec3 n ) +{ + // An isolated edge (e.g. like in a capsule) defines a circle through the + // origin on the Gauss map. So testing for overlap between this circle and + // the arc AB simplifies to a simple plane test. + float an = b3Dot( a, n ); + float bn = b3Dot( b, n ); + + return an * bn <= 0.0f; +} + +// bxa = cross(b, a) and dxc = cross(d, c) +// but in practice we use the edge vector between the faces for robustness +static inline bool b3IsMinkowskiFace( b3Vec3 a, b3Vec3 b, b3Vec3 bxa, b3Vec3 c, b3Vec3 d, b3Vec3 dxc ) +{ + // Two edges build a face on the Minkowski sum if the associated arcs ab and cd intersect on the Gauss map. + // The associated arcs are defined by the adjacent face normals of each edge. + float cba = b3Dot( c, bxa ); + float dba = b3Dot( d, bxa ); + float adc = b3Dot( a, dxc ); + float bdc = b3Dot( b, dxc ); + + return cba * dba < 0.0f && adc * bdc < 0.0f && cba * bdc > 0.0f; +} + static int b3ClipSegment( b3ClipVertex segment[2], b3Plane plane ) { int vertexCount = 0; @@ -84,8 +106,8 @@ static int b3ClipSegmentToHullFace( b3ClipVertex segment[2], const b3HullData* h return 2; } -static b3SeparatingAxis b3QueryFaceDirectionHullAndCapsule( const b3HullData* hull, const b3Capsule* capsule, - b3Transform capsuleTransform ) +static b3FaceQuery b3QueryFaceDirectionHullAndCapsule( const b3HullData* hull, const b3Capsule* capsule, + b3Transform capsuleTransform ) { int maxFaceIndex = -1; int maxVertexIndex = -1; @@ -112,32 +134,62 @@ static b3SeparatingAxis b3QueryFaceDirectionHullAndCapsule( const b3HullData* hu } } - return (b3SeparatingAxis){ - .normal = planes[maxFaceIndex].normal, + return (b3FaceQuery){ .separation = maxFaceSeparation, - .indexA = (uint8_t)maxFaceIndex, - .indexB = (uint8_t)maxVertexIndex, + .faceIndex = (uint8_t)maxFaceIndex, + .vertexIndex = (uint8_t)maxVertexIndex, }; } -static b3SeparatingAxis b3QueryEdgeDirectionHullAndCapsule( const b3HullData* hull, const b3Capsule* capsule, - b3Transform capsuleTransform ) +static b3FaceQuery b3QueryFaceDirections( const b3HullData* hullA, const b3HullData* hullB, b3Transform relativeTransform ) +{ + // We perform all computations in local space of the second hull + b3Transform transform = b3InvertTransform( relativeTransform ); + const b3Plane* planesA = b3GetHullPlanes( hullA ); + const b3Vec3* pointsB = b3GetHullPoints( hullB ); + + int maxFaceIndex = -1; + int maxVertexIndex = -1; + float maxFaceSeparation = -FLT_MAX; + + for ( int faceIndex = 0; faceIndex < hullA->faceCount; ++faceIndex ) + { + b3Plane plane = b3TransformPlane( transform, planesA[faceIndex] ); + + int vertexIndex = b3FindHullSupportVertex( hullB, b3Neg( plane.normal ) ); + b3Vec3 support = pointsB[vertexIndex]; + float separation = b3PlaneSeparation( plane, support ); + if ( separation > maxFaceSeparation ) + { + maxFaceIndex = faceIndex; + maxVertexIndex = vertexIndex; + maxFaceSeparation = separation; + } + } + + return (b3FaceQuery){ + .separation = maxFaceSeparation, + .faceIndex = (uint8_t)maxFaceIndex, + .vertexIndex = (uint8_t)maxVertexIndex, + }; +} + +static b3EdgeQuery b3QueryEdgeDirectionHullAndCapsule( const b3HullData* hull, const b3Capsule* capsule, + b3Transform capsuleTransform ) { // Find axis of minimum penetration - b3Vec3 maxNormal = b3Vec3_zero; float maxSeparation = -FLT_MAX; - int maxIndexA = B3_NULL_INDEX; - int maxIndexB = B3_NULL_INDEX; + int maxIndex1 = -1; + int maxIndex2 = -1; // We perform all computations in local space of the hull - b3Vec3 pA = b3TransformPoint( capsuleTransform, capsule->center1 ); - b3Vec3 qA = b3TransformPoint( capsuleTransform, capsule->center2 ); - b3Vec3 eA = b3Sub( qA, pA ); + b3Vec3 p1 = b3TransformPoint( capsuleTransform, capsule->center1 ); + b3Vec3 q1 = b3TransformPoint( capsuleTransform, capsule->center2 ); + b3Vec3 e1 = b3Sub( q1, p1 ); const b3HullHalfEdge* edges = b3GetHullEdges( hull ); const b3Vec3* points = b3GetHullPoints( hull ); const b3Plane* planes = b3GetHullPlanes( hull ); - float squaredTolerance = B3_PARALLEL_EDGE_TOL * B3_PARALLEL_EDGE_TOL; for ( int index = 0; index < hull->edgeCount; index += 2 ) { @@ -145,66 +197,283 @@ static b3SeparatingAxis b3QueryEdgeDirectionHullAndCapsule( const b3HullData* hu const b3HullHalfEdge* twin = edges + index + 1; B3_ASSERT( edge->twin == index + 1 && twin->twin == index ); - b3Vec3 qB = points[twin->origin]; - b3Vec3 uB = planes[edge->face].normal; - b3Vec3 vB = planes[twin->face].normal; + b3Vec3 p2 = points[edge->origin]; + b3Vec3 q2 = points[twin->origin]; + b3Vec3 e2 = b3Sub( q2, p2 ); - // An isolated edge (e.g. like in a capsule) defines a circle through the - // origin on the Gauss map. So testing for overlap between this circle and - // the arc AB simplifies to a plane test. - float cba = b3Dot( uB, eA ); - float dba = b3Dot( vB, eA ); + b3Vec3 u2 = planes[edge->face].normal; + b3Vec3 v2 = planes[twin->face].normal; - if ( cba * dba < 0.0f ) + if ( b3IsMinkowskiFaceIsolated( u2, v2, e1 ) ) { - // Avoid nearly parallel edges that may lead to invalid separation values at the noise floor. - if ( b3MaxFloat( cba * cba, dba * dba ) < squaredTolerance * b3LengthSquared( eA ) ) - { - continue; - } - - // The intersection of the arcs on the Gauss map is the edge pair axis. Cast the - // arc of hull B (from uB to vB) against the plane containing the arc of hull A: - // dot(uB + t * (vB - uB), eA) == 0 - // then - // t = cba / (cba - dba) - // - // The signs of cba and dba differ (Minkowski test), so the division is safe. - // - // The axis generated points from B to A by construction since it lands between - // two face normals on B. This removes the need to orient the separation axis - // using the hull centers. - // - // The axis is perpendicular to both edges so I can use qA and qB as arbitrary - // points on edgeA and edgeB to measure the separation. - - float t = cba / ( cba - dba ); - b3Vec3 axis = b3Lerp( uB, vB, t ); - B3_VALIDATE( b3LengthSquared( axis ) > 1000.0f * FLT_MIN ); - axis = b3Normalize( axis ); - float separation = b3Dot( axis, b3Sub( qA, qB ) ); - + // We can pass any point on the edge and choose + // the edge centers for better numerical precision. + b3Vec3 c1 = b3MulSV( 0.5f, b3Add( q1, p1 ) ); + b3Vec3 c2 = hull->center; + float separation = b3EdgeEdgeSeparation( q1, e1, c1, q2, e2, c2 ); if ( separation > maxSeparation ) { // Note: We don't exit early if we find a separating axis here since we want to // find the best one for caching and account for the convex radius later. - maxNormal = axis; maxSeparation = separation; - maxIndexA = 0; - maxIndexB = index; + maxIndex1 = 0; + maxIndex2 = index; } } } // Save result - return (b3SeparatingAxis){ - .normal = maxNormal, + return (b3EdgeQuery){ + .separation = maxSeparation, + .indexA = (uint8_t)maxIndex1, + .indexB = (uint8_t)maxIndex2, + }; +} + +static b3EdgeQuery b3QueryEdgeDirections( const b3HullData* hullA, const b3HullData* hullB, b3Transform transformBtoA ) +{ + // Find axis of minimum penetration + float maxSeparation = -FLT_MAX; + int maxIndexA = B3_NULL_INDEX; + int maxIndexB = B3_NULL_INDEX; + + const b3HullHalfEdge* edgesA = b3GetHullEdges( hullA ); + const b3Vec3* pointsA = b3GetHullPoints( hullA ); + const b3Plane* planesA = b3GetHullPlanes( hullA ); + const b3HullHalfEdge* edgesB = b3GetHullEdges( hullB ); + const b3Vec3* pointsB = b3GetHullPoints( hullB ); + const b3Plane* planesB = b3GetHullPlanes( hullB ); + + // Work in frame A + b3Matrix3 matrix = b3MakeMatrixFromQuat( transformBtoA.q ); + + // Arranged to minimize transform operations + for ( int indexB = 0; indexB < hullB->edgeCount; indexB += 2 ) + { + const b3HullHalfEdge* edgeB = edgesB + indexB; + const b3HullHalfEdge* twinB = edgesB + indexB + 1; + B3_ASSERT( edgeB->twin == indexB + 1 && twinB->twin == indexB ); + + b3Vec3 qB = pointsB[twinB->origin]; + b3Vec3 eB = b3MulMV( matrix, b3Sub( qB, pointsB[edgeB->origin] ) ); + qB = b3Add( b3MulMV( matrix, qB ), transformBtoA.p ); + + b3Vec3 uB = b3MulMV( matrix, planesB[edgeB->face].normal ); + b3Vec3 vB = b3MulMV( matrix, planesB[twinB->face].normal ); + + for ( int indexA = 0; indexA < hullA->edgeCount; indexA += 2 ) + { + const b3HullHalfEdge* edgeA = edgesA + indexA; + const b3HullHalfEdge* twinA = edgesA + indexA + 1; + B3_ASSERT( edgeA->twin == indexA + 1 && twinA->twin == indexA ); + + b3Vec3 qA = pointsA[twinA->origin]; + b3Vec3 eA = b3Sub( qA, pointsA[edgeA->origin] ); + b3Vec3 uA = planesA[edgeA->face].normal; + b3Vec3 vA = planesA[twinA->face].normal; + + bool isMinkowski; + { + // Two edges build a face on the Minkowski sum if the associated arcs AB and CD intersect on the Gauss map. + // The associated arcs are defined by the adjacent face normals of each edge. + float cba = b3Dot( uB, eA ); + float dba = b3Dot( vB, eA ); + float adc = -b3Dot( uA, eB ); + float bdc = -b3Dot( vA, eB ); + + isMinkowski = cba * dba < 0.0f && adc * bdc < 0.0f && cba * bdc > 0.0f; + } + + if ( isMinkowski ) + { + b3Vec3 centerA = hullA->center; + b3Vec3 centerB = b3TransformPoint( transformBtoA, hullB->center ); + float separation = b3EdgeEdgeSeparation( qA, eA, centerA, qB, eB, centerB ); + + if ( separation > maxSeparation ) + { + // Continues to find the maximum separating axis + maxSeparation = separation; + maxIndexA = indexA; + maxIndexB = indexB; + } + } + } + } + + return (b3EdgeQuery){ .separation = maxSeparation, .indexA = maxIndexA, .indexB = maxIndexB, }; } +// Reduce the manifold points to a maximum of 4 points. +// Note: this modifies the input point array to improve performance +static void b3ReduceManifoldPoints( b3LocalManifold* manifold, int capacity, b3LocalManifoldPoint* points, int count ) +{ + if ( capacity < 4 ) + { + return; + } + + if ( count <= 4 ) + { + for ( int i = 0; i < count; ++i ) + { + manifold->points[i] = points[i]; + } + + manifold->pointCount = count; + return; + } + + b3Vec3 normal = manifold->normal; + // float linearSlop = B3_LINEAR_SLOP; + float speculativeDistance = B3_SPECULATIVE_DISTANCE; + float tolSqr = speculativeDistance * speculativeDistance; + + // This bias is very important for contact point consistency across time steps. + // It creates a pecking order to avoid flickering between candidates with similar scores. + float bias = 0.95f; + + // Step 1: find extreme point that is touching + int bestIndex = B3_NULL_INDEX; + float bestScore = -FLT_MAX; + + // Arbitrary tangent direction + // b3Vec3 perp1 = b3Perp( normal ); + // b3Vec3 perp2 = b3Cross( perp1, normal ); + // b3Vec3 searchDirection = -0.4535961214255773f * perp1 + 0.8912073600614354f * perp2; + b3Vec3 searchDirection = b3ArbitraryPerp( normal ); + for ( int index = 0; index < count; ++index ) + { + b3LocalManifoldPoint* pt = points + index; + + if ( pt->separation > speculativeDistance ) + { + continue; + } + + // The deeper the better + float score = -pt->separation + b3Dot( searchDirection, pt->point ); + if ( bias * score > bestScore ) + { + bestIndex = index; + bestScore = score; + } + } + + B3_VALIDATE( 0 <= bestIndex && bestIndex < count ); + if ( bestIndex == B3_NULL_INDEX ) + { + manifold->pointCount = 0; + return; + } + + manifold->points[0] = points[bestIndex]; + manifold->pointCount = 1; + + // Remove best point from array + points[bestIndex] = points[count - 1]; + count -= 1; + + b3Vec3 a = manifold->points[0].point; + + // Step 2: Find farthest point in 2D + bestScore = 0.0f; + bestIndex = B3_NULL_INDEX; + float maxDistanceSquared = 0.0f; + + for ( int index = 0; index < count; ++index ) + { + b3Vec3 p = points[index].point; + b3Vec3 d = b3Sub( p, a ); + b3Vec3 v = b3MulSub( d, b3Dot( d, normal ), normal ); + float distanceSquared = b3LengthSquared( v ); + maxDistanceSquared = b3MaxFloat( maxDistanceSquared, distanceSquared ); + float separation = b3MaxFloat( 0.0f, -points[index].separation ); + float score = distanceSquared + 4.0f * separation * separation; + if ( bias * score > bestScore ) + { + bestScore = score; + bestIndex = index; + } + } + + if ( bestScore < tolSqr ) + { + return; + } + + B3_ASSERT( 0 <= bestIndex && bestIndex < count ); + manifold->points[1] = points[bestIndex]; + manifold->pointCount = 2; + + // Remove best point from array + points[bestIndex] = points[count - 1]; + count -= 1; + + b3Vec3 b = manifold->points[1].point; + + // Step 3: Find the point with the maximum triangular area + bestScore = tolSqr; + bestIndex = B3_NULL_INDEX; + float bestSignedArea = 0.0f; + b3Vec3 ba = b3Sub( b, a ); + for ( int index = 0; index < count; ++index ) + { + b3Vec3 p = points[index].point; + float signedArea = b3Dot( normal, b3Cross( ba, b3Sub( p, a ) ) ); + float score = b3AbsFloat( signedArea ); + if ( bias * score >= bestScore ) + { + bestScore = score; + bestIndex = index; + bestSignedArea = signedArea; + } + } + + if ( bestIndex == B3_NULL_INDEX ) + { + return; + } + + B3_ASSERT( bestIndex != B3_NULL_INDEX ); + + manifold->points[2] = points[bestIndex]; + manifold->pointCount = 3; + points[bestIndex] = points[count - 1]; + count -= 1; + + b3Vec3 c = manifold->points[2].point; + + // Step 4: get the point that adds the most area outside the current triangle + bestScore = tolSqr; + bestIndex = B3_NULL_INDEX; + float sign = bestSignedArea < 0.0f ? -1.0f : 1.0f; + for ( int index = 0; index < count; ++index ) + { + b3Vec3 p = points[index].point; + float u1 = sign * b3Dot( normal, b3Cross( b3Sub( p, a ), ba ) ); + float u2 = sign * b3Dot( normal, b3Cross( b3Sub( p, b ), b3Sub( c, b ) ) ); + float u3 = sign * b3Dot( normal, b3Cross( b3Sub( p, c ), b3Sub( a, c ) ) ); + float score = b3MaxFloat( u1, b3MaxFloat( u2, u3 ) ); + + if ( bias * score > bestScore ) + { + bestScore = score; + bestIndex = index; + } + } + + if ( bestIndex != B3_NULL_INDEX ) + { + manifold->points[manifold->pointCount] = points[bestIndex]; + manifold->pointCount += 1; + } +} + void b3CollideSpheres( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA, const b3Sphere* sphereB, b3Transform transformBtoA ) { @@ -218,11 +487,10 @@ void b3CollideSpheres( b3LocalManifold* manifold, int capacity, const b3Sphere* b3Vec3 center2 = b3TransformPoint( transformBtoA, sphereB->center ); float totalRadius = sphereA->radius + sphereB->radius; - float maxDistance = totalRadius + B3_SPECULATIVE_DISTANCE; b3Vec3 offset = b3Sub( center2, center1 ); float distanceSq = b3LengthSquared( offset ); - if ( distanceSq > maxDistance * maxDistance ) + if ( distanceSq > totalRadius * totalRadius ) { // We found a separating axis return; @@ -266,13 +534,12 @@ void b3CollideCapsuleAndSphere( b3LocalManifold* manifold, int capacity, const b b3Vec3 center2 = capsuleA->center2; float totalRadius = sphereB->radius + capsuleA->radius; - float maxDistance = totalRadius + B3_SPECULATIVE_DISTANCE; b3Vec3 closestPoint = b3PointToSegmentDistance( center1, center2, center ); b3Vec3 offset = b3Sub( center, closestPoint ); float distanceSq = b3LengthSquared( offset ); - if ( distanceSq > maxDistance * maxDistance ) + if ( distanceSq > totalRadius * totalRadius ) { // We found a separating axis return; @@ -543,13 +810,13 @@ void b3CollideCapsules( b3LocalManifold* manifold, int capacity, const b3Capsule } static bool b3BuildHullFaceAndCapsuleContact( b3LocalManifold* manifold, const b3HullData* hullA, const b3Capsule* capsuleB, - b3Transform transformBtoA, b3SeparatingAxis query ) + b3Transform transformBtoA, b3FaceQuery query ) { // Work in shapeA coordinates const b3Plane* planes = b3GetHullPlanes( hullA ); // Clip the capsule edge against the side planes of the reference face - int refFace = query.indexA; + int refFace = query.faceIndex; b3Plane refPlane = planes[refFace]; b3ClipVertex segmentB[2]; @@ -596,8 +863,21 @@ static bool b3BuildHullFaceAndCapsuleContact( b3LocalManifold* manifold, const b return false; } +static inline float b3DeepestPointSeparation( const b3LocalManifold* manifold ) +{ + // Deepest point + float minSeparation = FLT_MAX; + int pointCount = manifold->pointCount; + for ( int i = 0; i < pointCount; ++i ) + { + minSeparation = b3MinFloat( minSeparation, manifold->points[i].separation ); + } + + return minSeparation; +} + static bool b3BuildHullAndCapsuleEdgeContact( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, - const b3Capsule* capsuleB, b3Transform transformBtoA, b3SeparatingAxis query ) + const b3Capsule* capsuleB, b3Transform transformBtoA, b3EdgeQuery query ) { if ( capacity < 1 ) { @@ -615,11 +895,19 @@ static bool b3BuildHullAndCapsuleEdgeContact( b3LocalManifold* manifold, int cap const b3HullHalfEdge* edge2 = edges + query.indexB; const b3HullHalfEdge* twin2 = edges + edge2->twin; + b3Vec3 ch = hullA->center; b3Vec3 ph = points[edge2->origin]; b3Vec3 qh = points[twin2->origin]; b3Vec3 eh = b3Sub( qh, ph ); - b3Vec3 normal = query.normal; + b3Vec3 normal = b3Cross( ec, eh ); + normal = b3Normalize( normal ); + + // Normal should point outward from hull + if ( b3Dot( normal, b3Sub( ph, ch ) ) < 0.0f ) + { + normal = b3Neg( normal ); + } b3SegmentDistanceResult result = b3LineDistance( ph, eh, pc, ec ); @@ -630,6 +918,7 @@ static bool b3BuildHullAndCapsuleEdgeContact( b3LocalManifold* manifold, int cap } b3Vec3 point = b3MulSV( 0.5f, b3Add( b3MulSub( result.point1, capsuleB->radius, normal ), result.point2 ) ); + float separation = b3Dot( normal, b3Sub( result.point2, result.point1 ) ); B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP ); @@ -742,14 +1031,14 @@ void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3H // Deep penetration - b3SeparatingAxis faceQuery = b3QueryFaceDirectionHullAndCapsule( hullA, capsuleB, transformBtoA ); + b3FaceQuery faceQuery = b3QueryFaceDirectionHullAndCapsule( hullA, capsuleB, transformBtoA ); if ( faceQuery.separation > capsuleB->radius ) { // We found a separating axis return; } - b3SeparatingAxis edgeQuery = b3QueryEdgeDirectionHullAndCapsule( hullA, capsuleB, transformBtoA ); + b3EdgeQuery edgeQuery = b3QueryEdgeDirectionHullAndCapsule( hullA, capsuleB, transformBtoA ); if ( edgeQuery.separation > capsuleB->radius ) { // We found a separating axis @@ -759,253 +1048,27 @@ void b3CollideHullAndCapsule( b3LocalManifold* manifold, int capacity, const b3H // Create face contact float faceSeparation = faceQuery.separation - capsuleB->radius; b3BuildHullFaceAndCapsuleContact( manifold, hullA, capsuleB, transformBtoA, faceQuery ); - B3_VALIDATE( manifold->pointCount == 0 || manifold->pointCount == 2 ); - if ( manifold->pointCount == 2 ) + if ( manifold->pointCount > 1 ) { - // This becomes the clipped separation. - faceSeparation = b3MinFloat( manifold->points[0].separation, manifold->points[1].separation ); - } - - // Is there a valid edge-edge axis? - if ( edgeQuery.indexA == B3_NULL_INDEX ) - { - return; + // If ( Out.PointCount <= 1 ) -> Compare with unclipped separation + // If ( Out.PointCount > 1 ) -> Be aggressive and compare with clipped separation + // Face contact can be empty if it does not realize the axis of minimum penetration + faceSeparation = b3DeepestPointSeparation( manifold ); } + B3_VALIDATE( faceSeparation <= 0.0f ); // Face contact can be empty if it does not realize the axis of minimum penetration. // Create edge contact if face contact fails or edge contact is significantly better! - float linearSlop = B3_LINEAR_SLOP; + const float kRelEdgeTolerance = 0.90f; + const float kAbsTolerance = 0.5f * B3_LINEAR_SLOP; float edgeSeparation = edgeQuery.separation - capsuleB->radius; - if ( manifold->pointCount == 0 || edgeSeparation > faceSeparation + linearSlop ) + if ( manifold->pointCount == 0 || edgeSeparation > kRelEdgeTolerance * faceSeparation + kAbsTolerance ) { // Edge contact b3BuildHullAndCapsuleEdgeContact( manifold, capacity, hullA, capsuleB, transformBtoA, edgeQuery ); } } -_Static_assert( B3_MAX_MANIFOLD_POINTS >= 4, "must be 4 or more" ); - -#if B3_MAX_MANIFOLD_POINTS == 4 - -// Reduce the manifold points to a maximum of 4 points. -// Note: this modifies the input point array to improve performance -static void b3ReduceManifoldPoints( b3LocalManifold* manifold, int capacity, b3LocalManifoldPoint* points, int count ) -{ - if ( capacity < 4 ) - { - return; - } - - if ( count <= 4 ) - { - for ( int i = 0; i < count; ++i ) - { - manifold->points[i] = points[i]; - } - - manifold->pointCount = count; - return; - } - - b3Vec3 normal = manifold->normal; - // float linearSlop = B3_LINEAR_SLOP; - float speculativeDistance = B3_SPECULATIVE_DISTANCE; - float tolSqr = speculativeDistance * speculativeDistance; - - // This bias is very important for contact point consistency across time steps. - // It creates a pecking order to avoid flickering between candidates with similar scores. - float bias = 0.95f; - - // Step 1: find extreme point that is touching - int bestIndex = B3_NULL_INDEX; - float bestScore = -FLT_MAX; - - // Arbitrary tangent direction - // b3Vec3 perp1 = b3Perp( normal ); - // b3Vec3 perp2 = b3Cross( perp1, normal ); - // b3Vec3 searchDirection = -0.4535961214255773f * perp1 + 0.8912073600614354f * perp2; - b3Vec3 searchDirection = b3ArbitraryPerp( normal ); - for ( int index = 0; index < count; ++index ) - { - b3LocalManifoldPoint* pt = points + index; - - if ( pt->separation > speculativeDistance ) - { - continue; - } - - // The deeper the better - float score = -pt->separation + b3Dot( searchDirection, pt->point ); - if ( bias * score > bestScore ) - { - bestIndex = index; - bestScore = score; - } - } - - B3_VALIDATE( 0 <= bestIndex && bestIndex < count ); - if ( bestIndex == B3_NULL_INDEX ) - { - manifold->pointCount = 0; - return; - } - - manifold->points[0] = points[bestIndex]; - manifold->pointCount = 1; - - // Remove best point from array - points[bestIndex] = points[count - 1]; - count -= 1; - - b3Vec3 a = manifold->points[0].point; - - // Step 2: Find farthest point in 2D - bestScore = 0.0f; - bestIndex = B3_NULL_INDEX; - - for ( int index = 0; index < count; ++index ) - { - b3Vec3 p = points[index].point; - b3Vec3 d = b3Sub( p, a ); - b3Vec3 v = b3MulSub( d, b3Dot( d, normal ), normal ); - float distanceSquared = b3LengthSquared( v ); - float separation = b3MaxFloat( 0.0f, -points[index].separation ); - float score = distanceSquared + 4.0f * separation * separation; - if ( bias * score > bestScore ) - { - bestScore = score; - bestIndex = index; - } - } - - if ( bestScore < tolSqr ) - { - return; - } - - B3_ASSERT( 0 <= bestIndex && bestIndex < count ); - manifold->points[1] = points[bestIndex]; - manifold->pointCount = 2; - - // Remove best point from array - points[bestIndex] = points[count - 1]; - count -= 1; - - b3Vec3 b = manifold->points[1].point; - - // Step 3: Find the point with the maximum triangular area - bestScore = tolSqr; - bestIndex = B3_NULL_INDEX; - float bestSignedArea = 0.0f; - b3Vec3 ba = b3Sub( b, a ); - for ( int index = 0; index < count; ++index ) - { - b3Vec3 p = points[index].point; - float signedArea = b3Dot( normal, b3Cross( ba, b3Sub( p, a ) ) ); - float score = b3AbsFloat( signedArea ); - if ( bias * score >= bestScore ) - { - bestScore = score; - bestIndex = index; - bestSignedArea = signedArea; - } - } - - if ( bestIndex == B3_NULL_INDEX ) - { - return; - } - - B3_ASSERT( bestIndex != B3_NULL_INDEX ); - - manifold->points[2] = points[bestIndex]; - manifold->pointCount = 3; - points[bestIndex] = points[count - 1]; - count -= 1; - - b3Vec3 c = manifold->points[2].point; - - // Step 4: get the point that adds the most area outside the current triangle - bestScore = tolSqr; - bestIndex = B3_NULL_INDEX; - float sign = bestSignedArea < 0.0f ? -1.0f : 1.0f; - for ( int index = 0; index < count; ++index ) - { - b3Vec3 p = points[index].point; - float u1 = sign * b3Dot( normal, b3Cross( b3Sub( p, a ), ba ) ); - float u2 = sign * b3Dot( normal, b3Cross( b3Sub( p, b ), b3Sub( c, b ) ) ); - float u3 = sign * b3Dot( normal, b3Cross( b3Sub( p, c ), b3Sub( a, c ) ) ); - float score = b3MaxFloat( u1, b3MaxFloat( u2, u3 ) ); - - if ( bias * score > bestScore ) - { - bestScore = score; - bestIndex = index; - } - } - - if ( bestIndex != B3_NULL_INDEX ) - { - manifold->points[manifold->pointCount] = points[bestIndex]; - manifold->pointCount += 1; - } -} - -#else - -static void b3ReduceManifoldPoints( b3LocalManifold* manifold, int capacity, b3LocalManifoldPoint* points, int count ) -{ - if ( capacity < 4 ) - { - return; - } - - B3_ASSERT( count <= B3_MAX_CLIP_POINTS ); - - int target = b3MinInt( capacity, B3_MAX_MANIFOLD_POINTS ); - - if ( count <= target ) - { - for ( int i = 0; i < count; ++i ) - { - manifold->points[i] = points[i]; - } - - manifold->pointCount = count; - return; - } - - b3Vec3 normal = manifold->normal; - b3Vec3 u = b3Perp( normal ); - b3Vec3 v = b3Cross( normal, u ); - b3Vec3 origin = points[0].point; - - b3Point2D pts[B3_MAX_CLIP_POINTS]; - for ( int i = 0; i < count; ++i ) - { - b3Vec3 d = b3Sub( points[i].point, origin ); - pts[i].p = (b3Vec2){ b3Dot( d, u ), b3Dot( d, v ) }; - pts[i].separation = points[i].separation; - pts[i].originalIndex = i; - } - - b3Point2D hull[2 * B3_MAX_CLIP_POINTS]; - int hullCount = b3Hull2D( pts, count, hull, 0 ); - int finalCount = b3SimplifyHull2D( hull, hullCount, target ); - B3_ASSERT( 0 < finalCount && finalCount <= target ); - - for ( int i = 0; i < finalCount; ++i ) - { - int index = hull[i].originalIndex; - B3_ASSERT( 0 <= index && index < count ); - manifold->points[i] = points[index]; - } - - manifold->pointCount = finalCount; -} - -#endif - static int b3BuildPolygon( b3ClipVertex* out, b3Transform transform, const b3HullData* hull, int incFace, b3Plane refPlane ) { const b3HullFace* faces = b3GetHullFaces( hull ); @@ -1045,25 +1108,20 @@ static int b3BuildPolygon( b3ClipVertex* out, b3Transform transform, const b3Hul } static bool b3BuildFaceAContact( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SeparatingAxis query, b3SATCache* cache ) + b3Transform transformBtoA, b3FaceQuery query, b3SATCache* cache ) { - B3_ASSERT( capacity > 0 ); - B3_VALIDATE( query.type == b3_faceAxisA ); - B3_VALIDATE( 0 <= query.indexA && query.indexA < hullA->faceCount ); - B3_VALIDATE( 0 <= query.indexB && query.indexB < hullB->vertexCount ); - const b3HullFace* facesA = b3GetHullFaces( hullA ); const b3HullHalfEdge* edgesA = b3GetHullEdges( hullA ); const b3Plane* planesA = b3GetHullPlanes( hullA ); const b3Vec3* pointsA = b3GetHullPoints( hullA ); // Reference face - int refFace = query.indexA; + int refFace = query.faceIndex; b3Plane refPlane = planesA[refFace]; // Find incident face b3Vec3 refNormalInB = b3InvRotateVector( transformBtoA.q, refPlane.normal ); - int incFace = b3FindIncidentFace( hullB, refNormalInB, query.indexB ); + int incFace = b3FindIncidentFace( hullB, refNormalInB, query.vertexIndex ); // Build clip polygon from incident face in frame A b3ClipVertex buffer1[B3_MAX_CLIP_POINTS], buffer2[B3_MAX_CLIP_POINTS]; @@ -1140,30 +1198,19 @@ static bool b3BuildFaceAContact( b3LocalManifold* manifold, int capacity, const // Save cache cache->separation = minSeparation; cache->type = (uint8_t)b3_faceAxisA; - cache->indexA = (uint8_t)query.indexA; - cache->indexB = (uint8_t)query.indexB; + cache->indexA = (uint8_t)query.faceIndex; + cache->indexB = (uint8_t)query.vertexIndex; return true; } static bool b3BuildFaceBContact( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SeparatingAxis query, b3SATCache* cache ) + b3Transform transformBtoA, b3FaceQuery query, b3SATCache* cache ) { - B3_VALIDATE( query.type == b3_faceAxisB ); - b3Transform transformAtoB = b3InvertTransform( transformBtoA ); - b3SeparatingAxis flippedQuery = { - .normal = b3Neg( query.normal ), - .separation = query.separation, - .indexA = query.indexB, - .indexB = query.indexA, - .type = b3_faceAxisA, - }; - - bool touching = b3BuildFaceAContact( manifold, capacity, hullB, hullA, transformAtoB, flippedQuery, cache ); + bool touching = b3BuildFaceAContact( manifold, capacity, hullB, hullA, transformAtoB, query, cache ); if ( touching == false ) { - *cache = (b3SATCache){ 0 }; return false; } @@ -1172,6 +1219,9 @@ static bool b3BuildFaceBContact( b3LocalManifold* manifold, int capacity, const // Transform and flip normal so it points from A to B, even though the B has the reference face. manifold->normal = b3Neg( b3MulMV( matrix, manifold->normal ) ); + cache->type = (uint8_t)b3_faceAxisB; + cache->indexA = (uint8_t)query.vertexIndex; + cache->indexB = (uint8_t)query.faceIndex; // Transform points from frame B to frame A. // Also flip the pairs to ensure correct matches. @@ -1182,20 +1232,12 @@ static bool b3BuildFaceBContact( b3LocalManifold* manifold, int capacity, const pt->pair = b3FlipPair( pt->pair ); } - cache->type = (uint8_t)b3_faceAxisB; - cache->indexA = (uint8_t)query.indexA; - cache->indexB = (uint8_t)query.indexB; - return true; } -static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SeparatingAxis query, b3SATCache* cache ) +static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hullA, const b3HullData* hullB, b3Transform transformBtoA, + b3EdgeQuery query, b3SATCache* cache ) { - B3_VALIDATE( query.type == b3_edgePairAxis ); - B3_VALIDATE( 0 <= query.indexA && query.indexA < hullA->edgeCount ); - B3_VALIDATE( 0 <= query.indexB && query.indexB < hullB->edgeCount ); - // Work in shapeA coordinates const b3HullHalfEdge* edgesA = b3GetHullEdges( hullA ); const b3Vec3* pointsA = b3GetHullPoints( hullA ); @@ -1207,6 +1249,7 @@ static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hul const b3HullHalfEdge* edgeA = edgesA + query.indexA; const b3HullHalfEdge* twinA = edgesA + edgeA->twin; + b3Vec3 centerA = hullA->center; b3Vec3 pA = pointsA[edgeA->origin]; b3Vec3 qA = pointsA[twinA->origin]; b3Vec3 eA = b3Sub( qA, pA ); @@ -1217,7 +1260,14 @@ static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hul b3Vec3 qB = b3TransformPoint( transformBtoA, pointsB[twinB->origin] ); b3Vec3 eB = b3Sub( qB, pB ); - b3Vec3 normal = query.normal; + b3Vec3 normal = b3Cross( eA, eB ); + normal = b3Normalize( normal ); + + if ( b3Dot( normal, b3Sub( pA, centerA ) ) < 0.0f ) + { + normal = b3Neg( normal ); + } + b3SegmentDistanceResult result = b3LineDistance( pA, eA, pB, eB ); if ( b3IsWithinSegments( &result ) == false ) @@ -1228,6 +1278,10 @@ static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hul // This can slide off the end from caching float separation = b3Dot( normal, b3Sub( result.point2, result.point1 ) ); + + // todo I suspect this could trip if the cache becomes invalid + // B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP ); + b3Vec3 point = b3MulSV( 0.5f, b3Add( result.point1, result.point2 ) ); // Result in frame A @@ -1248,28 +1302,8 @@ static bool b3BuildEdgeContact( b3LocalManifold* manifold, const b3HullData* hul return true; } -b3AxisQuery b3ComputeSeparatingAxisAtWidth( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn, - int simdWidth ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - if ( simdWidth == 8 ) - { - return b3ComputeSeparatingAxisW8( hullA, hullB, xfB, earlyReturn ); - } -#else - B3_UNUSED( simdWidth ); -#endif - - return b3ComputeSeparatingAxisW4( hullA, hullB, xfB, earlyReturn ); -} - -b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn ) -{ - return b3ComputeSeparatingAxisAtWidth( hullA, hullB, xfB, earlyReturn, b3GetSIMDWidth() ); -} - -void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SATCache* cache, int simdWidth ) +void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, b3Transform transformBtoA, + b3SATCache* cache ) { manifold->pointCount = 0; @@ -1290,12 +1324,11 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul const b3Plane* planesB = b3GetHullPlanes( hullB ); const b3Vec3* pointsB = b3GetHullPoints( hullB ); - cache->hit = 0; - // Attempt to use the cache to speed up collision switch ( cache->type ) { case b3_invalidAxis: + *cache = (b3SATCache){ 0 }; break; case b3_faceAxisA: @@ -1305,7 +1338,6 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul // Check for separation using cached face b3Plane plane = planesA[cache->indexA]; b3Vec3 searchDirectionInB = b3Neg( b3InvRotateVector( transformBtoA.q, plane.normal ) ); - int vertexIndex = b3FindHullSupportVertex( hullB, searchDirectionInB ); b3Vec3 support = b3TransformPoint( transformBtoA, pointsB[vertexIndex] ); float separation = b3PlaneSeparation( plane, support ); @@ -1313,25 +1345,24 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul if ( separation >= speculativeDistance ) { // Cache hit, shapes are separated - cache->hit = 1; return; } - // Attempt face contact using cached feature - b3SeparatingAxis faceQuery; - faceQuery.normal = plane.normal; - faceQuery.separation = 0.0f; - faceQuery.indexA = cache->indexA; - faceQuery.indexB = vertexIndex; - faceQuery.type = b3_faceAxisA; - - b3SATCache localCache = { 0 }; - bool touching = b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, &localCache ); - if ( touching == true && b3AbsFloat( cache->separation - localCache.separation ) < linearSlop ) + // if ( cache->separation < speculativeDistance ) { - // Cache hit, contact points generated - cache->hit = 1; - return; + // Attempt face contact using cached feature + b3FaceQuery faceQuery; + faceQuery.separation = 0.0f; + faceQuery.faceIndex = cache->indexA; + faceQuery.vertexIndex = vertexIndex; + + b3SATCache localCache = { 0 }; + bool touching = b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, &localCache ); + if ( touching == true && b3AbsFloat( cache->separation - localCache.separation ) < linearSlop ) + { + // Cache hit, contact points generated + return; + } } } break; @@ -1343,8 +1374,6 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul // Check for separation using cached face b3Plane plane = planesB[cache->indexB]; b3Vec3 searchDirectionInA = b3Neg( b3RotateVector( transformBtoA.q, plane.normal ) ); - - // todo use b3GetSupportWide int vertexIndex = b3FindHullSupportVertex( hullA, searchDirectionInA ); b3Vec3 support = b3InvTransformPoint( transformBtoA, pointsA[vertexIndex] ); float separation = b3PlaneSeparation( plane, support ); @@ -1352,100 +1381,85 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul if ( separation >= speculativeDistance ) { // Cache hit, shapes are separated - cache->hit = 1; return; } - // Attempt face contact using cached feature - b3SeparatingAxis faceQuery; - faceQuery.normal = b3Neg( plane.normal ); - faceQuery.separation = 0.0f; - faceQuery.indexA = vertexIndex; - faceQuery.indexB = cache->indexB; - faceQuery.type = b3_faceAxisB; - - b3SATCache localCache = { 0 }; - bool touching = b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, &localCache ); - if ( touching == true && b3AbsFloat( cache->separation - localCache.separation ) < linearSlop ) + // if ( cache->separation < speculativeDistance ) { - // Cache hit, contact points generated - cache->hit = 1; - return; + // Attempt face contact using cached feature + b3FaceQuery faceQuery; + faceQuery.separation = 0.0f; + faceQuery.faceIndex = cache->indexB; + faceQuery.vertexIndex = vertexIndex; + + b3SATCache localCache = { 0 }; + bool touching = b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, &localCache ); + if ( touching == true && b3AbsFloat( cache->separation - localCache.separation ) < linearSlop ) + { + // Cache hit, contact points generated + return; + } } } break; case b3_edgePairAxis: { - int indexA = cache->indexA; - const b3HullHalfEdge* edge1 = edgesA + indexA; - const b3HullHalfEdge* twin1 = edgesA + indexA + 1; - B3_ASSERT( edge1->twin == indexA + 1 && twin1->twin == indexA ); + int index1 = cache->indexA; + const b3HullHalfEdge* edge1 = edgesA + index1; + const b3HullHalfEdge* twin1 = edgesA + index1 + 1; + B3_ASSERT( edge1->twin == index1 + 1 && twin1->twin == index1 ); - b3Vec3 pA = pointsA[edge1->origin]; - b3Vec3 qA = pointsA[twin1->origin]; - b3Vec3 eA = b3Sub( qA, pA ); + b3Vec3 p1 = pointsA[edge1->origin]; + b3Vec3 q1 = pointsA[twin1->origin]; + b3Vec3 e1 = b3Sub( q1, p1 ); - b3Vec3 uA = planesA[edge1->face].normal; - b3Vec3 vA = planesA[twin1->face].normal; + b3Vec3 u1 = planesA[edge1->face].normal; + b3Vec3 v1 = planesA[twin1->face].normal; - int indexB = cache->indexB; - const b3HullHalfEdge* edge2 = edgesB + indexB; - const b3HullHalfEdge* twin2 = edgesB + indexB + 1; - B3_ASSERT( edge2->twin == indexB + 1 && twin2->twin == indexB ); + int index2 = cache->indexB; + const b3HullHalfEdge* edge2 = edgesB + index2; + const b3HullHalfEdge* twin2 = edgesB + index2 + 1; + B3_ASSERT( edge2->twin == index2 + 1 && twin2->twin == index2 ); - b3Vec3 pB = b3TransformPoint( transformBtoA, pointsB[edge2->origin] ); - b3Vec3 qB = b3TransformPoint( transformBtoA, pointsB[twin2->origin] ); - b3Vec3 eB = b3Sub( qB, pB ); + b3Vec3 p2 = b3TransformPoint( transformBtoA, pointsB[edge2->origin] ); + b3Vec3 q2 = b3TransformPoint( transformBtoA, pointsB[twin2->origin] ); + b3Vec3 e2 = b3Sub( q2, p2 ); - b3Vec3 uB = b3RotateVector( transformBtoA.q, planesB[edge2->face].normal ); - b3Vec3 vB = b3RotateVector( transformBtoA.q, planesB[twin2->face].normal ); + b3Vec3 u2 = b3RotateVector( transformBtoA.q, planesB[edge2->face].normal ); + b3Vec3 v2 = b3RotateVector( transformBtoA.q, planesB[twin2->face].normal ); // flipping the signs of u2 and v2 // cross(v2, u2) == cross(-v2, -u2) // so we still use -e2 // but we can also use e1 = cross(u1, v1) and e2 = cross(u2, v2) - float cba = b3Dot( uB, eA ); - float dba = b3Dot( vB, eA ); - float adc = -b3Dot( uA, eB ); - float bdc = -b3Dot( vA, eB ); - - if ( cba * dba < 0.0f && adc * bdc < 0.0f && cba * bdc > 0.0f ) + bool isMinkowski = b3IsMinkowskiFace( u1, v1, e1, b3Neg( u2 ), b3Neg( v2 ), e2 ); + if ( isMinkowski == true ) { - // Avoid nearly parallel edges that may lead to invalid separation values at the noise floor. - float squaredTolerance = B3_PARALLEL_EDGE_TOL * B3_PARALLEL_EDGE_TOL; - if ( b3MaxFloat( cba * cba, dba * dba ) >= squaredTolerance * b3LengthSquared( eA ) ) + // Transform reference center of the first hull into local space of the second hull + b3Vec3 c1 = hullA->center; + b3Vec3 c2 = b3TransformPoint( transformBtoA, hullB->center ); + + float separation = b3EdgeEdgeSeparation( p1, e1, c1, p2, e2, c2 ); + if ( separation > speculativeDistance ) { - // Transform reference center of the first hull into local space of the second hull - float t = cba / ( cba - dba ); - b3Vec3 axis = b3Lerp( uB, vB, t ); - B3_VALIDATE( b3LengthSquared( axis ) > 1000.0f * FLT_MIN ); - axis = b3Normalize( axis ); - float separation = b3Dot( axis, b3Sub( qA, qB ) ); - - if ( separation > speculativeDistance ) - { - // Cache hit, shapes are separated - cache->hit = 1; - return; - } + // Cache hit, shapes are separated + return; + } + // if ( cache->separation <= speculativeDistance ) + { // Try to rebuild contact from last features - b3SeparatingAxis edgeQuery = { 0 }; - edgeQuery.normal = b3Neg( axis ); - edgeQuery.separation = 0.0f; + b3EdgeQuery edgeQuery; edgeQuery.indexA = cache->indexA; edgeQuery.indexB = cache->indexB; - edgeQuery.type = b3_edgePairAxis; + edgeQuery.separation = 0.0f; b3SATCache localCache = { 0 }; bool touching = b3BuildEdgeContact( manifold, hullA, hullB, transformBtoA, edgeQuery, &localCache ); - - // This separation tolerance may have a big impact on performance in some benchmarks. if ( touching && b3AbsFloat( cache->separation - localCache.separation ) < linearSlop ) { // Cache hit, contact point generated - cache->hit = 1; return; } } @@ -1456,26 +1470,23 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul // This case is for testing case b3_manualFaceAxisA: { - b3AxisQuery axisQuery = b3ComputeSeparatingAxisAtWidth( hullA, hullB, transformBtoA, false, simdWidth ); - b3SeparatingAxis faceQuery = axisQuery.faceA; - b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, cache ); + b3FaceQuery faceQueryA = b3QueryFaceDirections( hullA, hullB, transformBtoA ); + b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQueryA, cache ); return; } // This case is for testing case b3_manualFaceAxisB: { - b3AxisQuery axisQuery = b3ComputeSeparatingAxisAtWidth( hullA, hullB, transformBtoA, false, simdWidth ); - b3SeparatingAxis faceQuery = axisQuery.faceB; - b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, cache ); + b3FaceQuery faceQueryB = b3QueryFaceDirections( hullB, hullA, b3InvertTransform( transformBtoA ) ); + b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQueryB, cache ); return; } // This case is for testing case b3_manualEdgePairAxis: { - b3AxisQuery axisQuery = b3ComputeSeparatingAxisAtWidth( hullA, hullB, transformBtoA, false, simdWidth ); - b3SeparatingAxis edgeQuery = axisQuery.edge; + b3EdgeQuery edgeQuery = b3QueryEdgeDirections( hullA, hullB, transformBtoA ); if ( edgeQuery.indexA != B3_NULL_INDEX ) { b3BuildEdgeContact( manifold, hullA, hullB, transformBtoA, edgeQuery, cache ); @@ -1491,98 +1502,92 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul manifold->pointCount = 0; *cache = (b3SATCache){ 0 }; - b3AxisQuery axisQuery = b3ComputeSeparatingAxisAtWidth( hullA, hullB, transformBtoA, true, simdWidth ); - - if ( axisQuery.separatedFeature != b3_invalidAxis ) + // Find axis of minimum penetration + b3FaceQuery faceQueryA = b3QueryFaceDirections( hullA, hullB, transformBtoA ); + if ( faceQueryA.separation > speculativeDistance ) { - // We found a separating axis - cache->type = axisQuery.separatedFeature; + B3_ASSERT( faceQueryA.faceIndex < hullA->faceCount ); + B3_ASSERT( faceQueryA.vertexIndex < hullB->vertexCount ); - if ( axisQuery.separatedFeature == b3_faceAxisA ) - { - B3_VALIDATE( axisQuery.faceA.separation > speculativeDistance ); - cache->separation = axisQuery.faceA.separation; - cache->indexA = (uint8_t)axisQuery.faceA.indexA; - cache->indexB = (uint8_t)axisQuery.faceA.indexB; - } - else if ( axisQuery.separatedFeature == b3_faceAxisB ) - { - B3_VALIDATE( axisQuery.faceB.separation > speculativeDistance ); - cache->separation = axisQuery.faceB.separation; - cache->indexA = (uint8_t)axisQuery.faceB.indexA; - cache->indexB = (uint8_t)axisQuery.faceB.indexB; - } - else - { - B3_ASSERT( axisQuery.separatedFeature == b3_edgePairAxis ); - B3_VALIDATE( axisQuery.edge.separation > speculativeDistance ); - cache->separation = axisQuery.edge.separation; - cache->indexA = (uint8_t)axisQuery.edge.indexA; - cache->indexB = (uint8_t)axisQuery.edge.indexB; - } + // We found a separating axis + cache->separation = faceQueryA.separation; + cache->type = (uint8_t)b3_faceAxisA; + cache->indexA = (uint8_t)faceQueryA.faceIndex; + cache->indexB = (uint8_t)faceQueryA.vertexIndex; return; } - B3_VALIDATE( axisQuery.faceA.separation <= speculativeDistance || axisQuery.faceB.separation <= speculativeDistance || - axisQuery.edge.separation <= speculativeDistance ); - - if ( axisQuery.faceA.separation > axisQuery.faceB.separation ) + b3FaceQuery faceQueryB = b3QueryFaceDirections( hullB, hullA, b3InvertTransform( transformBtoA ) ); + if ( faceQueryB.separation > speculativeDistance ) { - b3SeparatingAxis faceQuery = axisQuery.faceA; - B3_VALIDATE( 0 <= faceQuery.indexA && faceQuery.indexA < hullA->faceCount ); - B3_VALIDATE( 0 <= faceQuery.indexB && faceQuery.indexB < hullB->vertexCount ); + B3_ASSERT( faceQueryB.faceIndex < hullB->faceCount ); + B3_ASSERT( faceQueryB.vertexIndex < hullA->vertexCount ); - // Face contact A - b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, cache ); + // We found a separating axis + cache->separation = faceQueryB.separation; + cache->type = (uint8_t)b3_faceAxisB; + cache->indexA = (uint8_t)faceQueryB.vertexIndex; + cache->indexB = (uint8_t)faceQueryB.faceIndex; + return; + } - B3_VALIDATE( cache->indexA < hullA->faceCount ); - B3_VALIDATE( cache->indexB < hullB->vertexCount ); + b3EdgeQuery edgeQuery = b3QueryEdgeDirections( hullA, hullB, transformBtoA ); + if ( edgeQuery.separation > speculativeDistance ) + { + // We found a separating axis + cache->separation = edgeQuery.separation; + cache->type = (uint8_t)b3_edgePairAxis; + cache->indexA = (uint8_t)edgeQuery.indexA; + cache->indexB = (uint8_t)edgeQuery.indexB; + return; + } + + // Always build a face contact (e.g. Jenga problem) + float faceSeparationA = faceQueryA.separation; + float faceSeparationB = faceQueryB.separation; + B3_VALIDATE( faceSeparationA <= speculativeDistance && faceSeparationB <= speculativeDistance ); + + if ( faceSeparationB > faceSeparationA + 0.5f * linearSlop ) + { + // Face contact B + b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQueryB, cache ); } else { - b3SeparatingAxis faceQuery = axisQuery.faceB; - B3_VALIDATE( 0 <= faceQuery.indexA && faceQuery.indexA < hullA->vertexCount ); - B3_VALIDATE( 0 <= faceQuery.indexB && faceQuery.indexB < hullB->faceCount ); - - // Face contact B - b3BuildFaceBContact( manifold, capacity, hullA, hullB, transformBtoA, faceQuery, cache ); - - B3_VALIDATE( cache->indexA < hullA->vertexCount ); - B3_VALIDATE( cache->indexB < hullB->faceCount ); + // Face contact A + b3BuildFaceAContact( manifold, capacity, hullA, hullB, transformBtoA, faceQueryA, cache ); } - b3SeparatingAxis edgeQuery = axisQuery.edge; - if ( edgeQuery.indexA == B3_NULL_INDEX ) { // There are no valid edge pairs (all edges parallel) return; } - float faceSeparation = b3MaxFloat( axisQuery.faceA.separation, axisQuery.faceB.separation ); - float clipSeparation = cache->separation; - float edgeTol = linearSlop; + float clippedFaceSeparation = cache->separation; - // Face contact can be empty if it is not the axis of maximum separation. It can also - // be empty in narrow cases in the speculative region. If that case was important then - // a GJK fallback would be used. So far it doesn't seem important. - // Create edge contact if face contact fails or edge contact is significantly better. - if ( ( manifold->pointCount == 0 && edgeQuery.separation > faceSeparation ) || - edgeQuery.separation > clipSeparation + edgeTol ) + B3_VALIDATE( edgeQuery.separation <= speculativeDistance ); + + // todo get rid of relative tolerance + const float kRelEdgeTolerance = 0.90f; + // const float kRelFaceTolerance = 0.98f; + const float kAbsTolerance = 0.5f * linearSlop; + + // Face contact can be empty if it does not realize the axis of minimum penetration. + // Create edge contact if face contact fails or edge contact is significantly better! + if ( manifold->pointCount == 0 || edgeQuery.separation > kRelEdgeTolerance * clippedFaceSeparation + kAbsTolerance ) { - B3_ASSERT( 0 <= edgeQuery.indexA && edgeQuery.indexA < hullA->edgeCount ); - B3_ASSERT( 0 <= edgeQuery.indexB && edgeQuery.indexB < hullB->edgeCount ); - // Edge contact b3LocalManifold edgeManifold = { 0 }; b3LocalManifoldPoint edgePoint = { 0 }; edgeManifold.points = &edgePoint; - b3SATCache edgeCache = { 0 }; - b3BuildEdgeContact( &edgeManifold, hullA, hullB, transformBtoA, edgeQuery, &edgeCache ); + b3BuildEdgeContact( &edgeManifold, hullA, hullB, transformBtoA, edgeQuery, cache ); + + // It is possible with speculation to have vertex-vertex collision that is missed by SAT. + // todo I doubt this backup scheme matters because I'm using the clipped face separation. + // B3_VALIDATE( edgeManifold.pointCount == 1 ); - // It is possible with speculation to have vertex-vertex collision that is missed by SAT, - // so edge contact yields no points. In that case perhaps the face contact has some points. if ( edgeManifold.pointCount == 1 ) { // Copy edge manifold out, being careful to preserve manifold point buffer. @@ -1590,13 +1595,6 @@ void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3Hul *manifold = edgeManifold; manifold->points = points; manifold->points[0] = edgePoint; - *cache = edgeCache; } } } - -void b3CollideHulls( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SATCache* cache ) -{ - b3CollideHullsAtWidth( manifold, capacity, hullA, hullB, transformBtoA, cache, b3GetSIMDWidth() ); -} diff --git a/src/convex_manifold_wide.inl b/src/convex_manifold_wide.inl deleted file mode 100644 index cbb293b..0000000 --- a/src/convex_manifold_wide.inl +++ /dev/null @@ -1,825 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "algorithm.h" -#include "hull.h" -#include "manifold.h" -#include "shape.h" -#include "simd.h" -#include "simd_wide.h" - -_Static_assert( B3_SIMD_WIDTH <= B3_HULL_SOA_PADDING, "hull SoA padding must cover the SIMD width" ); - -static inline int b3RoundUpToSIMDWidth( int count ) -{ - return ( count + B3_SIMD_WIDTH - 1 ) & ~( B3_SIMD_WIDTH - 1 ); -} - -// Transform a SoA point/normal stream (already split into X/Y/Z) by out = -(R*v (+t)). -// The inputs come straight from the hull's stored SoA arrays, so there's no transpose here. -static inline void b3NegativeTransformFromSoA( b3Matrix3 R, b3Vec3 p, const float* inX, const float* inY, const float* inZ, int n, - float* outX, float* outY, float* outZ, bool isPoint ) -{ - // row-column - b3Vec3W r0 = { b3SplatW( R.cx.x ), b3SplatW( R.cy.x ), b3SplatW( R.cz.x ) }; - b3Vec3W r1 = { b3SplatW( R.cx.y ), b3SplatW( R.cy.y ), b3SplatW( R.cz.y ) }; - b3Vec3W r2 = { b3SplatW( R.cx.z ), b3SplatW( R.cy.z ), b3SplatW( R.cz.z ) }; - - b3Vec3W t = { b3ZeroW(), b3ZeroW(), b3ZeroW() }; - if ( isPoint ) - { - t = b3SplatVW( p ); - } - - for ( int i = 0; i < n; i += B3_SIMD_WIDTH ) - { - b3Vec3W v = b3LoadVW( inX + i, inY + i, inZ + i ); - - // Rotate one vector per lane - b3Vec3W out = { b3DotW( r0, v ), b3DotW( r1, v ), b3DotW( r2, v ) }; - - if ( isPoint ) - { - out = b3AddVW( out, t ); - } - - b3StoreVW( outX + i, outY + i, outZ + i, b3NegVW( out ) ); - } -} - -_Static_assert( B3_MAX_HULL_VERTICES == 128, "must be 128" ); - -#define B3_HULL_BIT_COUNT 7 - -// SIMD support point calculation using a SoA vertex array padded with repeats of the first vertex -// to a multiple of 8. -// -// This minimizes (bias - dot), where the caller is expected to provide a bias that makes this always positive. -// It can be direction dependent. The bias should be just big enough to ensure the value is positive because -// an excessive bias causes a precision loss in the support calculation. -// -// The vertex index is embedded in the low B3_HULL_BIT_COUNT mantissa bits of the value. By minimizing a value that -// is always positive, the minimum carries the smallest index so that padded SoA values will never win. This is the -// purpose of using the bias instead of maximizing the dot directly. -// -// The support is then recomputed exactly as dot(normal, vertex), without the embedded index. -// todo consider using this for GJK -static inline void b3GetSupportWide( b3Vec3 normal, const float* vx, const float* vy, const float* vz, int n, float bias, - float* support, int* vertexIndex ) -{ - const b3Vec3W normalW = b3SplatVW( normal ); - const b3FloatW biasV = b3SplatW( bias ); - - // Start the minimum at a large value. - b3FloatW minValue = b3SplatW( INFINITY ); - - // Tail lanes hold vertex 0 with index bits >= vertexCount, so they never become the min value. - for ( int i = 0; i < n; i += B3_SIMD_WIDTH ) - { - b3Vec3W v = b3LoadVW( vx + i, vy + i, vz + i ); - b3FloatW d = b3DotW( normalW, v ); - - // This is always positive. - b3FloatW value = b3SubW( biasV, d ); - b3FloatW augmentedValue = b3EmbedIndexW( value, i, B3_HULL_BIT_COUNT ); - minValue = b3MinW( minValue, augmentedValue ); - } - - // One horizontal min, the winning lane's value and index bits ride through. - int vi = b3MinIndexW( minValue, B3_HULL_BIT_COUNT ); - - // Exact support for the chosen vertex. - *vertexIndex = vi; - - // Dot product - *support = normal.x * vx[vi] + normal.y * vy[vi] + normal.z * vz[vi]; -} - -static inline float b3GetFaceSeparation( b3Vec3 direction, float planeSeparation, const float* vx, const float* vy, - const float* vz, int n, b3Vec3 center, b3Vec3 extents, int* vertexIndex ) -{ - float bias = b3Dot( direction, center ) + 1.0625f * b3Dot( b3Abs( direction ), extents ); - float support; - b3GetSupportWide( direction, vx, vy, vz, n, bias, &support, vertexIndex ); - return planeSeparation - support; -} - -// Wide dot(n, d) for all face normals n of the hull, padded to the SIMD width. -static inline void b3GetFaceDots( const b3HullData* hull, b3Vec3 d, float* dots ) -{ - int faceStride = b3GetHullSoaStride( hull->faceCount ); - const float* nx = b3GetHullSoaNormals( hull ); - const float* ny = nx + faceStride; - const float* nz = ny + faceStride; - - b3Vec3W dW = b3SplatVW( d ); - - int wideFaceCount = b3RoundUpToSIMDWidth( hull->faceCount ); - for ( int i = 0; i < wideFaceCount; i += B3_SIMD_WIDTH ) - { - // dot product per lane - b3FloatW m = b3DotW( b3LoadVW( nx + i, ny + i, nz + i ), dW ); - b3StoreW( dots + i, m ); - } -} - -#define B3_PARALLEL_TOL 1e-4f - -// Inscribed sphere edge test. https://box2d.org/posts/2026/09/inscribed-spheres/ -// The implementation here is a mix of the versions from Cairn Overturf and Dirk Gregorius: -// https://gist.github.com/cairnc/dee7a2866da0709f2d9a77b6493b57b5 -// https://gist.github.com/dgregorius/e6751b5c00937cd21af63cba3c53c861 -// This benchmarks faster than the version from the blog post. -static inline int b3TestEdgeCandidateSorted( float a1, float a2, float c, float bound ) -{ - // We want to maximize - // - // f(t) = dot(d, nlerp(n1, n2, t)) - // - // over t in [0, 1], where - // - // a1 = dot(n1, d) - // a2 = dot(n2, d) - // c = dot(n1, n2). - // - // The maximum can occur either at an endpoint or at an interior - // critical point where f'(t) = 0. - - // Since the endpoint values are a1 and a2, only the larger endpoint - // needs to be tested against the bound. - float hi = b3MaxFloat( a1, a2 ); - float lo = b3MinFloat( a1, a2 ); - int exterior = hi >= bound; - - // Differentiating f(t) gives - // - // a2 - c*a1 - (1 - c)*(a1 + a2)*t - // f'(t) = -------------------------------------- - // ((1 - t)^2 + t^2 + 2*c*t*(1 - t))^(3/2) - // - // The denominator is positive and the numerator is linear in t. - // An interior maximum therefore requires - // - // f'(0) >= 0 -> a2 >= c*a1 - // f'(1) <= 0 -> a1 >= c*a2. - // - // After sorting these become - // - // hi >= c*lo - // lo >= c*hi. - // - // The second is always the stricter condition since - // - // (hi - c*lo) - (lo - c*hi) - // = (1 + c)*(hi - lo) >= 0. - // - // Thus both conditions reduce to u >= 0. - float u = lo - c * hi; - int maxIsInterior = u >= 0.0f; - - // Solving f'(t) = 0 and evaluating f(t) at tmax gives - // - // f(tmax)^2 = - // (a1^2 + a2^2 - 2*c*a1*a2) / (1 - c^2). - // - // After sorting, - // - // hi^2 + lo^2 - 2*c*hi*lo - // = hi^2*(1 - c^2) + u^2. - // - // Let s = 1 - c^2 and rearrange f(tmax) >= bound: - // - // u^2 >= (bound^2 - hi^2)*s. - float s = 1.0f - c * c; - float boundTerm = ( bound - hi ) * ( bound + hi ); - float lhs = u * u; - float rhs = boundTerm * s; - int maxBeatsBound = lhs >= rhs; - - // The interior expression contains 1 - c^2 in its denominator. - // When this approaches zero the arc is degenerate or ill-conditioned, - // so conservatively keep the edge as a candidate. - int nearlyParallel = s < B3_PARALLEL_TOL; - - int interior = maxIsInterior & ( maxBeatsBound | nearlyParallel ); - - return exterior | interior; -} - -// dot(n, otherCenter) - offset for all faces of the hull, padded to the SIMD width. -static inline void b3GetFacePlaneSeparations( const b3HullData* hull, b3Vec3 otherCenter, float* separations ) -{ - b3GetFaceDots( hull, otherCenter, separations ); - - const b3Plane* planes = b3GetHullPlanes( hull ); - int faceCount = hull->faceCount; - for ( int i = 0; i < faceCount; ++i ) - { - separations[i] -= planes[i].offset; - } -} - -// The number of edge pair tests needed to make the extra culling pass worthwhile. -#define B3_EDGE_PROBE_MIN_TESTS 10 - -// Re-test edge candidates against the plane separations of a probe point on the other hull -static inline int b3FilterEdgeCandidates( const b3HullData* hull, const float* planeSeparations, float bound, int* edgeIndices, - int count ) -{ - const b3HullHalfEdge* halfEdges = b3GetHullEdges( hull ); - const float* cosines = b3GetHullEdgeCosines( hull ); - int keptCount = 0; - - for ( int k = 0; k < count; ++k ) - { - int i = edgeIndices[k]; - int i1 = halfEdges[i].face; - int i2 = halfEdges[i + 1].face; - float c = cosines[i >> 1]; - edgeIndices[keptCount] = i; - keptCount += b3TestEdgeCandidateSorted( planeSeparations[i1], planeSeparations[i2], c, bound ); - } - - return keptCount; -} - -// Temporary abbreviations for convenience. -#define NE ( B3_MAX_HULL_EDGES + B3_SIMD_WIDTH ) -#define NF ( B3_MAX_HULL_FACES + B3_SIMD_WIDTH ) -#define NV ( B3_MAX_HULL_VERTICES + B3_SIMD_WIDTH ) - -// SIMD separating axis test based on an implementation developed by Cairn Overturf. -// See his article: https://cairnc.github.io/posts/improvements-to-the-separating-axis/ -b3AxisQuery B3_WIDE( b3ComputeSeparatingAxis )( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, - bool earlyReturn ) -{ - b3Matrix3 R = b3MakeMatrixFromQuat( xfB.q ); - b3Matrix3 invR = b3Transpose( R ); - - float speculativeDistance = B3_SPECULATIVE_DISTANCE; - - b3AxisQuery res = { - .faceA = - { - .normal = b3Vec3_zero, - .separation = -INFINITY, - .indexA = B3_NULL_INDEX, - .indexB = B3_NULL_INDEX, - .type = b3_faceAxisA, - }, - .faceB = - { - .normal = b3Vec3_zero, - .separation = -INFINITY, - .indexA = B3_NULL_INDEX, - .indexB = B3_NULL_INDEX, - .type = b3_faceAxisB, - }, - .edge = - { - .normal = b3Vec3_zero, - .separation = -INFINITY, - .indexA = B3_NULL_INDEX, - .indexB = B3_NULL_INDEX, - .type = b3_edgePairAxis, - }, - .separatedFeature = b3_invalidAxis, - }; - - int faceCountA = hullA->faceCount; - const b3Plane* planesA = b3GetHullPlanes( hullA ); - - int vertexStrideB = b3GetHullSoaStride( hullB->vertexCount ); - const float* vxB = b3GetHullSoaVertices( hullB ); - const float* vyB = vxB + vertexStrideB; - const float* vzB = vyB + vertexStrideB; - int wideVertexCountB = b3RoundUpToSIMDWidth( hullB->vertexCount ); - - b3Vec3 cB = b3AABB_Center( hullB->aabb ); - b3Vec3 hB = b3AABB_Extents( hullB->aabb ); - - // The hulls have a precomputed inner radius and centroid. - // A given axis cannot achieve a separation larger than: - // dot(axis, centerB - centerA) - innerRadiusA - innerRadiusB - // So this is the upper bound for the separation of a candidate axis. - // An axis can be skipped if it has an upper bound that is less than the current - // best separation. This lets me skip many of the candidates without computing - // support points. - - b3Vec3 deltaCenter = b3Sub( b3Add( b3MulMV( R, hullB->center ), xfB.p ), hullA->center ); - float centerDistance = b3Length( deltaCenter ); - float radius = hullA->innerRadius + hullB->innerRadius; - - // Adjust the radius to ensure the best axis isn't skipped. - float radiusBound = radius - ( B3_LINEAR_SLOP + 0.001f * ( centerDistance + radius ) ); - - // Compute dot(normalA, centerDelta) for all face normals of hullA. - _Alignas( B3_WIDE_ALIGNMENT ) float dotA[NF]; - b3GetFaceDots( hullA, deltaCenter, dotA ); - - // Find the face of hullA that most aligns with centerDelta. - int seedIndexA = 0; - float maxDotA = dotA[0]; - for ( int i = 1; i < faceCountA; ++i ) - { - if ( dotA[i] > maxDotA ) - { - maxDotA = dotA[i]; - seedIndexA = i; - } - } - - // Use the seed to get a lower bound on the separation for the faces of hullA. - float floorA = -INFINITY; - float seedSeparationA = -INFINITY; - int seedVertexB = 0; - if ( earlyReturn ) - { - b3Plane plane = planesA[seedIndexA]; - b3Vec3 direction = b3Neg( b3MulMV( invR, plane.normal ) ); - float planeSeparation = b3Dot( plane.normal, xfB.p ) - plane.offset; - seedSeparationA = b3GetFaceSeparation( direction, planeSeparation, vxB, vyB, vzB, wideVertexCountB, cB, hB, &seedVertexB ); - floorA = b3MinFloat( seedSeparationA, speculativeDistance ); - } - - // Test A's face planes against B's vertices. - for ( int i = 0; i < faceCountA; ++i ) - { - // The bound offset ensures the seed will be evaluated. - if ( dotA[i] - radiusBound < b3MaxFloat( floorA, res.faceA.separation ) ) - { - continue; - } - - b3Plane plane = planesA[i]; - int vertexIndex = seedVertexB; - float separation = seedSeparationA; - - // Avoid recomputing the seed face separation. - if ( earlyReturn == false || i != seedIndexA ) - { - b3Vec3 direction = b3Neg( b3MulMV( invR, plane.normal ) ); - float planeSeparation = b3Dot( plane.normal, xfB.p ) - plane.offset; - separation = b3GetFaceSeparation( direction, planeSeparation, vxB, vyB, vzB, wideVertexCountB, cB, hB, &vertexIndex ); - } - - if ( separation > res.faceA.separation ) - { - res.faceA.normal = plane.normal; - res.faceA.separation = separation; - res.faceA.indexA = i; - res.faceA.indexB = vertexIndex; - if ( separation > speculativeDistance && earlyReturn ) - { - res.separatedFeature = b3_faceAxisA; - return res; - } - } - } - - B3_VALIDATE( res.faceA.indexA != B3_NULL_INDEX ); - - int faceCountB = hullB->faceCount; - const b3Plane* planesB = b3GetHullPlanes( hullB ); - - int vertexStrideA = b3GetHullSoaStride( hullA->vertexCount ); - const float* vxA = b3GetHullSoaVertices( hullA ); - const float* vyA = vxA + vertexStrideA; - const float* vzA = vyA + vertexStrideA; - int wideVertexCountA = b3RoundUpToSIMDWidth( hullA->vertexCount ); - - b3Vec3 cA = b3AABB_Center( hullA->aabb ); - b3Vec3 hA = b3AABB_Extents( hullA->aabb ); - - // Similarly, find the face of hullB that most aligns with the vector pointing from centerB to centerA. - _Alignas( B3_WIDE_ALIGNMENT ) float dotB[NF]; - b3GetFaceDots( hullB, b3Neg( b3MulMV( invR, deltaCenter ) ), dotB ); - - int seedIndexB = 0; - float maxDotB = dotB[0]; - for ( int i = 1; i < faceCountB; ++i ) - { - if ( dotB[i] > maxDotB ) - { - maxDotB = dotB[i]; - seedIndexB = i; - } - } - - // Get a lower bound on the separation for the faces of hullB. - float floorB = -INFINITY; - float seedSeparationB = -INFINITY; - int seedVertexA = 0; - if ( earlyReturn ) - { - b3Plane plane = planesB[seedIndexB]; - b3Vec3 direction = b3Neg( b3MulMV( R, plane.normal ) ); - float planeSeparation = b3Dot( direction, xfB.p ) - plane.offset; - seedSeparationB = b3GetFaceSeparation( direction, planeSeparation, vxA, vyA, vzA, wideVertexCountA, cA, hA, &seedVertexA ); - - // Include the floor set by hull A faces. - floorB = b3MaxFloat( seedSeparationB, res.faceA.separation ); - floorB = b3MinFloat( floorB, speculativeDistance ); - } - - // Test B's face planes against A's vertices. - for ( int i = 0; i < faceCountB; ++i ) - { - if ( dotB[i] - radiusBound < b3MaxFloat( floorB, res.faceB.separation ) ) - { - continue; - } - - b3Plane plane = planesB[i]; - b3Vec3 direction = b3Neg( b3MulMV( R, plane.normal ) ); - int vertexIndex = seedVertexA; - float separation = seedSeparationB; - - // Avoid recomputing the seed face separation. - if ( earlyReturn == false || i != seedIndexB ) - { - float planeSeparation = b3Dot( direction, xfB.p ) - plane.offset; - separation = b3GetFaceSeparation( direction, planeSeparation, vxA, vyA, vzA, wideVertexCountA, cA, hA, &vertexIndex ); - } - - if ( separation > res.faceB.separation ) - { - res.faceB.normal = direction; - res.faceB.separation = separation; - res.faceB.indexA = vertexIndex; - res.faceB.indexB = i; - if ( separation > speculativeDistance && earlyReturn ) - { - res.separatedFeature = b3_faceAxisB; - return res; - } - } - } - - // Transform B into A's space once, into SoA arrays. Extra space so tail can be set to zero. - _Static_assert( ( B3_MAX_HULL_EDGES & ( B3_SIMD_WIDTH - 1 ) ) == 0, "must be multiple of SIMD width" ); - _Static_assert( ( B3_MAX_HULL_FACES & ( B3_HULL_SOA_PADDING - 1 ) ) == 0, "must be multiple of hull SoA padding" ); - _Static_assert( ( B3_MAX_HULL_VERTICES & ( B3_HULL_SOA_PADDING - 1 ) ) == 0, "must be multiple of hull SoA padding" ); - - B3_VALIDATE( earlyReturn == false || - centerDistance >= b3MaxFloat( res.faceA.separation, res.faceB.separation ) + radiusBound ); - - // Gather edges of A that can feasibly create a separating axis that beats the maximum face separation. - int halfEdgeCountA = hullA->edgeCount; - const b3HullHalfEdge* halfEdgesA = b3GetHullEdges( hullA ); - int edgeIndicesA[NE]; - int na = 0; - - int halfEdgeCountB = hullB->edgeCount; - const b3HullHalfEdge* halfEdgesB = b3GetHullEdges( hullB ); - int edgeIndicesB[B3_MAX_HULL_EDGES]; - int nb = 0; - - float maxFaceSeparation = b3MaxFloat( res.faceA.separation, res.faceB.separation ); - float boundSlack = radius - radiusBound; - float thresholdA = earlyReturn ? maxFaceSeparation + hullB->innerRadius - boundSlack : -INFINITY; - float thresholdB = earlyReturn ? maxFaceSeparation + hullA->innerRadius - boundSlack : -INFINITY; - - b3Vec3 centerBinA = b3Add( b3MulMV( R, hullB->center ), xfB.p ); - b3Vec3 centerAinB = b3MulMV( invR, b3Sub( hullA->center, xfB.p ) ); - - _Alignas( B3_WIDE_ALIGNMENT ) float planeDotA[NF]; - _Alignas( B3_WIDE_ALIGNMENT ) float planeDotB[NF]; - b3GetFacePlaneSeparations( hullA, centerBinA, planeDotA ); - b3GetFacePlaneSeparations( hullB, centerAinB, planeDotB ); - - const float* cosinesA = b3GetHullEdgeCosines( hullA ); - const float* cosinesB = b3GetHullEdgeCosines( hullB ); - - for ( int i = 0; i < halfEdgeCountA; i += 2 ) - { - int i1 = halfEdgesA[i].face; - int i2 = halfEdgesA[i + 1].face; - float c = cosinesA[i >> 1]; - edgeIndicesA[na] = i; - na += b3TestEdgeCandidateSorted( planeDotA[i1], planeDotA[i2], c, thresholdA ); - } - - for ( int i = 0; i < halfEdgeCountB; i += 2 ) - { - int i1 = halfEdgesB[i].face; - int i2 = halfEdgesB[i + 1].face; - float c = cosinesB[i >> 1]; - edgeIndicesB[nb] = i; - nb += b3TestEdgeCandidateSorted( planeDotB[i1], planeDotB[i2], c, thresholdB ); - } - - // Apply additional culling use the support points for the best face axes. - // The support vertices of the best faces are points on the other hull, so an edge pair axis cannot - // have a larger separation than the plane separation of these points over the arc of the edge. - // This can slow down boxes so skip this if there are not enough edge candidates. - if ( earlyReturn && nb * ( ( na + 3 ) >> 2 ) >= B3_EDGE_PROBE_MIN_TESTS ) - { - float probeBound = maxFaceSeparation - ( 0.1f * B3_LINEAR_SLOP + 0.001f * b3AbsFloat( centerDistance + radius ) ); - - int vertexB = res.faceA.indexB != B3_NULL_INDEX ? res.faceA.indexB : seedVertexB; - b3Vec3 probeB = { vxB[vertexB], vyB[vertexB], vzB[vertexB] }; - b3GetFacePlaneSeparations( hullA, b3Add( b3MulMV( R, probeB ), xfB.p ), planeDotA ); - na = b3FilterEdgeCandidates( hullA, planeDotA, probeBound, edgeIndicesA, na ); - - int vertexA = res.faceB.indexA != B3_NULL_INDEX ? res.faceB.indexA : seedVertexA; - b3Vec3 probeA = { vxA[vertexA], vyA[vertexA], vzA[vertexA] }; - b3GetFacePlaneSeparations( hullB, b3MulMV( invR, b3Sub( probeA, xfB.p ) ), planeDotB ); - nb = b3FilterEdgeCandidates( hullB, planeDotB, probeBound, edgeIndicesB, nb ); - } - - if ( na == 0 || nb == 0 ) - { - // No edge candidates found. - return res; - } - - // The alignments below are not necessary, but they don't hurt. - - // B face normals in A space, negated. - _Alignas( B3_WIDE_ALIGNMENT ) float bFNx[NF]; - _Alignas( B3_WIDE_ALIGNMENT ) float bFNy[NF]; - _Alignas( B3_WIDE_ALIGNMENT ) float bFNz[NF]; - - // B vertices in A space, negated. - _Alignas( B3_WIDE_ALIGNMENT ) float bWx[NV]; - _Alignas( B3_WIDE_ALIGNMENT ) float bWy[NV]; - _Alignas( B3_WIDE_ALIGNMENT ) float bWz[NV]; - - int faceStrideB = b3GetHullSoaStride( faceCountB ); - const float* nxB = b3GetHullSoaNormals( hullB ); - const float* nyB = nxB + faceStrideB; - const float* nzB = nyB + faceStrideB; - - int wideFaceCountB = b3RoundUpToSIMDWidth( faceCountB ); - b3NegativeTransformFromSoA( R, xfB.p, nxB, nyB, nzB, wideFaceCountB, bFNx, bFNy, bFNz, false ); - b3NegativeTransformFromSoA( R, xfB.p, vxB, vyB, vzB, wideVertexCountB, bWx, bWy, bWz, true ); - - // Per A edge data, already in A's space so just gathered. n0 and n1 are the two face - // normals, d the edge vector av1-av0, v0 the first vertex. Tol is the - // parallel edge tolerance, scaled by the edge length. - _Alignas( B3_WIDE_ALIGNMENT ) float aN0x[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aN0y[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aN0z[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aN1x[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aN1y[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aN1z[NE]; - // dir = av1 - av0 - _Alignas( B3_WIDE_ALIGNMENT ) float aDx[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aDy[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aDz[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aV0x[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aV0y[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aV0z[NE]; - _Alignas( B3_WIDE_ALIGNMENT ) float aTol[NE]; - - float squaredTol = B3_PARALLEL_EDGE_TOL * B3_PARALLEL_EDGE_TOL; - for ( int k = 0; k < na; ++k ) - { - const b3HullHalfEdge* edge = halfEdgesA + edgeIndicesA[k]; - const b3HullHalfEdge* twin = edge + 1; - - b3Vec3 A = planesA[edge->face].normal; - b3Vec3 B = planesA[twin->face].normal; - aN0x[k] = A.x; - aN0y[k] = A.y; - aN0z[k] = A.z; - aN1x[k] = B.x; - aN1y[k] = B.y; - aN1z[k] = B.z; - - int v0 = edge->origin; - int v1 = twin->origin; - - aDx[k] = vxA[v1] - vxA[v0]; - aDy[k] = vyA[v1] - vyA[v0]; - aDz[k] = vzA[v1] - vzA[v0]; - aV0x[k] = vxA[v0]; - aV0y[k] = vyA[v0]; - aV0z[k] = vzA[v0]; - - aTol[k] = squaredTol * ( aDx[k] * aDx[k] + aDy[k] * aDy[k] + aDz[k] * aDz[k] ); - } - - // Zero the tail lanes. - b3FloatW zero = b3ZeroW(); - b3Vec3W zeroV = { zero, zero, zero }; - b3StoreVW( aN0x + na, aN0y + na, aN0z + na, zeroV ); - b3StoreVW( aN1x + na, aN1y + na, aN1z + na, zeroV ); - b3StoreVW( aDx + na, aDy + na, aDz + na, zeroV ); - b3StoreVW( aV0x + na, aV0y + na, aV0z + na, zeroV ); - - b3StoreW( aTol + na, zero ); - - float linearSlop = B3_LINEAR_SLOP; - -#if defined( B3_SIMD_NONE ) - - // The SIMD emulated version of this code is very slow. This is a purely scalar version - // for platforms that don't have SIMD capability. It is much faster than SIMD emulation. - // WARNING: this math needs to match the SIMD version for cross platform determinism. - - const float EPS = -linearSlop * linearSlop; - - for ( int j = 0; j < nb; ++j ) - { - const b3HullHalfEdge* edge = halfEdgesB + edgeIndicesB[j]; - const b3HullHalfEdge* twin = edge + 1; - int f0 = edge->face; - int f1 = twin->face; - int v0 = edge->origin; - int v1 = twin->origin; - - b3Vec3 C = { bFNx[f0], bFNy[f0], bFNz[f0] }; - b3Vec3 D = { bFNx[f1], bFNy[f1], bFNz[f1] }; - b3Vec3 bv0 = { bWx[v0], bWy[v0], bWz[v0] }; - b3Vec3 bv1 = { bWx[v1], bWy[v1], bWz[v1] }; - b3Vec3 DC = b3Sub( bv1, bv0 ); - - for ( int i = 0; i < na; ++i ) - { - b3Vec3 d = { aDx[i], aDy[i], aDz[i] }; - - // CBA = C.dir, DBA = D.dir, where dir = B_x_A - float CBA = b3Dot( C, d ); - float DBA = b3Dot( D, d ); - if ( CBA * DBA >= EPS ) - { - continue; - } - - b3Vec3 n0 = { aN0x[i], aN0y[i], aN0z[i] }; - b3Vec3 n1 = { aN1x[i], aN1y[i], aN1z[i] }; - - // ADC = n0.DC, BDC = n1.DC, where DC = D_x_C - float ADC = b3Dot( n0, DC ); - float BDC = b3Dot( n1, DC ); - if ( ADC * BDC >= EPS || CBA * BDC >= EPS ) - { - continue; - } - - // Reject near parallel edges - float maxCD = b3MaxFloat( CBA * CBA, DBA * DBA ); - if ( maxCD <= aTol[i] ) - { - continue; - } - - // t = -CBA / (DBA - CBA) - float t = -CBA / ( DBA - CBA ); - - // normal = lerp(t, C, D) = C + (D-C)*t - b3Vec3 n = b3MulAdd( C, t, b3Sub( D, C ) ); - float len2 = b3Dot( n, n ); - - float inv = 1.0f / sqrtf( len2 ); - n = b3MulSV( inv, n ); - - // separation = -dot(normal, av0 + bv0) - b3Vec3 av0 = { aV0x[i], aV0y[i], aV0z[i] }; - float separation = -b3Dot( b3Add( av0, bv0 ), n ); - - if ( separation > res.edge.separation ) - { - res.edge.normal = n; - res.edge.separation = separation; - - // Half edge index - res.edge.indexA = edgeIndicesA[i]; - res.edge.indexB = edgeIndicesB[j]; - - if ( separation > speculativeDistance && earlyReturn ) - { - res.separatedFeature = b3_edgePairAxis; - return res; - } - } - } - } - -#else - - // This tolerance can skip edges shorter than 1cm. - const b3FloatW EPS = b3SplatW( -linearSlop * linearSlop ); - const b3FloatW INF = b3SplatW( INFINITY ); - - for ( int j = 0; j < nb; ++j ) - { - const b3HullHalfEdge* edge = halfEdgesB + edgeIndicesB[j]; - const b3HullHalfEdge* twin = edge + 1; - int f0 = edge->face; - int f1 = twin->face; - int v0 = edge->origin; - int v1 = twin->origin; - - b3Vec3 nC = { bFNx[f0], bFNy[f0], bFNz[f0] }; - b3Vec3 nD = { bFNx[f1], bFNy[f1], bFNz[f1] }; - b3Vec3 pB = { bWx[v0], bWy[v0], bWz[v0] }; - b3Vec3 qB = { bWx[v1], bWy[v1], bWz[v1] }; - - const b3Vec3W C = b3SplatVW( nC ); - const b3Vec3W D = b3SplatVW( nD ); - const b3Vec3W DC = b3SplatVW( b3Sub( qB, pB ) ); - const b3Vec3W bv0 = b3SplatVW( pB ); - - for ( int i = 0; i < na; i += B3_SIMD_WIDTH ) - { - b3Vec3W n0 = b3LoadVW( aN0x + i, aN0y + i, aN0z + i ); - b3Vec3W n1 = b3LoadVW( aN1x + i, aN1y + i, aN1z + i ); - b3Vec3W d = b3LoadVW( aDx + i, aDy + i, aDz + i ); - b3Vec3W av0 = b3LoadVW( aV0x + i, aV0y + i, aV0z + i ); - - b3FloatW tol = b3LoadW( aTol + i ); - - // CBA = C.dir, DBA = D.dir, where dir = B_x_A - b3FloatW CBA = b3DotW( C, d ); - b3FloatW DBA = b3DotW( D, d ); - // ADC = n0.DC, BDC = n1.DC, where DC = D_x_C - b3FloatW ADC = b3DotW( n0, DC ); - b3FloatW BDC = b3DotW( n1, DC ); - - // Gauss map arc crossing test, CBA*DBA res.edge.separation ) - { - res.edge.normal = (b3Vec3){ nxA[lane], nyA[lane], nzA[lane] }; - res.edge.separation = s; - - // Half edge index - res.edge.indexA = edgeIndicesA[ei]; - res.edge.indexB = edgeIndicesB[j]; - - if ( s > speculativeDistance && earlyReturn ) - { - res.separatedFeature = b3_edgePairAxis; - return res; - } - } - } - } - } -#endif - - return res; -} - -#undef NE -#undef NF -#undef NV diff --git a/src/core.c b/src/core.c index 2165eff..d6a09b0 100644 --- a/src/core.c +++ b/src/core.c @@ -11,7 +11,6 @@ #endif #include "core.h" -#include "rapidhash.h" #include "box3d/constants.h" #include "box3d/math_functions.h" @@ -19,7 +18,7 @@ #include #include -#ifdef BOX3D_PROFILE +#ifdef BOX2D_PROFILE #include #define b3TracyCAlloc( ptr, size ) TracyCAlloc( ptr, size ) @@ -36,8 +35,6 @@ #include -_Static_assert( B3_MAX_MANIFOLD_POINTS >= 4, "B3_MAX_MANIFOLD_POINTS must be at least 4" ); - // This allows the user to change the length units at runtime static float b3_lengthUnitsPerMeter = 1.0f; @@ -52,6 +49,19 @@ float b3GetLengthUnitsPerMeter( void ) return b3_lengthUnitsPerMeter; } +static float b3_stallThreshold = FLT_MAX; + +void b3SetStallThreshold(float seconds) +{ + B3_ASSERT( b3IsValidFloat( seconds ) && seconds > 0.0f ); + b3_stallThreshold = seconds; +} + +float b3GetStallThreshold(void) +{ + return b3_stallThreshold; +} + static int b3DefaultAssertFcn( const char* condition, const char* fileName, int lineNumber ) { printf( "BOX3D ASSERTION: %s, %s, line %d\n", condition, fileName, lineNumber ); @@ -105,7 +115,7 @@ void b3Log( const char* format, ... ) b3Version b3GetVersion( void ) { - return (b3Version){ 0, 2, 0 }; + return (b3Version){ 0, 1, 0 }; } bool b3IsDoublePrecision( void ) @@ -117,15 +127,10 @@ bool b3IsDoublePrecision( void ) #endif } -int b3GetMaxManifoldPoints( void ) -{ - return B3_MAX_MANIFOLD_POINTS; -} - static b3AllocFcn* b3_allocFcn = NULL; static b3FreeFcn* b3_freeFcn = NULL; -static b3AtomicI64 b3_byteCount; +b3AtomicInt b3_byteCount; void b3SetAllocator( b3AllocFcn* allocFcn, b3FreeFcn* freeFcn ) { @@ -133,6 +138,9 @@ void b3SetAllocator( b3AllocFcn* allocFcn, b3FreeFcn* freeFcn ) b3_freeFcn = freeFcn; } +// Use 64 byte alignment for everything to align to 64 byte cache line and works with 256bit SIMD. +#define B3_ALIGNMENT 64 + void* b3Alloc( size_t size ) { if ( size == 0 ) @@ -140,40 +148,42 @@ void* b3Alloc( size_t size ) return NULL; } - b3AtomicFetchAddI64( &b3_byteCount, (int)size ); + // This could cause some sharing issues, however Box3D rarely calls b3Alloc. + // todo this is not true, Box3D allocates a lot. + b3AtomicFetchAddInt( &b3_byteCount, (int)size ); - // Allocation must be a multiple of B3_ALIGNMENT (required by spec). + // Allocation must be a multiple of 32 or risk a seg fault // https://en.cppreference.com/w/c/memory/aligned_alloc - size_t alignedSize = ( ( size - 1 ) | ( B3_ALIGNMENT - 1 ) ) + 1; + int size64 = ( ( (int)size - 1 ) | 0x3F ) + 1; if ( b3_allocFcn != NULL ) { - void* ptr = b3_allocFcn( alignedSize, B3_ALIGNMENT ); + void* ptr = b3_allocFcn( size64, B3_ALIGNMENT ); b3TracyCAlloc( ptr, size ); B3_ASSERT( ptr != NULL ); - B3_ASSERT( ( (uintptr_t)ptr & ( B3_ALIGNMENT - 1 ) ) == 0 ); + B3_ASSERT( ( (uintptr_t)ptr & 0x3F ) == 0 ); return ptr; } #ifdef B3_PLATFORM_WINDOWS - void* ptr = _aligned_malloc( alignedSize, B3_ALIGNMENT ); + void* ptr = _aligned_malloc( size64, B3_ALIGNMENT ); #elif defined( B3_PLATFORM_ANDROID ) void* ptr = NULL; - if ( posix_memalign( &ptr, B3_ALIGNMENT, alignedSize ) != 0 ) + if ( posix_memalign( &ptr, B3_ALIGNMENT, size64 ) != 0 ) { // allocation failed, exit the application exit( EXIT_FAILURE ); } #else - void* ptr = aligned_alloc( B3_ALIGNMENT, alignedSize ); + void* ptr = aligned_alloc( B3_ALIGNMENT, size64 ); #endif b3TracyCAlloc( ptr, size ); B3_ASSERT( ptr != NULL ); - B3_ASSERT( ( (uintptr_t)ptr & ( B3_ALIGNMENT - 1 ) ) == 0 ); + B3_ASSERT( ( (uintptr_t)ptr & 0x3F ) == 0 ); return ptr; } @@ -189,8 +199,7 @@ void b3Free( void* mem, size_t size ) if ( b3_freeFcn != NULL ) { - size_t alignedSize = size > 0 ? ( ( size - 1 ) | ( B3_ALIGNMENT - 1 ) ) + 1 : 0; - b3_freeFcn( mem, alignedSize ); + b3_freeFcn( mem ); } else { @@ -201,11 +210,13 @@ void b3Free( void* mem, size_t size ) #endif } - b3AtomicFetchAddI64( &b3_byteCount, -(int64_t)size ); + b3AtomicFetchAddInt( &b3_byteCount, -(int)size ); } void* b3GrowAlloc( void* oldMem, int oldSize, int newSize ) { + // todo try _aligned_realloc + B3_ASSERT( newSize > oldSize ); void* newMem = b3Alloc( newSize ); if ( oldSize > 0 ) @@ -216,52 +227,141 @@ void* b3GrowAlloc( void* oldMem, int oldSize, int newSize ) return newMem; } -void* b3GrowAllocZeroed( void* oldMem, int oldSize, int newSize ) +int b3GetByteCount( void ) { - void* newMem = b3GrowAlloc( oldMem, oldSize, newSize ); - memset( (char*)newMem + oldSize, 0, (size_t)( newSize - oldSize ) ); - return newMem; + return b3AtomicLoadInt( &b3_byteCount ); } -int64_t b3GetByteCount( void ) -{ - return b3AtomicLoadI64( &b3_byteCount ); -} - -void* b3AllocZero( size_t size ) +void* b3AllocZeroed( size_t size ) { void* mem = b3Alloc( size ); memset( mem, 0, size ); return mem; } -// Not used. Keeping around in case I need this. -void b3StrCpy( char* dst, int size, const char* src ) +static FILE* b3OpenFile( const char* fileName, const char* mode ) { - B3_ASSERT( size > 0 ); + FILE* file = NULL; - if ( src != NULL ) - { #if defined( _MSC_VER ) - strncpy_s( dst, size, src, size - 1 ); + errno_t e = fopen_s( &file, fileName, mode ); + if ( e != 0 ) + { + return NULL; + } #else - strncpy( dst, src, size - 1 ); - dst[size - 1] = 0; + file = fopen( fileName, mode ); + if ( file == NULL ) + { + return NULL; + } #endif - } - else - { - memset( dst, 0, size ); - } + + return file; } -uint64_t b3Hash64NonZero( const uint8_t* bytes, int n ) +FILE* b3_dumpFile = NULL; +int b3_meshIndex = 0; + +void b3OpenDump( const char* fileName ) { - if ( n <= 0 ) + B3_ASSERT( b3_dumpFile == NULL ); + b3_dumpFile = b3OpenFile( fileName, "w" ); +} + +void b3Dump( const char* string, ... ) +{ + if ( b3_dumpFile == NULL ) { - return 1; + return; } - uint64_t h = rapidhash( bytes, n ); - return h == 0 ? 1 : h; + va_list args; + va_start( args, string ); + vfprintf( b3_dumpFile, string, args ); + va_end( args ); +} + +void b3CloseDump( void ) +{ + fclose( b3_dumpFile ); + b3_dumpFile = NULL; +} + +int b3FetchAddMeshDumpIndex( void ) +{ + int result = b3_meshIndex; + b3_meshIndex += 1; + return result; +} + +void b3WriteBinaryFile( void* data, int size, const char* fileName ) +{ + if ( data == NULL || size <= 0 || fileName == NULL ) + { + return; + } + + FILE* file = b3OpenFile( fileName, "wb" ); + if ( file == NULL ) + { + return; + } + + // Write binary blob; ignore partial-write errors for simplicity + (void)fwrite( data, 1, (size_t)size, file ); + fclose( file ); +} + +void* b3ReadBinaryFile( const char* prefix, const char* fileName, int* memSize ) +{ + *memSize = 0; + + if ( prefix == NULL || fileName == NULL ) + { + return NULL; + } + + char buffer[128]; + snprintf( buffer, sizeof( buffer ), "%s%s", prefix, fileName ); + + FILE* file = b3OpenFile( buffer, "rb" ); + if ( file == NULL ) + { + return NULL; + } + + // Determine file size + if ( fseek( file, 0, SEEK_END ) != 0 ) + { + fclose( file ); + return NULL; + } + + long size = ftell( file ); + if ( size <= 0 ) + { + fclose( file ); + return NULL; + } + + // Rewind + if ( fseek( file, 0, SEEK_SET ) != 0 ) + { + fclose( file ); + return NULL; + } + + void* data = b3Alloc( (size_t)size ); + size_t readCount = fread( data, 1, (size_t)size, file ); + fclose( file ); + + if ( readCount != (size_t)size ) + { + b3Free( data, (size_t)size ); + return NULL; + } + + *memSize = (int)size; + return data; } diff --git a/src/core.h b/src/core.h index 94de040..34656a9 100644 --- a/src/core.h +++ b/src/core.h @@ -49,48 +49,29 @@ // Define SIMD #if defined( BOX3D_DISABLE_SIMD ) #define B3_SIMD_NONE + #define B3_SIMD_WIDTH 4 //#pragma message("B3_SIMD_NONE") #else #if defined( B3_CPU_X86_X64 ) #define B3_SIMD_SSE2 - #if !defined( BOX3D_DISABLE_AVX2 ) - #define B3_SIMD_HAS_WIDTH_8 - #if defined( __AVX2__ ) || ( defined( B3_SIMD_WIDTH ) && B3_SIMD_WIDTH == 8 ) - #define B3_SIMD_AVX2 - #endif - #endif + #define B3_SIMD_WIDTH 4 + //#pragma message("B3_SIMD_SSE2") #elif defined( B3_CPU_ARM ) - // ARMv7 Neon doesn't have divide or sqrt so cannot be used. - #if defined( __aarch64__ ) || defined( _M_ARM64 ) - #define B3_SIMD_NEON - #else - #define B3_SIMD_NONE - #endif + #define B3_SIMD_NEON + #define B3_SIMD_WIDTH 4 //#pragma message("B3_SIMD_NEON") #elif defined( B3_CPU_WASM ) + #define B3_CPU_WASM #define B3_SIMD_SSE2 + #define B3_SIMD_WIDTH 4 //#pragma message("B3_SIMD_SSE2") #else #define B3_SIMD_NONE + #define B3_SIMD_WIDTH 4 //#pragma message("B3_SIMD_NONE") #endif #endif -#if !defined( B3_SIMD_NONE ) - #define B3_SIMD_ENABLED -#endif - -#if defined( B3_SIMD_AVX2 ) && defined( __clang__ ) - #define B3_AVX2_BEGIN _Pragma( "clang attribute push( __attribute__( ( target( \"avx2\" ) ) ), apply_to = function )" ) - #define B3_AVX2_END _Pragma( "clang attribute pop" ) -#elif defined( B3_SIMD_AVX2 ) && defined( __GNUC__ ) - #define B3_AVX2_BEGIN _Pragma( "GCC push_options" ) _Pragma( "GCC target( \"avx2\" )" ) - #define B3_AVX2_END _Pragma( "GCC pop_options" ) -#else - #define B3_AVX2_BEGIN - #define B3_AVX2_END -#endif - // Define compiler #if defined( __clang__ ) #define B3_COMPILER_CLANG @@ -127,17 +108,6 @@ typedef struct b3AtomicU32 uint32_t value; } b3AtomicU32; -typedef struct b3AtomicI64 -{ - // 64-bit atomic wants 8-byte alignment - _Alignas( 8 ) int64_t value; -} b3AtomicI64; - -// Minimum memory alignment used for all allocations -#define B3_ALIGNMENT 32 - -#define B3_RESTRICT restrict - // Returns the number of elements of an array #define B3_ARRAY_COUNT( A ) (int)( sizeof( A ) / sizeof( A[0] ) ) @@ -155,17 +125,18 @@ typedef struct b3AtomicI64 #define B3_FREE( M, T, N ) b3Free( M, N * sizeof( T ) ); void* b3Alloc( size_t size ); -void* b3AllocZero( size_t size ); +void* b3AllocZeroed( size_t size ); void b3Free( void* mem, size_t size ); void* b3GrowAlloc( void* oldMem, int oldSize, int newSize ); -void* b3GrowAllocZeroed( void* oldMem, int oldSize, int newSize ); -#define B3_GROW( A, N, M ) b3GrowAlloc( ( A ), (int)( ( N ) * sizeof( *( A ) ) ), (int)( ( M ) * sizeof( *( A ) ) ) ) -#define B3_GROW_ZERO( A, N, M ) b3GrowAllocZeroed( ( A ), (int)( ( N ) * sizeof( *( A ) ) ), (int)( ( M ) * sizeof( *( A ) ) ) ) - -B3_PRINTF_FORMAT( 1, 2 ) void b3Log( const char* format, ... ); +// Geometry content hashes reserve zero to mean unhashed +static inline uint32_t b3NonZeroHash( uint32_t hash ) +{ + return hash != 0 ? hash : 1; +} + typedef struct b3Mutex b3Mutex; b3Mutex* b3CreateMutex( void ); void b3DestroyMutex( b3Mutex* m ); @@ -184,6 +155,8 @@ typedef struct b3Thread b3Thread; b3Thread* b3CreateThread( b3ThreadFunction* function, void* context, const char* name ); void b3JoinThread( b3Thread* t ); -void b3StrCpy( char* dst, int size, const char* src ); - -uint64_t b3Hash64NonZero( const uint8_t* bytes, int n ); +// Dump to a file. Only one dump file allowed at a time. +void b3OpenDump( const char* fileName ); +void b3Dump( const char* string, ... ); +void b3CloseDump( void ); +int b3FetchAddMeshDumpIndex( void ); diff --git a/src/distance.c b/src/distance.c index 57f0814..3d558ab 100644 --- a/src/distance.c +++ b/src/distance.c @@ -847,10 +847,6 @@ b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* b3ComputeWitnessPoints( &simplex, &localPointA, &localPointB ); distanceOutput.pointA = localPointA; distanceOutput.pointB = localPointB; - distanceOutput.normal = b3Vec3_zero; - distanceOutput.distance = 0.0f; - distanceOutput.iterations = iteration; - distanceOutput.simplexCount = simplexIndex; return distanceOutput; } @@ -947,10 +943,6 @@ b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* b3ComputeWitnessPoints( &simplex, &localPointA, &localPointB ); distanceOutput.pointA = localPointA; distanceOutput.pointB = localPointB; - distanceOutput.normal = b3Vec3_zero; - distanceOutput.distance = 0.0f; - distanceOutput.iterations = iteration; - distanceOutput.simplexCount = simplexIndex; B3_VALIDATE( b3Distance( localPointA, localPointB ) < FLT_EPSILON ); return distanceOutput; } @@ -992,27 +984,25 @@ b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* simplex.count += 1; } - // Build witness points. - b3Vec3 localPointA, localPointB; - b3ComputeWitnessPoints( &simplex, &localPointA, &localPointB ); - - distanceOutput.pointA = localPointA; - distanceOutput.pointB = localPointB; - distanceOutput.iterations = iteration; - distanceOutput.simplexCount = simplexIndex; - normal = b3Normalize( normal ); if ( b3IsNormalized( normal ) == false ) { // Treat as overlap - distanceOutput.distance = 0.0f; - distanceOutput.normal = b3Vec3_zero; return distanceOutput; } + // Build witness points and safe cache + b3Vec3 localPointA, localPointB; + b3ComputeWitnessPoints( &simplex, &localPointA, &localPointB ); + b3WriteCache( cache, &simplex ); + // Results stay in frame A + distanceOutput.pointA = localPointA; + distanceOutput.pointB = localPointB; distanceOutput.distance = b3Distance( localPointA, localPointB ); distanceOutput.normal = normal; + distanceOutput.iterations = iteration; + distanceOutput.simplexCount = simplexIndex; // Apply radii if requested if ( input->useRadii ) @@ -1026,12 +1016,10 @@ b3DistanceOutput b3ShapeDistance( const b3DistanceInput* input, b3SimplexCache* distanceOutput.pointB = b3Sub( distanceOutput.pointB, b3MulSV( rB, normal ) ); } - // Simplex is useful, cache it. - b3WriteCache( cache, &simplex ); - return distanceOutput; } + // Separation function: // f(t) = (c2 + t * dp2 - c1 - t * dp1 ) * n @@ -1087,36 +1075,6 @@ b3CastOutput b3ShapeCast( const b3ShapeCastPairInput* input ) { target = distanceOutput.distance - linearSlop; } - else if ( input->canEncroach && distanceOutput.distance > 0.0f ) - { - // This is for box movers and can't normally be reached by capsule - // movers or regular shape casts. - - // Near-target start without overlap: advance by first order while - // retaining a rest separation. Sweeps that cannot consume the free - // gap (receding, tangential, grazing) miss. - float retained = 0.5f * linearSlop; - float needed = distanceOutput.distance - retained; - float approach = -b3Dot( delta2, distanceOutput.normal ); - if ( approach <= b3MaxFloat( needed, 0.0f ) ) - { - // Moving away, no hit. - return output; - } - - float fraction = needed > 0.0f ? needed / approach : 0.0f; - if ( fraction >= input->maxFraction ) - { - // Still no hit because the max fraction is small. - return output; - } - - output.fraction = fraction; - output.point = b3MulAdd( distanceOutput.pointA, input->proxyA.radius, distanceOutput.normal ); - output.normal = distanceOutput.normal; - output.hit = true; - return output; - } else { // Initial overlap @@ -1745,14 +1703,6 @@ b3TOIOutput b3TimeOfImpact( const b3TOIInput* input ) { output.state = b3_toiStateOverlapped; output.fraction = 0.0f; - - // Averaged hit point - b3Vec3 pA = b3MulAdd( worldPointA, proxyA.radius, worldNormal ); - b3Vec3 pB = b3MulAdd( worldPointB, -proxyB.radius, worldNormal ); - output.point = b3Lerp( pA, pB, 0.5f ); - output.point = b3Add( output.point, origin ); - output.normal = worldNormal; - break; } diff --git a/src/distance_joint.c b/src/distance_joint.c index b89c670..9185010 100644 --- a/src/distance_joint.c +++ b/src/distance_joint.c @@ -256,8 +256,8 @@ void b3PrepareDistanceJoint( b3JointSim* base, b3StepContext* context ) B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; diff --git a/src/dynamic_tree.c b/src/dynamic_tree.c index b1f7ca4..92be1a8 100644 --- a/src/dynamic_tree.c +++ b/src/dynamic_tree.c @@ -1,12 +1,9 @@ // SPDX-FileCopyrightText: 2025 Erin Catto // SPDX-License-Identifier: MIT -#include "dynamic_tree.h" - #include "aabb.h" -#include "algorithm.h" #include "core.h" -#include "platform.h" +#include "joint.h" #include "simd.h" #include "box3d/collision.h" @@ -17,100 +14,72 @@ #include #include -_Static_assert( B3_ROOT_NODE == 0, "bad root" ); -_Static_assert( sizeof( b3TreeNode ) == 32, "expected size" ); -_Static_assert( sizeof( b3TreeProxy ) == 24, "expected size" ); +#define B3_TREE_STACK_SIZE 1024 -// The free sibling pair list is chained through the parent index of their first node. A pair comes from the -// free list when there is one and from the bump pointer otherwise. A rebuild empties the free list, so -// allocations can just bump. -static int b3AllocateSiblingPair( b3DynamicTree* tree ) +static b3TreeNode b3_defaultTreeNode = { + .aabb = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f } }, + .categoryBits = B3_DEFAULT_CATEGORY_BITS, + .children = + { + .child1 = B3_NULL_INDEX, + .child2 = B3_NULL_INDEX, + }, + .parent = B3_NULL_INDEX, + .height = 0, + .flags = b3_allocatedNode, +}; + +static inline bool b3IsLeaf( const b3TreeNode* node ) { - // Allocate from free list. - if ( tree->pairFreeList != B3_NULL_INDEX ) - { - int pair = tree->pairFreeList; - tree->pairFreeList = tree->parents[pair]; - return pair; - } - - // Extend the bump allocator if needed. - if ( tree->nodeEnd + 2 > tree->nodeCapacity ) - { - int oldCapacity = tree->nodeCapacity; - int newCapacity = oldCapacity + ( oldCapacity >> 1 ); - newCapacity += newCapacity & 1; - tree->nodes = B3_GROW_ZERO( tree->nodes, oldCapacity, newCapacity ); - tree->parents = B3_GROW_ZERO( tree->parents, oldCapacity, newCapacity ); - tree->nodeCapacity = newCapacity; - - // The spare has to match, the rebuild allocates it again. - b3Free( tree->swapNodes, oldCapacity * sizeof( b3TreeNode ) ); - tree->swapNodes = NULL; - } - - int pair = tree->nodeEnd; - tree->nodeEnd += 2; - return pair; + return node->flags & b3_leafNode; } -static void b3FreePair( b3DynamicTree* tree, int pair ) +static inline bool b3IsAllocated( const b3TreeNode* node ) { - B3_ASSERT( ( pair & 1 ) == 0 && 2 <= pair && pair < tree->nodeEnd ); - tree->nodes[pair] = b3MakeEmptyNode(); - tree->nodes[pair + 1] = b3MakeEmptyNode(); - tree->parents[pair] = tree->pairFreeList; - tree->parents[pair + 1] = B3_NULL_INDEX; - tree->pairFreeList = pair; + return node->flags & b3_allocatedNode; +} + +static inline uint16_t b3MaxUInt16( uint16_t a, uint16_t b ) +{ + return a > b ? a : b; } b3DynamicTree b3DynamicTree_Create( int proxyCapacity ) { int capacity = b3MaxInt( proxyCapacity, 16 ); - // Intentionally _not_ initialized with brace initialization, which can leave - // uninitialized gaps. b3DynamicTree tree; // memset needed for deterministic serialization memset( &tree, 0, sizeof( b3DynamicTree ) ); tree.version = B3_DYNAMIC_TREE_VERSION; + tree.root = B3_NULL_INDEX; - // A tree of n proxies has 2n - 1 nodes plus the empty node beside the root - tree.nodeCapacity = 2 * capacity; - tree.nodes = (b3TreeNode*)b3AllocZero( tree.nodeCapacity * sizeof( b3TreeNode ) ); - tree.parents = (int32_t*)b3AllocZero( tree.nodeCapacity * sizeof( int32_t ) ); - tree.pairFreeList = B3_NULL_INDEX; + // maximum node count for a full binary tree is 2 * leafCount - 1 + tree.nodeCapacity = 2 * capacity - 1; + tree.nodeCount = 0; - // The root and the empty node always exist - tree.nodes[B3_ROOT_NODE] = b3MakeEmptyNode(); - tree.nodes[B3_ROOT_NODE + 1] = b3MakeEmptyNode(); - tree.parents[B3_ROOT_NODE] = B3_NULL_INDEX; - tree.parents[B3_ROOT_NODE + 1] = B3_NULL_INDEX; + tree.nodes = (b3TreeNode*)b3Alloc( tree.nodeCapacity * sizeof( b3TreeNode ) ); - // This is the bump index. - tree.nodeEnd = 2; - tree.dfsOrdered = true; + // Better to have 64 byte alignment + B3_VALIDATE( ( (uintptr_t)tree.nodes & 0x3F ) == 0 ); - tree.proxyCapacity = capacity; - tree.proxyCount = 0; - tree.proxies = (b3TreeProxy*)b3AllocZero( tree.proxyCapacity * sizeof( b3TreeProxy ) ); + memset( tree.nodes, 0, tree.nodeCapacity * sizeof( b3TreeNode ) ); // Build a linked list for the free list. - for ( int i = 0; i < tree.proxyCapacity - 1; ++i ) + // todo use a bump allocator until the capacity is consumed (see b3PoolAllocator) + for ( int i = 0; i < tree.nodeCapacity - 1; ++i ) { - tree.proxies[i].node = B3_NULL_INDEX; - tree.proxies[i].next = i + 1; + tree.nodes[i].next = i + 1; } - tree.proxies[tree.proxyCapacity - 1].node = B3_NULL_INDEX; - tree.proxies[tree.proxyCapacity - 1].next = B3_NULL_INDEX; - tree.proxyFreeList = 0; + tree.nodes[tree.nodeCapacity - 1].next = B3_NULL_INDEX; + tree.freeList = 0; + + tree.proxyCount = 0; - tree.swapNodes = NULL; tree.leafIndices = NULL; - tree.leafNodes = NULL; tree.leafBoxes = NULL; tree.leafCenters = NULL; tree.binIndices = NULL; @@ -122,113 +91,61 @@ b3DynamicTree b3DynamicTree_Create( int proxyCapacity ) void b3DynamicTree_Destroy( b3DynamicTree* tree ) { b3Free( tree->nodes, tree->nodeCapacity * sizeof( b3TreeNode ) ); - b3Free( tree->parents, tree->nodeCapacity * sizeof( int32_t ) ); - b3Free( tree->proxies, tree->proxyCapacity * sizeof( b3TreeProxy ) ); - b3Free( tree->swapNodes, tree->nodeCapacity * sizeof( b3TreeNode ) ); - b3Free( tree->leafIndices, tree->rebuildCapacity * sizeof( int32_t ) ); - b3Free( tree->leafNodes, tree->rebuildCapacity * sizeof( b3TreeNode ) ); + b3Free( tree->leafIndices, tree->rebuildCapacity * sizeof( int ) ); b3Free( tree->leafBoxes, tree->rebuildCapacity * sizeof( b3AABB ) ); b3Free( tree->leafCenters, tree->rebuildCapacity * sizeof( b3Vec3 ) ); - b3Free( tree->binIndices, tree->rebuildCapacity * sizeof( int32_t ) ); + b3Free( tree->binIndices, tree->rebuildCapacity * sizeof( int ) ); memset( tree, 0, sizeof( b3DynamicTree ) ); } -// Allocate a proxy from the pool. Grow the pool if necessary. -static int b3AllocateProxy( b3DynamicTree* tree ) +// Allocate a node from the pool. Grow the pool if necessary. +static int b3AllocateNode( b3DynamicTree* tree ) { - // Expand the pool as needed. - if ( tree->proxyFreeList == B3_NULL_INDEX ) + // Expand the node pool as needed. + if ( tree->freeList == B3_NULL_INDEX ) { - B3_ASSERT( tree->proxyCount == tree->proxyCapacity ); + B3_ASSERT( tree->nodeCount == tree->nodeCapacity ); // The free list is empty. Rebuild a bigger pool. - // A restored pool can have capacity 1, so guarantee strict growth. - int oldCapacity = tree->proxyCapacity; - tree->proxyCapacity += b3MaxInt( oldCapacity >> 1, 1 ); - tree->proxies = B3_GROW_ZERO( tree->proxies, oldCapacity, tree->proxyCapacity ); + b3TreeNode* oldNodes = tree->nodes; + int oldCapacity = tree->nodeCapacity; + tree->nodeCapacity += oldCapacity >> 1; + tree->nodes = (b3TreeNode*)b3Alloc( tree->nodeCapacity * sizeof( b3TreeNode ) ); + B3_ASSERT( oldNodes != NULL ); + memcpy( tree->nodes, oldNodes, tree->nodeCount * sizeof( b3TreeNode ) ); + memset( tree->nodes + tree->nodeCount, 0, ( tree->nodeCapacity - tree->nodeCount ) * sizeof( b3TreeNode ) ); + b3Free( oldNodes, oldCapacity * sizeof( b3TreeNode ) ); - // Build a linked list for the free list. - for ( int i = oldCapacity; i < tree->proxyCapacity - 1; ++i ) + // Build a linked list for the free list. The parent pointer becomes the "next" pointer. + // todo avoid building freelist? + for ( int i = tree->nodeCount; i < tree->nodeCapacity - 1; ++i ) { - tree->proxies[i].node = B3_NULL_INDEX; - tree->proxies[i].next = i + 1; + tree->nodes[i].next = i + 1; } - tree->proxies[tree->proxyCapacity - 1].node = B3_NULL_INDEX; - tree->proxies[tree->proxyCapacity - 1].next = B3_NULL_INDEX; - tree->proxyFreeList = oldCapacity; + tree->nodes[tree->nodeCapacity - 1].next = B3_NULL_INDEX; + tree->freeList = tree->nodeCount; } - // Peel a proxy off the free list. - int proxyIndex = tree->proxyFreeList; - tree->proxyFreeList = tree->proxies[proxyIndex].next; - memset( tree->proxies + proxyIndex, 0, sizeof( b3TreeProxy ) ); - tree->proxies[proxyIndex].node = B3_NULL_INDEX; - tree->proxies[proxyIndex].next = B3_NULL_INDEX; - ++tree->proxyCount; - return proxyIndex; + // Peel a node off the free list. + int nodeIndex = tree->freeList; + b3TreeNode* node = tree->nodes + nodeIndex; + tree->freeList = node->next; + *node = b3_defaultTreeNode; + ++tree->nodeCount; + return nodeIndex; } -// Return a proxy to the pool. -static void b3FreeProxy( b3DynamicTree* tree, int proxyId ) +// Return a node to the pool. +static void b3FreeNode( b3DynamicTree* tree, int nodeId ) { - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); - B3_ASSERT( 0 < tree->proxyCount ); - tree->proxies[proxyId].node = B3_NULL_INDEX; - tree->proxies[proxyId].next = tree->proxyFreeList; - tree->proxyFreeList = proxyId; - --tree->proxyCount; -} - -static inline int b3GetNodeHeight( const b3TreeNode* node ) -{ - return b3IsLeaf( node ) ? 0 : node->height; -} - -// The internal node above a children pair -static inline b3TreeNode b3MakeInternalNode( const b3TreeNode* nodes, int pair ) -{ - const b3TreeNode* c1 = nodes + pair; - const b3TreeNode* c2 = nodes + pair + 1; - - b3TreeNode node = { 0 }; - b3StoreAABBV( &node.aabb, b3UnionPairV( nodes + pair ), true ); - node.flagIndex = (uint32_t)pair | ( ( c1->flagIndex | c2->flagIndex ) & B3_MOVED_NODE ); - node.height = 1 + b3MaxInt( b3GetNodeHeight( c1 ), b3GetNodeHeight( c2 ) ); - return node; -} - -static inline b3TreeNode b3MakeLeafNode( b3AABB aabb, int proxyId, uint64_t userData, bool moved ) -{ - b3TreeNode node = { 0 }; - node.aabb = aabb; - node.flagIndex = (uint32_t)proxyId | B3_LEAF_NODE | ( moved ? B3_MOVED_NODE : 0 ); - node.shapeIndex = (int32_t)(uint32_t)userData; - return node; -} - -// A node landed at a new index, so tell what hangs below it -static inline void b3LinkChildren( b3DynamicTree* tree, int nodeIndex ) -{ - const b3TreeNode* node = tree->nodes + nodeIndex; - if ( b3IsLeaf( node ) ) - { - tree->proxies[b3GetProxyId( node )].node = nodeIndex; - } - else - { - int pair = b3GetLeftChild( node ); - tree->parents[pair] = nodeIndex; - tree->parents[pair + 1] = nodeIndex; - } -} - -// The sweep refit visits indices from high to low, so it needs every child above its parent -static inline bool b3IsNodeOrdered( const b3TreeNode* nodes, int nodeIndex ) -{ - const b3TreeNode* node = nodes + nodeIndex; - return b3IsLeaf( node ) || nodeIndex < b3GetLeftChild( node ); + B3_ASSERT( 0 <= nodeId && nodeId < tree->nodeCapacity ); + B3_ASSERT( 0 < tree->nodeCount ); + tree->nodes[nodeId].next = tree->freeList; + tree->nodes[nodeId].flags = 0; + tree->freeList = nodeId; + --tree->nodeCount; } // Greedy algorithm for sibling selection using the SAH @@ -254,14 +171,9 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) float areaD = b3Perimeter( boxD ); const b3TreeNode* nodes = tree->nodes; - int nodeIndex = B3_ROOT_NODE; + int rootIndex = tree->root; - if ( b3IsLeaf( nodes + nodeIndex ) ) - { - return nodeIndex; - } - - b3AABB rootBox = nodes[nodeIndex].aabb; + b3AABB rootBox = nodes[rootIndex].aabb; // Area of current node float areaBase = b3Perimeter( rootBox ); @@ -270,14 +182,15 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) float directCost = b3Perimeter( b3AABB_Union( rootBox, boxD ) ); float inheritedCost = 0.0f; - int bestSibling = nodeIndex; + int bestSibling = rootIndex; float bestCost = directCost; - // Descend the tree, following a single greedy path. - for ( ;; ) + // Descend the tree from root, following a single greedy path. + int index = rootIndex; + while ( b3IsLeaf( nodes + index ) == false ) { - int child1 = b3GetLeftChild( nodes + nodeIndex ); - int child2 = child1 + 1; + int child1 = nodes[index].children.child1; + int child2 = nodes[index].children.child2; // Cost of creating a new parent for this node and the new leaf float cost = directCost + inheritedCost; @@ -286,7 +199,7 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) // This breaks the ties using the centroid distance. if ( cost < bestCost ) { - bestSibling = nodeIndex; + bestSibling = index; bestCost = cost; } @@ -306,6 +219,8 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) // Child 1 is a leaf // Cost of creating new node and increasing area of node P float cost1 = directCost1 + inheritedCost; + + // Need this here due to while condition above if ( cost1 < bestCost ) { bestSibling = child1; @@ -317,11 +232,7 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) // Child 1 is an internal node area1 = b3Perimeter( box1 ); - // Lower bound cost of inserting under child 1. The minimum accounts for two possibilities: - // 1. Child1 could be the sibling with cost1 = inheritedCost + directCost1 - // 2. A descendant of child1 could be the sibling with the lower bound cost of - // cost1 = inheritedCost + (directCost1 - area1) + areaD - // This minimum here leads to the minimum of these two costs. + // Lower bound cost of inserting under child 1. lowerCost1 = inheritedCost + directCost1 + b3MinFloat( areaD - area1, 0.0f ); } @@ -332,7 +243,11 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) float area2 = 0.0f; if ( leaf2 ) { + // Child 2 is a leaf + // Cost of creating new node and increasing area of node P float cost2 = directCost2 + inheritedCost; + + // Need this here due to while condition above if ( cost2 < bestCost ) { bestSibling = child2; @@ -341,7 +256,11 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) } else { + // Child 2 is an internal node area2 = b3Perimeter( box2 ); + + // Lower bound cost of inserting under child 2. This is not the cost + // of child 2, it is the best we can hope for under child 2. lowerCost2 = inheritedCost + directCost2 + b3MinFloat( areaD - area2, 0.0f ); } @@ -372,231 +291,504 @@ static int b3FindBestSibling( const b3DynamicTree* tree, b3AABB boxD ) // Descend if ( lowerCost1 < lowerCost2 && leaf1 == false ) { - nodeIndex = child1; + index = child1; areaBase = area1; directCost = directCost1; } else { - nodeIndex = child2; + index = child2; areaBase = area2; directCost = directCost2; } + + B3_ASSERT( b3IsLeaf( nodes + index ) == false ); } return bestSibling; } -// Swap a child of A with a grandchild under the other child. -// Example swapping B with G: -// (A (B (D E) C (F G)) -> (A (G) C (F B (D E)) -static void b3SwapNodes( b3DynamicTree* tree, int iDown, int iUp ) +enum b3RotateType { - b3TreeNode* nodes = tree->nodes; - B3_SWAP( nodes[iDown], nodes[iUp] ); - b3LinkChildren( tree, iDown ); - b3LinkChildren( tree, iUp ); - - if ( b3IsNodeOrdered( nodes, iDown ) == false || b3IsNodeOrdered( nodes, iUp ) == false ) - { - tree->dfsOrdered = false; - } - - // The sibling of the node that went down holds a different subtree now - int iC = iDown ^ 1; - nodes[iC] = b3MakeInternalNode( nodes, b3GetLeftChild( nodes + iC ) ); -} + b3_rotateNone, + b3_rotateBF, + b3_rotateBG, + b3_rotateCD, + b3_rotateCE +}; // Perform a left or right rotation if node A is imbalanced. -// Tree: (A (B (D E) C (F G)) +// Returns the new root index. static void b3RotateNodes( b3DynamicTree* tree, int iA ) { + B3_ASSERT( iA != B3_NULL_INDEX ); + b3TreeNode* nodes = tree->nodes; - const b3TreeNode* A = nodes + iA; - B3_ASSERT( b3IsLeaf( A ) == false ); - int iB = b3GetLeftChild( A ); - int iC = iB + 1; - const b3TreeNode* B = nodes + iB; - const b3TreeNode* C = nodes + iC; - - bool leafB = b3IsLeaf( B ); - bool leafC = b3IsLeaf( C ); - if ( leafB && leafC ) + b3TreeNode* A = nodes + iA; + if ( b3IsLeaf( A ) == true ) { return; } - int bestDown = B3_NULL_INDEX; - int bestUp = B3_NULL_INDEX; - float bestDelta = 0.0f; + int iB = A->children.child1; + int iC = A->children.child2; + B3_ASSERT( 0 <= iB && iB < tree->nodeCapacity ); + B3_ASSERT( 0 <= iC && iC < tree->nodeCapacity ); - if ( leafC == false ) + b3TreeNode* B = nodes + iB; + b3TreeNode* C = nodes + iC; + + bool isLeafB = b3IsLeaf( B ); + bool isLeafC = b3IsLeaf( C ); + + if ( isLeafB == true && isLeafC == false ) { - // Swap B with F or G - int iF = b3GetLeftChild( C ); - int iG = iF + 1; - float areaC = b3Perimeter( C->aabb ); + int iF = C->children.child1; + int iG = C->children.child2; + b3TreeNode* F = nodes + iF; + b3TreeNode* G = nodes + iG; + B3_ASSERT( 0 <= iF && iF < tree->nodeCapacity ); + B3_ASSERT( 0 <= iG && iG < tree->nodeCapacity ); - // B <-> F then C (B G) - float deltaBF = b3Perimeter( b3UnionV( B->aabb, nodes[iG].aabb ) ) - areaC; - if ( deltaBF < bestDelta ) + // Base cost + float costBase = b3Perimeter( C->aabb ); + + // Cost of swapping B and F + b3AABB aabbBG = b3AABB_Union( B->aabb, G->aabb ); + float costBF = b3Perimeter( aabbBG ); + + // Cost of swapping B and G + b3AABB aabbBF = b3AABB_Union( B->aabb, F->aabb ); + float costBG = b3Perimeter( aabbBF ); + + if ( costBase < costBF && costBase < costBG ) { - bestDown = iB; - bestUp = iF; - bestDelta = deltaBF; + // Rotation does not improve cost + return; } - // B <-> G then C (F B) - float deltaBG = b3Perimeter( b3UnionV( B->aabb, nodes[iF].aabb ) ) - areaC; - if ( deltaBG < bestDelta ) + if ( costBF < costBG ) { - bestDown = iB; - bestUp = iG; - bestDelta = deltaBG; + // Swap B and F + A->children.child1 = iF; + C->children.child1 = iB; + + B->parent = iC; + F->parent = iA; + + C->aabb = aabbBG; + + C->height = 1 + b3MaxUInt16( B->height, G->height ); + A->height = 1 + b3MaxUInt16( C->height, F->height ); + C->categoryBits = B->categoryBits | G->categoryBits; + A->categoryBits = C->categoryBits | F->categoryBits; + C->flags |= ( B->flags | G->flags ) & b3_enlargedNode; + A->flags |= ( C->flags | F->flags ) & b3_enlargedNode; + } + else + { + // Swap B and G + A->children.child1 = iG; + C->children.child2 = iB; + + B->parent = iC; + G->parent = iA; + + C->aabb = aabbBF; + + C->height = 1 + b3MaxUInt16( B->height, F->height ); + A->height = 1 + b3MaxUInt16( C->height, G->height ); + C->categoryBits = B->categoryBits | F->categoryBits; + A->categoryBits = C->categoryBits | G->categoryBits; + C->flags |= ( B->flags | F->flags ) & b3_enlargedNode; + A->flags |= ( C->flags | G->flags ) & b3_enlargedNode; } } - - if ( leafB == false ) + else if ( isLeafC == true && isLeafB == false ) { - // Swap C with D or E - int iD = b3GetLeftChild( B ); - int iE = iD + 1; + // C is a leaf and B is internal + + int iD = B->children.child1; + int iE = B->children.child2; + b3TreeNode* D = nodes + iD; + b3TreeNode* E = nodes + iE; + B3_ASSERT( 0 <= iD && iD < tree->nodeCapacity ); + B3_ASSERT( 0 <= iE && iE < tree->nodeCapacity ); + + // Base cost + float costBase = b3Perimeter( B->aabb ); + + // Cost of swapping C and D + b3AABB aabbCE = b3AABB_Union( C->aabb, E->aabb ); + float costCD = b3Perimeter( aabbCE ); + + // Cost of swapping C and E + b3AABB aabbCD = b3AABB_Union( C->aabb, D->aabb ); + float costCE = b3Perimeter( aabbCD ); + + if ( costBase < costCD && costBase < costCE ) + { + // Rotation does not improve cost + return; + } + + if ( costCD < costCE ) + { + // Swap C and D + A->children.child2 = iD; + B->children.child1 = iC; + + C->parent = iB; + D->parent = iA; + + B->aabb = aabbCE; + + B->height = 1 + b3MaxUInt16( C->height, E->height ); + A->height = 1 + b3MaxUInt16( B->height, D->height ); + B->categoryBits = C->categoryBits | E->categoryBits; + A->categoryBits = B->categoryBits | D->categoryBits; + B->flags |= ( C->flags | E->flags ) & b3_enlargedNode; + A->flags |= ( B->flags | D->flags ) & b3_enlargedNode; + } + else + { + // Swap C and E + A->children.child2 = iE; + B->children.child2 = iC; + + C->parent = iB; + E->parent = iA; + + B->aabb = aabbCD; + + B->height = 1 + b3MaxUInt16( C->height, D->height ); + A->height = 1 + b3MaxUInt16( B->height, E->height ); + B->categoryBits = C->categoryBits | D->categoryBits; + A->categoryBits = B->categoryBits | E->categoryBits; + B->flags |= ( C->flags | D->flags ) & b3_enlargedNode; + A->flags |= ( B->flags | E->flags ) & b3_enlargedNode; + } + } + else if ( isLeafB == false && isLeafC == false ) + { + // All grand children exist so there are many options for rotation + int iD = B->children.child1; + int iE = B->children.child2; + int iF = C->children.child1; + int iG = C->children.child2; + + B3_ASSERT( 0 <= iD && iD < tree->nodeCapacity ); + B3_ASSERT( 0 <= iE && iE < tree->nodeCapacity ); + B3_ASSERT( 0 <= iF && iF < tree->nodeCapacity ); + B3_ASSERT( 0 <= iG && iG < tree->nodeCapacity ); + + b3TreeNode* D = nodes + iD; + b3TreeNode* E = nodes + iE; + b3TreeNode* F = nodes + iF; + b3TreeNode* G = nodes + iG; + + // Base cost float areaB = b3Perimeter( B->aabb ); + float areaC = b3Perimeter( C->aabb ); + float costBase = areaB + areaC; + enum b3RotateType bestRotation = b3_rotateNone; + float bestCost = costBase; - // C <-> D then B (C E) - float deltaCD = b3Perimeter( b3UnionV( C->aabb, nodes[iE].aabb ) ) - areaB; - if ( deltaCD < bestDelta ) + // Cost of swapping B and F + b3AABB aabbBG = b3AABB_Union( B->aabb, G->aabb ); + float costBF = areaB + b3Perimeter( aabbBG ); + if ( costBF < bestCost ) { - bestDown = iC; - bestUp = iD; - bestDelta = deltaCD; + bestRotation = b3_rotateBF; + bestCost = costBF; } - // C <-> E then B (D C) - float deltaCE = b3Perimeter( b3UnionV( C->aabb, nodes[iD].aabb ) ) - areaB; - if ( deltaCE < bestDelta ) + // Cost of swapping B and G + b3AABB aabbBF = b3AABB_Union( B->aabb, F->aabb ); + float costBG = areaB + b3Perimeter( aabbBF ); + if ( costBG < bestCost ) { - bestDown = iC; - bestUp = iE; - bestDelta = deltaCE; + bestRotation = b3_rotateBG; + bestCost = costBG; } - } - if ( bestDown != B3_NULL_INDEX ) - { - b3SwapNodes( tree, bestDown, bestUp ); + // Cost of swapping C and D + b3AABB aabbCE = b3AABB_Union( C->aabb, E->aabb ); + float costCD = areaC + b3Perimeter( aabbCE ); + if ( costCD < bestCost ) + { + bestRotation = b3_rotateCD; + bestCost = costCD; + } + + // Cost of swapping C and E + b3AABB aabbCD = b3AABB_Union( C->aabb, D->aabb ); + float costCE = areaC + b3Perimeter( aabbCD ); + if ( costCE < bestCost ) + { + bestRotation = b3_rotateCE; + // bestCost = costCE; + } + + switch ( bestRotation ) + { + case b3_rotateNone: + break; + + case b3_rotateBF: + A->children.child1 = iF; + C->children.child1 = iB; + + B->parent = iC; + F->parent = iA; + + C->aabb = aabbBG; + + C->height = 1 + b3MaxUInt16( B->height, G->height ); + A->height = 1 + b3MaxUInt16( C->height, F->height ); + C->categoryBits = B->categoryBits | G->categoryBits; + A->categoryBits = C->categoryBits | F->categoryBits; + C->flags |= ( B->flags | G->flags ) & b3_enlargedNode; + A->flags |= ( C->flags | F->flags ) & b3_enlargedNode; + break; + + case b3_rotateBG: + A->children.child1 = iG; + C->children.child2 = iB; + + B->parent = iC; + G->parent = iA; + + C->aabb = aabbBF; + + C->height = 1 + b3MaxUInt16( B->height, F->height ); + A->height = 1 + b3MaxUInt16( C->height, G->height ); + C->categoryBits = B->categoryBits | F->categoryBits; + A->categoryBits = C->categoryBits | G->categoryBits; + C->flags |= ( B->flags | F->flags ) & b3_enlargedNode; + A->flags |= ( C->flags | G->flags ) & b3_enlargedNode; + break; + + case b3_rotateCD: + A->children.child2 = iD; + B->children.child1 = iC; + + C->parent = iB; + D->parent = iA; + + B->aabb = aabbCE; + + B->height = 1 + b3MaxUInt16( C->height, E->height ); + A->height = 1 + b3MaxUInt16( B->height, D->height ); + B->categoryBits = C->categoryBits | E->categoryBits; + A->categoryBits = B->categoryBits | D->categoryBits; + B->flags |= ( C->flags | E->flags ) & b3_enlargedNode; + A->flags |= ( B->flags | D->flags ) & b3_enlargedNode; + break; + + case b3_rotateCE: + A->children.child2 = iE; + B->children.child2 = iC; + + C->parent = iB; + E->parent = iA; + + B->aabb = aabbCD; + + B->height = 1 + b3MaxUInt16( C->height, D->height ); + A->height = 1 + b3MaxUInt16( B->height, E->height ); + B->categoryBits = C->categoryBits | D->categoryBits; + A->categoryBits = B->categoryBits | E->categoryBits; + B->flags |= ( C->flags | D->flags ) & b3_enlargedNode; + A->flags |= ( B->flags | E->flags ) & b3_enlargedNode; + break; + + default: + B3_ASSERT( false ); + break; + } } } -static void b3InsertLeaf( b3DynamicTree* tree, b3AABB aabb, int proxyId, bool moved, bool shouldRotate ) +// It would be nicer if the root had zero height but maintaining this would drastically increase +// insertion cost because whole sub-trees would need the height to be updated. +static void b3InsertLeaf( b3DynamicTree* tree, int leaf, bool shouldRotate ) { - b3TreeProxy* proxy = tree->proxies + proxyId; - b3TreeNode leaf = b3MakeLeafNode( aabb, proxyId, proxy->userData, moved ); - - if ( b3IsEmptyNode( tree->nodes + B3_ROOT_NODE ) ) + if ( tree->root == B3_NULL_INDEX ) { - tree->nodes[B3_ROOT_NODE] = leaf; - proxy->node = B3_ROOT_NODE; + tree->root = leaf; + tree->nodes[tree->root].parent = B3_NULL_INDEX; return; } - int sibling = b3FindBestSibling( tree, aabb ); + // Stage 1: find the best sibling for this node + b3AABB leafAABB = tree->nodes[leaf].aabb; + int sibling = b3FindBestSibling( tree, leafAABB ); - // The sibling's position becomes the new parent. The sibling moves down into a new pair - // beside the leaf, which puts it below its own children when it is internal. - int pair = b3AllocateSiblingPair( tree ); + // Stage 2: create a new parent for the leaf and sibling + int oldParent = tree->nodes[sibling].parent; + int newParent = b3AllocateNode( tree ); + + // warning: node pointer can change after allocation b3TreeNode* nodes = tree->nodes; - int32_t* parents = tree->parents; + nodes[newParent].parent = oldParent; + nodes[newParent].userData = UINT64_MAX; + nodes[newParent].aabb = b3AABB_Union( leafAABB, nodes[sibling].aabb ); + nodes[newParent].categoryBits = nodes[leaf].categoryBits | nodes[sibling].categoryBits; + nodes[newParent].height = nodes[sibling].height + 1; - nodes[pair] = nodes[sibling]; - nodes[pair + 1] = leaf; - parents[pair] = sibling; - parents[pair + 1] = sibling; - b3LinkChildren( tree, pair ); - proxy->node = pair + 1; - - nodes[sibling] = b3MakeInternalNode( nodes, pair ); - - if ( b3IsNodeOrdered( nodes, sibling ) == false || b3IsNodeOrdered( nodes, pair ) == false ) + if ( oldParent != B3_NULL_INDEX ) { - tree->dfsOrdered = false; + // The sibling was not the root. + if ( nodes[oldParent].children.child1 == sibling ) + { + nodes[oldParent].children.child1 = newParent; + } + else + { + nodes[oldParent].children.child2 = newParent; + } + + nodes[newParent].children.child1 = sibling; + nodes[newParent].children.child2 = leaf; + nodes[sibling].parent = newParent; + nodes[leaf].parent = newParent; + } + else + { + // The sibling was the root. + nodes[newParent].children.child1 = sibling; + nodes[newParent].children.child2 = leaf; + nodes[sibling].parent = newParent; + nodes[leaf].parent = newParent; + tree->root = newParent; } - // Walk back up the tree refitting ancestors, the root included. - int index = sibling; + // Stage 3: walk back up the tree fixing heights and AABBs + int index = nodes[leaf].parent; while ( index != B3_NULL_INDEX ) { + int child1 = nodes[index].children.child1; + int child2 = nodes[index].children.child2; + + B3_ASSERT( child1 != B3_NULL_INDEX ); + B3_ASSERT( child2 != B3_NULL_INDEX ); + + nodes[index].aabb = b3AABB_Union( nodes[child1].aabb, nodes[child2].aabb ); + nodes[index].categoryBits = nodes[child1].categoryBits | nodes[child2].categoryBits; + nodes[index].height = 1 + b3MaxUInt16( nodes[child1].height, nodes[child2].height ); + nodes[index].flags |= ( nodes[child1].flags | nodes[child2].flags ) & b3_enlargedNode; + if ( shouldRotate ) { b3RotateNodes( tree, index ); } - nodes[index] = b3MakeInternalNode( nodes, b3GetLeftChild( nodes + index ) ); - index = parents[index]; + index = nodes[index].parent; } } -static void b3RemoveLeaf( b3DynamicTree* tree, int proxyId ) +static void b3RemoveLeaf( b3DynamicTree* tree, int leaf ) { - b3TreeNode* nodes = tree->nodes; - int32_t* parents = tree->parents; - - int leaf = tree->proxies[proxyId].node; - B3_ASSERT( 0 <= leaf && leaf < tree->nodeEnd ); - B3_ASSERT( b3IsLeaf( nodes + leaf ) && b3GetProxyId( nodes + leaf ) == proxyId ); - - if ( leaf == B3_ROOT_NODE ) + if ( leaf == tree->root ) { - nodes[B3_ROOT_NODE] = b3MakeEmptyNode(); + tree->root = B3_NULL_INDEX; return; } - // The sibling takes the parent's position and the pair is freed. This keeps the order, - // the sibling only moves down. - int parent = parents[leaf]; - nodes[parent] = nodes[leaf ^ 1]; - b3LinkChildren( tree, parent ); - b3FreePair( tree, leaf & ~1 ); + b3TreeNode* nodes = tree->nodes; - // Update ancestors. - int index = parents[parent]; - while ( index != B3_NULL_INDEX ) + int parent = nodes[leaf].parent; + int grandParent = nodes[parent].parent; + int sibling; + if ( nodes[parent].children.child1 == leaf ) { - nodes[index] = b3MakeInternalNode( nodes, b3GetLeftChild( nodes + index ) ); - index = parents[index]; + sibling = nodes[parent].children.child2; + } + else + { + sibling = nodes[parent].children.child1; + } + + if ( grandParent != B3_NULL_INDEX ) + { + // Destroy parent and connect sibling to grandParent. + if ( nodes[grandParent].children.child1 == parent ) + { + nodes[grandParent].children.child1 = sibling; + } + else + { + nodes[grandParent].children.child2 = sibling; + } + nodes[sibling].parent = grandParent; + b3FreeNode( tree, parent ); + + // Adjust ancestor bounds. + int index = grandParent; + while ( index != B3_NULL_INDEX ) + { + b3TreeNode* node = nodes + index; + b3TreeNode* child1 = nodes + node->children.child1; + b3TreeNode* child2 = nodes + node->children.child2; + + // Fast union using SSE + //__m128 aabb1 = _mm_load_ps(&child1->aabb.lowerBound.x); + //__m128 aabb2 = _mm_load_ps(&child2->aabb.lowerBound.x); + //__m128 lower = _mm_min_ps(aabb1, aabb2); + //__m128 upper = _mm_max_ps(aabb1, aabb2); + //__m128 aabb = _mm_shuffle_ps(lower, upper, _MM_SHUFFLE(3, 2, 1, 0)); + //_mm_store_ps(&node->aabb.lowerBound.x, aabb); + + node->aabb = b3AABB_Union( child1->aabb, child2->aabb ); + node->categoryBits = child1->categoryBits | child2->categoryBits; + node->height = 1 + b3MaxUInt16( child1->height, child2->height ); + + index = node->parent; + } + } + else + { + tree->root = sibling; + tree->nodes[sibling].parent = B3_NULL_INDEX; + b3FreeNode( tree, parent ); } } // Create a proxy in the tree as a leaf node. We return the index of the node instead of a pointer so that we can grow // the node pool. -int b3CreateTreeProxyInternal( b3DynamicTree* tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData, bool markMoved ) +int b3DynamicTree_CreateProxy( b3DynamicTree* tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData ) { - B3_VALIDATE( b3IsValidAABB( aabb ) ); + B3_ASSERT( b3IsValidAABB( aabb ) ); - int proxyId = b3AllocateProxy( tree ); + int proxyId = b3AllocateNode( tree ); + b3TreeNode* node = tree->nodes + proxyId; - b3TreeProxy* proxy = tree->proxies + proxyId; - proxy->categoryBits = categoryBits; - proxy->userData = userData; + node->aabb = aabb; + node->userData = userData; + node->categoryBits = categoryBits; + node->height = 0; + node->flags = b3_allocatedNode | b3_leafNode; bool shouldRotate = true; - b3InsertLeaf( tree, aabb, proxyId, markMoved, shouldRotate ); + b3InsertLeaf( tree, proxyId, shouldRotate ); + + tree->proxyCount += 1; return proxyId; } -int b3DynamicTree_CreateProxy( b3DynamicTree* tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData ) -{ - return b3CreateTreeProxyInternal( tree, aabb, categoryBits, userData, false ); -} - void b3DynamicTree_DestroyProxy( b3DynamicTree* tree, int proxyId ) { - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); + B3_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); + B3_ASSERT( b3IsLeaf( tree->nodes + proxyId ) ); b3RemoveLeaf( tree, proxyId ); - b3FreeProxy( tree, proxyId ); + b3FreeNode( tree, proxyId ); + + B3_ASSERT( tree->proxyCount > 0 ); + tree->proxyCount -= 1; } int b3DynamicTree_GetProxyCount( const b3DynamicTree* tree ) @@ -604,56 +796,43 @@ int b3DynamicTree_GetProxyCount( const b3DynamicTree* tree ) return tree->proxyCount; } -void b3DynamicTree_MoveProxyInternal( b3DynamicTree* tree, int proxyId, b3AABB aabb, bool markMoved ) +void b3DynamicTree_MoveProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb ) { - B3_VALIDATE( b3IsValidAABB( aabb ) ); - B3_VALIDATE( aabb.upperBound.x - aabb.lowerBound.x < B3_HUGE ); - B3_VALIDATE( aabb.upperBound.y - aabb.lowerBound.y < B3_HUGE ); - B3_VALIDATE( aabb.upperBound.z - aabb.lowerBound.z < B3_HUGE ); - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); + B3_ASSERT( b3IsValidAABB( aabb ) ); + B3_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); + B3_ASSERT( b3IsLeaf( tree->nodes + proxyId ) ); b3RemoveLeaf( tree, proxyId ); - bool shouldRotate = false; - b3InsertLeaf( tree, aabb, proxyId, markMoved, shouldRotate ); -} + tree->nodes[proxyId].aabb = aabb; -void b3DynamicTree_MoveProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb ) -{ - b3DynamicTree_MoveProxyInternal( tree, proxyId, aabb, false ); + bool shouldRotate = false; + b3InsertLeaf( tree, proxyId, shouldRotate ); } void b3DynamicTree_EnlargeProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb ) { - B3_VALIDATE( b3IsValidAABB( aabb ) ); - B3_VALIDATE( aabb.upperBound.x - aabb.lowerBound.x < B3_HUGE ); - B3_VALIDATE( aabb.upperBound.y - aabb.lowerBound.y < B3_HUGE ); - B3_VALIDATE( aabb.upperBound.z - aabb.lowerBound.z < B3_HUGE ); - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); - b3TreeNode* nodes = tree->nodes; - const int32_t* parents = tree->parents; - - int index = tree->proxies[proxyId].node; - b3TreeNode* node = nodes + index; - B3_ASSERT( b3IsLeaf( node ) ); + B3_VALIDATE( b3IsValidAABB( aabb ) ); + B3_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); + B3_VALIDATE( b3IsLeaf( tree->nodes + proxyId ) ); // Caller must ensure this - B3_VALIDATE( b3AABB_Contains( node->aabb, aabb ) == false ); + B3_VALIDATE( b3AABB_Contains( nodes[proxyId].aabb, aabb ) == false ); + b3TreeNode* node = nodes + proxyId; node->aabb = aabb; - node->flagIndex |= B3_MOVED_NODE; - index = parents[index]; - while ( index != B3_NULL_INDEX ) + int parentIndex = node->parent; + while ( parentIndex != B3_NULL_INDEX ) { - node = nodes + index; + node = nodes + parentIndex; bool changed = b3EnlargeAABB( &node->aabb, aabb ); - // This is marked to ensure the root is marked in this loop or the one below. - node->flagIndex |= B3_MOVED_NODE; + // todo not sure why this node is marked as enlarged even if it didn't change + node->flags |= b3_enlargedNode; - index = parents[index]; + parentIndex = node->parent; if ( changed == false ) { @@ -661,179 +840,246 @@ void b3DynamicTree_EnlargeProxy( b3DynamicTree* tree, int proxyId, b3AABB aabb ) } } - // Mark all the way up to the root. - while ( index != B3_NULL_INDEX ) + while ( parentIndex != B3_NULL_INDEX ) { - node = nodes + index; - if ( node->flagIndex & B3_MOVED_NODE ) + node = nodes + parentIndex; + if ( node->flags & b3_enlargedNode ) { - // Early out because this ancestor was previously ascended and marked as moved. + // early out because this ancestor was previously ascended and marked as enlarged break; } - node->flagIndex |= B3_MOVED_NODE; - index = parents[index]; + node->flags |= b3_enlargedNode; + parentIndex = node->parent; } } void b3DynamicTree_SetCategoryBits( b3DynamicTree* tree, int proxyId, uint64_t categoryBits ) { - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); - tree->proxies[proxyId].categoryBits = categoryBits; + b3TreeNode* nodes = tree->nodes; + + B3_ASSERT( b3IsLeaf( nodes + proxyId ) ); + + nodes[proxyId].categoryBits = categoryBits; + + // Fix up category bits in ancestor internal nodes + int nodeIndex = nodes[proxyId].parent; + while ( nodeIndex != B3_NULL_INDEX ) + { + b3TreeNode* node = nodes + nodeIndex; + int child1 = node->children.child1; + B3_ASSERT( child1 != B3_NULL_INDEX ); + int child2 = node->children.child2; + B3_ASSERT( child2 != B3_NULL_INDEX ); + node->categoryBits = nodes[child1].categoryBits | nodes[child2].categoryBits; + + nodeIndex = node->parent; + } } uint64_t b3DynamicTree_GetCategoryBits( b3DynamicTree* tree, int proxyId ) { - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); - return tree->proxies[proxyId].categoryBits; + B3_ASSERT( 0 <= proxyId && proxyId < tree->nodeCapacity ); + return tree->nodes[proxyId].categoryBits; } int b3DynamicTree_GetHeight( const b3DynamicTree* tree ) { - return b3GetNodeHeight( tree->nodes + B3_ROOT_NODE ); + if ( tree->root == B3_NULL_INDEX ) + { + return 0; + } + + return tree->nodes[tree->root].height; } -// The area ratio is the thing that SAH seeks to minimize. SAH -// cannot do anything about leaf boxes or the root box. It seeks -// to minimize the area of all non-root internal nodes. Divide this -// by the root area to make the metric non-dimensional. -// So this becomes a meaningful measure of tree quality. float b3DynamicTree_GetAreaRatio( const b3DynamicTree* tree ) { - if ( tree->proxyCount == 0 ) + if ( tree->root == B3_NULL_INDEX ) { return 0.0f; } - const b3TreeNode* nodes = tree->nodes; - float rootArea = b3Perimeter( nodes[B3_ROOT_NODE].aabb ); - if ( rootArea <= 0.0f ) - { - return 0.0f; - } + const b3TreeNode* root = tree->nodes + tree->root; + float rootArea = b3Perimeter( root->aabb ); - // Free nodes and the empty node are leaf tagged. - float internalArea = 0.0f; - int nodeEnd = tree->nodeEnd; - for ( int i = 2; i < nodeEnd; ++i ) + float totalArea = 0.0f; + for ( int i = 0; i < tree->nodeCapacity; ++i ) { - if ( b3IsLeaf( nodes + i ) == false ) + const b3TreeNode* node = tree->nodes + i; + if ( b3IsAllocated( node ) == false || b3IsLeaf( node ) || i == tree->root ) { - internalArea += b3Perimeter( nodes[i].aabb ); + continue; } + + totalArea += b3Perimeter( node->aabb ); } - return internalArea / rootArea; + return totalArea / rootArea; } b3AABB b3DynamicTree_GetRootBounds( const b3DynamicTree* tree ) { - if ( tree->proxyCount == 0 ) + if ( tree->root != B3_NULL_INDEX ) { - return B3_LITERAL( b3AABB ){ b3Vec3_zero, b3Vec3_zero }; + return tree->nodes[tree->root].aabb; } - return tree->nodes[B3_ROOT_NODE].aabb; + b3AABB empty = { b3Vec3_zero, b3Vec3_zero }; + return empty; } #if B3_ENABLE_VALIDATION - -static int b3ValidateSubtree( const b3DynamicTree* tree, int nodeIndex, int* leafCount ) +// Compute the height of a sub-tree. +static int b3ComputeHeightRecurse( const b3DynamicTree* tree, int nodeId ) { - B3_ASSERT( 0 <= nodeIndex && nodeIndex < tree->nodeEnd ); - const b3TreeNode* node = tree->nodes + nodeIndex; - B3_ASSERT( b3IsEmptyNode( node ) == false ); - B3_ASSERT( b3IsValidAABB( node->aabb ) ); + B3_ASSERT( 0 <= nodeId && nodeId < tree->nodeCapacity ); + b3TreeNode* node = tree->nodes + nodeId; if ( b3IsLeaf( node ) ) { - int proxyId = b3GetProxyId( node ); - B3_ASSERT( 0 <= proxyId && proxyId < tree->proxyCapacity ); - B3_ASSERT( tree->proxies[proxyId].node == nodeIndex ); - B3_ASSERT( (int32_t)(uint32_t)tree->proxies[proxyId].userData == node->shapeIndex ); - *leafCount += 1; return 0; } - int pair = b3GetLeftChild( node ); - B3_ASSERT( ( pair & 1 ) == 0 && 2 <= pair && pair < tree->nodeEnd ); - B3_ASSERT( tree->parents[pair] == nodeIndex ); - B3_ASSERT( tree->parents[pair + 1] == nodeIndex ); - B3_ASSERT( tree->dfsOrdered == false || nodeIndex < pair ); + int height1 = b3ComputeHeightRecurse( tree, node->children.child1 ); + int height2 = b3ComputeHeightRecurse( tree, node->children.child2 ); + return 1 + b3MaxInt( height1, height2 ); +} - const b3TreeNode* c1 = tree->nodes + pair; - const b3TreeNode* c2 = tree->nodes + pair + 1; - B3_ASSERT( b3AABB_Contains( node->aabb, c1->aabb ) ); - B3_ASSERT( b3AABB_Contains( node->aabb, c2->aabb ) ); - B3_ASSERT( b3IsNodeMoved( node ) == ( b3IsNodeMoved( c1 ) || b3IsNodeMoved( c2 ) ) ); - - // A bad tree can stack overflow, but that is validation on its own. - int height1 = b3ValidateSubtree( tree, pair, leafCount ); - int height2 = b3ValidateSubtree( tree, pair + 1, leafCount ); - int height = 1 + b3MaxInt( height1, height2 ); - B3_ASSERT( node->height == height ); +static int b3ComputeHeight( const b3DynamicTree* tree ) +{ + int height = b3ComputeHeightRecurse( tree, tree->root ); return height; } +static void b3ValidateStructure( const b3DynamicTree* tree, int index ) +{ + if ( index == B3_NULL_INDEX ) + { + return; + } + + if ( index == tree->root ) + { + B3_ASSERT( tree->nodes[index].parent == B3_NULL_INDEX ); + } + + const b3TreeNode* node = tree->nodes + index; + + B3_ASSERT( node->flags == 0 || ( node->flags & b3_allocatedNode ) != 0 ); + + if ( b3IsLeaf( node ) ) + { + B3_ASSERT( node->height == 0 ); + return; + } + + int child1 = node->children.child1; + int child2 = node->children.child2; + + B3_ASSERT( 0 <= child1 && child1 < tree->nodeCapacity ); + B3_ASSERT( 0 <= child2 && child2 < tree->nodeCapacity ); + + B3_ASSERT( tree->nodes[child1].parent == index ); + B3_ASSERT( tree->nodes[child2].parent == index ); + + if ( ( tree->nodes[child1].flags | tree->nodes[child2].flags ) & b3_enlargedNode ) + { + B3_ASSERT( node->flags & b3_enlargedNode ); + } + + b3ValidateStructure( tree, child1 ); + b3ValidateStructure( tree, child2 ); +} + +static void b3ValidateMetrics( const b3DynamicTree* tree, int index ) +{ + if ( index == B3_NULL_INDEX ) + { + return; + } + + const b3TreeNode* node = tree->nodes + index; + + B3_VALIDATE( b3IsValidAABB( node->aabb ) ); + + if ( b3IsLeaf( node ) ) + { + B3_ASSERT( node->height == 0 ); + return; + } + + int child1 = node->children.child1; + int child2 = node->children.child2; + + B3_ASSERT( 0 <= child1 && child1 < tree->nodeCapacity ); + B3_ASSERT( 0 <= child2 && child2 < tree->nodeCapacity ); + + int height1 = tree->nodes[child1].height; + int height2 = tree->nodes[child2].height; + int height = 1 + b3MaxInt( height1, height2 ); + B3_ASSERT( node->height == height ); + + // b3AABB aabb = b3AABB_Union(tree->nodes[child1].aabb, tree->nodes[child2].aabb); + + B3_ASSERT( b3AABB_Contains( node->aabb, tree->nodes[child1].aabb ) ); + B3_ASSERT( b3AABB_Contains( node->aabb, tree->nodes[child2].aabb ) ); + + // B3_ASSERT(aabb.lowerBound.x == node->aabb.lowerBound.x); + // B3_ASSERT(aabb.lowerBound.y == node->aabb.lowerBound.y); + // B3_ASSERT(aabb.upperBound.x == node->aabb.upperBound.x); + // B3_ASSERT(aabb.upperBound.y == node->aabb.upperBound.y); + + uint64_t categoryBits = tree->nodes[child1].categoryBits | tree->nodes[child2].categoryBits; + B3_ASSERT( node->categoryBits == categoryBits ); + + b3ValidateMetrics( tree, child1 ); + b3ValidateMetrics( tree, child2 ); +} #endif void b3DynamicTree_Validate( const b3DynamicTree* tree ) { #if B3_ENABLE_VALIDATION - B3_ASSERT( 2 <= tree->nodeEnd && tree->nodeEnd <= tree->nodeCapacity ); - B3_ASSERT( ( tree->nodeEnd & 1 ) == 0 ); - B3_ASSERT( tree->parents[B3_ROOT_NODE] == B3_NULL_INDEX ); - B3_ASSERT( b3IsEmptyNode( tree->nodes + B3_ROOT_NODE + 1 ) ); - - int freePairCount = 0; - int pair = tree->pairFreeList; - while ( pair != B3_NULL_INDEX ) + if ( tree->root == B3_NULL_INDEX ) { - B3_ASSERT( ( pair & 1 ) == 0 && 2 <= pair && pair < tree->nodeEnd ); - B3_ASSERT( b3IsEmptyNode( tree->nodes + pair ) ); - B3_ASSERT( b3IsEmptyNode( tree->nodes + pair + 1 ) ); - pair = tree->parents[pair]; - ++freePairCount; - B3_ASSERT( 2 * freePairCount < tree->nodeEnd ); - } - - // Validate proxy free list. - int freeProxyCount = 0; - int freeIndex = tree->proxyFreeList; - while ( freeIndex != B3_NULL_INDEX ) - { - B3_ASSERT( 0 <= freeIndex && freeIndex < tree->proxyCapacity ); - B3_ASSERT( tree->proxies[freeIndex].node == B3_NULL_INDEX ); - freeIndex = tree->proxies[freeIndex].next; - ++freeProxyCount; - } - B3_ASSERT( tree->proxyCount + freeProxyCount == tree->proxyCapacity ); - - B3_ASSERT( tree->nodeEnd == 2 * b3MaxInt( tree->proxyCount, 1 ) + 2 * freePairCount ); - - if ( tree->proxyCount == 0 ) - { - B3_ASSERT( b3IsEmptyNode( tree->nodes + B3_ROOT_NODE ) ); return; } - int leafCount = 0; - b3ValidateSubtree( tree, B3_ROOT_NODE, &leafCount ); - B3_ASSERT( leafCount == tree->proxyCount ); + b3ValidateStructure( tree, tree->root ); + b3ValidateMetrics( tree, tree->root ); + int freeCount = 0; + int freeIndex = tree->freeList; + while ( freeIndex != B3_NULL_INDEX ) + { + B3_ASSERT( 0 <= freeIndex && freeIndex < tree->nodeCapacity ); + freeIndex = tree->nodes[freeIndex].next; + ++freeCount; + } + + int height = b3DynamicTree_GetHeight( tree ); + int computedHeight = b3ComputeHeight( tree ); + B3_ASSERT( height == computedHeight ); + + B3_ASSERT( tree->nodeCount + freeCount == tree->nodeCapacity ); #else B3_UNUSED( tree ); #endif } -void b3DynamicTree_ValidateNoMoved( const b3DynamicTree* tree ) +void b3DynamicTree_ValidateNoEnlarged( const b3DynamicTree* tree ) { #if B3_ENABLE_VALIDATION == 1 + int capacity = tree->nodeCapacity; const b3TreeNode* nodes = tree->nodes; - int nodeEnd = tree->nodeEnd; - for ( int i = 0; i < nodeEnd; ++i ) + for ( int i = 0; i < capacity; ++i ) { - B3_ASSERT( b3IsNodeMoved( nodes + i ) == false ); + const b3TreeNode* node = nodes + i; + if ( node->flags & b3_allocatedNode ) + { + B3_ASSERT( ( node->flags & b3_enlargedNode ) == 0 ); + } } #else B3_UNUSED( tree ); @@ -842,85 +1088,48 @@ void b3DynamicTree_ValidateNoMoved( const b3DynamicTree* tree ) int b3DynamicTree_GetByteCount( const b3DynamicTree* tree ) { - size_t size = sizeof( b3DynamicTree ); - size += tree->nodeCapacity * sizeof( b3TreeNode ); - size += tree->nodeCapacity * sizeof( int32_t ); - size += tree->proxyCapacity * sizeof( b3TreeProxy ); - size += tree->swapNodes == NULL ? 0 : tree->nodeCapacity * sizeof( b3TreeNode ); - - // leafIndices - size += tree->rebuildCapacity * sizeof( int32_t ); - // leafNodes - size += tree->rebuildCapacity * sizeof( b3TreeNode ); - // leafBoxes - size += tree->rebuildCapacity * sizeof( b3AABB ); - // leafCenters - size += tree->rebuildCapacity * sizeof( b3Vec3 ); - // binIndices - size += tree->rebuildCapacity * sizeof( int32_t ); + size_t size = sizeof( b3DynamicTree ) + sizeof( b3TreeNode ) * tree->nodeCapacity + + tree->rebuildCapacity * ( sizeof( int ) + sizeof( b3AABB ) + sizeof( b3Vec3 ) + sizeof( int ) ); return (int)size; } -B3_FORCE_INLINE bool b3TestCategory( uint64_t categoryBits, uint64_t maskBits, bool requireAllBits ) -{ - return requireAllBits ? ( categoryBits & maskBits ) == maskBits : ( categoryBits & maskBits ) != 0; -} - -B3_FORCE_INLINE uint32_t b3LoadNodeFlags( const b3TreeNode* node, bool relaxedFlags ) -{ - return relaxedFlags ? b3AtomicLoadU32Raw( &node->flagIndex ) : node->flagIndex; -} - -B3_FORCE_INLINE b3TreeStats b3QueryTreeView( const b3TreeView* view, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context, bool hasProxies, - bool relaxedFlags ) +b3TreeStats b3DynamicTree_Query( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, + b3TreeQueryCallbackFcn* callback, void* context ) { b3TreeStats result = { 0 }; - const b3TreeNode* nodes = view->nodes; - - uint32_t rootFlags = b3LoadNodeFlags( nodes + B3_ROOT_NODE, relaxedFlags ); - if ( rootFlags == B3_EMPTY_NODE ) + if ( tree->nodeCount == 0 ) { return result; } int stack[B3_TREE_STACK_SIZE]; int stackCount = 0; - stack[stackCount++] = ( rootFlags & B3_LEAF_NODE ) ? B3_ROOT_NODE : (int)( rootFlags & B3_NODE_INDEX_MASK ); - - b3AABBV boxv = b3LoadAABBV( &aabb ); + stack[stackCount++] = tree->root; while ( stackCount > 0 ) { - int pair = stack[--stackCount]; + int nodeId = stack[--stackCount]; + if ( nodeId == B3_NULL_INDEX ) + { + // todo huh? + B3_ASSERT( false ); + continue; + } + + const b3TreeNode* node = tree->nodes + nodeId; result.nodeVisits += 1; - for ( int i = 0; i < 2; ++i ) + // Assuming branch prediction deals with requireAllBits well + uint64_t bitMatch = requireAllBits ? ( node->categoryBits & maskBits ) == maskBits : ( node->categoryBits & maskBits ); + + if ( bitMatch && b3AABB_Overlaps( node->aabb, aabb ) ) { - const b3TreeNode* node = nodes + pair + i; - if ( b3OverlapNode( boxv, node ) == false ) + if ( b3IsLeaf( node ) ) { - continue; - } - - uint32_t flags = b3LoadNodeFlags( node, relaxedFlags ); - if ( flags & B3_LEAF_NODE ) - { - int proxyId = (int)( flags & B3_NODE_INDEX_MASK ); - uint64_t userData = (uint64_t)(uint32_t)node->shapeIndex; - if ( hasProxies ) - { - const b3TreeProxy* proxy = view->proxies + proxyId; - if ( b3TestCategory( proxy->categoryBits, maskBits, requireAllBits ) == false ) - { - continue; - } - userData = proxy->userData; - } - - bool proceed = callback( proxyId, userData, context ); + // callback to user code with proxy id + bool proceed = callback( nodeId, node->userData, context ); result.leafVisits += 1; if ( proceed == false ) @@ -930,13 +1139,11 @@ B3_FORCE_INLINE b3TreeStats b3QueryTreeView( const b3TreeView* view, b3AABB aabb } else { + B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); if ( stackCount < B3_TREE_STACK_SIZE - 1 ) { - stack[stackCount++] = (int)( flags & B3_NODE_INDEX_MASK ); - } - else - { - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + stack[stackCount++] = node->children.child1; + stack[stackCount++] = node->children.child2; } } } @@ -957,119 +1164,83 @@ struct b3QueryClosestItem float distanceToNodeSqr; }; -B3_FORCE_INLINE b3TreeStats b3QueryClosestTreeView( const b3TreeView* view, b3Vec3 point, uint64_t maskBits, bool requireAllBits, - b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr, - bool hasProxies ) +b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits, + b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr ) { b3TreeStats result = { 0 }; - if ( b3IsEmptyNode( view->nodes + B3_ROOT_NODE ) ) + if ( tree->nodeCount == 0 ) { return result; } - const b3TreeNode* nodes = view->nodes; - float minSqr = *minDistanceSqr; struct b3QueryClosestItem stack[B3_TREE_STACK_SIZE]; int stackCount = 0; - int rootPair = b3GetRootPair( nodes ); - struct b3QueryClosestItem seed1 = { - .nodeIndex = rootPair, - .distanceToNodeSqr = b3DistanceToNodeSqr( point, nodes + rootPair ), + float rootDistanceSqr = b3DistanceToNodeSqr( point, tree->nodes + tree->root ); + stack[stackCount++] = (struct b3QueryClosestItem){ + .nodeIndex = tree->root, + .distanceToNodeSqr = rootDistanceSqr, }; - if ( rootPair == B3_ROOT_NODE ) - { - stack[stackCount++] = seed1; - } - else - { - struct b3QueryClosestItem seed2 = { - .nodeIndex = rootPair + 1, - .distanceToNodeSqr = b3DistanceToNodeSqr( point, nodes + rootPair + 1 ), - }; - - // Ensure we iterate the closest child first as we pop off the stack - if ( seed2.distanceToNodeSqr < seed1.distanceToNodeSqr ) - { - stack[stackCount++] = seed1; - stack[stackCount++] = seed2; - } - else - { - stack[stackCount++] = seed2; - stack[stackCount++] = seed1; - } - } - while ( stackCount > 0 ) { struct b3QueryClosestItem item = stack[--stackCount]; - const b3TreeNode* node = nodes + item.nodeIndex; + const b3TreeNode* node = tree->nodes + item.nodeIndex; result.nodeVisits += 1; - if ( item.distanceToNodeSqr >= minSqr ) - { - continue; - } + uint64_t bitMatch = requireAllBits ? ( node->categoryBits & maskBits ) == maskBits : ( node->categoryBits & maskBits ); - if ( b3IsLeaf( node ) ) + if ( bitMatch ) { - int proxyId = b3GetProxyId( node ); - uint64_t userData = (uint64_t)(uint32_t)node->shapeIndex; - if ( hasProxies ) + if ( item.distanceToNodeSqr < minSqr ) { - const b3TreeProxy* proxy = view->proxies + proxyId; - if ( b3TestCategory( proxy->categoryBits, maskBits, requireAllBits ) == false ) + if ( b3IsLeaf( node ) ) { - continue; + // callback to user code with minimum distance squared so far and proxy id + float dd = callback( minSqr, item.nodeIndex, node->userData, context ); + + if ( dd < minSqr ) + { + minSqr = dd; + } + + result.leafVisits += 1; + } + else + { + B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + if ( stackCount < B3_TREE_STACK_SIZE - 1 ) + { + int child1 = node->children.child1; + int child2 = node->children.child2; + + // Store the distance to node in the stack instead of recomputing after pop + struct b3QueryClosestItem item1 = { + .nodeIndex = child1, + .distanceToNodeSqr = b3DistanceToNodeSqr( point, tree->nodes + child1 ), + }; + + struct b3QueryClosestItem item2 = { + .nodeIndex = child2, + .distanceToNodeSqr = b3DistanceToNodeSqr( point, tree->nodes + child2 ), + }; + + // Ensure we iterate the closest child first as we pop off the stack + if ( item2.distanceToNodeSqr < item1.distanceToNodeSqr ) + { + stack[stackCount++] = item1; + stack[stackCount++] = item2; + } + else + { + stack[stackCount++] = item2; + stack[stackCount++] = item1; + } + } } - userData = proxy->userData; } - - // callback to user code with minimum distance squared so far and proxy id - float dd = callback( minSqr, proxyId, userData, context ); - - if ( dd < minSqr ) - { - minSqr = dd; - } - - result.leafVisits += 1; - continue; - } - - if ( stackCount + 2 > B3_TREE_STACK_SIZE ) - { - B3_ASSERT( stackCount + 2 <= B3_TREE_STACK_SIZE ); - continue; - } - - int pair = b3GetLeftChild( node ); - - // Store the distance to node in the stack instead of recomputing after pop - struct b3QueryClosestItem item1 = { - .nodeIndex = pair, - .distanceToNodeSqr = b3DistanceToNodeSqr( point, nodes + pair ), - }; - - struct b3QueryClosestItem item2 = { - .nodeIndex = pair + 1, - .distanceToNodeSqr = b3DistanceToNodeSqr( point, nodes + pair + 1 ), - }; - - // Ensure we iterate the closest child first as we pop off the stack - if ( item2.distanceToNodeSqr < item1.distanceToNodeSqr ) - { - stack[stackCount++] = item1; - stack[stackCount++] = item2; - } - else - { - stack[stackCount++] = item2; - stack[stackCount++] = item1; } } @@ -1078,18 +1249,12 @@ B3_FORCE_INLINE b3TreeStats b3QueryClosestTreeView( const b3TreeView* view, b3Ve return result; } -// A lot of optimization work went into this. The children of a popped pair are both tested -// before either is followed, then the survivors are ordered so the closer one narrows first. -B3_FORCE_INLINE b3TreeStats b3RayCastTreeView( const b3TreeView* view, const b3RayCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeRayCastCallbackFcn* callback, void* context, - bool hasProxies, bool relaxedFlags ) +b3TreeStats b3DynamicTree_RayCast( const b3DynamicTree* tree, const b3RayCastInput* input, uint64_t maskBits, bool requireAllBits, + b3TreeRayCastCallbackFcn* callback, void* context ) { b3TreeStats result = { 0 }; - const b3TreeNode* nodes = view->nodes; - - uint32_t rootFlags = b3LoadNodeFlags( nodes + B3_ROOT_NODE, relaxedFlags ); - if ( rootFlags == B3_EMPTY_NODE ) + if ( tree->nodeCount == 0 ) { return result; } @@ -1106,110 +1271,87 @@ B3_FORCE_INLINE b3TreeStats b3RayCastTreeView( const b3TreeView* view, const b3R // Build a bounding box for the segment. b3AABB segmentAABB = { b3Min( p1, p2 ), b3Max( p1, p2 ) }; - b3AABBV boxv = b3LoadAABBV( &segmentAABB ); int stack[B3_TREE_STACK_SIZE]; int stackCount = 0; - stack[stackCount++] = ( rootFlags & B3_LEAF_NODE ) ? B3_ROOT_NODE : (int)( rootFlags & B3_NODE_INDEX_MASK ); + stack[stackCount++] = tree->root; + + const b3TreeNode* nodes = tree->nodes; b3RayCastInput subInput = *input; while ( stackCount > 0 ) { - int pair = stack[--stackCount]; + int nodeId = stack[--stackCount]; + if ( nodeId == B3_NULL_INDEX ) + { + // todo is this possible? + B3_ASSERT( false ); + continue; + } + + const b3TreeNode* node = nodes + nodeId; result.nodeVisits += 1; - const b3TreeNode* hit[2]; - bool isLeaf[2]; - int index[2]; - int hitCount = 0; - for ( int i = 0; i < 2; ++i ) + b3AABB nodeAABB = node->aabb; + + // todo look at disassembly + uint64_t bitMatch = requireAllBits ? ( node->categoryBits & maskBits ) == maskBits : ( node->categoryBits & maskBits ); + + if ( bitMatch == 0 || b3AABB_Overlaps( nodeAABB, segmentAABB ) == false ) { - const b3TreeNode* node = nodes + pair + i; - - if ( b3OverlapNode( boxv, node ) == false ) - { - continue; - } - - b3AABB nodeAABB = node->aabb; - b3V32 lower = b3LoadV( &nodeAABB.lowerBound.x ); - b3V32 upper = b3LoadV( &nodeAABB.upperBound.x ); - if ( b3TestBoundsRayOverlap( lower, upper, pv1, dv ) == false ) - { - continue; - } - - uint32_t flags = b3LoadNodeFlags( node, relaxedFlags ); - isLeaf[hitCount] = ( flags & B3_LEAF_NODE ) != 0; - index[hitCount] = (int)( flags & B3_NODE_INDEX_MASK ); - hit[hitCount] = node; - hitCount += 1; + continue; } - if ( hitCount == 2 && isLeaf[0] == false && isLeaf[1] == false ) - { - b3Vec3 center1 = b3AABB_Center( hit[0]->aabb ); - b3Vec3 center2 = b3AABB_Center( hit[1]->aabb ); - float d1 = b3DistanceSquared( center1, p1 ); - float d2 = b3DistanceSquared( center2, p1 ); + b3V32 lower = b3LoadV( &nodeAABB.lowerBound.x ); + b3V32 upper = b3LoadV( &nodeAABB.upperBound.x ); - // Want to push the closest one last. Both have the same isLeaf, so they don't swap. - if ( d1 < d2 ) - { - B3_SWAP( hit[0], hit[1] ); - B3_SWAP( index[0], index[1] ); - } + bool edgeOverlap = b3TestBoundsRayOverlap( lower, upper, pv1, dv ); + if ( edgeOverlap == false ) + { + continue; } - for ( int i = 0; i < hitCount; ++i ) + if ( b3IsLeaf( node ) ) { - if ( isLeaf[i] ) + subInput.maxFraction = maxFraction; + + float value = callback( &subInput, nodeId, node->userData, context ); + result.leafVisits += 1; + + // The user may return -1 to indicate this shape should be skipped + + if ( value == 0.0f ) { - int proxyId = index[i]; - uint64_t userData = (uint64_t)(uint32_t)hit[i]->shapeIndex; - if ( hasProxies ) - { - const b3TreeProxy* proxy = view->proxies + proxyId; - if ( b3TestCategory( proxy->categoryBits, maskBits, requireAllBits ) == false ) - { - continue; - } - userData = proxy->userData; - } - - subInput.maxFraction = maxFraction; - - float value = callback( &subInput, proxyId, userData, context ); - result.leafVisits += 1; - - // The user may return -1 to indicate this shape should be skipped - - if ( value == 0.0f ) - { - // The client has terminated the ray cast. - return result; - } - - if ( 0.0f < value && value <= maxFraction ) - { - // Update segment bounding box. - maxFraction = value; - p2 = b3MulAdd( p1, maxFraction, d ); - segmentAABB.lowerBound = b3Min( p1, p2 ); - segmentAABB.upperBound = b3Max( p1, p2 ); - boxv = b3LoadAABBV( &segmentAABB ); - } + // The client has terminated the ray cast. + return result; } - else + + if ( 0.0f < value && value <= maxFraction ) { - if ( stackCount < B3_TREE_STACK_SIZE - 1 ) + // Update segment bounding box. + maxFraction = value; + p2 = b3MulAdd( p1, maxFraction, d ); + segmentAABB.lowerBound = b3Min( p1, p2 ); + segmentAABB.upperBound = b3Max( p1, p2 ); + } + } + else + { + B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + if ( stackCount < B3_TREE_STACK_SIZE - 1 ) + { + b3Vec3 c1 = b3AABB_Center( nodes[node->children.child1].aabb ); + b3Vec3 c2 = b3AABB_Center( nodes[node->children.child2].aabb ); + if ( b3DistanceSquared( c1, p1 ) < b3DistanceSquared( c2, p1 ) ) { - stack[stackCount++] = index[i]; + stack[stackCount++] = node->children.child2; + stack[stackCount++] = node->children.child1; } else { - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + stack[stackCount++] = node->children.child1; + stack[stackCount++] = node->children.child2; } } } @@ -1218,19 +1360,14 @@ B3_FORCE_INLINE b3TreeStats b3RayCastTreeView( const b3TreeView* view, const b3R return result; } -// Follows structure of ray cast with small tweaks to handle a swept box. -B3_FORCE_INLINE b3TreeStats b3BoxCastTreeView( const b3TreeView* view, const b3BoxCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeBoxCastCallbackFcn* callback, void* context, - bool hasProxies, bool relaxedFlags ) +b3TreeStats b3DynamicTree_BoxCast( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits, bool requireAllBits, + b3TreeBoxCastCallbackFcn* callback, void* context ) { - b3TreeStats result = { 0 }; + b3TreeStats stats = { 0 }; - const b3TreeNode* nodes = view->nodes; - - uint32_t rootFlags = b3LoadNodeFlags( nodes + B3_ROOT_NODE, relaxedFlags ); - if ( rootFlags == B3_EMPTY_NODE ) + if ( tree->nodeCount == 0 ) { - return result; + return stats; } // The caller folds the shape radius and the world origin into the box @@ -1253,245 +1390,85 @@ B3_FORCE_INLINE b3TreeStats b3BoxCastTreeView( const b3TreeView* view, const b3B b3Min( originAABB.lowerBound, b3Add( originAABB.lowerBound, t ) ), b3Max( originAABB.upperBound, b3Add( originAABB.upperBound, t ) ), }; - b3AABBV boxv = b3LoadAABBV( &totalAABB ); + + b3BoxCastInput subInput = *input; + const b3TreeNode* nodes = tree->nodes; int stack[B3_TREE_STACK_SIZE]; int stackCount = 0; - stack[stackCount++] = ( rootFlags & B3_LEAF_NODE ) ? B3_ROOT_NODE : (int)( rootFlags & B3_NODE_INDEX_MASK ); - - b3BoxCastInput subInput = *input; + stack[stackCount++] = tree->root; while ( stackCount > 0 ) { - int pair = stack[--stackCount]; - result.nodeVisits += 1; - - const b3TreeNode* hit[2]; - bool isLeaf[2]; - int index[2]; - int hitCount = 0; - for ( int i = 0; i < 2; ++i ) + int nodeId = stack[--stackCount]; + if ( nodeId == B3_NULL_INDEX ) { - const b3TreeNode* node = nodes + pair + i; - - if ( b3OverlapNode( boxv, node ) == false ) - { - continue; - } - - // radius extension is added to the node in this case - b3AABB nodeAABB = node->aabb; - b3V32 lower = b3SubV( b3LoadV( &nodeAABB.lowerBound.x ), ev ); - b3V32 upper = b3AddV( b3LoadV( &nodeAABB.upperBound.x ), ev ); - if ( b3TestBoundsRayOverlap( lower, upper, pv1, dv ) == false ) - { - continue; - } - - uint32_t flags = b3LoadNodeFlags( node, relaxedFlags ); - isLeaf[hitCount] = ( flags & B3_LEAF_NODE ) != 0; - index[hitCount] = (int)( flags & B3_NODE_INDEX_MASK ); - hit[hitCount] = node; - hitCount += 1; + B3_ASSERT( false ); + continue; } - if ( hitCount == 2 && isLeaf[0] == false && isLeaf[1] == false ) - { - b3Vec3 center1 = b3AABB_Center( hit[0]->aabb ); - b3Vec3 center2 = b3AABB_Center( hit[1]->aabb ); - float d1 = b3DistanceSquared( center1, p1 ); - float d2 = b3DistanceSquared( center2, p1 ); + const b3TreeNode* node = nodes + nodeId; + stats.nodeVisits += 1; - // Want to push the closest one last. Both have the same isLeaf, so they don't swap. - if ( d1 < d2 ) - { - B3_SWAP( hit[0], hit[1] ); - B3_SWAP( index[0], index[1] ); - } + uint64_t bitMatch = requireAllBits ? ( node->categoryBits & maskBits ) == maskBits : ( node->categoryBits & maskBits ); + + if ( bitMatch == 0 || b3AABB_Overlaps( node->aabb, totalAABB ) == false ) + { + continue; } - for ( int i = 0; i < hitCount; ++i ) + // radius extension is added to the node in this case + b3V32 lower = b3SubV( b3LoadV( &node->aabb.lowerBound.x ), ev ); + b3V32 upper = b3AddV( b3LoadV( &node->aabb.upperBound.x ), ev ); + bool edgeOverlap = b3TestBoundsRayOverlap( lower, upper, pv1, dv ); + if ( edgeOverlap == false ) { - if ( isLeaf[i] ) + continue; + } + + if ( b3IsLeaf( node ) ) + { + subInput.maxFraction = maxFraction; + + float value = callback( &subInput, nodeId, node->userData, context ); + stats.leafVisits += 1; + + if ( value == 0.0f ) { - int proxyId = index[i]; - uint64_t userData = (uint64_t)(uint32_t)hit[i]->shapeIndex; - if ( hasProxies ) - { - const b3TreeProxy* proxy = view->proxies + proxyId; - if ( b3TestCategory( proxy->categoryBits, maskBits, requireAllBits ) == false ) - { - continue; - } - userData = proxy->userData; - } - - subInput.maxFraction = maxFraction; - - float value = callback( &subInput, proxyId, userData, context ); - result.leafVisits += 1; - - if ( value == 0.0f ) - { - // The client has terminated the cast. - return result; - } - - if ( 0.0f < value && value < maxFraction ) - { - maxFraction = value; - t = b3MulSV( maxFraction, input->translation ); - totalAABB.lowerBound = b3Min( originAABB.lowerBound, b3Add( originAABB.lowerBound, t ) ); - totalAABB.upperBound = b3Max( originAABB.upperBound, b3Add( originAABB.upperBound, t ) ); - boxv = b3LoadAABBV( &totalAABB ); - } + // The client has terminated the cast. + return stats; } - else + + if ( 0.0f < value && value < maxFraction ) { - if ( stackCount < B3_TREE_STACK_SIZE - 1 ) + maxFraction = value; + t = b3MulSV( maxFraction, input->translation ); + totalAABB.lowerBound = b3Min( originAABB.lowerBound, b3Add( originAABB.lowerBound, t ) ); + totalAABB.upperBound = b3Max( originAABB.upperBound, b3Add( originAABB.upperBound, t ) ); + } + } + else + { + B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + if ( stackCount < B3_TREE_STACK_SIZE - 1 ) + { + b3Vec3 c1 = b3AABB_Center( nodes[node->children.child1].aabb ); + b3Vec3 c2 = b3AABB_Center( nodes[node->children.child2].aabb ); + if ( b3DistanceSquared( c1, p1 ) < b3DistanceSquared( c2, p1 ) ) { - stack[stackCount++] = index[i]; + stack[stackCount++] = node->children.child2; + stack[stackCount++] = node->children.child1; } else { - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE - 1 ); + stack[stackCount++] = node->children.child1; + stack[stackCount++] = node->children.child2; } } } } - return result; -} - -B3_FORCE_INLINE b3TreeStats b3QueryDynamicTree( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, - bool requireAllBits, b3TreeQueryCallbackFcn* callback, void* context, - bool relaxedFlags ) -{ - if ( tree->proxyCount == 0 ) - { - return B3_LITERAL( b3TreeStats ){ 0 }; - } - - b3TreeView view = b3MakeTreeView( tree ); - return b3QueryTreeView( &view, aabb, maskBits, requireAllBits, callback, context, true, relaxedFlags ); -} - -b3TreeStats b3DynamicTree_Query( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context ) -{ - return b3QueryDynamicTree( tree, aabb, maskBits, requireAllBits, callback, context, false ); -} - -b3TreeStats b3DynamicTree_QueryRelaxed( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context ) -{ - return b3QueryDynamicTree( tree, aabb, maskBits, requireAllBits, callback, context, true ); -} - -b3TreeStats b3DynamicTree_QueryClosest( const b3DynamicTree* tree, b3Vec3 point, uint64_t maskBits, bool requireAllBits, - b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr ) -{ - if ( tree->proxyCount == 0 ) - { - return B3_LITERAL( b3TreeStats ){ 0 }; - } - - b3TreeView view = b3MakeTreeView( tree ); - return b3QueryClosestTreeView( &view, point, maskBits, requireAllBits, callback, context, minDistanceSqr, true ); -} - -B3_FORCE_INLINE b3TreeStats b3RayCastDynamicTree( const b3DynamicTree* tree, const b3RayCastInput* input, - uint64_t maskBits, bool requireAllBits, - b3TreeRayCastCallbackFcn* callback, void* context, bool relaxedFlags ) -{ - if ( tree->proxyCount == 0 ) - { - return B3_LITERAL( b3TreeStats ){ 0 }; - } - - b3TreeView view = b3MakeTreeView( tree ); - return b3RayCastTreeView( &view, input, maskBits, requireAllBits, callback, context, true, relaxedFlags ); -} - -b3TreeStats b3DynamicTree_RayCast( const b3DynamicTree* tree, const b3RayCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeRayCastCallbackFcn* callback, void* context ) -{ - return b3RayCastDynamicTree( tree, input, maskBits, requireAllBits, callback, context, false ); -} - -b3TreeStats b3DynamicTree_RayCastRelaxed( const b3DynamicTree* tree, const b3RayCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeRayCastCallbackFcn* callback, void* context ) -{ - return b3RayCastDynamicTree( tree, input, maskBits, requireAllBits, callback, context, true ); -} - -B3_FORCE_INLINE b3TreeStats b3BoxCastDynamicTree( const b3DynamicTree* tree, const b3BoxCastInput* input, - uint64_t maskBits, bool requireAllBits, - b3TreeBoxCastCallbackFcn* callback, void* context, bool relaxedFlags ) -{ - if ( tree->proxyCount == 0 ) - { - return B3_LITERAL( b3TreeStats ){ 0 }; - } - - b3TreeView view = b3MakeTreeView( tree ); - return b3BoxCastTreeView( &view, input, maskBits, requireAllBits, callback, context, true, relaxedFlags ); -} - -b3TreeStats b3DynamicTree_BoxCast( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits, bool requireAllBits, - b3TreeBoxCastCallbackFcn* callback, void* context ) -{ - return b3BoxCastDynamicTree( tree, input, maskBits, requireAllBits, callback, context, false ); -} - -b3TreeStats b3DynamicTree_BoxCastRelaxed( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeBoxCastCallbackFcn* callback, void* context ) -{ - return b3BoxCastDynamicTree( tree, input, maskBits, requireAllBits, callback, context, true ); -} - -b3TreeStats b3TreeView_Query( const b3TreeView* view, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context ) -{ - if ( view->proxies == NULL ) - { - return b3QueryTreeView( view, aabb, maskBits, requireAllBits, callback, context, false, false ); - } - - return b3QueryTreeView( view, aabb, maskBits, requireAllBits, callback, context, true, false ); -} - -b3TreeStats b3TreeView_QueryClosest( const b3TreeView* view, b3Vec3 point, uint64_t maskBits, bool requireAllBits, - b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr ) -{ - if ( view->proxies == NULL ) - { - return b3QueryClosestTreeView( view, point, maskBits, requireAllBits, callback, context, minDistanceSqr, false ); - } - - return b3QueryClosestTreeView( view, point, maskBits, requireAllBits, callback, context, minDistanceSqr, true ); -} - -b3TreeStats b3TreeView_RayCast( const b3TreeView* view, const b3RayCastInput* input, uint64_t maskBits, bool requireAllBits, - b3TreeRayCastCallbackFcn* callback, void* context ) -{ - if ( view->proxies == NULL ) - { - return b3RayCastTreeView( view, input, maskBits, requireAllBits, callback, context, false, false ); - } - - return b3RayCastTreeView( view, input, maskBits, requireAllBits, callback, context, true, false ); -} - -b3TreeStats b3TreeView_BoxCast( const b3TreeView* view, const b3BoxCastInput* input, uint64_t maskBits, bool requireAllBits, - b3TreeBoxCastCallbackFcn* callback, void* context ) -{ - if ( view->proxies == NULL ) - { - return b3BoxCastTreeView( view, input, maskBits, requireAllBits, callback, context, false, false ); - } - - return b3BoxCastTreeView( view, input, maskBits, requireAllBits, callback, context, true, false ); + return stats; } // Median split == 0, Surface area heuristic == 1 @@ -1814,141 +1791,30 @@ static int b3PartitionSAH( int* indices, int* binIndices, b3AABB* boxes, int cou #endif -// Temporary data used to track the rebuild of a tree node. -typedef struct b3RebuildItem +// Temporary data used to track the rebuild of a tree node +struct b3RebuildItem { - // Where this node is written and the pair its children go in. int nodeIndex; - int pair; int childCount; // Leaf indices int startIndex; int splitIndex; int endIndex; -} b3RebuildItem; +}; -typedef struct b3CopyItem +// Returns root node index +static int b3BuildTree( b3DynamicTree* tree, int leafCount ) { - int oldPair; - int newIndex; -} b3CopyItem; - -// Bump allocate a pair of sibling nodes. Returns index to the first one. -static inline int b3BumpPair( b3DynamicTree* tree, int parent ) -{ - int pair = tree->nodeEnd; - B3_ASSERT( pair + 2 <= tree->nodeCapacity ); - tree->nodeEnd += 2; - tree->parents[pair] = parent; - tree->parents[pair + 1] = parent; - return pair; -} - -static inline void b3SetLeftChild( b3TreeNode* node, int pair ) -{ - node->flagIndex = ( node->flagIndex & ~B3_NODE_INDEX_MASK ) | (uint32_t)pair; -} - -// Copy a retained subtree from the old array into the rebuilt DFS array using -// a bump allocator. -static void b3CopySubtree( b3DynamicTree* tree, b3TreeNode node, int newIndex ) -{ - const b3TreeNode* oldNodes = tree->nodes; - b3TreeNode* newNodes = tree->swapNodes; - b3TreeProxy* proxies = tree->proxies; - - if ( b3IsLeaf( &node ) ) - { - newNodes[newIndex] = node; - proxies[b3GetProxyId( &node )].node = newIndex; - return; - } - - b3CopyItem stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - - int oldPair = b3GetLeftChild( &node ); - int newPair = b3BumpPair( tree, newIndex ); - b3SetLeftChild( &node, newPair ); - - // Copy the subtree root. This can be a left or right sibling (even or odd). - newNodes[newIndex] = node; - - for ( ;; ) - { - b3TreeNode* pair = newNodes + newPair; - - // Copy the siblings. - pair[0] = oldNodes[oldPair]; - pair[1] = oldNodes[oldPair + 1]; - - if ( b3IsLeaf( pair + 1 ) ) - { - // Hook up proxy on right sibling. - int proxyId = b3GetProxyId( pair + 1 ); - proxies[proxyId].node = newPair + 1; - } - else - { - // Push the left child of the right sibling. - if ( stackCount < B3_TREE_STACK_SIZE ) - { - int leftChild = b3GetLeftChild( pair + 1 ); - stack[stackCount++] = B3_LITERAL( b3CopyItem ){ leftChild, newPair + 1 }; - } - else - { - // todo fail gracefully if the stack runs out in release - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); - } - } - - if ( b3IsLeaf( pair ) == false ) - { - // Descend into left subtree. - int leftIndex = newPair; - oldPair = b3GetLeftChild( pair ); - newPair = b3BumpPair( tree, leftIndex ); - b3SetLeftChild( newNodes + leftIndex, newPair ); - continue; - } - - // Hook up proxy on left sibling. - proxies[b3GetProxyId( pair )].node = newPair; - - if ( stackCount == 0 ) - { - break; - } - - // Descend a right subtree that was previously pushed. - b3CopyItem item = stack[--stackCount]; - oldPair = item.oldPair; - newPair = b3BumpPair( tree, item.newIndex ); - b3SetLeftChild( newNodes + item.newIndex, newPair ); - } -} - -static void b3PlaceLeaf( b3DynamicTree* tree, b3TreeNode leaf, int newIndex ) -{ - if ( b3IsLeaf( &leaf ) ) - { - tree->swapNodes[newIndex] = leaf; - tree->proxies[b3GetProxyId( &leaf )].node = newIndex; - } - else - { - b3CopySubtree( tree, leaf, newIndex ); - } -} - -static void b3BuildTree( b3DynamicTree* tree, int leafCount ) -{ - b3TreeNode* nodes = tree->swapNodes; - const b3TreeNode* leaves = tree->leafNodes; + b3TreeNode* nodes = tree->nodes; int* leafIndices = tree->leafIndices; + if ( leafCount == 1 ) + { + nodes[leafIndices[0]].parent = B3_NULL_INDEX; + return leafIndices[0]; + } + #if B3_TREE_HEURISTIC == 0 b3Vec3* leafCenters = tree->leafCenters; #else @@ -1956,23 +1822,11 @@ static void b3BuildTree( b3DynamicTree* tree, int leafCount ) int* binIndices = tree->binIndices; #endif - // Bump allocation into the swap nodes. - tree->nodeEnd = 2; - nodes[B3_ROOT_NODE + 1] = b3MakeEmptyNode(); - tree->parents[B3_ROOT_NODE] = B3_NULL_INDEX; - tree->parents[B3_ROOT_NODE + 1] = B3_NULL_INDEX; - - if ( leafCount == 1 ) - { - b3PlaceLeaf( tree, leaves[leafIndices[0]], B3_ROOT_NODE ); - return; - } - - b3RebuildItem stack[B3_TREE_STACK_SIZE]; + // todo large stack item + struct b3RebuildItem stack[B3_TREE_STACK_SIZE]; int top = 0; - stack[0].nodeIndex = B3_ROOT_NODE; - stack[0].pair = b3BumpPair( tree, B3_ROOT_NODE ); + stack[0].nodeIndex = b3AllocateNode( tree ); stack[0].childCount = -1; stack[0].startIndex = 0; stack[0].endIndex = leafCount; @@ -1984,57 +1838,128 @@ static void b3BuildTree( b3DynamicTree* tree, int leafCount ) while ( true ) { - b3RebuildItem* item = stack + top; + struct b3RebuildItem* item = stack + top; + item->childCount += 1; if ( item->childCount == 2 ) { - // Both children written, so the parent node can be finalized. - nodes[item->nodeIndex] = b3MakeInternalNode( nodes, item->pair ); + // This internal node has both children established + if ( top == 0 ) { + // all done break; } + struct b3RebuildItem* parentItem = stack + ( top - 1 ); + b3TreeNode* parentNode = nodes + parentItem->nodeIndex; + + if ( parentItem->childCount == 0 ) + { + B3_ASSERT( parentNode->children.child1 == B3_NULL_INDEX ); + parentNode->children.child1 = item->nodeIndex; + } + else + { + B3_ASSERT( parentItem->childCount == 1 ); + B3_ASSERT( parentNode->children.child2 == B3_NULL_INDEX ); + parentNode->children.child2 = item->nodeIndex; + } + + b3TreeNode* node = nodes + item->nodeIndex; + + B3_ASSERT( node->parent == B3_NULL_INDEX ); + node->parent = parentItem->nodeIndex; + + B3_ASSERT( node->children.child1 != B3_NULL_INDEX ); + B3_ASSERT( node->children.child2 != B3_NULL_INDEX ); + b3TreeNode* child1 = nodes + node->children.child1; + b3TreeNode* child2 = nodes + node->children.child2; + + node->aabb = b3AABB_Union( child1->aabb, child2->aabb ); + node->height = 1 + b3MaxUInt16( child1->height, child2->height ); + node->categoryBits = child1->categoryBits | child2->categoryBits; + + // Pop stack top -= 1; - continue; } - - int slot = item->childCount; - int startIndex = slot == 0 ? item->startIndex : item->splitIndex; - int endIndex = slot == 0 ? item->splitIndex : item->endIndex; - int count = endIndex - startIndex; - B3_ASSERT( count > 0 ); - - int nodeIndex = item->pair + slot; - if ( count == 1 ) + else { - b3PlaceLeaf( tree, leaves[leafIndices[startIndex]], nodeIndex ); - continue; - } + int startIndex, endIndex; + if ( item->childCount == 0 ) + { + startIndex = item->startIndex; + endIndex = item->splitIndex; + } + else + { + B3_ASSERT( item->childCount == 1 ); + startIndex = item->splitIndex; + endIndex = item->endIndex; + } - // todo fail gracefully if the stack runs out in release - B3_ASSERT( top < B3_TREE_STACK_SIZE - 1 ); + int count = endIndex - startIndex; - top += 1; - b3RebuildItem* newItem = stack + top; - newItem->nodeIndex = nodeIndex; - newItem->pair = b3BumpPair( tree, nodeIndex ); - newItem->childCount = -1; - newItem->startIndex = startIndex; - newItem->endIndex = endIndex; - newItem->splitIndex = startIndex; + if ( count == 1 ) + { + int childIndex = leafIndices[startIndex]; + b3TreeNode* node = nodes + item->nodeIndex; + + if ( item->childCount == 0 ) + { + B3_ASSERT( node->children.child1 == B3_NULL_INDEX ); + node->children.child1 = childIndex; + } + else + { + B3_ASSERT( item->childCount == 1 ); + B3_ASSERT( node->children.child2 == B3_NULL_INDEX ); + node->children.child2 = childIndex; + } + + b3TreeNode* childNode = nodes + childIndex; + B3_ASSERT( childNode->parent == B3_NULL_INDEX ); + childNode->parent = item->nodeIndex; + } + else + { + B3_ASSERT( count > 0 ); + B3_ASSERT( top < B3_TREE_STACK_SIZE ); + + top += 1; + struct b3RebuildItem* newItem = stack + top; + newItem->nodeIndex = b3AllocateNode( tree ); + newItem->childCount = -1; + newItem->startIndex = startIndex; + newItem->endIndex = endIndex; #if B3_TREE_HEURISTIC == 0 - newItem->splitIndex += b3PartitionMid( leafIndices + startIndex, leafCenters + startIndex, count ); + newItem->splitIndex = b3PartitionMid( leafIndices + startIndex, leafCenters + startIndex, count ); #else - newItem->splitIndex += b3PartitionSAH( leafIndices + startIndex, binIndices + startIndex, leafBoxes + startIndex, count ); + newItem->splitIndex = + b3PartitionSAH( leafIndices + startIndex, binIndices + startIndex, leafBoxes + startIndex, count ); #endif + newItem->splitIndex += startIndex; + } + } } + + b3TreeNode* rootNode = nodes + stack[0].nodeIndex; + B3_ASSERT( rootNode->parent == B3_NULL_INDEX ); + B3_ASSERT( rootNode->children.child1 != B3_NULL_INDEX ); + B3_ASSERT( rootNode->children.child2 != B3_NULL_INDEX ); + + b3TreeNode* child1 = nodes + rootNode->children.child1; + b3TreeNode* child2 = nodes + rootNode->children.child2; + + rootNode->aabb = b3AABB_Union( child1->aabb, child2->aabb ); + rootNode->height = 1 + b3MaxUInt16( child1->height, child2->height ); + rootNode->categoryBits = child1->categoryBits | child2->categoryBits; + + return stack[0].nodeIndex; } -// Rebuild the stale parts of the tree. The entire tree is put into DFS order. This makes -// refitting much faster. This is done async with threading, so the cost is hidden. -// Not safe to access tree during this operation. +// Not safe to access tree during this operation because it may grow int b3DynamicTree_Rebuild( b3DynamicTree* tree, bool fullBuild ) { int proxyCount = tree->proxyCount; @@ -2043,375 +1968,112 @@ int b3DynamicTree_Rebuild( b3DynamicTree* tree, bool fullBuild ) return 0; } - // An unordered tree is rebuilt even when nothing moved, the sweep refit needs the order - const b3TreeNode* nodes = tree->nodes; - const b3TreeNode* root = nodes + B3_ROOT_NODE; - if ( fullBuild == false && b3IsNodeMoved( root ) == false && tree->dfsOrdered ) - { - return 0; - } - - if ( tree->swapNodes == NULL ) - { - tree->swapNodes = b3AllocZero( tree->nodeCapacity * sizeof( b3TreeNode ) ); - } - + // Ensure capacity for rebuild space if ( proxyCount > tree->rebuildCapacity ) { - int oldCapacity = tree->rebuildCapacity; int newCapacity = proxyCount + proxyCount / 2; - b3Free( tree->leafIndices, oldCapacity * sizeof( int32_t ) ); - tree->leafIndices = (int32_t*)b3Alloc( newCapacity * sizeof( int32_t ) ); - - b3Free( tree->leafNodes, oldCapacity * sizeof( b3TreeNode ) ); - tree->leafNodes = (b3TreeNode*)b3Alloc( newCapacity * sizeof( b3TreeNode ) ); + b3Free( tree->leafIndices, tree->rebuildCapacity * sizeof( int ) ); + tree->leafIndices = (int*)b3Alloc( newCapacity * sizeof( int ) ); #if B3_TREE_HEURISTIC == 0 - b3Free( tree->leafCenters, oldCapacity * sizeof( b3Vec3 ) ); + b3Free( tree->leafCenters, tree->rebuildCapacity * sizeof( b3Vec3 ) ); tree->leafCenters = (b3Vec3*)b3Alloc( newCapacity * sizeof( b3Vec3 ) ); #else - b3Free( tree->leafBoxes, oldCapacity * sizeof( b3AABB ) ); + b3Free( tree->leafBoxes, tree->rebuildCapacity * sizeof( b3AABB ) ); tree->leafBoxes = (b3AABB*)b3Alloc( newCapacity * sizeof( b3AABB ) ); - b3Free( tree->binIndices, oldCapacity * sizeof( int32_t ) ); - tree->binIndices = (int32_t*)b3Alloc( newCapacity * sizeof( int32_t ) ); + b3Free( tree->binIndices, tree->rebuildCapacity * sizeof( int ) ); + tree->binIndices = (int*)b3Alloc( newCapacity * sizeof( int ) ); #endif tree->rebuildCapacity = newCapacity; } + int leafCount = 0; + int stack[B3_TREE_STACK_SIZE]; + int stackCount = 0; + + int nodeIndex = tree->root; + b3TreeNode* nodes = tree->nodes; + b3TreeNode* node = nodes + nodeIndex; + + // These are the nodes that get sorted to rebuild the tree. + // I'm using indices because the node pool may grow during the build. int* leafIndices = tree->leafIndices; - b3TreeNode* leaves = tree->leafNodes; + #if B3_TREE_HEURISTIC == 0 b3Vec3* leafCenters = tree->leafCenters; #else b3AABB* leafBoxes = tree->leafBoxes; #endif - // Gather build leaves. A marked internal node is descended and abandoned in the old array. - // Everything else is a build leaf, kept subtrees included. A leaf root, or an unmarked root - // on an unordered array, is the one build leaf. - int leafCount = 0; - int stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - if ( b3IsLeaf( root ) == false && ( fullBuild || b3IsNodeMoved( root ) ) ) + // Gather all proxy nodes that have grown and all internal nodes that haven't grown. Both are + // considered leaves in the tree rebuild. + // Free all internal nodes that have grown. + // todo use a node growth metric instead of simply enlarged to reduce rebuild size and frequency + // this should be weighed against B3_MAX_AABB_MARGIN + while ( true ) { - stack[stackCount++] = b3GetLeftChild( root ); - } - else - { - b3TreeNode node = *root; - if ( fullBuild == false ) + if ( b3IsLeaf( node ) == true || ( ( node->flags & b3_enlargedNode ) == 0 && fullBuild == false ) ) { - node.flagIndex &= ~B3_MOVED_NODE; - } - leafIndices[0] = 0; - leaves[0] = node; + leafIndices[leafCount] = nodeIndex; #if B3_TREE_HEURISTIC == 0 - leafCenters[0] = b3AABB_Center( node.aabb ); + leafCenters[leafCount] = b3AABB_Center( node->aabb ); #else - leafBoxes[0] = node.aabb; -#endif - leafCount = 1; - } - - while ( stackCount > 0 ) - { - int pair = stack[--stackCount]; - for ( int i = 0; i < 2; ++i ) - { - b3TreeNode node = nodes[pair + i]; - if ( b3IsLeaf( &node ) == false && ( fullBuild || b3IsNodeMoved( &node ) ) ) - { - // todo fail gracefully if the stack runs out in release - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); - stack[stackCount++] = b3GetLeftChild( &node ); - continue; - } - - if ( fullBuild == false ) - { - node.flagIndex &= ~B3_MOVED_NODE; - } - leafIndices[leafCount] = leafCount; - leaves[leafCount] = node; -#if B3_TREE_HEURISTIC == 0 - leafCenters[leafCount] = b3AABB_Center( node.aabb ); -#else - leafBoxes[leafCount] = node.aabb; + leafBoxes[leafCount] = node->aabb; #endif leafCount += 1; - } - } - B3_ASSERT( 0 < leafCount && leafCount <= proxyCount ); - - b3BuildTree( tree, leafCount ); - - // The spare is now the tree and the old array is the spare. The build is dense, so the - // stale tail of the old array sits above the end and is never read. - B3_SWAP( tree->nodes, tree->swapNodes ); - tree->pairFreeList = B3_NULL_INDEX; - tree->dfsOrdered = true; - - b3DynamicTree_Validate( tree ); - if ( fullBuild == false ) - { - b3DynamicTree_ValidateNoMoved( tree ); - } - - return leafCount; -} - -// Set the moved flag on the ancestors of the proxy. Serial use case. -void b3DynamicTree_MarkProxyMovedSerial( b3DynamicTree* tree, int proxyId ) -{ - B3_VALIDATE( 0 <= proxyId && proxyId < tree->proxyCapacity ); - - b3TreeNode* nodes = tree->nodes; - const int32_t* parents = tree->parents; - - int index = tree->proxies[proxyId].node; - B3_VALIDATE( 0 <= index && index < tree->nodeEnd ); - B3_VALIDATE( b3IsLeaf( nodes + index ) ); - - while ( index != B3_NULL_INDEX ) - { - nodes[index].flagIndex |= B3_MOVED_NODE; - index = parents[index]; - } -} - -// Update a proxy AABB and flag the ancestors as moved. Thread-safe using atomics. -void b3DynamicTree_MarkProxyMoved( b3DynamicTree* tree, int proxyId, b3AABB aabb ) -{ - B3_VALIDATE( 0 <= proxyId && proxyId < tree->proxyCapacity ); - - b3TreeNode* nodes = tree->nodes; - const int32_t* parents = tree->parents; - - int index = tree->proxies[proxyId].node; - B3_VALIDATE( 0 <= index && index < tree->nodeEnd ); - - b3TreeNode* node = nodes + index; - B3_VALIDATE( b3IsLeaf( node ) ); - B3_VALIDATE( b3AABB_Contains( node->aabb, aabb ) == false ); - - // This is not raced since it is the leaf. - node->aabb = aabb; - node->flagIndex |= B3_MOVED_NODE; - - index = parents[index]; - while ( index != B3_NULL_INDEX ) - { - node = nodes + index; - - // Read first to avoid the FetchOr if possible. - if ( b3AtomicLoadU32Raw( &node->flagIndex ) & B3_MOVED_NODE ) - { - break; - } - - uint32_t previousFlags = b3AtomicFetchOrU32( &node->flagIndex, B3_MOVED_NODE ); - if ( previousFlags & B3_MOVED_NODE ) - { - // Ancestor already visited. - break; - } - - index = parents[index]; - } -} - -// Clear the moved flags from the entire tree. -void b3DynamicTree_ClearMoved( b3DynamicTree* tree ) -{ - b3TreeNode* nodes = tree->nodes; - - b3TreeNode* root = nodes + B3_ROOT_NODE; - if ( b3IsNodeMoved( root ) == false ) - { - return; - } - - b3AtomicStoreU32Raw( &root->flagIndex, root->flagIndex & ~B3_MOVED_NODE ); - if ( b3IsLeaf( root ) ) - { - return; - } - - int stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - stack[stackCount++] = b3GetLeftChild( root ); - - while ( stackCount > 0 ) - { - int pair = stack[--stackCount]; - for ( int i = 0; i < 2; ++i ) - { - b3TreeNode* node = nodes + pair + i; - if ( node->flagIndex & B3_MOVED_NODE ) - { - b3AtomicStoreU32Raw( &node->flagIndex, node->flagIndex & ~B3_MOVED_NODE ); - if ( b3IsLeaf( node ) == false ) - { - if ( stackCount < B3_TREE_STACK_SIZE ) - { - stack[stackCount++] = b3GetLeftChild( node ); - } - else - { - // Bad stuff will happen if the moved flags don't get cleared. - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); - } - } - } - } - } -} - -int b3DynamicTree_GatherMovedProxies( const b3DynamicTree* tree, int* proxyIds ) -{ - const b3TreeNode* nodes = tree->nodes; - const b3TreeNode* root = nodes + B3_ROOT_NODE; - if ( b3IsNodeMoved( root ) == false ) - { - return 0; - } - - if ( b3IsLeaf( root ) ) - { - proxyIds[0] = b3GetProxyId( root ); - return 1; - } - - int count = 0; - int stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - stack[stackCount++] = b3GetLeftChild( root ); - - while ( stackCount > 0 ) - { - int pair = stack[--stackCount]; - for ( int i = 0; i < 2; ++i ) - { - const b3TreeNode* node = nodes + pair + i; - if ( b3IsNodeMoved( node ) == false ) - { - continue; - } - - if ( b3IsLeaf( node ) ) - { - proxyIds[count++] = b3GetProxyId( node ); - } - else - { - if ( stackCount < B3_TREE_STACK_SIZE ) - { - stack[stackCount++] = b3GetLeftChild( node ); - } - else - { - B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); - } - } - } - } - - return count; -} - -// Slow refit for unit tests. -static void b3RefitSubtree( b3TreeNode* nodes, int rootIndex ) -{ - b3TreeNode* root = nodes + rootIndex; - if ( b3IsLeaf( root ) || b3IsNodeMoved( root ) == false ) - { - return; - } - - // Negative entries indicate deferred unions. A parent is pushed before its children so the - // LIFO order guarantees both children are finished when the union runs. - int stack[B3_TREE_STACK_SIZE]; - int stackCount = 0; - // ~0 == -1 - stack[stackCount++] = ~rootIndex; - stack[stackCount++] = b3GetLeftChild( root ); - stack[stackCount++] = b3GetLeftChild( root ) + 1; - - while ( stackCount > 0 ) - { - int item = stack[--stackCount]; - if ( item < 0 ) - { - b3TreeNode* node = nodes + ~item; - int pair = b3GetLeftChild( node ); - node->aabb = b3UnionV( nodes[pair].aabb, nodes[pair + 1].aabb ); - continue; - } - - b3TreeNode* node = nodes + item; - if ( b3IsLeaf( node ) || b3IsNodeMoved( node ) == false ) - { - continue; - } - - if ( stackCount + 3 <= B3_TREE_STACK_SIZE ) - { - int pair = b3GetLeftChild( node ); - stack[stackCount++] = ~item; - stack[stackCount++] = pair; - stack[stackCount++] = pair + 1; + // Detach + node->parent = B3_NULL_INDEX; } else { - B3_ASSERT( stackCount + 3 <= B3_TREE_STACK_SIZE ); - } - } -} + int doomedNodeIndex = nodeIndex; -void b3DynamicTree_Refit( b3DynamicTree* tree ) -{ - if ( b3HasTreeMoved( tree ) == false ) - { - return; - } + // Handle children + nodeIndex = node->children.child1; - b3TreeNode* nodes = tree->nodes; + B3_ASSERT( stackCount < B3_TREE_STACK_SIZE ); + if ( stackCount < B3_TREE_STACK_SIZE ) + { + stack[stackCount++] = node->children.child2; + } - if ( tree->dfsOrdered == false ) - { - // This only happens in unit tests. - b3RefitSubtree( nodes, B3_ROOT_NODE ); - return; - } + node = nodes + nodeIndex; - for ( int pair = tree->nodeEnd - 2; pair >= 0; pair -= 2 ) - { - b3TreeNode* node = nodes + pair; - uint32_t flags1 = node[0].flagIndex; - uint32_t flags2 = node[1].flagIndex; + // Remove doomed node + b3FreeNode( tree, doomedNodeIndex ); - // Did either move? - if ( ( ( flags1 | flags2 ) & B3_MOVED_NODE ) == 0 ) - { continue; } - // Is the node internal and moved? - bool refit1 = ( flags1 & ( B3_LEAF_NODE | B3_MOVED_NODE ) ) == B3_MOVED_NODE; - bool refit2 = ( flags2 & ( B3_LEAF_NODE | B3_MOVED_NODE ) ) == B3_MOVED_NODE; + if ( stackCount == 0 ) + { + break; + } - // If the node needs a refit then get the child index. Otherwise use a valid dummy index. - // The store function won't actually modify the node at the dummy index. This - // avoids an unpredictable branch. SIMD FTW. - int children1 = refit1 ? (int)( flags1 & B3_NODE_INDEX_MASK ) : pair; - int children2 = refit2 ? (int)( flags2 & B3_NODE_INDEX_MASK ) : pair; - - // Conditionally store the union. - b3StoreAABBV( &node[0].aabb, b3UnionPairV( nodes + children1 ), refit1 ); - b3StoreAABBV( &node[1].aabb, b3UnionPairV( nodes + children2 ), refit2 ); + nodeIndex = stack[--stackCount]; + node = nodes + nodeIndex; } + +#if B3_ENABLE_VALIDATION == 1 + int capacity = tree->nodeCapacity; + for ( int i = 0; i < capacity; ++i ) + { + if ( nodes[i].flags & b3_allocatedNode ) + { + B3_ASSERT( ( nodes[i].flags & b3_enlargedNode ) == 0 ); + } + } +#endif + + B3_ASSERT( leafCount <= proxyCount ); + + tree->root = b3BuildTree( tree, leafCount ); + + b3DynamicTree_Validate( tree ); + + return leafCount; } static FILE* b3OpenTreeFile( const char* fileName, const char* mode ) @@ -2437,11 +2099,6 @@ static FILE* b3OpenTreeFile( const char* fileName, const char* mode ) void b3DynamicTree_Save( const b3DynamicTree* tree, const char* fileName ) { - if ( tree->nodes == NULL || tree->parents == NULL || tree->proxies == NULL ) - { - return; - } - FILE* file = b3OpenTreeFile( fileName, "wb" ); if ( file == NULL ) { @@ -2453,29 +2110,19 @@ void b3DynamicTree_Save( const b3DynamicTree* tree, const char* fileName ) // Zero pointers and temp data temp.nodes = NULL; - temp.parents = NULL; - temp.proxies = NULL; - temp.swapNodes = NULL; temp.leafIndices = NULL; - temp.leafNodes = NULL; temp.leafBoxes = NULL; temp.leafCenters = NULL; temp.binIndices = NULL; temp.rebuildCapacity = 0; - temp.nodeCapacity = tree->nodeEnd; - + // Write tree struct fwrite( &temp, sizeof( b3DynamicTree ), 1, file ); - if ( tree->nodeEnd > 0 ) + // Write the node array, this includes the free list + if ( tree->nodeCapacity > 0 && tree->nodes != NULL ) { - fwrite( tree->nodes, sizeof( b3TreeNode ), tree->nodeEnd, file ); - fwrite( tree->parents, sizeof( int32_t ), tree->nodeEnd, file ); - } - - if ( tree->proxyCapacity > 0 ) - { - fwrite( tree->proxies, sizeof( b3TreeProxy ), tree->proxyCapacity, file ); + fwrite( tree->nodes, sizeof( b3TreeNode ), tree->nodeCapacity, file ); } fclose( file ); @@ -2495,7 +2142,6 @@ b3DynamicTree b3DynamicTree_Load( const char* fileName, float scale ) if ( readCount != 1 ) { fclose( file ); - memset( &tree, 0, sizeof( b3DynamicTree ) ); return tree; } @@ -2506,54 +2152,37 @@ b3DynamicTree b3DynamicTree_Load( const char* fileName, float scale ) return tree; } - tree.nodes = NULL; - tree.parents = NULL; - tree.proxies = NULL; - tree.swapNodes = NULL; + if ( tree.nodeCapacity > 0 ) + { + tree.nodes = (b3TreeNode*)b3Alloc( tree.nodeCapacity * sizeof( b3TreeNode ) ); + readCount = (int)fread( tree.nodes, sizeof( b3TreeNode ), tree.nodeCapacity, file ); + if ( readCount != tree.nodeCapacity ) + { + b3Free( tree.nodes, tree.nodeCapacity * sizeof( b3TreeNode ) ); + fclose( file ); + memset( &tree, 0, sizeof( b3DynamicTree ) ); + return tree; + } + + for ( int i = 0; i < tree.nodeCapacity; ++i ) + { + b3TreeNode* node = tree.nodes + i; + node->aabb.lowerBound = b3MulSV( scale, node->aabb.lowerBound ); + node->aabb.upperBound = b3MulSV( scale, node->aabb.upperBound ); + } + } + else + { + tree.nodes = NULL; + } + + // Zero temp data fields tree.leafIndices = NULL; - tree.leafNodes = NULL; tree.leafBoxes = NULL; tree.leafCenters = NULL; tree.binIndices = NULL; tree.rebuildCapacity = 0; - bool ok = tree.nodeCapacity >= 2 && tree.proxyCapacity >= 1 && ( tree.nodeEnd & 1 ) == 0 && tree.nodeEnd >= 2 && - tree.nodeEnd <= tree.nodeCapacity; - - if ( ok ) - { - tree.nodes = (b3TreeNode*)b3Alloc( tree.nodeCapacity * sizeof( b3TreeNode ) ); - tree.parents = (int32_t*)b3Alloc( tree.nodeCapacity * sizeof( int32_t ) ); - tree.proxies = (b3TreeProxy*)b3Alloc( tree.proxyCapacity * sizeof( b3TreeProxy ) ); - - ok = (int)fread( tree.nodes, sizeof( b3TreeNode ), tree.nodeCapacity, file ) == tree.nodeCapacity; - ok = ok && (int)fread( tree.parents, sizeof( int32_t ), tree.nodeCapacity, file ) == tree.nodeCapacity; - ok = ok && (int)fread( tree.proxies, sizeof( b3TreeProxy ), tree.proxyCapacity, file ) == tree.proxyCapacity; - } - - if ( ok == false ) - { - b3Free( tree.nodes, tree.nodeCapacity * sizeof( b3TreeNode ) ); - b3Free( tree.parents, tree.nodeCapacity * sizeof( int32_t ) ); - b3Free( tree.proxies, tree.proxyCapacity * sizeof( b3TreeProxy ) ); - fclose( file ); - memset( &tree, 0, sizeof( b3DynamicTree ) ); - return tree; - } - - // An empty node has infinite bounds, so the scale has to skip it. - for ( int i = 0; i < tree.nodeEnd; ++i ) - { - b3TreeNode* node = tree.nodes + i; - if ( b3IsEmptyNode( node ) ) - { - continue; - } - - node->aabb.lowerBound = b3MulSV( scale, node->aabb.lowerBound ); - node->aabb.upperBound = b3MulSV( scale, node->aabb.upperBound ); - } - fclose( file ); return tree; diff --git a/src/dynamic_tree.h b/src/dynamic_tree.h deleted file mode 100644 index 906c59b..0000000 --- a/src/dynamic_tree.h +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#define B3_TREE_STACK_SIZE 512 - -// Used to mark a node as being moved such that pairs need to be generated and the tree -// may need to be rebuilt. This mark comes from a few sources: -// - updating the transform and AABB in the solver from movement -// - a joint disabling collision -// - creating a proxy -// - setting the transform on a body - -#define B3_MOVED_NODE ( 1u << 30 ) -#define B3_LEAF_NODE ( 1u << 31 ) -#define B3_NODE_INDEX_MASK ( 0xFFFFFFFFu & ~( B3_MOVED_NODE | B3_LEAF_NODE ) ) - -// Used to indicate empty nodes. It also passes as a leaf so that internal node -// processing will naturally skip it. -#define B3_EMPTY_NODE ( B3_NODE_INDEX_MASK | B3_LEAF_NODE ) - -#define B3_ROOT_NODE 0 - -B3_FORCE_INLINE bool b3IsLeaf( const b3TreeNode* node ) -{ - return ( node->flagIndex & B3_LEAF_NODE ) == B3_LEAF_NODE; -} - -B3_FORCE_INLINE bool b3IsNodeMoved( const b3TreeNode* node ) -{ - return ( node->flagIndex & B3_MOVED_NODE ) == B3_MOVED_NODE; -} - -B3_FORCE_INLINE bool b3IsEmptyNode( const b3TreeNode* node ) -{ - return node->flagIndex == B3_EMPTY_NODE; -} - -B3_FORCE_INLINE int b3GetLeftChild( const b3TreeNode* node ) -{ - return (int)( node->flagIndex & B3_NODE_INDEX_MASK ); -} - -B3_FORCE_INLINE int b3GetProxyId( const b3TreeNode* node ) -{ - return (int)( node->flagIndex & B3_NODE_INDEX_MASK ); -} - -B3_FORCE_INLINE int b3GetRootPair( const b3TreeNode* nodes ) -{ - const b3TreeNode* root = nodes + B3_ROOT_NODE; - return b3IsLeaf( root ) ? B3_ROOT_NODE : b3GetLeftChild( root ); -} - -B3_FORCE_INLINE b3TreeNode b3MakeEmptyNode( void ) -{ - return B3_LITERAL( b3TreeNode ){ - .aabb = - { - .lowerBound = { INFINITY, INFINITY, INFINITY }, - .upperBound = { -INFINITY, -INFINITY, -INFINITY }, - }, - .flagIndex = B3_EMPTY_NODE, - .height = 0, - }; -} - -typedef struct b3TreeView -{ - const b3TreeNode* nodes; - const b3TreeProxy* proxies; -} b3TreeView; - -static inline b3TreeView b3MakeTreeView( const b3DynamicTree* tree ) -{ - b3TreeView view = { - .nodes = tree->nodes, - .proxies = tree->proxies, - }; - return view; -} - -b3TreeStats b3TreeView_Query( const b3TreeView* view, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context ); -b3TreeStats b3TreeView_QueryClosest( const b3TreeView* view, b3Vec3 point, uint64_t maskBits, bool requireAllBits, - b3TreeQueryClosestCallbackFcn* callback, void* context, float* minDistanceSqr ); -b3TreeStats b3TreeView_RayCast( const b3TreeView* view, const b3RayCastInput* input, uint64_t maskBits, bool requireAllBits, - b3TreeRayCastCallbackFcn* callback, void* context ); -b3TreeStats b3TreeView_BoxCast( const b3TreeView* view, const b3BoxCastInput* input, uint64_t maskBits, bool requireAllBits, - b3TreeBoxCastCallbackFcn* callback, void* context ); - -static inline bool b3HasTreeMoved( const b3DynamicTree* tree ) -{ - return b3IsNodeMoved( tree->nodes + B3_ROOT_NODE ); -} - -static inline bool b3NeedsRebuild( const b3DynamicTree* tree ) -{ - return b3IsNodeMoved( tree->nodes + B3_ROOT_NODE ) || tree->dfsOrdered == false; -} - -int b3CreateTreeProxyInternal( b3DynamicTree* tree, b3AABB aabb, uint64_t categoryBits, uint64_t userData, bool markMoved ); -void b3DynamicTree_MoveProxyInternal( b3DynamicTree* tree, int proxyId, b3AABB aabb, bool markMoved ); - -void b3DynamicTree_MarkProxyMovedSerial( b3DynamicTree* tree, int proxyId ); -void b3DynamicTree_MarkProxyMoved( b3DynamicTree* tree, int proxyId, b3AABB aabb ); -void b3DynamicTree_ClearMoved( b3DynamicTree* tree ); -b3TreeStats b3DynamicTree_QueryRelaxed( const b3DynamicTree* tree, b3AABB aabb, uint64_t maskBits, bool requireAllBits, - b3TreeQueryCallbackFcn* callback, void* context ); -b3TreeStats b3DynamicTree_RayCastRelaxed( const b3DynamicTree* tree, const b3RayCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeRayCastCallbackFcn* callback, void* context ); -b3TreeStats b3DynamicTree_BoxCastRelaxed( const b3DynamicTree* tree, const b3BoxCastInput* input, uint64_t maskBits, - bool requireAllBits, b3TreeBoxCastCallbackFcn* callback, void* context ); -int b3DynamicTree_GatherMovedProxies( const b3DynamicTree* tree, int* proxyIds ); -void b3DynamicTree_Refit( b3DynamicTree* tree ); diff --git a/src/height_field.c b/src/height_field.c index 13ec97e..1b0307f 100644 --- a/src/height_field.c +++ b/src/height_field.c @@ -99,53 +99,6 @@ 21 3 22 */ -static b3Vec3 b3GetGridPoint( const float* heights, int columnCount, b3Vec3 scale, int row, int column ) -{ - return b3Mul( scale, (b3Vec3){ (float)column, heights[row * columnCount + column], (float)row } ); -} - -static b3Vec3 b3GetGridTriangleNormal( const float* heights, int columnCount, b3Vec3 scale, int row, int column, bool odd ) -{ - b3Vec3 point11 = b3GetGridPoint( heights, columnCount, scale, row, column ); - b3Vec3 point12 = b3GetGridPoint( heights, columnCount, scale, row, column + 1 ); - b3Vec3 point21 = b3GetGridPoint( heights, columnCount, scale, row + 1, column ); - b3Vec3 point22 = b3GetGridPoint( heights, columnCount, scale, row + 1, column + 1 ); - - b3Vec3 v1 = odd ? point22 : point11; - b3Vec3 v2 = odd ? point12 : point21; - b3Vec3 v3 = odd ? point21 : point12; - return b3Normalize( b3Cross( b3Sub( v2, v1 ), b3Sub( v3, v1 ) ) ); -} - -// Mark vertices as flat or concave. -static void b3MarkGridEdge( uint8_t* vertexFlags, int index1, int index2, b3Vec3 point1, b3Vec3 point2, b3Vec3 normal1, - b3Vec3 normal2, bool clockwise ) -{ - b3Vec3 outward = b3Cross( b3Normalize( b3Sub( point2, point1 ) ), normal1 ); - float angle = b3Atan2( b3Dot( normal2, outward ), b3Dot( normal2, normal1 ) ); - - // Quantize to match the mesh rule. - int8_t quantized = b3QuantizeEdgeAngle( clockwise ? -angle : angle ); - - if ( quantized != 0 ) - { - vertexFlags[index1] = (uint8_t)( vertexFlags[index1] & ~b3_flatVertex ); - vertexFlags[index2] = (uint8_t)( vertexFlags[index2] & ~b3_flatVertex ); - } - - if ( quantized < 0 ) - { - vertexFlags[index1] |= b3_concaveVertex; - vertexFlags[index2] |= b3_concaveVertex; - } -} - -static void b3MarkGridBoundary( uint8_t* vertexFlags, int index1, int index2 ) -{ - vertexFlags[index1] = (uint8_t)( vertexFlags[index1] & ~b3_flatVertex ); - vertexFlags[index2] = (uint8_t)( vertexFlags[index2] & ~b3_flatVertex ); -} - b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data ) { int columnCount = data->countX; @@ -166,8 +119,6 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data ) byteCount += b3AlignUp8( cellCount * sizeof( uint8_t ) ); int flagsOffset = (int)byteCount; byteCount += b3AlignUp8( triangleCount * sizeof( uint8_t ) ); - int vertexFlagOffset = (int)byteCount; - byteCount += b3AlignUp8( (size_t)( ( heightCount + 7 ) / 8 ) ); // Zero the whole blob so alignment padding is defined. The construction-time hash // sweeps raw bytes and would otherwise pick up uninitialized padding. @@ -182,7 +133,6 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data ) hf->heightsOffset = heightsOffset; hf->materialOffset = materialOffset; hf->flagsOffset = flagsOffset; - hf->vertexFlagOffset = vertexFlagOffset; hf->clockwise = data->clockwiseWinding; uint16_t* compressedHeights = (uint16_t*)( (intptr_t)hf + heightsOffset ); @@ -516,87 +466,18 @@ b3HeightFieldData* b3CreateHeightField( const b3HeightFieldDef* data ) B3_ASSERT( triangleIndex == triangleCount ); - // b3MeshVertexFlags - uint8_t* vertexFlags = (uint8_t*)b3Alloc( heightCount * sizeof( uint8_t ) ); - memset( vertexFlags, b3_flatVertex, heightCount * sizeof( uint8_t ) ); - - bool clockwise = hf->clockwise != 0; - int cellColumnCount = columnCount - 1; - int cellRowCount = rowCount - 1; - - for ( int row = 0; row < rowCount; ++row ) - { - for ( int column = 0; column < columnCount; ++column ) - { - int index = row * columnCount + column; - b3Vec3 point = b3GetGridPoint( heights, columnCount, scale, row, column ); - - if ( column < cellColumnCount ) - { - bool below = row < cellRowCount && materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE; - bool above = - row > 0 && materialIndices[( row - 1 ) * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE; - if ( below && above ) - { - b3Vec3 next = b3GetGridPoint( heights, columnCount, scale, row, column + 1 ); - b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false ); - b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row - 1, column, true ); - b3MarkGridEdge( vertexFlags, index + 1, index, next, point, normal1, normal2, clockwise ); - } - else if ( below || above ) - { - b3MarkGridBoundary( vertexFlags, index, index + 1 ); - } - } - - if ( row < cellRowCount ) - { - bool right = - column < cellColumnCount && materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE; - bool left = column > 0 && materialIndices[row * cellColumnCount + column - 1] != B3_HEIGHT_FIELD_HOLE; - if ( right && left ) - { - b3Vec3 next = b3GetGridPoint( heights, columnCount, scale, row + 1, column ); - b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false ); - b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column - 1, true ); - b3MarkGridEdge( vertexFlags, index, index + columnCount, point, next, normal1, normal2, clockwise ); - } - else if ( right || left ) - { - b3MarkGridBoundary( vertexFlags, index, index + columnCount ); - } - } - - if ( row < cellRowCount && column < cellColumnCount && - materialIndices[row * cellColumnCount + column] != B3_HEIGHT_FIELD_HOLE ) - { - b3Vec3 point21 = b3GetGridPoint( heights, columnCount, scale, row + 1, column ); - b3Vec3 point12 = b3GetGridPoint( heights, columnCount, scale, row, column + 1 ); - b3Vec3 normal1 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, false ); - b3Vec3 normal2 = b3GetGridTriangleNormal( heights, columnCount, scale, row, column, true ); - b3MarkGridEdge( vertexFlags, index + columnCount, index + 1, point21, point12, normal1, normal2, clockwise ); - } - } - } - - uint8_t* vertexBits = (uint8_t*)( (intptr_t)hf + vertexFlagOffset ); - for ( int i = 0; i < heightCount; ++i ) - { - if ( vertexFlags[i] == 0 ) - { - vertexBits[i >> 3] |= (uint8_t)( 1 << ( i & 7 ) ); - } - } - - b3Free( vertexFlags, heightCount * sizeof( uint8_t ) ); b3Free( decompressedHeights, heightCount * sizeof( float ) ); + // Content hash over the whole blob with the hash field zeroed, like b3HullData/b3MeshData. hf->hash = 0; - hf->hash = b3Hash64NonZero( (const uint8_t*)hf, hf->byteCount ); + hf->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (const uint8_t*)hf, hf->byteCount ) ); return hf; } +_Static_assert( b3_concaveEdge3 == 4 * b3_concaveEdge1, "bit math" ); +_Static_assert( b3_inverseConcaveEdge3 == 4 * b3_inverseConcaveEdge1, "bit math" ); + // Decode the four corner vertices of a height field cell into local space. // Output order matches the index naming used throughout this file: // corners[0] = (column, row), corners[1] = (column + 1, row), @@ -638,6 +519,8 @@ b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int t B3_ASSERT( triangleIndex < 2 * ( heightField->columnCount - 1 ) * ( heightField->rowCount - 1 ) ); b3Triangle triangle; + triangle.flags = b3GetHeightFieldFlags( heightField )[triangleIndex]; + int columnCount = heightField->columnCount; int quadIndex = triangleIndex >> 1; int row = quadIndex / ( columnCount - 1 ); @@ -680,6 +563,15 @@ b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int t { B3_SWAP( triangle.vertices[1], triangle.vertices[2] ); B3_SWAP( triangle.i2, triangle.i3 ); + + // Reversing winding swaps edge1 and edge3; edge2 (the diagonal) is preserved. + int flags = triangle.flags; + int edge1Bits = flags & ( b3_concaveEdge1 | b3_inverseConcaveEdge1 ); + int edge3Bits = flags & ( b3_concaveEdge3 | b3_inverseConcaveEdge3 ); + flags &= ~( b3_concaveEdge1 | b3_concaveEdge3 | b3_inverseConcaveEdge1 | b3_inverseConcaveEdge3 ); + flags |= edge1Bits << 2; + flags |= edge3Bits >> 2; + triangle.flags = flags; } return triangle; @@ -694,124 +586,6 @@ int b3GetHeightFieldMaterial( const b3HeightFieldData* heightField, int triangle return b3GetHeightFieldMaterialIndices( heightField )[cellIndex]; } -bool b3GetHeightFieldNeighborNormal( const b3HeightFieldData* heightField, int triangleIndex, int edgeIndex, b3Vec3* normal ) -{ - B3_ASSERT( 0 <= triangleIndex && triangleIndex < b3GetHeightFieldTriangleCount( heightField ) ); - B3_ASSERT( 0 <= edgeIndex && edgeIndex < 3 ); - - if ( heightField->clockwise ) - { - // Reflected - edgeIndex = 2 - edgeIndex; - } - - int cellColumnCount = heightField->columnCount - 1; - int cellRowCount = heightField->rowCount - 1; - int cellIndex = triangleIndex >> 1; - int row = cellIndex / cellColumnCount; - int column = cellIndex - row * cellColumnCount; - bool odd = ( triangleIndex & 1 ) == 1; - - // Get the row and column for the neighbor cell. - if ( edgeIndex == 0 ) - { - column += odd ? 1 : -1; - } - else if ( edgeIndex == 2 ) - { - row += odd ? 1 : -1; - } - - if ( row < 0 || row >= cellRowCount || column < 0 || column >= cellColumnCount ) - { - return false; - } - - int neighborCell = row * cellColumnCount + column; - - const uint8_t* materialIndices = b3GetHeightFieldMaterialIndices( heightField ); - if ( materialIndices[neighborCell] == B3_HEIGHT_FIELD_HOLE ) - { - return false; - } - - b3Triangle neighbor = b3GetHeightFieldTriangle( heightField, 2 * neighborCell + ( odd ? 0 : 1 ) ); - b3Vec3 e1 = b3Sub( neighbor.vertices[1], neighbor.vertices[0] ); - b3Vec3 e2 = b3Sub( neighbor.vertices[2], neighbor.vertices[0] ); - *normal = b3Normalize( b3Cross( e1, e2 ) ); - return true; -} - -bool b3IsHeightFieldVertexConvex( const b3HeightFieldData* heightField, int triangleIndex, int vertexIndex ) -{ - B3_ASSERT( 0 <= triangleIndex && triangleIndex < b3GetHeightFieldTriangleCount( heightField ) ); - B3_ASSERT( 0 <= vertexIndex && vertexIndex < 3 ); - - if ( heightField->vertexFlagOffset == 0 ) - { - return false; - } - - if ( heightField->clockwise ) - { - vertexIndex = ( 3 - vertexIndex ) % 3; - } - - int columnCount = heightField->columnCount; - int cellIndex = triangleIndex >> 1; - int row = cellIndex / ( columnCount - 1 ); - int column = cellIndex - row * ( columnCount - 1 ); - - int offsets[2][3] = { - { 0, columnCount, 1 }, - { columnCount + 1, 1, columnCount }, - }; - - int index = row * columnCount + column + offsets[triangleIndex & 1][vertexIndex]; - const uint8_t* vertexBits = (const uint8_t*)( (intptr_t)heightField + heightField->vertexFlagOffset ); - return ( vertexBits[index >> 3] & ( 1 << ( index & 7 ) ) ) != 0; -} - -int b3GetHeightFieldVertexTriangles( const b3HeightFieldData* heightField, int vertex, int triangles[6] ) -{ - int columnCount = heightField->columnCount; - int cellColumnCount = columnCount - 1; - int cellRowCount = heightField->rowCount - 1; - int row = vertex / columnCount; - int column = vertex - row * columnCount; - - int rowOffsets[4] = { 0, 0, -1, -1 }; - int columnOffsets[4] = { 0, -1, 0, -1 }; - int firstParity[4] = { 0, 0, 0, 1 }; - int lastParity[4] = { 0, 1, 1, 1 }; - - const uint8_t* materialIndices = b3GetHeightFieldMaterialIndices( heightField ); - int count = 0; - for ( int i = 0; i < 4; ++i ) - { - int cellRow = row + rowOffsets[i]; - int cellColumn = column + columnOffsets[i]; - if ( cellRow < 0 || cellRow >= cellRowCount || cellColumn < 0 || cellColumn >= cellColumnCount ) - { - continue; - } - - int cellIndex = cellRow * cellColumnCount + cellColumn; - if ( materialIndices[cellIndex] == B3_HEIGHT_FIELD_HOLE ) - { - continue; - } - - for ( int parity = firstParity[i]; parity <= lastParity[i]; ++parity ) - { - triangles[count] = 2 * cellIndex + parity; - count += 1; - } - } - - return count; -} - b3AABB b3ComputeHeightFieldAABB( const b3HeightFieldData* shape, b3Transform transform ) { return b3AABB_Transform( transform, shape->aabb ); @@ -835,7 +609,6 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const b3Vec3 shapeTranslation = input->translation; b3Vec3 scale = heightField->scale; - // The shape start is the center of the proxy. b3Vec3 shapeStart = b3AABB_Center( shapeBounds ); b3Vec3 shapeDelta = b3MulSV( input->maxFraction, shapeTranslation ); b3Vec3 shapeEnd = b3Add( shapeStart, shapeDelta ); @@ -976,7 +749,7 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const // nextFractionX / nextFractionZ advance in units of the clamped sweep // [minFraction, maxFraction], but bestFraction is a fraction of the full input // translation. Precompute the affine map from clamped space to input space so - // the loop termination test compares like with like. Otherwise it can exit + // the loop termination test compares like with like — otherwise it can exit // early and miss a closer hit in a later cell. float gridFractionScale = input->maxFraction * ( maxFraction - minFraction ); float gridFractionOffset = input->maxFraction * minFraction; @@ -996,12 +769,9 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const castBounds.lowerBound = b3Sub( b3Min( centerStart, centerEnd ), shapeExtents ); castBounds.upperBound = b3Add( b3Max( centerStart, centerEnd ), shapeExtents ); - // The ray origin is the center of the shape. b3V32 rayOrigin = b3LoadV( &shapeStart.x ); b3V32 rayTranslation = b3LoadV( &shapeTranslation.x ); - bool clockwise = heightField->clockwise; - while ( true ) { int column1, column2; @@ -1058,11 +828,6 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const b3Vec3 point21 = corners[2]; b3Vec3 point22 = corners[3]; - if ( clockwise ) - { - B3_SWAP( point12, point21 ); - } - // I know the min/max x and z values, but not the min/max heights. b3AABB bounds; bounds.lowerBound = b3Min( b3Min( point11, point12 ), b3Min( point21, point22 ) ); @@ -1082,8 +847,18 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const // Ray cast { b3V32 vertex1 = b3LoadV( &point11.x ); - b3V32 vertex2 = b3LoadV( &point21.x ); - b3V32 vertex3 = b3LoadV( &point12.x ); + b3V32 vertex2, vertex3; + + if ( heightField->clockwise ) + { + vertex2 = b3LoadV( &point12.x ); + vertex3 = b3LoadV( &point21.x ); + } + else + { + vertex2 = b3LoadV( &point21.x ); + vertex3 = b3LoadV( &point12.x ); + } float alpha = b3IntersectRayTriangle( rayOrigin, rayTranslation, vertex1, vertex2, vertex3 ); B3_ASSERT( 0 <= alpha && alpha <= 1.0f ); @@ -1092,7 +867,7 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const { b3Vec3 edge1 = b3Sub( point21, point11 ); b3Vec3 edge2 = b3Sub( point12, point11 ); - b3Vec3 normal = b3Cross( edge1, edge2 ); + b3Vec3 normal = heightField->clockwise ? b3Cross( edge2, edge1 ) : b3Cross( edge1, edge2 ); result.point = b3MulAdd( shapeStart, alpha, shapeTranslation ); result.normal = b3Normalize( normal ); @@ -1106,8 +881,18 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const { b3V32 vertex1 = b3LoadV( &point22.x ); - b3V32 vertex2 = b3LoadV( &point12.x ); - b3V32 vertex3 = b3LoadV( &point21.x ); + b3V32 vertex2, vertex3; + + if ( heightField->clockwise ) + { + vertex2 = b3LoadV( &point21.x ); + vertex3 = b3LoadV( &point12.x ); + } + else + { + vertex2 = b3LoadV( &point12.x ); + vertex3 = b3LoadV( &point21.x ); + } float alpha = b3IntersectRayTriangle( rayOrigin, rayTranslation, vertex1, vertex2, vertex3 ); B3_ASSERT( 0 <= alpha && alpha <= 1.0f ); @@ -1116,7 +901,7 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const { b3Vec3 edge1 = b3Sub( point22, point21 ); b3Vec3 edge2 = b3Sub( point12, point21 ); - b3Vec3 normal = b3Cross( edge1, edge2 ); + b3Vec3 normal = heightField->clockwise ? b3Cross( edge2, edge1 ) : b3Cross( edge1, edge2 ); result.point = b3MulAdd( shapeStart, alpha, shapeTranslation ); result.normal = b3Normalize( normal ); @@ -1131,55 +916,44 @@ b3CastOutput b3ShapeCastHeightField( const b3HeightFieldData* heightField, const else { // Shape cast + // todo back-side culling { - // shapeStart is the center of the proxy. - float signedVolume = b3SignedVolume( point11, point21, point12, shapeStart ); + // Shift origin to first vertex + b3Vec3 origin = point11; + b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( point21, origin ), b3Sub( point12, origin ) }; + pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; + pairInput.maxFraction = bestFraction; + pairInput.transform.p = b3Neg( origin ); - if ( signedVolume >= 0.0f ) + b3CastOutput pairOutput = b3ShapeCast( &pairInput ); + + if ( pairOutput.hit ) { - // Shift origin to first vertex - b3Vec3 origin = point11; - b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( point21, origin ), b3Sub( point12, origin ) }; - pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; - pairInput.maxFraction = bestFraction; - pairInput.transform.p = b3Neg( origin ); - - b3CastOutput pairOutput = b3ShapeCast( &pairInput ); - - if ( pairOutput.hit ) - { - bestFraction = pairOutput.fraction; - result = pairOutput; - result.point = b3Add( result.point, origin ); - result.triangleIndex = triangleIndex1; - result.materialIndex = materialIndex; - } + bestFraction = pairOutput.fraction; + result = pairOutput; + result.point = b3Add( result.point, origin ); + result.triangleIndex = triangleIndex1; + result.materialIndex = materialIndex; } } { - // shapeStart is the center of the proxy. - float signedVolume = b3SignedVolume( point21, point22, point12, shapeStart ); + // Shift origin to first vertex + b3Vec3 origin = point21; + b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( point22, origin ), b3Sub( point12, origin ) }; + pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; + pairInput.maxFraction = bestFraction; + pairInput.transform.p = b3Neg( origin ); - if ( signedVolume >= 0.0f ) + b3CastOutput pairOutput = b3ShapeCast( &pairInput ); + + if ( pairOutput.hit ) { - // Shift origin to first vertex - b3Vec3 origin = point21; - b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( point22, origin ), b3Sub( point12, origin ) }; - pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; - pairInput.maxFraction = bestFraction; - pairInput.transform.p = b3Neg( origin ); - - b3CastOutput pairOutput = b3ShapeCast( &pairInput ); - - if ( pairOutput.hit ) - { - bestFraction = pairOutput.fraction; - result = pairOutput; - result.point = b3Add( result.point, origin ); - result.triangleIndex = triangleIndex2; - result.materialIndex = materialIndex; - } + bestFraction = pairOutput.fraction; + result = pairOutput; + result.point = b3Add( result.point, origin ); + result.triangleIndex = triangleIndex2; + result.materialIndex = materialIndex; } } } @@ -1282,7 +1056,8 @@ bool b3OverlapHeightField( const b3HeightFieldData* shape, b3Transform shapeTran b3SimplexCache cache = { 0 }; - // Outer loop on rows and inner loop on columns so that triangle indices increase monotonically. + // Outer loop on rows and inner loop on columns so that triangle indices + // increase monotonically. for ( int row = minRow; row <= maxRow; ++row ) { if ( row < 0 || shape->rowCount - 1 <= row ) @@ -1436,7 +1211,6 @@ int b3CollideMoverAndHeightField( b3PlaneResult* planes, int capacity, const b3H b3SimplexCache cache = { 0 }; float radius = mover->radius; - b3Vec3 center = b3Lerp( mover->center1, mover->center2, 0.5f ); b3V32 center1 = b3LoadV( &mover->center1.x ); b3V32 center2 = b3LoadV( &mover->center2.x ); b3V32 r = b3SplatV( radius ); @@ -1456,8 +1230,6 @@ int b3CollideMoverAndHeightField( b3PlaneResult* planes, int capacity, const b3H int minCol = (int)floorf( localMinX / scale.x ); int maxCol = (int)floorf( localMaxX / scale.x ); - bool clockWise = shape->clockwise; - int planeCount = 0; // Outer loop on rows and inner loop on columns so that triangle indices @@ -1491,84 +1263,63 @@ int b3CollideMoverAndHeightField( b3PlaneResult* planes, int capacity, const b3H b3Vec3 point21 = corners[2]; b3Vec3 point22 = corners[3]; - if ( clockWise ) - { - B3_SWAP( point12, point21 ); - } - b3V32 v11 = b3LoadV( &point11.x ); b3V32 v12 = b3LoadV( &point12.x ); b3V32 v21 = b3LoadV( &point21.x ); b3V32 v22 = b3LoadV( &point22.x ); - bool overlap1 = b3TestBoundsTriangleOverlap( boundsCenter, boundsExtent, v11, v21, v12 ); - if ( overlap1 ) + if ( b3TestBoundsTriangleOverlap( boundsCenter, boundsExtent, v11, v21, v12 ) ) { - float signedVolume = b3SignedVolume( point11, point21, point12, center ); + b3Vec3 triangleVertices[] = { point11, point21, point12 }; + distanceInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; - // Front side? - if ( signedVolume >= 0.0f ) + // reset the cache + cache.count = 0; + + // get distance between triangle and mover + b3DistanceOutput distanceOutput = b3ShapeDistance( &distanceInput, &cache, NULL, 0 ); + + if ( distanceOutput.distance == 0.0f ) { - b3Vec3 triangleVertices[] = { point11, point21, point12 }; - distanceInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; + // todo SAT + } + else if ( distanceOutput.distance <= mover->radius ) + { + b3Plane plane = { distanceOutput.normal, mover->radius - distanceOutput.distance }; + planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA }; + planeCount += 1; - // reset the cache - cache.count = 0; - - // get distance between triangle and mover - b3DistanceOutput distanceOutput = b3ShapeDistance( &distanceInput, &cache, NULL, 0 ); - - if ( distanceOutput.distance == 0.0f ) + if ( planeCount == capacity ) { - // deep overlap - } - else if ( distanceOutput.distance <= mover->radius ) - { - int triangleIndex = 2 * cellIndex; - b3Plane plane = { distanceOutput.normal, mover->radius - distanceOutput.distance }; - planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA, triangleIndex, 0, material }; - planeCount += 1; - - if ( planeCount == capacity ) - { - return planeCount; - } + return planeCount; } } } - bool overlap2 = b3TestBoundsTriangleOverlap( boundsCenter, boundsExtent, v21, v22, v12 ); - if ( overlap2 ) + if ( b3TestBoundsTriangleOverlap( boundsCenter, boundsExtent, v21, v22, v12 ) ) { - float signedVolume = b3SignedVolume( point22, point12, point21, center ); + b3Vec3 triangleVertices[] = { point22, point12, point21 }; + distanceInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; - // Front side? - if ( signedVolume >= 0.0f ) + // reset the cache + cache.count = 0; + + // get distance between triangle and mover + b3DistanceOutput distanceOutput = b3ShapeDistance( &distanceInput, &cache, NULL, 0 ); + + if ( distanceOutput.distance == 0.0f ) { - b3Vec3 triangleVertices[] = { point22, point12, point21 }; - distanceInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; + // todo SAT + } + else if ( distanceOutput.distance <= mover->radius ) + { + b3Plane plane = { distanceOutput.normal, mover->radius - distanceOutput.distance }; + planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA }; + planeCount += 1; - // reset the cache - cache.count = 0; - - // get distance between triangle and mover - b3DistanceOutput distanceOutput = b3ShapeDistance( &distanceInput, &cache, NULL, 0 ); - - if ( distanceOutput.distance == 0.0f ) + if ( planeCount == capacity ) { - // deep overlap - } - else if ( distanceOutput.distance <= mover->radius ) - { - int triangleIndex = 2 * cellIndex + 1; - b3Plane plane = { distanceOutput.normal, mover->radius - distanceOutput.distance }; - planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA, triangleIndex, 0, material }; - planeCount += 1; - - if ( planeCount == capacity ) - { - return planeCount; - } + return planeCount; } } } @@ -1631,7 +1382,7 @@ b3HeightFieldData* b3CreateGrid( int rowCount, int columnCount, b3Vec3 scale, bo } b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, float rowFrequency, float columnFrequency, - bool makeHoles ) + bool makeHoles ) { int heightCount = rowCount * columnCount; float* heights = (float*)b3Alloc( heightCount * sizeof( float ) ); @@ -1639,18 +1390,14 @@ b3HeightFieldData* b3CreateWave( int rowCount, int columnCount, b3Vec3 scale, fl float omegaZ = 2.0f * B3_PI * rowFrequency; float omegaX = 2.0f * B3_PI * columnFrequency; - b3CosSin cs = { 0 }; - for ( int i = 0; i < rowCount; ++i ) { - cs = b3ComputeCosSin( omegaZ * i ); - float rowHeight = cs.sine; + float rowHeight = sinf( omegaZ * i ); for ( int j = 0; j < columnCount; ++j ) { int k = i * columnCount + j; - cs = b3ComputeCosSin( omegaX * j ); - float columnHeight = cs.sine; + float columnHeight = sinf( omegaX * j ); heights[k] = rowHeight * columnHeight; } } diff --git a/src/hull.c b/src/hull.c index dad8468..75bace9 100644 --- a/src/hull.c +++ b/src/hull.c @@ -3,13 +3,10 @@ // Dirk Gregorius contributed portions of this code -#include "hull.h" - #include "algorithm.h" +#include "hull_map.h" #include "math_internal.h" -#include "qsort.h" #include "shape.h" -#include "simd.h" #include "box3d/collision.h" #include "box3d/constants.h" @@ -29,8 +26,8 @@ #define B3_MARK_VISIBLE 0 #define B3_MARK_DELETE 1 -// Final hull is index-encoded with uint8_t, so vertex/edge/face counts are capped at 256. -#define B3_HULL_MAX_COUNT ( UINT8_MAX + 1 ) +// Final hull is index-encoded with uint8_t, so vertex/edge/face counts are capped at UINT8_MAX. +#define B3_HULL_LIMIT UINT8_MAX typedef struct b3QHListNode { @@ -123,16 +120,12 @@ typedef struct b3HullBuilder b3QHHalfEdge* edgeBase; int edgeCapacity; int edgeCount; - - // LIFO free list. Built with edge->next. - b3QHHalfEdge* edgeFreeHead; + b3QHHalfEdge* edgeFreeHead; // LIFO free list; overlays edge->next b3QHFace* faceBase; int faceCapacity; int faceCount; - - // LIFO free list. Built with face->link.next. - b3QHFace* faceFreeHead; + b3QHFace* faceFreeHead; // LIFO free list; overlays face->link.next // Reusable scratch buffers. b3QHHalfEdge** horizon; @@ -152,6 +145,7 @@ typedef struct b3HullBuilder int horizonStackCapacity; // Final counts of the constructed hull (vertexList / faceList / half-edges around faces). + // Populated by CleanHull; zero until then. int finalVertexCount; int finalHalfEdgeCount; int finalFaceCount; @@ -306,18 +300,17 @@ static b3QHFace* b3HullBuilder_NewFace( b3HullBuilder* b, b3QHVertex* v1, b3QHVe return face; } -// Remove face and add to free list. +// Remove face from faceList if still linked, clear its edge pointer, then push onto faceFreeHead. +// Uses face->link.next as the free-list next pointer (link.prev stays NULL, so b3QHList_Contains +// returns false on a free slot, as required by the retire-guard in ResolveFaces). static void b3HullBuilder_RetireFace( b3HullBuilder* b, b3QHFace* face ) { - // Sometimes a cone face gets merged and never added to the list. if ( b3QHList_Contains( &face->link ) ) { b3QHList_Remove( &face->link ); } - face->edge = NULL; - // link.prev is already NULL after Remove (or was never set). - B3_VALIDATE( face->link.prev == NULL ); + // link.prev is already NULL after Remove (or was never set). link.next holds free-list ptr. face->link.next = (b3QHListNode*)b->faceFreeHead; b->faceFreeHead = face; } @@ -399,8 +392,7 @@ static void b3FindFarthestPointsAlongCardinalAxes( int* index1Out, int* index2Ou } } -static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount, - const b3Vec3* vertexBase ) +static int b3FindFarthestPointFromLine( int index1, int index2, float tolerance, int vertexCount, const b3Vec3* vertexBase ) { b3Vec3 a = vertexBase[index1]; b3Vec3 b = vertexBase[index2]; @@ -766,8 +758,7 @@ static void b3HullBuilder_RecacheConflicts( b3QHFace* face, float minOutside ) b3QHVertex* maxVertex = NULL; float maxDistance = minOutside; - for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link; - node = node->next ) + for ( b3QHListNode* node = face->conflictListHead.link.next; node != &face->conflictListHead.link; node = node->next ) { b3QHVertex* vertex = (b3QHVertex*)node; float distance = b3PlaneSeparation( face->plane, vertex->position ); @@ -787,8 +778,7 @@ static b3QHVertex* b3HullBuilder_NextConflictVertex( const b3HullBuilder* b ) b3QHVertex* maxVertex = NULL; float maxDistance = b->minOutside; - for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; - faceNode = faceNode->next ) + for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next ) { const b3QHFace* face = (const b3QHFace*)faceNode; if ( face->maxConflict != NULL && face->maxConflictDistance > maxDistance ) @@ -821,8 +811,7 @@ static void b3HullBuilder_DrainConflictList( b3HullBuilder* b, b3QHFace* face ) // `entryEdge` is the half-edge in `face` whose twin lies in the just-deleted parent face, or // NULL for the seed. The frame skips `entryEdge` on recursive entries (it would be ignored // anyway since the parent's mark is now DELETE, but skipping saves one iteration). -static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge, - b3HorizonFrame* frameOut ) +static void b3HullBuilder_EnterHorizonFace( b3HullBuilder* b, b3QHFace* face, b3QHHalfEdge* entryEdge, b3HorizonFrame* frameOut ) { face->mark = B3_MARK_DELETE; b3HullBuilder_DrainConflictList( b, face ); @@ -1243,7 +1232,7 @@ static void b3HullBuilder_ResolveVertices( b3HullBuilder* b ) static void b3HullBuilder_ResolveFaces( b3HullBuilder* b ) { // Splice deleted faces out of the face list. Faces already retired by AbsorbFaces are no - // longer on faceList, so guard with b3QHList_Contains before removing. + // longer on faceList, so we guard with b3QHList_Contains before removing. b3QHListNode* node = b->faceList.link.next; while ( node != &b->faceList.link ) { @@ -1253,21 +1242,7 @@ static void b3HullBuilder_ResolveFaces( b3HullBuilder* b ) if ( face->mark == B3_MARK_DELETE && b3QHList_Contains( &face->link ) ) { B3_ASSERT( B3_LIST_EMPTY( &face->conflictListHead.link ) ); - - // Each half-edge is owned by exactly one face, so ring walks over the - // dead region retire every interior edge exactly once. Merge deleted - // faces are already off the face list. - b3QHHalfEdge* start = face->edge; - b3QHHalfEdge* edge = start; - do - { - b3QHHalfEdge* next = edge->next; - b3HullBuilder_RetireEdge( b, edge ); - edge = next; - } - while ( edge != start ); - - b3HullBuilder_RetireFace( b, face ); + b3QHList_Remove( &face->link ); } } @@ -1362,8 +1337,7 @@ static bool b3HullBuilder_IsConsistent( const b3HullBuilder* b ) return false; } - for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; - faceNode = faceNode->next ) + for ( const b3QHListNode* faceNode = b->faceList.link.next; faceNode != &b->faceList.link; faceNode = faceNode->next ) { const b3QHFace* face = (const b3QHFace*)faceNode; if ( face->edge->face != face ) @@ -1433,8 +1407,8 @@ static bool b3HullBuilder_HasHull( const b3HullBuilder* b ) } // Build the entire hull. Returns true iff the result satisfies Euler's identity. -static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount, - b3Vec3 origin, b3Vec3* shiftedPoints ) +static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int pointCount, int maxVertexCount, b3Vec3 origin, + b3Vec3* shiftedPoints ) { if ( pointCount < 4 ) { @@ -1447,13 +1421,12 @@ static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int } b3HullBuilder_ComputeTolerance( b, pointCount, shiftedPoints ); - bool haveInitialHull = b3HullBuilder_BuildInitialHull( b, pointCount, shiftedPoints ); - if ( haveInitialHull == false ) + if ( !b3HullBuilder_BuildInitialHull( b, pointCount, shiftedPoints ) ) { return false; } - int budget = b3ClampInt( maxVertexCount - 4, 0, B3_HULL_MAX_COUNT - 4 ); + int budget = b3ClampInt( maxVertexCount - 4, 0, B3_HULL_LIMIT - 4 ); b3QHVertex* vertex = b3HullBuilder_NextConflictVertex( b ); while ( vertex && budget > 0 ) @@ -1474,10 +1447,8 @@ static bool b3HullBuilder_Construct( b3HullBuilder* b, const b3Vec3* points, int typedef struct b3HullWorkSizes { - // Input point count - int N; - // Output point limit - int M; + int N; // pointCount + int M; // clamped maxVertexCount, in [4, B3_HULL_LIMIT] int vertexCapacity; int edgeCapacity; int faceCapacity; @@ -1507,19 +1478,39 @@ static b3HullWorkSizes b3ComputeHullWorkSizes( int pointCount, int clampedMaxCou s.vertexCapacity = pointCount + 4; // Edges and faces use free-list recycling; capacity is proportional to live hull size. - // edgeCapacity: peak is ~twice live edges plus cone edges. Minimum 48. - s.edgeCapacity = b3MaxInt( 48, 24 * s.M - 48 ); + // edgeCapacity: peak is ~twice live edges plus cone edges; floor 48. + s.edgeCapacity = 24 * s.M - 48; + if ( s.edgeCapacity < 48 ) + { + s.edgeCapacity = 48; + } - // faceCapacity: peak intermediate state live faces (<=2*M-4) plus full cone (<=3*M-6). Minimum 16. - s.faceCapacity = b3MaxInt( 16, 5 * s.M - 10 ); + // faceCapacity: peak intermediate state live faces (<=2*M-4) plus full cone (<=3*M-6); floor 16. + s.faceCapacity = 5 * s.M - 10; + if ( s.faceCapacity < 16 ) + { + s.faceCapacity = 16; + } - // Horizon/cone bounded by current half-edge count. Merged faces by face count. - s.horizonCapacity = b3MaxInt( 6, 3 * s.M - 6 ); + // Horizon/cone bounded by current half-edge count; mergedFaces by face count. + s.horizonCapacity = 3 * s.M - 6; + if ( s.horizonCapacity < 6 ) + { + s.horizonCapacity = 6; + } s.coneCapacity = s.horizonCapacity; - s.mergedFacesCapacity = b3MaxInt( 4, 2 * s.M - 4 ); + s.mergedFacesCapacity = 2 * s.M - 4; + if ( s.mergedFacesCapacity < 4 ) + { + s.mergedFacesCapacity = 4; + } // Horizon DFS depth is bounded by the number of live faces (Euler: <=2*M-4). - s.horizonStackCapacity = b3MaxInt( 4, 2 * s.M - 4 ); + s.horizonStackCapacity = 2 * s.M - 4; + if ( s.horizonStackCapacity < 4 ) + { + s.horizonStackCapacity = 4; + } size_t offset = 0; @@ -1616,85 +1607,25 @@ static b3HullHalfEdge* b3GetHullEdgesWrite( b3HullData* hull ) return (b3HullHalfEdge*)( (intptr_t)hull + hull->edgeOffset ); } -static float* b3GetHullSoaVerticesWrite( b3HullData* hull ) -{ - if ( hull->soaVertexOffset == 0 ) - { - return NULL; - } - return (float*)( (intptr_t)hull + hull->soaVertexOffset ); -} - -static float* b3GetHullSoaNormalsWrite( b3HullData* hull ) -{ - if ( hull->soaNormalOffset == 0 ) - { - return NULL; - } - return (float*)( (intptr_t)hull + hull->soaNormalOffset ); -} - -static void b3UpdateHullEdgeCosines( b3HullData* hull ) -{ - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Plane* planes = b3GetHullPlanes( hull ); - float* cosines = (float*)( (intptr_t)hull + hull->edgeCosineOffset ); - int count = hull->edgeCount / 2; - - for ( int i = 0; i < count; ++i ) - { - cosines[i] = b3Dot( planes[edges[2 * i].face].normal, planes[edges[2 * i + 1].face].normal ); - } -} - int b3FindHullSupportVertex( const b3HullData* hull, b3Vec3 direction ) { int bestIndex = B3_NULL_INDEX; float bestDot = -FLT_MAX; int vertexCount = hull->vertexCount; - const float* vx = b3GetHullSoaVertices( hull ); + const b3Vec3* points = b3GetHullPoints( hull ); - int soaVertexCount = b3GetHullSoaStride( vertexCount ); - const float* vy = vx + soaVertexCount; - const float* vz = vy + soaVertexCount; - - b3FloatW4 dx = b3SplatW4( direction.x ); - b3FloatW4 dy = b3SplatW4( direction.y ); - b3FloatW4 dz = b3SplatW4( direction.z ); - b3FloatW4 four = b3SplatW4( 4.0f ); - b3FloatW4 index = b3SetW4( 0.0f, 1.0f, 2.0f, 3.0f ); - b3FloatW4 bestDotW = b3SplatW4( -FLT_MAX ); - b3FloatW4 bestIndexW = b3SplatW4( -1.0f ); - - // Keep this at 4 wide to avoid regressing 4 wide platforms. - int loopCount = ( vertexCount + 3 ) & ~3; - for ( int i = 0; i < loopCount; i += 4 ) + for ( int index = 0; index < vertexCount; ++index ) { - b3FloatW4 dot = b3AddW4( b3AddW4( b3MulW4( dx, b3LoadW4( vx + i ) ), b3MulW4( dy, b3LoadW4( vy + i ) ) ), - b3MulW4( dz, b3LoadW4( vz + i ) ) ); - b3FloatW4 mask = b3GreaterThanW4( dot, bestDotW ); - bestDotW = b3BlendW4( bestDotW, dot, mask ); - bestIndexW = b3BlendW4( bestIndexW, index, mask ); - index = b3AddW4( index, four ); - } - - _Alignas( 16 ) float dots[4]; - _Alignas( 16 ) float indices[4]; - b3StoreW4( dots, bestDotW ); - b3StoreW4( indices, bestIndexW ); - - for ( int lane = 0; lane < 4; ++lane ) - { - int laneIndex = (int)indices[lane]; - if ( laneIndex >= 0 && ( dots[lane] > bestDot || ( dots[lane] == bestDot && laneIndex < bestIndex ) ) ) + float dot = b3Dot( direction, points[index] ); + if ( dot > bestDot ) { - bestIndex = laneIndex; - bestDot = dots[lane]; + bestIndex = index; + bestDot = dot; } } + B3_ASSERT( bestIndex >= 0 ); - B3_ASSERT( 0 <= bestIndex && bestIndex < vertexCount ); return bestIndex; } @@ -1941,51 +1872,6 @@ b3HullData* b3CreateRock( float radius ) return b3CreateHull( points, pointCount, pointCount ); } -// PEEL's BasicRandom. This is just for testing. -static uint32_t b3NextComplexHullRandom( uint32_t* state ) -{ - *state = *state * 2147001325u + 715136305u; - return *state; -} - -static float b3ComplexHullRandomFloat( uint32_t* state ) -{ - return (float)( b3NextComplexHullRandom( state ) & 0xffff ) / 65535.0f - 0.5f; -} - -static b3Vec3 b3ComplexHullRandomDirection( uint32_t* state ) -{ - b3Vec3 point; - float lengthSquared; - do - { - point.x = b3ComplexHullRandomFloat( state ); - point.y = b3ComplexHullRandomFloat( state ); - point.z = b3ComplexHullRandomFloat( state ); - lengthSquared = b3Dot( point, point ); - } - while ( lengthSquared > 0.25f ); - - return b3Normalize( point ); -} - -b3HullData* b3CreateComplexHull( float radius ) -{ - enum - { - pointCount = 32 - }; - - b3Vec3 points[pointCount]; - uint32_t state = 42; - for ( int i = 0; i < pointCount; ++i ) - { - points[i] = b3MulSV( radius, b3ComplexHullRandomDirection( &state ) ); - } - - return b3CreateHull( points, pointCount, pointCount ); -} - static void b3UpdateHullBounds( b3HullData* hull ) { const b3Vec3* points = b3GetHullPoints( hull ); @@ -2142,7 +2028,7 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou } b3Vec3 origin = points[0]; - int clampedMaxCount = b3ClampInt( maxVertexCount, 4, B3_MAX_HULL_VERTICES ); + int clampedMaxCount = b3ClampInt( maxVertexCount, 4, B3_HULL_LIMIT ); // Single allocation for all working memory. b3HullWorkSizes sizes = b3ComputeHullWorkSizes( pointCount, clampedMaxCount ); @@ -2154,41 +2040,40 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou b3Vec3* shiftedPoints = (b3Vec3*)( work + sizes.offsetShiftedPoints ); bool ok = b3HullBuilder_Construct( &builder, points, pointCount, clampedMaxCount, origin, shiftedPoints ); - if ( ok == false ) + if ( !ok ) { b3Free( work, sizes.totalBytes ); return NULL; } - if ( builder.finalVertexCount > B3_MAX_HULL_VERTICES ) + if ( builder.finalVertexCount >= B3_HULL_LIMIT ) { - b3Log( "hull final vertex count of %d exceeds limit of %d", builder.finalVertexCount, B3_MAX_HULL_VERTICES ); + b3Log( "hull final vertex count of %d exceeds limit of %d", builder.finalVertexCount, B3_HULL_LIMIT ); b3Free( work, sizes.totalBytes ); return NULL; } - if ( builder.finalFaceCount > B3_MAX_HULL_FACES ) + if ( builder.finalFaceCount >= B3_HULL_LIMIT ) { - b3Log( "hull final face count of %d exceeds limit of %d", builder.finalFaceCount, B3_MAX_HULL_FACES ); + b3Log( "hull final face count of %d exceeds limit of %d", builder.finalFaceCount, B3_HULL_LIMIT ); b3Free( work, sizes.totalBytes ); return NULL; } - int maxHalfEdgeCount = 2 * B3_MAX_HULL_EDGES; - if ( builder.finalHalfEdgeCount > maxHalfEdgeCount ) + if ( builder.finalHalfEdgeCount >= B3_HULL_LIMIT ) { - b3Log( "hull final half edge count of %d exceeds limit of %d", builder.finalHalfEdgeCount, maxHalfEdgeCount ); + b3Log( "hull final half edge count of %d exceeds limit of %d", builder.finalHalfEdgeCount, B3_HULL_LIMIT ); b3Free( work, sizes.totalBytes ); return NULL; } - // Walk lists into temp arrays bounded by B3_HULL_MAX_COUNT, stamping finalIndex on each node so + // Walk lists into temp arrays bounded by B3_HULL_LIMIT, stamping finalIndex on each node so // the resolution pass below is O(E + F) instead of O(E^2 + F^2). - const b3QHVertex* tempVertices[B3_HULL_MAX_COUNT]; + const b3QHVertex* tempVertices[B3_HULL_LIMIT]; int vertexCount = 0; for ( b3QHListNode* node = builder.vertexList.link.next; node != &builder.vertexList.link; node = node->next ) { - B3_ASSERT( vertexCount < B3_HULL_MAX_COUNT ); + B3_ASSERT( vertexCount <= B3_HULL_LIMIT - 1 ); b3QHVertex* vertex = (b3QHVertex*)node; vertex->finalIndex = vertexCount; @@ -2196,15 +2081,15 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou } // Collect edges in twin-paired order (i, i+1) by stamping each pair as we discover it. - const b3QHFace* tempFaces[B3_HULL_MAX_COUNT]; - const b3QHHalfEdge* tempEdges[B3_HULL_MAX_COUNT]; + // Replaces b3SortEdges' O(E^2) twin pairing. + const b3QHFace* tempFaces[B3_HULL_LIMIT]; + const b3QHHalfEdge* tempEdges[B3_HULL_LIMIT]; int faceCount = 0; int edgeCount = 0; - for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link; - faceNode = faceNode->next ) + for ( b3QHListNode* faceNode = builder.faceList.link.next; faceNode != &builder.faceList.link; faceNode = faceNode->next ) { - B3_ASSERT( faceCount < B3_HULL_MAX_COUNT ); + B3_ASSERT( faceCount <= B3_HULL_LIMIT - 1 ); b3QHFace* face = (b3QHFace*)faceNode; face->finalIndex = faceCount; @@ -2215,7 +2100,7 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou { if ( edge->finalIndex < 0 ) { - B3_ASSERT( edgeCount + 1 < B3_HULL_MAX_COUNT ); + B3_ASSERT( edgeCount + 1 <= B3_HULL_LIMIT - 1 ); edge->finalIndex = edgeCount; tempEdges[edgeCount++] = edge; @@ -2227,9 +2112,6 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou while ( edge != face->edge ); } - int soaVertexCount = b3GetHullSoaStride( vertexCount ); - int soaNormalCount = b3GetHullSoaStride( faceCount ); - // Allocate the hull. Arrays hang off the end. size_t byteCount = b3AlignUp8( sizeof( b3HullData ) ); int vertexOffset = (int)byteCount; @@ -2238,16 +2120,10 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou byteCount += b3AlignUp8( vertexCount * (int)sizeof( b3Vec3 ) ); int edgeOffset = (int)byteCount; byteCount += b3AlignUp8( edgeCount * (int)sizeof( b3HullHalfEdge ) ); - int planeOffset = (int)byteCount; - byteCount += b3AlignUp8( faceCount * (int)sizeof( b3Plane ) ); int faceOffset = (int)byteCount; byteCount += b3AlignUp8( faceCount * (int)sizeof( b3HullFace ) ); - int soaVertexOffset = (int)byteCount; - byteCount += b3AlignUp8( 3 * soaVertexCount * (int)sizeof( float ) ); - int soaNormalOffset = (int)byteCount; - byteCount += b3AlignUp8( 3 * soaNormalCount * (int)sizeof( float ) ); - int edgeCosineOffset = (int)byteCount; - byteCount += b3AlignUp8( ( edgeCount / 2 ) * (int)sizeof( float ) ); + int planeOffset = (int)byteCount; + byteCount += b3AlignUp8( faceCount * (int)sizeof( b3Plane ) ); b3HullData* hull = b3Alloc( byteCount ); memset( hull, 0, byteCount ); @@ -2256,11 +2132,8 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou hull->vertexOffset = vertexOffset; hull->pointOffset = pointOffset; hull->edgeOffset = edgeOffset; - hull->planeOffset = planeOffset; hull->faceOffset = faceOffset; - hull->soaVertexOffset = soaVertexOffset; - hull->soaNormalOffset = soaNormalOffset; - hull->edgeCosineOffset = edgeCosineOffset; + hull->planeOffset = planeOffset; hull->vertexCount = vertexCount; hull->edgeCount = edgeCount; @@ -2273,29 +2146,11 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou b3HullFace* faces = (b3HullFace*)( (intptr_t)hull + hull->faceOffset ); b3Vec3* finalPoints = b3GetHullPointsWrite( hull ); b3Plane* planes = b3GetHullPlanesWrite( hull ); - float* soaVertices = b3GetHullSoaVerticesWrite( hull ); - float* soaNormals = b3GetHullSoaNormalsWrite( hull ); - - float* vx = soaVertices; - float* vy = vx + soaVertexCount; - float* vz = vy + soaVertexCount; for ( int index = 0; index < vertexCount; ++index ) { vertices[index].edge = 0; - b3Vec3 p = tempVertices[index]->position; - finalPoints[index] = p; - - vx[index] = p.x; - vy[index] = p.y; - vz[index] = p.z; - } - - for ( int index = vertexCount; index < soaVertexCount; ++index ) - { - vx[index] = vx[0]; - vy[index] = vy[0]; - vz[index] = vz[0]; + finalPoints[index] = tempVertices[index]->position; } for ( int index = 0; index < edgeCount; ++index ) @@ -2314,10 +2169,6 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou vertices[edge->origin->finalIndex].edge = (uint8_t)index; } - float* nx = soaNormals; - float* ny = nx + soaNormalCount; - float* nz = ny + soaNormalCount; - for ( int index = 0; index < faceCount; ++index ) { const b3QHFace* face = tempFaces[index]; @@ -2325,25 +2176,11 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou faces[index].edge = (uint8_t)face->edge->finalIndex; planes[index] = face->plane; - - b3Vec3 n = face->plane.normal; - nx[index] = n.x; - ny[index] = n.y; - nz[index] = n.z; - } - - for ( int index = faceCount; index < soaNormalCount; ++index ) - { - nx[index] = 0.0f; - ny[index] = 0.0f; - nz[index] = 0.0f; } // All builder pointers are dead from here on. b3Free( work, sizes.totalBytes ); - b3UpdateHullEdgeCosines( hull ); - b3UpdateHullBounds( hull ); bool success = b3UpdateHullBulkProperties( hull ); if ( success == false ) @@ -2359,7 +2196,7 @@ b3HullData* b3CreateHull( const b3Vec3* points, int pointCount, int maxVertexCou } hull->hash = 0; - hull->hash = b3Hash64NonZero( (uint8_t*)hull, hull->byteCount ); + hull->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)hull, hull->byteCount ) ); return hull; } @@ -2371,7 +2208,7 @@ b3HullData* b3CloneHull( const b3HullData* hull ) return NULL; } - b3HullData* clone = b3Alloc( hull->byteCount ); + b3HullData* clone = (b3HullData*)b3Alloc( hull->byteCount ); memcpy( clone, hull, hull->byteCount ); return clone; @@ -2379,7 +2216,9 @@ b3HullData* b3CloneHull( const b3HullData* hull ) uint64_t b3HashHullData( const b3HullData* hull ) { - return hull->hash; + // The baked content hash already covers byteCount. Spread the 32 bits across 64 so the table + // can use the high bits for its fast reject fragment. + return (uint64_t)hull->hash * 0x9E3779B97F4A7C15ull; } bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 ) @@ -2399,10 +2238,9 @@ bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 ) // Hull identity covers every byte, so the structs carry explicit padding. These lock // the layout, re-audit padding if a size changes. -_Static_assert( sizeof( b3HullData ) == 152, "unexpected hull data size" ); -_Static_assert( sizeof( b3BoxHull ) == 696, "unexpected box hull size" ); +_Static_assert( sizeof( b3HullData ) == 136, "unexpected hull data size" ); +_Static_assert( sizeof( b3BoxHull ) == 440, "unexpected box hull size" ); -// Implement b3HullMap. #define NAME b3HullMap #define KEY_TY const b3HullData* #define VAL_TY int @@ -2431,7 +2269,7 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra return NULL; } - b3HullData* hull = b3Alloc( original->byteCount ); + b3HullData* hull = (b3HullData*)b3Alloc( original->byteCount ); memcpy( hull, original, original->byteCount ); b3Vec3 safeScale = b3SafeScale( scale ); @@ -2448,9 +2286,9 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra { const b3HullFace* face = faces + i; - int startEdgeIndex = face->edge; - int currentEdgeIndex = startEdgeIndex; - int prevEdgeIndex = B3_NULL_INDEX; + uint8_t startEdgeIndex = face->edge; + uint8_t currentEdgeIndex = startEdgeIndex; + uint8_t prevEdgeIndex = UINT8_MAX; do { @@ -2466,7 +2304,7 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra } while ( currentEdgeIndex != startEdgeIndex ); - B3_ASSERT( prevEdgeIndex != B3_NULL_INDEX ); + B3_ASSERT( prevEdgeIndex != UINT8_MAX ); currentEdgeIndex = startEdgeIndex; @@ -2474,7 +2312,7 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra { b3HullHalfEdge* edge = edges + currentEdgeIndex; uint8_t nextIndex = edge->next; - edge->next = (uint8_t)prevEdgeIndex; + edge->next = prevEdgeIndex; if ( currentEdgeIndex < edge->twin ) { @@ -2501,32 +2339,12 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra b3Matrix3 matrix = b3MakeMatrixFromQuat( transform.q ); b3Vec3* points = b3GetHullPointsWrite( hull ); - int soaVertexCount = b3GetHullSoaStride( vertexCount ); - float* vx = b3GetHullSoaVerticesWrite( hull ); - float* vy = vx + soaVertexCount; - float* vz = vy + soaVertexCount; - for ( int i = 0; i < vertexCount; ++i ) { - b3Vec3 p = b3Add( b3MulMV( matrix, b3Mul( safeScale, points[i] ) ), transform.p ); - points[i] = p; - vx[i] = p.x; - vy[i] = p.y; - vz[i] = p.z; - } - - for ( int i = vertexCount; i < soaVertexCount; ++i ) - { - vx[i] = vx[0]; - vy[i] = vy[0]; - vz[i] = vz[0]; + points[i] = b3Add( b3MulMV( matrix, b3Mul( safeScale, points[i] ) ), transform.p ); } b3Plane* planes = b3GetHullPlanesWrite( hull ); - int soaNormalCount = b3GetHullSoaStride( faceCount ); - float* nx = b3GetHullSoaNormalsWrite( hull ); - float* ny = nx + soaNormalCount; - float* nz = ny + soaNormalCount; for ( int i = 0; i < faceCount; ++i ) { @@ -2572,21 +2390,8 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra normal = b3MulSV( 1.0f / area, normal ); planes[i] = b3MakePlaneFromNormalAndPoint( normal, centroid ); - - nx[i] = normal.x; - ny[i] = normal.y; - nz[i] = normal.z; } - for ( int i = faceCount; i < soaNormalCount; ++i ) - { - nx[i] = 0.0f; - ny[i] = 0.0f; - nz[i] = 0.0f; - } - - b3UpdateHullEdgeCosines( hull ); - b3UpdateHullBounds( hull ); bool success = b3UpdateHullBulkProperties( hull ); if ( success == false ) @@ -2595,9 +2400,8 @@ b3HullData* b3CloneAndTransformHull( const b3HullData* original, b3Transform tra return NULL; } - // Must ensure the hash is 0 so it doesn't contribute to itself. hull->hash = 0; - hull->hash = b3Hash64NonZero( (uint8_t*)hull, hull->byteCount ); + hull->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)hull, hull->byteCount ) ); B3_VALIDATE( b3IsValidHull( hull ) ); @@ -2757,7 +2561,7 @@ int b3CollideMoverAndHull( b3PlaneResult* result, const b3HullData* shape, const if ( distanceOutput.distance <= totalRadius ) { b3Plane plane = { distanceOutput.normal, totalRadius - distanceOutput.distance }; - *result = (b3PlaneResult){ plane, distanceOutput.pointA, 0, 0, 0 }; + *result = (b3PlaneResult){ plane, distanceOutput.pointA }; return 1; } @@ -2837,11 +2641,8 @@ static const b3BoxHull s_boxHull = { .vertexOffset = offsetof( b3BoxHull, boxVertices ), .pointOffset = offsetof( b3BoxHull, boxPoints ), .edgeOffset = offsetof( b3BoxHull, boxEdges ), - .planeOffset = offsetof( b3BoxHull, boxPlanes ), .faceOffset = offsetof( b3BoxHull, boxFaces ), - .soaVertexOffset = offsetof( b3BoxHull, vx ), - .soaNormalOffset = offsetof( b3BoxHull, nx ), - .edgeCosineOffset = offsetof( b3BoxHull, edgeCosines ), + .planeOffset = offsetof( b3BoxHull, boxPlanes ), }, .boxVertices = { @@ -2876,8 +2677,6 @@ static const b3BoxHull s_boxHull = { b3BoxHull b3MakeTransformedBoxHull( float hx, float hy, float hz, b3Transform transform ) { - B3_ASSERT( b3IsValidTransform( transform ) ); - b3BoxHull boxHull = s_boxHull; float minH = 0.2f * B3_LINEAR_SLOP; @@ -2911,64 +2710,8 @@ b3BoxHull b3MakeTransformedBoxHull( float hx, float hy, float hz, b3Transform tr boxHull.boxPoints[6] = b3TransformPoint( transform, (b3Vec3){ -h.x, -h.y, -h.z } ); boxHull.boxPoints[7] = b3TransformPoint( transform, (b3Vec3){ h.x, -h.y, -h.z } ); - // SOA - boxHull.vx[0] = boxHull.boxPoints[0].x; - boxHull.vx[1] = boxHull.boxPoints[1].x; - boxHull.vx[2] = boxHull.boxPoints[2].x; - boxHull.vx[3] = boxHull.boxPoints[3].x; - boxHull.vx[4] = boxHull.boxPoints[4].x; - boxHull.vx[5] = boxHull.boxPoints[5].x; - boxHull.vx[6] = boxHull.boxPoints[6].x; - boxHull.vx[7] = boxHull.boxPoints[7].x; - - boxHull.vy[0] = boxHull.boxPoints[0].y; - boxHull.vy[1] = boxHull.boxPoints[1].y; - boxHull.vy[2] = boxHull.boxPoints[2].y; - boxHull.vy[3] = boxHull.boxPoints[3].y; - boxHull.vy[4] = boxHull.boxPoints[4].y; - boxHull.vy[5] = boxHull.boxPoints[5].y; - boxHull.vy[6] = boxHull.boxPoints[6].y; - boxHull.vy[7] = boxHull.boxPoints[7].y; - - boxHull.vz[0] = boxHull.boxPoints[0].z; - boxHull.vz[1] = boxHull.boxPoints[1].z; - boxHull.vz[2] = boxHull.boxPoints[2].z; - boxHull.vz[3] = boxHull.boxPoints[3].z; - boxHull.vz[4] = boxHull.boxPoints[4].z; - boxHull.vz[5] = boxHull.boxPoints[5].z; - boxHull.vz[6] = boxHull.boxPoints[6].z; - boxHull.vz[7] = boxHull.boxPoints[7].z; - - boxHull.nx[0] = boxHull.boxPlanes[0].normal.x; - boxHull.nx[1] = boxHull.boxPlanes[1].normal.x; - boxHull.nx[2] = boxHull.boxPlanes[2].normal.x; - boxHull.nx[3] = boxHull.boxPlanes[3].normal.x; - boxHull.nx[4] = boxHull.boxPlanes[4].normal.x; - boxHull.nx[5] = boxHull.boxPlanes[5].normal.x; - boxHull.nx[6] = 0.0f; - boxHull.nx[7] = 0.0f; - - boxHull.ny[0] = boxHull.boxPlanes[0].normal.y; - boxHull.ny[1] = boxHull.boxPlanes[1].normal.y; - boxHull.ny[2] = boxHull.boxPlanes[2].normal.y; - boxHull.ny[3] = boxHull.boxPlanes[3].normal.y; - boxHull.ny[4] = boxHull.boxPlanes[4].normal.y; - boxHull.ny[5] = boxHull.boxPlanes[5].normal.y; - boxHull.ny[6] = 0.0f; - boxHull.ny[7] = 0.0f; - - boxHull.nz[0] = boxHull.boxPlanes[0].normal.z; - boxHull.nz[1] = boxHull.boxPlanes[1].normal.z; - boxHull.nz[2] = boxHull.boxPlanes[2].normal.z; - boxHull.nz[3] = boxHull.boxPlanes[3].normal.z; - boxHull.nz[4] = boxHull.boxPlanes[4].normal.z; - boxHull.nz[5] = boxHull.boxPlanes[5].normal.z; - boxHull.nz[6] = 0.0f; - boxHull.nz[7] = 0.0f; - - // Must ensure the hash is 0 so it doesn't contribute to itself. boxHull.base.hash = 0; - boxHull.base.hash = b3Hash64NonZero( (uint8_t*)&boxHull.base, boxHull.base.byteCount ); + boxHull.base.hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)&boxHull, sizeof( b3BoxHull ) ) ); return boxHull; } @@ -3041,265 +2784,8 @@ void b3ScaleBox( b3Vec3* halfWidths, b3Transform* transform, b3Vec3 postScale, f // todo use new hull scaling technique b3BoxHull b3MakeScaledBoxHull( b3Vec3 halfWidths, b3Transform transform, b3Vec3 postScale ) { - B3_ASSERT( b3IsValidTransform( transform ) ); - b3Vec3 h = halfWidths; b3Transform xf = transform; b3ScaleBox( &h, &xf, postScale, 4.0f * B3_LINEAR_SLOP ); return b3MakeTransformedBoxHull( h.x, h.y, h.z, xf ); } - -// 2D hull (Andrew's monotone chain) - -// cross(b - a, c - a) -static inline float b3Cross2D( b3Vec2 a, b3Vec2 b, b3Vec2 c ) -{ - return ( b.x - a.x ) * ( c.y - a.y ) - ( b.y - a.y ) * ( c.x - a.x ); -} - -// Iteratively remove the vertices contributing the least area. -int b3SimplifyHull2D( b3Point2D* hull, int count1, int target ) -{ - B3_ASSERT( target >= 3 ); - - if ( count1 <= 3 ) - { - return count1; - } - - float linearSlop = B3_LINEAR_SLOP; - float areaTol = 0.25f * linearSlop * linearSlop; - int count2 = count1; - - for ( ;; ) - { - float minArea = FLT_MAX; - int minIndex = 0; - - for ( int i = 0; i < count2; i++ ) - { - int prev = ( i + count2 - 1 ) % count2; - int next = ( i + 1 ) % count2; - float area = b3Cross2D( hull[prev].p, hull[i].p, hull[next].p ); - B3_VALIDATE( area >= -FLT_EPSILON ); - - if ( area + areaTol < minArea ) - { - minArea = area; - minIndex = i; - } - } - - if ( count2 <= 3 || ( minArea > areaTol && count2 <= target ) ) - { - break; - } - - count2 -= 1; - if ( minIndex < count2 ) - { - memmove( hull + minIndex, hull + ( minIndex + 1 ), ( count2 - minIndex ) * sizeof( b3Point2D ) ); - } - } - - return count2; -} - -// Comparator for sorting points for the 2D hull. -static inline bool b3IsPoint2DLess( const b3Point2D* a, const b3Point2D* b ) -{ - if ( a->p.x != b->p.x ) - { - return a->p.x < b->p.x; - } - - if ( a->p.y != b->p.y ) - { - return a->p.y < b->p.y; - } - - return a->originalIndex < b->originalIndex; -} - -// Welds points that have been sorted O(n) time -static int b3Weld2D( b3Point2D* pts, int count1 ) -{ - if ( count1 <= 1 ) - { - return count1; - } - - float linearSlop = 0.25f * B3_LINEAR_SLOP; - float tolSqr = linearSlop * linearSlop; - - int count2 = 1; - int baseIndex = 0; - for ( int i = 1; i < count1; i++ ) - { - float distanceSqr = b3DistanceSquared2( pts[i].p, pts[baseIndex].p ); - if ( distanceSqr < tolSqr ) - { - if ( pts[i].originalIndex < pts[baseIndex].originalIndex ) - { - pts[baseIndex] = pts[i]; - } - } - else - { - pts[count2] = pts[i]; - baseIndex = count2; - count2 += 1; - } - } - - return count2; -} - -// Only merge points that line up exactly. -static int b3MergeExact2D( b3Point2D* pts, int count1 ) -{ - float separationTol = B3_LINEAR_SLOP; - - int count2 = 0; - for ( int i = 0; i < count1; i++ ) - { - b3Point2D point = pts[i]; - if ( count2 > 0 && pts[count2 - 1].p.x == point.p.x && pts[count2 - 1].p.y == point.p.y ) - { - if ( point.separation < pts[count2 - 1].separation - separationTol ) - { - pts[count2 - 1] = point; - } - } - else - { - pts[count2] = point; - count2 += 1; - } - } - - return count2; -} - -// Andrew's monotone chain convex hull algorithm -// hull must have space for 2 * count1 points -int b3Hull2D( b3Point2D* pts, int count, b3Point2D* hull, int flags ) -{ - if ( count <= 0 ) - { - return 0; - } - -#define LESS( i, j ) b3IsPoint2DLess( pts + (int)( i ), pts + (int)( j ) ) -#define SWAP( i, j ) \ - do \ - { \ - b3Point2D swapPoint = pts[(int)( i )]; \ - pts[(int)( i )] = pts[(int)( j )]; \ - pts[(int)( j )] = swapPoint; \ - } \ - while ( 0 ) - - QSORT( count, LESS, SWAP ); - -#undef LESS -#undef SWAP - - int count1; - if ( flags & b3_hull2DExactMerge ) - { - count1 = b3MergeExact2D( pts, count ); - } - else - { - count1 = b3Weld2D( pts, count ); - } - - bool keepCollinear = ( flags & b3_hull2DKeepCollinear ) != 0; - - int count2 = 0; - if ( count1 <= 2 ) - { - for ( int i = 0; i < count1; i++ ) - { - hull[i] = pts[i]; - } - - count2 = count1; - } - else - { - for ( int i = 0; i < count1; i++ ) - { - while ( count2 >= 2 ) - { - float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p ); - if ( area > 0.0f || ( keepCollinear && area == 0.0f ) ) - { - break; - } - - count2 -= 1; - } - - B3_VALIDATE( count2 < 2 * count1 ); - hull[count2] = pts[i]; - count2 += 1; - } - - int lowerCount = count2 + 1; - int lowerIndex = count2 - 2; - - for ( int i = count1 - 2; i >= 0; i-- ) - { - if ( lowerIndex >= 0 && hull[lowerIndex].p.x == pts[i].p.x && hull[lowerIndex].p.y == pts[i].p.y ) - { - lowerIndex -= 1; - if ( i > 0 ) - { - continue; - } - } - - while ( count2 >= lowerCount ) - { - float area = b3Cross2D( hull[count2 - 2].p, hull[count2 - 1].p, pts[i].p ); - if ( area > 0.0f || ( keepCollinear && area == 0.0f ) ) - { - break; - } - - count2 -= 1; - } - - B3_VALIDATE( count2 < 2 * count1 ); - hull[count2] = pts[i]; - count2 += 1; - } - - B3_VALIDATE( hull[0].originalIndex == hull[count2 - 1].originalIndex ); - count2 -= 1; - } - - B3_VALIDATE( count2 <= count1 ); - - if ( flags & b3_hull2DIndexOrder ) - { -#define LESS( i, j ) ( hull[(int)( i )].originalIndex < hull[(int)( j )].originalIndex ) -#define SWAP( i, j ) \ - do \ - { \ - b3Point2D swapPoint = hull[(int)( i )]; \ - hull[(int)( i )] = hull[(int)( j )]; \ - hull[(int)( j )] = swapPoint; \ - } \ - while ( 0 ) - - QSORT( count2, LESS, SWAP ); - -#undef LESS -#undef SWAP - } - - return count2; -} diff --git a/src/hull.h b/src/hull_map.h similarity index 56% rename from src/hull.h rename to src/hull_map.h index 23ebbe4..5b50c56 100644 --- a/src/hull.h +++ b/src/hull_map.h @@ -7,19 +7,13 @@ #include -// Big enough to handle AVX2. -#define B3_HULL_SOA_PADDING 8 - -static inline int b3GetHullSoaStride( int count ) -{ - return ( count + B3_HULL_SOA_PADDING - 1 ) & ~( B3_HULL_SOA_PADDING - 1 ); -} - +// Content hash and equality over the whole baked hull. Shared by every hull +// de-duplication map so they agree on identity. uint64_t b3HashHullData( const b3HullData* hull ); bool b3CompareHullData( const b3HullData* hull1, const b3HullData* hull2 ); -// Map keyed by hull content. The world hull database uses the value as a reference count, -// while compound baking stores uses the value as a byte offset. Implementation is in hull.c. +// Map keyed by hull content. The world hull database stores a reference count, +// compound baking stores a byte offset. Implementation lives in hull.c. #define NAME b3HullMap #define KEY_TY const b3HullData* #define VAL_TY int diff --git a/src/island.c b/src/island.c index 111b304..625a1b3 100644 --- a/src/island.c +++ b/src/island.c @@ -29,7 +29,7 @@ b3Island* b3CreateIsland( b3World* world, int setIndex ) B3_ASSERT( world->islands.data[islandId].setIndex == B3_NULL_INDEX ); } - b3SolverSet* set = b3GetSolverSet( world, setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); b3Island* island = b3Array_Get( world->islands, islandId ); island->setIndex = setIndex; @@ -55,7 +55,7 @@ void b3DestroyIsland( b3World* world, int islandId ) // assume island is empty b3Island* island = b3Array_Get( world->islands, islandId ); - b3SolverSet* set = b3GetSolverSet( world, island->setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, island->setIndex ); { int localIndex = island->localIndex; int lastIndex = set->islandSims.count - 1; @@ -498,7 +498,7 @@ void b3SplitIsland( b3World* world, int baseId ) } } - // Island is still fully connected, no split needed. + // Early return — island is still fully connected, no split needed. if ( componentCount == 1 ) { baseIsland->constraintRemoveCount = 0; diff --git a/src/joint.c b/src/joint.c index 4250ace..5875f55 100644 --- a/src/joint.c +++ b/src/joint.c @@ -62,21 +62,6 @@ b3MotorJointDef b3DefaultMotorJointDef( void ) return def; } -b3MoverJointDef b3DefaultMoverJointDef( void ) -{ - b3MoverJointDef def = { 0 }; - def.base = b3DefaultJointDef(); - return def; -} - -b3PogoJointDef b3DefaultPogoJointDef( void ) -{ - b3PogoJointDef def = { 0 }; - def.base = b3DefaultJointDef(); - def.normal = b3Vec3_axisY; - return def; -} - b3FilterJointDef b3DefaultFilterJointDef( void ) { b3FilterJointDef def = { 0 }; @@ -135,7 +120,7 @@ b3ExplosionDef b3DefaultExplosionDef( void ) b3Joint* b3GetJointFullId( b3World* world, b3JointId jointId ) { int id = jointId.index1 - 1; - b3Joint* joint = b3Array_Get( world->joints, id ); + b3Joint* joint = b3Array_Get( world->joints, id ); B3_ASSERT( joint->jointId == id && joint->generation == jointId.generation ); return joint; } @@ -146,11 +131,11 @@ b3JointSim* b3GetJointSim( b3World* world, b3Joint* joint ) { B3_ASSERT( 0 <= joint->colorIndex && joint->colorIndex < B3_GRAPH_COLOR_COUNT ); b3GraphColor* color = world->constraintGraph.colors + joint->colorIndex; - return b3Array_Get( color->jointSims, joint->localIndex ); + return b3Array_Get( color->jointSims, joint->localIndex ); } - b3SolverSet* set = b3GetSolverSet( world, joint->setIndex ); - return b3Array_Get( set->jointSims, joint->localIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, joint->setIndex ); + return b3Array_Get( set->jointSims, joint->localIndex ); } b3JointSim* b3GetJointSimCheckType( b3JointId jointId, b3JointType type ) @@ -164,46 +149,6 @@ b3JointSim* b3GetJointSimCheckType( b3JointId jointId, b3JointType type ) return jointSim; } -static void b3DestroyContactsBetweenBodies( b3World* world, b3Body* bodyA, b3Body* bodyB ) -{ - int contactKey; - int otherBodyId; - - // use the smaller of the two contact lists - if ( bodyA->contactCount < bodyB->contactCount ) - { - contactKey = bodyA->headContactKey; - otherBodyId = bodyB->id; - } - else - { - contactKey = bodyB->headContactKey; - otherBodyId = bodyA->id; - } - - // no need to wake bodies when a joint removes collision between them - bool wakeBodies = false; - - // destroy the contacts - while ( contactKey != B3_NULL_INDEX ) - { - int contactId = contactKey >> 1; - int edgeIndex = contactKey & 1; - - b3Contact* contact = b3Array_Get( world->contacts, contactId ); - contactKey = contact->edges[edgeIndex].nextKey; - - int otherEdgeIndex = edgeIndex ^ 1; - if ( contact->edges[otherEdgeIndex].bodyId == otherBodyId ) - { - // Careful, this removes the contact from the current doubly linked list - b3DestroyContact( world, contact, wakeBodies ); - } - } - - b3ValidateSolverSets( world ); -} - typedef struct b3JointPair { b3Joint* joint; @@ -214,20 +159,10 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint { B3_ASSERT( b3IsValidTransform( def->localFrameA ) ); B3_ASSERT( b3IsValidTransform( def->localFrameB ) ); - B3_ASSERT( world->worldId == def->bodyIdA.world0 ); - B3_ASSERT( world->worldId == def->bodyIdB.world0 ); - B3_ASSERT( B3_ID_EQUALS( def->bodyIdA, def->bodyIdB ) == false ); b3Body* bodyA = b3GetBodyFullId( world, def->bodyIdA ); b3Body* bodyB = b3GetBodyFullId( world, def->bodyIdB ); - // If the joint prevents collisions, then destroy all contacts between attached bodies. - // Do this first so world arrays are not disturbed in the following code. - if ( def->collideConnected == false ) - { - b3DestroyContactsBetweenBodies( world, bodyA, bodyB ); - } - int bodyIdA = bodyA->id; int bodyIdB = bodyB->id; int maxSetIndex = b3MaxInt( bodyA->setIndex, bodyB->setIndex ); @@ -236,10 +171,10 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint int jointId = b3AllocId( &world->jointIdPool ); if ( jointId == world->joints.count ) { - b3Array_Push( world->joints, (b3Joint){ 0 } ); + b3Array_Push( world->joints, (b3Joint){ 0 } ); } - b3Joint* joint = b3Array_Get( world->joints, jointId ); + b3Joint* joint = b3Array_Get( world->joints, jointId ); joint->jointId = jointId; joint->userData = def->userData; joint->generation += 1; @@ -260,7 +195,7 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint int keyA = ( jointId << 1 ) | 0; if ( bodyA->headJointKey != B3_NULL_INDEX ) { - b3Joint* jointA = b3Array_Get( world->joints, bodyA->headJointKey >> 1 ); + b3Joint* jointA = b3Array_Get( world->joints, bodyA->headJointKey >> 1 ); b3JointEdge* edgeA = jointA->edges + ( bodyA->headJointKey & 1 ); edgeA->prevKey = keyA; } @@ -275,7 +210,7 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint int keyB = ( jointId << 1 ) | 1; if ( bodyB->headJointKey != B3_NULL_INDEX ) { - b3Joint* jointB = b3Array_Get( world->joints, bodyB->headJointKey >> 1 ); + b3Joint* jointB = b3Array_Get( world->joints, bodyB->headJointKey >> 1 ); b3JointEdge* edgeB = jointB->edges + ( bodyB->headJointKey & 1 ); edgeB->prevKey = keyB; } @@ -287,7 +222,7 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint if ( bodyA->setIndex == b3_disabledSet || bodyB->setIndex == b3_disabledSet ) { // if either body is disabled, create in disabled set - b3SolverSet* set = b3GetSolverSet( world, b3_disabledSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_disabledSet ); joint->setIndex = b3_disabledSet; joint->localIndex = set->jointSims.count; @@ -301,7 +236,7 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint else if ( bodyA->type != b3_dynamicBody && bodyB->type != b3_dynamicBody ) { // joint is not attached to a dynamic body - b3SolverSet* set = b3GetSolverSet( world, b3_staticSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_staticSet ); joint->setIndex = b3_staticSet; joint->localIndex = set->jointSims.count; @@ -330,14 +265,13 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint else { // joint connected between sleeping and/or static bodies - B3_ASSERT( bodyA->setIndex >= b3_firstSleepingSet || - bodyB->setIndex >= b3_firstSleepingSet ); + B3_ASSERT( bodyA->setIndex >= b3_firstSleepingSet || bodyB->setIndex >= b3_firstSleepingSet ); B3_ASSERT( bodyA->setIndex != b3_staticSet || bodyB->setIndex != b3_staticSet ); // joint should go into the sleeping set (not static set) int setIndex = maxSetIndex; - b3SolverSet* set = b3GetSolverSet( world, setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); joint->setIndex = setIndex; joint->localIndex = set->jointSims.count; @@ -358,10 +292,10 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint // fix potentially invalid set index setIndex = bodyA->setIndex; - b3SolverSet* mergedSet = b3GetSolverSet( world, setIndex ); + b3SolverSet* mergedSet = b3Array_Get( world->solverSets, setIndex ); // Careful! The joint sim pointer was orphaned by the set merge. - jointSim = b3Array_Get( mergedSet->jointSims, joint->localIndex ); + jointSim = b3Array_Get( mergedSet->jointSims, joint->localIndex ); } B3_ASSERT( joint->setIndex == setIndex ); @@ -399,6 +333,46 @@ static b3JointPair b3CreateJoint( b3World* world, const b3JointDef* def, b3Joint return (b3JointPair){ joint, jointSim }; } +static void b3DestroyContactsBetweenBodies( b3World* world, b3Body* bodyA, b3Body* bodyB ) +{ + int contactKey; + int otherBodyId; + + // use the smaller of the two contact lists + if ( bodyA->contactCount < bodyB->contactCount ) + { + contactKey = bodyA->headContactKey; + otherBodyId = bodyB->id; + } + else + { + contactKey = bodyB->headContactKey; + otherBodyId = bodyA->id; + } + + // no need to wake bodies when a joint removes collision between them + bool wakeBodies = false; + + // destroy the contacts + while ( contactKey != B3_NULL_INDEX ) + { + int contactId = contactKey >> 1; + int edgeIndex = contactKey & 1; + + b3Contact* contact = b3Array_Get( world->contacts, contactId ); + contactKey = contact->edges[edgeIndex].nextKey; + + int otherEdgeIndex = edgeIndex ^ 1; + if ( contact->edges[otherEdgeIndex].bodyId == otherBodyId ) + { + // Careful, this removes the contact from the current doubly linked list + b3DestroyContact( world, contact, wakeBodies ); + } + } + + b3ValidateSolverSets( world ); +} + void b3Joint_SetConstraintTuning( b3JointId jointId, float hertz, float dampingRatio ) { B3_ASSERT( b3IsValidFloat( hertz ) && hertz >= 0.0f ); @@ -463,7 +437,7 @@ b3JointId b3CreateDistanceJoint( b3WorldId worldId, const b3DistanceJointDef* de { B3_CHECK_JOINT_DEF( def ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -527,71 +501,11 @@ b3JointId b3CreateMotorJoint( b3WorldId worldId, const b3MotorJointDef* def ) return jointId; } -b3JointId b3CreateMoverJoint( b3WorldId worldId, const b3MoverJointDef* def ) -{ - B3_CHECK_JOINT_DEF( def ); - B3_ASSERT( b3IsValidVec3( def->linearVelocity ) ); - B3_ASSERT( b3IsValidFloat( def->maxForce ) && def->maxForce >= 0.0f ); - - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return (b3JointId){ 0 }; - } - - b3JointPair pair = b3CreateJoint( world, &def->base, b3_moverJoint ); - b3JointSim* joint = pair.jointSim; - - joint->moverJoint = (b3MoverJoint){ 0 }; - joint->moverJoint.linearVelocity = def->linearVelocity; - joint->moverJoint.maxForce = def->maxForce; - - b3JointId jointId = { joint->jointId + 1, world->worldId, pair.joint->generation }; - B3_REC_CREATE( world, CreateMoverJoint, jointId, worldId, *def ); - return jointId; -} - -b3JointId b3CreatePogoJoint( b3WorldId worldId, const b3PogoJointDef* def ) -{ - B3_CHECK_JOINT_DEF( def ); - B3_ASSERT( b3IsValidVec3( def->normal ) && b3IsNormalized( def->normal ) ); - B3_ASSERT( b3IsValidFloat( def->restLength ) && def->restLength >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->hertz ) && def->hertz >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->dampingRatio ) && def->dampingRatio >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->maxTensionForce ) && def->maxTensionForce >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->maxCompressionForce ) && def->maxCompressionForce >= 0.0f ); - B3_ASSERT( b3IsValidFloat( def->impulse ) ); - B3_ASSERT( b3IsValidFloat( def->velocity ) ); - - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return (b3JointId){ 0 }; - } - - b3JointPair pair = b3CreateJoint( world, &def->base, b3_pogoJoint ); - b3JointSim* joint = pair.jointSim; - - joint->pogoJoint = (b3PogoJoint){ 0 }; - joint->pogoJoint.normal = def->normal; - joint->pogoJoint.restLength = def->restLength; - joint->pogoJoint.hertz = def->hertz; - joint->pogoJoint.dampingRatio = def->dampingRatio; - joint->pogoJoint.maxTensionForce = def->maxTensionForce; - joint->pogoJoint.maxCompressionForce = def->maxCompressionForce; - joint->pogoJoint.impulse = def->impulse; - joint->pogoJoint.velocity = def->velocity; - - b3JointId jointId = { joint->jointId + 1, world->worldId, pair.joint->generation }; - B3_REC_CREATE( world, CreatePogoJoint, jointId, worldId, *def ); - return jointId; -} - b3JointId b3CreateFilterJoint( b3WorldId worldId, const b3FilterJointDef* def ) { B3_CHECK_JOINT_DEF( def ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -609,7 +523,7 @@ b3JointId b3CreateParallelJoint( b3WorldId worldId, const b3ParallelJointDef* de { B3_CHECK_JOINT_DEF( def ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -638,7 +552,7 @@ b3JointId b3CreatePrismaticJoint( b3WorldId worldId, const b3PrismaticJointDef* B3_ASSERT( def->lowerTranslation <= def->upperTranslation ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -669,7 +583,7 @@ b3JointId b3CreateRevoluteJoint( b3WorldId worldId, const b3RevoluteJointDef* de B3_CHECK_JOINT_DEF( def ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -706,7 +620,7 @@ b3JointId b3CreateSphericalJoint( b3WorldId worldId, const b3SphericalJointDef* B3_ASSERT( b3IsValidQuat( def->targetRotation ) ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -723,10 +637,8 @@ b3JointId b3CreateSphericalJoint( b3WorldId worldId, const b3SphericalJointDef* float lowerAngle = b3MinFloat( def->lowerTwistAngle, def->upperTwistAngle ); float upperAngle = b3MaxFloat( def->lowerTwistAngle, def->upperTwistAngle ); - joint->sphericalJoint.lowerTwistAngle = - b3ClampFloat( lowerAngle, -0.99f * B3_PI, 0.99f * B3_PI ); - joint->sphericalJoint.upperTwistAngle = - b3ClampFloat( upperAngle, -0.99f * B3_PI, 0.99f * B3_PI ); + joint->sphericalJoint.lowerTwistAngle = b3ClampFloat( lowerAngle, -0.99f * B3_PI, 0.99f * B3_PI ); + joint->sphericalJoint.upperTwistAngle = b3ClampFloat( upperAngle, -0.99f * B3_PI, 0.99f * B3_PI ); joint->sphericalJoint.maxMotorTorque = def->maxMotorTorque; joint->sphericalJoint.motorVelocity = def->motorVelocity; @@ -749,7 +661,7 @@ b3JointId b3CreateWeldJoint( b3WorldId worldId, const b3WeldJointDef* def ) B3_ASSERT( 0.0f <= def->linearDampingRatio ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -775,7 +687,7 @@ b3JointId b3CreateWheelJoint( b3WorldId worldId, const b3WheelJointDef* def ) B3_ASSERT( def->lowerSuspensionLimit <= def->upperSuspensionLimit ); b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + if (world == NULL) { return (b3JointId){ 0 }; } @@ -818,20 +730,20 @@ void b3DestroyJointInternal( b3World* world, b3Joint* joint, bool wakeBodies ) int idA = edgeA->bodyId; int idB = edgeB->bodyId; - b3Body* bodyA = b3Array_Get( world->bodies, idA ); - b3Body* bodyB = b3Array_Get( world->bodies, idB ); + b3Body* bodyA = b3Array_Get( world->bodies, idA ); + b3Body* bodyB = b3Array_Get( world->bodies, idB ); // Remove from body A if ( edgeA->prevKey != B3_NULL_INDEX ) { - b3Joint* prevJoint = b3Array_Get( world->joints, edgeA->prevKey >> 1 ); + b3Joint* prevJoint = b3Array_Get( world->joints, edgeA->prevKey >> 1 ); b3JointEdge* prevEdge = prevJoint->edges + ( edgeA->prevKey & 1 ); prevEdge->nextKey = edgeA->nextKey; } if ( edgeA->nextKey != B3_NULL_INDEX ) { - b3Joint* nextJoint = b3Array_Get( world->joints, edgeA->nextKey >> 1 ); + b3Joint* nextJoint = b3Array_Get( world->joints, edgeA->nextKey >> 1 ); b3JointEdge* nextEdge = nextJoint->edges + ( edgeA->nextKey & 1 ); nextEdge->prevKey = edgeA->prevKey; } @@ -847,14 +759,14 @@ void b3DestroyJointInternal( b3World* world, b3Joint* joint, bool wakeBodies ) // Remove from body B if ( edgeB->prevKey != B3_NULL_INDEX ) { - b3Joint* prevJoint = b3Array_Get( world->joints, edgeB->prevKey >> 1 ); + b3Joint* prevJoint = b3Array_Get( world->joints, edgeB->prevKey >> 1 ); b3JointEdge* prevEdge = prevJoint->edges + ( edgeB->prevKey & 1 ); prevEdge->nextKey = edgeB->nextKey; } if ( edgeB->nextKey != B3_NULL_INDEX ) { - b3Joint* nextJoint = b3Array_Get( world->joints, edgeB->nextKey >> 1 ); + b3Joint* nextJoint = b3Array_Get( world->joints, edgeB->nextKey >> 1 ); b3JointEdge* nextEdge = nextJoint->edges + ( edgeB->nextKey & 1 ); nextEdge->prevKey = edgeB->prevKey; } @@ -883,19 +795,18 @@ void b3DestroyJointInternal( b3World* world, b3Joint* joint, bool wakeBodies ) if ( setIndex == b3_awakeSet ) { - b3RemoveJointFromGraph( world, joint->edges[0].bodyId, joint->edges[1].bodyId, - joint->colorIndex, localIndex ); + b3RemoveJointFromGraph( world, joint->edges[0].bodyId, joint->edges[1].bodyId, joint->colorIndex, localIndex ); } else { - b3SolverSet* set = b3GetSolverSet( world, setIndex ); - int movedIndex = b3Array_RemoveSwap( set->jointSims, localIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); + int movedIndex = b3Array_RemoveSwap( set->jointSims, localIndex ); if ( movedIndex != B3_NULL_INDEX ) { // Fix moved joint b3JointSim* movedJointSim = set->jointSims.data + localIndex; int movedId = movedJointSim->jointId; - b3Joint* movedJoint = b3Array_Get( world->joints, movedId ); + b3Joint* movedJoint = b3Array_Get( world->joints, movedId ); B3_ASSERT( movedJoint->localIndex == movedIndex ); movedJoint->localIndex = localIndex; } @@ -1015,8 +926,8 @@ void b3Joint_SetCollideConnected( b3JointId jointId, bool shouldCollide ) joint->collideConnected = shouldCollide; - b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); - b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); + b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); + b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); if ( shouldCollide ) { @@ -1028,11 +939,11 @@ void b3Joint_SetCollideConnected( b3JointId jointId, bool shouldCollide ) int shapeId = shapeCountA < shapeCountB ? bodyA->headShapeId : bodyB->headShapeId; while ( shapeId != B3_NULL_INDEX ) { - b3Shape* shape = b3Array_Get( world->shapes, shapeId ); + b3Shape* shape = b3Array_Get( world->shapes, shapeId ); if ( shape->proxyKey != B3_NULL_INDEX ) { - b3BroadPhase_MarkProxyMovedSerial( &world->broadPhase, shape->proxyKey ); + b3BufferMove( &world->broadPhase, shape->proxyKey ); } shapeId = shape->nextShapeId; @@ -1078,8 +989,8 @@ void b3Joint_WakeBodies( b3JointId jointId ) world->locked = true; b3Joint* joint = b3GetJointFullId( world, jointId ); - b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); - b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); + b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); + b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); b3WakeBody( world, bodyA ); b3WakeBody( world, bodyB ); @@ -1087,17 +998,7 @@ void b3Joint_WakeBodies( b3JointId jointId ) world->locked = false; } -bool b3Joint_IsAwake( b3JointId jointId ) -{ - b3World* world = b3GetWorld( jointId.world0 ); - b3Joint* joint = b3GetJointFullId( world, jointId ); - - // Cheaper than checking if the bodies are awake. - return joint->setIndex == b3_awakeSet; -} - -void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, float* force, - float* torque ) +void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, float* force, float* torque ) { float linearImpulse = 0.0f; float angularImpulse = 0.0f; @@ -1119,18 +1020,15 @@ void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, flo case b3_distanceJoint: { b3DistanceJoint* joint = &sim->distanceJoint; - linearImpulse = b3AbsFloat( joint->impulse + joint->lowerImpulse - joint->upperImpulse + - joint->motorImpulse ); + linearImpulse = b3AbsFloat( joint->impulse + joint->lowerImpulse - joint->upperImpulse + joint->motorImpulse ); } break; case b3_motorJoint: { b3MotorJoint* joint = &sim->motorJoint; - linearImpulse = - b3Length( b3Add( joint->linearVelocityImpulse, joint->linearSpringImpulse ) ); - angularImpulse = - b3Length( b3Add( joint->angularVelocityImpulse, joint->angularSpringImpulse ) ); + linearImpulse = b3Length( b3Add( joint->linearVelocityImpulse, joint->linearSpringImpulse ) ); + angularImpulse = b3Length( b3Add( joint->angularVelocityImpulse, joint->angularSpringImpulse ) ); } break; @@ -1177,8 +1075,7 @@ void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, flo b3Vec3 swingAxis = b3Normalize( b3Cross( coneAxis, twistAxis ) ); b3Vec3 impulse = b3Add( joint->springImpulse, joint->motorImpulse ); - impulse = - b3MulAdd( impulse, joint->lowerTwistImpulse - joint->upperTwistImpulse, twistAxis ); + impulse = b3MulAdd( impulse, joint->lowerTwistImpulse - joint->upperTwistImpulse, twistAxis ); impulse = b3MulAdd( impulse, joint->swingImpulse, swingAxis ); angularImpulse = b3Length( impulse ); @@ -1198,28 +1095,12 @@ void b3GetJointReaction( b3World* world, b3JointSim* sim, float invTimeStep, flo // todo probably wrong b3WheelJoint* joint = &sim->wheelJoint; b3Vec2 perpImpulse = joint->linearImpulse; - float axialImpulse = joint->suspensionSpringImpulse + joint->lowerSuspensionImpulse - - joint->upperSuspensionImpulse; - linearImpulse = sqrtf( perpImpulse.x * perpImpulse.x + perpImpulse.y * perpImpulse.y + - axialImpulse * axialImpulse ); + float axialImpulse = joint->suspensionSpringImpulse + joint->lowerSuspensionImpulse - joint->upperSuspensionImpulse; + linearImpulse = sqrtf( perpImpulse.x * perpImpulse.x + perpImpulse.y * perpImpulse.y + axialImpulse * axialImpulse ); angularImpulse = b3AbsFloat( joint->spinImpulse ); } break; - case b3_moverJoint: - { - b3MoverJoint* joint = &sim->moverJoint; - linearImpulse = b3Length2( joint->impulse ); - } - break; - - case b3_pogoJoint: - { - b3PogoJoint* joint = &sim->pogoJoint; - linearImpulse = b3AbsFloat( joint->impulse ); - } - break; - default: break; } @@ -1261,12 +1142,6 @@ static b3Vec3 b3GetJointConstraintForce( b3World* world, b3Joint* joint ) case b3_wheelJoint: return b3GetWheelJointForce( world, base ); - case b3_moverJoint: - return b3GetMoverJointForce( world, base ); - - case b3_pogoJoint: - return b3GetPogoJointForce( world, base ); - default: B3_ASSERT( false ); return b3Vec3_zero; @@ -1306,10 +1181,6 @@ static b3Vec3 b3GetJointConstraintTorque( b3World* world, b3Joint* joint ) case b3_wheelJoint: return b3GetWheelJointTorque( world, base ); - case b3_moverJoint: - case b3_pogoJoint: - return b3Vec3_zero; - default: B3_ASSERT( false ); return b3Vec3_zero; @@ -1378,12 +1249,6 @@ float b3Joint_GetLinearSeparation( b3JointId jointId ) case b3_motorJoint: return 0.0f; - case b3_moverJoint: - return 0.0f; - - case b3_pogoJoint: - return 0.0f; - case b3_filterJoint: return 0.0f; @@ -1409,8 +1274,7 @@ float b3Joint_GetLinearSeparation( b3JointId jointId ) } } - return sqrtf( perpendicularSeparation * perpendicularSeparation + - limitSeparation * limitSeparation ); + return sqrtf( perpendicularSeparation * perpendicularSeparation + limitSeparation * limitSeparation ); } case b3_revoluteJoint: @@ -1452,8 +1316,7 @@ float b3Joint_GetLinearSeparation( b3JointId jointId ) } } - return sqrtf( perpendicularSeparation * perpendicularSeparation + - limitSeparation * limitSeparation ); + return sqrtf( perpendicularSeparation * perpendicularSeparation + limitSeparation * limitSeparation ); } default: @@ -1488,12 +1351,6 @@ float b3Joint_GetAngularSeparation( b3JointId jointId ) case b3_motorJoint: return 0.0f; - case b3_moverJoint: - return 0.0f; - - case b3_pogoJoint: - return 0.0f; - case b3_filterJoint: return 0.0f; @@ -1646,14 +1503,6 @@ void b3PrepareJoint( b3JointSim* joint, b3StepContext* context ) b3PrepareWheelJoint( joint, context ); break; - case b3_moverJoint: - b3PrepareMoverJoint( joint, context ); - break; - - case b3_pogoJoint: - b3PreparePogoJoint( joint, context ); - break; - default: B3_ASSERT( false ); } @@ -1698,14 +1547,6 @@ void b3WarmStartJoint( b3JointSim* joint, b3StepContext* context ) b3WarmStartWheelJoint( joint, context ); break; - case b3_moverJoint: - b3WarmStartMoverJoint( joint, context ); - break; - - case b3_pogoJoint: - b3WarmStartPogoJoint( joint, context ); - break; - default: B3_ASSERT( false ); } @@ -1752,14 +1593,6 @@ void b3SolveJoint( b3JointSim* joint, b3StepContext* context, bool useBias ) b3SolveWheelJoint( joint, context, useBias ); break; - case b3_moverJoint: - b3SolveMoverJoint( joint, context ); - break; - - case b3_pogoJoint: - b3SolvePogoJoint( joint, context, useBias ); - break; - default: B3_ASSERT( false ); } @@ -1818,8 +1651,8 @@ void b3SolveJoints_Overflow( b3StepContext* context, bool useBias ) void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint ) { - b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); - b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); + b3Body* bodyA = b3Array_Get( world->bodies, joint->edges[0].bodyId ); + b3Body* bodyB = b3Array_Get( world->bodies, joint->edges[1].bodyId ); if ( bodyA->setIndex == b3_disabledSet || bodyB->setIndex == b3_disabledSet ) { return; @@ -1876,14 +1709,6 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint ) b3DrawWheelJoint( draw, jointSim, transformA, transformB, scale ); break; - case b3_moverJoint: - b3DrawMoverJoint( draw, world, jointSim, transformA, transformB ); - break; - - case b3_pogoJoint: - b3DrawPogoJoint( draw, world, jointSim, transformA, transformB, scale ); - break; - default: draw->DrawSegmentFcn( transformA.p, pA, color, draw->context ); draw->DrawSegmentFcn( pA, pB, color, draw->context ); @@ -1894,12 +1719,10 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint ) if ( draw->drawGraphColors ) { b3HexColor graphColors[B3_GRAPH_COLOR_COUNT] = { - b3_colorRed, b3_colorOrange, b3_colorYellow, b3_colorGreen, - b3_colorCyan, b3_colorBlue, b3_colorViolet, b3_colorPink, - b3_colorChocolate, b3_colorGoldenRod, b3_colorCoral, b3_colorRosyBrown, - b3_colorAqua, b3_colorPeru, b3_colorLime, b3_colorGold, - b3_colorPlum, b3_colorSnow, b3_colorTeal, b3_colorKhaki, - b3_colorSalmon, b3_colorPeachPuff, b3_colorHoneyDew, b3_colorBlack, + b3_colorRed, b3_colorOrange, b3_colorYellow, b3_colorGreen, b3_colorCyan, b3_colorBlue, + b3_colorViolet, b3_colorPink, b3_colorChocolate, b3_colorGoldenRod, b3_colorCoral, b3_colorRosyBrown, + b3_colorAqua, b3_colorPeru, b3_colorLime, b3_colorGold, b3_colorPlum, b3_colorSnow, + b3_colorTeal, b3_colorKhaki, b3_colorSalmon, b3_colorPeachPuff, b3_colorHoneyDew, b3_colorBlack, }; int colorIndex = joint->colorIndex; @@ -1910,14 +1733,13 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint ) } } - if ( draw->drawJointExtras && joint->type != b3_moverJoint && joint->type != b3_pogoJoint ) + if ( draw->drawJointExtras ) { b3Vec3 force = b3GetJointConstraintForce( world, joint ); b3Vec3 torque = b3GetJointConstraintTorque( world, joint ); b3Pos p = b3LerpPosition( pA, pB, 0.5f ); - draw->DrawSegmentFcn( p, b3OffsetPos( p, b3MulSV( draw->forceScale, force ) ), - b3_colorAzure, draw->context ); + draw->DrawSegmentFcn( p, b3OffsetPos( p, b3MulSV( 0.001f, force ) ), b3_colorAzure, draw->context ); char buffer[64]; snprintf( buffer, 64, "f = %g, t = %g", b3Length( force ), b3Length( torque ) ); diff --git a/src/joint.h b/src/joint.h index 45da807..64171b9 100644 --- a/src/joint.h +++ b/src/joint.h @@ -121,39 +121,6 @@ typedef struct b3MotorJoint b3Matrix3 angularMass; } b3MotorJoint; -typedef struct b3MoverJoint -{ - b3Vec3 linearVelocity; - float maxForce; - - b3Vec3 axisX; - b3Vec3 axisZ; - b3Vec2 impulse; - - int indexA; - int indexB; - float linearMass; -} b3MoverJoint; - -typedef struct b3PogoJoint -{ - b3Vec3 normal; - float restLength; - float hertz; - float dampingRatio; - float maxTensionForce; - float maxCompressionForce; - - float impulse; - int indexA; - int indexB; - b3Transform frameA; - b3Transform frameB; - b3Vec3 deltaCenter; - float linearMass; - float velocity; -} b3PogoJoint; - typedef struct b3ParallelJoint { float hertz; @@ -369,9 +336,7 @@ typedef struct b3JointSim { b3DistanceJoint distanceJoint; b3MotorJoint motorJoint; - b3MoverJoint moverJoint; b3ParallelJoint parallelJoint; - b3PogoJoint pogoJoint; b3RevoluteJoint revoluteJoint; b3SphericalJoint sphericalJoint; b3PrismaticJoint prismaticJoint; @@ -400,8 +365,6 @@ void b3DrawJoint( b3DebugDraw* draw, b3World* world, b3Joint* joint ); b3Vec3 b3GetDistanceJointForce( b3World* world, b3JointSim* base ); b3Vec3 b3GetMotorJointForce( b3World* world, b3JointSim* base ); -b3Vec3 b3GetMoverJointForce( b3World* world, b3JointSim* base ); -b3Vec3 b3GetPogoJointForce( b3World* world, b3JointSim* base ); b3Vec3 b3GetPrismaticJointForce( b3World* world, b3JointSim* base ); b3Vec3 b3GetRevoluteJointForce( b3World* world, b3JointSim* base ); b3Vec3 b3GetSphericalJointForce( b3World* world, b3JointSim* base ); @@ -418,8 +381,6 @@ b3Vec3 b3GetWheelJointTorque( b3World* world, b3JointSim* base ); void b3PrepareDistanceJoint( b3JointSim* base, b3StepContext* context ); void b3PrepareMotorJoint( b3JointSim* base, b3StepContext* context ); -void b3PrepareMoverJoint( b3JointSim* base, b3StepContext* context ); -void b3PreparePogoJoint( b3JointSim* base, b3StepContext* context ); void b3PrepareParallelJoint( b3JointSim* base, b3StepContext* context ); void b3PreparePrismaticJoint( b3JointSim* base, b3StepContext* context ); void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context ); @@ -429,8 +390,6 @@ void b3PrepareWheelJoint( b3JointSim* base, b3StepContext* context ); void b3WarmStartDistanceJoint( b3JointSim* base, b3StepContext* context ); void b3WarmStartMotorJoint( b3JointSim* base, b3StepContext* context ); -void b3WarmStartMoverJoint( b3JointSim* base, b3StepContext* context ); -void b3WarmStartPogoJoint( b3JointSim* base, b3StepContext* context ); void b3WarmStartParallelJoint( b3JointSim* base, b3StepContext* context ); void b3WarmStartPrismaticJoint( b3JointSim* base, b3StepContext* context ); void b3WarmStartRevoluteJoint( b3JointSim* base, b3StepContext* context ); @@ -440,8 +399,6 @@ void b3WarmStartWheelJoint( b3JointSim* base, b3StepContext* context ); void b3SolveDistanceJoint( b3JointSim* base, b3StepContext* context, bool useBias ); void b3SolveMotorJoint( b3JointSim* base, b3StepContext* context ); -void b3SolveMoverJoint( b3JointSim* base, b3StepContext* context ); -void b3SolvePogoJoint( b3JointSim* base, b3StepContext* context, bool useBias ); void b3SolveParallelJoint( b3JointSim* base, b3StepContext* context ); void b3SolvePrismaticJoint( b3JointSim* base, b3StepContext* context, bool useBias ); void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBias ); @@ -450,56 +407,9 @@ void b3SolveWeldJoint( b3JointSim* base, b3StepContext* context, bool useBias ); void b3SolveWheelJoint( b3JointSim* base, b3StepContext* context, bool useBias ); void b3DrawDistanceJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB ); -void b3DrawMoverJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, b3WorldTransform transformA, - b3WorldTransform transformB ); -void b3DrawPogoJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, b3WorldTransform transformA, - b3WorldTransform transformB, float scale ); void b3DrawParallelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); void b3DrawPrismaticJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); void b3DrawRevoluteJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); void b3DrawSphericalJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); void b3DrawWeldJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); void b3DrawWheelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform transformA, b3WorldTransform transformB, float scale ); - -// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] -static inline b3Vec3 b3SolvePointConstraint( float mA, float mB, b3Matrix3 iA, b3Matrix3 iB, b3Vec3 rA, b3Vec3 rB, b3Vec3 rhs ) -{ - float axy = rA.z * iA.cy.y - rA.y * iA.cz.y; - float axz = rA.z * iA.cy.z - rA.y * iA.cz.z; - b3Vec3 ay = b3Sub( b3MulSV( rA.x, iA.cz ), b3MulSV( rA.z, iA.cx ) ); - b3Vec3 az = b3Sub( b3MulSV( rA.y, iA.cx ), b3MulSV( rA.x, iA.cy ) ); - - float bxy = rB.z * iB.cy.y - rB.y * iB.cz.y; - float bxz = rB.z * iB.cy.z - rB.y * iB.cz.z; - b3Vec3 by = b3Sub( b3MulSV( rB.x, iB.cz ), b3MulSV( rB.z, iB.cx ) ); - b3Vec3 bz = b3Sub( b3MulSV( rB.y, iB.cx ), b3MulSV( rB.x, iB.cy ) ); - - float m = mA + mB; - float kxx = ( axy * rA.z - axz * rA.y ) + ( bxy * rB.z - bxz * rB.y ) + m; - float kyy = ( ay.z * rA.x - ay.x * rA.z ) + ( by.z * rB.x - by.x * rB.z ) + m; - float kzz = ( az.x * rA.y - az.y * rA.x ) + ( bz.x * rB.y - bz.y * rB.x ) + m; - float kxy = ( ay.y * rA.z - ay.z * rA.y ) + ( by.y * rB.z - by.z * rB.y ); - float kxz = ( az.y * rA.z - az.z * rA.y ) + ( bz.y * rB.z - bz.z * rB.y ); - float kyz = ( az.z * rA.x - az.x * rA.z ) + ( bz.z * rB.x - bz.x * rB.z ); - - float cxx = kyy * kzz - kyz * kyz; - float cyy = kxx * kzz - kxz * kxz; - float czz = kxx * kyy - kxy * kxy; - float cxy = kxz * kyz - kxy * kzz; - float cxz = kxy * kyz - kyy * kxz; - float cyz = kxy * kxz - kxx * kyz; - - float det = kxx * cxx + kxy * cxy + kxz * cxz; - if ( b3AbsFloat( det ) > 1000.0f * FLT_MIN ) - { - float invDet = 1.0f / det; - b3Vec3 b = { - invDet * ( cxx * rhs.x + cxy * rhs.y + cxz * rhs.z ), - invDet * ( cxy * rhs.x + cyy * rhs.y + cyz * rhs.z ), - invDet * ( cxz * rhs.x + cyz * rhs.y + czz * rhs.z ), - }; - return b; - } - - return b3Vec3_zero; -} diff --git a/src/manifold.c b/src/manifold.c index f15db6c..40e60ad 100644 --- a/src/manifold.c +++ b/src/manifold.c @@ -10,6 +10,58 @@ #include "box3d/math_functions.h" +// p1 : origin on edge 1 +// e1 : edge 1 +// c1 : shape 1 centroid +// p2 : origin on edge 2 +// e2 : edge 2 +// c2 : shape 2 centroid +float b3EdgeEdgeSeparation( b3Vec3 p1, b3Vec3 e1, b3Vec3 c1, b3Vec3 p2, b3Vec3 e2, b3Vec3 c2 ) +{ + // Build search direction + b3Vec3 u = b3Cross( e1, e2 ); + float length = b3Length( u ); + + // Skip near parallel edges: |e1 x e1| = sin(alpha) * |e1| * |e2| + const float kTolerance = 0.005f; + if ( length < kTolerance * sqrtf( b3LengthSquared( e1 ) * b3LengthSquared( e2 ) ) ) + { + return -FLT_MAX; + } + + if ( length * length < 1000.0f * FLT_MIN ) + { + return -FLT_MAX; + } + + b3Vec3 n = b3MulSV( 1.0f / length, u ); + + // Make sure normal points away from the first shape + // For a triangle, it is possible that N is aligned with the triangle normal and the sign + // value can be close to zero and flicker between small negative and positive values, leading to + // an incorrect separation value. So we assume the other hull has some volume and pick the most + // significant sign value to orient N. + float sign1 = b3Dot( n, b3Sub( p1, c1 ) ); + float sign2 = b3Dot( n, b3Sub( p2, c2 ) ); + if ( b3AbsFloat( sign1 ) > b3AbsFloat( sign2 ) ) + { + if ( sign1 < 0.0f ) + { + n = b3Neg( n ); + } + } + else + { + if ( sign2 > 0.0f ) + { + n = b3Neg( n ); + } + } + + // s = Dot(n, p2) - d = Dot(n, p2) - Dot(n, p1) = Dot(n, p2 - p1) + return b3Dot( n, b3Sub( p2, p1 ) ); +} + // This was extended to make the wedge shape get the correct incident face. // Instead of looking directly for the most anti-parallel face, we first find the closest vertex (passed in). // Then we look for all edges coming out of that vertex and look for the edge that is @@ -17,8 +69,6 @@ // Then from that edge, we select the adjacent face that is most anti-parallel to the reference normal. int b3FindIncidentFace( const b3HullData* hull, b3Vec3 refNormal, int vertexIndex ) { - B3_ASSERT( 0 <= vertexIndex && vertexIndex < hull->vertexCount ); - const b3HullVertex* vertices = b3GetHullVertices( hull ); const b3HullHalfEdge* edges = b3GetHullEdges( hull ); const b3Plane* planes = b3GetHullPlanes( hull ); diff --git a/src/manifold.h b/src/manifold.h index 9f0e662..9e529ab 100644 --- a/src/manifold.h +++ b/src/manifold.h @@ -8,22 +8,19 @@ #define B3_MAX_CLIP_POINTS 64 -typedef struct b3SeparatingAxis +typedef struct b3FaceQuery +{ + float separation; + int faceIndex; + int vertexIndex; +} b3FaceQuery; + +typedef struct b3EdgeQuery { - b3Vec3 normal; float separation; int indexA; int indexB; - b3SeparatingFeature type; -} b3SeparatingAxis; - -typedef struct b3AxisQuery -{ - b3SeparatingAxis faceA; - b3SeparatingAxis faceB; - b3SeparatingAxis edge; - b3SeparatingFeature separatedFeature; -} b3AxisQuery; +} b3EdgeQuery; typedef struct b3ClipVertex { @@ -38,6 +35,7 @@ typedef enum b3FeatureOwner b3_featureShapeB = 1 } b3FeatureOwner; +float b3EdgeEdgeSeparation( b3Vec3 p1, b3Vec3 e1, b3Vec3 c1, b3Vec3 p2, b3Vec3 e2, b3Vec3 c2 ); int b3FindIncidentFace( const b3HullData* hull, b3Vec3 refNormal, int vertexIndex ); b3FeaturePair b3MakeFeaturePair( b3FeatureOwner owner1, int index1, b3FeatureOwner owner2, int index2 ); @@ -45,21 +43,6 @@ b3FeaturePair b3FlipPair( b3FeaturePair pair ); int b3ClipPolygon( b3ClipVertex* out, b3ClipVertex* polygon, int count, b3Plane clipPlane, int edge, b3Plane refPlane ); -b3AxisQuery b3ComputeSeparatingAxis( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn ); -b3AxisQuery b3ComputeSeparatingAxisAtWidth( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn, - int simdWidth ); -void b3CollideHullsAtWidth( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, const b3HullData* hullB, - b3Transform transformBtoA, b3SATCache* cache, int simdWidth ); - -void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane, - const b3Capsule* capsule ); - -void b3BuildTriangleAndHullFaceContact( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, const b3HullData* hull, - b3SATCache* cache, bool enableSpeculative ); - -b3AxisQuery b3ComputeSeparatingAxisW4( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn ); -b3AxisQuery b3ComputeSeparatingAxisW8( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, bool earlyReturn ); - #if B3_ENABLE_VALIDATION bool b3ValidatePolygon( b3ClipVertex* polygon, int count ); #endif @@ -72,27 +55,3 @@ static inline uint32_t b3MakeFeatureId( b3FeaturePair pair ) return ( (uint32_t)pair.owner1 << 24 ) | ( (uint32_t)pair.index1 << 16 ) | ( (uint32_t)pair.owner2 << 8 ) | (uint32_t)pair.index2; } - -static inline b3SeparatingAxis b3GetBestAxis( const b3AxisQuery* query ) -{ - B3_VALIDATE( query->faceA.type == b3_faceAxisA ); - B3_VALIDATE( query->edge.type == b3_edgePairAxis ); - B3_VALIDATE( query->faceB.type == b3_faceAxisB ); - - if ( query->faceA.separation > query->faceB.separation ) - { - if ( query->edge.separation > query->faceA.separation ) - { - return query->edge; - } - - return query->faceA; - } - - if ( query->edge.separation > query->faceB.separation ) - { - return query->edge; - } - - return query->faceB; -} diff --git a/src/math_functions.c b/src/math_functions.c index e533fdc..a339d95 100644 --- a/src/math_functions.c +++ b/src/math_functions.c @@ -166,6 +166,49 @@ bool b3IsValidWorldTransform( b3WorldTransform t ) return b3IsValidPosition( t.p ) && b3IsValidQuat( t.q ); } +// https://stackoverflow.com/questions/46210708/atan2-approximation-with-11bits-in-mantissa-on-x86with-sse2-and-armwith-vfpv4 +float b3Atan2( float y, float x ) +{ + // Added check for (0,0) to match atan2f and avoid NaN + if ( x == 0.0f && y == 0.0f ) + { + return 0.0f; + } + + float ax = b3AbsFloat( x ); + float ay = b3AbsFloat( y ); + float mx = b3MaxFloat( ay, ax ); + float mn = b3MinFloat( ay, ax ); + float a = mn / mx; + + // Minimax polynomial approximation to atan(a) on [0,1] + float s = a * a; + float c = s * a; + float q = s * s; + float r = 0.024840285f * q + 0.18681418f; + float t = -0.094097948f * q - 0.33213072f; + r = r * s + t; + r = r * c + a; + + // Map to full circle + if ( ay > ax ) + { + r = 1.57079637f - r; + } + + if ( x < 0 ) + { + r = 3.14159274f - r; + } + + if ( y < 0 ) + { + r = -r; + } + + return r; +} + // Approximate cosine and sine for determinism. In my testing cosf and sinf produced // the same results on x64 and ARM using MSVC, GCC, and Clang. However, I don't trust // this result. diff --git a/src/math_internal.h b/src/math_internal.h index be8418d..736268b 100644 --- a/src/math_internal.h +++ b/src/math_internal.h @@ -28,6 +28,7 @@ typedef struct b3Triangle { b3Vec3 vertices[3]; int i1, i2, i3; + int flags; } b3Triangle; typedef struct b3TrianglePoint @@ -60,7 +61,6 @@ b3Matrix3 b3BoxInertia( float mass, b3Vec3 min, b3Vec3 max ); int b3GetProxySupport( const b3ShapeProxy* proxy, b3Vec3 axis ); int b3GetPointSupport( const b3Vec3* points, int count, b3Vec3 axis ); -// Align up to 8 byte alignment. static inline size_t b3AlignUp8( size_t x ) { return ( x + 7u ) & ~(size_t)7u; @@ -203,16 +203,14 @@ static inline b3Quat b3QuatFromExponentialMap( b3Vec3 v ) /// q2 = q1 + 0.5 * omega * q1 static inline b3Quat b3IntegrateRotation( b3Quat q1, b3Vec3 deltaRotation ) { -#if 1 // https://fgiesen.wordpress.com/2012/08/24/quaternion-differentiation/ b3Quat qd = { b3MulSV( 0.5f, deltaRotation ), 0.0f }; qd = b3MulQuat( qd, q1 ); b3Quat q2 = { b3Add( q1.v, qd.v ), qd.s + q1.s }; q2 = b3NormalizeQuat( q2 ); return q2; -#else - return b3NormalizeQuat( b3MulQuat(b3QuatFromExponentialMap( deltaRotation ), q1) ); -#endif + + // return b3NormalizeQuat( b3MulQuat(b3QuatFromExponentialMap( deltaRotation ), q1) ); } // Pseudo angular velocity from a quaternion target @@ -393,6 +391,16 @@ static inline b3Matrix3 b3MakeDiagonalMatrix( float a, float b, float c ) return (b3Matrix3){ { a, 0.0f, 0.0f }, { 0.0f, b, 0.0f }, { 0.0f, 0.0f, c } }; } +static inline b3Matrix3 b3Skew( b3Vec3 v ) +{ + b3Matrix3 out; + out.cx = (b3Vec3){ 0, v.z, -v.y }; + out.cy = (b3Vec3){ -v.z, 0, v.x }; + out.cz = (b3Vec3){ v.y, -v.x, 0 }; + + return out; +} + static inline b3Plane b3NormalizePlane( b3Plane plane ) { float invLength = 1.0f / b3Length( plane.normal ); diff --git a/src/mesh.c b/src/mesh.c index fb4484e..c034899 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -128,26 +128,6 @@ static uint8_t* b3GetMeshFlagsWrite( b3MeshData* mesh ) return (uint8_t*)( (intptr_t)mesh + mesh->flagsOffset ); } -static int8_t* b3GetMeshEdgeAnglesWrite( b3MeshData* mesh ) -{ - if ( mesh->edgeAngleOffset == 0 ) - { - return NULL; - } - - return (int8_t*)( (intptr_t)mesh + mesh->edgeAngleOffset ); -} - -static uint8_t* b3GetMeshVertexFlagsWrite( b3MeshData* mesh ) -{ - if ( mesh->vertexFlagOffset == 0 ) - { - return NULL; - } - - return (uint8_t*)( (intptr_t)mesh + mesh->vertexFlagOffset ); -} - static int b3GetNodeHeight( const b3MeshNode* node ) { if ( b3IsLeaf( node ) ) @@ -264,12 +244,12 @@ static bool b3IsConsistent( const b3MeshData* mesh ) const b3MeshNode* child2 = b3GetRightChild( node ); b3AABB bounds2 = b3GetNodeAABB( child2 ); - if ( b3AABB_Contains( nodeBounds, bounds1 ) == false ) + if ( !b3AABB_Contains( nodeBounds, bounds1 ) ) { return false; } - if ( b3AABB_Contains( nodeBounds, bounds2 ) == false ) + if ( !b3AABB_Contains( nodeBounds, bounds2 ) ) { return false; } @@ -349,11 +329,6 @@ bool b3IsValidMesh( const b3MeshData* meshData ) #endif -static inline b3Vec3 b3GetStridedVertex( const b3Vec3* vertices, int index, size_t stride ) -{ - return *(const b3Vec3*)( (const uint8_t*)vertices + index * stride ); -} - // Node for a vertex linked list typedef struct b3VertexNode { @@ -375,18 +350,15 @@ typedef struct b3SpatialHash b3Array( b3VertexNode ) nodes; const b3Vec3* vertices; int vertexCount; - size_t stride; b3VertexMap vertexMap; float cellSize; float tolerance; } b3SpatialHash; -static void b3CreateSpatialHash( b3SpatialHash* h, const b3Vec3* vertices, int vertexCount, size_t stride, - float tolerance ) +static void b3SpatialHash_Create( b3SpatialHash* h, const b3Vec3* vertices, int vertexCount, float tolerance ) { h->vertices = vertices; h->vertexCount = vertexCount; - h->stride = stride; h->tolerance = tolerance; h->cellSize = 2.0f * tolerance; b3Array_CreateN( h->nodes, vertexCount ); @@ -397,7 +369,7 @@ static void b3CreateSpatialHash( b3SpatialHash* h, const b3Vec3* vertices, int v B3_ASSERT( h->cellSize > 0.0f ); } -static void b3DestroySpatialHash( b3SpatialHash* h ) +static void b3SpatialHash_Destroy( b3SpatialHash* h ) { b3VertexMap_cleanup( &h->vertexMap ); b3Array_Destroy( h->nodes ); @@ -408,8 +380,7 @@ static void b3DestroySpatialHash( b3SpatialHash* h ) static int32_t b3SpatialHash_FindDuplicate( b3SpatialHash* h, int32_t currentIndex ) { B3_ASSERT( currentIndex < h->vertexCount ); - size_t stride = h->stride; - b3Vec3 vertex = b3GetStridedVertex( h->vertices, currentIndex, stride ); + b3Vec3 vertex = h->vertices[currentIndex]; float cellSize = h->cellSize; float tolerance = h->tolerance; @@ -449,7 +420,7 @@ static int32_t b3SpatialHash_FindDuplicate( b3SpatialHash* h, int32_t currentInd B3_ASSERT( existingIndex < currentIndex ); B3_ASSERT( existingIndex < h->vertexCount ); - b3Vec3 other = b3GetStridedVertex( h->vertices, existingIndex, stride ); + b3Vec3 other = h->vertices[existingIndex]; // IsEqual inlined: check if vertices are within tolerance if ( fabsf( vertex.x - other.x ) <= tolerance && fabsf( vertex.y - other.y ) <= tolerance && @@ -510,18 +481,16 @@ typedef struct b3WeldData int vertexCount; int indexCount; - size_t stride; } b3WeldData; static int b3WeldVertices( b3WeldData* data, float tolerance ) { int vertexCount = data->vertexCount; int uniqueCount = 0; - size_t stride = data->stride; // Create spatial hash and find duplicates b3SpatialHash spatialHash; - b3CreateSpatialHash( &spatialHash, data->srcVertices, vertexCount, stride, tolerance ); + b3SpatialHash_Create( &spatialHash, data->srcVertices, vertexCount, tolerance ); b3Array( int ) vertexMapping = { 0 }; b3Array_Resize( vertexMapping, vertexCount ); @@ -533,7 +502,7 @@ static int b3WeldVertices( b3WeldData* data, float tolerance ) { // New unique vertex vertexMapping.data[i] = uniqueCount; - data->dstVertices[uniqueCount] = b3GetStridedVertex( data->srcVertices, i, stride ); + data->dstVertices[uniqueCount] = data->srcVertices[i]; uniqueCount += 1; } else @@ -548,11 +517,11 @@ static int b3WeldVertices( b3WeldData* data, float tolerance ) for ( int i = 0; i < indexCount; ++i ) { int srcIndex = data->srcIndices[i]; - B3_ASSERT( 0 <= srcIndex && srcIndex < vertexCount ); + B3_ASSERT( srcIndex < vertexCount ); data->dstIndices[i] = vertexMapping.data[srcIndex]; } - b3DestroySpatialHash( &spatialHash ); + b3SpatialHash_Destroy( &spatialHash ); b3Array_Destroy( vertexMapping ); return uniqueCount; @@ -574,70 +543,10 @@ typedef struct b3Primitive int triangleIndex; } b3Primitive; -_Static_assert( offsetof( b3Primitive, aabb.upperBound ) == 3 * sizeof( float ) && - offsetof( b3Primitive, center ) == 6 * sizeof( float ), - "primitive floats must be contiguous" ); - -static inline b3FloatW4 b3PrimitiveMinW4( b3FloatW4 a, b3FloatW4 b ) -{ -#if defined( B3_SIMD_SSE2 ) - return b3MinW4( a, b ); -#else - return b3BlendW4( b, a, b3LessThanW4( a, b ) ); -#endif -} - -static inline b3FloatW4 b3PrimitiveMaxW4( b3FloatW4 a, b3FloatW4 b ) -{ -#if defined( B3_SIMD_SSE2 ) - return b3MaxW4( a, b ); -#else - return b3BlendW4( b, a, b3GreaterThanW4( a, b ) ); -#endif -} - -static inline b3Vec3 b3PrimitiveLanes( b3FloatW4 v, int first ) -{ - float lanes[4]; - b3StoreW4( lanes, v ); - return (b3Vec3){ lanes[first], lanes[first + 1], lanes[first + 2] }; -} - -static b3AABB b3PrimitiveBounds( const b3Primitive* primitives, int count ) -{ - b3FloatW4 lower = b3SplatW4( FLT_MAX ); - b3FloatW4 upper = b3SplatW4( -FLT_MAX ); - - for ( int i = 0; i < count; ++i ) - { - const float* p = &primitives[i].aabb.lowerBound.x; - lower = b3PrimitiveMinW4( lower, b3LoadW4( p ) ); - upper = b3PrimitiveMaxW4( upper, b3LoadW4( p + 2 ) ); - } - - return (b3AABB){ b3PrimitiveLanes( lower, 0 ), b3PrimitiveLanes( upper, 1 ) }; -} - -static b3AABB b3PrimitiveCenterBounds( const b3Primitive* primitives, int count ) -{ - b3FloatW4 lower = b3LoadW4( &primitives[0].aabb.lowerBound.x + 5 ); - b3FloatW4 upper = lower; - - for ( int i = 1; i < count; ++i ) - { - b3FloatW4 center = b3LoadW4( &primitives[i].aabb.lowerBound.x + 5 ); - lower = b3PrimitiveMinW4( lower, center ); - upper = b3PrimitiveMaxW4( upper, center ); - } - - return (b3AABB){ b3PrimitiveLanes( lower, 1 ), b3PrimitiveLanes( upper, 1 ) }; -} - typedef struct b3Bucket { - b3FloatW4 lower; - b3FloatW4 upper; int count; + b3AABB bounds; } b3Bucket; typedef struct b3Split @@ -655,9 +564,11 @@ static b3Split b3SplitBinnedSah( int count, b3Primitive* primitives ) split.index = -1; // Compute bounds of primitive centroids and choose split axis - b3AABB bounds = b3PrimitiveCenterBounds( primitives, count ); - b3FloatW4 emptyLower = b3SplatW4( FLT_MAX ); - b3FloatW4 emptyUpper = b3SplatW4( -FLT_MAX ); + b3AABB bounds = { primitives[0].center, primitives[0].center }; + for ( int i = 1; i < count; ++i ) + { + bounds = b3AABB_AddPoint( bounds, primitives[i].center ); + } // Compute costs for splitting after each bucket and keep track of best split // This is a small O(n^2) loop. This can be further optimized, but it is already @@ -665,90 +576,54 @@ static b3Split b3SplitBinnedSah( int count, b3Primitive* primitives ) int bestBucket = -1; float bestCost = FLT_MAX; - b3Vec3 extent = b3AABB_Extents( bounds ); - bool binAxis[3]; - float factors[3]; - b3Bucket axisBuckets[3][B3_BIN_COUNT]; for ( int axis = 0; axis < 3; ++axis ) { - binAxis[axis] = b3GetByIndex( extent, axis ) >= B3_LINEAR_SLOP; - factors[axis] = binAxis[axis] ? B3_BIN_COUNT * ( 1.0f - FLT_EPSILON ) / - ( b3GetByIndex( bounds.upperBound, axis ) - b3GetByIndex( bounds.lowerBound, axis ) ) - : 0.0f; - - for ( int i = 0; i < B3_BIN_COUNT; ++i ) - { - axisBuckets[axis][i].lower = emptyLower; - axisBuckets[axis][i].upper = emptyUpper; - axisBuckets[axis][i].count = 0; - } - } - - for ( int i = 0; i < count; ++i ) - { - b3Vec3 center = primitives[i].center; - int indexX = (int)( factors[0] * ( center.x - bounds.lowerBound.x ) ); - int indexY = (int)( factors[1] * ( center.y - bounds.lowerBound.y ) ); - int indexZ = (int)( factors[2] * ( center.z - bounds.lowerBound.z ) ); - B3_ASSERT( 0 <= indexX && indexX < B3_BIN_COUNT ); - B3_ASSERT( 0 <= indexY && indexY < B3_BIN_COUNT ); - B3_ASSERT( 0 <= indexZ && indexZ < B3_BIN_COUNT ); - - const float* p = &primitives[i].aabb.lowerBound.x; - b3FloatW4 lower = b3LoadW4( p ); - b3FloatW4 upper = b3LoadW4( p + 2 ); - - b3Bucket* bucketX = axisBuckets[0] + indexX; - bucketX->count += 1; - bucketX->lower = b3PrimitiveMinW4( bucketX->lower, lower ); - bucketX->upper = b3PrimitiveMaxW4( bucketX->upper, upper ); - - b3Bucket* bucketY = axisBuckets[1] + indexY; - bucketY->count += 1; - bucketY->lower = b3PrimitiveMinW4( bucketY->lower, lower ); - bucketY->upper = b3PrimitiveMaxW4( bucketY->upper, upper ); - - b3Bucket* bucketZ = axisBuckets[2] + indexZ; - bucketZ->count += 1; - bucketZ->lower = b3PrimitiveMinW4( bucketZ->lower, lower ); - bucketZ->upper = b3PrimitiveMaxW4( bucketZ->upper, upper ); - } - - for ( int axis = 0; axis < 3; ++axis ) - { - if ( binAxis[axis] == false ) + b3Vec3 extent = b3AABB_Extents( bounds ); + if ( b3GetByIndex( extent, axis ) < B3_LINEAR_SLOP ) { continue; } - b3Bucket* buckets = axisBuckets[axis]; + // Initialize buckets + b3Bucket buckets[B3_BIN_COUNT]; + for ( int i = 0; i < B3_BIN_COUNT; ++i ) + { + buckets[i].count = 0; + buckets[i].bounds = B3_BOUNDS3_EMPTY; + } + + // Fill buckets + float factor = B3_BIN_COUNT * ( 1.0f - FLT_EPSILON ) / + ( b3GetByIndex( bounds.upperBound, axis ) - b3GetByIndex( bounds.lowerBound, axis ) ); + for ( int i = 0; i < count; ++i ) + { + b3Vec3 center = primitives[i].center; + int index = (int)( factor * ( b3GetByIndex( center, axis ) - b3GetByIndex( bounds.lowerBound, axis ) ) ); + B3_ASSERT( 0 <= index && index < B3_BIN_COUNT ); + + buckets[index].count++; + buckets[index].bounds = b3AABB_Union( buckets[index].bounds, primitives[i].aabb ); + } // Evaluate splits for ( int i = 0; i < B3_BIN_COUNT - 1; ++i ) { int leftCount = 0; - b3FloatW4 leftLower = emptyLower; - b3FloatW4 leftUpper = emptyUpper; + b3AABB leftBounds = B3_BOUNDS3_EMPTY; for ( int k = 0; k <= i; ++k ) { leftCount += buckets[k].count; - leftLower = b3PrimitiveMinW4( leftLower, buckets[k].lower ); - leftUpper = b3PrimitiveMaxW4( leftUpper, buckets[k].upper ); + leftBounds = b3AABB_Union( leftBounds, buckets[k].bounds ); } int rightCount = 0; - b3FloatW4 rightLower = emptyLower; - b3FloatW4 rightUpper = emptyUpper; + b3AABB rightBounds = B3_BOUNDS3_EMPTY; for ( int k = i + 1; k < B3_BIN_COUNT; ++k ) { rightCount += buckets[k].count; - rightLower = b3PrimitiveMinW4( rightLower, buckets[k].lower ); - rightUpper = b3PrimitiveMaxW4( rightUpper, buckets[k].upper ); + rightBounds = b3AABB_Union( rightBounds, buckets[k].bounds ); } - b3AABB leftBounds = { b3PrimitiveLanes( leftLower, 0 ), b3PrimitiveLanes( leftUpper, 1 ) }; - b3AABB rightBounds = { b3PrimitiveLanes( rightLower, 0 ), b3PrimitiveLanes( rightUpper, 1 ) }; - B3_ASSERT( leftCount + rightCount == count ); if ( leftCount > 0 && rightCount > 0 ) { @@ -800,8 +675,18 @@ static b3Split b3SplitHalf( int count, b3Primitive* primitives ) // Split in the middle int splitIndex = count / 2; - b3AABB leftBounds = b3PrimitiveBounds( primitives, splitIndex ); - b3AABB rightBounds = b3PrimitiveBounds( primitives + splitIndex, count - splitIndex ); + b3AABB leftBounds = B3_BOUNDS3_EMPTY; + for ( int i = 0; i < splitIndex; ++i ) + { + leftBounds = b3AABB_Union( leftBounds, primitives[i].aabb ); + } + + b3AABB rightBounds = B3_BOUNDS3_EMPTY; + for ( int i = splitIndex; i < count; ++i ) + { + + rightBounds = b3AABB_Union( rightBounds, primitives[i].aabb ); + } b3AABB bounds = b3AABB_Union( leftBounds, rightBounds ); int axis = b3MajorAxis( b3AABB_Extents( bounds ) ); @@ -819,9 +704,14 @@ static b3Split b3SplitMedian( int count, b3Primitive* primitives ) { B3_ASSERT( count > 2 ); - b3AABB centerBounds = b3PrimitiveCenterBounds( primitives, count ); - b3Vec3 lowerBound = centerBounds.lowerBound; - b3Vec3 upperBound = centerBounds.upperBound; + b3Vec3 lowerBound = primitives[0].center; + b3Vec3 upperBound = primitives[0].center; + + for ( int i = 1; i < count; ++i ) + { + lowerBound = b3Min( lowerBound, primitives[i].center ); + upperBound = b3Max( upperBound, primitives[i].center ); + } b3Vec3 d = b3Sub( upperBound, lowerBound ); b3Vec3 c = b3MulSV( 0.5f, b3Add( lowerBound, upperBound ) ); @@ -932,9 +822,21 @@ static b3Split b3SplitMedian( int count, b3Primitive* primitives ) i1 = count / 2; } + b3AABB leftBounds = B3_BOUNDS3_EMPTY; + for ( int i = 0; i < i1; ++i ) + { + leftBounds = b3AABB_Union( leftBounds, primitives[i].aabb ); + } + + b3AABB rightBounds = B3_BOUNDS3_EMPTY; + for ( int i = i1; i < count; ++i ) + { + rightBounds = b3AABB_Union( rightBounds, primitives[i].aabb ); + } + split.index = i1; - split.leftBounds = b3PrimitiveBounds( primitives, i1 ); - split.rightBounds = b3PrimitiveBounds( primitives + i1, count - i1 ); + split.leftBounds = leftBounds; + split.rightBounds = rightBounds; return split; } @@ -993,7 +895,11 @@ static int b3BuildRecursive( b3Array( b3MeshNode ) * nodes, int count, b3Primiti } else { - b3AABB bounds = b3PrimitiveBounds( primitives, count ); + b3AABB bounds = B3_BOUNDS3_EMPTY; + for ( int i = 0; i < count; ++i ) + { + bounds = b3AABB_Union( bounds, primitives[i].aabb ); + } // We have only a few triangles left. Create a leaf. int index = b3Array_AddIndex( *nodes ); @@ -1008,8 +914,8 @@ static int b3BuildRecursive( b3Array( b3MeshNode ) * nodes, int count, b3Primiti int index = b3Array_AddIndex( *nodes ); int heightLeft = 0, heightRight = 0; int leftIndex = b3BuildRecursive( nodes, split.index, primitives, base, useMedianSplit, &heightLeft ); - int rightIndex = b3BuildRecursive( nodes, count - split.index, primitives + split.index, base, useMedianSplit, - &heightRight ); + int rightIndex = + b3BuildRecursive( nodes, count - split.index, primitives + split.index, base, useMedianSplit, &heightRight ); *height = b3MaxInt( heightLeft, heightRight ) + 1; @@ -1022,14 +928,17 @@ static int b3BuildRecursive( b3Array( b3MeshNode ) * nodes, int count, b3Primiti node->data.asNode.childOffset = rightIndex - index; node->lowerBound = aabb.lowerBound; node->upperBound = aabb.upperBound; - - // Zero so mesh->hash is deterministic + // triangleOffset is leaf-only, but lives outside the union — zero it so mesh->hash is deterministic node->triangleOffset = 0; return index; } - b3AABB aabb = b3PrimitiveBounds( primitives, count ); + b3AABB aabb = B3_BOUNDS3_EMPTY; + for ( int i = 0; i < count; ++i ) + { + aabb = b3AABB_Union( aabb, primitives[i].aabb ); + } int index = b3Array_AddIndex( *nodes ); b3StoreLeaf( &nodes->data[index], &aabb, count, (int)( primitives - base ) ); @@ -1114,570 +1023,44 @@ typedef struct uint8_t triangleEdgeIndex2; } b3MeshEdge; -#define B3_EDGE_ANGLE_STEPS 127.0f +#define NAME b3EdgeMap +#define KEY_TY uint64_t +#define VAL_TY int +#define HASH_FN vt_hash_integer +#define CMPR_FN vt_cmpr_integer +#define MALLOC_FN b3Alloc +#define FREE_FN b3Free +#include "verstable.h" -// Lookup table for 8-bit compressed triangle neighbor angles. -static const b3CosSin s_quantizedCosSin[255] = { - { 1.0f, 0.0f }, - { 0.9999235f, 0.012368159f }, - { 0.99969405f, 0.024734428f }, - { 0.9993117f, 0.03709691f }, - { 0.99877644f, 0.04945372f }, - { 0.99808836f, 0.061802965f }, - { 0.99724764f, 0.074142754f }, - { 0.9962543f, 0.0864712f }, - { 0.99510866f, 0.09878642f }, - { 0.9938107f, 0.111086525f }, - { 0.9923608f, 0.12336964f }, - { 0.990759f, 0.13563387f }, - { 0.9890057f, 0.14787737f }, - { 0.9871011f, 0.16009824f }, - { 0.9850455f, 0.17229462f }, - { 0.98283917f, 0.18446463f }, - { 0.98048246f, 0.19660644f }, - { 0.97797585f, 0.20871817f }, - { 0.97531956f, 0.22079796f }, - { 0.9725141f, 0.23284398f }, - { 0.96955985f, 0.24485438f }, - { 0.9664573f, 0.25682732f }, - { 0.9632069f, 0.26876098f }, - { 0.9598091f, 0.2806535f }, - { 0.95626456f, 0.29250312f }, - { 0.9525737f, 0.304308f }, - { 0.9487371f, 0.3160663f }, - { 0.9447554f, 0.32777625f }, - { 0.9406291f, 0.33943605f }, - { 0.936359f, 0.35104394f }, - { 0.9319456f, 0.36259815f }, - { 0.9273896f, 0.37409684f }, - { 0.9226918f, 0.38553834f }, - { 0.9178528f, 0.39692086f }, - { 0.91287345f, 0.40824264f }, - { 0.9077544f, 0.419502f }, - { 0.9024965f, 0.43069714f }, - { 0.89710057f, 0.44182643f }, - { 0.89156735f, 0.4528881f }, - { 0.88589776f, 0.4638805f }, - { 0.8800927f, 0.47480196f }, - { 0.8741529f, 0.48565078f }, - { 0.8680794f, 0.4964253f }, - { 0.8618732f, 0.5071239f }, - { 0.8555351f, 0.51774484f }, - { 0.8490661f, 0.52828664f }, - { 0.8424672f, 0.5387476f }, - { 0.83573943f, 0.5491262f }, - { 0.8288838f, 0.55942076f }, - { 0.82190144f, 0.5696297f }, - { 0.8147933f, 0.57975155f }, - { 0.8075605f, 0.58978474f }, - { 0.8002042f, 0.59972763f }, - { 0.79272544f, 0.60957885f }, - { 0.78512543f, 0.6193367f }, - { 0.7774054f, 0.62899995f }, - { 0.7695663f, 0.6385669f }, - { 0.76160955f, 0.6480362f }, - { 0.7535363f, 0.65740633f }, - { 0.74534774f, 0.66667587f }, - { 0.73704517f, 0.6758435f }, - { 0.7286299f, 0.6849077f }, - { 0.7201031f, 0.6938671f }, - { 0.71146613f, 0.70272034f }, - { 0.70272034f, 0.71146613f }, - { 0.6938671f, 0.7201031f }, - { 0.6849077f, 0.7286299f }, - { 0.6758435f, 0.73704517f }, - { 0.66667587f, 0.74534774f }, - { 0.65740633f, 0.7535363f }, - { 0.6480362f, 0.76160955f }, - { 0.6385669f, 0.7695663f }, - { 0.62899995f, 0.7774054f }, - { 0.6193367f, 0.78512543f }, - { 0.60957885f, 0.79272544f }, - { 0.59972763f, 0.8002042f }, - { 0.58978474f, 0.8075605f }, - { 0.57975155f, 0.8147933f }, - { 0.5696297f, 0.82190144f }, - { 0.55942076f, 0.8288838f }, - { 0.5491262f, 0.83573943f }, - { 0.5387476f, 0.8424672f }, - { 0.52828664f, 0.8490661f }, - { 0.51774484f, 0.8555351f }, - { 0.5071239f, 0.8618732f }, - { 0.4964253f, 0.8680794f }, - { 0.48565078f, 0.8741529f }, - { 0.47480196f, 0.8800927f }, - { 0.4638805f, 0.88589776f }, - { 0.4528881f, 0.89156735f }, - { 0.44182643f, 0.89710057f }, - { 0.43069714f, 0.9024965f }, - { 0.419502f, 0.9077544f }, - { 0.40824264f, 0.91287345f }, - { 0.39692086f, 0.9178528f }, - { 0.38553834f, 0.9226918f }, - { 0.37409684f, 0.9273896f }, - { 0.36259815f, 0.9319456f }, - { 0.35104394f, 0.936359f }, - { 0.33943605f, 0.9406291f }, - { 0.32777625f, 0.9447554f }, - { 0.3160663f, 0.9487371f }, - { 0.304308f, 0.9525737f }, - { 0.29250312f, 0.95626456f }, - { 0.2806535f, 0.9598091f }, - { 0.26876098f, 0.9632069f }, - { 0.25682732f, 0.9664573f }, - { 0.24485438f, 0.96955985f }, - { 0.23284398f, 0.9725141f }, - { 0.22079796f, 0.97531956f }, - { 0.20871817f, 0.97797585f }, - { 0.19660644f, 0.98048246f }, - { 0.18446463f, 0.98283917f }, - { 0.17229462f, 0.9850455f }, - { 0.16009824f, 0.9871011f }, - { 0.14787737f, 0.9890057f }, - { 0.13563387f, 0.990759f }, - { 0.12336964f, 0.9923608f }, - { 0.111086525f, 0.9938107f }, - { 0.09878642f, 0.99510866f }, - { 0.0864712f, 0.9962543f }, - { 0.074142754f, 0.99724764f }, - { 0.061802965f, 0.99808836f }, - { 0.04945372f, 0.99877644f }, - { 0.03709691f, 0.9993117f }, - { 0.024734428f, 0.99969405f }, - { 0.012368159f, 0.9999235f }, - { 0.0f, 1.0f }, - { -0.012368159f, 0.9999235f }, - { -0.024734428f, 0.99969405f }, - { -0.03709691f, 0.9993117f }, - { -0.04945372f, 0.99877644f }, - { -0.061802965f, 0.99808836f }, - { -0.074142754f, 0.99724764f }, - { -0.0864712f, 0.9962543f }, - { -0.09878642f, 0.99510866f }, - { -0.111086525f, 0.9938107f }, - { -0.12336964f, 0.9923608f }, - { -0.13563387f, 0.990759f }, - { -0.14787737f, 0.9890057f }, - { -0.16009824f, 0.9871011f }, - { -0.17229462f, 0.9850455f }, - { -0.18446463f, 0.98283917f }, - { -0.19660644f, 0.98048246f }, - { -0.20871817f, 0.97797585f }, - { -0.22079796f, 0.97531956f }, - { -0.23284398f, 0.9725141f }, - { -0.24485438f, 0.96955985f }, - { -0.25682732f, 0.9664573f }, - { -0.26876098f, 0.9632069f }, - { -0.2806535f, 0.9598091f }, - { -0.29250312f, 0.95626456f }, - { -0.304308f, 0.9525737f }, - { -0.3160663f, 0.9487371f }, - { -0.32777625f, 0.9447554f }, - { -0.33943605f, 0.9406291f }, - { -0.35104394f, 0.936359f }, - { -0.36259815f, 0.9319456f }, - { -0.37409684f, 0.9273896f }, - { -0.38553834f, 0.9226918f }, - { -0.39692086f, 0.9178528f }, - { -0.40824264f, 0.91287345f }, - { -0.419502f, 0.9077544f }, - { -0.43069714f, 0.9024965f }, - { -0.44182643f, 0.89710057f }, - { -0.4528881f, 0.89156735f }, - { -0.4638805f, 0.88589776f }, - { -0.47480196f, 0.8800927f }, - { -0.48565078f, 0.8741529f }, - { -0.4964253f, 0.8680794f }, - { -0.5071239f, 0.8618732f }, - { -0.51774484f, 0.8555351f }, - { -0.52828664f, 0.8490661f }, - { -0.5387476f, 0.8424672f }, - { -0.5491262f, 0.83573943f }, - { -0.55942076f, 0.8288838f }, - { -0.5696297f, 0.82190144f }, - { -0.57975155f, 0.8147933f }, - { -0.58978474f, 0.8075605f }, - { -0.59972763f, 0.8002042f }, - { -0.60957885f, 0.79272544f }, - { -0.6193367f, 0.78512543f }, - { -0.62899995f, 0.7774054f }, - { -0.6385669f, 0.7695663f }, - { -0.6480362f, 0.76160955f }, - { -0.65740633f, 0.7535363f }, - { -0.66667587f, 0.74534774f }, - { -0.6758435f, 0.73704517f }, - { -0.6849077f, 0.7286299f }, - { -0.6938671f, 0.7201031f }, - { -0.70272034f, 0.71146613f }, - { -0.71146613f, 0.70272034f }, - { -0.7201031f, 0.6938671f }, - { -0.7286299f, 0.6849077f }, - { -0.73704517f, 0.6758435f }, - { -0.74534774f, 0.66667587f }, - { -0.7535363f, 0.65740633f }, - { -0.76160955f, 0.6480362f }, - { -0.7695663f, 0.6385669f }, - { -0.7774054f, 0.62899995f }, - { -0.78512543f, 0.6193367f }, - { -0.79272544f, 0.60957885f }, - { -0.8002042f, 0.59972763f }, - { -0.8075605f, 0.58978474f }, - { -0.8147933f, 0.57975155f }, - { -0.82190144f, 0.5696297f }, - { -0.8288838f, 0.55942076f }, - { -0.83573943f, 0.5491262f }, - { -0.8424672f, 0.5387476f }, - { -0.8490661f, 0.52828664f }, - { -0.8555351f, 0.51774484f }, - { -0.8618732f, 0.5071239f }, - { -0.8680794f, 0.4964253f }, - { -0.8741529f, 0.48565078f }, - { -0.8800927f, 0.47480196f }, - { -0.88589776f, 0.4638805f }, - { -0.89156735f, 0.4528881f }, - { -0.89710057f, 0.44182643f }, - { -0.9024965f, 0.43069714f }, - { -0.9077544f, 0.419502f }, - { -0.91287345f, 0.40824264f }, - { -0.9178528f, 0.39692086f }, - { -0.9226918f, 0.38553834f }, - { -0.9273896f, 0.37409684f }, - { -0.9319456f, 0.36259815f }, - { -0.936359f, 0.35104394f }, - { -0.9406291f, 0.33943605f }, - { -0.9447554f, 0.32777625f }, - { -0.9487371f, 0.3160663f }, - { -0.9525737f, 0.304308f }, - { -0.95626456f, 0.29250312f }, - { -0.9598091f, 0.2806535f }, - { -0.9632069f, 0.26876098f }, - { -0.9664573f, 0.25682732f }, - { -0.96955985f, 0.24485438f }, - { -0.9725141f, 0.23284398f }, - { -0.97531956f, 0.22079796f }, - { -0.97797585f, 0.20871817f }, - { -0.98048246f, 0.19660644f }, - { -0.98283917f, 0.18446463f }, - { -0.9850455f, 0.17229462f }, - { -0.9871011f, 0.16009824f }, - { -0.9890057f, 0.14787737f }, - { -0.990759f, 0.13563387f }, - { -0.9923608f, 0.12336964f }, - { -0.9938107f, 0.111086525f }, - { -0.99510866f, 0.09878642f }, - { -0.9962543f, 0.0864712f }, - { -0.99724764f, 0.074142754f }, - { -0.99808836f, 0.061802965f }, - { -0.99877644f, 0.04945372f }, - { -0.9993117f, 0.03709691f }, - { -0.99969405f, 0.024734428f }, - { -0.9999235f, 0.012368159f }, - { -1.0f, 0.0f }, +#if 0 +// todo this is for testing other hash tables +struct b3TestHash +{ + size_t operator()( uint64_t key ) const + { + key ^= key >> 23; + key *= 0x2127599bf4325c37ull; + key ^= key >> 47; + return (size_t)key; + } }; +#endif -static b3CosSin b3GetQuantizedCosSin( int code ) -{ - B3_ASSERT( -254 <= code && code <= 254 ); - int index = b3MinInt( code < 0 ? -code : code, 254 ); - b3CosSin cs = s_quantizedCosSin[index]; - if ( code < 0 ) - { - cs.sine = -cs.sine; - } - - return cs; -} - -int8_t b3QuantizeEdgeAngle( float radians ) -{ - float scaled = radians * ( B3_EDGE_ANGLE_STEPS / B3_PI ); - int quantized = scaled >= 0.0f ? (int)( scaled + 0.5f ) : -(int)( 0.5f - scaled ); - return (int8_t)b3ClampInt( quantized, -127, 127 ); -} - -// Ring of mesh-space edge directions in 16-bit octahedral encoding. -typedef struct b3VertexRing -{ - // Number of boundary edges with 90 degree cliffs. - uint16_t cliffCount; -} b3VertexRing; - -typedef struct b3VertexRingEntry -{ - // Octohedral encoded edge direction. - uint16_t code; -} b3VertexRingEntry; - -static b3Vec3 b3FoldOctahedral( float x, float y ) -{ - return (b3Vec3){ - ( 1.0f - b3AbsFloat( y ) ) * ( x >= 0.0f ? 1.0f : -1.0f ), - ( 1.0f - b3AbsFloat( x ) ) * ( y >= 0.0f ? 1.0f : -1.0f ), - 0.0f, - }; -} - -static b3Vec3 b3DecodeRingDirection( uint16_t code ) -{ - float x = (float)( code & 0xFF ) * ( 2.0f / 255.0f ) - 1.0f; - float y = (float)( code >> 8 ) * ( 2.0f / 255.0f ) - 1.0f; - float z = 1.0f - b3AbsFloat( x ) - b3AbsFloat( y ); - if ( z < 0.0f ) - { - b3Vec3 folded = b3FoldOctahedral( x, y ); - x = folded.x; - y = folded.y; - } - - return b3Normalize( (b3Vec3){ x, y, z } ); -} - -typedef struct b3RingEncoder -{ - float* x; - float* y; - float* z; - b3VertexRingEntry* entries; - int count; - int capacity; -} b3RingEncoder; - -static void b3PushRingEntry( b3RingEncoder* encoder, b3Vec3 direction ) -{ - int index = encoder->count; - B3_ASSERT( index < encoder->capacity ); - encoder->x[index] = direction.x; - encoder->y[index] = direction.y; - encoder->z[index] = direction.z; - encoder->count = index + 1; -} - -static void b3EncodeRingEntries( b3RingEncoder* encoder ) -{ - float* xs = encoder->x; - float* ys = encoder->y; - float* zs = encoder->z; - int count = encoder->count; - - int paddedCount = ( count + 3 ) & ~3; - B3_ASSERT( paddedCount <= encoder->capacity ); - for ( int i = count; i < paddedCount; ++i ) - { - xs[i] = 0.0f; - ys[i] = 0.0f; - zs[i] = 1.0f; - } - - for ( int i = 0; i < count; i += 4 ) - { - b3FloatW4 x = b3LoadW4( xs + i ); - b3FloatW4 y = b3LoadW4( ys + i ); - b3FloatW4 z = b3LoadW4( zs + i ); - b3FloatW4 zero = b3ZeroW4(); - b3FloatW4 one = b3SplatW4( 1.0f ); - b3FloatW4 minusOne = b3SplatW4( -1.0f ); - b3FloatW4 sum = b3AddW4( b3AddW4( b3AbsW4( x ), b3AbsW4( y ) ), b3AbsW4( z ) ); - b3FloatW4 ox = b3DivW4( x, sum ); - b3FloatW4 oy = b3DivW4( y, sum ); - b3FloatW4 fx = b3MulW4( b3SubW4( one, b3AbsW4( oy ) ), b3BlendW4( one, minusOne, b3LessThanW4( ox, zero ) ) ); - b3FloatW4 fy = b3MulW4( b3SubW4( one, b3AbsW4( ox ) ), b3BlendW4( one, minusOne, b3LessThanW4( oy, zero ) ) ); - b3FloatW4 below = b3LessThanW4( z, zero ); - ox = b3BlendW4( ox, fx, below ); - oy = b3BlendW4( oy, fy, below ); - b3FloatW4 scale = b3SplatW4( 127.5f ); - b3FloatW4 half = b3SplatW4( 0.5f ); - b3StoreW4( xs + i, b3AddW4( b3MulW4( scale, b3AddW4( ox, one ) ), half ) ); - b3StoreW4( ys + i, b3AddW4( b3MulW4( scale, b3AddW4( oy, one ) ), half ) ); - } - - for ( int i = 0; i < count; ++i ) - { - int u = b3ClampInt( (int)xs[i], 0, 255 ); - int v = b3ClampInt( (int)ys[i], 0, 255 ); - encoder->entries[i].code = (uint16_t)( u | ( v << 8 ) ); - } -} - -bool b3GetMeshNeighborNormal( const b3Mesh* mesh, int triangleIndex, int edgeIndex, b3Vec3* normal ) -{ - const b3MeshData* data = mesh->data; - B3_ASSERT( 0 <= triangleIndex && triangleIndex < data->triangleCount ); - B3_ASSERT( 0 <= edgeIndex && edgeIndex < 3 ); - - const int8_t* edgeAngles = b3GetMeshEdgeAngles( data ); - if ( edgeAngles == NULL ) - { - return false; - } - - b3Vec3 scale = mesh->scale; - if ( scale.x * scale.y * scale.z < 0.0f ) - { - // Reflected mesh. - edgeIndex = 2 - edgeIndex; - } - - int8_t quantized = edgeAngles[3 * triangleIndex + edgeIndex]; - if ( quantized == B3_BOUNDARY_EDGE_ANGLE ) - { - return false; - } - - const b3MeshTriangle* triangles = b3GetMeshTriangles( data ); - const b3Vec3* vertices = b3GetMeshVertices( data ); - b3MeshTriangle triangle = triangles[triangleIndex]; - int indices[3] = { triangle.index1, triangle.index2, triangle.index3 }; - - b3Vec3 a = vertices[indices[edgeIndex]]; - b3Vec3 b = vertices[indices[( edgeIndex + 1 ) % 3]]; - b3Vec3 c = vertices[indices[( edgeIndex + 2 ) % 3]]; - b3Vec3 n = b3Normalize( b3Cross( b3Sub( b, a ), b3Sub( c, a ) ) ); - b3Vec3 outward = b3Cross( b3Normalize( b3Sub( b, a ) ), n ); - - b3CosSin cs = b3GetQuantizedCosSin( 2 * quantized ); - b3Vec3 unscaled = b3Add( b3MulSV( cs.cosine, n ), b3MulSV( cs.sine, outward ) ); - - b3Vec3 absScale = b3Abs( scale ); - if ( absScale.y == absScale.x && absScale.z == absScale.x ) - { - // Shortcut for uniform scale. Common case. - *normal = (b3Vec3){ - scale.x < 0.0f ? -unscaled.x : unscaled.x, - scale.y < 0.0f ? -unscaled.y : unscaled.y, - scale.z < 0.0f ? -unscaled.z : unscaled.z, - }; - return true; - } - - // Handle non-uniform scale. - b3Vec3 invScale = { 1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z }; - *normal = b3Normalize( b3Mul( invScale, unscaled ) ); - return true; -} - -static int b3GetMeshVertexIndex( const b3Mesh* mesh, b3MeshTriangle triangle, int vertexIndex ) -{ - b3Vec3 scale = mesh->scale; - if ( scale.x * scale.y * scale.z < 0.0f ) - { - // Handle reflection. - vertexIndex = ( 3 - vertexIndex ) % 3; - } - - int indices[3] = { triangle.index1, triangle.index2, triangle.index3 }; - return indices[vertexIndex]; -} - -int b3GetMeshVertexFlag( const b3Mesh* mesh, int triangleIndex, int vertexIndex ) -{ - const b3MeshData* data = mesh->data; - B3_ASSERT( 0 <= triangleIndex && triangleIndex < data->triangleCount ); - B3_ASSERT( 0 <= vertexIndex && vertexIndex < 3 ); - - const uint8_t* vertexFlags = b3GetMeshVertexFlags( data ); - if ( vertexFlags == NULL ) - { - return b3_flatVertex; - } - - b3MeshTriangle triangle = b3GetMeshTriangles( data )[triangleIndex]; - int index = b3GetMeshVertexIndex( mesh, triangle, vertexIndex ); - return vertexFlags[index]; -} - -// Is the candidate manifold normal in vertex Voronoi region? -bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexIndex, b3Vec3 normal, float tolerance ) -{ - const b3MeshData* data = mesh->data; - B3_ASSERT( 0 <= triangleIndex && triangleIndex < data->triangleCount ); - B3_ASSERT( 0 <= vertexIndex && vertexIndex < 3 ); - - if ( data->vertexRingOffset == 0 ) - { - return true; - } - - const b3MeshTriangle* triangles = b3GetMeshTriangles( data ); - b3MeshTriangle triangle = triangles[triangleIndex]; - int vertex = b3GetMeshVertexIndex( mesh, triangle, vertexIndex ); - - // Account for the mesh scale, including reflection. The cliff scale is separate - // to maintain the 90 degree angle that all cliffs use. - b3Vec3 scale = mesh->scale; - b3Vec3 edgeScale, cliffScale; - b3Vec3 absScale = b3Abs( scale ); - bool uniform = absScale.y == absScale.x && absScale.z == absScale.x; - if ( uniform ) - { - edgeScale = - (b3Vec3){ scale.x < 0.0f ? -1.0f : 1.0f, scale.y < 0.0f ? -1.0f : 1.0f, scale.z < 0.0f ? -1.0f : 1.0f }; - cliffScale = edgeScale; - } - else - { - edgeScale = scale; - cliffScale = (b3Vec3){ 1.0f / scale.x, 1.0f / scale.y, 1.0f / scale.z }; - } - - const int* starts = (const int*)( (intptr_t)data + data->vertexRingOffset ); - int byteCount = starts[vertex + 1] - starts[vertex]; - if ( byteCount == 0 ) - { - // Flat vertex - const b3Vec3* vertices = b3GetMeshVertices( data ); - b3Vec3 faceNormal = - b3MakeNormalFromPoints( vertices[triangle.index1], vertices[triangle.index2], vertices[triangle.index3] ); - faceNormal = b3Normalize( b3Mul( cliffScale, faceNormal ) ); - float cosAngle = b3Dot( normal, faceNormal ); - return cosAngle > 0.0f && cosAngle * cosAngle >= 1.0f - tolerance * tolerance; - } - - const b3VertexRing* ring = (const b3VertexRing*)( (intptr_t)data + starts[vertex] ); - const b3VertexRingEntry* entries = (const b3VertexRingEntry*)( ring + 1 ); - int entryCount = ( byteCount - (int)sizeof( b3VertexRing ) ) / (int)sizeof( b3VertexRingEntry ); - int edgeCount = entryCount - ring->cliffCount; - - b3Vec3 edgeNormal = b3Mul( edgeScale, normal ); - b3Vec3 cliffNormal = b3Mul( cliffScale, normal ); - - for ( int i = 0; i < entryCount; ++i ) - { - bool isCliff = i >= edgeCount; - b3Vec3 direction = b3DecodeRingDirection( entries[i].code ); - float lean = b3Dot( isCliff ? cliffNormal : edgeNormal, direction ); - - float limit = tolerance; - if ( uniform == false ) - { - limit *= b3Length( b3Mul( isCliff ? cliffScale : edgeScale, direction ) ); - } - - if ( lean > limit ) - { - return false; - } - } - - return true; -} - -static void b3IdentifyEdges( b3MeshData* mesh, b3Vec3* normals ) +// Results for MeshCreationBenchmark +// eastl::hash_map : 4.9703 ms and 5.1445ms with FastHash function +// std::unordered_map : 4.8755 ms and 4.4780ms with FastHash function +// verstable : 3.3968 ms with default FastHash +// no edge identification : 1.7396 ms +static void b3IdentifyEdges( b3MeshData* mesh ) { b3MeshTriangle* triangles = b3GetMeshTrianglesWrite( mesh ); const b3Vec3* vertices = b3GetMeshVertices( mesh ); uint8_t* flags = b3GetMeshFlagsWrite( mesh ); - int8_t* edgeAngles = b3GetMeshEdgeAnglesWrite( mesh ); - B3_ASSERT( edgeAngles != NULL ); int triangleCount = mesh->triangleCount; int edgeCount = 3 * triangleCount; - - for ( int i = 0; i < edgeCount; ++i ) - { - edgeAngles[i] = B3_BOUNDARY_EDGE_ANGLE; - } - b3MeshEdge* edges = B3_ALLOC( b3MeshEdge, edgeCount ); + b3Vec3* normals = B3_ALLOC( b3Vec3, triangleCount ); for ( int i = 0; i < triangleCount; ++i ) { @@ -1721,61 +1104,27 @@ static void b3IdentifyEdges( b3MeshData* mesh, b3Vec3* normals ) normals[i] = b3Normalize( n ); } - // Counting sort for edges. Faster than a hashtable. - int vertexCount = mesh->vertexCount; - int* edgeStarts = B3_ALLOC( int, ( vertexCount + 1 ) ); - int* sortedEdges = B3_ALLOC( int, edgeCount ); - int* stamps = B3_ALLOC( int, vertexCount ); - int* firstEdges = B3_ALLOC( int, vertexCount ); + b3EdgeMap map; + b3EdgeMap_init( &map ); + b3EdgeMap_reserve( &map, edgeCount ); - for ( int i = 0; i <= vertexCount; ++i ) - { - edgeStarts[i] = 0; - } - - for ( int i = 0; i < vertexCount; ++i ) - { - stamps[i] = B3_NULL_INDEX; - } - - for ( int i = 0; i < edgeCount; ++i ) - { - B3_ASSERT( 0 <= edges[i].vertex1 && edges[i].vertex2 < vertexCount ); - edgeStarts[edges[i].vertex1 + 1] += 1; - } - - for ( int i = 0; i < vertexCount; ++i ) - { - edgeStarts[i + 1] += edgeStarts[i]; - } - - for ( int i = 0; i < edgeCount; ++i ) - { - int vertex1 = edges[i].vertex1; - sortedEdges[edgeStarts[vertex1]] = i; - edgeStarts[vertex1] += 1; - } + uint64_t key = (uint64_t)edges[0].vertex1 << 32 | (uint64_t)edges[0].vertex2; + b3EdgeMap_insert( &map, key, 0 ); // Find unique edges and assign adjacency - int begin = 0; - for ( int vertex1 = 0; vertex1 < vertexCount; ++vertex1 ) + for ( int i = 1; i < edgeCount; ++i ) { - int end = edgeStarts[vertex1]; - for ( int j = begin; j < end; ++j ) + b3MeshEdge* edge = edges + i; + key = (uint64_t)edge->vertex1 << 32 | (uint64_t)edge->vertex2; + b3EdgeMap_itr itr = b3EdgeMap_get( &map, key ); + + if ( b3EdgeMap_is_end( itr ) ) { - int i = sortedEdges[j]; - b3MeshEdge* edge = edges + i; - int vertex2 = edge->vertex2; - - // Establish twin. - if ( stamps[vertex2] != vertex1 ) - { - stamps[vertex2] = vertex1; - firstEdges[vertex2] = i; - continue; - } - - int otherIndex = firstEdges[vertex2]; + b3EdgeMap_insert( &map, key, i ); + } + else + { + int otherIndex = itr.data->val; B3_ASSERT( otherIndex < i ); b3MeshEdge* base = edges + otherIndex; @@ -1787,21 +1136,9 @@ static void b3IdentifyEdges( b3MeshData* mesh, b3Vec3* normals ) base->triangleCount += 1; } - - begin = end; } - B3_FREE( firstEdges, int, vertexCount ); - B3_FREE( stamps, int, vertexCount ); - B3_FREE( sortedEdges, int, edgeCount ); - B3_FREE( edgeStarts, int, ( vertexCount + 1 ) ); - - int angleCapacity = ( edgeCount / 2 + 3 ) & ~3; - float* angleYs = B3_ALLOC( float, angleCapacity ); - float* angleXs = B3_ALLOC( float, angleCapacity ); - float* angleLengthSqs = B3_ALLOC( float, angleCapacity ); - int* angleSlots = B3_ALLOC( int, 2 * angleCapacity ); - int angleCount = 0; + b3EdgeMap_cleanup( &map ); for ( int i = 0; i < edgeCount; ++i ) { @@ -1851,31 +1188,11 @@ static void b3IdentifyEdges( b3MeshData* mesh, b3Vec3* normals ) b3Vec3 v2 = vertices[i2]; b3Vec3 v3 = vertices[i3]; b3Vec3 p = vertices[opposite]; - b3Vec3 n1 = normals[edge->triangle1]; - b3Vec3 n2 = normals[edge->triangle2]; - - // Quantize the angles between neighboring normals. - int indices1[3] = { i1, i2, i3 }; - int indices2[3] = { j1, j2, j3 }; - int k1 = edge->triangleEdgeIndex1; - int k2 = edge->triangleEdgeIndex2; - if ( indices1[k1] == indices2[( k2 + 1 ) % 3] ) - { - b3Vec3 a = vertices[indices1[k1]]; - b3Vec3 b = vertices[indices1[( k1 + 1 ) % 3]]; - b3Vec3 edgeVector = b3Sub( b, a ); - b3Vec3 outward = b3Cross( edgeVector, n1 ); - B3_ASSERT( angleCount < angleCapacity ); - angleYs[angleCount] = b3Dot( n2, outward ); - angleXs[angleCount] = b3Dot( n2, n1 ); - angleLengthSqs[angleCount] = b3Dot( edgeVector, edgeVector ); - angleSlots[2 * angleCount + 0] = 3 * edge->triangle1 + k1; - angleSlots[2 * angleCount + 1] = 3 * edge->triangle2 + k2; - angleCount += 1; - } float cos5Deg = 0.9962f; float signedVolume = b3SignedVolume( v1, v2, v3, p ); + b3Vec3 n1 = normals[edge->triangle1]; + b3Vec3 n2 = normals[edge->triangle2]; float cosAngle = b3Dot( n1, n2 ); if ( signedVolume > 0.0f || cosAngle > cos5Deg ) { @@ -1892,288 +1209,10 @@ static void b3IdentifyEdges( b3MeshData* mesh, b3Vec3* normals ) } } - int paddedAngleCount = ( angleCount + 3 ) & ~3; - B3_ASSERT( paddedAngleCount <= angleCapacity ); - for ( int i = angleCount; i < paddedAngleCount; ++i ) - { - angleYs[i] = 0.0f; - angleXs[i] = 0.0f; - angleLengthSqs[i] = 0.0f; - } - - for ( int i = 0; i < angleCount; i += 4 ) - { - b3FloatW4 x = b3MulW4( b3LoadW4( angleXs + i ), b3SqrtW4( b3LoadW4( angleLengthSqs + i ) ) ); - b3FloatW4 angle = b3Atan2W4( b3LoadW4( angleYs + i ), x ); - b3StoreW4( angleYs + i, angle ); - } - - for ( int i = 0; i < angleCount; ++i ) - { - int8_t quantized = b3QuantizeEdgeAngle( angleYs[i] ); - edgeAngles[angleSlots[2 * i + 0]] = quantized; - edgeAngles[angleSlots[2 * i + 1]] = quantized; - } - - B3_FREE( angleSlots, int, 2 * angleCapacity ); - B3_FREE( angleLengthSqs, float, angleCapacity ); - B3_FREE( angleXs, float, angleCapacity ); - B3_FREE( angleYs, float, angleCapacity ); - - uint8_t* vertexFlags = b3GetMeshVertexFlagsWrite( mesh ); - B3_ASSERT( vertexFlags != NULL ); - - for ( int i = 0; i < mesh->vertexCount; ++i ) - { - vertexFlags[i] = b3_flatVertex; - } - - // Vertex flags for ghost collision handling. - for ( int i = 0; i < triangleCount; ++i ) - { - int indices[3] = { triangles[i].index1, triangles[i].index2, triangles[i].index3 }; - for ( int k = 0; k < 3; ++k ) - { - int8_t angle = edgeAngles[3 * i + k]; - int a = indices[k]; - int b = indices[k < 2 ? k + 1 : 0]; - - // Edge not flat? - if ( angle != 0 ) - { - vertexFlags[a] = (uint8_t)( vertexFlags[a] & ~b3_flatVertex ); - vertexFlags[b] = (uint8_t)( vertexFlags[b] & ~b3_flatVertex ); - } - - // Edge concave? - if ( angle < 0 && angle != B3_BOUNDARY_EDGE_ANGLE ) - { - vertexFlags[a] |= b3_concaveVertex; - vertexFlags[b] |= b3_concaveVertex; - } - } - } - + B3_FREE( normals, b3Vec3, triangleCount ); B3_FREE( edges, b3MeshEdge, edgeCount ); } -// Push the ring entry directions of a vertex to the encoder. Returns the cliff count. -static int b3BuildVertexRing( const b3MeshData* mesh, const b3Vec3* normals, const int* fan, int fanCount, int vertex, - int* stamps, b3RingEncoder* encoder ) -{ - const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh ); - const b3Vec3* vertices = b3GetMeshVertices( mesh ); - const int8_t* edgeAngles = b3GetMeshEdgeAngles( mesh ); - - for ( int i = 0; i < fanCount; ++i ) - { - b3MeshTriangle triangle = triangles[fan[i]]; - int indices[3] = { triangle.index1, triangle.index2, triangle.index3 }; - int k = indices[0] == vertex ? 0 : ( indices[1] == vertex ? 1 : 2 ); - - // The other vertex indices on this triangle that are not the input vertex index. - int others[2] = { indices[k < 2 ? k + 1 : 0], indices[k > 0 ? k - 1 : 2] }; - - for ( int j = 0; j < 2; ++j ) - { - int other = others[j]; - if ( stamps[other] == vertex ) - { - continue; - } - - stamps[other] = vertex; - - // This encodes every edge. The intersection of all planes perpendicular to the edge axis builds - // the Voronoi region. That process can identify edges that don't contribute to the Voronoi region. - // That culling could save storage but is skipped for simplicity. - b3PushRingEntry( encoder, b3Sub( vertices[other], vertices[vertex] ) ); - } - } - - int cliffCount = 0; - for ( int i = 0; i < fanCount; ++i ) - { - int triangleIndex = fan[i]; - b3MeshTriangle triangle = triangles[triangleIndex]; - int indices[3] = { triangle.index1, triangle.index2, triangle.index3 }; - int k = indices[0] == vertex ? 0 : ( indices[1] == vertex ? 1 : 2 ); - int edgeIndices[2] = { k, k > 0 ? k - 1 : 2 }; - - for ( int j = 0; j < 2; ++j ) - { - if ( edgeAngles[3 * triangleIndex + edgeIndices[j]] != B3_BOUNDARY_EDGE_ANGLE ) - { - continue; - } - - // The cliff is a 90 degree drop. - b3PushRingEntry( encoder, b3Neg( normals[triangleIndex] ) ); - cliffCount += 1; - } - } - - return cliffCount; -} - -// Build a neighbor angle ring for each vertex. Used to mitigate ghost collisions with minimal tolerances -// and fudge factors. -static b3MeshData* b3AppendVertexRings( b3MeshData* mesh, const b3Vec3* normals ) -{ - const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh ); - const uint8_t* vertexFlags = b3GetMeshVertexFlags( mesh ); - B3_ASSERT( vertexFlags != NULL ); - - int vertexCount = mesh->vertexCount; - int triangleCount = mesh->triangleCount; - - // Triangle fan counts per vertex via counting sort and prefix sum. - int* fanStarts = B3_ALLOC( int, ( vertexCount + 1 ) ); - - // Sub-arrays of triangle fans for each vertex. - int* fans = B3_ALLOC( int, ( 3 * triangleCount ) ); - - // Cursors for walking fan sub-arrays. - int* cursors = B3_ALLOC( int, vertexCount ); - - // Edge stamps to avoid visiting the same edge twice when - // iterating triangles. - int* stamps = B3_ALLOC( int, vertexCount ); - - // Byte offsets for each sub-array of ring entries per vertex. - int* ringStarts = B3_ALLOC( int, ( vertexCount + 1 ) ); - - // Counting sort - memset( fanStarts, 0, ( vertexCount + 1 ) * sizeof( int ) ); - for ( int i = 0; i < triangleCount; ++i ) - { - fanStarts[triangles[i].index1 + 1] += 1; - fanStarts[triangles[i].index2 + 1] += 1; - fanStarts[triangles[i].index3 + 1] += 1; - } - - for ( int i = 0; i < vertexCount; ++i ) - { - fanStarts[i + 1] += fanStarts[i]; - } - - memcpy( cursors, fanStarts, vertexCount * sizeof( int ) ); - for ( int i = 0; i < triangleCount; ++i ) - { - fans[cursors[triangles[i].index1]++] = i; - fans[cursors[triangles[i].index2]++] = i; - fans[cursors[triangles[i].index3]++] = i; - } - - for ( int i = 0; i < vertexCount; ++i ) - { - stamps[i] = B3_NULL_INDEX; - } - - // Hey dude, I got an offset to the array of offsets. - size_t startsOffset = mesh->byteCount; - - // After the array of offsets, the ring sub-arrays begin. - size_t ringOffset = startsOffset + b3AlignUp8( ( vertexCount + 1 ) * sizeof( int ) ); - - // Upper bound on entries: two edges per fan triangle and two cliffs per boundary edge. - const int8_t* edgeAngles = b3GetMeshEdgeAngles( mesh ); - int entryBound = 0; - for ( int i = 0; i < vertexCount; ++i ) - { - if ( ( vertexFlags[i] & b3_flatVertex ) == 0 ) - { - entryBound += 2 * ( fanStarts[i + 1] - fanStarts[i] ); - } - } - - for ( int i = 0; i < 3 * triangleCount; ++i ) - { - if ( edgeAngles[i] == B3_BOUNDARY_EDGE_ANGLE ) - { - entryBound += 2; - } - } - - b3RingEncoder encoder = { 0 }; - encoder.capacity = ( entryBound + 3 ) & ~3; - encoder.x = B3_ALLOC( float, encoder.capacity ); - encoder.y = B3_ALLOC( float, encoder.capacity ); - encoder.z = B3_ALLOC( float, encoder.capacity ); - encoder.entries = B3_ALLOC( b3VertexRingEntry, encoder.capacity ); - - int* entryStarts = B3_ALLOC( int, ( vertexCount + 1 ) ); - int* cliffCounts = B3_ALLOC( int, vertexCount ); - - // The vertex ring offset for the current vertex. - size_t offset = ringOffset; - - for ( int i = 0; i < vertexCount; ++i ) - { - ringStarts[i] = (int)offset; - entryStarts[i] = encoder.count; - cliffCounts[i] = 0; - if ( vertexFlags[i] & b3_flatVertex ) - { - // Flat vertices don't store ring data. - continue; - } - - const int* fan = fans + fanStarts[i]; - int fanCount = fanStarts[i + 1] - fanStarts[i]; - cliffCounts[i] = b3BuildVertexRing( mesh, normals, fan, fanCount, i, stamps, &encoder ); - int entryCount = encoder.count - entryStarts[i]; - offset += sizeof( b3VertexRing ) + entryCount * sizeof( b3VertexRingEntry ); - } - - ringStarts[vertexCount] = (int)offset; - entryStarts[vertexCount] = encoder.count; - - b3EncodeRingEntries( &encoder ); - - // We now have the required space, grow the blob. - size_t byteCount = ringOffset + b3AlignUp8( offset - ringOffset ); - b3MeshData* result = b3Alloc( byteCount ); - memset( result, 0, byteCount ); - memcpy( result, mesh, mesh->byteCount ); - b3Free( mesh, mesh->byteCount ); - - result->byteCount = (int)byteCount; - result->vertexRingOffset = (int)startsOffset; - - // Copy the ring sub-array offsets per vertex. The vertexCount + 1 entry is the end offset. - memcpy( (uint8_t*)result + startsOffset, ringStarts, ( vertexCount + 1 ) * sizeof( int ) ); - - for ( int i = 0; i < vertexCount; ++i ) - { - if ( ringStarts[i + 1] == ringStarts[i] ) - { - continue; - } - - b3VertexRing* ring = (b3VertexRing*)( (uint8_t*)result + ringStarts[i] ); - B3_ASSERT( cliffCounts[i] <= UINT16_MAX ); - ring->cliffCount = (uint16_t)cliffCounts[i]; - - int entryCount = entryStarts[i + 1] - entryStarts[i]; - memcpy( ring + 1, encoder.entries + entryStarts[i], entryCount * sizeof( b3VertexRingEntry ) ); - } - - B3_FREE( cliffCounts, int, vertexCount ); - B3_FREE( entryStarts, int, ( vertexCount + 1 ) ); - B3_FREE( encoder.entries, b3VertexRingEntry, encoder.capacity ); - B3_FREE( encoder.z, float, encoder.capacity ); - B3_FREE( encoder.y, float, encoder.capacity ); - B3_FREE( encoder.x, float, encoder.capacity ); - B3_FREE( ringStarts, int, ( vertexCount + 1 ) ); - B3_FREE( stamps, int, vertexCount ); - B3_FREE( cursors, int, vertexCount ); - B3_FREE( fans, int, ( 3 * triangleCount ) ); - B3_FREE( fanStarts, int, ( vertexCount + 1 ) ); - - return result; -} - b3MeshData* b3CreateGridMesh( int xCount, int zCount, float cellWidth, int materialCount, bool identifyEdges ) { B3_ASSERT( 0 <= materialCount && materialCount <= UINT8_MAX ); @@ -2282,17 +1321,14 @@ b3MeshData* b3CreateWaveMesh( int xCount, int zCount, float cellWidth, float amp float omegaX = 2.0f * B3_PI * columnFrequency * cellWidth; float x = -0.5f * xWidth; - b3CosSin cs = { 0 }; for ( int ix = 0; ix <= xCount; ++ix ) { - cs = b3ComputeCosSin( omegaX * ix ); - float rowHeight = cs.sine; + float rowHeight = sinf( omegaX * ix ); float z = -0.5f * zWidth; for ( int iz = 0; iz <= zCount; ++iz ) { - cs = b3ComputeCosSin( omegaZ * iz ); - float columnHeight = cs.sine; + float columnHeight = sinf( omegaZ * iz ); float y = amplitude * rowHeight * columnHeight; vertices.data[index] = (b3Vec3){ x, y, z }; @@ -2418,8 +1454,7 @@ b3MeshData* b3CreateBoxMesh( b3Vec3 center, b3Vec3 extent, bool identifyEdges ) float y = extent.y; float z = extent.z; b3Vec3 vertices[] = { - { x, y, z }, { -x, y, z }, { -x, -y, z }, { x, -y, z }, - { x, y, -z }, { -x, y, -z }, { -x, -y, -z }, { x, -y, -z }, + { x, y, z }, { -x, y, z }, { -x, -y, z }, { x, -y, z }, { x, y, -z }, { -x, y, -z }, { -x, -y, -z }, { x, -y, -z }, }; for ( int i = 0; i < 8; ++i ) @@ -2447,14 +1482,13 @@ b3MeshData* b3CreateBoxMesh( b3Vec3 center, b3Vec3 extent, bool identifyEdges ) return b3CreateMesh( &def, NULL, 0 ); } -b3MeshData* b3CreateHollowBoxMesh( b3Vec3 center, b3Vec3 extent ) +b3MeshData* b3CreateHollowBoxMesh(b3Vec3 center, b3Vec3 extent) { float x = extent.x; float y = extent.y; float z = extent.z; b3Vec3 vertices[] = { - { x, y, z }, { -x, y, z }, { -x, -y, z }, { x, -y, z }, - { x, y, -z }, { -x, y, -z }, { -x, -y, -z }, { x, -y, -z }, + { x, y, z }, { -x, y, z }, { -x, -y, z }, { x, -y, z }, { x, y, -z }, { -x, y, -z }, { -x, -y, -z }, { x, -y, -z }, }; for ( int i = 0; i < 8; ++i ) @@ -2517,36 +1551,9 @@ b3MeshData* b3CreatePlatformMesh( b3Vec3 center, float height, float topWidth, f return b3CreateMesh( &def, NULL, 0 ); } -static void b3CopyVerticesWithStride( b3Vec3* dst, const b3Vec3* src, int count, size_t stride ) -{ - if ( stride == sizeof( b3Vec3 ) ) - { - memcpy( dst, src, count * sizeof( b3Vec3 ) ); - return; - } - - for ( int i = 0; i < count; ++i ) - { - dst[i] = *(const b3Vec3*)( (const uint8_t*)src + i * stride ); - } -} - -// Stride larger than this likely indicates stride is uninitialized memory. -#define B3_MAX_STRIDE 4096 - // todo this should fail if the mesh has a height greater than B3_MESH_STACK_SIZE b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, int degenerateCapacity ) { - if ( def->stride != 0 && ( def->stride < sizeof( b3Vec3 ) || B3_MAX_STRIDE < def->stride ) ) - { - return NULL; - } - - if ( ( def->stride & 3 ) != 0 ) - { - return NULL; - } - if ( def->vertexCount < 3 || def->vertices == NULL || def->triangleCount <= 0 || def->indices == NULL ) { return NULL; @@ -2559,7 +1566,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, } int vertexCount = def->vertexCount; - size_t stride = def->stride == 0 ? sizeof( b3Vec3 ) : def->stride; b3AABB meshBounds = B3_BOUNDS3_EMPTY; @@ -2574,7 +1580,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, { b3Array_Resize( vertices, vertexCount ); b3Array_Resize( indices, 3 * triangleCount ); - b3WeldData data = { .srcVertices = def->vertices, .srcIndices = def->indices, @@ -2582,17 +1587,14 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, .dstIndices = indices.data, .vertexCount = vertexCount, .indexCount = 3 * triangleCount, - .stride = stride, }; - vertices.count = b3WeldVertices( &data, def->weldTolerance ); vertexCount = vertices.count; B3_ASSERT( vertexCount <= def->vertexCount ); } else { - vertices.count = vertexCount; - b3CopyVerticesWithStride( vertices.data, def->vertices, vertexCount, stride ); + b3Array_Append( vertices, def->vertices, vertexCount ); b3Array_Append( indices, def->indices, 3 * triangleCount ); } @@ -2602,7 +1604,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, float minArea = 0.01f * B3_LINEAR_SLOP * B3_LINEAR_SLOP; float surfaceArea = 0.0f; int materialCount = 1; - bool clockWise = def->clockWiseWinding; for ( int index = 0; index < triangleCount; ++index ) { @@ -2610,10 +1611,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, int index2 = indices.data[3 * index + 1]; int index3 = indices.data[3 * index + 2]; - B3_ASSERT( 0 <= index1 && index1 < vertexCount ); - B3_ASSERT( 0 <= index2 && index2 < vertexCount ); - B3_ASSERT( 0 <= index3 && index3 < vertexCount ); - b3Vec3 vertex1 = vertices.data[index1]; b3Vec3 vertex2 = vertices.data[index2]; b3Vec3 vertex3 = vertices.data[index3]; @@ -2627,12 +1624,11 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, if ( index1 != index2 && index1 != index3 && index2 != index3 ) { + degenerateCount += 1; if ( degenerateTriangleIndices != NULL && degenerateCount < degenerateCapacity ) { - degenerateTriangleIndices[degenerateCount] = index; + degenerateTriangleIndices[degenerateCount - 1] = index; } - - degenerateCount += 1; } continue; @@ -2641,8 +1637,8 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, surfaceArea += area; b3AABB box = { - .lowerBound = b3Min( vertex1, b3Min( vertex2, vertex3 ) ), - .upperBound = b3Max( vertex1, b3Max( vertex2, vertex3 ) ), + b3Min( vertex1, b3Min( vertex2, vertex3 ) ), + b3Max( vertex1, b3Max( vertex2, vertex3 ) ), }; b3Vec3 center = b3AABB_Center( box ); @@ -2668,8 +1664,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, if ( b3IsSaneAABB( meshBounds ) == false ) { b3Array_Destroy( primitives ); - b3Array_Destroy( indices ); - b3Array_Destroy( vertices ); return NULL; } @@ -2692,15 +1686,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, byteCount += b3AlignUp8( triangleCount * sizeof( uint8_t ) ); int flagsOffset = (int)byteCount; byteCount += b3AlignUp8( triangleCount * sizeof( uint8_t ) ); - int edgeAngleOffset = 0; - int vertexFlagOffset = 0; - if ( def->identifyEdges ) - { - edgeAngleOffset = (int)byteCount; - byteCount += b3AlignUp8( 3 * triangleCount * sizeof( int8_t ) ); - vertexFlagOffset = (int)byteCount; - byteCount += b3AlignUp8( vertexCount * sizeof( uint8_t ) ); - } b3MeshData* mesh = b3Alloc( byteCount ); @@ -2722,8 +1707,6 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, mesh->materialOffset = materialIndicesOffset; mesh->materialCount = materialCount; mesh->flagsOffset = flagsOffset; - mesh->edgeAngleOffset = edgeAngleOffset; - mesh->vertexFlagOffset = vertexFlagOffset; b3MeshNode* nodes = b3GetMeshNodesWrite( mesh ); b3MeshTriangle* triangles = b3GetMeshTrianglesWrite( mesh ); @@ -2737,18 +1720,9 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, for ( int index = 0; index < triangleCount; ++index ) { b3Primitive primitive = primitives.data[index]; - - int i1 = 3 * primitive.triangleIndex + 0; - int i2 = 3 * primitive.triangleIndex + 1; - int i3 = 3 * primitive.triangleIndex + 2; - if ( clockWise ) - { - B3_SWAP( i2, i3 ); - } - - triangles[index].index1 = indices.data[i1]; - triangles[index].index2 = indices.data[i2]; - triangles[index].index3 = indices.data[i3]; + triangles[index].index1 = indices.data[3 * primitive.triangleIndex + 0]; + triangles[index].index2 = indices.data[3 * primitive.triangleIndex + 1]; + triangles[index].index3 = indices.data[3 * primitive.triangleIndex + 2]; flags[index] = 0; // Copy material indices if they exist. Otherwise the material indices are all zeroes. @@ -2767,22 +1741,12 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, { b3Array_Destroy( tempNodes ); b3Array_Destroy( primitives ); - b3Array_Destroy( indices ); - b3Array_Destroy( vertices ); - b3Free( mesh, byteCount ); return NULL; } if ( def->identifyEdges ) { - int meshTriangleCount = mesh->triangleCount; - b3Vec3* normals = B3_ALLOC( b3Vec3, meshTriangleCount ); - - b3IdentifyEdges( mesh, normals ); - - mesh = b3AppendVertexRings( mesh, normals ); - - B3_FREE( normals, b3Vec3, meshTriangleCount ); + b3IdentifyEdges( mesh ); } B3_VALIDATE( b3IsNonDegenerate( mesh, minArea ) ); @@ -2794,7 +1758,7 @@ b3MeshData* b3CreateMesh( const b3MeshDef* def, int* degenerateTriangleIndices, b3Array_Destroy( vertices ); mesh->hash = 0; - mesh->hash = b3Hash64NonZero( (uint8_t*)mesh, mesh->byteCount ); + mesh->hash = b3NonZeroHash( b3Hash( B3_HASH_INIT, (uint8_t*)mesh, mesh->byteCount ) ); return mesh; } @@ -2928,7 +1892,7 @@ b3CastOutput b3RayCastMesh( const b3Mesh* mesh, const b3RayCastInput* input ) b3V32 scale = b3LoadV( &meshScale.x ); b3V32 invScale = b3DivV( b3_oneV, scale ); - bool ccw = meshScale.x * meshScale.y * meshScale.z > 0.0f; + bool clockwise = meshScale.x * meshScale.y * meshScale.z < 0.0f; // Use the inverse scaled ray for traversal of the BVH b3V32 invScaledRayStart = b3MulV( invScale, rayStart ); @@ -2968,16 +1932,16 @@ b3CastOutput b3RayCastMesh( const b3Mesh* mesh, const b3RayCastInput* input ) b3Vec3 vertex2, vertex3; // The CPU should predict this branch - if ( ccw ) - { - vertex2 = b3Mul( meshScale, vertices[triangle.index2] ); - vertex3 = b3Mul( meshScale, vertices[triangle.index3] ); - } - else + if ( clockwise ) { vertex2 = b3Mul( meshScale, vertices[triangle.index3] ); vertex3 = b3Mul( meshScale, vertices[triangle.index2] ); } + else + { + vertex2 = b3Mul( meshScale, vertices[triangle.index2] ); + vertex3 = b3Mul( meshScale, vertices[triangle.index3] ); + } // Collide ray with triangle in scaled space b3V32 v1 = b3LoadV( &vertex1.x ); @@ -3062,7 +2026,7 @@ b3CastOutput b3ShapeCastMesh( const b3Mesh* mesh, const b3ShapeCastInput* input b3V32 scale = b3LoadV( &meshScale.x ); b3V32 invScale = b3DivV( b3_oneV, scale ); b3V32 absInvScale = b3AbsV( invScale ); - bool ccw = meshScale.x * meshScale.y * meshScale.z > 0.0f; + bool clockwise = meshScale.x * meshScale.y * meshScale.z < 0.0f; // Use the inverse scaled shape cast for traversal of the BVH b3V32 invScaledRayStart = b3MulV( invScale, rayStart ); @@ -3099,21 +2063,21 @@ b3CastOutput b3ShapeCastMesh( const b3Mesh* mesh, const b3ShapeCastInput* input int triangleIndex = triangleOffset + index; b3MeshTriangle triangle = triangles[triangleIndex]; - // Collide shape with triangle in scaled space + // Collide ray with triangle in scaled space b3Vec3 vertex1 = b3Mul( meshScale, vertices[triangle.index1] ); b3Vec3 vertex2, vertex3; // The CPU should predict this branch - if ( ccw ) - { - vertex2 = b3Mul( meshScale, vertices[triangle.index2] ); - vertex3 = b3Mul( meshScale, vertices[triangle.index3] ); - } - else + if ( clockwise ) { vertex2 = b3Mul( meshScale, vertices[triangle.index3] ); vertex3 = b3Mul( meshScale, vertices[triangle.index2] ); } + else + { + vertex2 = b3Mul( meshScale, vertices[triangle.index2] ); + vertex3 = b3Mul( meshScale, vertices[triangle.index3] ); + } b3V32 v1 = b3LoadV( &vertex1.x ); b3V32 v2 = b3LoadV( &vertex2.x ); @@ -3122,54 +2086,43 @@ b3CastOutput b3ShapeCastMesh( const b3Mesh* mesh, const b3ShapeCastInput* input b3V32 triangleMin = b3SubV( b3MinV( v1, b3MinV( v2, v3 ) ), shapeExtent ); b3V32 triangleMax = b3AddV( b3MaxV( v1, b3MaxV( v2, v3 ) ), shapeExtent ); - // Test extended triangle vs ray bounds overlap in scaled space. Skip edge tests. - bool overlap = b3TestBoundsOverlap( triangleMin, triangleMax, rayMin, rayMax ); - if ( overlap == false ) + // Test triangle-ray overlap in scaled space + if ( b3TestBoundsOverlap( triangleMin, triangleMax, rayMin, rayMax ) ) { - continue; - } + // Collide shape with triangle in scaled space + b3Vec3 origin = vertex1; + b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( vertex2, origin ), b3Sub( vertex3, origin ) }; + b3Transform shiftedOrigin = { b3Neg( origin ), b3Quat_identity }; - // This test is in scaled space. vertices and center are scaled. - float signedVolume = b3SignedVolume( vertex1, vertex2, vertex3, center ); - if ( signedVolume < 0.0f ) - { - // Backside - continue; - } + b3ShapeCastPairInput pairInput; + pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; + pairInput.proxyB = input->proxy; + pairInput.transform = shiftedOrigin; + pairInput.maxFraction = bestOutput.fraction; + pairInput.translationB = input->translation; + pairInput.canEncroach = input->canEncroach; - // Collide shape with triangle in scaled space. - b3Vec3 origin = vertex1; - b3Vec3 triangleVertices[] = { b3Vec3_zero, b3Sub( vertex2, origin ), b3Sub( vertex3, origin ) }; - b3Transform shiftedOrigin = { b3Neg( origin ), b3Quat_identity }; + b3CastOutput pairOutput = b3ShapeCast( &pairInput ); - b3ShapeCastPairInput pairInput; - pairInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; - pairInput.proxyB = input->proxy; - pairInput.transform = shiftedOrigin; - pairInput.maxFraction = bestOutput.fraction; - pairInput.translationB = input->translation; - pairInput.canEncroach = input->canEncroach; + if ( pairOutput.hit ) + { + pairOutput.point = b3Add( pairOutput.point, origin ); - b3CastOutput pairOutput = b3ShapeCast( &pairInput ); + bestOutput = pairOutput; + bestOutput.triangleIndex = triangleIndex; + bestOutput.materialIndex = materialIndices[triangleIndex]; - if ( pairOutput.hit ) - { - pairOutput.point = b3Add( pairOutput.point, origin ); + // Update ray bounds in scaled space + lambda = b3SplatV( pairOutput.fraction ); + rayEnd = b3AddV( rayStart, b3MulV( lambda, rayDelta ) ); + rayMin = b3MinV( rayStart, rayEnd ); + rayMax = b3MaxV( rayStart, rayEnd ); - bestOutput = pairOutput; - bestOutput.triangleIndex = triangleIndex; - bestOutput.materialIndex = materialIndices[triangleIndex]; - - // Update ray bounds in scaled space - lambda = b3SplatV( pairOutput.fraction ); - rayEnd = b3AddV( rayStart, b3MulV( lambda, rayDelta ) ); - rayMin = b3MinV( rayStart, rayEnd ); - rayMax = b3MaxV( rayStart, rayEnd ); - - // Ray bounds in unscaled space - invScaledRayEnd = b3AddV( invScaledRayStart, b3MulV( lambda, invScaledRayDelta ) ); - invScaledRayMin = b3MinV( invScaledRayStart, invScaledRayEnd ); - invScaledRayMax = b3MaxV( invScaledRayStart, invScaledRayEnd ); + // Ray bounds in unscaled space + invScaledRayEnd = b3AddV( invScaledRayStart, b3MulV( lambda, invScaledRayDelta ) ); + invScaledRayMin = b3MinV( invScaledRayStart, invScaledRayEnd ); + invScaledRayMax = b3MaxV( invScaledRayStart, invScaledRayEnd ); + } } } } @@ -3204,6 +2157,50 @@ b3CastOutput b3ShapeCastMesh( const b3Mesh* mesh, const b3ShapeCastInput* input return bestOutput; } +b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleIndex ) +{ + B3_ASSERT( 0 <= triangleIndex && triangleIndex < mesh->data->triangleCount ); + + const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh->data ); + const uint8_t* flags = b3GetMeshFlags( mesh->data ); + const b3Vec3* vertices = b3GetMeshVertices( mesh->data ); + + b3Triangle result; + b3MeshTriangle triangle = triangles[triangleIndex]; + uint8_t triangleFlags = flags[triangleIndex]; + + b3Vec3 scale = mesh->scale; + + result.vertices[0] = b3Mul( scale, vertices[triangle.index1] ); + result.i1 = triangle.index1; + + if ( scale.x * scale.y * scale.z < 0.0f ) + { + result.vertices[1] = b3Mul( scale, vertices[triangle.index3] ); + result.vertices[2] = b3Mul( scale, vertices[triangle.index2] ); + + result.i2 = triangle.index3; + result.i3 = triangle.index2; + + // mesh is inverted, so concave edges are now convex + result.flags = 0; + result.flags |= ( triangleFlags & b3_inverseConcaveEdge1 ) ? b3_concaveEdge1 : 0; + result.flags |= ( triangleFlags & b3_inverseConcaveEdge2 ) ? b3_concaveEdge2 : 0; + result.flags |= ( triangleFlags & b3_inverseConcaveEdge3 ) ? b3_concaveEdge3 : 0; + } + else + { + result.vertices[1] = b3Mul( scale, vertices[triangle.index2] ); + result.vertices[2] = b3Mul( scale, vertices[triangle.index3] ); + + result.i2 = triangle.index2; + result.i3 = triangle.index3; + result.flags = triangleFlags; + } + + return result; +} + int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* shape, const b3Capsule* mover ) { if ( capacity == 0 ) @@ -3218,7 +2215,7 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh b3SimplexCache cache = { 0 }; float radius = mover->radius; - b3Vec3 center = b3Lerp( mover->center1, mover->center2, 0.5f ); + b3V32 center1 = b3LoadV( &mover->center1.x ); b3V32 center2 = b3LoadV( &mover->center2.x ); b3V32 r = b3SplatV( radius ); @@ -3227,7 +2224,6 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh // Scale may have reflection so min/max may become invalid when unscaled b3Vec3 meshScale = shape->scale; - bool ccw = meshScale.x * meshScale.y * meshScale.z > 0.0f; b3V32 scale = b3LoadV( &meshScale.x ); b3V32 invScale = b3DivV( b3_oneV, scale ); b3V32 temp1 = b3MulV( invScale, boundsMin ); @@ -3242,7 +2238,6 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh const b3MeshNode* node = b3GetRoot( shape->data ); const b3MeshTriangle* triangles = b3GetMeshTriangles( shape->data ); const b3Vec3* vertices = b3GetMeshVertices( shape->data ); - const uint8_t* materialIndices = b3GetMeshMaterialIndices( shape->data ); int planeCount = 0; while ( planeCount < capacity ) @@ -3265,12 +2260,6 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh b3Vec3 vertex1 = vertices[triangle.index1]; b3Vec3 vertex2 = vertices[triangle.index2]; b3Vec3 vertex3 = vertices[triangle.index3]; - - if ( ccw == false ) - { - B3_SWAP( vertex2, vertex3 ); - } - b3V32 v1 = b3LoadV( &vertex1.x ); b3V32 v2 = b3LoadV( &vertex2.x ); b3V32 v3 = b3LoadV( &vertex3.x ); @@ -3278,19 +2267,10 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh // Test triangle bounds overlap in unscaled space if ( b3TestBoundsTriangleOverlap( invScaledBoundsCenter, invScaledBoundsExtent, v1, v2, v3 ) ) { - // Compute shape distance in scaled space. + // Compute shape distance in scaled space. Winding order doesn't matter. + // todo implement one-sided collision? b3Vec3 triangleVertices[] = { b3Mul( meshScale, vertex1 ), b3Mul( meshScale, vertex2 ), b3Mul( meshScale, vertex3 ) }; - - // Vertices and center are in scaled space. - float signedVolume = - b3SignedVolume( triangleVertices[0], triangleVertices[1], triangleVertices[2], center ); - if ( signedVolume < 0.0f ) - { - // Backside - continue; - } - distanceInput.proxyA = (b3ShapeProxy){ triangleVertices, 3, 0.0f }; // reset the cache @@ -3301,13 +2281,12 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh if ( distanceOutput.distance == 0.0f ) { - // deep overlap + // todo SAT } else if ( distanceOutput.distance <= mover->radius ) { b3Plane plane = { distanceOutput.normal, mover->radius - distanceOutput.distance }; - planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA, triangleIndex, 0, - materialIndices[triangleIndex] }; + planes[planeCount] = (b3PlaneResult){ plane, distanceOutput.pointA }; planeCount += 1; if ( planeCount == capacity ) @@ -3342,7 +2321,7 @@ int b3CollideMoverAndMesh( b3PlaneResult* planes, int capacity, const b3Mesh* sh void b3QueryMesh( const b3Mesh* mesh, b3AABB bounds, b3MeshQueryFcn* fcn, void* context ) { b3Vec3 meshScale = mesh->scale; - bool ccw = meshScale.x * meshScale.y * meshScale.z > 0.0f; + bool clockwise = meshScale.x * meshScale.y * meshScale.z > 0.0f; // Scale may have reflection so min/max may become invalid when unscaled b3V32 scale = b3LoadV( &meshScale.x ); @@ -3362,84 +2341,63 @@ void b3QueryMesh( const b3Mesh* mesh, b3AABB bounds, b3MeshQueryFcn* fcn, void* const b3MeshTriangle* triangles = b3GetMeshTriangles( data ); const b3Vec3* vertices = b3GetMeshVertices( data ); - // Test node overlap in unscaled space - if ( b3TestBoundsOverlap( b3LoadV( &node->lowerBound.x ), b3LoadV( &node->upperBound.x ), invScaledBoundsMin, - invScaledBoundsMax ) == false ) - { - return; - } - while ( true ) { - if ( b3IsLeaf( node ) ) + // Test node overlap in unscaled space + b3V32 nodeMin = b3LoadV( &node->lowerBound.x ); + b3V32 nodeMax = b3LoadV( &node->upperBound.x ); + + if ( b3TestBoundsOverlap( nodeMin, nodeMax, invScaledBoundsMin, invScaledBoundsMax ) ) { - int triangleCount = node->data.asLeaf.triangleCount; - int triangleOffset = node->triangleOffset; - - for ( int index = 0; index < triangleCount; ++index ) + if ( b3IsLeaf( node ) ) { - int triangleIndex = triangleOffset + index; - b3MeshTriangle triangle = triangles[triangleIndex]; + int triangleCount = node->data.asLeaf.triangleCount; + int triangleOffset = node->triangleOffset; - b3Vec3 vertex1 = vertices[triangle.index1]; - b3Vec3 vertex2 = vertices[triangle.index2]; - b3Vec3 vertex3 = vertices[triangle.index3]; - b3V32 v1 = b3LoadV( &vertex1.x ); - b3V32 v2 = b3LoadV( &vertex2.x ); - b3V32 v3 = b3LoadV( &vertex3.x ); - - // Perform triangle overlap test in unscaled space. - // todo it is possible that some margins are getting scaled - if ( b3TestBoundsTriangleOverlap( invScaledBoundsCenter, invScaledBoundsExtent, v1, v2, v3 ) ) + for ( int index = 0; index < triangleCount; ++index ) { - b3Vec3 a = b3Mul( meshScale, vertex1 ); - b3Vec3 b, c; - if ( ccw ) - { - b = b3Mul( meshScale, vertex2 ); - c = b3Mul( meshScale, vertex3 ); - } - else - { - b = b3Mul( meshScale, vertex3 ); - c = b3Mul( meshScale, vertex2 ); - } + int triangleIndex = triangleOffset + index; + b3MeshTriangle triangle = triangles[triangleIndex]; - bool result = fcn( a, b, c, triangleIndex, context ); - if ( result == false ) + b3Vec3 vertex1 = vertices[triangle.index1]; + b3Vec3 vertex2 = vertices[triangle.index2]; + b3Vec3 vertex3 = vertices[triangle.index3]; + b3V32 v1 = b3LoadV( &vertex1.x ); + b3V32 v2 = b3LoadV( &vertex2.x ); + b3V32 v3 = b3LoadV( &vertex3.x ); + + // Perform triangle overlap test in unscaled space. Winding order doesn't matter. + // todo it is possible that some margins are getting scaled + if ( b3TestBoundsTriangleOverlap( invScaledBoundsCenter, invScaledBoundsExtent, v1, v2, v3 ) ) { - return; + b3Vec3 a = b3Mul( meshScale, vertex1 ); + b3Vec3 b, c; + if ( clockwise ) + { + b = b3Mul( meshScale, vertex2 ); + c = b3Mul( meshScale, vertex3 ); + } + else + { + b = b3Mul( meshScale, vertex3 ); + c = b3Mul( meshScale, vertex2 ); + } + + bool result = fcn( a, b, c, triangleIndex, context ); + if ( result == false ) + { + return; + } } } } - } - else - { - const b3MeshNode* leftChild = b3GetLeftChild( node ); - const b3MeshNode* rightChild = b3GetRightChild( node ); - - bool overlapLeft = - b3TestBoundsOverlap( b3LoadV( &leftChild->lowerBound.x ), b3LoadV( &leftChild->upperBound.x ), - invScaledBoundsMin, invScaledBoundsMax ); - bool overlapRight = - b3TestBoundsOverlap( b3LoadV( &rightChild->lowerBound.x ), b3LoadV( &rightChild->upperBound.x ), - invScaledBoundsMin, invScaledBoundsMax ); - - if ( overlapLeft ) + else { - if ( overlapRight ) - { - B3_ASSERT( count <= B3_MESH_STACK_SIZE - 1 ); - stack[count++] = rightChild; - } + // Recurse + B3_ASSERT( count <= B3_MESH_STACK_SIZE - 1 ); + stack[count++] = b3GetRightChild( node ); + node = b3GetLeftChild( node ); - node = leftChild; - continue; - } - - if ( overlapRight ) - { - node = rightChild; continue; } } diff --git a/src/mesh_contact.c b/src/mesh_contact.c index 35c880f..d3144b2 100644 --- a/src/mesh_contact.c +++ b/src/mesh_contact.c @@ -2,18 +2,17 @@ // SPDX-License-Identifier: MIT #include "contact.h" -#include "ctz.h" #include "manifold.h" #include "physics_world.h" +#include "qsort.h" #include "shape.h" -#include "simd.h" #include "box3d/types.h" #include -#include -#define B3_FORCE_GHOST_COLLISIONS 0 +// This guards against excessive memory usage and complex collision +#define B3_MAX_MESH_CONTACT_TRIANGLES 256 #define B3_MAX_POINTS_PER_TRIANGLE 32 #if B3_ENABLE_VALIDATION @@ -31,11 +30,8 @@ static bool b3IsSorted( const int* array, int count ) } #endif -#define B3_INITIAL_TRIANGLE_CAPACITY 512 - typedef struct b3TriangleQueryContext { - b3Arena* arena; int* indices; int capacity; int count; @@ -44,23 +40,41 @@ typedef struct b3TriangleQueryContext static bool b3CollectTriangleIndicesCallback( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ) { B3_UNUSED( a, b, c ); - b3TriangleQueryContext* triangleContext = context; + b3TriangleQueryContext* triangleContext = (b3TriangleQueryContext*)context; if ( triangleContext->count == triangleContext->capacity ) { - int capacity = 2 * triangleContext->capacity; - int* indices = b3Bump( triangleContext->arena, capacity * (int)sizeof( int ) ); - memcpy( indices, triangleContext->indices, triangleContext->count * sizeof( int ) ); - triangleContext->indices = indices; - triangleContext->capacity = capacity; + return false; } - triangleContext->indices[triangleContext->count] = triangleIndex; triangleContext->count += 1; - return true; + return triangleContext->count < triangleContext->capacity; } -static void b3RefreshCache( b3Contact* contact, const b3Shape* shapeA, b3WorldTransform xfA, const b3AABB* bounds, - b3Arena arena ) +static int b3QueryMeshTriangles( int* indices, int capacity, const b3Mesh* mesh, b3AABB bounds ) +{ + b3TriangleQueryContext context = { + .indices = indices, + .capacity = capacity, + .count = 0, + }; + + b3QueryMesh( mesh, bounds, b3CollectTriangleIndicesCallback, &context ); + return context.count; +} + +static int b3QueryHeightFieldTriangles( int* indices, int capacity, const b3HeightFieldData* heightField, b3AABB bounds ) +{ + b3TriangleQueryContext context = { + .indices = indices, + .capacity = capacity, + .count = 0, + }; + + b3QueryHeightField( heightField, bounds, b3CollectTriangleIndicesCallback, &context ); + return context.count; +} + +static void b3RefreshCache( b3Contact* contact, const b3Shape* shapeA, b3WorldTransform xfA, const b3AABB* bounds ) { B3_ASSERT( shapeA->type == b3_meshShape || shapeA->type == b3_heightShape ); @@ -74,8 +88,7 @@ static void b3RefreshCache( b3Contact* contact, const b3Shape* shapeA, b3WorldTr for ( int i = 0; i < contact->meshContact.triangleCache.count; ++i ) { B3_ASSERT( 0 <= contact->meshContact.triangleCache.data[i].triangleIndex && - contact->meshContact.triangleCache.data[i].triangleIndex < - shapeA->mesh.data->triangleCount ); + contact->meshContact.triangleCache.data[i].triangleIndex < shapeA->mesh.data->triangleCount ); } } @@ -89,35 +102,40 @@ static void b3RefreshCache( b3Contact* contact, const b3Shape* shapeA, b3WorldTr meshContact->queryBounds.upperBound = b3Add( bounds->upperBound, extension ); // Query triangles - b3TriangleQueryContext queryContext = { - .arena = &arena, - .indices = b3Bump( &arena, B3_INITIAL_TRIANGLE_CAPACITY * (int)sizeof( int ) ), - .capacity = B3_INITIAL_TRIANGLE_CAPACITY, - .count = 0, - }; + int triangleCapacity = B3_MAX_MESH_CONTACT_TRIANGLES; + + int triangleIndices[B3_MAX_MESH_CONTACT_TRIANGLES]; // Bounds are in world space. Convert to the local mesh frame. The broadphase bounds are float, // so the demoted mesh transform is the matching float world frame (exact in float mode). b3Transform meshTransform = b3ToRelativeTransform( xfA, b3Pos_zero ); b3AABB localBounds = b3AABB_Transform( b3InvertTransform( meshTransform ), meshContact->queryBounds ); + int triangleCount; if ( shapeA->type == b3_meshShape ) { - b3QueryMesh( &shapeA->mesh, localBounds, b3CollectTriangleIndicesCallback, &queryContext ); + triangleCount = b3QueryMeshTriangles( triangleIndices, triangleCapacity, &shapeA->mesh, localBounds ); } else { B3_ASSERT( shapeA->type == b3_heightShape ); - b3QueryHeightField( shapeA->heightField, localBounds, b3CollectTriangleIndicesCallback, &queryContext ); + triangleCount = b3QueryHeightFieldTriangles( triangleIndices, triangleCapacity, shapeA->heightField, localBounds ); } - int* triangleIndices = queryContext.indices; - int triangleCount = queryContext.count; + if ( triangleCount == triangleCapacity ) + { + static bool s_once = false; + if ( s_once == false ) + { + b3Log( "WARNING: complex mesh detected, triangle buffer capacity of %d reached", triangleCapacity ); + s_once = true; + } + } // Triangle indices must be sorted to match caches. B3_VALIDATE( b3IsSorted( triangleIndices, triangleCount ) ); // Create new contact cache and match with old one - b3ContactCache* contactCache = b3Bump( &arena, triangleCount * sizeof( b3ContactCache ) ); + b3ContactCache contactCache[B3_MAX_MESH_CONTACT_TRIANGLES]; int index2 = 0; for ( int index1 = 0; index1 < triangleCount; ++index1 ) @@ -151,11 +169,113 @@ static void b3RefreshCache( b3Contact* contact, const b3Shape* shapeA, b3WorldTr } } -#if B3_MAX_MANIFOLD_POINTS == 4 +typedef struct b3TentativeTriangle +{ + float squaredDistance; + int index; +} b3TentativeTriangle; + +#define B3_MAX_EDGE_COUNT 64 + +typedef struct b3FoundEdges +{ + uint64_t keys[B3_MAX_EDGE_COUNT]; + int count; +} b3FoundEdges; + +static inline bool b3AddEdge( b3FoundEdges* edges, int vertex1, int vertex2 ) +{ + uint64_t i1 = (uint64_t)b3MinInt( vertex1, vertex2 ); + uint64_t i2 = (uint64_t)b3MaxInt( vertex1, vertex2 ); + uint64_t key = i1 << 32 | i2; + + int count = edges->count; + for ( int i = 0; i < count; ++i ) + { + if ( edges->keys[i] == key ) + { + return false; + } + } + + if ( count == B3_MAX_EDGE_COUNT ) + { + // This will lead to a potential ghost collision + return true; + } + + edges->keys[count] = key; + edges->count += 1; + + return true; +} + +static inline bool b3FindEdge( b3FoundEdges* edges, int vertex1, int vertex2 ) +{ + uint64_t i1 = (uint64_t)b3MinInt( vertex1, vertex2 ); + uint64_t i2 = (uint64_t)b3MaxInt( vertex1, vertex2 ); + uint64_t key = i1 << 32 | i2; + + int count = edges->count; + for ( int i = 0; i < count; ++i ) + { + if ( edges->keys[i] == key ) + { + return true; + } + } + + return false; +} + +#if 0 +// Two triangles share an edge iff they share at least two vertex indices. +static inline bool b3TrianglesShareEdge( int a1, int a2, int a3, int b1, int b2, int b3 ) +{ + int matches = 0; + matches += ( a1 == b1 || a1 == b2 || a1 == b3 ); + matches += ( a2 == b1 || a2 == b2 || a2 == b3 ); + matches += ( a3 == b1 || a3 == b2 || a3 == b3 ); + return matches >= 2; +} +#endif + +#define B3_MAX_VERTEX_COUNT 64 + +typedef struct b3FoundVertices +{ + int keys[B3_MAX_VERTEX_COUNT]; + int count; +} b3FoundVertices; + +static inline bool b3AddVertex( b3FoundVertices* vertices, int vertex ) +{ + int key = vertex; + + int count = vertices->count; + for ( int i = 0; i < count; ++i ) + { + if ( vertices->keys[i] == key ) + { + return false; + } + } + + if ( count == B3_MAX_VERTEX_COUNT ) + { + // This will lead to a potential ghost collision + return true; + } + + vertices->keys[count] = key; + vertices->count += 1; + + return true; +} // Returns true if (score, separation) should replace (bestScore, bestSeparation). -static inline bool b3IsBetterCullCandidate( float score, float separation, float bestScore, float bestSeparation, - float scoreTol, float separationTol ) +static inline bool b3IsBetterCullCandidate( float score, float separation, float bestScore, float bestSeparation, float scoreTol, + float separationTol ) { if ( score > bestScore + scoreTol ) { @@ -170,34 +290,14 @@ static inline bool b3IsBetterCullCandidate( float score, float separation, float return separation < bestSeparation - separationTol; } -// Find the farthest point from the base point. -static int b3FindFarthestCullPoint( const b3Point2D* points, int count, int index, float scoreTol, float separationTol ) +typedef struct b3Point2D { - b3Vec2 origin = points[index].p; - float bestScore = 0.0f; - float bestSeparation = FLT_MAX; - int bestIndex = B3_NULL_INDEX; - for ( int i = 0; i < count; ++i ) - { - if ( i == index ) - { - continue; - } + b3Vec2 p; + float separation; + int originalIndex; +} b3Point2D; - float score = b3DistanceSquared2( origin, points[i].p ); - if ( b3IsBetterCullCandidate( score, points[i].separation, bestScore, bestSeparation, scoreTol, - separationTol ) ) - { - bestIndex = i; - bestScore = score; - bestSeparation = points[i].separation; - } - } - - return bestIndex; -} - -static int b3CullPoints( b3Point2D* points, int count, bool sweep ) +static int b3CullPoints( b3Point2D* points, int count ) { if ( count <= 1 ) { @@ -209,56 +309,29 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) float separationTol = B3_LINEAR_SLOP; b3Point2D finalPoints[4]; + int count1 = count; + // Step 1: the two points with the largest distance, ties broken by deepest combined separation float bestScore = 0.0f; float bestSeparation = FLT_MAX; int bestIndex1 = B3_NULL_INDEX; int bestIndex2 = B3_NULL_INDEX; - if ( sweep ) + for ( int i = 0; i < count1; ++i ) { - // Arbitrary search direction. - b3Vec2 axis = { 0.92106099f, 0.38941834f }; - int startIndex = 0; - float startScore = b3Dot2( axis, points[0].p ); - float startSeparation = points[0].separation; - for ( int i = 1; i < count; ++i ) + b3Vec2 p1 = points[i].p; + for ( int j = i + 1; j < count1; ++j ) { - float score = b3Dot2( axis, points[i].p ); - if ( b3IsBetterCullCandidate( score, points[i].separation, startScore, startSeparation, tol, - separationTol ) ) - { - startIndex = i; - startScore = score; - startSeparation = points[i].separation; - } - } + float score = b3DistanceSquared2( p1, points[j].p ); + // Separation sum heuristic + float separation = points[i].separation + points[j].separation; - bestIndex1 = b3FindFarthestCullPoint( points, count, startIndex, tolSqr, separationTol ); - B3_ASSERT( bestIndex1 != B3_NULL_INDEX ); - bestIndex2 = b3FindFarthestCullPoint( points, count, bestIndex1, tolSqr, separationTol ); - B3_ASSERT( bestIndex2 != B3_NULL_INDEX ); - bestScore = b3DistanceSquared2( points[bestIndex1].p, points[bestIndex2].p ); - } - else - { - // Step 1: the two points with the largest distance, ties broken by deepest combined separation - for ( int i = 0; i < count; ++i ) - { - b3Vec2 p1 = points[i].p; - for ( int j = i + 1; j < count; ++j ) + if ( b3IsBetterCullCandidate( score, separation, bestScore, bestSeparation, tolSqr, separationTol ) ) { - float score = b3DistanceSquared2( p1, points[j].p ); - // Separation sum heuristic - float separation = points[i].separation + points[j].separation; - - if ( b3IsBetterCullCandidate( score, separation, bestScore, bestSeparation, tolSqr, separationTol ) ) - { - bestIndex1 = i; - bestIndex2 = j; - bestScore = score; - bestSeparation = separation; - } + bestIndex1 = i; + bestIndex2 = j; + bestScore = score; + bestSeparation = separation; } } } @@ -267,7 +340,7 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) { // Choose deepest point int deepestIndex = 0; - for ( int i = 1; i < count; ++i ) + for ( int i = 1; i < count1; ++i ) { if ( points[i].separation < points[deepestIndex].separation ) { @@ -285,7 +358,12 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) finalPoints[0] = points[bestIndex1]; finalPoints[1] = points[bestIndex2]; - if ( count == 2 ) + // Cull + points[bestIndex2] = points[count1 - 1]; + points[bestIndex1] = points[count1 - 2]; + count1 -= 2; + + if ( count1 == 0 ) { points[0] = finalPoints[0]; points[1] = finalPoints[1]; @@ -304,16 +382,10 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) // Step 2: find the point with the maximum triangular area, ties broken by deepest separation bestScore = 0.0f; bestSeparation = FLT_MAX; - int bestIndex3 = B3_NULL_INDEX; + int bestIndex = B3_NULL_INDEX; float bestSignedArea = 0.0f; - for ( int i = 0; i < count; ++i ) + for ( int i = 0; i < count1; ++i ) { - // Skip best points 1 and 2 rather than culling them. This preserves order under octogon culling. - if ( i == bestIndex1 || i == bestIndex2 ) - { - continue; - } - b3Vec2 p = points[i].p; float signedArea = b3Cross2( ba, b3Sub2( p, a ) ); float score = b3AbsFloat( signedArea ); @@ -323,11 +395,11 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) bestSignedArea = signedArea; bestScore = score; bestSeparation = points[i].separation; - bestIndex3 = i; + bestIndex = i; } } - if ( bestIndex3 == B3_NULL_INDEX ) + if ( bestIndex == B3_NULL_INDEX ) { // All points collinear points[0] = finalPoints[0]; @@ -336,9 +408,9 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) } // Store best point - finalPoints[2] = points[bestIndex3]; + finalPoints[2] = points[bestIndex]; - if ( count == 3 ) + if ( count1 == 1 ) { points[0] = finalPoints[0]; points[1] = finalPoints[1]; @@ -346,6 +418,10 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) return 3; } + // Cull + points[bestIndex] = points[count1 - 1]; + count1 -= 1; + // Step 4: get the point that adds the most area outside the current triangle // Third anchor @@ -363,14 +439,9 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) bestScore = 0.0f; bestSeparation = FLT_MAX; - int bestIndex4 = B3_NULL_INDEX; - for ( int i = 0; i < count; ++i ) + bestIndex = B3_NULL_INDEX; + for ( int i = 0; i < count1; ++i ) { - if ( i == bestIndex1 || i == bestIndex2 || i == bestIndex3 ) - { - continue; - } - b3Vec2 p = points[i].p; float u1 = b3Cross2( b3Sub2( p, a ), ba ); float u2 = b3Cross2( b3Sub2( p, b ), cb ); @@ -382,11 +453,11 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) { bestScore = score; bestSeparation = points[i].separation; - bestIndex4 = i; + bestIndex = i; } } - if ( bestIndex4 == B3_NULL_INDEX ) + if ( bestIndex == B3_NULL_INDEX ) { // No additional area points[0] = finalPoints[0]; @@ -396,7 +467,7 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) } // Store best point - finalPoints[3] = points[bestIndex4]; + finalPoints[3] = points[bestIndex]; // Full quad points[0] = finalPoints[0]; @@ -406,155 +477,6 @@ static int b3CullPoints( b3Point2D* points, int count, bool sweep ) return 4; } -// Above this point count it is worth culling interior points prior to the regular culling algorithm. -#define B3_CULL_FILTER_THRESHOLD 64 - -// If the cull filter leaves this many points then fallback to a linear tests for the first to points. -#define B3_CULL_SWEEP_THRESHOLD 256 - -// Drop interior points before computing the farthest two points. This is faster than brute-force O(N^2). -static int b3DropInteriorPoints( b3Point2D* points, int count, float margin ) -{ - int extremes[8] = { 0 }; - float bests[8] = { - points[0].p.x, points[0].p.x + points[0].p.y, points[0].p.y, points[0].p.y - points[0].p.x, - -points[0].p.x, -points[0].p.x - points[0].p.y, -points[0].p.y, points[0].p.x - points[0].p.y, - }; - - // Find the maximum offsets in the octogon. - for ( int i = 1; i < count; ++i ) - { - b3Vec2 p = points[i].p; - float values[8] = { p.x, p.x + p.y, p.y, p.y - p.x, -p.x, -p.x - p.y, -p.y, p.x - p.y }; - for ( int k = 0; k < 8; ++k ) - { - if ( values[k] > bests[k] ) - { - bests[k] = values[k]; - extremes[k] = i; - } - } - } - - // Build 8 planes as an approximate convex hull for culling. - b3Vec2 normals[8]; - float offsets[8]; - int edgeCount = 0; - for ( int k = 0; k < 8; ++k ) - { - b3Vec2 a = points[extremes[k]].p; - b3Vec2 b = points[extremes[( k + 1 ) & 7]].p; - b3Vec2 normal = { a.y - b.y, b.x - a.x }; - float length = b3Length2( normal ); - if ( length == 0.0f ) - { - continue; - } - - normals[edgeCount] = normal; - offsets[edgeCount] = b3Dot2( normal, a ) + margin * length; - edgeCount += 1; - } - - if ( edgeCount < 3 ) - { - return count; - } - - // Cull points. - int keptCount = 0; - for ( int i = 0; i < count; ++i ) - { - b3Vec2 p = points[i].p; - bool interior = true; - for ( int k = 0; k < edgeCount; ++k ) - { - if ( b3Dot2( normals[k], p ) <= offsets[k] ) - { - interior = false; - break; - } - } - - if ( interior == false ) - { - points[keptCount] = points[i]; - keptCount += 1; - } - } - - return keptCount; -} - -#endif - -// Fallback if culling leads to all points separated. Rare. -static void b3KeepDeepestPoint( b3Point2D* kept, int keptCount, const b3LocalManifoldPoint* points, int count, - b3Vec3 origin, b3Vec3 u, b3Vec3 v ) -{ - int deepest = 0; - for ( int i = 1; i < count; ++i ) - { - if ( points[i].separation < points[deepest].separation ) - { - deepest = i; - } - } - - float keptSeparation = FLT_MAX; - for ( int i = 0; i < keptCount; ++i ) - { - if ( kept[i].originalIndex == deepest ) - { - return; - } - - keptSeparation = b3MinFloat( keptSeparation, points[kept[i].originalIndex].separation ); - } - - float separation = points[deepest].separation; - if ( separation <= 0.0f || separation >= keptSeparation - B3_LINEAR_SLOP ) - { - return; - } - - int replaceIndex = 0; - float bestArea = -1.0f; - for ( int candidate = 0; candidate < keptCount; ++candidate ) - { - b3Vec2 ring[B3_MAX_MANIFOLD_POINTS]; - int ringCount = 0; - for ( int i = 0; i < keptCount; ++i ) - { - int index = i == candidate ? deepest : kept[i].originalIndex; - b3Vec3 d = b3Sub( points[index].point, origin ); - ring[ringCount] = (b3Vec2){ b3Dot( d, u ), b3Dot( d, v ) }; - ringCount += 1; - } - - float area = 0.0f; - for ( int i = 0; i < ringCount; ++i ) - { - for ( int j = i + 1; j < ringCount; ++j ) - { - for ( int k = j + 1; k < ringCount; ++k ) - { - float signedArea = b3Cross2( b3Sub2( ring[j], ring[i] ), b3Sub2( ring[k], ring[i] ) ); - area = b3MaxFloat( area, b3AbsFloat( signedArea ) ); - } - } - } - - if ( area > bestArea ) - { - bestArea = area; - replaceIndex = candidate; - } - } - - kept[replaceIndex].originalIndex = deepest; -} - static int b3ReduceCluster( b3LocalManifoldPoint* points, int count1, b3Vec3 normal, b3Arena arena ) { int targetCount = 1; @@ -576,32 +498,13 @@ static int b3ReduceCluster( b3LocalManifoldPoint* points, int count1, b3Vec3 nor pts[i].originalIndex = i; } -#if B3_MAX_MANIFOLD_POINTS == 4 - b3Point2D* hull = pts; - int count2; - if ( count1 <= B3_CULL_FILTER_THRESHOLD ) - { - count2 = b3CullPoints( pts, count1, false ); - } - else - { - // Many points. Reduce point count using bounding octogon. - int keptCount = b3DropInteriorPoints( pts, count1, 0.25f * B3_LINEAR_SLOP ); - count2 = b3CullPoints( pts, keptCount, keptCount > B3_CULL_SWEEP_THRESHOLD ); - } -#else - b3Point2D* hull = b3Bump( &arena, 2 * count1 * sizeof( b3Point2D ) ); - int hullCount = b3Hull2D( pts, count1, hull, 0 ); - int count2 = b3SimplifyHull2D( hull, hullCount, B3_MAX_MANIFOLD_POINTS ); -#endif + int count2 = b3CullPoints( pts, count1 ); B3_ASSERT( count2 <= B3_MAX_MANIFOLD_POINTS ); - b3KeepDeepestPoint( hull, count2, points, count1, origin, u, v ); - b3LocalManifoldPoint finalPoints[B3_MAX_MANIFOLD_POINTS]; for ( int i = 0; i < count2; ++i ) { - int index = hull[i].originalIndex; + int index = pts[i].originalIndex; B3_ASSERT( 0 <= index && index < count1 ); finalPoints[i] = points[index]; } @@ -619,550 +522,36 @@ typedef struct b3Cluster int pointCount; } b3Cluster; -typedef enum b3NeighborResult +bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact, const b3Shape* shapeA, const int* materialMap, + b3WorldTransform xfA, const b3Shape* shapeB, b3WorldTransform xfB, bool isFast, b3Arena arena ) { - // Admit for flat edges. - b3_neighborAdmit, - // Skip for convex edges. - b3_neighborSkip, - // Snap for concave edges. - b3_neighborSnap, - // Drop for a cliff. - b3_neighborDrop, -} b3NeighborResult; + B3_ASSERT( shapeA->type == b3_meshShape || shapeA->type == b3_heightShape ); + B3_UNUSED( workerIndex ); + B3_UNUSED( isFast ); + B3_UNUSED( materialMap ); -// 1.0027 degrees -#define B3_NEIGHBOR_TOLERANCE 0.0175f + b3TaskContext* context = b3Array_Get( world->taskContexts, workerIndex ); -// Cross product of triangle edge with neighbor triangle normal. A vector pointing away from the edge -// in the neighbor triangle plane towards its center. -// tangent = cross(e, n) -static bool b3GetNeighborTangent( const b3Shape* shape, int triangleIndex, const b3Vec3* vertices, - b3Matrix3 meshToLocal, int edgeIndex, b3Vec3* tangent ) -{ - b3Vec3 neighborNormal; - - bool haveNeighbor = b3GetNeighborNormal( shape, triangleIndex, edgeIndex, &neighborNormal ); - if ( haveNeighbor == false ) - { - // Cliff edge axis along negative triangle normal. - *tangent = b3Neg( b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] ) ); - return false; - } - - neighborNormal = b3MulMV( meshToLocal, neighborNormal ); - b3Vec3 edge = b3Normalize( b3Sub( vertices[( edgeIndex + 1 ) % 3], vertices[edgeIndex] ) ); - *tangent = b3Cross( edge, neighborNormal ); - return true; -} - -// Is the normal in the vertex Voronoi region? -static bool b3IsInVertexRegion( const b3Vec3* vertices, int vertexIndex, b3Vec3 normal ) -{ - b3Vec3 vertex = vertices[vertexIndex]; - b3Vec3 next = vertices[vertexIndex < 2 ? vertexIndex + 1 : 0]; - b3Vec3 previous = vertices[vertexIndex > 0 ? vertexIndex - 1 : 2]; - b3Vec3 e1 = b3Sub( next, vertex ); - b3Vec3 e2 = b3Sub( previous, vertex ); - return b3Dot( normal, e1 ) <= 0.0f && b3Dot( normal, e2 ) <= 0.0f; -} - -// This is used to avoid ghost collisions at vertices. It is called rarely. -// trees25 : 2.6% -// mesh_drop : 0.04% -static bool b3IsInVertexCone( const b3Shape* shape, int triangleIndex, int vertexIndex, b3Matrix3 meshToLocal, - b3Vec3 normal ) -{ - b3Vec3 meshNormal = b3MulMV( b3Transpose( meshToLocal ), normal ); - float tolerance = B3_NEIGHBOR_TOLERANCE; - - if ( shape->type == b3_meshShape ) - { - return b3IsInMeshVertexRing( &shape->mesh, triangleIndex, vertexIndex, meshNormal, tolerance ); - } - - B3_ASSERT( shape->type == b3_heightShape ); - float toleranceSquared = tolerance * tolerance; - - b3Triangle triangle = b3GetHeightFieldTriangle( shape->heightField, triangleIndex ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - int vertex = indices[vertexIndex]; - - int fanTriangles[6]; - int fanCount = b3GetHeightFieldVertexTriangles( shape->heightField, vertex, fanTriangles ); - - for ( int i = 0; i < fanCount; ++i ) - { - int fanIndex = fanTriangles[i]; - b3Triangle fan = b3GetHeightFieldTriangle( shape->heightField, fanIndex ); - int fanIndices[3] = { fan.i1, fan.i2, fan.i3 }; - int k = fanIndices[0] == vertex ? 0 : ( fanIndices[1] == vertex ? 1 : 2 ); - B3_ASSERT( fanIndices[k] == vertex ); - - int next = k < 2 ? k + 1 : 0; - int previous = k > 0 ? k - 1 : 2; - b3Vec3 edges[2] = { b3Sub( fan.vertices[next], fan.vertices[k] ), - b3Sub( fan.vertices[previous], fan.vertices[k] ) }; - int edgeIndices[2] = { k, previous }; - - for ( int j = 0; j < 2; ++j ) - { - float lean = b3Dot( meshNormal, edges[j] ); - if ( lean > 0.0f && lean * lean > toleranceSquared * b3LengthSquared( edges[j] ) ) - { - return false; - } - - b3Vec3 neighborNormal; - if ( b3GetNeighborNormal( shape, fanIndex, edgeIndices[j], &neighborNormal ) == false ) - { - // Cliff at boundary or hole. - b3Vec3 fanNormal = b3MakeNormalFromPoints( fan.vertices[0], fan.vertices[1], fan.vertices[2] ); - if ( b3Dot( meshNormal, fanNormal ) < -tolerance ) - { - return false; - } - } - } - } - - return true; -} - -// Check the vertex flags to determined if this normal is admissible. -static bool b3AdmitsVertexNormal( const b3Shape* shape, int triangleIndex, const b3Vec3* vertices, int vertexIndex, - b3Matrix3 meshToLocal, b3Vec3 normal ) -{ - if ( b3IsInVertexRegion( vertices, vertexIndex, normal ) == false ) - { - // Not in the vertex region so this vertex cannot admit the normal. - return false; - } - - if ( b3IsConvexVertex( shape, triangleIndex, vertexIndex ) == false ) - { - return false; - } - - return b3IsInVertexCone( shape, triangleIndex, vertexIndex, meshToLocal, normal ); -} - -// Voronoi test of an edge or vertex normal against the neighbor normals. -static b3NeighborResult b3TestNeighbors( const b3Shape* shape, int triangleIndex, const b3Vec3* vertices, - b3Matrix3 meshToLocal, b3TriangleFeature feature, b3Vec3 candidateNormal, - int* ownerEdge ) -{ - *ownerEdge = B3_NULL_INDEX; - - int edges[2] = { 0, 0 }; - int edgeCount = 1; - int vertexIndex = B3_NULL_INDEX; - - switch ( feature ) - { - case b3_featureEdge1: - edges[0] = 0; - break; - - case b3_featureEdge2: - edges[0] = 1; - break; - - case b3_featureEdge3: - edges[0] = 2; - break; - - case b3_featureVertex1: - edges[0] = 0; - edges[1] = 2; - edgeCount = 2; - vertexIndex = 0; - break; - - case b3_featureVertex2: - edges[0] = 0; - edges[1] = 1; - edgeCount = 2; - vertexIndex = 1; - break; - - case b3_featureVertex3: - edges[0] = 1; - edges[1] = 2; - edgeCount = 2; - vertexIndex = 2; - break; - - default: - return b3_neighborAdmit; - } - - b3Vec3 triangleNormal = b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] ); - float tolerance = B3_NEIGHBOR_TOLERANCE; - bool admit = true; - bool convex = false; - - for ( int i = 0; i < edgeCount; ++i ) - { - // neighborTangent = cross(edgeAxis, neighborTriangleNormal) - b3Vec3 neighborTangent; - bool haveNeighbor = - b3GetNeighborTangent( shape, triangleIndex, vertices, meshToLocal, edges[i], &neighborTangent ); - - // Does the candidate normal lean into the neighbor's face region? - bool admitted = b3Dot( candidateNormal, neighborTangent ) <= tolerance; - if ( admitted == false && haveNeighbor && *ownerEdge == B3_NULL_INDEX ) - { - *ownerEdge = edges[i]; - } - - admit = admit && admitted; - - // Convex if at least one edge is convex. - convex = convex || b3Dot( triangleNormal, neighborTangent ) < -tolerance; - } - - if ( admit ) - { - if ( vertexIndex == B3_NULL_INDEX || - b3IsInVertexCone( shape, triangleIndex, vertexIndex, meshToLocal, candidateNormal ) ) - { - return b3_neighborAdmit; - } - - bool inVertexRegion = b3IsInVertexRegion( vertices, vertexIndex, candidateNormal ); - return inVertexRegion ? b3_neighborSkip : b3_neighborSnap; - } - - // Check vertex area first to avoid a saddle tunnel. - if ( vertexIndex != B3_NULL_INDEX && b3IsInVertexRegion( vertices, vertexIndex, candidateNormal ) && - b3IsInVertexCone( shape, triangleIndex, vertexIndex, meshToLocal, candidateNormal ) ) - { - return b3_neighborAdmit; - } - - if ( convex ) - { - // Edge is convex. Drop for a cliff with no deep consideration. - return *ownerEdge == B3_NULL_INDEX ? b3_neighborDrop : b3_neighborSkip; - } - - return b3_neighborSnap; -} - -// Classify a clipped hull point relative to the triangle features. ORs into the vertex and edge masks. -// Returns false if the point isn't close to an edge or vertex. -static bool b3ClassifyHullFacePoint( const b3Vec3* vertices, b3Vec3 triangleNormal, b3Vec3 point, b3FeaturePair pair, - int* vertexMask, int* edgeMask ) -{ - B3_ASSERT( pair.owner1 != pair.owner2 || pair.index1 != pair.index2 ); - - float linearSlop = B3_LINEAR_SLOP; - - int edges[3]; - int edgeCount = 0; - if ( pair.owner1 == b3_featureShapeA ) - { - edges[edgeCount] = pair.index1; - edgeCount += 1; - } - - if ( pair.owner2 == b3_featureShapeA && ( edgeCount == 0 || pair.index2 != edges[0] ) ) - { - edges[edgeCount] = pair.index2; - edgeCount += 1; - } - - if ( edgeCount == 0 ) - { - // Close to an edge? - for ( int i = 0; i < 3; ++i ) - { - b3Vec3 vertex = vertices[i]; - b3Vec3 edge = b3Normalize( b3Sub( vertices[i < 2 ? i + 1 : 0], vertex ) ); - b3Vec3 inwardTangent = b3Cross( triangleNormal, edge ); - if ( b3Dot( inwardTangent, b3Sub( point, vertex ) ) <= linearSlop ) - { - edges[edgeCount] = i; - edgeCount += 1; - } - } - } - - if ( edgeCount == 0 || edgeCount == 3 ) - { - // Not close to any triangle edge or triangle is very small. - return false; - } - - if ( edgeCount == 2 ) - { - // Close to two edges, mask the shared vertex. - int a = edges[0]; - int b = edges[1]; - int vertex = ( a < 2 ? a + 1 : 0 ) == b ? b : a; - *vertexMask |= 1 << vertex; - return true; - } - - B3_ASSERT( edgeCount == 1 ); - - // Close to only one edge. Determine if it should be classified as a vertex or edge point. - int edge = edges[0]; - int next = edge < 2 ? edge + 1 : 0; - if ( b3DistanceSquared( point, vertices[edge] ) <= linearSlop * linearSlop ) - { - *vertexMask |= 1 << edge; - } - else if ( b3DistanceSquared( point, vertices[next] ) <= linearSlop * linearSlop ) - { - *vertexMask |= 1 << next; - } - else - { - *edgeMask |= 1 << edge; - } - - return true; -} - -static inline bool b3IsSubset( int mask, int allowed ) -{ - return ( mask & ~allowed ) == 0; -} - -// Voronoi test of neighbors based on deepest point. -// Ghost collisions arise when the chose manifold normal does not align with what GJK would give with slight separation. -// A non-ghosting normal must be within the Voronoi regions the triangles face, edges, and vertices. However, even -// normals within the Voronoi regions can ghost. So we use the deepest point as a proxy for what GJK would yield with -// slight separation. -static b3NeighborResult b3TestHullFaceNeighbors( const b3Shape* shape, int triangleIndex, const b3Vec3* vertices, - b3Matrix3 meshToLocal, const b3LocalManifold* manifold, - b3TriangleFeature* nearFeature ) -{ - *nearFeature = b3_featureNone; - b3Vec3 normal = manifold->normal; - b3Vec3 triangleNormal = b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] ); - float tolerance = B3_NEIGHBOR_TOLERANCE; - float cosAngle = b3Dot( normal, triangleNormal ); - if ( cosAngle > 0.0f && cosAngle * cosAngle >= 1.0f - tolerance * tolerance ) - { - // Face normal (flipped to point from A to B) is parallel to triangle normal. - return b3_neighborAdmit; - } - - float minSeparation = manifold->points[0].separation; - for ( int i = 1; i < manifold->pointCount; ++i ) - { - minSeparation = b3MinFloat( minSeparation, manifold->points[i].separation ); - } - - // Determine if the overlapped points are on the triangle face or boundary. Classify - // considering all points within slop of deepest point. - float depthLimit = minSeparation + B3_LINEAR_SLOP; - int vertexMask = 0; - int edgeMask = 0; - bool onFace = false; - for ( int i = 0; i < manifold->pointCount; ++i ) - { - const b3LocalManifoldPoint* manifoldPoint = manifold->points + i; - if ( manifoldPoint->separation > depthLimit ) - { - continue; - } - - // Clip points were moved onto the hull face, step back along the normal to the triangle. - b3Vec3 point = b3MulSub( manifoldPoint->point, manifoldPoint->separation, normal ); - bool onBoundary = - b3ClassifyHullFacePoint( vertices, triangleNormal, point, manifoldPoint->pair, &vertexMask, &edgeMask ); - - onFace = onFace || onBoundary == false; - } - - b3TriangleFeature vertexFeatures[3] = { b3_featureVertex1, b3_featureVertex2, b3_featureVertex3 }; - b3TriangleFeature edgeFeatures[3] = { b3_featureEdge1, b3_featureEdge2, b3_featureEdge3 }; - - // If the hull overlaps this triangle then determine if a deepest point is close to a vertex. - if ( minSeparation < 0.0f ) - { - for ( int i = 0; i < 3; ++i ) - { - if ( ( vertexMask & ( 1 << i ) ) == 0 ) - { - continue; - } - - bool admit = b3AdmitsVertexNormal( shape, triangleIndex, vertices, i, meshToLocal, normal ); - if ( admit ) - { - // This vertex tentatively accepts the normal. - *nearFeature = vertexFeatures[i]; - return b3_neighborAdmit; - } - } - } - - if ( onFace ) - { - // A tilted hull face over the triangle interior, the triangle face owns the normal. - return b3_neighborSnap; - } - - B3_ASSERT( edgeMask != 0 || vertexMask != 0 ); - - b3TriangleFeature feature = b3_featureNone; - int edges[2] = { 0, 0 }; - int edgeCount = 0; - - // Is the contact point close to only one vertex? - if ( edgeMask == 0 && vertexMask != 0 && ( vertexMask & ( vertexMask - 1 ) ) == 0 ) - { - int vertex = vertexMask == 1 ? 0 : ( vertexMask == 2 ? 1 : 2 ); - feature = vertexFeatures[vertex]; - edges[0] = vertex; - edges[1] = vertex > 0 ? vertex - 1 : 2; - edgeCount = 2; - } - else - { - // Is the contact point close to an edge - for ( int i = 0; i < 3; ++i ) - { - int next = i < 2 ? i + 1 : 0; - int edgeBit = 1 << i; - int vertexBits = ( 1 << i ) | ( 1 << next ); - - // Is this edge and its vertices a subset? One mask can be zero and always a subset. - if ( b3IsSubset( edgeMask, edgeBit ) && b3IsSubset( vertexMask, vertexBits ) ) - { - feature = edgeFeatures[i]; - edges[0] = i; - edgeCount = 1; - break; - } - } - } - - if ( feature == b3_featureNone ) - { - return b3_neighborSnap; - } - - for ( int i = 0; i < edgeCount; ++i ) - { - int edgeIndex = edges[i]; - b3Vec3 vertex = vertices[edgeIndex]; - b3Vec3 edge = b3Normalize( b3Sub( vertices[edgeIndex < 2 ? edgeIndex + 1 : 0], vertex ) ); - b3Vec3 inwardTangent = b3Cross( triangleNormal, edge ); - - // An edge or vertex normal cone tilts outward from the triangle and an edge cone is perpendicular to the - // edge, a hull face normal need be neither. - if ( b3Dot( normal, inwardTangent ) > tolerance ) - { - return b3_neighborSnap; - } - - if ( edgeCount == 1 && b3AbsFloat( b3Dot( normal, edge ) ) > tolerance ) - { - return b3_neighborSnap; - } - } - - *nearFeature = feature; - - // Never skip a hull face, its normal can miss the whole vertex cone so every triangle would - // skip, the face contact is empty when the hull is off this triangle. - int ownerEdge; - b3NeighborResult result = - b3TestNeighbors( shape, triangleIndex, vertices, meshToLocal, feature, normal, &ownerEdge ); - return result == b3_neighborSkip || result == b3_neighborDrop ? b3_neighborSnap : result; -} - -// Special handling if a boundary collision drops all points. Rare. -static void b3CollideBoundaryEdge( b3LocalManifold* manifold, const b3Shape* shapeA, int triangleIndex, - const b3Vec3* vertices, b3Matrix3 meshToLocal, const b3HullData* hull, - float speculativeDistance ) -{ - float linearSlop = B3_LINEAR_SLOP; - - b3DistanceInput input = { 0 }; - input.proxyA = (b3ShapeProxy){ vertices, 3, 0.0f }; - input.proxyB = (b3ShapeProxy){ b3GetHullPoints( hull ), hull->vertexCount, 0.0f }; - input.transform = b3Transform_identity; - input.useRadii = false; - b3SimplexCache simplexCache = { 0 }; - b3DistanceOutput output = b3ShapeDistance( &input, &simplexCache, NULL, 0 ); - - if ( output.distance < B3_OVERLAP_SLOP || output.distance > speculativeDistance ) - { - return; - } - - float tolerance = 0.01f * linearSlop; - b3TriangleFeature feature = b3_featureNone; - bool onBoundary = false; - b3TriangleFeature vertexFeatures[] = { b3_featureVertex1, b3_featureVertex2, b3_featureVertex3 }; - b3TriangleFeature edgeFeatures[] = { b3_featureEdge1, b3_featureEdge2, b3_featureEdge3 }; - for ( int i = 0; i < 3; ++i ) - { - b3Vec3 a = vertices[i]; - b3Vec3 e = b3Sub( vertices[i < 2 ? i + 1 : 0], a ); - float t = b3ClampFloat( b3Dot( b3Sub( output.pointA, a ), e ) / b3LengthSquared( e ), 0.0f, 1.0f ); - b3Vec3 closest = b3MulAdd( a, t, e ); - if ( b3DistanceSquared( closest, output.pointA ) >= tolerance * tolerance ) - { - continue; - } - - b3Vec3 neighborNormal; - onBoundary = onBoundary || b3GetNeighborNormal( shapeA, triangleIndex, i, &neighborNormal ) == false; - - if ( b3DistanceSquared( a, output.pointA ) < tolerance * tolerance ) - { - feature = vertexFeatures[i]; - } - else if ( b3DistanceSquared( b3Add( a, e ), output.pointA ) < tolerance * tolerance ) - { - feature = vertexFeatures[i < 2 ? i + 1 : 0]; - } - else if ( feature == b3_featureNone ) - { - feature = edgeFeatures[i]; - } - } - - if ( onBoundary == false || feature == b3_featureNone ) - { - return; - } - - int ownerEdge; - if ( b3TestNeighbors( shapeA, triangleIndex, vertices, meshToLocal, feature, output.normal, &ownerEdge ) != - b3_neighborAdmit ) - { - return; - } - - b3LocalManifoldPoint* point = manifold->points + 0; - point->point = b3Lerp( output.pointA, output.pointB, 0.5f ); - point->separation = output.distance; - point->pair = b3MakeFeaturePair( b3_featureShapeA, (int)feature, b3_featureShapeA, (int)feature ); - manifold->normal = output.normal; - manifold->pointCount = 1; - manifold->feature = feature; -} - -static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shapeA, const b3Shape* shapeB, - b3Transform transformAtoB, b3TriangleCache* triangleCaches, int triangleCount, - bool enableSpeculative, bool handleGhosts, bool isFast, int manifoldCapacity, - b3TaskContext* context, b3Arena* arena ) -{ - *clustersOut = NULL; + b3RefreshCache( contact, shapeA, xfA, &shapeB->aabb ); // Collide with triangles and build manifolds - b3LocalManifold** acceptedManifolds = b3Bump( arena, triangleCount * sizeof( b3LocalManifold* ) ); - int acceptedManifoldCount = 0; + b3MeshContact* meshContact = &contact->meshContact; + int triangleCount = meshContact->triangleCache.count; + b3LocalManifold** acceptedManifolds = b3Bump( &arena, triangleCount * sizeof( b3LocalManifold* ) ); + int acceptedManifoldCount = 0; + b3LocalManifold** tentativeManifolds = b3Bump( &arena, triangleCount * sizeof( b3LocalManifold* ) ); + int tentativeManifoldCount = 0; + b3TentativeTriangle* tentativeTriangles = b3Bump( &arena, triangleCount * sizeof( b3TentativeTriangle ) ); + int tentativeTriangleCount = 0; + + b3FoundEdges foundEdges; + b3FoundVertices foundVertices; + foundEdges.count = 0; + foundVertices.count = 0; + + // This transform converts from mesh frame into the shapeB frame + b3Transform transformAtoB = b3InvMulWorldTransforms( xfB, xfA ); b3Matrix3 relativeMatrix = b3MakeMatrixFromQuat( transformAtoB.q ); float linearSlop = B3_LINEAR_SLOP; @@ -1173,314 +562,75 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape // collision, especially for hull versus mesh. float restOffset = B3_MESH_REST_OFFSET; + // Make room for clip points + int pointBufferCapacity = B3_MAX_POINTS_PER_TRIANGLE * triangleCount; + + b3LocalManifoldPoint* pointBuffer = b3Bump( &arena, pointBufferCapacity * sizeof( b3LocalManifoldPoint ) ); + int totalPointCount = 0; + + b3LocalManifold* manifoldBuffer = b3Bump( &arena, triangleCount * sizeof( b3LocalManifold ) ); + int manifoldCount = 0; + + b3TriangleCache* triangleCaches = meshContact->triangleCache.data; + const b3HullData* hullB = shapeB->type == b3_hullShape ? shapeB->hull : NULL; - float hullSpeculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : restOffset; - b3Vec3 hullMargin = { hullSpeculativeDistance, hullSpeculativeDistance, hullSpeculativeDistance }; - int* survivorIndices = b3Bump( arena, triangleCount * sizeof( int ) ); - b3Vec3* survivorVertices = b3Bump( arena, 3 * triangleCount * sizeof( b3Vec3 ) ); - int survivorCount = 0; - - const b3MeshTriangle* meshTriangles = NULL; - const b3Vec3* meshVertices = NULL; - b3Vec3 meshScale = b3Vec3_one; - bool meshFlipped = false; - bool unitScale = true; - if ( shapeA->type == b3_meshShape ) + for ( int index = 0; index < triangleCount && totalPointCount + 3 < pointBufferCapacity; ++index ) { - meshTriangles = b3GetMeshTriangles( shapeA->mesh.data ); - meshVertices = b3GetMeshVertices( shapeA->mesh.data ); - meshScale = shapeA->mesh.scale; - meshFlipped = meshScale.x * meshScale.y * meshScale.z < 0.0f; - unitScale = meshScale.x == 1.0f && meshScale.y == 1.0f && meshScale.z == 1.0f; - } + int triangleIndex = triangleCaches[index].triangleIndex; - b3FloatW4 cxx = b3SplatW4( relativeMatrix.cx.x ); - b3FloatW4 cxy = b3SplatW4( relativeMatrix.cx.y ); - b3FloatW4 cxz = b3SplatW4( relativeMatrix.cx.z ); - b3FloatW4 cyx = b3SplatW4( relativeMatrix.cy.x ); - b3FloatW4 cyy = b3SplatW4( relativeMatrix.cy.y ); - b3FloatW4 cyz = b3SplatW4( relativeMatrix.cy.z ); - b3FloatW4 czx = b3SplatW4( relativeMatrix.cz.x ); - b3FloatW4 czy = b3SplatW4( relativeMatrix.cz.y ); - b3FloatW4 czz = b3SplatW4( relativeMatrix.cz.z ); - b3FloatW4 px = b3SplatW4( transformAtoB.p.x ); - b3FloatW4 py = b3SplatW4( transformAtoB.p.y ); - b3FloatW4 pz = b3SplatW4( transformAtoB.p.z ); - - b3FloatW4 marginW = b3SplatW4( hullMargin.x ); - b3AABB hullBounds = hullB != NULL ? hullB->aabb : (b3AABB){ 0 }; - b3FloatW4 hullLowerX = b3SplatW4( hullBounds.lowerBound.x ); - b3FloatW4 hullLowerY = b3SplatW4( hullBounds.lowerBound.y ); - b3FloatW4 hullLowerZ = b3SplatW4( hullBounds.lowerBound.z ); - b3FloatW4 hullUpperX = b3SplatW4( hullBounds.upperBound.x ); - b3FloatW4 hullUpperY = b3SplatW4( hullBounds.upperBound.y ); - b3FloatW4 hullUpperZ = b3SplatW4( hullBounds.upperBound.z ); - - for ( int baseIndex = 0; baseIndex < triangleCount; baseIndex += 4 ) - { - int laneCount = b3MinInt( 4, triangleCount - baseIndex ); - - b3Vec3 lanes[3][4]; - for ( int lane = 0; lane < 4; ++lane ) + b3Triangle triangle; + if ( shapeA->type == b3_meshShape ) { - int index = baseIndex + b3MinInt( lane, laneCount - 1 ); - int triangleIndex = triangleCaches[index].triangleIndex; - - if ( meshVertices != NULL ) - { - b3MeshTriangle meshTriangle = meshTriangles[triangleIndex]; - b3Vec3 v1 = meshVertices[meshTriangle.index1]; - b3Vec3 v2 = meshVertices[meshFlipped ? meshTriangle.index3 : meshTriangle.index2]; - b3Vec3 v3 = meshVertices[meshFlipped ? meshTriangle.index2 : meshTriangle.index3]; - - // This bool gets predicted, so worth it. - if ( unitScale == false ) - { - v1 = b3Mul( meshScale, v1 ); - v2 = b3Mul( meshScale, v2 ); - v3 = b3Mul( meshScale, v3 ); - } - - lanes[0][lane] = v1; - lanes[1][lane] = v2; - lanes[2][lane] = v3; - } - else - { - B3_ASSERT( shapeA->type == b3_heightShape ); - b3Triangle triangle = b3GetHeightFieldTriangle( shapeA->heightField, triangleIndex ); - lanes[0][lane] = triangle.vertices[0]; - lanes[1][lane] = triangle.vertices[1]; - lanes[2][lane] = triangle.vertices[2]; - } + triangle = b3GetMeshTriangle( &shapeA->mesh, triangleIndex ); + } + else + { + B3_ASSERT( shapeA->type == b3_heightShape ); + triangle = b3GetHeightFieldTriangle( shapeA->heightField, triangleIndex ); } // Transform triangle into the shape frame - b3FloatW4 vx[3], vy[3], vz[3]; - for ( int k = 0; k < 3; ++k ) - { - b3FloatW4 ax = b3SetW4( lanes[k][0].x, lanes[k][1].x, lanes[k][2].x, lanes[k][3].x ); - b3FloatW4 ay = b3SetW4( lanes[k][0].y, lanes[k][1].y, lanes[k][2].y, lanes[k][3].y ); - b3FloatW4 az = b3SetW4( lanes[k][0].z, lanes[k][1].z, lanes[k][2].z, lanes[k][3].z ); - - vx[k] = b3AddW4( b3AddW4( b3AddW4( b3MulW4( cxx, ax ), b3MulW4( cyx, ay ) ), b3MulW4( czx, az ) ), px ); - vy[k] = b3AddW4( b3AddW4( b3AddW4( b3MulW4( cxy, ax ), b3MulW4( cyy, ay ) ), b3MulW4( czy, az ) ), py ); - vz[k] = b3AddW4( b3AddW4( b3AddW4( b3MulW4( cxz, ax ), b3MulW4( cyz, ay ) ), b3MulW4( czz, az ) ), pz ); - } - - uint32_t keepMask = ( 1u << laneCount ) - 1u; - if ( hullB != NULL ) - { - b3FloatW4 lowerX = b3SubW4( b3MinW4( vx[0], b3MinW4( vx[1], vx[2] ) ), marginW ); - b3FloatW4 lowerY = b3SubW4( b3MinW4( vy[0], b3MinW4( vy[1], vy[2] ) ), marginW ); - b3FloatW4 lowerZ = b3SubW4( b3MinW4( vz[0], b3MinW4( vz[1], vz[2] ) ), marginW ); - b3FloatW4 upperX = b3AddW4( b3MaxW4( vx[0], b3MaxW4( vx[1], vx[2] ) ), marginW ); - b3FloatW4 upperY = b3AddW4( b3MaxW4( vy[0], b3MaxW4( vy[1], vy[2] ) ), marginW ); - b3FloatW4 upperZ = b3AddW4( b3MaxW4( vz[0], b3MaxW4( vz[1], vz[2] ) ), marginW ); - - b3FloatW4 separated = b3OrW4( b3LessThanW4( upperX, hullLowerX ), b3GreaterThanW4( lowerX, hullUpperX ) ); - separated = b3OrW4( separated, - b3OrW4( b3LessThanW4( upperY, hullLowerY ), b3GreaterThanW4( lowerY, hullUpperY ) ) ); - separated = b3OrW4( separated, - b3OrW4( b3LessThanW4( upperZ, hullLowerZ ), b3GreaterThanW4( lowerZ, hullUpperZ ) ) ); - - uint32_t cullMask = keepMask & (uint32_t)b3MoveMaskW4( separated ); - keepMask &= ~cullMask; - - while ( cullMask != 0 ) - { - uint32_t lane = b3CTZ32( cullMask ); - cullMask &= cullMask - 1u; - triangleCaches[baseIndex + (int)lane].cache.satCache = (b3SATCache){ 0 }; - } - } - - if ( keepMask == 0 ) - { - continue; - } - - float x[3][4], y[3][4], z[3][4]; - for ( int k = 0; k < 3; ++k ) - { - b3StoreW4( x[k], vx[k] ); - b3StoreW4( y[k], vy[k] ); - b3StoreW4( z[k], vz[k] ); - } - - while ( keepMask != 0 ) - { - uint32_t lane = b3CTZ32( keepMask ); - keepMask &= keepMask - 1u; - - b3Vec3* survivor = survivorVertices + 3 * survivorCount; - survivor[0] = (b3Vec3){ x[0][lane], y[0][lane], z[0][lane] }; - survivor[1] = (b3Vec3){ x[1][lane], y[1][lane], z[1][lane] }; - survivor[2] = (b3Vec3){ x[2][lane], y[2][lane], z[2][lane] }; - survivorIndices[survivorCount] = baseIndex + (int)lane; - survivorCount += 1; - } - } - - if ( survivorCount == 0 ) - { - return 0; - } - - // Make room for clip points. Additional capacity for a heavy clip. - int pointBufferCapacity = B3_MAX_POINTS_PER_TRIANGLE * survivorCount + 2 * B3_MAX_CLIP_POINTS; - - b3LocalManifoldPoint* pointBuffer = b3Bump( arena, pointBufferCapacity * sizeof( b3LocalManifoldPoint ) ); - int totalPointCount = 0; - - b3LocalManifold* manifoldBuffer = b3Bump( arena, survivorCount * sizeof( b3LocalManifold ) ); - int manifoldCount = 0; - - int* survivorManifolds = b3Bump( arena, survivorCount * sizeof( int ) ); - memset( survivorManifolds, 0xFF, survivorCount * sizeof( int ) ); - - for ( int survivorIndex = 0; survivorIndex < survivorCount && totalPointCount + 3 < pointBufferCapacity; - ++survivorIndex ) - { - int index = survivorIndices[survivorIndex]; - int triangleIndex = triangleCaches[index].triangleIndex; - const b3Vec3* vertices = survivorVertices + 3 * survivorIndex; + b3Vec3 vertices[3]; + vertices[0] = b3Add( b3MulMV( relativeMatrix, triangle.vertices[0] ), transformAtoB.p ); + vertices[1] = b3Add( b3MulMV( relativeMatrix, triangle.vertices[1] ), transformAtoB.p ); + vertices[2] = b3Add( b3MulMV( relativeMatrix, triangle.vertices[2] ), transformAtoB.p ); b3ContactCache* cache = &triangleCaches[index].cache; int pointCapacity = pointBufferCapacity - totalPointCount; b3LocalManifold* manifold = manifoldBuffer + manifoldCount; manifold->points = pointBuffer + totalPointCount; manifold->pointCount = 0; + manifold->triangleFlags = triangle.flags; manifold->feature = b3_featureNone; switch ( shapeB->type ) { case b3_capsuleShape: - b3CollideTriangleAndCapsule( manifold, pointCapacity, vertices, &shapeB->capsule, - &cache->simplexCache ); + b3CollideCapsuleAndTriangle( manifold, pointCapacity, &shapeB->capsule, vertices, &cache->simplexCache ); break; case b3_hullShape: - // Cached edge contact is dangerous at high speed because the hull can rotate around - // the edge and tunnel through the triangle. + // Cached edge contact is dangerous at high speed because the hull can rotate around the edge and tunnel + // through the triangle. if ( isFast && cache->satCache.type == b3_edgePairAxis ) { cache->satCache = (b3SATCache){ 0 }; } - b3CollideTriangleAndHull( manifold, pointCapacity, vertices[0], vertices[1], vertices[2], hullB, - &cache->satCache, enableSpeculative ); - if ( context != NULL ) - { - context->satCallCount += 1; - context->satCacheHitCount += cache->satCache.hit; - } + b3CollideHullAndTriangle( manifold, pointCapacity, hullB, vertices[0], vertices[1], vertices[2], + triangle.flags, &cache->satCache ); + context->satCallCount += 1; + context->satCacheHitCount += cache->satCache.hit; break; case b3_sphereShape: - b3CollideTriangleAndSphere( manifold, pointCapacity, vertices, &shapeB->sphere ); + b3CollideSphereAndTriangle( manifold, pointCapacity, &shapeB->sphere, vertices ); break; default: B3_ASSERT( false ); - return 0; - } - - b3TriangleFeature nearFeature = manifold->feature; - b3NeighborResult result = b3_neighborAdmit; - int ownerEdge = B3_NULL_INDEX; - uint8_t meshFlags = manifold->feature == b3_featureHullFace ? b3_meshContactHullFace : 0; - if ( handleGhosts && manifold->pointCount > 0 && manifold->feature != b3_featureTriangleFace ) - { - if ( manifold->feature == b3_featureHullFace ) - { - result = - b3TestHullFaceNeighbors( shapeA, triangleIndex, vertices, relativeMatrix, manifold, &nearFeature ); - } - else - { - result = b3TestNeighbors( shapeA, triangleIndex, vertices, relativeMatrix, manifold->feature, - manifold->normal, &ownerEdge ); - } - - // Check deep overlap before skipping. - if ( result == b3_neighborSkip ) - { - bool deep = false; - for ( int i = 0; i < manifold->pointCount; ++i ) - { - if ( manifold->points[i].separation < -2.0f * linearSlop ) - { - deep = true; - break; - } - } - - if ( deep ) - { - meshFlags |= b3_meshContactDeep; - - // Handle deep overlap. - if ( shapeB->type == b3_sphereShape ) - { - // No way to snap a deep sphere normal. - b3Vec3 neighborNormal; - if ( ownerEdge != B3_NULL_INDEX && - b3GetNeighborNormal( shapeA, triangleIndex, ownerEdge, &neighborNormal ) ) - { - neighborNormal = b3MulMV( relativeMatrix, neighborNormal ); - float neighborSeparation = - b3Dot( neighborNormal, b3Sub( shapeB->sphere.center, vertices[ownerEdge] ) ); - if ( neighborSeparation < 0.0f ) - { - // Neighbor would cull, so better keep this one. - result = b3_neighborAdmit; - } - } - } - else - { - // In deep overlap the owning neighbor may apply backside culling. Experiments show that in this - // case the neighbor should snap the normal. - result = b3_neighborSnap; - } - } - } - - if ( result == b3_neighborSnap ) - { - meshFlags |= b3_meshContactSnapped; - } - - float rawSeparation = FLT_MAX; - for ( int i = 0; i < manifold->pointCount; ++i ) - { - rawSeparation = b3MinFloat( rawSeparation, manifold->points[i].separation ); - } - - if ( result == b3_neighborSkip || result == b3_neighborSnap || result == b3_neighborDrop ) - { - // Skip leaves the normal to the neighbor. A sphere off the face cannot snap. - manifold->pointCount = 0; - } - - if ( result == b3_neighborSnap && shapeB->type == b3_capsuleShape ) - { - // Snap clips the segment to the triangle for a face contact. May clip all points. - b3Plane plane = b3MakePlaneFromPoints( vertices[0], vertices[1], vertices[2] ); - b3BuildTriangleAndCapsuleFaceContact( manifold, vertices, plane, &shapeB->capsule ); - } - else if ( result == b3_neighborSnap && shapeB->type == b3_hullShape ) - { - b3BuildTriangleAndHullFaceContact( manifold, pointCapacity, vertices, hullB, &cache->satCache, - enableSpeculative ); - if ( rawSeparation > 0.0f ) - { - b3CollideBoundaryEdge( manifold, shapeA, triangleIndex, vertices, relativeMatrix, hullB, - hullSpeculativeDistance ); - } - } + return false; } int manifoldPointCount = manifold->pointCount; @@ -1489,96 +639,195 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape { B3_ASSERT( manifold->feature != b3_featureNone ); - b3TriangleFeature pointFeature = manifold->feature; - if ( pointFeature == b3_featureHullFace && nearFeature != b3_featureHullFace && - nearFeature != b3_featureNone ) - { - pointFeature = nearFeature; - } - else if ( pointFeature == b3_featureHullFace && nearFeature == b3_featureNone && - result == b3_neighborAdmit ) - { - pointFeature = b3_featureTriangleFace; - } - - for ( int i = 0; i < manifoldPointCount; ++i ) - { - manifold->points[i].triangleFeature = (uint8_t)pointFeature; - manifold->points[i].meshFlags = meshFlags; - } - - manifold->triangleIndex = triangleIndex; - manifold->triangleNormal = b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] ); - - survivorManifolds[survivorIndex] = manifoldCount; manifoldCount += 1; totalPointCount += manifoldPointCount; + manifold->triangleIndex = triangleIndex; + manifold->triangleNormal = b3MakeNormalFromPoints( vertices[0], vertices[1], vertices[2] ); + manifold->i1 = triangle.i1; + manifold->i2 = triangle.i2; + manifold->i3 = triangle.i3; + + if ( manifold->feature == b3_featureTriangleFace || B3_FORCE_GHOST_COLLISIONS ) + { + (void)b3AddEdge( &foundEdges, triangle.i1, triangle.i2 ); + (void)b3AddEdge( &foundEdges, triangle.i2, triangle.i3 ); + (void)b3AddEdge( &foundEdges, triangle.i3, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i2 ); + (void)b3AddVertex( &foundVertices, triangle.i3 ); + + acceptedManifolds[acceptedManifoldCount++] = manifold; + } + else if ( manifold->feature == b3_featureHullFace ) + { + float cosNormalAngle = b3Dot( manifold->triangleNormal, manifold->normal ); + if ( cosNormalAngle > 0.5f ) + { + (void)b3AddEdge( &foundEdges, triangle.i1, triangle.i2 ); + (void)b3AddEdge( &foundEdges, triangle.i2, triangle.i3 ); + (void)b3AddEdge( &foundEdges, triangle.i3, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i2 ); + (void)b3AddVertex( &foundVertices, triangle.i3 ); + + acceptedManifolds[acceptedManifoldCount++] = manifold; + } + else + { + float minSeparation = manifold->points[0].separation; + for ( int i = 1; i < manifoldPointCount; ++i ) + { + minSeparation = b3MinFloat( minSeparation, manifold->points[i].separation ); + } + + if ( minSeparation < -2.0f * linearSlop ) + { + // Deep overlap + (void)b3AddEdge( &foundEdges, triangle.i1, triangle.i2 ); + (void)b3AddEdge( &foundEdges, triangle.i2, triangle.i3 ); + (void)b3AddEdge( &foundEdges, triangle.i3, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i1 ); + (void)b3AddVertex( &foundVertices, triangle.i2 ); + (void)b3AddVertex( &foundVertices, triangle.i3 ); + acceptedManifolds[acceptedManifoldCount++] = manifold; + } + else + { + b3TentativeTriangle tentativeTriangle = { .squaredDistance = manifold->squaredDistance, + .index = tentativeManifoldCount }; + tentativeTriangles[tentativeTriangleCount++] = tentativeTriangle; + tentativeManifolds[tentativeManifoldCount++] = manifold; + } + } + } + else + { + b3TentativeTriangle tentativeTriangle = { .squaredDistance = manifold->squaredDistance, + .index = tentativeManifoldCount }; + tentativeTriangles[tentativeTriangleCount++] = tentativeTriangle; + tentativeManifolds[tentativeManifoldCount++] = manifold; + } } } - if ( hullB != NULL && handleGhosts ) + B3_ASSERT( acceptedManifoldCount <= triangleCount ); + B3_ASSERT( tentativeManifoldCount <= triangleCount ); + B3_ASSERT( tentativeTriangleCount <= triangleCount ); + + if ( shapeB->type == b3_sphereShape ) { - // Cull triangles fully below the hull face when it rests on a triangle and has a tilted manifold normal. This - // helps when a box slides across a chamfered channel. - float tolerance = B3_NEIGHBOR_TOLERANCE; - float cosSquaredTolerance = 1.0f - tolerance * tolerance; - const b3LocalManifold* resting = NULL; - for ( int i = 0; i < manifoldCount && resting == NULL; ++i ) + // Sort triangles so the closest triangles are processed first { - const b3LocalManifold* manifold = manifoldBuffer + i; - float cosAngle = b3Dot( manifold->normal, manifold->triangleNormal ); - if ( manifold->pointCount > 0 && manifold->feature == b3_featureHullFace && cosAngle > 0.0f && - cosAngle * cosAngle >= cosSquaredTolerance ) - { - resting = manifold; - } +#define LESS( i, j ) tentativeTriangles[(int)i].squaredDistance < tentativeTriangles[(int)j].squaredDistance +#define SWAP( i, j ) \ + do \ + { \ + b3TentativeTriangle tmp = tentativeTriangles[(int)i]; \ + tentativeTriangles[(int)i] = tentativeTriangles[(int)j]; \ + tentativeTriangles[(int)j] = tmp; \ + } \ + while ( 0 ) + QSORT( tentativeTriangleCount, LESS, SWAP ); +#undef LESS +#undef SWAP } - if ( resting != NULL ) + // Add tentative manifolds in sorted order. Avoid adding manifolds that generate ghost collisions. + for ( int i = 0; i < tentativeTriangleCount; ++i ) { - b3Vec3 normal = resting->triangleNormal; - const b3Vec3* hullPoints = b3GetHullPoints( hullB ); - float hullBottom = FLT_MAX; - for ( int i = 0; i < hullB->vertexCount; ++i ) + b3LocalManifold* m = tentativeManifolds[tentativeTriangles[i].index]; + + bool addedEdge1 = b3AddEdge( &foundEdges, m->i1, m->i2 ); + bool addedEdge2 = b3AddEdge( &foundEdges, m->i2, m->i3 ); + bool addedEdge3 = b3AddEdge( &foundEdges, m->i3, m->i1 ); + bool addedVertex1 = b3AddVertex( &foundVertices, m->i1 ); + bool addedVertex2 = b3AddVertex( &foundVertices, m->i2 ); + bool addedVertex3 = b3AddVertex( &foundVertices, m->i3 ); + + b3TriangleFeature feature = m->feature; + bool shouldCollide = false; + switch ( feature ) { - hullBottom = b3MinFloat( hullBottom, b3Dot( normal, hullPoints[i] ) ); + case b3_featureNone: + case b3_featureTriangleFace: + B3_ASSERT( false ); + break; + + case b3_featureEdge1: + shouldCollide = addedEdge1; + break; + + case b3_featureEdge2: + shouldCollide = addedEdge2; + break; + + case b3_featureEdge3: + shouldCollide = addedEdge3; + break; + + case b3_featureVertex1: + shouldCollide = addedVertex1; + break; + + case b3_featureVertex2: + shouldCollide = addedVertex2; + break; + + case b3_featureVertex3: + shouldCollide = addedVertex3; + break; + + default: + B3_ASSERT( false ); + break; } - float restingSeparation = FLT_MAX; - for ( int i = 0; i < resting->pointCount; ++i ) + if ( shouldCollide == true ) { - restingSeparation = b3MinFloat( restingSeparation, resting->points[i].separation ); + acceptedManifolds[acceptedManifoldCount++] = m; + } + } + } + else + { + // Problem: hull can tunnel if time of impact is at concave edge + // Example: flat box sliding down a ramp to a flat bottom + // Solution: only ignore flat edges + for ( int i = 0; i < tentativeManifoldCount; ++i ) + { + b3LocalManifold* m = tentativeManifolds[i]; + int triangleFlags = m->triangleFlags; + + if ( ( triangleFlags & b3_allFlatEdges ) == b3_allFlatEdges ) + { + continue; } - // Padding - hullBottom = b3MinFloat( hullBottom, hullBottom - restingSeparation + 0.25f * linearSlop ); - - for ( int i = 0; i < survivorCount; ++i ) + if ( ( triangleFlags & b3_flatEdge1 ) == b3_flatEdge1 ) { - if ( survivorManifolds[i] == B3_NULL_INDEX ) + if ( b3FindEdge( &foundEdges, m->i1, m->i2 ) ) { continue; } + } - b3LocalManifold* manifold = manifoldBuffer + survivorManifolds[i]; - const b3Vec3* vertices = survivorVertices + 3 * i; - float cosAngle = b3Dot( manifold->normal, normal ); - float height = b3MaxFloat( b3Dot( normal, vertices[0] ), - b3MaxFloat( b3Dot( normal, vertices[1] ), b3Dot( normal, vertices[2] ) ) ); - if ( ( cosAngle <= 0.0f || cosAngle * cosAngle < cosSquaredTolerance ) && height < hullBottom ) + if ( ( triangleFlags & b3_flatEdge2 ) == b3_flatEdge2 ) + { + if ( b3FindEdge( &foundEdges, m->i2, m->i3 ) ) { - manifold->pointCount = 0; + continue; } } - } - } - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) - { - b3LocalManifold* manifold = manifoldBuffer + manifoldIndex; - if ( manifold->pointCount > 0 ) - { - acceptedManifolds[acceptedManifoldCount++] = manifold; + if ( ( triangleFlags & b3_flatEdge3 ) == b3_flatEdge3 ) + { + if ( b3FindEdge( &foundEdges, m->i3, m->i1 ) ) + { + continue; + } + } + + acceptedManifolds[acceptedManifoldCount++] = m; } } @@ -1586,11 +835,17 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape if ( acceptedManifoldCount == 0 ) { - return 0; + if ( contact->manifoldCount > 0 ) + { + b3FreeManifolds( world, contact->manifolds, contact->manifoldCount ); + contact->manifolds = NULL; + contact->manifoldCount = 0; + } + return false; } - b3Cluster* clusters = b3Bump( arena, acceptedManifoldCount * sizeof( b3Cluster ) ); - int* clusterMemberships = b3Bump( arena, acceptedManifoldCount * sizeof( int ) ); + b3Cluster* clusters = b3Bump( &arena, acceptedManifoldCount * sizeof( b3Cluster ) ); + int* clusterMemberships = b3Bump( &arena, acceptedManifoldCount * sizeof( int ) ); // Cluster tolerance is tighter than the warm starting manifold matching tolerance. These // serve different purposes. @@ -1622,9 +877,37 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape continue; } +#if 0 + // todo there could be later triangles that create the connection + // then failure to cluster breaks greedy impulse warm starting + bool edgeConnected = false; + + for ( int k = 0; k < i; ++k ) + { + if ( clusterMemberships[k] != j ) + { + continue; + } + + const b3LocalManifold* other = acceptedManifolds[k]; + if ( b3TrianglesShareEdge( manifold->i1, manifold->i2, manifold->i3, other->i1, other->i2, other->i3 ) ) + { + edgeConnected = true; + break; + } + } + + if ( edgeConnected ) + { + clusterIndex = j; + break; + } +#else + // Found a cluster clusterIndex = j; break; +#endif } if ( clusterIndex != B3_NULL_INDEX ) @@ -1644,105 +927,11 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape if ( clusterPointCount == 0 ) { - return 0; - } - - if ( clusterCount > manifoldCapacity ) - { - float* clusterSeparations = b3Bump( arena, clusterCount * sizeof( float ) ); - int* clusterRemap = b3Bump( arena, clusterCount * sizeof( int ) ); - for ( int i = 0; i < clusterCount; ++i ) - { - clusterSeparations[i] = FLT_MAX; - clusterRemap[i] = B3_NULL_INDEX; - } - - // Compute cluster separations. - for ( int i = 0; i < acceptedManifoldCount; ++i ) - { - const b3LocalManifold* manifold = acceptedManifolds[i]; - int clusterIndex = clusterMemberships[i]; - for ( int j = 0; j < manifold->pointCount; ++j ) - { - clusterSeparations[clusterIndex] = b3MinFloat( clusterSeparations[clusterIndex], manifold->points[j].separation ); - } - } - - int keptCount = 0; - - // If there are 8 or more manifolds then find the best per octant region. - if ( manifoldCapacity >= 8 ) - { - int octantClusters[8] = { B3_NULL_INDEX, B3_NULL_INDEX, B3_NULL_INDEX, B3_NULL_INDEX, - B3_NULL_INDEX, B3_NULL_INDEX, B3_NULL_INDEX, B3_NULL_INDEX }; - for ( int i = 0; i < clusterCount; ++i ) - { - b3Vec3 normal = b3InvRotateVector( transformAtoB.q, clusters[i].manifoldNormal ); - int octant = ( normal.x > 0.0f ? 1 : 0 ) | ( normal.y > 0.0f ? 2 : 0 ) | ( normal.z > 0.0f ? 4 : 0 ); - int best = octantClusters[octant]; - if ( best == B3_NULL_INDEX || clusterSeparations[i] < clusterSeparations[best] ) - { - octantClusters[octant] = i; - } - } - - for ( int i = 0; i < 8; ++i ) - { - if ( octantClusters[i] != B3_NULL_INDEX ) - { - // This cluster wins the octant. - clusterRemap[octantClusters[i]] = 0; - keptCount += 1; - } - } - } - - // If the octant culling left some capacity then find the deepest remaining clusters. - while ( keptCount < manifoldCapacity ) - { - int best = B3_NULL_INDEX; - for ( int i = 0; i < clusterCount; ++i ) - { - if ( clusterRemap[i] != B3_NULL_INDEX ) - { - continue; - } - - if ( best == B3_NULL_INDEX || clusterSeparations[i] < clusterSeparations[best] ) - { - best = i; - } - } - - B3_ASSERT( best != B3_NULL_INDEX ); - - // This cluster wins the separation test. - clusterRemap[best] = 0; - keptCount += 1; - } - - // Remap the winning clusters. - keptCount = 0; - for ( int i = 0; i < clusterCount; ++i ) - { - if ( clusterRemap[i] != B3_NULL_INDEX ) - { - clusters[keptCount] = clusters[i]; - clusterRemap[i] = keptCount; - keptCount += 1; - } - } - - for ( int i = 0; i < acceptedManifoldCount; ++i ) - { - clusterMemberships[i] = clusterRemap[clusterMemberships[i]]; - } - - clusterCount = keptCount; + return false; } // Setup clusters - b3LocalManifoldPoint* clusterPoints = b3Bump( arena, clusterPointCount * sizeof( b3LocalManifoldPoint ) ); + b3LocalManifoldPoint* clusterPoints = b3Bump( &arena, clusterPointCount * sizeof( b3LocalManifoldPoint ) ); int pointOffset = 0; for ( int i = 0; i < clusterCount; ++i ) @@ -1776,8 +965,6 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape cp->point = ap->point; cp->separation = ap->separation; cp->pair = ap->pair; - cp->triangleFeature = ap->triangleFeature; - cp->meshFlags = ap->meshFlags; cm->pointCount += 1; } } @@ -1787,47 +974,10 @@ static int b3CollideMeshTriangles( b3Cluster** clustersOut, const b3Shape* shape { b3Cluster* cm = clusters + i; B3_ASSERT( cm->pointCount == cm->pointCapacity ); - int reducedCount = b3ReduceCluster( cm->points, cm->pointCount, cm->triangleNormal, *arena ); + int reducedCount = b3ReduceCluster( cm->points, cm->pointCount, cm->triangleNormal, arena ); cm->pointCount = reducedCount; } - *clustersOut = clusters; - return clusterCount; -} - -bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact, const b3Shape* shapeA, - const uint16_t* materialMap, b3WorldTransform xfA, const b3Shape* shapeB, - b3WorldTransform xfB, bool isFast, b3Arena arena ) -{ - B3_ASSERT( shapeA->type == b3_meshShape || shapeA->type == b3_heightShape ); - b3TaskContext* context = b3Array_Get( world->taskContexts, workerIndex ); - - b3RefreshCache( contact, shapeA, xfA, &shapeB->aabb, arena ); - - b3MeshContact* meshContact = &contact->meshContact; - b3Transform transformAtoB = b3InvMulWorldTransforms( xfB, xfA ); - bool enableSpeculative = contact->flags & b3_enableSpeculativePoints; - bool handleGhosts = B3_FORCE_GHOST_COLLISIONS == 0; - - b3Cluster* clusters; - int clusterCount = b3CollideMeshTriangles( &clusters, shapeA, shapeB, transformAtoB, - meshContact->triangleCache.data, meshContact->triangleCache.count, - enableSpeculative, handleGhosts, isFast, B3_MAX_MANIFOLDS, context, - &arena ); - - if ( clusterCount == 0 ) - { - if ( contact->manifoldCount > 0 ) - { - b3FreeManifolds( world, contact->manifolds, contact->manifoldCount ); - contact->manifolds = NULL; - contact->manifoldCount = 0; - } - return false; - } - - float restOffset = B3_MESH_REST_OFFSET; - // Make a temporary copy of previous manifolds int oldManifoldCount = contact->manifoldCount; b3Manifold* oldManifolds = NULL; @@ -1911,8 +1061,6 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact target->separation = source->separation - restOffset; target->featureId = b3MakeFeatureId( source->pair ); target->triangleIndex = source->triangleIndex; - target->triangleFeature = source->triangleFeature; - target->meshFlags = source->meshFlags; // Preserve normal impulse if possible if ( matchedManifold != NULL ) @@ -1983,8 +1131,8 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact b3SurfaceMaterial material = materialsA[materialIndex]; friction += world->frictionCallback( material.friction, material.userMaterialId, materialB->friction, materialB->userMaterialId ); - restitution += world->restitutionCallback( material.restitution, material.userMaterialId, - materialB->restitution, materialB->userMaterialId ); + restitution += world->restitutionCallback( material.restitution, material.userMaterialId, materialB->restitution, + materialB->userMaterialId ); tangentVelocityA = b3Add( tangentVelocityA, material.tangentVelocity ); @@ -2006,8 +1154,8 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact else { // Keep these updated in case the values on the shapes are modified - contact->friction = world->frictionCallback( materialsA[0].friction, materialsA[0].userMaterialId, - materialB->friction, materialB->userMaterialId ); + contact->friction = world->frictionCallback( materialsA[0].friction, materialsA[0].userMaterialId, materialB->friction, + materialB->userMaterialId ); contact->restitution = world->restitutionCallback( materialsA[0].restitution, materialsA[0].userMaterialId, materialB->restitution, materialB->userMaterialId ); tangentVelocityA = materialsA[0].tangentVelocity; @@ -2035,108 +1183,3 @@ bool b3ComputeMeshManifolds( b3World* world, int workerIndex, b3Contact* contact contact->tangentVelocity = b3Sub( tangentVelocityA, tangentVelocityB ); return true; } - -// Mesh collision testing interface. -static int b3CollideMeshAndShape( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3Shape* shapeB, - b3AABB localBounds, b3Transform transformBtoA, bool enableSpeculative, - bool handleGhosts ) -{ - if ( capacity <= 0 ) - { - return 0; - } - - b3Shape meshShape = { - .type = b3_meshShape, - .mesh = *mesh, - }; - - b3Arena arena = b3CreateArena( 64 * 1024 ); - - float margin = B3_SPECULATIVE_DISTANCE; - b3Vec3 extension = { margin, margin, margin }; - b3AABB shapeBounds = b3AABB_Transform( transformBtoA, localBounds ); - b3AABB queryBounds = { - .lowerBound = b3Sub( shapeBounds.lowerBound, extension ), - .upperBound = b3Add( shapeBounds.upperBound, extension ), - }; - - b3TriangleQueryContext queryContext = { - .arena = &arena, - .indices = b3Bump( &arena, B3_INITIAL_TRIANGLE_CAPACITY * (int)sizeof( int ) ), - .capacity = B3_INITIAL_TRIANGLE_CAPACITY, - .count = 0, - }; - - b3QueryMesh( mesh, queryBounds, b3CollectTriangleIndicesCallback, &queryContext ); - - int triangleCount = queryContext.count; - b3TriangleCache* triangleCaches = b3Bump( &arena, triangleCount * (int)sizeof( b3TriangleCache ) ); - for ( int i = 0; i < triangleCount; ++i ) - { - triangleCaches[i] = (b3TriangleCache){ .triangleIndex = queryContext.indices[i] }; - } - - b3Transform transformAtoB = b3InvertTransform( transformBtoA ); - - b3Cluster* clusters; - int manifoldCapacity = b3MinInt( capacity, B3_MAX_MANIFOLDS ); - int clusterCount = b3CollideMeshTriangles( &clusters, &meshShape, shapeB, transformAtoB, triangleCaches, - triangleCount, enableSpeculative, handleGhosts, false, manifoldCapacity, - NULL, &arena ); - - int count = b3MinInt( clusterCount, capacity ); - b3Matrix3 matrixB = b3MakeMatrixFromQuat( transformBtoA.q ); - float restOffset = B3_MESH_REST_OFFSET; - - for ( int i = 0; i < count; ++i ) - { - const b3Cluster* cluster = clusters + i; - b3Manifold* manifold = manifolds + i; - *manifold = (b3Manifold){ 0 }; - manifold->normal = b3MulMV( matrixB, cluster->manifoldNormal ); - manifold->pointCount = cluster->pointCount; - - for ( int j = 0; j < cluster->pointCount; ++j ) - { - const b3LocalManifoldPoint* source = cluster->points + j; - b3ManifoldPoint* target = manifold->points + j; - target->anchorB = b3MulMV( matrixB, source->point ); - target->anchorA = b3Add( target->anchorB, transformBtoA.p ); - target->separation = source->separation - restOffset; - target->featureId = b3MakeFeatureId( source->pair ); - target->triangleIndex = source->triangleIndex; - target->triangleFeature = source->triangleFeature; - target->meshFlags = source->meshFlags; - } - } - - b3DestroyArena( &arena ); - return count; -} - -int b3CollideMeshAndHull( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3HullData* hull, - b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts ) -{ - b3Shape hullShape = { - .type = b3_hullShape, - .hull = hull, - }; - - return b3CollideMeshAndShape( manifolds, capacity, mesh, &hullShape, hull->aabb, transformBtoA, enableSpeculative, - handleGhosts ); -} - -int b3CollideMeshAndSphere( b3Manifold* manifolds, int capacity, const b3Mesh* mesh, const b3Sphere* sphere, - b3Transform transformBtoA, bool enableSpeculative, bool handleGhosts ) -{ - b3Shape sphereShape = { - .type = b3_sphereShape, - .sphere = *sphere, - }; - - b3Vec3 extent = { sphere->radius, sphere->radius, sphere->radius }; - b3AABB bounds = { b3Sub( sphere->center, extent ), b3Add( sphere->center, extent ) }; - return b3CollideMeshAndShape( manifolds, capacity, mesh, &sphereShape, bounds, transformBtoA, enableSpeculative, - handleGhosts ); -} diff --git a/src/motor_joint.c b/src/motor_joint.c index 6210d81..734d497 100644 --- a/src/motor_joint.c +++ b/src/motor_joint.c @@ -193,8 +193,8 @@ void b3PrepareMotorJoint( b3JointSim* base, b3StepContext* context ) B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -360,7 +360,17 @@ void b3SolveMotorJoint( b3JointSim* base, b3StepContext* context ) b3Vec3 cdot = b3Sub( b3Add( vB, b3Cross( wB, rB ) ), b3Add( vA, b3Cross( wA, rA ) ) ); - b3Vec3 b = b3SolvePointConstraint( mA, mB, base->invIA, base->invIB, rA, rB, b3Add( cdot, bias ) ); + //// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] + b3Matrix3 sA = b3Skew( rA ); + b3Matrix3 sB = b3Skew( rB ); + b3Matrix3 kA = b3MulMM( sA, b3MulMM( base->invIA, sA ) ); + b3Matrix3 kB = b3MulMM( sB, b3MulMM( base->invIB, sB ) ); + b3Matrix3 k = b3NegateMat3( b3AddMM( kA, kB ) ); + k.cx.x += mA + mB; + k.cy.y += mA + mB; + k.cz.z += mA + mB; + + b3Vec3 b = b3Solve3( k, b3Add( cdot, bias ) ); b3Vec3 oldImpulse = joint->linearSpringImpulse; b3Vec3 impulse = b3MulSub( b3MulSV( -massScale, b ), impulseScale, oldImpulse ); @@ -385,8 +395,17 @@ void b3SolveMotorJoint( b3JointSim* base, b3StepContext* context ) { b3Vec3 cdot = b3Sub( b3Add( vB, b3Cross( wB, rB ) ), b3Add( vA, b3Cross( wA, rA ) ) ); cdot = b3Sub( cdot, joint->linearVelocity ); + //// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] + b3Matrix3 sA = b3Skew( rA ); + b3Matrix3 sB = b3Skew( rB ); + b3Matrix3 kA = b3MulMM( sA, b3MulMM( base->invIA, sA ) ); + b3Matrix3 kB = b3MulMM( sB, b3MulMM( base->invIB, sB ) ); + b3Matrix3 k = b3NegateMat3( b3AddMM( kA, kB ) ); + k.cx.x += mA + mB; + k.cy.y += mA + mB; + k.cz.z += mA + mB; - b3Vec3 b = b3SolvePointConstraint( mA, mB, base->invIA, base->invIB, rA, rB, cdot ); + b3Vec3 b = b3Solve3( k, cdot ); b3Vec3 impulse = b3Neg( b ); b3Vec3 oldImpulse = joint->linearVelocityImpulse; diff --git a/src/mover_joint.c b/src/mover_joint.c deleted file mode 100644 index ac91319..0000000 --- a/src/mover_joint.c +++ /dev/null @@ -1,286 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "body.h" -#include "core.h" -#include "joint.h" -#include "physics_world.h" -#include "recording.h" -#include "solver.h" -#include "solver_set.h" - -// needed for dll export -#include "box3d/box3d.h" - -#include - -void b3MoverJoint_SetLinearVelocity( b3JointId jointId, b3Vec3 velocity ) -{ - B3_ASSERT( b3IsValidVec3( velocity ) ); - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, MoverJointSetLinearVelocity, jointId, velocity ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint ); - joint->moverJoint.linearVelocity = velocity; -} - -b3Vec3 b3MoverJoint_GetLinearVelocity( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint ); - return joint->moverJoint.linearVelocity; -} - -void b3MoverJoint_SetMaxVelocityForce( b3JointId jointId, float maxForce ) -{ - B3_ASSERT( b3IsValidFloat( maxForce ) && maxForce >= 0.0f ); - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, MoverJointSetMaxVelocityForce, jointId, maxForce ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint ); - joint->moverJoint.maxForce = maxForce; -} - -float b3MoverJoint_GetMaxVelocityForce( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_moverJoint ); - return joint->moverJoint.maxForce; -} - -b3Vec3 b3GetMoverJointForce( b3World* world, b3JointSim* base ) -{ - b3MoverJoint* joint = &base->moverJoint; - b3Vec3 P = b3Blend2( joint->impulse.x, joint->axisX, joint->impulse.y, joint->axisZ ); - return b3MulSV( world->inv_h, P ); -} - -void b3PrepareMoverJoint( b3JointSim* base, b3StepContext* context ) -{ - B3_ASSERT( base->type == b3_moverJoint ); - - int idA = base->bodyIdA; - int idB = base->bodyIdB; - - b3World* world = context->world; - - b3Body* bodyA = b3Array_Get( world->bodies, idA ); - b3Body* bodyB = b3Array_Get( world->bodies, idB ); - - B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); - - int localIndexA = bodyA->localIndex; - int localIndexB = bodyB->localIndex; - - b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA ); - b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB ); - - float mA = bodySimA->invMass; - float mB = bodySimB->invMass; - - base->invMassA = mA; - base->invMassB = mB; - base->invIA = b3Mat3_zero; - base->invIB = b3Mat3_zero; - - b3MoverJoint* joint = &base->moverJoint; - joint->indexA = bodyA->setIndex == b3_awakeSet ? localIndexA : B3_NULL_INDEX; - joint->indexB = bodyB->setIndex == b3_awakeSet ? localIndexB : B3_NULL_INDEX; - - b3Quat quatB = b3MulQuat( bodySimB->transform.q, base->localFrameB.q ); - b3Matrix3 matrixB = b3MakeMatrixFromQuat( quatB ); - joint->axisX = matrixB.cx; - joint->axisZ = matrixB.cz; - - float k = mA + mB; - joint->linearMass = k > 0.0f ? 1.0f / k : 0.0f; - - if ( context->enableWarmStarting == false ) - { - joint->impulse = (b3Vec2){ 0 }; - } -} - -void b3WarmStartMoverJoint( b3JointSim* base, b3StepContext* context ) -{ - B3_ASSERT( base->type == b3_moverJoint ); - - float mA = base->invMassA; - float mB = base->invMassB; - - b3MoverJoint* joint = &base->moverJoint; - - // dummy state for static bodies - b3BodyState dummyState = b3_identityBodyState; - - b3BodyState* stateA = - joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA; - b3BodyState* stateB = - joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB; - - b3Vec3 P = b3Blend2( joint->impulse.x, joint->axisX, joint->impulse.y, joint->axisZ ); - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = b3MulSub( stateA->linearVelocity, mA, P ); - } - - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = b3MulAdd( stateB->linearVelocity, mB, P ); - } -} - -void b3SolveMoverJoint( b3JointSim* base, b3StepContext* context ) -{ - B3_ASSERT( base->type == b3_moverJoint ); - - float mA = base->invMassA; - float mB = base->invMassB; - - // dummy state for static bodies - b3BodyState dummyState = b3_identityBodyState; - - b3MoverJoint* joint = &base->moverJoint; - b3BodyState* stateA = - joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA; - b3BodyState* stateB = - joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB; - - b3Vec3 vA = stateA->linearVelocity; - b3Vec3 vB = stateB->linearVelocity; - - float maxForce = joint->maxForce; - b3Vec3 vr = b3Sub( b3Sub( vB, vA ), joint->linearVelocity ); - b3Vec2 cdot = { b3Dot( vr, joint->axisX ), b3Dot( vr, joint->axisZ ) }; - b3Vec2 deltaImpulse = b3MulSV2( -joint->linearMass, cdot ); - b3Vec2 newImpulse = { - joint->impulse.x + deltaImpulse.x, - joint->impulse.y + deltaImpulse.y, - }; - - float maxImpulse = context->h * maxForce; - - float lengthSquared = b3Dot2( newImpulse, newImpulse ); - if ( lengthSquared > maxImpulse * maxImpulse ) - { - float scale = maxImpulse / sqrtf( lengthSquared ); - newImpulse.x *= scale; - newImpulse.y *= scale; - } - - deltaImpulse = b3Sub2( newImpulse, joint->impulse ); - joint->impulse = newImpulse; - - b3Vec3 P = b3Blend2( deltaImpulse.x, joint->axisX, deltaImpulse.y, joint->axisZ ); - vA = b3MulSub( vA, mA, P ); - vB = b3MulAdd( vB, mB, P ); - - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = vA; - } - - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = vB; - } -} - -static b3HexColor b3LerpColor( b3HexColor a, b3HexColor b, float t ) -{ - uint32_t result = 0; - for ( int shift = 0; shift < 24; shift += 8 ) - { - float ca = (float)( ( (uint32_t)a >> shift ) & 0xFF ); - float cb = (float)( ( (uint32_t)b >> shift ) & 0xFF ); - uint32_t c = (uint32_t)( b3LerpFloat( ca, cb, t ) + 0.5f ); - result |= c << shift; - } - return (b3HexColor)result; -} - -static void b3DrawArrow( b3DebugDraw* draw, b3Pos a, b3Pos b, b3Vec3 planeNormal, float size, - b3HexColor color ) -{ - draw->DrawSegmentFcn( a, b, color, draw->context ); - - b3Vec3 shaft = b3SubPos( b, a ); - float shaftLen = b3Length( shaft ); - if ( shaftLen < 1e-6f ) - { - return; - } - - b3Vec3 dir = { shaft.x / shaftLen, shaft.y / shaftLen, shaft.z / shaftLen }; - float headLen = size; - - b3Vec3 perp = b3Normalize( b3Cross( planeNormal, dir ) ); - b3Vec3 backFromTip = b3MulSV( -headLen, dir ); - b3Vec3 sideStep = b3MulSV( headLen * 0.5f, perp ); - b3Pos tip1 = b3OffsetPos( b, b3Add( backFromTip, sideStep ) ); - b3Pos tip2 = b3OffsetPos( b, b3Sub( backFromTip, sideStep ) ); - draw->DrawSegmentFcn( b, tip1, color, draw->context ); - draw->DrawSegmentFcn( b, tip2, color, draw->context ); -} - -void b3DrawMoverJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, - b3WorldTransform transformA, b3WorldTransform transformB ) -{ - B3_ASSERT( base->type == b3_moverJoint ); - B3_UNUSED( transformA ); - - b3MoverJoint* joint = &base->moverJoint; - - b3WorldTransform frameB = b3MulWorldTransforms( transformB, base->localFrameB ); - b3Matrix3 matrixB = b3MakeMatrixFromQuat( frameB.q ); - b3Vec3 axisX = matrixB.cx; - b3Vec3 axisZ = matrixB.cz; - - b3Body* bodyA = b3Array_Get( world->bodies, base->bodyIdA ); - b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); - b3BodyState* stateA = b3GetBodyState( world, bodyA ); - b3BodyState* stateB = b3GetBodyState( world, bodyB ); - b3Vec3 vA = stateA != NULL ? stateA->linearVelocity : b3Vec3_zero; - b3Vec3 vB = stateB != NULL ? stateB->linearVelocity : b3Vec3_zero; - - b3Vec3 velocityError = b3Sub( b3Sub( vB, vA ), joint->linearVelocity ); - b3Vec2 planarVelocityError = { b3Dot( velocityError, axisX ), b3Dot( velocityError, axisZ ) }; - b3Vec2 targetVelocity = { b3Dot( joint->linearVelocity, axisX ), - b3Dot( joint->linearVelocity, axisZ ) }; - - // Colorize ring by ratio of velocity error magnitude to target speed. - b3HexColor color = b3_colorWhite; - float targetSpeed = b3Length2( targetVelocity ); - if ( targetSpeed > 0.0f ) - { - float t = b3ClampFloat( b3Length2( planarVelocityError ) / targetSpeed, 0.0f, 1.0f ); - color = b3LerpColor( b3_colorWhite, b3_colorBlue, t ); - } - - float radius = draw->jointScale; - b3Vec3 rx = b3MulSV( radius, axisX ); - b3Vec3 rz = b3MulSV( radius, axisZ ); - const int segmentCount = 32; - b3CosSin cs = b3ComputeCosSin( 2.0f * B3_PI / segmentCount ); - float x1 = 1.0f, y1 = 0.0f; - b3Pos p1 = b3OffsetPos( frameB.p, rx ); - for ( int i = 0; i < segmentCount; ++i ) - { - float x2 = cs.cosine * x1 - cs.sine * y1; - float y2 = cs.sine * x1 + cs.cosine * y1; - b3Pos p2 = b3OffsetPos( frameB.p, b3Blend2( x2, rx, y2, rz ) ); - draw->DrawSegmentFcn( p1, p2, color, draw->context ); - x1 = x2; - y1 = y2; - p1 = p2; - } - - if ( joint->maxForce > 0.0f ) - { - b3Vec3 force = b3Blend2( joint->impulse.x, rx, joint->impulse.y, rz ); - b3Vec3 dir = b3Normalize( force ); - b3Pos origin = b3OffsetPos( frameB.p, b3MulSV( -radius, dir ) ); - float scale = world->inv_h / joint->maxForce; - b3Pos tip = b3OffsetPos( origin, b3MulSV( scale, force ) ); - b3DrawArrow( draw, origin, tip, matrixB.cy, 0.1f * draw->jointScale, b3_colorWhite ); - } -} diff --git a/src/name_cache.c b/src/name_cache.c deleted file mode 100644 index a7833df..0000000 --- a/src/name_cache.c +++ /dev/null @@ -1,155 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "name_cache.h" - -#include "recording.h" - -#include - -#define NAME b3NameMap -#define KEY_TY uint32_t -#define VAL_TY int -#define HASH_FN vt_hash_integer -#define CMPR_FN vt_cmpr_integer -#define MALLOC_FN b3Alloc -#define FREE_FN b3Free -#include "verstable.h" - -#define FNV32_OFFSET_BASIS 0x811c9dc5u -#define FNV32_PRIME 0x01000193u - -// This is designed to hash small strings and while avoiding collisions -// for a 32-bit hash. -// Note: changing this will break recordings -uint32_t b3Hash32( const void* data, size_t length ) -{ - // Cast to unsigned to avoid sign extension - const unsigned char* p = data; - - // FNV-1a - uint32_t h = FNV32_OFFSET_BASIS; - for ( size_t i = 0; i < length; ++i ) - { - h ^= p[i]; - h *= FNV32_PRIME; - } - - // Murmur3 finalizer to help with short strings - h ^= h >> 16; - h *= 0x85ebca6bu; - h ^= h >> 13; - h *= 0xc2b2ae35u; - h ^= h >> 16; - return h; -} - -b3NameCache b3CreateNameCache( void ) -{ - b3NameCache cache = { 0 }; - b3Array_Create( cache.entries ); - - b3NameMap* map = b3Alloc( sizeof( b3NameMap ) ); - b3NameMap_init( map ); - cache.map = map; - return cache; -} - -void b3DestroyNameCache( b3NameCache* cache ) -{ - int count = cache->entries.count; - for ( int i = 0; i < count; ++i ) - { - b3NameEntry* entry = cache->entries.data + i; - b3Free( entry->name, entry->length + 1 ); - } - - b3Array_Destroy( cache->entries ); - b3NameMap_cleanup( (b3NameMap*)cache->map ); - b3Free( cache->map, sizeof( b3NameMap ) ); -} - -uint32_t b3AddName( b3NameCache* cache, const char* name ) -{ - if ( name == NULL || name[0] == 0 ) - { - return B3_NULL_NAME; - } - - size_t length = strlen( name ); - uint32_t id = b3Hash32( name, length ); - - id = id == 0 ? 1 : id; - - b3NameMap* map = cache->map; - b3NameMap_itr itr = b3NameMap_get( map, id ); - if ( b3NameMap_is_end( itr ) == false ) - { - if ( strcmp( cache->entries.data[itr.data->val].name, name ) != 0 ) - { - // Different name, same hash - b3Log( "Hash collision on %s", name ); - } - return id; - } - - char* clone = b3Alloc( length + 1 ); - memcpy( clone, name, length + 1 ); - int index = cache->entries.count; - b3NameEntry entry = { - .hash = id, - .name = clone, - .length = (int)length, - }; - - b3Array_Push( cache->entries, entry ); - - b3NameMap_insert( map, id, index ); - return id; -} - -const char* b3FindName( const b3NameCache* cache, uint32_t id ) -{ - b3NameMap* map = cache->map; - b3NameMap_itr itr = b3NameMap_get( map, id ); - if ( b3NameMap_is_end( itr ) == false ) - { - int index = itr.data->val; - const b3NameEntry* entry = b3Array_Get( cache->entries, index ); - return entry->name; - } - - return NULL; -} - -void b3LoadName( b3NameCache* cache, uint32_t id, char* name, int length ) -{ - if ( name == NULL ) - { - return; - } - - if ( name[0] == 0 || id == B3_NULL_NAME ) - { - b3Free( name, length + 1 ); - return; - } - - b3NameMap* map = cache->map; - b3NameMap_itr itr = b3NameMap_get( map, id ); - if ( b3NameMap_is_end( itr ) == false ) - { - b3Free( name, length + 1 ); - return; - } - - int index = cache->entries.count; - b3NameEntry entry = { - .hash = id, - .name = name, - .length = length, - }; - - b3Array_Push( cache->entries, entry ); - b3NameMap_insert( map, id, index ); -} diff --git a/src/name_cache.h b/src/name_cache.h deleted file mode 100644 index d1535b3..0000000 --- a/src/name_cache.h +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "container.h" - -#define B3_NULL_NAME 0u - -typedef struct b3NameEntry -{ - // Names are used for debugging and I'm favoring simplicity and - // minimal storage. Collisions will be logged. - uint32_t hash; - int length; - char* name; -} b3NameEntry; - -b3DeclareArray( b3NameEntry ); - -typedef struct b3NameCache -{ - b3Array( b3NameEntry ) entries; - void* map; -} b3NameCache; - -b3NameCache b3CreateNameCache( void ); -void b3DestroyNameCache( b3NameCache* cache ); - -uint32_t b3AddName( b3NameCache* cache, const char* name ); -const char* b3FindName( const b3NameCache* cache, uint32_t id ); - -// Load a name from a recording. Name ownership is transferred. -void b3LoadName( b3NameCache* cache, uint32_t id, char* name, int length ); - -uint32_t b3Hash32( const void* data, size_t length ); - -static inline const char* b3FindNameWithDefault( const b3NameCache* cache, uint32_t id, const char* def ) -{ - const char* name = b3FindName( cache, id ); - return name == NULL ? def : name; -} diff --git a/src/parallel_for.c b/src/parallel_for.c index d444fa6..07d1c3f 100644 --- a/src/parallel_for.c +++ b/src/parallel_for.c @@ -6,85 +6,29 @@ #include "core.h" #include "physics_world.h" #include "platform.h" -#include "solver.h" #include "box3d/base.h" #include "box3d/constants.h" #include -static void b3RunStepTask( void* taskContext ) +// Shared state for one b3ParallelFor invocation. Workers race on nextBlock to +// claim work, so a slow chunk can't strand the other threads. +typedef struct b3ParallelForShared { - b3StepTask* task = taskContext; - b3StepContext* stepContext = task->stepContext; + b3AtomicInt nextBlock; + int blockCount; + int blockSize; + int itemCount; + b3ParallelForCallback* callback; + void* context; +} b3ParallelForShared; - task->fcn( task->context ); - - int index = (int)( task - stepContext->stepTasks ); - if ( stepContext->tasks[index].deferred ) - { - if ( b3AtomicFetchAddInt( &stepContext->treePending, -1 ) == 1 && stepContext->signalSemaphores ) - { - b3SignalSemaphore( stepContext->treeSemaphore ); - } - } - else - { - if ( b3AtomicFetchAddInt( &stepContext->pendingCount, -1 ) == 1 && stepContext->signalSemaphores ) - { - b3SignalSemaphore( stepContext->batchSemaphore ); - } - } -} - -void b3ResetTaskBatch( b3StepContext* stepContext ) +typedef struct b3ParallelForTask { - stepContext->batchTaskBase = 1; - stepContext->batchTaskCount = 0; - stepContext->joinTree = false; -} - -void b3AddTask( b3StepContext* stepContext, b3TaskType type, b3TaskCallback* fcn, void* context ) -{ - int index = stepContext->batchTaskBase + stepContext->batchTaskCount; - B3_ASSERT( 1 <= index && index < B3_STEP_TASK_CAPACITY ); - - b3StepTask* stepTask = stepContext->stepTasks + index; - stepTask->fcn = fcn; - stepTask->context = context; - stepTask->stepContext = stepContext; - - stepContext->tasks[index] = (b3Task){ - .fcn = b3RunStepTask, - .context = stepTask, - .type = type, - .deferred = false, - }; - - stepContext->batchTaskCount += 1; - stepContext->taskCount += 1; -} - -void b3StageDeferredTask( b3StepContext* stepContext, b3TaskType type, b3TaskCallback* fcn, void* context ) -{ - B3_ASSERT( stepContext->treeStaged == false ); - - b3StepTask* stepTask = stepContext->stepTasks + 0; - stepTask->fcn = fcn; - stepTask->context = context; - stepTask->stepContext = stepContext; - - stepContext->tasks[0] = (b3Task){ - .fcn = b3RunStepTask, - .context = stepTask, - .type = type, - .deferred = true, - }; - - stepContext->treeStaged = true; - stepContext->taskCount += 1; - b3AtomicStoreInt( &stepContext->treePending, 1 ); -} + b3ParallelForShared* shared; + int workerIndex; +} b3ParallelForTask; static void b3ParallelForTrampoline( void* taskContext ) { @@ -117,8 +61,8 @@ static void b3ParallelForTrampoline( void* taskContext ) } } -void b3StageParallelFor( b3World* world, b3TaskType type, b3ParallelForCallback* callback, int itemCount, int minRange, - void* context ) +void b3ParallelFor( b3World* world, b3ParallelForCallback* callback, int itemCount, int minRange, void* context, + const char* name ) { if ( itemCount <= 0 ) { @@ -133,8 +77,7 @@ void b3StageParallelFor( b3World* world, b3TaskType type, b3ParallelForCallback* // Target multiple blocks per worker to reduce thread stalls. // block size grows once items exceed maxBlockCount * minRange // so the block count stays bounded and per-block sync overhead stays low. - // Benchmarking shows 32 is optimal for the convex pile benchmark and others. - int blocksPerWorker = 32; + int blocksPerWorker = 4; int maxBlockCount = blocksPerWorker * workerCount; int blockSize; @@ -155,20 +98,38 @@ void b3StageParallelFor( b3World* world, b3TaskType type, b3ParallelForCallback* // No point enqueueing more tasks than blocks. int taskCount = workerCount < blockCount ? workerCount : blockCount; - b3StepContext* stepContext = world->stepContext; - b3ParallelForShared* shared = &stepContext->parallelFor; - shared->blockCount = blockCount; - shared->blockSize = blockSize; - shared->itemCount = itemCount; - shared->callback = callback; - shared->context = context; - b3AtomicStoreInt( &shared->nextBlock, 0 ); + b3ParallelForShared shared; + shared.blockCount = blockCount; + shared.blockSize = blockSize; + shared.itemCount = itemCount; + shared.callback = callback; + shared.context = context; + b3AtomicStoreInt( &shared.nextBlock, 0 ); + + b3ParallelForTask tasks[B3_MAX_WORKERS]; + void* handles[B3_MAX_WORKERS]; + for ( int i = 0; i < taskCount; ++i ) + { + tasks[i].shared = &shared; + tasks[i].workerIndex = i; + + if (world->taskCount < B3_MAX_TASKS) + { + handles[i] = world->enqueueTaskFcn( &b3ParallelForTrampoline, tasks + i, world->userTaskContext, name ); + world->taskCount += 1; + } + else + { + handles[i] = NULL; + b3ParallelForTrampoline( tasks + i ); + } + } for ( int i = 0; i < taskCount; ++i ) { - b3ParallelForTask* task = stepContext->parallelForTasks + i; - task->shared = shared; - task->workerIndex = i; - b3AddTask( stepContext, type, b3ParallelForTrampoline, task ); + if ( handles[i] != NULL ) + { + world->finishTaskFcn( handles[i], world->userTaskContext ); + } } } diff --git a/src/parallel_for.h b/src/parallel_for.h index 59f8218..4a6d285 100644 --- a/src/parallel_for.h +++ b/src/parallel_for.h @@ -3,16 +3,9 @@ #pragma once -#include "core.h" - -#include "box3d/types.h" - -// todo rename files to task.c and task.h - -typedef struct b3StepContext b3StepContext; typedef struct b3World b3World; -// Callback invoked by a staged parallel-for to process a range of items. May be called +// Callback invoked by b3ParallelFor to process a range of items. May be called // multiple times per worker: work is divided into blocks that workers claim // atomically, so a worker that finishes early picks up the next unclaimed // block instead of sitting idle. workerIndex is the worker identity and is @@ -20,29 +13,11 @@ typedef struct b3World b3World; // an index into per-worker state (e.g. world->taskContexts.data + workerIndex). typedef void b3ParallelForCallback( int startIndex, int endIndex, int workerIndex, void* context ); -typedef struct b3ParallelForShared -{ - b3AtomicInt nextBlock; - int blockCount; - int blockSize; - int itemCount; - b3ParallelForCallback* callback; - void* context; -} b3ParallelForShared; - -typedef struct b3ParallelForTask -{ - b3ParallelForShared* shared; - int workerIndex; -} b3ParallelForTask; - -void b3ResetTaskBatch( b3StepContext* stepContext ); -void b3AddTask( b3StepContext* stepContext, b3TaskType type, b3TaskCallback* fcn, void* context ); -void b3StageDeferredTask( b3StepContext* stepContext, b3TaskType type, b3TaskCallback* fcn, void* context ); - -// Divide [0, itemCount) into blocks and add up to world->workerCount tasks to the current -// batch. Each task loops, atomically claiming the next unclaimed block until the range is -// drained. minRange is the minimum block size. Block size grows once itemCount exceeds -// 32 * workerCount * minRange so block count stays bounded. -void b3StageParallelFor( b3World* world, b3TaskType type, b3ParallelForCallback* callback, int itemCount, int minRange, - void* context ); +// Divide [0, itemCount) into blocks and process them with cooperative claiming: +// up to world->workerCount tasks are enqueued, and each task loops, atomically +// claiming the next unclaimed block until the range is drained. Blocks the +// caller until all work is complete. minRange is the minimum block size; block +// size grows once itemCount exceeds 4 * workerCount * minRange so block count +// stays bounded. +void b3ParallelFor( b3World* world, b3ParallelForCallback* callback, int itemCount, int minRange, void* context, + const char* name ); diff --git a/src/parallel_joint.c b/src/parallel_joint.c index e476db1..7390a21 100644 --- a/src/parallel_joint.c +++ b/src/parallel_joint.c @@ -81,8 +81,8 @@ void b3PrepareParallelJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; diff --git a/src/physics_world.c b/src/physics_world.c index 2cea1d0..7f5630b 100644 --- a/src/physics_world.c +++ b/src/physics_world.c @@ -3,6 +3,8 @@ #include "physics_world.h" +#include "recording.h" + #include "arena_allocator.h" #include "bitset.h" #include "body.h" @@ -11,16 +13,14 @@ #include "contact.h" #include "core.h" #include "ctz.h" -#include "hull.h" +#include "hull_map.h" #include "island.h" #include "joint.h" #include "parallel_for.h" #include "platform.h" -#include "recording.h" #include "scheduler.h" #include "sensor.h" #include "shape.h" -#include "simd.h" #include "solver.h" #include "solver_set.h" @@ -28,7 +28,6 @@ #include "box3d/constants.h" #include -#include #include #include @@ -42,21 +41,18 @@ const b3HullData* b3AddHullToDatabase( b3World* world, const b3HullData* src ) { b3HullMap* database = world->hullDatabase; - // Compare by content to de-duplicate. Not trusting the hash. + // Compare by content so an unowned query hull finds the shared copy. b3HullMap_itr itr = b3HullMap_get( database, src ); if ( b3HullMap_is_end( itr ) == false ) { - // Bump reference count. itr.data->val += 1; return itr.data->key; } - b3HullData* clone = b3CloneHull( src ); - B3_ASSERT( clone != NULL ); - - // Start with reference count of 1. - b3HullMap_insert( database, clone, 1 ); - return clone; + b3HullData* owned = b3CloneHull( src ); + B3_ASSERT( owned != NULL ); + b3HullMap_insert( database, owned, 1 ); + return owned; } const b3HullData* b3AddOwnedHullToDatabase( b3World* world, b3HullData* owned ) @@ -139,9 +135,9 @@ b3World* b3GetUnlockedWorld( int index ) return world; } -static void* b3DefaultAddTaskFcn( b3TaskCallback* task, void* taskContext, void* userContext, b3TaskType taskType ) +static void* b3DefaultAddTaskFcn( b3TaskCallback* task, void* taskContext, void* userContext, const char* name ) { - B3_UNUSED( userContext, taskType ); + B3_UNUSED( userContext, name ); task( taskContext ); return NULL; } @@ -176,11 +172,11 @@ static void b3CreateWorkerContexts( b3World* world ) { world->taskContexts.data[i].arena = b3CreateArena( 128 * 1024 ); b3Array_Reserve( world->taskContexts.data[i].sensorHits, 8 ); - b3Array_Reserve( world->taskContexts.data[i].pairKeys, 64 ); world->taskContexts.data[i].contactStateBitSet = b3CreateBitSet( 1024 ); world->taskContexts.data[i].hitEventBitSet = b3CreateBitSet( 1024 ); world->taskContexts.data[i].hasHitEvents = false; world->taskContexts.data[i].jointStateBitSet = b3CreateBitSet( 1024 ); + world->taskContexts.data[i].enlargedSimBitSet = b3CreateBitSet( 256 ); world->taskContexts.data[i].awakeIslandBitSet = b3CreateBitSet( 256 ); world->taskContexts.data[i].splitIslandId = B3_NULL_INDEX; @@ -194,10 +190,10 @@ static void b3DestroyWorkerContexts( b3World* world ) { b3DestroyArena( &world->taskContexts.data[i].arena ); b3Array_Destroy( world->taskContexts.data[i].sensorHits ); - b3Array_Destroy( world->taskContexts.data[i].pairKeys ); b3DestroyBitSet( &world->taskContexts.data[i].contactStateBitSet ); b3DestroyBitSet( &world->taskContexts.data[i].hitEventBitSet ); b3DestroyBitSet( &world->taskContexts.data[i].jointStateBitSet ); + b3DestroyBitSet( &world->taskContexts.data[i].enlargedSimBitSet ); b3DestroyBitSet( &world->taskContexts.data[i].awakeIslandBitSet ); b3DestroyBitSet( &world->sensorTaskContexts.data[i].eventBits ); @@ -245,8 +241,6 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) memset( world, 0, sizeof( b3World ) ); - world->simdWidth = b3GetSIMDWidth(); - world->worldId = (uint16_t)worldId; world->generation = revision; world->inUse = true; @@ -264,7 +258,7 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) int bodyCapacity = b3MaxInt( 16, def->capacity.staticBodyCount + def->capacity.dynamicBodyCount ); b3Array_Reserve( world->bodies, bodyCapacity ); - b3Array_Reserve( world->sleepingSets, 8 ); + b3Array_Reserve( world->solverSets, 8 ); // add empty static, active, and disabled body sets world->solverSetIdPool = b3CreateIdPool(); @@ -272,34 +266,31 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) // static set set.setIndex = b3AllocId( &world->solverSetIdPool ); - world->fixedSets[set.setIndex] = set; - b3Array_Reserve( b3GetSolverSet( world, b3_staticSet )->bodySims, b3MaxInt( 16, def->capacity.staticBodyCount ) ); - B3_ASSERT( b3GetSolverSet( world, b3_staticSet )->setIndex == b3_staticSet ); + b3Array_Push( world->solverSets, set ); + b3Array_Reserve( world->solverSets.data[b3_staticSet].bodySims, b3MaxInt( 16, def->capacity.staticBodyCount ) ); + B3_ASSERT( world->solverSets.data[b3_staticSet].setIndex == b3_staticSet ); // disabled set set.setIndex = b3AllocId( &world->solverSetIdPool ); - world->fixedSets[set.setIndex] = set; - B3_ASSERT( b3GetSolverSet( world, b3_disabledSet )->setIndex == b3_disabledSet ); + b3Array_Push( world->solverSets, set ); + B3_ASSERT( world->solverSets.data[b3_disabledSet].setIndex == b3_disabledSet ); // awake set set.setIndex = b3AllocId( &world->solverSetIdPool ); - world->fixedSets[set.setIndex] = set; - b3Array_Reserve( b3GetSolverSet( world, b3_awakeSet )->bodySims, b3MaxInt( 16, def->capacity.dynamicBodyCount ) ); - b3Array_Reserve( b3GetSolverSet( world, b3_awakeSet )->bodyStates, b3MaxInt( 16, def->capacity.dynamicBodyCount ) ); - b3Array_Reserve( b3GetSolverSet( world, b3_awakeSet )->contactIndices, b3MaxInt( 16, def->capacity.contactCount ) ); - B3_ASSERT( b3GetSolverSet( world, b3_awakeSet )->setIndex == b3_awakeSet ); + b3Array_Push( world->solverSets, set ); + b3Array_Reserve( world->solverSets.data[b3_awakeSet].bodySims, b3MaxInt( 16, def->capacity.dynamicBodyCount ) ); + b3Array_Reserve( world->solverSets.data[b3_awakeSet].bodyStates, b3MaxInt( 16, def->capacity.dynamicBodyCount ) ); + b3Array_Reserve( world->solverSets.data[b3_awakeSet].contactIndices, b3MaxInt( 16, def->capacity.contactCount ) ); + B3_ASSERT( world->solverSets.data[b3_awakeSet].setIndex == b3_awakeSet ); world->shapeIdPool = b3CreateIdPool(); int shapeCapacity = b3MaxInt( 16, def->capacity.staticShapeCount + def->capacity.dynamicShapeCount ); b3Array_Reserve( world->shapes, shapeCapacity ); - b3Array_Reserve( world->fatAABBs, shapeCapacity ); world->hullDatabase = b3Alloc( sizeof( b3HullMap ) ); b3HullMap_init( world->hullDatabase ); - world->names = b3CreateNameCache(); - world->contactIdPool = b3CreateIdPool(); b3Array_Reserve( world->contacts, b3MaxInt( 16, def->capacity.contactCount ) ); @@ -324,13 +315,12 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) world->stepIndex = 0; world->splitIslandId = B3_NULL_INDEX; + world->activeTaskCount = 0; + world->taskCount = 0; world->gravity = def->gravity; world->hitEventThreshold = def->hitEventThreshold; world->restitutionThreshold = def->restitutionThreshold; - world->restitutionIterations = b3ClampInt( def->restitutionIterations, 0, B3_MAX_RESTITUTION_ITERATIONS ); - world->enableRestitutionPropagation = def->enableRestitutionPropagation; world->maxLinearSpeed = def->maximumLinearSpeed; - world->isotropicInertiaTolerance = b3ClampFloat( def->isotropicInertiaTolerance, 0.0f, 1.0f ); world->contactSpeed = def->contactSpeed; world->contactHertz = def->contactHertz; world->contactDampingRatio = def->contactDampingRatio; @@ -359,10 +349,10 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) world->enableWarmStarting = true; world->enableContinuous = def->enableContinuous; world->enableSpeculative = true; - world->useScheduler = false; + world->userTreeTask = NULL; world->userData = def->userData; - if ( def->workerCount > 0 && def->enqueueTask != NULL ) + if ( def->workerCount > 0 && def->enqueueTask != NULL && def->finishTask != NULL ) { // External task system world->workerCount = b3MinInt( def->workerCount, B3_MAX_WORKERS ); @@ -373,13 +363,12 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) } else if ( def->workerCount > 1 ) { - // Built-in scheduler, created on the first b3World_Step + // Built-in scheduler world->workerCount = b3MinInt( def->workerCount, B3_MAX_WORKERS ); - world->useScheduler = true; - world->scheduler = NULL; + world->scheduler = b3CreateScheduler( world->workerCount ); world->enqueueTaskFcn = b3SchedulerEnqueueTask; world->finishTaskFcn = b3SchedulerFinishTask; - world->userTaskContext = NULL; + world->userTaskContext = world->scheduler; } else { @@ -393,14 +382,6 @@ b3WorldId b3CreateWorld( const b3WorldDef* def ) b3CreateWorkerContexts( world ); - world->stepContext = b3AllocZero( sizeof( b3StepContext ) ); - - if ( world->finishTaskFcn == NULL ) - { - world->stepContext->batchSemaphore = b3CreateSemaphore( 0 ); - world->stepContext->treeSemaphore = b3CreateSemaphore( 0 ); - } - world->debugBodySet = b3CreateBitSet( 256 ); world->debugJointSet = b3CreateBitSet( 256 ); world->debugContactSet = b3CreateBitSet( 256 ); @@ -434,15 +415,6 @@ void b3DestroyWorld( b3WorldId worldId ) world->scheduler = NULL; } - if ( world->stepContext->batchSemaphore != NULL ) - { - b3DestroySemaphore( world->stepContext->batchSemaphore ); - b3DestroySemaphore( world->stepContext->treeSemaphore ); - } - - b3Free( world->stepContext, sizeof( b3StepContext ) ); - world->stepContext = NULL; - b3DestroyBitSet( &world->debugBodySet ); b3DestroyBitSet( &world->debugJointSet ); b3DestroyBitSet( &world->debugContactSet ); @@ -502,10 +474,7 @@ void b3DestroyWorld( b3WorldId worldId ) b3Free( world->hullDatabase, sizeof( b3HullMap ) ); world->hullDatabase = NULL; - b3DestroyNameCache( &world->names ); - b3Array_Destroy( world->shapes ); - b3Array_Destroy( world->fatAABBs ); b3Array_Destroy( world->contacts ); b3Array_Destroy( world->joints ); @@ -518,17 +487,17 @@ void b3DestroyWorld( b3WorldId worldId ) b3Array_Destroy( world->islands ); // Destroy solver sets - int setCapacity = b3GetSolverSetCount( world ); + int setCapacity = world->solverSets.count; for ( int i = 0; i < setCapacity; ++i ) { - b3SolverSet* set = b3GetSolverSet( world, i ); + b3SolverSet* set = world->solverSets.data + i; if ( set->setIndex != B3_NULL_INDEX ) { b3DestroySolverSet( world, i ); } } - b3Array_Destroy( world->sleepingSets ); + b3Array_Destroy( world->solverSets ); b3DestroyGraph( &world->constraintGraph ); b3DestroyBroadPhase( &world->broadPhase ); @@ -579,24 +548,6 @@ static inline void b3PrefetchContact( const b3Contact* contact ) b3Prefetch( p + 192 ); } -static inline b3BodySim* b3ResolveContactBodySim( b3World* world, b3BodySim* awakeSims, b3BodySim* staticSims, int encodedIndex, - int bodyId ) -{ - if ( encodedIndex >= 0 ) - { - return awakeSims + encodedIndex; - } - - if ( b3IsStaticSimIndex( encodedIndex ) ) - { - return staticSims - encodedIndex - 2; - } - - b3Body* body = b3Array_Get( world->bodies, bodyId ); - b3SolverSet* set = b3GetSolverSet( world, body->setIndex ); - return b3Array_Get( set->bodySims, body->localIndex ); -} - static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* context ) { b3TracyCZoneNC( collide_task, "Collide Task", b3_colorDodgerBlue, true ); @@ -608,9 +559,9 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* int* contactIndices = stepContext->awakeContactIndices; b3Contact* contacts = world->contacts.data; b3Shape* shapes = world->shapes.data; - const b3AABB* fatAABBs = world->fatAABBs.data; - b3BodySim* awakeSims = b3GetSolverSet( world, b3_awakeSet )->bodySims.data; - b3BodySim* staticSims = b3GetSolverSet( world, b3_staticSet )->bodySims.data; + b3Body* bodies = world->bodies.data; + b3BodySim* awakeSims = world->solverSets.data[b3_awakeSet].bodySims.data; + b3BodySim* staticSims = world->solverSets.data[b3_staticSet].bodySims.data; B3_ASSERT( startIndex < endIndex ); @@ -618,6 +569,9 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* float speculativeDistance = B3_SPECULATIVE_DISTANCE; float recycleDistanceNonTouching = b3MinFloat( recycleDistance, speculativeDistance ); + // Prefetch contact[i + contactPrefetchDistance] each iteration so the random + // 216 B contact load lands in L1 by the time we reach it. Distance picked to + // cover ~200 cycles of memory latency without overshooting the L1 working set. const int contactPrefetchDistance = 4; int prefetchEnd = endIndex - contactPrefetchDistance; @@ -634,11 +588,11 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* b3Contact* contact = contacts + contactIndex; B3_VALIDATE( contact->contactId == contactIndex ); - int shapeIdA = contact->shapeIdA; - int shapeIdB = contact->shapeIdB; + b3Shape* shapeA = shapes + contact->shapeIdA; + b3Shape* shapeB = shapes + contact->shapeIdB; // Do proxies still overlap? - bool overlap = b3OverlapV( fatAABBs + shapeIdA, fatAABBs + shapeIdB ); + bool overlap = b3AABB_Overlaps( shapeA->fatAABB, shapeB->fatAABB ); if ( overlap == false ) { // This contact will be destroyed @@ -648,43 +602,63 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* continue; } - b3Shape* shapeA = shapes + shapeIdA; - b3Shape* shapeB = shapes + shapeIdB; - - // Update contact respecting shape/body order (A,B) - int encodedA = contact->encodedBodySimA; - int encodedB = contact->encodedBodySimB; - b3BodySim* bodySimA = b3ResolveContactBodySim( world, awakeSims, staticSims, encodedA, contact->edges[0].bodyId ); - b3BodySim* bodySimB = b3ResolveContactBodySim( world, awakeSims, staticSims, encodedB, contact->edges[1].bodyId ); - + // Update contact respecting shape/body order (A,B). Bodies behind awake-set + // contacts are always either awake or static - inline b3GetBodySim with that + // invariant to skip the cross-TU call and per-call solverSets indirection. + b3Body* bodyA = bodies + shapeA->bodyId; + b3Body* bodyB = bodies + shapeB->bodyId; + bool isStaticA = bodyA->type == b3_staticBody; + bool isStaticB = bodyB->type == b3_staticBody; bool wasTouching = ( contact->flags & b3_simTouchingFlag ); + bool isMeshContact = ( contact->flags & b3_simMeshContact ); + b3BodySim* bodySimA; + b3BodySim* bodySimB; + if ( wasTouching ) + { + B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyA->setIndex == b3_staticSet ); + B3_ASSERT( bodyB->setIndex == b3_awakeSet || bodyB->setIndex == b3_staticSet ); + bodySimA = ( isStaticA ? staticSims : awakeSims ) + bodyA->localIndex; + bodySimB = ( isStaticB ? staticSims : awakeSims ) + bodyB->localIndex; + } + else + { + // There can be non-touching contacts between awake bodies and sleeping bodies. + { + b3SolverSet* set = b3Array_Get( world->solverSets, bodyA->setIndex ); + bodySimA = b3Array_Get( set->bodySims, bodyA->localIndex ); + } + { + b3SolverSet* set = b3Array_Get( world->solverSets, bodyB->setIndex ); + bodySimB = b3Array_Get( set->bodySims, bodyB->localIndex ); + } + } b3WorldTransform transformA = bodySimA->transform; b3WorldTransform transformB = bodySimB->transform; - // This is really just needed for mesh collision to prevent tunneling. - bool isFast = ( ( bodySimA->flags | bodySimB->flags ) & b3_isFast ) != 0; + bool isFast = ( bodySimA->flags & b3_isFast ) || ( bodySimB->flags & b3_isFast ); + // These are used by the contact solver. If the contact is between an awake body + // and a sleeping body and the contact begins to touch, the these will be invalid + // but fixed when linked in the constraint graph. + contact->bodySimIndexA = isStaticA ? B3_NULL_INDEX : bodyA->localIndex; + contact->bodySimIndexB = isStaticB ? B3_NULL_INDEX : bodyB->localIndex; float recycleTolerance = wasTouching ? recycleDistance : recycleDistanceNonTouching; // Contact recycling optimization. Please cite this library if you use this optimization. // This is inspired by persistent contact manifolds used in some physics engines, such as PhysX. // However, this allows larger relative motion and has fewer tuning parameters (just one). - if ( isFast == false && recycleDistance > 0.0f && ( contact->flags & b3_relativeTransformValid ) && - ( contact->flags & b3_contactRecycleFlag ) ) + if ( ( isFast == false || isMeshContact == false ) && recycleDistance > 0.0f && + ( contact->flags & b3_relativeTransformValid ) && ( contact->flags & b3_contactRecycleFlag ) ) { - // The scalar part of b3InvMulQuat is just the quaternion dot product. - // cos(relative_angle/2) = scalar(conj(q1) * q2) = dot(q1, q2) - // A small relative angle means this value is close to 1. Need to use abs or square - // due to double cover. float angleA = b3DotQuat( transformA.q, contact->cachedRotationA ); float angleB = b3DotQuat( transformB.q, contact->cachedRotationB ); float angularDistance = b3MinFloat( angleA * angleA, angleB * angleB ); b3Transform xf = b3InvMulWorldTransforms( transformA, transformB ); b3Transform xfc = contact->cachedRelativePose; - b3Vec3 maxExtentA = b3IsStaticSimIndex( encodedA ) ? b3Vec3_zero : bodySimA->maxExtent; - b3Vec3 maxExtentB = b3IsStaticSimIndex( encodedB ) ? b3Vec3_zero : bodySimB->maxExtent; + b3Vec3 maxExtentA = isStaticA ? b3Vec3_zero : bodySimA->maxExtent; + b3Vec3 maxExtentB = isStaticB ? b3Vec3_zero : bodySimB->maxExtent; b3Vec3 maxExtent = b3Max( maxExtentA, maxExtentB ); // Variation of Conservative Advancement @@ -733,14 +707,13 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* b3Vec3 rB = b3MulMV( matrixB, mp->anchorB ); b3Vec3 dp = b3Add( dc, b3Sub( rB, rA ) ); mp->separation = mp->baseSeparation + b3Dot( dp, normal ); - mp->normalVelocity = 0.0f; mp->persisted = true; } } // Diagnostics taskContext->recycledContactCount += 1; - int bucketIndex = b3MinInt( manifoldCount, B3_MAX_MANIFOLDS ); + int bucketIndex = b3MinInt( manifoldCount, B3_CONTACT_MANIFOLD_COUNT_BUCKETS - 1 ); if ( bucketIndex > 0 ) { taskContext->manifoldCounts[bucketIndex - 1] += 1; @@ -760,11 +733,10 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* contact->flags |= b3_relativeTransformValid; // This updates solid contacts - bool touching = b3UpdateContact( world, workerIndex, contact, shapeA, bodySimA->localCenter, - transformA, shapeB, + bool touching = b3UpdateContact( world, workerIndex, contact, shapeA, bodySimA->localCenter, transformA, shapeB, bodySimB->localCenter, transformB, isFast, taskContext->arena ); - int bucketIndex = b3MinInt( contact->manifoldCount, B3_MAX_MANIFOLDS ); + int bucketIndex = b3MinInt( contact->manifoldCount, B3_CONTACT_MANIFOLD_COUNT_BUCKETS - 1 ); if ( bucketIndex > 0 ) { taskContext->manifoldCounts[bucketIndex - 1] += 1; @@ -792,19 +764,14 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* b3SetBit( &taskContext->contactStateBitSet, contactIndex ); } - if ( touching ) + for ( int manifoldIndex = 0; manifoldIndex < contact->manifoldCount; ++manifoldIndex ) { - int manifoldCount = contact->manifoldCount; - for ( int manifoldIndex = 0; manifoldIndex < manifoldCount; ++manifoldIndex ) + b3Manifold* manifold = contact->manifolds + manifoldIndex; + for ( int pointIndex = 0; pointIndex < manifold->pointCount; ++pointIndex ) { - b3Manifold* manifold = contact->manifolds + manifoldIndex; - int pointCount = manifold->pointCount; - for ( int pointIndex = 0; pointIndex < pointCount; ++pointIndex ) - { - // Cache separation - b3ManifoldPoint* mp = manifold->points + pointIndex; - mp->baseSeparation = mp->separation; - } + // Cache separation + b3ManifoldPoint* mp = manifold->points + pointIndex; + mp->baseSeparation = mp->separation; } } } @@ -815,15 +782,17 @@ static void b3CollideTask( int startIndex, int endIndex, int workerIndex, void* static void b3AddNonTouchingContact( b3World* world, b3Contact* contact ) { B3_ASSERT( contact->setIndex == b3_awakeSet ); - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); contact->colorIndex = B3_NULL_INDEX; contact->localIndex = set->contactIndices.count; + contact->bodySimIndexA = B3_NULL_INDEX; + contact->bodySimIndexB = B3_NULL_INDEX; b3Array_Push( set->contactIndices, contact->contactId ); } static void b3RemoveNonTouchingContact( b3World* world, int setIndex, int localIndex ) { - b3SolverSet* set = b3GetSolverSet( world, setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); int movedIndex = b3Array_RemoveSwap( set->contactIndices, localIndex ); if ( movedIndex != B3_NULL_INDEX ) { @@ -837,12 +806,14 @@ static void b3RemoveNonTouchingContact( b3World* world, int setIndex, int localI } // Narrow-phase collision -static void b3BeginCollide( b3StepContext* context ) +static void b3Collide( b3StepContext* context ) { b3World* world = context->world; B3_ASSERT( world->workerCount > 0 ); + b3TracyCZoneNC( collide, "Collide", b3_colorDarkOrchid, true ); + // Gather contacts from all the graph colors into a single array for easier parallel-for int touchingCount = 0; @@ -852,19 +823,17 @@ static void b3BeginCollide( b3StepContext* context ) touchingCount += graphColors[i].convexContacts.count + graphColors[i].contacts.count; } - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); int nonTouchingCount = awakeSet->contactIndices.count; int contactCount = touchingCount + nonTouchingCount; - context->collideContactCount = contactCount; if ( contactCount == 0 ) { + b3TracyCZoneEnd( collide ); return; } - b3TracyCZoneNC( collide, "Narrow Phase Setup", b3_colorDarkOrchid, true ); - int* contactIndices = (int*)b3StackAlloc( &world->stack, contactCount * sizeof( int ), "contact indices" ); int contactIndex = 0; @@ -910,22 +879,11 @@ static void b3BeginCollide( b3StepContext* context ) // Task should take at least 40us on a 4GHz CPU (10K cycles) int minRange = 20; - b3StageParallelFor( world, b3_taskCollide, b3CollideTask, contactCount, minRange, context ); + b3ParallelFor( world, b3CollideTask, contactCount, minRange, context, "collide" ); - b3TracyCZoneEnd( collide ); -} - -static void b3EndCollide( b3StepContext* context ) -{ - b3World* world = context->world; - - if ( context->collideContactCount == 0 ) - { - return; - } - - b3StackFree( &world->stack, context->awakeContactIndices ); + b3StackFree( &world->stack, contactIndices ); context->awakeContactIndices = NULL; + contactIndices = NULL; // Serially update contact state // todo bring this zone together with island merge @@ -937,14 +895,15 @@ static void b3EndCollide( b3StepContext* context ) b3BitSet* bitSet = &world->taskContexts.data[0].contactStateBitSet; world->satCallCount = satMultiplier * world->taskContexts.data[0].satCallCount; world->satCacheHitCount = satMultiplier * world->taskContexts.data[0].satCacheHitCount; - memcpy( world->manifoldCounts, world->taskContexts.data[0].manifoldCounts, B3_MAX_MANIFOLDS * sizeof( int ) ); + memcpy( world->manifoldCounts, world->taskContexts.data[0].manifoldCounts, + B3_CONTACT_MANIFOLD_COUNT_BUCKETS * sizeof( int ) ); for ( int i = 1; i < world->workerCount; ++i ) { b3InPlaceUnion( bitSet, &world->taskContexts.data[i].contactStateBitSet ); world->satCallCount += world->taskContexts.data[i].satCallCount; world->satCacheHitCount += world->taskContexts.data[i].satCacheHitCount; - for ( int j = 0; j < B3_MAX_MANIFOLDS; ++j ) + for ( int j = 0; j < B3_CONTACT_MANIFOLD_COUNT_BUCKETS; ++j ) { world->manifoldCounts[j] += world->taskContexts.data[i].manifoldCounts[j]; } @@ -1060,253 +1019,23 @@ static void b3EndCollide( b3StepContext* context ) b3ValidateContacts( world ); b3TracyCZoneEnd( contact_state ); + b3TracyCZoneEnd( collide ); } -static void b3PrepareStepContext( b3World* world, b3StepContext* context ) +void b3World_Step( b3WorldId worldId, float timeStep, int subStepCount ) { - float timeStep = context->dt; - context->subStepCount = b3MaxInt( 1, context->subStepCount ); - - if ( timeStep > 0.0f ) + b3World* world = b3GetUnlockedWorldFromId( worldId ); + if ( world == NULL ) { - context->inv_dt = 1.0f / timeStep; - context->h = timeStep / context->subStepCount; - context->inv_h = context->subStepCount * context->inv_dt; - } - else - { - context->inv_dt = 0.0f; - context->h = 0.0f; - context->inv_h = 0.0f; + return; } - world->inv_h = context->inv_h; - world->inv_dt = context->inv_dt; - - // Hertz values get reduced for large time steps - float contactHertz = b3MinFloat( world->contactHertz, 0.125f * context->inv_h ); - context->contactSoftness = b3MakeSoft( contactHertz, world->contactDampingRatio, context->h ); - context->staticSoftness = b3MakeSoft( 2.0f * contactHertz, 0.5f * world->contactDampingRatio, context->h ); - - context->maxLinearVelocity = world->maxLinearSpeed; - context->enableWarmStarting = world->enableWarmStarting; -} - -static b3TaskBatch b3MakeTaskBatch( b3StepContext* context ) -{ - int deferredCount = context->batchTaskBase == 0 && context->tasks[0].deferred ? 1 : 0; - b3AtomicStoreInt( &context->pendingCount, context->batchTaskCount - deferredCount ); - - return (b3TaskBatch){ - .tasks = context->tasks + context->batchTaskBase, - .count = context->batchTaskCount, - .joinTasks = context->joinTree ? context->tasks : NULL, - .joinCount = context->joinTree ? 1 : 0, - }; -} - -static void b3LaunchTreeTask( b3StepContext* context, bool deferred ) -{ - B3_ASSERT( context->treeStaged && context->treeLaunched == false ); - context->batchTaskBase = 0; - context->batchTaskCount += 1; - context->treeLaunched = true; - - if ( deferred == false ) - { - context->tasks[0].deferred = false; - b3AtomicStoreInt( &context->treePending, 0 ); - } -} - -static void b3JoinTreeTask( b3StepContext* context ) -{ - if ( context->treeStaged ) - { - B3_ASSERT( b3AtomicLoadInt( &context->treePending ) == 0 ); - context->treeStaged = false; - b3ValidateNoMoved( &context->world->broadPhase ); - } -} - -static void b3EnterSensors( b3World* world, b3StepContext* context ) -{ - context->phase = b3_stepSensors; - context->sensorTicks = b3GetTicks(); - b3BeginSensors( world ); -} - -static void b3EndStep( b3World* world ) -{ - b3StepContext* context = world->stepContext; - B3_ASSERT( context->treeStaged == false ); - - world->profile.step = b3GetMilliseconds( context->stepTicks ); - - B3_ASSERT( world->stack.allocation == 0 ); - - // Ensure stack is large enough - b3GrowStack( &world->stack ); - - // Swap end event array buffers - world->endEventArrayIndex = 1 - world->endEventArrayIndex; - b3Array_Clear( world->sensorEndEvents[world->endEventArrayIndex] ); - b3Array_Clear( world->contactEndEvents[world->endEventArrayIndex] ); - - if ( world->recording != NULL ) - { - b3WorldId worldId = { (uint16_t)( world->worldId + 1 ), world->generation }; - uint64_t hash = b3HashWorldState( world ); - b3RecArgs_StateHash stateHash = { worldId, hash }; - b3RecWrite_StateHash( world->recording, &stateHash ); - - // Fold this step's world bounds into the recording so a viewer can frame the whole motion. - b3AABB worldBounds = { 0 }; - bool haveBounds = false; - for ( int i = 0; i < b3_bodyTypeCount; ++i ) - { - b3DynamicTree* tree = world->broadPhase.trees + i; - if ( b3DynamicTree_GetProxyCount( tree ) == 0 ) - { - continue; - } - b3AABB bounds = b3DynamicTree_GetRootBounds( tree ); - worldBounds = haveBounds ? b3AABB_Union( worldBounds, bounds ) : bounds; - haveBounds = true; - } - if ( haveBounds ) - { - b3RecAccumulateBounds( world->recording, worldBounds ); - } - } - - context->phase = b3_stepIdle; - world->locked = false; - - b3TracyCFrame; -} - -static b3TaskBatch b3AdvanceStep( b3World* world ) -{ - b3StepContext* context = world->stepContext; - - for ( ;; ) - { - b3ResetTaskBatch( context ); - - switch ( context->phase ) - { - case b3_stepBegin: - context->phase = b3_stepCrossPairs; - context->pairTicks = b3GetTicks(); - context->pairsUpdated = b3BeginPairs( world ); - break; - - case b3_stepCrossPairs: - context->phase = b3_stepSelfPairs; - if ( context->pairsUpdated ) - { - b3StageSelfPairs( world ); - } - break; - - case b3_stepSelfPairs: - if ( context->pairsUpdated ) - { - b3EndPairs( world ); - } - world->profile.pairs = b3GetMilliseconds( context->pairTicks ); - - b3PrepareStepContext( world, context ); - - context->phase = b3_stepCollide; - context->collideTicks = b3GetTicks(); - context->solveSkipped = - ( context->dt > 0.0f ) == false || b3GetSolverSet( world, b3_awakeSet )->bodySims.count == 0; - - b3BeginCollide( context ); - - if ( context->treeStaged && ( context->batchTaskCount > 0 || context->solveSkipped ) ) - { - b3LaunchTreeTask( context, context->solveSkipped == false ); - } - break; - - case b3_stepCollide: - b3EndCollide( context ); - world->profile.collide = b3GetMilliseconds( context->collideTicks ); - - // Integrate velocities, solve velocity constraints, and integrate positions. - if ( context->dt > 0.0f ) - { - context->phase = b3_stepSolve; - context->solveTicks = b3GetTicks(); - if ( b3BeginSolve( world, context ) ) - { - B3_ASSERT( context->solveSkipped == false ); - if ( context->treeStaged ) - { - if ( context->treeLaunched ) - { - context->joinTree = true; - } - else - { - b3LaunchTreeTask( context, false ); - } - } - break; - } - - world->profile.solve = b3GetMilliseconds( context->solveTicks ); - } - - B3_ASSERT( context->solveSkipped ); - b3JoinTreeTask( context ); - b3EnterSensors( world, context ); - break; - - case b3_stepSolve: - b3JoinTreeTask( context ); - context->phase = b3_stepFinalize; - b3BeginFinalize( world, context ); - break; - - case b3_stepFinalize: - context->phase = b3_stepBullets; - b3BeginBullets( world, context ); - break; - - case b3_stepBullets: - b3EndBullets( world, context ); - world->profile.solve = b3GetMilliseconds( context->solveTicks ); - b3EnterSensors( world, context ); - break; - - case b3_stepSensors: - b3EndSensors( world ); - world->profile.sensors = b3GetMilliseconds( context->sensorTicks ); - b3EndStep( world ); - return (b3TaskBatch){ 0 }; - - default: - B3_ASSERT( false ); - return (b3TaskBatch){ 0 }; - } - - if ( context->batchTaskCount > 0 ) - { - return b3MakeTaskBatch( context ); - } - } -} - -static b3TaskBatch b3StartStep( b3World* world, b3WorldId worldId, float timeStep, int subStepCount, - bool signalSemaphores ) -{ - // Record step inputs before simulation runs B3_REC( world, Step, worldId, timeStep, subStepCount ); + world->locked = true; + + b3TracyCZoneNC( world_step, "Step", b3_colorBox2DGreen, true ); + // Clear debug buffers for ( int i = 0; i < world->workerCount; ++i ) { @@ -1324,29 +1053,22 @@ static b3TaskBatch b3StartStep( b3World* world, b3WorldId worldId, float timeSte world->profile = (b3Profile){ 0 }; - world->locked = true; + world->activeTaskCount = 0; + world->taskCount = 0; - b3StepContext* context = world->stepContext; - b3Semaphore* batchSemaphore = context->batchSemaphore; - b3Semaphore* treeSemaphore = context->treeSemaphore; - memset( context, 0, sizeof( b3StepContext ) ); - context->batchSemaphore = batchSemaphore; - context->treeSemaphore = treeSemaphore; - context->signalSemaphores = signalSemaphores; - B3_ASSERT( signalSemaphores == false || ( batchSemaphore != NULL && treeSemaphore != NULL ) ); + if ( world->scheduler != NULL ) + { + b3ResetScheduler( world->scheduler ); + } - context->world = world; - context->dt = timeStep; - context->subStepCount = subStepCount; - context->phase = b3_stepBegin; - context->stepTicks = b3GetTicks(); + uint64_t stepTicks = b3GetTicks(); { b3Capacity* c = &world->maxCapacity; c->staticShapeCount = b3MaxInt( c->staticShapeCount, world->broadPhase.trees[b3_staticBody].proxyCount ); c->dynamicShapeCount = b3MaxInt( c->dynamicShapeCount, world->broadPhase.trees[b3_dynamicBody].proxyCount ); - int staticBodyCount = b3GetSolverSet( world, b3_staticSet )->bodySims.count; + int staticBodyCount = world->solverSets.data[b3_staticSet].bodySims.count; c->staticBodyCount = b3MaxInt( c->staticBodyCount, staticBodyCount ); // this includes kinematic bodies @@ -1357,219 +1079,120 @@ static b3TaskBatch b3StartStep( b3World* world, b3WorldId worldId, float timeSte c->contactCount = b3MaxInt( c->contactCount, totalContactCount ); } - return b3AdvanceStep( world ); -} - -static b3TaskBatch b3ContinueStepInternal( b3World* world ) -{ - b3StepContext* context = world->stepContext; - B3_UNUSED( context ); - B3_ASSERT( b3AtomicLoadInt( &context->pendingCount ) == 0 ); - B3_ASSERT( context->joinTree == false || b3AtomicLoadInt( &context->treePending ) == 0 ); - return b3AdvanceStep( world ); -} - -typedef struct b3StepDriver -{ - b3World* world; - void* treeTask; - int enqueueCount; - bool useFinish; -} b3StepDriver; - -static void b3RunTaskBatch( b3StepDriver* driver, b3TaskBatch batch ) -{ - b3World* world = driver->world; - void* userContext = world->userTaskContext; - - void* handles[B3_STEP_TASK_CAPACITY]; - bool waitBatch = false; - int lastIndex = batch.count - 1; - B3_ASSERT( 0 <= lastIndex && lastIndex < B3_STEP_TASK_CAPACITY ); - - for ( int i = 0; i < lastIndex; ++i ) + // Update collision pairs and create contacts { - const b3Task* task = batch.tasks + i; - void* handle = NULL; - if ( driver->enqueueCount < B3_MAX_TASKS ) - { - handle = world->enqueueTaskFcn( task->fcn, task->context, userContext, task->type ); - driver->enqueueCount += 1; - } - else - { - task->fcn( task->context ); - } - - if ( task->deferred ) - { - B3_ASSERT( driver->treeTask == NULL ); - driver->treeTask = handle; - handles[i] = NULL; - } - else - { - handles[i] = handle; - waitBatch = true; - } + uint64_t pairTicks = b3GetTicks(); + b3UpdateBroadPhasePairs( world ); + world->profile.pairs = b3GetMilliseconds( pairTicks ); } - const b3Task* lastTask = batch.tasks + lastIndex; - waitBatch = waitBatch || lastTask->deferred == false; - lastTask->fcn( lastTask->context ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); - if ( driver->useFinish ) + b3StepContext context = { 0 }; + context.world = world; + context.states = awakeSet->bodyStates.data; + context.dt = timeStep; + context.subStepCount = b3MaxInt( 1, subStepCount ); + + if ( timeStep > 0.0f ) { - for ( int i = 0; i < lastIndex; ++i ) + context.inv_dt = 1.0f / timeStep; + context.h = timeStep / context.subStepCount; + context.inv_h = context.subStepCount * context.inv_dt; + } + else + { + context.inv_dt = 0.0f; + context.h = 0.0f; + context.inv_h = 0.0f; + } + + world->inv_h = context.inv_h; + world->inv_dt = context.inv_dt; + + // Hertz values get reduced for large time steps + float contactHertz = b3MinFloat( world->contactHertz, 0.125f * context.inv_h ); + context.contactSoftness = b3MakeSoft( contactHertz, world->contactDampingRatio, context.h ); + context.staticSoftness = b3MakeSoft( 2.0f * contactHertz, 0.5f * world->contactDampingRatio, context.h ); + + context.restitutionThreshold = world->restitutionThreshold; + context.maxLinearVelocity = world->maxLinearSpeed; + context.enableWarmStarting = world->enableWarmStarting; + + // Narrow phase : update contacts + { + uint64_t collideTicks = b3GetTicks(); + b3Collide( &context ); + world->profile.collide = b3GetMilliseconds( collideTicks ); + } + + // Integrate velocities, solve velocity constraints, and integrate positions. + if ( timeStep > 0.0f ) + { + uint64_t solveTicks = b3GetTicks(); + b3Solve( world, &context ); + world->profile.solve = b3GetMilliseconds( solveTicks ); + } + + // Finish the tree task in case b3Solve didn't finish it + if ( world->userTreeTask ) + { + world->finishTaskFcn( world->userTreeTask, world->userTaskContext ); + world->userTreeTask = NULL; + world->activeTaskCount -= 1; + } + + // Update sensors + { + uint64_t sensorTicks = b3GetTicks(); + b3OverlapSensors( world ); + world->profile.sensors = b3GetMilliseconds( sensorTicks ); + } + + world->profile.step = b3GetMilliseconds( stepTicks ); + + B3_ASSERT( world->stack.allocation == 0 ); + + // Ensure stack is large enough + b3GrowStack( &world->stack ); + + // Make sure all tasks that were started were also finished + B3_ASSERT( world->activeTaskCount == 0 ); + + // Swap end event array buffers + world->endEventArrayIndex = 1 - world->endEventArrayIndex; + b3Array_Clear( world->sensorEndEvents[world->endEventArrayIndex] ); + b3Array_Clear( world->contactEndEvents[world->endEventArrayIndex] ); + world->locked = false; + + if ( world->recording != NULL ) + { + uint64_t hash = b3HashWorldState( world ); + b3RecArgs_StateHash stateHash = { worldId, hash }; + b3RecWrite_StateHash( world->recording, &stateHash ); + + // Fold this step's world bounds into the recording so a viewer can frame the whole motion. + b3AABB worldBounds = { 0 }; + bool haveBounds = false; + for ( int i = 0; i < b3_bodyTypeCount; ++i ) { - if ( handles[i] != NULL ) + b3DynamicTree* tree = world->broadPhase.trees + i; + if ( b3DynamicTree_GetProxyCount( tree ) == 0 ) { - world->finishTaskFcn( handles[i], userContext ); + continue; } + b3AABB bounds = b3DynamicTree_GetRootBounds( tree ); + worldBounds = haveBounds ? b3AABB_Union( worldBounds, bounds ) : bounds; + haveBounds = true; + } + if ( haveBounds ) + { + b3RecAccumulateBounds( world->recording, worldBounds ); } } - else if ( waitBatch ) - { - b3WaitSemaphore( world->stepContext->batchSemaphore ); - } - - if ( batch.joinCount > 0 ) - { - if ( driver->useFinish ) - { - if ( driver->treeTask != NULL ) - { - world->finishTaskFcn( driver->treeTask, userContext ); - } - } - else - { - b3WaitSemaphore( world->stepContext->treeSemaphore ); - } - - driver->treeTask = NULL; - } -} - -void b3World_Step( b3WorldId worldId, float timeStep, int subStepCount ) -{ - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return; - } - - b3TracyCZoneNC( world_step, "Step", b3_colorBox2DGreen, true ); - - if ( world->useScheduler ) - { - if ( world->scheduler == NULL ) - { - world->scheduler = b3CreateScheduler( world->workerCount ); - world->userTaskContext = world->scheduler; - } - - b3ResetScheduler( world->scheduler ); - } - - b3StepDriver driver = { - .world = world, - .treeTask = NULL, - .enqueueCount = 0, - .useFinish = world->finishTaskFcn != NULL, - }; - - b3TaskBatch batch = b3StartStep( world, worldId, timeStep, subStepCount, driver.useFinish == false ); - while ( batch.count > 0 ) - { - switch ( world->stepContext->phase ) - { - case b3_stepCrossPairs: - case b3_stepSelfPairs: - { - b3TracyCZoneNC( find_pairs, "Find Pairs", b3_colorMediumSlateBlue, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( find_pairs ); - } - break; - - case b3_stepCollide: - { - b3TracyCZoneNC( collide, "Narrow Phase", b3_colorDarkOrchid, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( collide ); - } - break; - - case b3_stepSolve: - { - b3TracyCZoneNC( solve_constraints, "Solve Constraints", b3_colorIndigo, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( solve_constraints ); - } - break; - - case b3_stepFinalize: - { - b3TracyCZoneNC( update_transforms, "Update Transforms", b3_colorMediumSeaGreen, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( update_transforms ); - } - break; - - case b3_stepBullets: - { - b3TracyCZoneNC( bullets, "Bullets", b3_colorDarkGoldenRod, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( bullets ); - } - break; - - case b3_stepSensors: - { - b3TracyCZoneNC( sensors, "Sensors", b3_colorMediumPurple, true ); - b3RunTaskBatch( &driver, batch ); - b3TracyCZoneEnd( sensors ); - } - break; - - default: - B3_ASSERT( false ); - break; - } - - batch = b3ContinueStepInternal( world ); - } - - B3_ASSERT( driver.treeTask == NULL ); - world->stepContext->enqueueCount = driver.enqueueCount; b3TracyCZoneEnd( world_step ); -} - -b3TaskBatch b3World_BeginStep( b3WorldId worldId, float timeStep, int subStepCount ) -{ - b3World* world = b3GetWorldFromId( worldId ); - B3_ASSERT( world->locked == false ); - if ( world->locked ) - { - return (b3TaskBatch){ 0 }; - } - - return b3StartStep( world, worldId, timeStep, subStepCount, false ); -} - -b3TaskBatch b3World_ContinueStep( b3WorldId worldId ) -{ - b3World* world = b3GetWorldFromId( worldId ); - b3StepContext* context = world->stepContext; - B3_ASSERT( world->locked && context->phase != b3_stepIdle ); - if ( context->phase == b3_stepIdle ) - { - return (b3TaskBatch){ 0 }; - } - - return b3ContinueStepInternal( world ); + b3TracyCFrame; } typedef struct DrawContext @@ -1627,7 +1250,7 @@ static bool DrawQueryCallback( int proxyId, uint64_t userData, void* context ) { rgb = b3_colorWheat; } - else if ( bodySim->flags & b3_hadTimeOfImpact ) + else if ( body->flags & b3_hadTimeOfImpact ) { rgb = b3_colorLime; } @@ -1726,7 +1349,7 @@ static bool DrawQueryCallback( int proxyId, uint64_t userData, void* context ) if ( draw->drawBounds ) { - draw->DrawBoundsFcn( world->fatAABBs.data[shapeId], b3_colorGold, draw->context ); + draw->DrawBoundsFcn( shape->fatAABB, b3_colorGold, draw->context ); } return true; @@ -1791,59 +1414,25 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) b3Body* body = b3Array_Get( world->bodies, bodyId ); b3BodySim* bodySim = b3GetBodySim( world, body ); - if ( draw->drawBodyNames && body->nameId != B3_NULL_NAME ) + if ( draw->drawBodyNames && body->name[0] != 0 ) { b3Vec3 offset = { 0.05f, 0.05f, 0.05f }; b3WorldTransform transform = { bodySim->center, bodySim->transform.q }; b3Pos p = b3TransformWorldPoint( transform, offset ); - const char* name = b3FindName( &world->names, body->nameId ); - if ( name != NULL ) - { - draw->DrawStringFcn( p, name, b3_colorWhite, draw->context ); - } + draw->DrawStringFcn( p, body->name, b3_colorOrange, draw->context ); } - if ( draw->drawMass ) + if ( draw->drawMass && body->type == b3_dynamicBody ) { + b3Vec3 offset = { 0.1f, 0.1f, 0.1f }; + b3WorldTransform transform = { bodySim->center, bodySim->transform.q }; draw->DrawTransformFcn( transform, draw->context ); + b3Pos p = b3TransformWorldPoint( transform, offset ); - if ( body->type == b3_dynamicBody ) - { - b3Vec3 offset = { 0.05f, 0.05f, 0.05f }; - b3Pos p = b3TransformWorldPoint( transform, offset ); - char buffer[32]; - snprintf( buffer, 32, "%.2f", body->mass ); - draw->DrawStringFcn( p, buffer, b3_colorWhite, draw->context ); - } - } - - if ( draw->drawSleep ) - { - b3BodyState* bodyState = b3GetBodyState( world, body ); - - if ( bodyState != NULL ) - { - b3HexColor colors[4] = { b3_colorBlue, b3_colorSkyBlue, b3_colorOrange, b3_colorRed }; - - b3HexColor color = b3_colorBlack; - if ( body->sleepThreshold > 0.0f ) - { - float ratio = body->sleepVelocity / body->sleepThreshold; - int index = b3ClampInt( (int)ratio, 0, 3 ); - color = colors[index]; - } - - b3Pos center = bodySim->center; - draw->DrawPointFcn( center, 10.0f, color, draw->context ); - - b3Vec3 offset = { 0.1f, 0.1f, 0.1f }; - b3Pos p = b3OffsetPos( center, offset ); - - char buffer[32]; - snprintf( buffer, 32, " %.3f", body->sleepVelocity ); - draw->DrawStringFcn( p, buffer, color, draw->context ); - } + char buffer[32]; + snprintf( buffer, 32, " %.2f", body->mass ); + draw->DrawStringFcn( p, buffer, b3_colorWhite, draw->context ); } if ( draw->drawJoints ) @@ -1898,10 +1487,8 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) b3Vec3 normal = manifold->normal; // Average the anchors not the world points so the friction center stays exact far from the origin - b3Pos contactCenter = draw->drawAnchorA ? bodySimA->center : bodySimB->center; - b3Vec3 frictionAnchor = b3Vec3_zero; - float totalWeight = 0.0f; - float invTau = 1.0f / B3_SPECULATIVE_DISTANCE; + b3Pos contactCenter = draw->drawAnchorA == 1 ? bodySimA->center : bodySimB->center; + b3Vec3 anchorSum = b3Vec3_zero; const b3ManifoldPoint* points = manifold->points; for ( int pointIndex = 0; pointIndex < manifold->pointCount; ++pointIndex ) @@ -1910,13 +1497,10 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) char buffer[32]; - b3Vec3 anchor = draw->drawAnchorA ? mp->anchorA : mp->anchorB; + b3Vec3 anchor = draw->drawAnchorA == 1 ? mp->anchorA : mp->anchorB; b3Pos p = b3OffsetPos( contactCenter, anchor ); - // See similar friction anchor weights in b3PrepareContacts_Mesh. - float weight = b3ClampFloat( 2.0f - mp->separation * invTau, B3_MIN_FRICTION_WEIGHT, 1.0f ); - frictionAnchor = b3MulAdd( frictionAnchor, weight, anchor ); - totalWeight += weight; + anchorSum = b3Add( anchorSum, anchor ); if ( draw->drawContactNormals ) { @@ -1931,7 +1515,9 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) { // Hack inv_dt for single step debugging float inv_dt = world->inv_dt > 0.0f ? world->inv_dt : 60.0f; - float force = mp->totalNormalImpulse * inv_dt; + // todo validate + // multiply by one-half due to relax iteration + float force = 0.5f * mp->totalNormalImpulse * inv_dt; b3Pos p1 = p; b3Pos p2 = b3OffsetPos( p1, b3MulSV( draw->forceScale * force, normal ) ); draw->DrawSegmentFcn( p1, p2, impulseColor, draw->context ); @@ -1977,14 +1563,15 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) { // Hack inv_dt for single step debugging float inv_dt = world->inv_dt > 0.0f ? world->inv_dt : 60.0f; - frictionAnchor = b3MulSV( 1.0f / totalWeight, frictionAnchor ); - b3Pos p1 = b3OffsetPos( contactCenter, frictionAnchor ); + + b3Vec3 avgAnchor = b3MulSV( 1.0f / manifold->pointCount, anchorSum ); + b3Pos p1 = b3OffsetPos( contactCenter, avgAnchor ); b3Vec3 frictionForce = b3MulSV( 0.5f * inv_dt, manifold->frictionImpulse ); b3Pos p2 = b3OffsetPos( p1, b3MulSV( draw->forceScale, frictionForce ) ); draw->DrawSegmentFcn( p1, p2, frictionColor, draw->context ); draw->DrawPointFcn( p1, 5.0f, frictionColor, draw->context ); - p1 = b3OffsetPos( p1, b3MulSV( 0.05f * lengthScale, normal ) ); + p1 = b3OffsetPos( p1, b3MulSV(0.05f * lengthScale, normal) ); char buffer[32]; snprintf( buffer, B3_ARRAY_COUNT( buffer ), "%.2f", b3Length( frictionForce ) ); draw->DrawStringFcn( p1, buffer, b3_colorWhite, draw->context ); @@ -2023,7 +1610,7 @@ void b3World_Draw( b3WorldId worldId, b3DebugDraw* draw, uint64_t maskBits ) while ( shapeId != B3_NULL_INDEX ) { b3Shape* shape = b3Array_Get( world->shapes, shapeId ); - aabb = b3AABB_Union( aabb, world->fatAABBs.data[shapeId] ); + aabb = b3AABB_Union( aabb, shape->fatAABB ); shapeCount += 1; shapeId = shape->nextShapeId; } @@ -2359,10 +1946,10 @@ void b3World_EnableSleeping( b3WorldId worldId, bool flag ) if ( flag == false ) { - int setCount = b3GetSolverSetCount( world ); + int setCount = world->solverSets.count; for ( int i = b3_firstSleepingSet; i < setCount; ++i ) { - b3SolverSet* set = b3GetSolverSet( world, i ); + b3SolverSet* set = b3Array_Get( world->solverSets, i ); if ( set->bodySims.count > 0 ) { b3WakeSolverSet( world, i ); @@ -2396,17 +1983,6 @@ bool b3World_IsWarmStartingEnabled( b3WorldId worldId ) return world->enableWarmStarting; } -void b3World_EnableSSE2Fallback( b3WorldId worldId, bool flag ) -{ - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return; - } - - world->simdWidth = flag ? 4 : b3GetSIMDWidth(); -} - int b3World_GetAwakeBodyCount( b3WorldId worldId ) { b3World* world = b3GetUnlockedWorldFromId( worldId ); @@ -2414,7 +1990,7 @@ int b3World_GetAwakeBodyCount( b3WorldId worldId ) { return 0; } - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); return awakeSet->bodySims.count; } @@ -2456,55 +2032,6 @@ float b3World_GetRestitutionThreshold( b3WorldId worldId ) return world->restitutionThreshold; } -void b3World_SetRestitutionIterations( b3WorldId worldId, int iterations ) -{ - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return; - } - - iterations = b3ClampInt( iterations, 0, B3_MAX_RESTITUTION_ITERATIONS ); - if ( iterations == world->restitutionIterations ) - { - return; - } - - B3_REC( world, WorldSetRestitutionIterations, worldId, iterations ); - - world->restitutionIterations = iterations; -} - -int b3World_GetRestitutionIterations( b3WorldId worldId ) -{ - b3World* world = b3GetWorldFromId( worldId ); - return world->restitutionIterations; -} - -void b3World_EnableRestitutionPropagation( b3WorldId worldId, bool flag ) -{ - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return; - } - - if ( flag == world->enableRestitutionPropagation ) - { - return; - } - - B3_REC( world, WorldEnableRestitutionPropagation, worldId, flag ); - - world->enableRestitutionPropagation = flag; -} - -bool b3World_IsRestitutionPropagationEnabled( b3WorldId worldId ) -{ - b3World* world = b3GetWorldFromId( worldId ); - return world->enableRestitutionPropagation; -} - void b3World_SetHitEventThreshold( b3WorldId worldId, float value ) { b3World* world = b3GetUnlockedWorldFromId( worldId ); @@ -2580,27 +2107,6 @@ float b3World_GetMaximumLinearSpeed( b3WorldId worldId ) return world->maxLinearSpeed; } -void b3World_SetIsotropicInertiaTolerance( b3WorldId worldId, float tolerance ) -{ - B3_ASSERT( b3IsValidFloat( tolerance ) ); - - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) - { - return; - } - - B3_REC( world, WorldSetIsotropicInertiaTolerance, worldId, tolerance ); - - world->isotropicInertiaTolerance = b3ClampFloat( tolerance, 0.0f, 1.0f ); -} - -float b3World_GetIsotropicInertiaTolerance( b3WorldId worldId ) -{ - b3World* world = b3GetWorldFromId( worldId ); - return world->isotropicInertiaTolerance; -} - b3Profile b3World_GetProfile( b3WorldId worldId ) { b3World* world = b3GetUnlockedWorldFromId( worldId ); @@ -2611,6 +2117,70 @@ b3Profile b3World_GetProfile( b3WorldId worldId ) return world->profile; } +b3Counters b3World_GetCounters( b3WorldId worldId ) +{ + b3World* world = b3GetUnlockedWorldFromId( worldId ); + if ( world == NULL ) + { + return (b3Counters){ 0 }; + } + + b3Counters s = { 0 }; + s.bodyCount = b3GetIdCount( &world->bodyIdPool ); + s.shapeCount = b3GetIdCount( &world->shapeIdPool ); + s.contactCount = b3GetIdCount( &world->contactIdPool ); + s.jointCount = b3GetIdCount( &world->jointIdPool ); + s.islandCount = b3GetIdCount( &world->islandIdPool ); + + b3DynamicTree* staticTree = world->broadPhase.trees + b3_staticBody; + s.staticTreeHeight = b3DynamicTree_GetHeight( staticTree ); + + b3DynamicTree* dynamicTree = world->broadPhase.trees + b3_dynamicBody; + b3DynamicTree* kinematicTree = world->broadPhase.trees + b3_kinematicBody; + s.treeHeight = b3MaxInt( b3DynamicTree_GetHeight( dynamicTree ), b3DynamicTree_GetHeight( kinematicTree ) ); + + s.satCallCount = world->satCallCount; + s.satCacheHitCount = world->satCacheHitCount; + memcpy( s.manifoldCounts, world->manifoldCounts, B3_CONTACT_MANIFOLD_COUNT_BUCKETS * sizeof( int ) ); + s.stackUsed = world->stack.maxAllocation; + s.byteCount = b3GetByteCount(); + s.taskCount = world->taskCount; + + _Static_assert( B3_GRAPH_COLOR_COUNT == sizeof( s.colorCounts ) / sizeof( s.colorCounts[0] ), "colorCounts size mismatch" ); + + s.awakeContactCount = 0; + for ( int i = 0; i < B3_GRAPH_COLOR_COUNT; ++i ) + { + b3GraphColor* color = world->constraintGraph.colors + i; + int colorContactCount = color->convexContacts.count + color->contacts.count; + s.colorCounts[i] = colorContactCount + color->jointSims.count; + s.awakeContactCount += colorContactCount; + } + s.awakeContactCount += world->solverSets.data[b3_awakeSet].contactIndices.count; + + s.recycledContactCount = 0; + s.arenaCapacity = 0; + s.distanceIterations = 0; + s.pushBackIterations = 0; + s.rootIterations = 0; + for ( int i = 0; i < world->workerCount; ++i ) + { + s.recycledContactCount += world->taskContexts.data[i].recycledContactCount; + + s.distanceIterations = b3MaxInt( s.distanceIterations, world->taskContexts.data[i].distanceIterations ); + s.pushBackIterations = b3MaxInt( s.pushBackIterations, world->taskContexts.data[i].pushBackIterations ); + s.rootIterations = b3MaxInt( s.rootIterations, world->taskContexts.data[i].rootIterations ); + + int peak = world->taskContexts.data[i].arena.shared->peakDemand; + if ( peak > s.arenaCapacity ) + { + s.arenaCapacity = peak; + } + } + + return s; +} + b3Capacity b3World_GetMaxCapacity( b3WorldId worldId ) { b3World* world = b3GetUnlockedWorldFromId( worldId ); @@ -2663,31 +2233,14 @@ void b3World_SetWorkerCount( b3WorldId worldId, int count ) return; } - int clampedCount = b3ClampInt( count, 1, B3_MAX_WORKERS ); - - if ( clampedCount == world->workerCount ) + if ( count == world->workerCount ) { return; } - if ( world->enqueueTaskFcn == b3DefaultAddTaskFcn && clampedCount > 1 ) - { - world->useScheduler = true; - world->enqueueTaskFcn = b3SchedulerEnqueueTask; - world->finishTaskFcn = b3SchedulerFinishTask; - } - b3DestroyWorkerContexts( world ); - world->workerCount = clampedCount; + world->workerCount = b3ClampInt( count, 1, B3_MAX_WORKERS ); b3CreateWorkerContexts( world ); - - if ( world->scheduler != NULL ) - { - // The scheduler will be recreated on the next world step. - b3DestroyScheduler( world->scheduler ); - world->scheduler = NULL; - world->userTaskContext = NULL; - } } int b3World_GetWorkerCount( b3WorldId worldId ) @@ -2725,8 +2278,32 @@ void b3World_StopRecording( b3WorldId worldId ) b3StopRecordingInternal( world ); } -static uint64_t b3GetWorldByteCount( b3World* world, bool log ) +static FILE* b3OpenFile( const char* fileName ) { + FILE* file = NULL; + +#if defined( _MSC_VER ) + errno_t e = fopen_s( &file, fileName, "w" ); + if ( e != 0 ) + { + return NULL; + } +#else + file = fopen( fileName, "w" ); +#endif + + return file; +} + +void b3World_DumpMemoryStats( b3WorldId worldId ) +{ + b3World* world = b3GetUnlockedWorldFromId( worldId ); + if ( world == NULL ) + { + return; + } + + // Large worlds can exceed 2GB, sum in 64 bits uint64_t total = 0; // id pools @@ -2738,16 +2315,13 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) int shapeIdBytes = b3GetIdBytes( &world->shapeIdPool ); total += (uint64_t)bodyIdBytes + solverSetIdBytes + jointIdBytes + contactIdBytes + islandIdBytes + shapeIdBytes; - if ( log ) - { - b3Log( "id pools" ); - b3Log( "body ids: %d", bodyIdBytes ); - b3Log( "solver set ids: %d", solverSetIdBytes ); - b3Log( "joint ids: %d", jointIdBytes ); - b3Log( "contact ids: %d", contactIdBytes ); - b3Log( "island ids: %d", islandIdBytes ); - b3Log( "shape ids: %d", shapeIdBytes ); - } + b3Log( "id pools" ); + b3Log( "body ids: %d", bodyIdBytes ); + b3Log( "solver set ids: %d", solverSetIdBytes ); + b3Log( "joint ids: %d", jointIdBytes ); + b3Log( "contact ids: %d", contactIdBytes ); + b3Log( "island ids: %d", islandIdBytes ); + b3Log( "shape ids: %d", shapeIdBytes ); // Islands own per-island body/contact/joint link arrays int islandLinkBytes = 0; @@ -2761,7 +2335,7 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) // world arrays int bodyArrayBytes = b3Array_ByteCount( world->bodies ); - int solverSetArrayBytes = b3Array_ByteCount( world->sleepingSets ); + int solverSetArrayBytes = b3Array_ByteCount( world->solverSets ); int jointArrayBytes = b3Array_ByteCount( world->joints ); int contactArrayBytes = b3Array_ByteCount( world->contacts ); int islandArrayBytes = b3Array_ByteCount( world->islands ); @@ -2770,18 +2344,15 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) total += (uint64_t)bodyArrayBytes + solverSetArrayBytes + jointArrayBytes + contactArrayBytes + islandArrayBytes + islandLinkBytes + shapeArrayBytes + sensorArrayBytes; - if ( log ) - { - b3Log( "world arrays" ); - b3Log( "bodies: %d", bodyArrayBytes ); - b3Log( "solver sets: %d", solverSetArrayBytes ); - b3Log( "joints: %d", jointArrayBytes ); - b3Log( "contacts: %d", contactArrayBytes ); - b3Log( "islands: %d", islandArrayBytes ); - b3Log( "island links: %d", islandLinkBytes ); - b3Log( "shapes: %d", shapeArrayBytes ); - b3Log( "sensors: %d", sensorArrayBytes ); - } + b3Log( "world arrays" ); + b3Log( "bodies: %d", bodyArrayBytes ); + b3Log( "solver sets: %d", solverSetArrayBytes ); + b3Log( "joints: %d", jointArrayBytes ); + b3Log( "contacts: %d", contactArrayBytes ); + b3Log( "islands: %d", islandArrayBytes ); + b3Log( "island links: %d", islandLinkBytes ); + b3Log( "shapes: %d", shapeArrayBytes ); + b3Log( "sensors: %d", sensorArrayBytes ); // Sensors own overlap tracking arrays. The sensor array is dense. int sensorOverlapBytes = 0; @@ -2794,11 +2365,8 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) } total += sensorOverlapBytes; - if ( log ) - { - b3Log( "owned arrays" ); - b3Log( "sensor overlaps: %d", sensorOverlapBytes ); - } + b3Log( "owned arrays" ); + b3Log( "sensor overlaps: %d", sensorOverlapBytes ); // Shared hull database. The map owns a combined bucket and metadata allocation // plus the small map struct. Each stored key is an owned clone sized by byteCount. @@ -2813,37 +2381,31 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) } total += hullMapBytes + hullDataBytes; - if ( log ) - { - b3Log( "hulls" ); - b3Log( "database: %d (%d, %d)", (int)hullMapBytes, hullCount, hullBucketCount ); - b3Log( "hull data: %d", (int)hullDataBytes ); - } + b3Log( "hulls" ); + b3Log( "database: %llu (%d, %d)", (unsigned long long)hullMapBytes, hullCount, hullBucketCount ); + b3Log( "hull data: %llu", (unsigned long long)hullDataBytes ); // broad-phase int staticTreeBytes = b3DynamicTree_GetByteCount( world->broadPhase.trees + b3_staticBody ); int kinematicTreeBytes = b3DynamicTree_GetByteCount( world->broadPhase.trees + b3_kinematicBody ); int dynamicTreeBytes = b3DynamicTree_GetByteCount( world->broadPhase.trees + b3_dynamicBody ); + int movedBytes = 0; + for ( int i = 0; i < b3_bodyTypeCount; ++i ) + { + movedBytes += b3GetBitSetBytes( &world->broadPhase.movedProxies[i] ); + } + int moveArrayBytes = b3Array_ByteCount( world->broadPhase.moveArray ); b3HashSet* pairSet = &world->broadPhase.pairSet; int pairSetBytes = b3GetHashSetBytes( pairSet ); - total += (uint64_t)staticTreeBytes + kinematicTreeBytes + dynamicTreeBytes + pairSetBytes; + total += (uint64_t)staticTreeBytes + kinematicTreeBytes + dynamicTreeBytes + movedBytes + moveArrayBytes + pairSetBytes; - if ( log ) - { - b3Log( "broad-phase" ); - b3Log( "static tree: %d", staticTreeBytes ); - b3Log( "kinematic tree: %d", kinematicTreeBytes ); - b3Log( "dynamic tree: %d", dynamicTreeBytes ); - b3Log( "pairSet: %d (%d, %d)", pairSetBytes, pairSet->count, pairSet->capacity ); - } - - int stepContextBytes = (int)sizeof( b3StepContext ); - total += (uint64_t)stepContextBytes; - - if ( log ) - { - b3Log( "step context: %d", stepContextBytes ); - } + b3Log( "broad-phase" ); + b3Log( "static tree: %d", staticTreeBytes ); + b3Log( "kinematic tree: %d", kinematicTreeBytes ); + b3Log( "dynamic tree: %d", dynamicTreeBytes ); + b3Log( "movedProxies: %d", movedBytes ); + b3Log( "moveArray: %d", moveArrayBytes ); + b3Log( "pairSet: %d (%d, %d)", pairSetBytes, pairSet->count, pairSet->capacity ); // Manifold block allocators, one per manifold point count int manifoldArrayBytes = b3Array_ByteCount( world->manifoldAllocators ); @@ -2856,12 +2418,9 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) } total += (uint64_t)manifoldArrayBytes + manifoldBlockBytes; - if ( log ) - { - b3Log( "manifold allocators" ); - b3Log( "allocator array: %d", manifoldArrayBytes ); - b3Log( "blocks: %d", manifoldBlockBytes ); - } + b3Log( "manifold allocators" ); + b3Log( "allocator array: %d", manifoldArrayBytes ); + b3Log( "blocks: %d", manifoldBlockBytes ); // solver sets int bodySimCapacity = 0; @@ -2869,10 +2428,10 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) int jointSimCapacity = 0; int contactIndexCapacity = 0; int islandSimCapacity = 0; - int solverSetCapacity = b3GetSolverSetCount( world ); + int solverSetCapacity = world->solverSets.count; for ( int i = 0; i < solverSetCapacity; ++i ) { - b3SolverSet* set = b3GetSolverSet( world, i ); + b3SolverSet* set = world->solverSets.data + i; if ( set->setIndex == B3_NULL_INDEX ) { continue; @@ -2892,15 +2451,12 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) int setIslandSimBytes = islandSimCapacity * (int)sizeof( b3IslandSim ); total += (uint64_t)setBodySimBytes + setBodyStateBytes + setJointSimBytes + setContactSimBytes + setIslandSimBytes; - if ( log ) - { - b3Log( "solver sets" ); - b3Log( "body sim: %d", setBodySimBytes ); - b3Log( "body state: %d", setBodyStateBytes ); - b3Log( "joint sim: %d", setJointSimBytes ); - b3Log( "contact sim: %d", setContactSimBytes ); - b3Log( "island sim: %d", setIslandSimBytes ); - } + b3Log( "solver sets" ); + b3Log( "body sim: %d", setBodySimBytes ); + b3Log( "body state: %d", setBodyStateBytes ); + b3Log( "joint sim: %d", setJointSimBytes ); + b3Log( "contact sim: %d", setContactSimBytes ); + b3Log( "island sim: %d", setIslandSimBytes ); // constraint graph int bodyBitSetBytes = 0; @@ -2915,13 +2471,10 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) } total += (uint64_t)bodyBitSetBytes + graphJointSimBytes + graphContactBytes; - if ( log ) - { - b3Log( "constraint graph" ); - b3Log( "body bit sets: %d", bodyBitSetBytes ); - b3Log( "joint sim: %d", graphJointSimBytes ); - b3Log( "contact sim: %d", graphContactBytes ); - } + b3Log( "constraint graph" ); + b3Log( "body bit sets: %d", bodyBitSetBytes ); + b3Log( "joint sim: %d", graphJointSimBytes ); + b3Log( "contact sim: %d", graphContactBytes ); // Per worker task storage and its bit sets int taskContextBytes = b3Array_ByteCount( world->taskContexts ); @@ -2929,10 +2482,10 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) { b3TaskContext* taskContext = world->taskContexts.data + i; taskContextBytes += b3Array_ByteCount( taskContext->sensorHits ); - taskContextBytes += b3Array_ByteCount( taskContext->pairKeys ); taskContextBytes += b3GetBitSetBytes( &taskContext->contactStateBitSet ); taskContextBytes += b3GetBitSetBytes( &taskContext->jointStateBitSet ); taskContextBytes += b3GetBitSetBytes( &taskContext->hitEventBitSet ); + taskContextBytes += b3GetBitSetBytes( &taskContext->enlargedSimBitSet ); taskContextBytes += b3GetBitSetBytes( &taskContext->awakeIslandBitSet ); } @@ -2944,12 +2497,9 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) } total += (uint64_t)taskContextBytes + sensorTaskContextBytes; - if ( log ) - { - b3Log( "task contexts" ); - b3Log( "worker: %d", taskContextBytes ); - b3Log( "sensor: %d", sensorTaskContextBytes ); - } + b3Log( "task contexts" ); + b3Log( "worker: %d", taskContextBytes ); + b3Log( "sensor: %d", sensorTaskContextBytes ); // Double buffered event arrays int eventBytes = 0; @@ -2964,10 +2514,7 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) eventBytes += b3Array_ByteCount( world->jointEvents ); total += eventBytes; - if ( log ) - { - b3Log( "events: %d", eventBytes ); - } + b3Log( "events: %d", eventBytes ); // Debug draw bit sets int debugBytes = 0; @@ -2977,97 +2524,50 @@ static uint64_t b3GetWorldByteCount( b3World* world, bool log ) debugBytes += b3GetBitSetBytes( &world->debugIslandSet ); total += debugBytes; - if ( log ) - { - b3Log( "debug draw: %d", debugBytes ); - } + b3Log( "debug draw: %d", debugBytes ); // stack allocator total += world->stack.capacity; + b3Log( "stack allocator: %d", world->stack.capacity ); - if ( log ) - { - b3Log( "stack allocator: %d", world->stack.capacity ); - b3Log( "total: %u KB", (uint32_t)( total / 1024 ) ); - } - - return total; + b3Log( "total: %llu", (unsigned long long)total ); } -void b3World_DumpMemoryStats( b3WorldId worldId ) +void b3World_DumpShapeBounds( b3WorldId worldId, b3BodyType type ) { + B3_ASSERT( b3_staticBody <= type && type <= b3_dynamicBody ); b3World* world = b3GetUnlockedWorldFromId( worldId ); if ( world == NULL ) { return; } - b3GetWorldByteCount( world, true ); -} - -b3Counters b3World_GetCounters( b3WorldId worldId ) -{ - b3World* world = b3GetUnlockedWorldFromId( worldId ); - if ( world == NULL ) + FILE* file = b3OpenFile( "box3d_bounds.txt" ); + if ( file == NULL ) { - return (b3Counters){ 0 }; + return; } - b3Counters s = { 0 }; - s.bodyCount = b3GetIdCount( &world->bodyIdPool ); - s.shapeCount = b3GetIdCount( &world->shapeIdPool ); - s.contactCount = b3GetIdCount( &world->contactIdPool ); - s.jointCount = b3GetIdCount( &world->jointIdPool ); - s.islandCount = b3GetIdCount( &world->islandIdPool ); + b3DynamicTree* tree = world->broadPhase.trees + type; + b3TreeNode* nodes = tree->nodes; - b3DynamicTree* staticTree = world->broadPhase.trees + b3_staticBody; - s.staticTreeHeight = b3DynamicTree_GetHeight( staticTree ); - - b3DynamicTree* dynamicTree = world->broadPhase.trees + b3_dynamicBody; - b3DynamicTree* kinematicTree = world->broadPhase.trees + b3_kinematicBody; - s.treeHeight = b3MaxInt( b3DynamicTree_GetHeight( dynamicTree ), b3DynamicTree_GetHeight( kinematicTree ) ); - - s.satCallCount = world->satCallCount; - s.satCacheHitCount = world->satCacheHitCount; - memcpy( s.manifoldCounts, world->manifoldCounts, B3_MAX_MANIFOLDS * sizeof( int ) ); - s.stackUsed = world->stack.maxAllocation; - s.byteCount = (int64_t)b3GetWorldByteCount( world, false ); - s.taskCount = world->stepContext->taskCount; - s.enqueueCount = world->stepContext->enqueueCount; - - _Static_assert( B3_GRAPH_COLOR_COUNT == sizeof( s.colorCounts ) / sizeof( s.colorCounts[0] ), "colorCounts size mismatch" ); - - s.awakeContactCount = 0; - for ( int i = 0; i < B3_GRAPH_COLOR_COUNT; ++i ) + uint16_t requiredFlags = b3_allocatedNode | b3_leafNode; + int capacity = tree->nodeCapacity; + for ( int i = 0; i < capacity; ++i ) { - b3GraphColor* color = world->constraintGraph.colors + i; - int colorContactCount = color->convexContacts.count + color->contacts.count; - s.colorCounts[i] = colorContactCount + color->jointSims.count; - s.awakeContactCount += colorContactCount; - } - s.awakeContactCount += b3GetSolverSet( world, b3_awakeSet )->contactIndices.count; - - s.recycledContactCount = 0; - s.arenaCapacity = 0; - s.distanceIterations = 0; - s.pushBackIterations = 0; - s.rootIterations = 0; - for ( int i = 0; i < world->workerCount; ++i ) - { - s.recycledContactCount += world->taskContexts.data[i].recycledContactCount; - - s.distanceIterations = b3MaxInt( s.distanceIterations, world->taskContexts.data[i].distanceIterations ); - s.pushBackIterations = b3MaxInt( s.pushBackIterations, world->taskContexts.data[i].pushBackIterations ); - s.rootIterations = b3MaxInt( s.rootIterations, world->taskContexts.data[i].rootIterations ); - - int peak = world->taskContexts.data[i].arena.shared->peakDemand; - if ( peak > s.arenaCapacity ) + b3TreeNode* node = nodes + i; + if ( ( node->flags & requiredFlags ) != requiredFlags ) { - s.arenaCapacity = peak; + // skip internal and free nodes + continue; } + + b3Vec3 a = node->aabb.lowerBound; + b3Vec3 b = node->aabb.upperBound; + fprintf( file, "%.9f %.9f %.9f %.9f %.9f %.9f\n", a.x, a.y, a.z, b.x, b.y, b.z ); } - return s; + fclose( file ); } typedef struct WorldQueryContext @@ -3147,17 +2647,6 @@ b3TreeStats b3World_OverlapAABB( b3WorldId worldId, b3AABB aabb, b3QueryFilter f return treeStats; } -b3TreeStats b3World_OverlapAABB_Static( b3WorldId worldId, b3AABB aabb, b3QueryFilter filter, b3OverlapResultFcn* fcn, - void* context ) -{ - b3World* world = b3GetWorldFromId( worldId ); - B3_ASSERT( b3IsValidAABB( aabb ) ); - - WorldQueryContext worldContext = { world, fcn, filter, context }; - return b3DynamicTree_QueryRelaxed( world->broadPhase.trees + b3_staticBody, aabb, filter.maskBits, false, - TreeQueryCallback, &worldContext ); -} - typedef struct WorldOverlapContext { b3World* world; @@ -3253,21 +2742,6 @@ b3TreeStats b3World_OverlapShape( b3WorldId worldId, b3Pos origin, const b3Shape return treeStats; } -b3TreeStats b3World_OverlapShape_Static( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, - b3QueryFilter filter, b3OverlapResultFcn* fcn, void* context ) -{ - b3World* world = b3GetWorldFromId( worldId ); - B3_ASSERT( b3IsValidPosition( origin ) ); - - b3AABB aabb = b3OffsetAABB( b3MakeAABB( proxy->points, proxy->count, proxy->radius ), origin ); - WorldOverlapContext worldContext = { - world, fcn, filter, *proxy, origin, context, - }; - - return b3DynamicTree_QueryRelaxed( world->broadPhase.trees + b3_staticBody, aabb, filter.maskBits, false, - b3TreeOverlapCallback, &worldContext ); -} - typedef struct WorldMoverContext { b3World* world; @@ -3342,6 +2816,7 @@ void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mov b3Vec3 r = { mover->radius, mover->radius, mover->radius }; + // Relative box lifted to world float with outward rounding, conservative for the tree b3AABB relBox; relBox.lowerBound = b3Sub( b3Min( mover->center1, mover->center2 ), r ); relBox.upperBound = b3Add( b3Max( mover->center1, mover->center2 ), r ); @@ -3358,6 +2833,7 @@ void b3World_CollideMover( b3WorldId worldId, b3Pos origin, const b3Capsule* mov if ( world->recording != NULL ) { + // CollideMover returns void: no treestats tail, just the per-shape plane batches. b3RecPatchU32( &recWriter.buf, recWriter.countOffset, recWriter.hitCount ); b3RecQueryCommit( world->recording, b3_recOpQueryCollideMover, &recWriter ); } @@ -3483,20 +2959,6 @@ b3TreeStats b3World_CastRay( b3WorldId worldId, b3Pos origin, b3Vec3 translation return treeStats; } -b3TreeStats b3World_CastRay_Static( b3WorldId worldId, b3Pos origin, b3Vec3 translation, b3QueryFilter filter, - b3CastResultFcn* fcn, void* context ) -{ - b3World* world = b3GetWorldFromId( worldId ); - B3_ASSERT( b3IsValidPosition( origin ) ); - B3_ASSERT( b3IsValidVec3( translation ) ); - - b3RayCastInput input = { b3ToVec3( origin ), translation, 1.0f }; - WorldRayCastContext worldContext = { world, fcn, filter, 1.0f, origin, context }; - - return b3DynamicTree_RayCastRelaxed( world->broadPhase.trees + b3_staticBody, &input, filter.maskBits, false, - RayCastCallback, &worldContext ); -} - // This callback finds the closest hit. This is the most common callback used in games. static float b3RayCastClosestFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, int triangleIndex, int childIndex, void* context ) @@ -3710,32 +3172,6 @@ b3TreeStats b3World_CastShape( b3WorldId worldId, b3Pos origin, const b3ShapePro return treeStats; } -b3TreeStats b3World_CastShape_Static( b3WorldId worldId, b3Pos origin, const b3ShapeProxy* proxy, b3Vec3 translation, - b3QueryFilter filter, b3CastResultFcn* fcn, void* context ) -{ - b3World* world = b3GetWorldFromId( worldId ); - B3_ASSERT( b3IsValidPosition( origin ) ); - B3_ASSERT( b3IsValidVec3( translation ) ); - - WorldShapeCastContext worldContext = { 0 }; - worldContext.world = world; - worldContext.fcn = fcn; - worldContext.filter = filter; - worldContext.fraction = 1.0f; - worldContext.origin = origin; - worldContext.input.proxy = *proxy; - worldContext.input.translation = translation; - worldContext.input.maxFraction = 1.0f; - worldContext.input.canEncroach = false; - worldContext.userContext = context; - - b3AABB localBox = b3MakeAABB( proxy->points, proxy->count, proxy->radius ); - b3BoxCastInput treeInput = { b3OffsetAABB( localBox, origin ), translation, 1.0f }; - - return b3DynamicTree_BoxCastRelaxed( world->broadPhase.trees + b3_staticBody, &treeInput, filter.maskBits, false, - b3ShapeCastCallback, &worldContext ); -} - typedef struct WorldMoverCastContext { b3World* world; @@ -3986,7 +3422,7 @@ static bool ExplosionCallback( int proxyId, uint64_t userData, void* context ) b3Vec3 impulse = b3MulSV( magnitude, b3RotateVector( xf.q, direction ) ); int localIndex = body->localIndex; - b3SolverSet* set = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodyState* state = b3Array_Get( set->bodyStates, localIndex ); b3BodySim* bodySim = b3Array_Get( set->bodySims, localIndex ); state->linearVelocity = b3MulAdd( state->linearVelocity, bodySim->invMass, impulse ); @@ -4154,22 +3590,7 @@ void b3ValidateSolverSets( b3World* world ) B3_ASSERT( b3GetIdCapacity( &world->contactIdPool ) == world->contacts.count ); B3_ASSERT( b3GetIdCapacity( &world->jointIdPool ) == world->joints.count ); B3_ASSERT( b3GetIdCapacity( &world->islandIdPool ) == world->islands.count ); - B3_ASSERT( b3GetIdCapacity( &world->solverSetIdPool ) == b3GetSolverSetCount( world ) ); - - // Ensure the encoded body sim indices are correct. - for ( int contactIndex = 0; contactIndex < world->contacts.count; ++contactIndex ) - { - b3Contact* contact = world->contacts.data + contactIndex; - if ( contact->contactId == B3_NULL_INDEX ) - { - continue; - } - - b3Body* bodyA = b3Array_Get( world->bodies, contact->edges[0].bodyId ); - b3Body* bodyB = b3Array_Get( world->bodies, contact->edges[1].bodyId ); - B3_ASSERT( contact->encodedBodySimA == b3EncodeBodySimIndex( bodyA ) ); - B3_ASSERT( contact->encodedBodySimB == b3EncodeBodySimIndex( bodyB ) ); - } + B3_ASSERT( b3GetIdCapacity( &world->solverSetIdPool ) == world->solverSets.count ); int activeSetCount = 0; int totalBodyCount = 0; @@ -4178,10 +3599,10 @@ void b3ValidateSolverSets( b3World* world ) int totalIslandCount = 0; // Validate all solver sets - int setCount = b3GetSolverSetCount( world ); + int setCount = world->solverSets.count; for ( int setIndex = 0; setIndex < setCount; ++setIndex ) { - b3SolverSet* set = b3GetSolverSet( world, setIndex ); + b3SolverSet* set = world->solverSets.data + setIndex; if ( set->setIndex != B3_NULL_INDEX ) { activeSetCount += 1; @@ -4222,7 +3643,7 @@ void b3ValidateSolverSets( b3World* world ) B3_ASSERT( body->setIndex == setIndex ); B3_ASSERT( body->localIndex == i ); - uint32_t syncedFlags = body->flags & ~( b3_isFast | b3_bodyTransientFlags ); + uint32_t syncedFlags = body->flags & ~b3_bodyTransientFlags; B3_ASSERT( ( bodySim->flags & syncedFlags ) == syncedFlags ); b3BodyState* bodyState = b3GetBodyState( world, body ); @@ -4554,13 +3975,37 @@ void b3ValidateContacts( b3World* world ) bool touching = ( contact->flags & b3_contactTouchingFlag ) != 0; int setId = contact->setIndex; - b3SolverSet* set = b3GetSolverSet( world, setId ); + b3SolverSet* set = b3Array_Get( world->solverSets, setId ); if ( setId == b3_awakeSet ) { if ( touching ) { B3_ASSERT( 0 <= contact->colorIndex && contact->colorIndex < B3_GRAPH_COLOR_COUNT ); + // Validate body sim indices + b3Shape* shapeA = b3Array_Get( world->shapes, contact->shapeIdA ); + b3Shape* shapeB = b3Array_Get( world->shapes, contact->shapeIdB ); + + b3Body* bodyA = b3Array_Get( world->bodies, shapeA->bodyId ); + b3Body* bodyB = b3Array_Get( world->bodies, shapeB->bodyId ); + + if ( bodyA->type == b3_staticBody ) + { + B3_ASSERT( contact->bodySimIndexA == B3_NULL_INDEX ); + } + else + { + B3_ASSERT( contact->bodySimIndexA == bodyA->localIndex ); + } + + if ( bodyB->type == b3_staticBody ) + { + B3_ASSERT( contact->bodySimIndexB == B3_NULL_INDEX ); + } + else + { + B3_ASSERT( contact->bodySimIndexB == bodyB->localIndex ); + } if ( ( contact->flags & b3_simMeshContact ) != 0 || contact->colorIndex == B3_OVERFLOW_INDEX ) { @@ -4670,3 +4115,123 @@ void b3ValidateContacts( b3World* world ) } #endif + +#define NAME int_set +#define KEY_TY int +#define MALLOC_FN b3Alloc +#define FREE_FN b3Free +#define HASH_FN vt_hash_integer +#define CMPR_FN vt_cmpr_integer +#include "verstable.h" + +void b3World_DumpAwake( b3WorldId worldId ) +{ + b3World* world = b3GetWorldFromId( worldId ); + if ( world->locked == true ) + { + return; + } + + b3OpenDump( "box3d_dump.inl" ); + + b3Vec3 g = world->gravity; + b3Dump( "b3Vec3 gravity = {%.9g, %.9g, %.9g};\n", g.x, g.y, g.z ); + b3Dump( "b3World_SetGravity(m_worldId, gravity);\n" ); + + b3Dump( "std::vector bodies;\n" ); + b3Dump( "std::vector joints;\n\n" ); + + int_set staticBodies; + int_set_init( &staticBodies ); + + b3Body* bodies = world->bodies.data; + for ( int i = 0; i < world->bodies.count; ++i ) + { + b3Body* body = bodies + i; + + if ( body->id == B3_NULL_INDEX ) + { + continue; + } + + if ( body->setIndex != b3_awakeSet ) + { + continue; + } + + b3DumpBody( world, body ); + + // Gather + int edgeKey = body->headContactKey; + while ( edgeKey != B3_NULL_INDEX ) + { + int contactId = edgeKey >> 1; + int edgeIndex = edgeKey & 1; + + b3Contact* contact = b3Array_Get( world->contacts, contactId ); + edgeKey = contact->edges[edgeIndex].nextKey; + + if ( ( contact->flags & b3_contactTouchingFlag ) == 0 ) + { + continue; + } + + int otherIndex = 1 - edgeIndex; + b3Body* otherBody = b3Array_Get( world->bodies, contact->edges[otherIndex].bodyId ); + if ( otherBody->setIndex == b3_staticSet ) + { + (void)int_set_insert( &staticBodies, otherBody->id ); + } + } + } + + // Dump the bodies that are touching + for ( int_set_itr itr = int_set_first( &staticBodies ); int_set_is_end( itr ) == false; itr = int_set_next( itr ) ) + { + b3Body* body = b3Array_Get( world->bodies, itr.data->key ); + b3DumpBody( world, body ); + } + + int_set_cleanup( &staticBodies ); + + b3CloseDump(); +} + +void b3World_Dump( b3WorldId worldId ) +{ + b3World* world = b3GetWorldFromId( worldId ); + + if ( world->locked == true ) + { + return; + } + + b3OpenDump( "box3d_dump.inl" ); + + b3Vec3 g = world->gravity; + b3Dump( "b3Vec3 gravity = {%.9g, %.9g, %.9g};\n", g.x, g.y, g.z ); + b3Dump( "b3World_SetGravity(m_worldId, gravity);\n" ); + + b3Dump( "std::vector bodies;\n" ); + b3Dump( "std::vector joints;\n\n" ); + + b3Body* bodies = world->bodies.data; + for ( int i = 0; i < world->bodies.count; ++i ) + { + b3Body* body = bodies + i; + + if ( body->id == B3_NULL_INDEX ) + { + continue; + } + + if ( body->setIndex != b3_awakeSet ) + { + continue; + } + + b3DumpBody( world, body ); + } + + b3CloseDump(); +} diff --git a/src/physics_world.h b/src/physics_world.h index a7ecd28..8387e2a 100644 --- a/src/physics_world.h +++ b/src/physics_world.h @@ -9,7 +9,6 @@ #include "broad_phase.h" #include "constraint_graph.h" #include "id_pool.h" -#include "name_cache.h" #include "box3d/types.h" @@ -33,7 +32,6 @@ b3DeclareArray( b3SolverSet ); b3DeclareArray( b3Joint ); b3DeclareArray( b3Contact ); b3DeclareArray( b3Island ); -b3DeclareArray( b3AABB ); b3DeclareArray( b3Shape ); b3DeclareArray( b3Sensor ); b3DeclareArray( b3SensorTaskContext ); @@ -77,9 +75,6 @@ typedef struct b3TaskContext // Collect per thread sensor continuous hit events. b3Array( b3SensorHit ) sensorHits; - // Broad-phase pairs. - b3Array( uint64_t ) pairKeys; - // These bits align with the b3ConstraintGraph::contactBlocks and signal a change in contact status b3BitSet contactStateBitSet; @@ -92,6 +87,10 @@ typedef struct b3TaskContext // Fast-path flag: true when this worker set at least one bit in hitEventBitSet this step. bool hasHitEvents; + // Used to track bodies with shapes that have enlarged AABBs. This avoids having a bit array + // that is very large when there are many static shapes. + b3BitSet enlargedSimBitSet; + // Used to put islands to sleep b3BitSet awakeIslandBitSet; @@ -115,7 +114,7 @@ typedef struct b3TaskContext b3DebugLine lines[B3_DEBUG_LINE_CAPACITY]; int lineCount; - int manifoldCounts[B3_MAX_MANIFOLDS]; + int manifoldCounts[B3_CONTACT_MANIFOLD_COUNT_BUCKETS]; // Prevent false sharing char cacheLine[64]; } b3TaskContext; @@ -147,12 +146,10 @@ typedef struct b3World // Provides free list for solver sets. b3IdPool solverSetIdPool; - // Solvers sets allow body sims to be stored in contiguous arrays. The first holds static bodies. The second set - // holds disabled bodies. The third holds awake bodies. A growable array holds the sleeping islands. - // This is split up so that the static set can be accessed without being remapped during a static query while - // the physics step is concurrently putting an island to sleep (race condition). - b3SolverSet fixedSets[b3_firstSleepingSet]; - b3Array( b3SolverSet ) sleepingSets; + // Solvers sets allow sims to be stored in contiguous arrays. The first + // set is all static sims. The second set is active sims. The third set is disabled + // sims. The remaining sets are sleeping islands. + b3Array( b3SolverSet ) solverSets; // Used to create stable ids for joints b3IdPool jointIdPool; @@ -179,21 +176,11 @@ typedef struct b3World // These are sparse arrays that point into the pools above b3Array( b3Shape ) shapes; - // This follows the shape array and is split out for the hot path in the narrow phase. - b3Array( b3AABB ) fatAABBs; - - // Compound shapes are static only, so only the broad-phase static pass can meet one. This - // lets a world without compounds skip the shape type read in the pair batch. - int compoundShapeCount; - // Reference counted store of shared hull data keyed by content. Shapes hold a - // pointer to the hull stored in the db. Type erased to avoid leaking the verstable map + // pointer to the owned copy here. Opaque to avoid leaking the verstable map // type into this header. void* hullDatabase; - // Name cache for shape and body names. This works with recording. - b3NameCache names; - // This is a dense array of sensor data. b3Array( b3Sensor ) sensors; @@ -237,10 +224,7 @@ typedef struct b3World b3Vec3 gravity; float hitEventThreshold; float restitutionThreshold; - int restitutionIterations; - bool enableRestitutionPropagation; float maxLinearSpeed; - float isotropicInertiaTolerance; float contactSpeed; float contactHertz; float contactDampingRatio; @@ -254,7 +238,7 @@ typedef struct b3World b3Profile profile; int satCallCount; int satCacheHitCount; - int manifoldCounts[B3_MAX_MANIFOLDS]; + int manifoldCounts[B3_CONTACT_MANIFOLD_COUNT_BUCKETS]; b3Capacity maxCapacity; @@ -265,27 +249,24 @@ typedef struct b3World void* customFilterContext; int workerCount; - int simdWidth; b3EnqueueTaskCallback* enqueueTaskFcn; b3FinishTaskCallback* finishTaskFcn; void* userTaskContext; - struct b3StepContext* stepContext; + void* userTreeTask; struct b3Scheduler* scheduler; - bool useScheduler; void* userData; - // Non-NULL while a recording session is active. Set by b3World_StartRecording, - // cleared by b3World_StopRecording. Hooks in mutators check this before writing. - struct b3Recording* recording; - // latest inverse sub-step float inv_h; // latest inverse full-step float inv_dt; + int activeTaskCount; + int taskCount; + uint16_t worldId; bool enableSleep; @@ -293,42 +274,23 @@ typedef struct b3World // This indicates there is a world write operation in progress. This is for debugging and // not a real mutex. This should have minimal performance impact. bool locked; + + // Non-NULL while a recording session is active. Set by b3World_StartRecording, + // cleared by b3World_StopRecording. Hooks in mutators check this before writing. + struct b3Recording* recording; + bool enableWarmStarting; bool enableContinuous; bool enableSpeculative; bool inUse; } b3World; -static inline b3SolverSet* b3GetSolverSet( b3World* world, int setIndex ) -{ - if ( setIndex < b3_firstSleepingSet ) - { - B3_ASSERT( 0 <= setIndex ); - return world->fixedSets + setIndex; - } - - return b3Array_Get( world->sleepingSets, setIndex - b3_firstSleepingSet ); -} - -static inline b3SolverSet* b3GetFixedSolverSet( b3World* world, int setIndex ) -{ - B3_ASSERT( 0 <= setIndex && setIndex < b3_firstSleepingSet ); - return world->fixedSets + setIndex; -} - -static inline int b3GetSolverSetCount( const b3World* world ) -{ - return b3_firstSleepingSet + world->sleepingSets.count; -} - b3World* b3GetUnlockedWorldFromId( b3WorldId id ); b3World* b3GetWorldFromId( b3WorldId id ); b3World* b3GetUnlockedWorld( int index ); b3World* b3GetWorld( int index ); -void b3World_RebuildStaticTree( b3WorldId worldId ); - void b3ValidateConnectivity( b3World* world ); void b3ValidateSolverSets( b3World* world ); void b3ValidateContacts( b3World* world ); @@ -351,8 +313,6 @@ static inline b3Manifold* b3AllocateManifolds( b3World* world, int count ) return NULL; } - B3_ASSERT( count <= B3_MAX_MANIFOLDS ); - int index = count - 1; // Need lock because this is called from the parallel narrow phase @@ -378,11 +338,10 @@ static inline void b3FreeManifolds( b3World* world, b3Manifold* manifolds, int c return; } - B3_ASSERT( count <= B3_MAX_MANIFOLDS ); - int index = count - 1; b3LockMutex( world->manifoldAllocatorMutex ); b3BlockAllocator* allocator = b3Array_Get( world->manifoldAllocators, index ); b3FreeElement( allocator, manifolds ); b3UnlockMutex( world->manifoldAllocatorMutex ); } + diff --git a/src/platform.h b/src/platform.h index b2d6fa3..49d63a8 100644 --- a/src/platform.h +++ b/src/platform.h @@ -8,24 +8,17 @@ #include #include -#if defined( _MSC_VER ) && ( defined( _M_ARM ) || defined( _M_ARM64 ) || defined( _M_ARM64EC ) ) +// Software prefetch hint. T0 brings the line into all cache levels. +// On x86 MSVC exposes _mm_prefetch, ARM MSVC uses __prefetch instead. +// clang/gcc provide __builtin_prefetch on every target. +#if defined( B3_COMPILER_MSVC ) #include -#elif defined( _MSC_VER ) -#include -// _MM_HINT_T0 lives here. Prefetch is a platform intrinsic, not part of the SIMD kernel -// selection, so it has to survive a BOX3D_DISABLE_SIMD build. -#if defined( _M_X64 ) || defined( _M_IX86 ) -#include -#endif -#endif - -#if defined( _MSC_VER ) -#if defined( _M_X64 ) || defined( __x86_64__ ) || defined( _M_IX86 ) || defined( __i386__ ) +#if defined( B3_CPU_X86_X64 ) #define b3Prefetch( addr ) _mm_prefetch( (const char*)( addr ), _MM_HINT_T0 ) #else #define b3Prefetch( addr ) __prefetch( (const void*)( addr ) ) #endif -#elif defined( __GNUC__ ) || defined( __clang__ ) +#elif defined( B3_COMPILER_CLANG ) || defined( B3_COMPILER_GCC ) #define b3Prefetch( addr ) __builtin_prefetch( (const void*)( addr ), 0, 3 ) #else #define b3Prefetch( addr ) ( (void)( addr ) ) @@ -38,24 +31,18 @@ static inline void b3AtomicStoreInt( b3AtomicInt* a, int value ) #elif defined( __GNUC__ ) || defined( __clang__ ) __atomic_store_n( &a->value, value, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" + #error "Unsupported platform" #endif } static inline int b3AtomicLoadInt( b3AtomicInt* a ) { -#if defined( _MSC_VER ) && !defined( __clang__ ) - int value = __iso_volatile_load32( (volatile __int32*)&a->value ); -#if defined( _M_ARM ) || defined( _M_ARM64 ) || defined( _M_ARM64EC ) - __dmb( 0xB ); -#else - _ReadWriteBarrier(); -#endif - return value; +#if defined( _MSC_VER ) + return _InterlockedOr( (long*)&a->value, 0 ); #elif defined( __GNUC__ ) || defined( __clang__ ) return __atomic_load_n( &a->value, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" + #error "Unsupported platform" #endif } @@ -66,7 +53,7 @@ static inline int b3AtomicFetchAddInt( b3AtomicInt* a, int increment ) #elif defined( __GNUC__ ) || defined( __clang__ ) return __atomic_fetch_add( &a->value, increment, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" + #error "Unsupported platform" #endif } @@ -78,7 +65,7 @@ static inline bool b3AtomicCompareExchangeInt( b3AtomicInt* a, int expected, int // The value written to expected is ignored return __atomic_compare_exchange_n( &a->value, &expected, desired, false, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" + #error "Unsupported platform" #endif } @@ -89,88 +76,17 @@ static inline void b3AtomicStoreU32( b3AtomicU32* a, uint32_t value ) #elif defined( __GNUC__ ) || defined( __clang__ ) __atomic_store_n( &a->value, value, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" + #error "Unsupported platform" #endif } static inline uint32_t b3AtomicLoadU32( b3AtomicU32* a ) { -#if defined( _MSC_VER ) && !defined( __clang__ ) - uint32_t value = (uint32_t)__iso_volatile_load32( (volatile __int32*)&a->value ); -#if defined( _M_ARM ) || defined( _M_ARM64 ) || defined( _M_ARM64EC ) - __dmb( 0xB ); -#else - _ReadWriteBarrier(); -#endif - return value; +#if defined( _MSC_VER ) + return (uint32_t)_InterlockedOr( (long*)&a->value, 0 ); #elif defined( __GNUC__ ) || defined( __clang__ ) return __atomic_load_n( &a->value, __ATOMIC_SEQ_CST ); #else -#error "Unsupported platform" -#endif -} - -// Relaxed load on a plain word. Lets a racing reader peek before paying for a read modify write. -static inline uint32_t b3AtomicLoadU32Raw( const uint32_t* a ) -{ -#if defined( _MSC_VER ) && !defined( __clang__ ) - return (uint32_t)__iso_volatile_load32( (const volatile __int32*)a ); -#elif defined( __GNUC__ ) || defined( __clang__ ) - return __atomic_load_n( a, __ATOMIC_RELAXED ); -#else -#error "Unsupported platform" -#endif -} - -static inline void b3AtomicStoreU32Raw( uint32_t* a, uint32_t value ) -{ -#if defined( _MSC_VER ) && !defined( __clang__ ) - __iso_volatile_store32( (volatile __int32*)a, (__int32)value ); -#elif defined( __GNUC__ ) || defined( __clang__ ) - __atomic_store_n( a, value, __ATOMIC_RELAXED ); -#else -#error "Unsupported platform" -#endif -} - -static inline uint32_t b3AtomicFetchOrU32( uint32_t* a, uint32_t mask ) -{ -#if defined( _MSC_VER ) - return (uint32_t)_InterlockedOr( (long*)a, (long)mask ); -#elif defined( __GNUC__ ) || defined( __clang__ ) - return __atomic_fetch_or( a, mask, __ATOMIC_SEQ_CST ); -#else -#error "Unsupported platform" -#endif -} - -static inline int64_t b3AtomicFetchAddI64( b3AtomicI64* a, int64_t increment ) -{ -#if defined( _MSC_VER ) - return (int64_t)_InterlockedExchangeAdd64( (__int64*)&a->value, (__int64)increment ); -#elif defined( __GNUC__ ) || defined( __clang__ ) - return __atomic_fetch_add( &a->value, increment, __ATOMIC_SEQ_CST ); -#else -#error "Unsupported platform" -#endif -} - -static inline int64_t b3AtomicLoadI64( b3AtomicI64* a ) -{ -#if defined( _MSC_VER ) && !defined( __clang__ ) && !defined( _M_ARM ) - int64_t value = __iso_volatile_load64( (volatile __int64*)&a->value ); -#if defined( _M_ARM64 ) || defined( _M_ARM64EC ) - __dmb( 0xB ); -#else - _ReadWriteBarrier(); -#endif - return value; -#elif defined( _MSC_VER ) && !defined( __clang__ ) - // 32-bit ARM has no plain atomic 64-bit load - return _InterlockedOr64( (__int64*)&a->value, 0 ); -#elif defined( __GNUC__ ) || defined( __clang__ ) - return __atomic_load_n( &a->value, __ATOMIC_SEQ_CST ); -#else -#error "Unsupported platform" + #error "Unsupported platform" #endif } diff --git a/src/pogo_joint.c b/src/pogo_joint.c deleted file mode 100644 index cd51be6..0000000 --- a/src/pogo_joint.c +++ /dev/null @@ -1,449 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "body.h" -#include "core.h" -#include "joint.h" -#include "math_internal.h" -#include "physics_world.h" -#include "recording.h" -#include "solver.h" -#include "solver_set.h" - -// needed for dll export -#include "box3d/box3d.h" - -#include - -void b3PogoJoint_SetRestLength( b3JointId jointId, float length ) -{ - B3_ASSERT( b3IsValidFloat( length ) && length >= 0.0f ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - if ( joint->pogoJoint.restLength == length ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetRestLength, jointId, length ); - joint->pogoJoint.restLength = length; -} - -float b3PogoJoint_GetRestLength( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.restLength; -} - -void b3PogoJoint_SetSpringHertz( b3JointId jointId, float hertz ) -{ - B3_ASSERT( b3IsValidFloat( hertz ) && hertz >= 0.0f ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - if ( joint->pogoJoint.hertz == hertz ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetSpringHertz, jointId, hertz ); - joint->pogoJoint.hertz = hertz; -} - -float b3PogoJoint_GetSpringHertz( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.hertz; -} - -void b3PogoJoint_SetSpringDampingRatio( b3JointId jointId, float dampingRatio ) -{ - B3_ASSERT( b3IsValidFloat( dampingRatio ) && dampingRatio >= 0.0f ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - if ( joint->pogoJoint.dampingRatio == dampingRatio ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetSpringDampingRatio, jointId, dampingRatio ); - joint->pogoJoint.dampingRatio = dampingRatio; -} - -float b3PogoJoint_GetSpringDampingRatio( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.dampingRatio; -} - -void b3PogoJoint_SetMaxTensionForce( b3JointId jointId, float force ) -{ - B3_ASSERT( b3IsValidFloat( force ) && force >= 0.0f ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - if ( joint->pogoJoint.maxTensionForce == force ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetMaxTensionForce, jointId, force ); - joint->pogoJoint.maxTensionForce = force; -} - -float b3PogoJoint_GetMaxTensionForce(b3JointId jointId) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.maxTensionForce; -} - -void b3PogoJoint_SetMaxCompressionForce(b3JointId jointId, float force) -{ - B3_ASSERT( b3IsValidFloat( force ) && force >= 0.0f ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - if ( joint->pogoJoint.maxCompressionForce == force ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetMaxCompressionForce, jointId, force ); - joint->pogoJoint.maxCompressionForce = force; -} - -float b3PogoJoint_GetMaxCompressionForce(b3JointId jointId) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.maxCompressionForce; -} - -void b3PogoJoint_SetNormal( b3JointId jointId, b3Vec3 normal ) -{ - B3_ASSERT( b3IsValidVec3( normal ) && b3IsNormalized( normal ) ); - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - b3Vec3 current = joint->pogoJoint.normal; - if ( current.x == normal.x && current.y == normal.y && current.z == normal.z ) - { - return; - } - - b3World* world = b3GetWorld( jointId.world0 ); - B3_REC( world, PogoJointSetNormal, jointId, normal ); - joint->pogoJoint.normal = normal; -} - -b3Vec3 b3PogoJoint_GetNormal( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.normal; -} - -float b3PogoJoint_GetCurrentLength( b3JointId jointId ) -{ - b3World* world = b3GetWorld( jointId.world0 ); - b3JointSim* base = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - - b3WorldTransform worldTransformA = b3GetBodyTransform( world, base->bodyIdA ); - b3Transform transformA = b3ToRelativeTransform( worldTransformA, worldTransformA.p ); - b3Transform transformB = - b3ToRelativeTransform( b3GetBodyTransform( world, base->bodyIdB ), worldTransformA.p ); - - b3Vec3 axis = b3RotateVector( b3MulQuat( transformB.q, base->localFrameB.q ), b3Vec3_axisY ); - b3Vec3 pA = b3TransformPoint( transformA, base->localFrameA.p ); - b3Vec3 pB = b3TransformPoint( transformB, base->localFrameB.p ); - return b3Dot( b3Sub( pB, pA ), axis ); -} - -float b3PogoJoint_GetImpulse( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.impulse; -} - -float b3PogoJoint_GetCurrentSpeed( b3JointId jointId ) -{ - b3JointSim* joint = b3GetJointSimCheckType( jointId, b3_pogoJoint ); - return joint->pogoJoint.velocity; -} - -b3Vec3 b3GetPogoJointForce( b3World* world, b3JointSim* base ) -{ - return b3MulSV( world->inv_h * base->pogoJoint.impulse, base->pogoJoint.normal ); -} - -void b3PreparePogoJoint( b3JointSim* base, b3StepContext* context ) -{ - B3_ASSERT( base->type == b3_pogoJoint ); - - b3World* world = context->world; - - // chase body id to the solver set where the body lives - int idA = base->bodyIdA; - int idB = base->bodyIdB; - - b3Body* bodyA = b3Array_Get( world->bodies, idA ); - b3Body* bodyB = b3Array_Get( world->bodies, idB ); - - B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); - - int localIndexA = bodyA->localIndex; - int localIndexB = bodyB->localIndex; - - b3BodySim* bodySimA = b3Array_Get( setA->bodySims, localIndexA ); - b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB ); - - float mA = bodySimA->invMass; - float mB = bodySimB->invMass; - b3Matrix3 iA = bodySimA->invInertiaWorld; - b3Matrix3 iB = bodySimB->invInertiaWorld; - - base->invMassA = mA; - base->invMassB = mB; - base->invIA = iA; - base->invIB = iB; - - b3PogoJoint* joint = &base->pogoJoint; - joint->indexA = bodyA->setIndex == b3_awakeSet ? localIndexA : B3_NULL_INDEX; - joint->indexB = bodyB->setIndex == b3_awakeSet ? localIndexB : B3_NULL_INDEX; - - // Compute joint anchor frames with world space rotation, relative to center of mass - joint->frameA.q = b3MulQuat( bodySimA->transform.q, base->localFrameA.q ); - joint->frameA.p = b3RotateVector( bodySimA->transform.q, - b3Sub( base->localFrameA.p, bodySimA->localCenter ) ); - joint->frameB.q = b3MulQuat( bodySimB->transform.q, base->localFrameB.q ); - joint->frameB.p = b3RotateVector( bodySimB->transform.q, - b3Sub( base->localFrameB.p, bodySimB->localCenter ) ); - - // Compute the initial center delta. Incremental position updates are relative to this. - joint->deltaCenter = b3SubPos( bodySimB->center, bodySimA->center ); - - b3Vec3 rnA = b3Cross( joint->frameA.p, joint->normal ); - b3Vec3 rnB = b3Cross( joint->frameB.p, joint->normal ); - float k = mA + mB + b3Dot( rnA, b3MulMV( iA, rnA ) ) + b3Dot( rnB, b3MulMV( iB, rnB ) ); - joint->linearMass = k > 0.0f ? 1.0f / k : 0.0f; - - if ( context->enableWarmStarting == false ) - { - joint->velocity = 0.0f; - joint->impulse = 0.0f; - } -} - -void b3WarmStartPogoJoint( b3JointSim* base, b3StepContext* context ) -{ - B3_ASSERT( base->type == b3_pogoJoint ); - - float mA = base->invMassA; - float mB = base->invMassB; - b3Matrix3 iA = base->invIA; - b3Matrix3 iB = base->invIB; - - b3PogoJoint* joint = &base->pogoJoint; - - if ( joint->hertz == 0.0f ) - { - joint->impulse = 0.0f; - return; - } - - // dummy state for static bodies - b3BodyState dummyState = b3_identityBodyState; - - b3BodyState* stateA = - joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA; - b3BodyState* stateB = - joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB; - - b3Vec3 rA = b3RotateVector( stateA->deltaRotation, joint->frameA.p ); - b3Vec3 rB = b3RotateVector( stateB->deltaRotation, joint->frameB.p ); - - b3Vec3 linearImpulse = b3MulSV( joint->impulse, joint->normal ); - - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = b3MulSub( stateA->linearVelocity, mA, linearImpulse ); - stateA->angularVelocity = - b3Sub( stateA->angularVelocity, b3MulMV( iA, b3Cross( rA, linearImpulse ) ) ); - } - - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = b3MulAdd( stateB->linearVelocity, mB, linearImpulse ); - stateB->angularVelocity = - b3Add( stateB->angularVelocity, b3MulMV( iB, b3Cross( rB, linearImpulse ) ) ); - } -} - -void b3SolvePogoJoint( b3JointSim* base, b3StepContext* context, bool useBias ) -{ - B3_ASSERT( base->type == b3_pogoJoint ); - - float mA = base->invMassA; - float mB = base->invMassB; - b3Matrix3 iA = base->invIA; - b3Matrix3 iB = base->invIB; - - // dummy state for static bodies - b3BodyState dummyState = b3_identityBodyState; - - b3PogoJoint* joint = &base->pogoJoint; - if ( joint->hertz == 0.0f ) - { - joint->impulse = 0.0f; - joint->velocity = 0.0f; - return; - } - - b3BodyState* stateA = - joint->indexA == B3_NULL_INDEX ? &dummyState : context->states + joint->indexA; - b3BodyState* stateB = - joint->indexB == B3_NULL_INDEX ? &dummyState : context->states + joint->indexB; - - b3Vec3 vA = stateA->linearVelocity; - b3Vec3 wA = stateA->angularVelocity; - b3Vec3 vB = stateB->linearVelocity; - b3Vec3 wB = stateB->angularVelocity; - - b3Vec3 rA = b3RotateVector( stateA->deltaRotation, joint->frameA.p ); - b3Vec3 rB = b3RotateVector( stateB->deltaRotation, joint->frameB.p ); - - float bias = 0.0f; - if ( useBias ) - { - // This is a custom pogo position correction designed to avoid feeding velocity into - // the mover body. Otherwise the mover can make huge jumps going up stairs. This still - // works with continuous collision. - - b3Vec3 dcA = stateA->deltaPosition; - b3Vec3 dcB = stateB->deltaPosition; - b3Vec3 d = b3Add( b3Add( b3Sub( dcB, dcA ), b3Sub( rB, rA ) ), joint->deltaCenter ); - - // The pogo axis is usually fixed as the world y-axis. Different than the ground normal. - b3Vec3 pogoAxis = b3RotateVector( joint->frameB.q, b3Vec3_axisY ); - float c = b3Dot( pogoAxis, d ) - joint->restLength; - - // This could be divided by dot(joint->normal, pogoAxis) to account for the constraint - // direction, but I'd rather diminish the pogo recovery rate than risk making it huge. - joint->velocity = - b3SpringDamper( joint->hertz, joint->dampingRatio, c, joint->velocity, context->h ); - bias = -joint->velocity; - } - - b3Vec3 vr = b3Sub( b3Add( vB, b3Cross( wB, rB ) ), b3Add( vA, b3Cross( wA, rA ) ) ); - float cdot = b3Dot( joint->normal, vr ); - - float maxTensionImpulse = context->h * joint->maxTensionForce; - float maxCompressionImpulse = context->h * joint->maxCompressionForce; - float oldImpulse = joint->impulse; - float impulse = -joint->linearMass * ( cdot + bias ); - joint->impulse = - b3ClampFloat( joint->impulse + impulse, -maxTensionImpulse, maxCompressionImpulse ); - impulse = joint->impulse - oldImpulse; - - b3Vec3 P = b3MulSV( impulse, joint->normal ); - vA = b3MulSub( vA, mA, P ); - wA = b3Sub( wA, b3MulMV( iA, b3Cross( rA, P ) ) ); - vB = b3MulAdd( vB, mB, P ); - wB = b3Add( wB, b3MulMV( iB, b3Cross( rB, P ) ) ); - - if ( stateA->flags & b3_dynamicFlag ) - { - stateA->linearVelocity = vA; - stateA->angularVelocity = wA; - } - - if ( stateB->flags & b3_dynamicFlag ) - { - stateB->linearVelocity = vB; - stateB->angularVelocity = wB; - } -} - -void b3DrawPogoJoint( b3DebugDraw* draw, b3World* world, b3JointSim* base, - b3WorldTransform transformA, b3WorldTransform transformB, float scale ) -{ - B3_ASSERT( base->type == b3_pogoJoint ); - - b3PogoJoint* joint = &base->pogoJoint; - - b3Pos pA = b3TransformWorldPoint( transformA, base->localFrameA.p ); - b3Pos pB = b3TransformWorldPoint( transformB, base->localFrameB.p ); - b3Vec3 axis = b3RotateVector( b3MulQuat( transformB.q, base->localFrameB.q ), b3Vec3_axisY ); - b3Vec3 perp1 = b3Perp( axis ); - b3Vec3 perp2 = b3Cross( axis, perp1 ); - - float length = b3Dot( b3SubPos( pB, pA ), axis ); - b3Pos foot = b3OffsetPos( pB, b3MulSV( -length, axis ) ); - - float force = world->inv_h * joint->impulse; - - // Tolerance for reaching max force. - float saturation = 0.99f; - - b3HexColor color; - if ( joint->hertz == 0.0f ) - { - color = b3_colorGray; - } - else if ( force > 0.0f && force >= saturation * joint->maxCompressionForce ) - { - color = b3_colorRed; - } - else if ( force < 0.0f && -force >= saturation * joint->maxTensionForce ) - { - color = b3_colorRed; - } - else if ( force > 0.0f ) - { - color = b3_colorLimeGreen; - } - else if ( force < 0.0f ) - { - color = b3_colorDeepSkyBlue; - } - else - { - color = b3_colorLightGray; - } - - // Spring - int segmentCount = 12; - float width = 0.1f * scale; - b3Pos p1 = pB; - for ( int i = 1; i <= segmentCount; ++i ) - { - float side = i == segmentCount ? 0.0f : ( i & 1 ) ? width : -width; - float t = (float)i / (float)segmentCount; - b3Pos p2 = b3OffsetPos( pB, b3MulAdd( b3MulSV( -t * length, axis ), side, perp2 ) ); - draw->DrawSegmentFcn( p1, p2, color, draw->context ); - p1 = p2; - } - - // Ground plane - b3Pos rest = b3OffsetPos( pB, b3MulSV( -joint->restLength, axis ) ); - float tick = 1.5f * width; - draw->DrawSegmentFcn( b3OffsetPos( rest, b3MulSV( -tick, perp1 ) ), - b3OffsetPos( rest, b3MulSV( tick, perp1 ) ), b3_colorWhite, - draw->context ); - draw->DrawSegmentFcn( b3OffsetPos( rest, b3MulSV( -tick, perp2 ) ), - b3OffsetPos( rest, b3MulSV( tick, perp2 ) ), b3_colorWhite, - draw->context ); - - if ( b3Length( b3SubPos( pA, foot ) ) > B3_LINEAR_SLOP ) - { - draw->DrawSegmentFcn( foot, pA, b3_colorDimGray, draw->context ); - } - - draw->DrawPointFcn( pA, 6.0f, color, draw->context ); - draw->DrawSegmentFcn( pA, b3OffsetPos( pA, b3MulSV( 0.5f * scale, joint->normal ) ), - b3_colorOrange, draw->context ); - - if ( draw->drawJointExtras ) - { - char buffer[96]; - snprintf( buffer, 96, "length = %.3f, rest = %.3f, f = %.1f, v = %.3f", length, - joint->restLength, force, joint->velocity ); - draw->DrawStringFcn( pB, buffer, color, draw->context ); - } -} diff --git a/src/prismatic_joint.c b/src/prismatic_joint.c index 3950e5f..c96e6d6 100644 --- a/src/prismatic_joint.c +++ b/src/prismatic_joint.c @@ -307,9 +307,9 @@ void b3PreparePrismaticJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyA = b3Array_Get( world->bodies, base->bodyIdA ); b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); - B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + B3_ASSERT( bodyB->setIndex == b3_awakeSet ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; diff --git a/src/rapidhash.h b/src/rapidhash.h deleted file mode 100644 index 88de4bc..0000000 --- a/src/rapidhash.h +++ /dev/null @@ -1,568 +0,0 @@ -/* - * rapidhash V3 - Very fast, high quality, platform-independent hashing algorithm. - * - * Based on 'wyhash', by Wang Yi - * - * Copyright (C) 2025 Nicolas De Carli - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * You can contact the author at: - * - rapidhash source repository: https://github.com/Nicoshev/rapidhash - */ - - #pragma once - -/* - * Includes. - */ - #include - #include - #if defined(_MSC_VER) - # include - # if defined(_M_X64) && !defined(_M_ARM64EC) - # pragma intrinsic(_umul128) - # endif - #endif - - /* - * C/C++ macros. - */ - - #ifdef _MSC_VER - # define RAPIDHASH_ALWAYS_INLINE __forceinline - #elif defined(__GNUC__) - # define RAPIDHASH_ALWAYS_INLINE inline __attribute__((__always_inline__)) - #else - # define RAPIDHASH_ALWAYS_INLINE inline - #endif - - #ifdef __cplusplus - # define RAPIDHASH_NOEXCEPT noexcept - # define RAPIDHASH_CONSTEXPR constexpr - # ifndef RAPIDHASH_INLINE - # define RAPIDHASH_INLINE RAPIDHASH_ALWAYS_INLINE - # endif - # if __cplusplus >= 201402L && !defined(_MSC_VER) - # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_ALWAYS_INLINE constexpr - # else - # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_ALWAYS_INLINE - # endif - #else - # define RAPIDHASH_NOEXCEPT - # define RAPIDHASH_CONSTEXPR static const - # ifndef RAPIDHASH_INLINE - # define RAPIDHASH_INLINE static RAPIDHASH_ALWAYS_INLINE - # endif - # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_INLINE - #endif - - /* - * Unrolled macro. - * Improves large input speed, but increases code size and worsens small input speed. - * - * RAPIDHASH_COMPACT: Normal behavior. - * RAPIDHASH_UNROLLED: - * - */ - #ifndef RAPIDHASH_UNROLLED - # define RAPIDHASH_COMPACT - #elif defined(RAPIDHASH_COMPACT) - # error "cannot define RAPIDHASH_COMPACT and RAPIDHASH_UNROLLED simultaneously." - #endif - - /* - * Protection macro, alters behaviour of rapid_mum multiplication function. - * - * RAPIDHASH_FAST: Normal behavior, max speed. - * RAPIDHASH_PROTECTED: Extra protection against entropy loss. - */ - #ifndef RAPIDHASH_PROTECTED - # define RAPIDHASH_FAST - #elif defined(RAPIDHASH_FAST) - # error "cannot define RAPIDHASH_PROTECTED and RAPIDHASH_FAST simultaneously." - #endif - - /* - * Likely and unlikely macros. - */ - #if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__) - # define _likely_(x) __builtin_expect(x,1) - # define _unlikely_(x) __builtin_expect(x,0) - #else - # define _likely_(x) (x) - # define _unlikely_(x) (x) - #endif - - /* - * Endianness macros. - */ - #ifndef RAPIDHASH_LITTLE_ENDIAN - # if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) - # define RAPIDHASH_LITTLE_ENDIAN - # elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - # define RAPIDHASH_BIG_ENDIAN - # else - # warning "could not determine endianness! Falling back to little endian." - # define RAPIDHASH_LITTLE_ENDIAN - # endif - #endif - - /* - * Default secret parameters. - */ - RAPIDHASH_CONSTEXPR uint64_t rapid_secret[8] = { - 0x2d358dccaa6c78a5ull, - 0x8bb84b93962eacc9ull, - 0x4b33a62ed433d4a3ull, - 0x4d5a2da51de1aa47ull, - 0xa0761d6478bd642full, - 0xe7037ed1a0b428dbull, - 0x90ed1765281c388cull, - 0xaaaaaaaaaaaaaaaaull}; - - /* - * 64*64 -> 128bit multiply function. - * - * @param A Address of 64-bit number. - * @param B Address of 64-bit number. - * - * Calculates 128-bit C = *A * *B. - * - * When RAPIDHASH_FAST is defined: - * Overwrites A contents with C's low 64 bits. - * Overwrites B contents with C's high 64 bits. - * - * When RAPIDHASH_PROTECTED is defined: - * Xors and overwrites A contents with C's low 64 bits. - * Xors and overwrites B contents with C's high 64 bits. - */ - RAPIDHASH_INLINE_CONSTEXPR void rapid_mum(uint64_t *A, uint64_t *B) RAPIDHASH_NOEXCEPT { - #if defined(__SIZEOF_INT128__) - __uint128_t r=*A; r*=*B; - #ifdef RAPIDHASH_PROTECTED - *A^=(uint64_t)r; *B^=(uint64_t)(r>>64); - #else - *A=(uint64_t)r; *B=(uint64_t)(r>>64); - #endif - #elif defined(_MSC_VER) && (defined(_WIN64) || defined(_M_HYBRID_CHPE_ARM64)) - #if defined(_M_X64) - #ifdef RAPIDHASH_PROTECTED - uint64_t a, b; - a=_umul128(*A,*B,&b); - *A^=a; *B^=b; - #else - *A=_umul128(*A,*B,B); - #endif - #else - #ifdef RAPIDHASH_PROTECTED - uint64_t a, b; - b = __umulh(*A, *B); - a = *A * *B; - *A^=a; *B^=b; - #else - uint64_t c = __umulh(*A, *B); - *A = *A * *B; - *B = c; - #endif - #endif - #else - uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B; - uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t>32)+(rm1>>32)+c; - #ifdef RAPIDHASH_PROTECTED - *A^=lo; *B^=hi; - #else - *A=lo; *B=hi; - #endif - #endif - } - - /* - * Multiply and xor mix function. - * - * @param A 64-bit number. - * @param B 64-bit number. - * - * Calculates 128-bit C = A * B. - * Returns 64-bit xor between high and low 64 bits of C. - */ - RAPIDHASH_INLINE_CONSTEXPR uint64_t rapid_mix(uint64_t A, uint64_t B) RAPIDHASH_NOEXCEPT { rapid_mum(&A,&B); return A^B; } - - /* - * Read functions. - */ - #ifdef RAPIDHASH_LITTLE_ENDIAN - RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return v;} - RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return v;} - #elif defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__) - RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return __builtin_bswap64(v);} - RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return __builtin_bswap32(v);} - #elif defined(_MSC_VER) - RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return _byteswap_uint64(v);} - RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return _byteswap_ulong(v);} - #else - RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { - uint64_t v; memcpy(&v, p, 8); - return (((v >> 56) & 0xff)| ((v >> 40) & 0xff00)| ((v >> 24) & 0xff0000)| ((v >> 8) & 0xff000000)| ((v << 8) & 0xff00000000)| ((v << 24) & 0xff0000000000)| ((v << 40) & 0xff000000000000)| ((v << 56) & 0xff00000000000000)); - } - RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { - uint32_t v; memcpy(&v, p, 4); - return (((v >> 24) & 0xff)| ((v >> 8) & 0xff00)| ((v << 8) & 0xff0000)| ((v << 24) & 0xff000000)); - } - #endif - - /* - * rapidhash main function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * @param secret Triplet of 64-bit secrets used to alter hash result predictably. - * - * Returns a 64-bit hash. - */ -RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT { - const uint8_t *p=(const uint8_t *)key; - seed ^= rapid_mix(seed ^ secret[2], secret[1]); - uint64_t a=0, b=0; - size_t i = len; - if (_likely_(len <= 16)) { - if (len >= 4) { - seed ^= len; - if (len >= 8) { - const uint8_t* plast = p + len - 8; - a = rapid_read64(p); - b = rapid_read64(plast); - } else { - const uint8_t* plast = p + len - 4; - a = rapid_read32(p); - b = rapid_read32(plast); - } - } else if (len > 0) { - a = (((uint64_t)p[0])<<45)|p[len-1]; - b = p[len>>1]; - } else - a = b = 0; - } else { - if (len > 112) { - uint64_t see1 = seed, see2 = seed; - uint64_t see3 = seed, see4 = seed; - uint64_t see5 = seed, see6 = seed; -#ifdef RAPIDHASH_COMPACT - do { - seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed); - see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1); - see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2); - see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3); - see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4); - see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5); - see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6); - p += 112; - i -= 112; - } while(i > 112); -#else - while (i > 224) { - seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed); - see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1); - see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2); - see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3); - see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4); - see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5); - see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6); - seed = rapid_mix(rapid_read64(p + 112) ^ secret[0], rapid_read64(p + 120) ^ seed); - see1 = rapid_mix(rapid_read64(p + 128) ^ secret[1], rapid_read64(p + 136) ^ see1); - see2 = rapid_mix(rapid_read64(p + 144) ^ secret[2], rapid_read64(p + 152) ^ see2); - see3 = rapid_mix(rapid_read64(p + 160) ^ secret[3], rapid_read64(p + 168) ^ see3); - see4 = rapid_mix(rapid_read64(p + 176) ^ secret[4], rapid_read64(p + 184) ^ see4); - see5 = rapid_mix(rapid_read64(p + 192) ^ secret[5], rapid_read64(p + 200) ^ see5); - see6 = rapid_mix(rapid_read64(p + 208) ^ secret[6], rapid_read64(p + 216) ^ see6); - p += 224; - i -= 224; - } - if (i > 112) { - seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed); - see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1); - see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2); - see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3); - see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4); - see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5); - see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6); - p += 112; - i -= 112; - } -#endif - seed ^= see1; - see2 ^= see3; - see4 ^= see5; - seed ^= see6; - see2 ^= see4; - seed ^= see2; - } - if (i > 16) { - seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed); - if (i > 32) { - seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed); - if (i > 48) { - seed = rapid_mix(rapid_read64(p + 32) ^ secret[1], rapid_read64(p + 40) ^ seed); - if (i > 64) { - seed = rapid_mix(rapid_read64(p + 48) ^ secret[1], rapid_read64(p + 56) ^ seed); - if (i > 80) { - seed = rapid_mix(rapid_read64(p + 64) ^ secret[2], rapid_read64(p + 72) ^ seed); - if (i > 96) { - seed = rapid_mix(rapid_read64(p + 80) ^ secret[1], rapid_read64(p + 88) ^ seed); - } - } - } - } - } - } - a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8); - } - a ^= secret[1]; - b ^= seed; - rapid_mum(&a, &b); - return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i); -} - - /* - * rapidhashMicro main function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * @param secret Triplet of 64-bit secrets used to alter hash result predictably. - * - * Returns a 64-bit hash. - */ - RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT { - const uint8_t *p=(const uint8_t *)key; - seed ^= rapid_mix(seed ^ secret[2], secret[1]); - uint64_t a=0, b=0; - size_t i = len; - if (_likely_(len <= 16)) { - if (len >= 4) { - seed ^= len; - if (len >= 8) { - const uint8_t* plast = p + len - 8; - a = rapid_read64(p); - b = rapid_read64(plast); - } else { - const uint8_t* plast = p + len - 4; - a = rapid_read32(p); - b = rapid_read32(plast); - } - } else if (len > 0) { - a = (((uint64_t)p[0])<<45)|p[len-1]; - b = p[len>>1]; - } else - a = b = 0; - } else { - if (i > 80) { - uint64_t see1 = seed, see2 = seed; - uint64_t see3 = seed, see4 = seed; - do { - seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed); - see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1); - see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2); - see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3); - see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4); - p += 80; - i -= 80; - } while(i > 80); - seed ^= see1; - see2 ^= see3; - seed ^= see4; - seed ^= see2; - } - if (i > 16) { - seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed); - if (i > 32) { - seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed); - if (i > 48) { - seed = rapid_mix(rapid_read64(p + 32) ^ secret[1], rapid_read64(p + 40) ^ seed); - if (i > 64) { - seed = rapid_mix(rapid_read64(p + 48) ^ secret[1], rapid_read64(p + 56) ^ seed); - } - } - } - } - a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8); - } - a ^= secret[1]; - b ^= seed; - rapid_mum(&a, &b); - return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i); - } - - /* - * rapidhashNano main function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * @param secret Triplet of 64-bit secrets used to alter hash result predictably. - * - * Returns a 64-bit hash. - */ - RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT { - const uint8_t *p=(const uint8_t *)key; - seed ^= rapid_mix(seed ^ secret[2], secret[1]); - uint64_t a=0, b=0; - size_t i = len; - if (_likely_(len <= 16)) { - if (len >= 4) { - seed ^= len; - if (len >= 8) { - const uint8_t* plast = p + len - 8; - a = rapid_read64(p); - b = rapid_read64(plast); - } else { - const uint8_t* plast = p + len - 4; - a = rapid_read32(p); - b = rapid_read32(plast); - } - } else if (len > 0) { - a = (((uint64_t)p[0])<<45)|p[len-1]; - b = p[len>>1]; - } else - a = b = 0; - } else { - if (i > 48) { - uint64_t see1 = seed, see2 = seed; - do { - seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed); - see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1); - see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2); - p += 48; - i -= 48; - } while(i > 48); - seed ^= see1; - seed ^= see2; - } - if (i > 16) { - seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed); - if (i > 32) { - seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed); - } - } - a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8); - } - a ^= secret[1]; - b ^= seed; - rapid_mum(&a, &b); - return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i); - } - -/* - * rapidhash seeded hash function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * - * Calls rapidhash_internal using provided parameters and default secrets. - * - * Returns a 64-bit hash. - */ -RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT { - return rapidhash_internal(key, len, seed, rapid_secret); -} - -/* - * rapidhash general purpose hash function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * - * Calls rapidhash_withSeed using provided parameters and the default seed. - * - * Returns a 64-bit hash. - */ -RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash(const void *key, size_t len) RAPIDHASH_NOEXCEPT { - return rapidhash_withSeed(key, len, 0); -} - -/* - * rapidhashMicro seeded hash function. - * - * Designed for HPC and server applications, where cache misses make a noticeable performance detriment. - * Clang-18+ compiles it to ~140 instructions without stack usage, both on x86-64 and aarch64. - * Faster for sizes up to 512 bytes, just 15%-20% slower for inputs above 1kb. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * - * Calls rapidhash_internal using provided parameters and default secrets. - * - * Returns a 64-bit hash. - */ - RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT { - return rapidhashMicro_internal(key, len, seed, rapid_secret); -} - -/* - * rapidhashMicro hash function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * - * Calls rapidhash_withSeed using provided parameters and the default seed. - * - * Returns a 64-bit hash. - */ -RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro(const void *key, size_t len) RAPIDHASH_NOEXCEPT { - return rapidhashMicro_withSeed(key, len, 0); -} - -/* - * rapidhashNano seeded hash function. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * @param seed 64-bit seed used to alter the hash result predictably. - * - * Calls rapidhash_internal using provided parameters and default secrets. - * - * Returns a 64-bit hash. - */ - RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT { - return rapidhashNano_internal(key, len, seed, rapid_secret); -} - -/* - * rapidhashNano hash function. - * - * Designed for Mobile and embedded applications, where keeping a small code size is a top priority. - * Clang-18+ compiles it to less than 100 instructions without stack usage, both on x86-64 and aarch64. - * The fastest for sizes up to 48 bytes, but may be considerably slower for larger inputs. - * - * @param key Buffer to be hashed. - * @param len @key length, in bytes. - * - * Calls rapidhash_withSeed using provided parameters and the default seed. - * - * Returns a 64-bit hash. - */ -RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano(const void *key, size_t len) RAPIDHASH_NOEXCEPT { - return rapidhashNano_withSeed(key, len, 0); -} diff --git a/src/recording.c b/src/recording.c index e3cdced..933449f 100644 --- a/src/recording.c +++ b/src/recording.c @@ -217,9 +217,6 @@ void b3RecW_PLANERESULT( b3RecBuffer* buf, b3PlaneResult v ) b3RecW_VEC3( buf, v.plane.normal ); b3RecW_F32( buf, v.plane.offset ); b3RecW_VEC3( buf, v.point ); - b3RecW_I32( buf, v.triangleIndex ); - b3RecW_I32( buf, v.childIndex ); - b3RecW_I32( buf, v.materialIndex ); } void b3RecW_WORLDID( b3RecBuffer* buf, b3WorldId v ) @@ -292,7 +289,7 @@ void b3RecW_LOCKS( b3RecBuffer* buf, b3MotionLocks v ) b3RecW_BOOL( buf, v.angularZ ); } -static void b3RecW_STR( b3RecBuffer* buf, const char* s ) +void b3RecW_STR( b3RecBuffer* buf, const char* s ) { if ( s == NULL ) { @@ -320,9 +317,9 @@ static void b3RecW_STR( b3RecBuffer* buf, const char* s ) // single-precision and double-precision sizes (equal for most), so either build configuration passes. _Static_assert( sizeof( void* ) != 8 || sizeof( b3ExplosionDef ) == 32 || sizeof( b3ExplosionDef ) == 48, "b3ExplosionDef changed: update b3RecW_EXPLOSIONDEF and b3RecR_EXPLOSIONDEF together" ); -_Static_assert( sizeof( void* ) != 8 || sizeof( b3BodyDef ) == 112 || sizeof( b3BodyDef ) == 128, +_Static_assert( sizeof( void* ) != 8 || sizeof( b3BodyDef ) == 104 || sizeof( b3BodyDef ) == 120, "b3BodyDef changed: update b3RecW_BODYDEF and b3RecR_BODYDEF together" ); -_Static_assert( sizeof( void* ) != 8 || sizeof( b3ShapeDef ) == 120, +_Static_assert( sizeof( void* ) != 8 || sizeof( b3ShapeDef ) == 112, "b3ShapeDef changed: update b3RecW_SHAPEDEF and b3RecR_SHAPEDEF together" ); _Static_assert( sizeof( void* ) != 8 || sizeof( b3ParallelJointDef ) == 128, "b3ParallelJointDef changed: update b3RecW_PARALLELJOINTDEF and its reader together" ); @@ -342,10 +339,6 @@ _Static_assert( sizeof( void* ) != 8 || sizeof( b3WeldJointDef ) == 128, "b3WeldJointDef changed: update b3RecW_WELDJOINTDEF and its reader together" ); _Static_assert( sizeof( void* ) != 8 || sizeof( b3WheelJointDef ) == 184, "b3WheelJointDef changed: update b3RecW_WHEELJOINTDEF and its reader together" ); -_Static_assert( sizeof( void* ) != 8 || sizeof( b3MoverJointDef ) == 128, - "b3MoverJointDef changed: update b3RecW_MOVERJOINTDEF and its reader together" ); -_Static_assert( sizeof( void* ) != 8 || sizeof( b3PogoJointDef ) == 152, - "b3PogoJointDef changed: update b3RecW_POGOJOINTDEF and its reader together" ); void b3RecW_EXPLOSIONDEF( b3RecBuffer* buf, b3ExplosionDef v ) { @@ -367,7 +360,6 @@ void b3RecW_BODYDEF( b3RecBuffer* buf, b3BodyDef v ) b3RecW_F32( buf, v.angularDamping ); b3RecW_F32( buf, v.gravityScale ); b3RecW_F32( buf, v.sleepThreshold ); - b3RecW_F32( buf, v.safetyFactor ); b3RecW_STR( buf, v.name ); // userData: not preserved b3RecW_U64( buf, 0u ); @@ -383,8 +375,6 @@ void b3RecW_BODYDEF( b3RecBuffer* buf, b3BodyDef v ) void b3RecW_SHAPEDEF( b3RecBuffer* buf, b3ShapeDef v ) { - b3RecW_STR( buf, v.name ); - // userData: not preserved b3RecW_U64( buf, 0u ); // Per-triangle materials: length-prefixed so the reader can rebuild the array. @@ -407,7 +397,6 @@ void b3RecW_SHAPEDEF( b3RecBuffer* buf, b3ShapeDef v ) b3RecW_BOOL( buf, v.enablePreSolveEvents ); b3RecW_BOOL( buf, v.invokeContactCreation ); b3RecW_BOOL( buf, v.updateBodyMass ); - b3RecW_BOOL( buf, v.enableSpeculativeContact ); // internalValue omitted } @@ -552,26 +541,6 @@ void b3RecW_WHEELJOINTDEF( b3RecBuffer* buf, b3WheelJointDef v ) b3RecW_F32( buf, v.upperSteeringLimit ); } -void b3RecW_MOVERJOINTDEF( b3RecBuffer* buf, b3MoverJointDef v ) -{ - b3RecW_JointBase( buf, &v.base ); - b3RecW_VEC3( buf, v.linearVelocity ); - b3RecW_F32( buf, v.maxForce ); -} - -void b3RecW_POGOJOINTDEF( b3RecBuffer* buf, b3PogoJointDef v ) -{ - b3RecW_JointBase( buf, &v.base ); - b3RecW_VEC3( buf, v.normal ); - b3RecW_F32( buf, v.hertz ); - b3RecW_F32( buf, v.dampingRatio ); - b3RecW_F32( buf, v.restLength ); - b3RecW_F32( buf, v.maxTensionForce ); - b3RecW_F32( buf, v.maxCompressionForce ); - b3RecW_F32( buf, v.impulse ); - b3RecW_F32( buf, v.velocity ); -} - // Query recording. A query collects a variable number of hits through a user callback, so the count // is not known until the callback stops firing. The record is built in a local buffer with a // reserved hit-count slot, then committed whole under the lock so concurrent query threads never @@ -763,6 +732,45 @@ void b3RecEndRecord( b3Recording* rec ) // Geometry registry +// Full 64-bit content hash, so distinct blobs of the same length get independent bits. A reseeded +// 32-bit djb2 cannot: djb2 is affine in its seed, so a same-length collision survives every seed and +// the high word would just track the low one. Word folded for speed, byte order normalized on +// big-endian to match b3Hash, then a splitmix64 finalizer so tiny inputs still spread across all bits. +// From Fowler/Noll/Vo FNV-1a salted by length, then the splitmix64 mix. +uint64_t b3Hash64Blob( const uint8_t* bytes, int n ) +{ + uint64_t h = 0xcbf29ce484222325ull ^ (uint64_t)(uint32_t)n; + const uint64_t prime = 0x100000001b3ull; + int i = 0; + + while ( i + 8 <= n ) + { + uint64_t word; + memcpy( &word, bytes + i, sizeof( word ) ); +#if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + word = ( ( word & 0x00000000000000FFULL ) << 56 ) | ( ( word & 0x000000000000FF00ULL ) << 40 ) | + ( ( word & 0x0000000000FF0000ULL ) << 24 ) | ( ( word & 0x00000000FF000000ULL ) << 8 ) | + ( ( word & 0x000000FF00000000ULL ) >> 8 ) | ( ( word & 0x0000FF0000000000ULL ) >> 24 ) | + ( ( word & 0x00FF000000000000ULL ) >> 40 ) | ( ( word & 0xFF00000000000000ULL ) >> 56 ); +#endif + h = ( h ^ word ) * prime; + i += 8; + } + + while ( i < n ) + { + h = ( h ^ (uint64_t)bytes[i] ) * prime; + i += 1; + } + + h ^= h >> 30; + h *= 0xbf58476d1ce4e5b9ull; + h ^= h >> 27; + h *= 0x94d049bb133111ebull; + h ^= h >> 31; + return h; +} + // Content hash to chain head, so dedup is near O(1). Colliding hashes share a head and are walked // through b3GeometryEntry::hashNext, so the byteCount + memcmp check always finds an existing blob. #define NAME b3GeometryHashMap @@ -786,20 +794,25 @@ void b3RecEndRecord( b3Recording* rec ) // Append a fresh entry and splice it onto the front of its hash chain. The map value is the chain head. static uint32_t b3RegistryPush( b3GeometryRegistry* reg, b3GeometryHashMap* map, b3GeometryHashMap_itr itr, bool hashPresent, - b3GeometryKind kind, uint64_t contentHash, const uint8_t* bytes, int byteCount ) + b3GeometryKind kind, uint64_t contentHash, uint8_t* bytes, int byteCount ) { - B3_ASSERT( byteCount > 0 ); - uint8_t* copy = b3Alloc( (size_t)byteCount ); - memcpy( copy, bytes, (size_t)byteCount ); + if ( reg->count >= reg->capacity ) + { + int newCap = reg->capacity < 8 ? 8 : reg->capacity * 2; + reg->entries = (b3GeometryEntry*)b3GrowAlloc( reg->entries, reg->capacity * (int)sizeof( b3GeometryEntry ), + newCap * (int)sizeof( b3GeometryEntry ) ); + reg->capacity = newCap; + } - uint32_t id = (uint32_t)reg->entries.count; - b3GeometryEntry* entry = b3Array_Emplace( reg->entries ); + uint32_t id = (uint32_t)reg->count; + b3GeometryEntry* entry = reg->entries + reg->count; entry->contentHash = contentHash; entry->id = id; entry->kind = kind; entry->byteCount = byteCount; - entry->bytes = copy; + entry->bytes = bytes; // take ownership entry->hashNext = hashPresent ? (int)itr.data->val : B3_NULL_INDEX; + reg->count++; if ( hashPresent ) { @@ -816,14 +829,14 @@ static b3GeometryHashMap* b3RegistryMap( b3GeometryRegistry* reg ) { if ( reg->dedupMap == NULL ) { - b3GeometryHashMap* fresh = b3Alloc( sizeof( b3GeometryHashMap ) ); + b3GeometryHashMap* fresh = (b3GeometryHashMap*)b3Alloc( sizeof( b3GeometryHashMap ) ); b3GeometryHashMap_init( fresh ); reg->dedupMap = fresh; } - return reg->dedupMap; + return (b3GeometryHashMap*)reg->dedupMap; } -uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, const uint8_t* bytes, int byteCount ) +uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, uint8_t* bytes, int byteCount ) { b3GeometryHashMap* map = b3RegistryMap( reg ); @@ -832,11 +845,13 @@ uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_ if ( hashPresent ) { // Walk every entry sharing this hash so a collision still finds the identical blob. - for ( int index = (int)itr.data->val; index != B3_NULL_INDEX; index = reg->entries.data[index].hashNext ) + for ( int idx = (int)itr.data->val; idx != B3_NULL_INDEX; idx = reg->entries[idx].hashNext ) { - b3GeometryEntry* e = reg->entries.data + index; + b3GeometryEntry* e = reg->entries + idx; if ( e->byteCount == byteCount && memcmp( e->bytes, bytes, (size_t)byteCount ) == 0 ) { + // Duplicate: the caller transferred ownership; return existing id + b3Free( bytes, (size_t)byteCount ); return e->id; } } @@ -845,7 +860,7 @@ uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_ return b3RegistryPush( reg, map, itr, hashPresent, kind, contentHash, bytes, byteCount ); } -uint32_t b3AppendGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, const uint8_t* bytes, int byteCount ) +uint32_t b3AppendGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, uint8_t* bytes, int byteCount ) { b3GeometryHashMap* map = b3RegistryMap( reg ); b3GeometryHashMap_itr itr = b3GeometryHashMap_get( map, contentHash ); @@ -855,18 +870,22 @@ uint32_t b3AppendGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_ void b3FreeRegistry( b3GeometryRegistry* reg ) { - for ( int i = 0; i < reg->entries.count; ++i ) + for ( int i = 0; i < reg->count; ++i ) { - b3Free( reg->entries.data[i].bytes, (size_t)reg->entries.data[i].byteCount ); + b3Free( reg->entries[i].bytes, (size_t)reg->entries[i].byteCount ); + } + if ( reg->entries != NULL ) + { + b3Free( reg->entries, (size_t)( reg->capacity * (int)sizeof( b3GeometryEntry ) ) ); } - - b3Array_Destroy( reg->entries ); - if ( reg->dedupMap != NULL ) { b3GeometryHashMap_cleanup( (b3GeometryHashMap*)reg->dedupMap ); b3Free( reg->dedupMap, sizeof( b3GeometryHashMap ) ); } + reg->entries = NULL; + reg->count = 0; + reg->capacity = 0; reg->dedupMap = NULL; } @@ -919,12 +938,12 @@ void b3RecInternTag( b3Recording* rec, uint64_t key, uint64_t id, const char* na tag->key = key; tag->id = id; int n = 0; - while ( name != NULL && name[n] != '\0' && n < B3_MAX_QUERY_NAME_LENGTH ) + while ( name != NULL && name[n] != '\0' && n < B3_BODY_NAME_LENGTH ) { - tag->queryName[n] = name[n]; + tag->name[n] = name[n]; n++; } - tag->queryName[n] = '\0'; + tag->name[n] = '\0'; b3RecTagMap_insert( map, key, index ); } @@ -933,10 +952,10 @@ void b3RecInternTag( b3Recording* rec, uint64_t key, uint64_t id, const char* na // the tag table stops after the geometry entries and ignores the trailing tag bytes. void b3RecWriteRegistry( b3Recording* rec ) { - b3RecW_U32( &rec->buffer, (uint32_t)rec->registry.entries.count ); - for ( int i = 0; i < rec->registry.entries.count; ++i ) + b3RecW_U32( &rec->buffer, (uint32_t)rec->registry.count ); + for ( int i = 0; i < rec->registry.count; ++i ) { - b3GeometryEntry* e = rec->registry.entries.data + i; + b3GeometryEntry* e = rec->registry.entries + i; b3RecW_U8( &rec->buffer, (uint8_t)e->kind ); b3RecW_U32( &rec->buffer, (uint32_t)e->byteCount ); b3RecBufAppend( &rec->buffer, e->bytes, e->byteCount ); @@ -947,7 +966,7 @@ void b3RecWriteRegistry( b3Recording* rec ) { b3RecW_U64( &rec->buffer, rec->tags[i].key ); b3RecW_U64( &rec->buffer, rec->tags[i].id ); - b3RecW_STR( &rec->buffer, rec->tags[i].queryName ); + b3RecW_STR( &rec->buffer, rec->tags[i].name ); } } @@ -955,7 +974,7 @@ void b3RecWriteRegistry( b3Recording* rec ) b3Recording* b3CreateRecording( int byteCapacity ) { - b3Recording* rec = b3Alloc( sizeof( b3Recording ) ); + b3Recording* rec = (b3Recording*)b3Alloc( sizeof( b3Recording ) ); *rec = (b3Recording){ 0 }; int initCap = byteCapacity > 0 ? byteCapacity : 65536; @@ -1171,31 +1190,43 @@ b3Recording* b3LoadRecordingFromFile( const char* path ) // Geometry interning helpers -static uint32_t b3RecInternBlob( b3Recording* rec, b3GeometryKind kind, const void* blob, int byteCount ) -{ - const uint8_t* bytes = (const uint8_t*)blob; - uint64_t h = b3Hash64NonZero( bytes, byteCount ); - return b3InternGeometry( &rec->registry, kind, h, bytes, byteCount ); -} - uint32_t b3RecInternHull( b3Recording* rec, const b3HullData* hull ) { - return b3RecInternBlob( rec, b3_geometryHull, hull, hull->byteCount ); + int byteCount = hull->byteCount; + uint8_t* bytes = (uint8_t*)b3Alloc( (size_t)byteCount ); + memcpy( bytes, hull, (size_t)byteCount ); + uint64_t h = b3Hash64Blob( bytes, byteCount ); + return b3InternGeometry( &rec->registry, b3_geometryHull, h, bytes, byteCount ); } uint32_t b3RecInternMesh( b3Recording* rec, const b3MeshData* mesh ) { - return b3RecInternBlob( rec, b3_geometryMesh, mesh, mesh->byteCount ); + int byteCount = mesh->byteCount; + uint8_t* bytes = (uint8_t*)b3Alloc( (size_t)byteCount ); + memcpy( bytes, mesh, (size_t)byteCount ); + uint64_t h = b3Hash64Blob( bytes, byteCount ); + return b3InternGeometry( &rec->registry, b3_geometryMesh, h, bytes, byteCount ); } uint32_t b3RecInternHeightField( b3Recording* rec, const b3HeightFieldData* hf ) { - return b3RecInternBlob( rec, b3_geometryHeightField, hf, hf->byteCount ); + int byteCount = hf->byteCount; + uint8_t* bytes = (uint8_t*)b3Alloc( (size_t)byteCount ); + memcpy( bytes, hf, (size_t)byteCount ); + uint64_t h = b3Hash64Blob( bytes, byteCount ); + return b3InternGeometry( &rec->registry, b3_geometryHeightField, h, bytes, byteCount ); } uint32_t b3RecInternCompound( b3Recording* rec, const b3CompoundData* compound ) { - return b3RecInternBlob( rec, b3_geometryCompound, compound, compound->byteCount ); + int byteCount = compound->byteCount; + uint8_t* bytes = (uint8_t*)b3Alloc( (size_t)byteCount ); + memcpy( bytes, compound, (size_t)byteCount ); + // Null the tree node pointer in the copy so the canonical bytes are pointer-free. + // b3ConvertBytesToCompound fixes it back on load via nodeOffset. + ( (b3CompoundData*)bytes )->tree.nodes = NULL; + uint64_t h = b3Hash64Blob( bytes, byteCount ); + return b3InternGeometry( &rec->registry, b3_geometryCompound, h, bytes, byteCount ); } uint64_t b3HashWorldState( b3World* world ) diff --git a/src/recording.h b/src/recording.h index 1afd800..9c8750c 100644 --- a/src/recording.h +++ b/src/recording.h @@ -3,7 +3,6 @@ #pragma once -#include "container.h" #include "core.h" #include "box3d/id.h" @@ -46,15 +45,12 @@ typedef struct b3World b3World; // Magic 'B3RC' in little-endian: bytes B(0x42) 3(0x33) R(0x52) C(0x43) #define B3_REC_MAGIC 0x43523342u -// Major recording version is bumped when writers change. -// Major version 6 widened the body def with the safety factor. -#define B3_REC_VERSION_MAJOR 6 +// Minor tracks op-stream additions that keep the 48 byte header shape (e.g. the spatial query ops). +// Minor 2 added the QueryTag op and the interned query-tag table at the tail of the registry block. +#define B3_REC_VERSION_MAJOR 2 +#define B3_REC_VERSION_MINOR 2 -// Minor tracks op-stream additions that keep the 48 byte header shape. -// Minor version 7 made the contact body sim locators persistent -#define B3_REC_VERSION_MINOR 10 - -// File header, fixed 48 bytes. Contains the registry locator so the player +// File header, fixed 48 bytes, little-endian. Contains the registry locator so the player // can load geometry before replaying any ops. typedef struct b3RecHeader { @@ -107,29 +103,24 @@ typedef struct b3GeometryEntry int hashNext; } b3GeometryEntry; -b3DeclareArray( b3GeometryEntry ); - // Growable array of geometry entries. Ids are array indices, so the array is serialized in order. // dedupMap maps content hash to entry id for O(1) dedup; it is opaque here and owned by recording.c. typedef struct b3GeometryRegistry { - b3Array( b3GeometryEntry ) entries; + b3GeometryEntry* entries; + int count; + int capacity; void* dedupMap; } b3GeometryRegistry; -// Limit the maximum query name length to make recording simpler. Query names longer than this -// probably indicate a bug in user code. -#define B3_MAX_QUERY_NAME_LENGTH 64 - // Query tag from b3QueryFilter. // Stored once per key in the trailing block so a tagged query carries only the 8 byte key on the wire. // Shared by the recorder (accumulate) and the player (load). typedef struct b3RecTag { - // hash of (id, queryName) - uint64_t key; - uint64_t id; - char queryName[B3_MAX_QUERY_NAME_LENGTH + 1]; + uint64_t key; // hash of (id, name) + uint64_t id; // entity/actor id + char name[B3_BODY_NAME_LENGTH + 1]; // query label } b3RecTag; // User-owned recording buffer. The world appends into it while active; the host saves and @@ -196,8 +187,6 @@ typedef b3RevoluteJointDef b3RecCType_REVOLUTEJOINTDEF; typedef b3SphericalJointDef b3RecCType_SPHERICALJOINTDEF; typedef b3WeldJointDef b3RecCType_WELDJOINTDEF; typedef b3WheelJointDef b3RecCType_WHEELJOINTDEF; -typedef b3MoverJointDef b3RecCType_MOVERJOINTDEF; -typedef b3PogoJointDef b3RecCType_POGOJOINTDEF; // Codegen pass 1a: arg structs. Generated here so call sites (body.c, shape.c, etc.) can see them. #define ARG( TAG, field ) b3RecCType_##TAG field; @@ -256,6 +245,7 @@ void b3RecW_FILTER( b3RecBuffer* buf, b3Filter v ); void b3RecW_MATERIAL( b3RecBuffer* buf, b3SurfaceMaterial v ); void b3RecW_MASSDATA( b3RecBuffer* buf, b3MassData v ); void b3RecW_LOCKS( b3RecBuffer* buf, b3MotionLocks v ); +void b3RecW_STR( b3RecBuffer* buf, const char* s ); void b3RecW_EXPLOSIONDEF( b3RecBuffer* buf, b3ExplosionDef v ); void b3RecW_BODYDEF( b3RecBuffer* buf, b3BodyDef v ); void b3RecW_SHAPEDEF( b3RecBuffer* buf, b3ShapeDef v ); @@ -268,8 +258,6 @@ void b3RecW_REVOLUTEJOINTDEF( b3RecBuffer* buf, b3RevoluteJointDef v ); void b3RecW_SPHERICALJOINTDEF( b3RecBuffer* buf, b3SphericalJointDef v ); void b3RecW_WELDJOINTDEF( b3RecBuffer* buf, b3WeldJointDef v ); void b3RecW_WHEELJOINTDEF( b3RecBuffer* buf, b3WheelJointDef v ); -void b3RecW_MOVERJOINTDEF( b3RecBuffer* buf, b3MoverJointDef v ); -void b3RecW_POGOJOINTDEF( b3RecBuffer* buf, b3PogoJointDef v ); // Record framing void b3RecBeginRecord( b3Recording* rec, uint8_t opcode ); @@ -355,11 +343,11 @@ float b3RecCastTrampoline( b3ShapeId id, b3Pos point, b3Vec3 normal, float fract bool b3RecPlaneTrampoline( b3ShapeId id, const b3PlaneResult* planes, int planeCount, void* ctx ); // Geometry registry -uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, const uint8_t* bytes, int byteCount ); +uint32_t b3InternGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, uint8_t* bytes, int byteCount ); // Append an entry unconditionally and return its id, which equals its array index. Unlike // b3InternGeometry it never deduplicates, so the keyframe seed can mirror slots 1:1 even when an // already-recorded file carries byte-identical duplicate slots (a hash collision wrote them apart). -uint32_t b3AppendGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, const uint8_t* bytes, int byteCount ); +uint32_t b3AppendGeometry( b3GeometryRegistry* reg, b3GeometryKind kind, uint64_t contentHash, uint8_t* bytes, int byteCount ); void b3FreeRegistry( b3GeometryRegistry* reg ); void b3RecWriteRegistry( b3Recording* rec ); @@ -368,14 +356,18 @@ void b3RecWriteRegistry( b3Recording* rec ); uint64_t b3HashQueryTag( uint64_t id, const char* name ); // Record a key->(id, name) mapping once, deduped by key (a repeated key keeps its first id/name). +// The name is clamped to B3_BODY_NAME_LENGTH. void b3RecInternTag( b3Recording* rec, uint64_t key, uint64_t id, const char* name ); // Intern each large geometry kind and return a stable u32 id for use in create ops. +// Caller does NOT free bytes; b3InternGeometry takes ownership (frees on duplicate). uint32_t b3RecInternHull( b3Recording* rec, const b3HullData* hull ); uint32_t b3RecInternMesh( b3Recording* rec, const b3MeshData* mesh ); uint32_t b3RecInternHeightField( b3Recording* rec, const b3HeightFieldData* hf ); uint32_t b3RecInternCompound( b3Recording* rec, const b3CompoundData* compound ); +uint64_t b3Hash64Blob( const uint8_t* bytes, int n ); + // Lifecycle engine-side hooks void b3StartRecordingIntoBuffer( b3World* world, b3Recording* recording ); void b3StopRecordingInternal( b3World* world ); diff --git a/src/recording_ops.inl b/src/recording_ops.inl index df13ebe..3c8086e 100644 --- a/src/recording_ops.inl +++ b/src/recording_ops.inl @@ -15,7 +15,6 @@ // 0x40-0x4F shape create/destroy // 0x50-0x6F shape mutators // 0x80 step -// 0x81-0x8F mover and pogo joints // 0x90-0xE7 joints (create, generic, per-type) // 0xE8-0xEF spatial queries // 0xF0-0xFF markers @@ -39,9 +38,6 @@ B3_REC_OP( 0x0A, WorldSetMaximumLinearSpeed, RET_NONE, ARG( WORLDID, world ) ARG B3_REC_OP( 0x0B, WorldEnableWarmStarting, RET_NONE, ARG( WORLDID, world ) ARG( BOOL, flag ) ) B3_REC_OP( 0x0C, WorldRebuildStaticTree, RET_NONE, ARG( WORLDID, world ) ) B3_REC_OP( 0x0D, WorldEnableSpeculative, RET_NONE, ARG( WORLDID, world ) ARG( BOOL, flag ) ) -B3_REC_OP( 0x0E, WorldSetRestitutionIterations, RET_NONE, ARG( WORLDID, world ) ARG( I32, iterations ) ) -B3_REC_OP( 0x0F, WorldEnableRestitutionPropagation, RET_NONE, ARG( WORLDID, world ) ARG( BOOL, flag ) ) -B3_REC_OP( 0x70, WorldSetIsotropicInertiaTolerance, RET_NONE, ARG( WORLDID, world ) ARG( F32, tolerance ) ) // Body B3_REC_OP( 0x10, CreateBody, RET_BODYID, ARG( WORLDID, world ) ARG( BODYDEF, def ) ) @@ -72,8 +68,6 @@ B3_REC_OP( 0x36, BodySetMotionLocks, RET_NONE, ARG( BODYID, body ) ARG( LOCKS, l B3_REC_OP( 0x37, BodySetBullet, RET_NONE, ARG( BODYID, body ) ARG( BOOL, flag ) ) B3_REC_OP( 0x38, BodyEnableContactRecycling, RET_NONE, ARG( BODYID, body ) ARG( BOOL, flag ) ) B3_REC_OP( 0x39, BodyEnableHitEvents, RET_NONE, ARG( BODYID, body ) ARG( BOOL, flag ) ) -B3_REC_OP( 0x3A, BodyAllowFastRotation, RET_NONE, ARG( BODYID, body ) ARG( BOOL, flag ) ) -B3_REC_OP( 0x3B, BodySetSafetyFactor, RET_NONE, ARG( BODYID, body ) ARG( F32, value ) ) // Shape create/destroy B3_REC_OP( 0x40, CreateSphereShape, RET_SHAPEID, ARG( BODYID, body ) ARG( SHAPEDEF, def ) ARG( SPHERE, sphere ) ) @@ -96,11 +90,8 @@ B3_REC_OP( 0x57, ShapeEnablePreSolveEvents, RET_NONE, ARG( SHAPEID, shape ) ARG( B3_REC_OP( 0x58, ShapeEnableHitEvents, RET_NONE, ARG( SHAPEID, shape ) ARG( BOOL, flag ) ) B3_REC_OP( 0x59, ShapeSetSphere, RET_NONE, ARG( SHAPEID, shape ) ARG( SPHERE, sphere ) ) B3_REC_OP( 0x5A, ShapeSetCapsule, RET_NONE, ARG( SHAPEID, shape ) ARG( CAPSULE, capsule ) ) -B3_REC_OP( 0x5B, ShapeApplyWind, RET_NONE, ARG( SHAPEID, shape ) ARG( VEC3, wind ) ARG( F32, drag ) ARG( F32, lift ) ARG( F32, maxSpeed ) ARG( BOOL, wake ) ) -B3_REC_OP( 0x5C, ShapeSetName, RET_NONE, ARG( SHAPEID, shape ) ARG( STR, name ) ) -B3_REC_OP( 0x5D, ShapeSetMeshMaterial, RET_NONE, ARG( SHAPEID, shape ) ARG( MATERIAL, material ) ARG( I32, index ) ) -B3_REC_OP( 0x5E, ShapeSetHull, RET_NONE, ARG( SHAPEID, shape ) ARG( GEOMID, geometryId ) ) -B3_REC_OP( 0x5F, ShapeSetMesh, RET_NONE, ARG( SHAPEID, shape ) ARG( GEOMID, geometryId ) ARG( VEC3, scale ) ) +B3_REC_OP( 0x5B, ShapeApplyWind, RET_NONE, + ARG( SHAPEID, shape ) ARG( VEC3, wind ) ARG( F32, drag ) ARG( F32, lift ) ARG( F32, maxSpeed ) ARG( BOOL, wake ) ) // Joint create and destroy B3_REC_OP( 0x90, CreateParallelJoint, RET_JOINTID, ARG( WORLDID, world ) ARG( PARALLELJOINTDEF, def ) ) @@ -140,7 +131,7 @@ B3_REC_OP( 0xAB, DistanceJointEnableMotor, RET_NONE, ARG( JOINTID, joint ) ARG( B3_REC_OP( 0xAC, DistanceJointSetMotorSpeed, RET_NONE, ARG( JOINTID, joint ) ARG( F32, motorSpeed ) ) B3_REC_OP( 0xAD, DistanceJointSetMaxMotorForce, RET_NONE, ARG( JOINTID, joint ) ARG( F32, force ) ) -// Motor joint +// Motor joint (3D: linear/angular velocities are vec3) B3_REC_OP( 0xAE, MotorJointSetLinearVelocity, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, velocity ) ) B3_REC_OP( 0xAF, MotorJointSetAngularVelocity, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, velocity ) ) B3_REC_OP( 0xB0, MotorJointSetMaxVelocityForce, RET_NONE, ARG( JOINTID, joint ) ARG( F32, maxForce ) ) @@ -174,7 +165,7 @@ B3_REC_OP( 0xC7, RevoluteJointEnableMotor, RET_NONE, ARG( JOINTID, joint ) ARG( B3_REC_OP( 0xC8, RevoluteJointSetMotorSpeed, RET_NONE, ARG( JOINTID, joint ) ARG( F32, motorSpeed ) ) B3_REC_OP( 0xC9, RevoluteJointSetMaxMotorTorque, RET_NONE, ARG( JOINTID, joint ) ARG( F32, torque ) ) -// Spherical joint +// Spherical joint (3D-only) B3_REC_OP( 0xCA, SphericalJointEnableConeLimit, RET_NONE, ARG( JOINTID, joint ) ARG( BOOL, enableLimit ) ) B3_REC_OP( 0xCB, SphericalJointSetConeLimit, RET_NONE, ARG( JOINTID, joint ) ARG( F32, angleRadians ) ) B3_REC_OP( 0xCC, SphericalJointEnableTwistLimit, RET_NONE, ARG( JOINTID, joint ) ARG( BOOL, enableLimit ) ) @@ -193,7 +184,7 @@ B3_REC_OP( 0xD6, WeldJointSetLinearDampingRatio, RET_NONE, ARG( JOINTID, joint ) B3_REC_OP( 0xD7, WeldJointSetAngularHertz, RET_NONE, ARG( JOINTID, joint ) ARG( F32, hertz ) ) B3_REC_OP( 0xD8, WeldJointSetAngularDampingRatio, RET_NONE, ARG( JOINTID, joint ) ARG( F32, dampingRatio ) ) -// Wheel joint +// Wheel joint (Box3D uses Suspension/Spin/Steering naming) B3_REC_OP( 0xD9, WheelJointEnableSuspension, RET_NONE, ARG( JOINTID, joint ) ARG( BOOL, flag ) ) B3_REC_OP( 0xDA, WheelJointSetSuspensionHertz, RET_NONE, ARG( JOINTID, joint ) ARG( F32, hertz ) ) B3_REC_OP( 0xDB, WheelJointSetSuspensionDampingRatio, RET_NONE, ARG( JOINTID, joint ) ARG( F32, dampingRatio ) ) @@ -202,7 +193,8 @@ B3_REC_OP( 0xDD, WheelJointSetSuspensionLimits, RET_NONE, ARG( JOINTID, joint ) B3_REC_OP( 0xDE, WheelJointEnableSpinMotor, RET_NONE, ARG( JOINTID, joint ) ARG( BOOL, flag ) ) B3_REC_OP( 0xDF, WheelJointSetSpinMotorSpeed, RET_NONE, ARG( JOINTID, joint ) ARG( F32, speed ) ) -// Wheel joint continued, overflow past the 0xDF range. +// Wheel joint continued, overflow past the 0xDF range. Opcodes are arbitrary and need not match +// Box2D, so the wheel ops keep 0xE0-0xE7 and queries follow at 0xE8. B3_REC_OP( 0xE0, WheelJointSetMaxSpinTorque, RET_NONE, ARG( JOINTID, joint ) ARG( F32, torque ) ) B3_REC_OP( 0xE1, WheelJointEnableSteering, RET_NONE, ARG( JOINTID, joint ) ARG( BOOL, flag ) ) B3_REC_OP( 0xE2, WheelJointSetSteeringHertz, RET_NONE, ARG( JOINTID, joint ) ARG( F32, hertz ) ) @@ -212,22 +204,10 @@ B3_REC_OP( 0xE5, WheelJointEnableSteeringLimit, RET_NONE, ARG( JOINTID, joint ) B3_REC_OP( 0xE6, WheelJointSetSteeringLimits, RET_NONE, ARG( JOINTID, joint ) ARG( F32, lower ) ARG( F32, upper ) ) B3_REC_OP( 0xE7, WheelJointSetTargetSteeringAngle, RET_NONE, ARG( JOINTID, joint ) ARG( F32, radians ) ) -// Mover joint -B3_REC_OP( 0x81, CreateMoverJoint, RET_JOINTID, ARG( WORLDID, world ) ARG( MOVERJOINTDEF, def ) ) -B3_REC_OP( 0x82, MoverJointSetLinearVelocity, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, velocity ) ) -B3_REC_OP( 0x83, MoverJointSetMaxVelocityForce, RET_NONE, ARG( JOINTID, joint ) ARG( F32, maxForce ) ) - -// Pogo joint -B3_REC_OP( 0x84, CreatePogoJoint, RET_JOINTID, ARG( WORLDID, world ) ARG( POGOJOINTDEF, def ) ) -B3_REC_OP( 0x85, PogoJointSetRestLength, RET_NONE, ARG( JOINTID, joint ) ARG( F32, length ) ) -B3_REC_OP( 0x86, PogoJointSetSpringHertz, RET_NONE, ARG( JOINTID, joint ) ARG( F32, hertz ) ) -B3_REC_OP( 0x87, PogoJointSetSpringDampingRatio, RET_NONE, ARG( JOINTID, joint ) ARG( F32, dampingRatio ) ) -B3_REC_OP( 0x88, PogoJointSetMaxTensionForce, RET_NONE, ARG( JOINTID, joint ) ARG( F32, force ) ) -B3_REC_OP( 0x89, PogoJointSetMaxCompressionForce, RET_NONE, ARG( JOINTID, joint ) ARG( F32, force ) ) -B3_REC_OP( 0x8A, PogoJointSetNormal, RET_NONE, ARG( JOINTID, joint ) ARG( VEC3, normal ) ) - // Spatial queries. Inputs flow through the manifest (reader side). The hit tail and result are -// hand-written in recording.c / recording_replay.c since they are variable length. +// hand-written in recording.c / recording_replay.c since they are variable length. Query geometry is +// relative to the origin so a recording reproduces queries far from the world origin. OverlapAABB has +// no origin in 3D: the box is already world space. B3_REC_OP( 0xE8, QueryOverlapAABB, RET_NONE, ARG( WORLDID, world ) ARG( AABB, aabb ) ARG( QUERYFILTER, filter ) ) B3_REC_OP( 0xE9, QueryOverlapShape, RET_NONE, ARG( WORLDID, world ) ARG( POSITION, origin ) ARG( SHAPEPROXY, proxy ) ARG( QUERYFILTER, filter ) ) @@ -250,5 +230,5 @@ B3_REC_OP( 0xEF, QueryTag, RET_NONE, ARG( U64, key ) ) B3_REC_OP( 0xF1, StateHash, RET_NONE, ARG( WORLDID, world ) ARG( U64, hash ) ) -// Accumulated world bounds over the whole recording, written once at stop. +// Accumulated world bounds over the whole recording, written once at stop. Informational. B3_REC_OP( 0xF2, RecordingBounds, RET_NONE, ARG( AABB, bounds ) ) diff --git a/src/replay.c b/src/recording_replay.c similarity index 90% rename from src/replay.c rename to src/recording_replay.c index 78b73df..f0537e0 100644 --- a/src/replay.c +++ b/src/recording_replay.c @@ -5,15 +5,15 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include "replay.h" +#include "recording_replay.h" #include "body.h" +#include "compound.h" #include "physics_world.h" #include "world_snapshot.h" #include "box3d/box3d.h" -#include #include #include #include @@ -288,9 +288,6 @@ b3PlaneResult b3RecR_PLANERESULT( b3RecReader* rdr ) v.plane.normal = b3RecR_VEC3( rdr ); v.plane.offset = b3RecR_F32( rdr ); v.point = b3RecR_VEC3( rdr ); - v.triangleIndex = b3RecR_I32( rdr ); - v.childIndex = b3RecR_I32( rdr ); - v.materialIndex = b3RecR_I32( rdr ); return v; } @@ -378,8 +375,8 @@ b3MotionLocks b3RecR_LOCKS( b3RecReader* rdr ) // Rotating set of static string buffers, valid until the next 4 STR reads. const char* b3RecR_STR( b3RecReader* rdr ) { - char* buf = rdr->stringBuffers[rdr->nextString]; - rdr->nextString = ( rdr->nextString + 1 ) & 3; + char* buf = rdr->strBufs[rdr->strNext]; + rdr->strNext = ( rdr->strNext + 1 ) & 3; uint16_t len = b3RecR_U16( rdr ); if ( len == 0xFFFFu ) @@ -388,9 +385,9 @@ const char* b3RecR_STR( b3RecReader* rdr ) } int n = (int)len; - if ( n > B3_MAX_NAME_LENGTH ) + if ( n > B3_BODY_NAME_LENGTH ) { - n = B3_MAX_NAME_LENGTH; + n = B3_BODY_NAME_LENGTH; } b3RecRdrCheck( rdr, (int)len ); if ( rdr->ok && n > 0 ) @@ -428,7 +425,6 @@ b3BodyDef b3RecR_BODYDEF( b3RecReader* rdr ) def.angularDamping = b3RecR_F32( rdr ); def.gravityScale = b3RecR_F32( rdr ); def.sleepThreshold = b3RecR_F32( rdr ); - def.safetyFactor = b3RecR_F32( rdr ); def.name = b3RecR_STR( rdr ); (void)b3RecR_U64( rdr ); // userData placeholder def.motionLocks = b3RecR_LOCKS( rdr ); @@ -445,8 +441,6 @@ b3BodyDef b3RecR_BODYDEF( b3RecReader* rdr ) b3ShapeDef b3RecR_SHAPEDEF( b3RecReader* rdr ) { b3ShapeDef def = b3DefaultShapeDef(); - - def.name = b3RecR_STR( rdr ); (void)b3RecR_U64( rdr ); // userData placeholder int matCount = b3RecR_I32( rdr ); @@ -486,7 +480,6 @@ b3ShapeDef b3RecR_SHAPEDEF( b3RecReader* rdr ) def.enablePreSolveEvents = b3RecR_BOOL( rdr ); def.invokeContactCreation = b3RecR_BOOL( rdr ); def.updateBodyMass = b3RecR_BOOL( rdr ); - def.enableSpeculativeContact = b3RecR_BOOL( rdr ); def.userData = NULL; return def; } @@ -649,30 +642,6 @@ b3WheelJointDef b3RecR_WHEELJOINTDEF( b3RecReader* rdr ) return def; } -b3MoverJointDef b3RecR_MOVERJOINTDEF( b3RecReader* rdr ) -{ - b3MoverJointDef def = b3DefaultMoverJointDef(); - b3RecR_JointBase( rdr, &def.base ); - def.linearVelocity = b3RecR_VEC3( rdr ); - def.maxForce = b3RecR_F32( rdr ); - return def; -} - -b3PogoJointDef b3RecR_POGOJOINTDEF( b3RecReader* rdr ) -{ - b3PogoJointDef def = b3DefaultPogoJointDef(); - b3RecR_JointBase( rdr, &def.base ); - def.normal = b3RecR_VEC3( rdr ); - def.hertz = b3RecR_F32( rdr ); - def.dampingRatio = b3RecR_F32( rdr ); - def.restLength = b3RecR_F32( rdr ); - def.maxTensionForce = b3RecR_F32( rdr ); - def.maxCompressionForce = b3RecR_F32( rdr ); - def.impulse = b3RecR_F32( rdr ); - def.velocity = b3RecR_F32( rdr ); - return def; -} - // Outliner body tracking. Defined after the player struct; forward declared here because the // create/destroy dispatch sits above that struct. static void b3RecTrackBodyCreate( b3RecPlayer* player, b3BodyId id ); @@ -734,13 +703,37 @@ static void b3RecCheckJointId( b3RecReader* rdr, b3JointId got, b3JointId rec ) b3RecCheckId( rdr, "joint", got.index1, got.generation, rec.index1, rec.generation ); } -b3RegistrySlot* b3RecGetSlot( b3RecReader* rdr, uint32_t id, b3GeometryKind kind ) +// Registry slot reconstruction. Returns the live pointer for the given slot, building it +// on first use. The hull case is handled inline at the call site since it doesn't cache. + +static void* b3RecGetLiveMesh( b3RegistrySlot* slot ) { - if ( rdr == NULL || id >= (uint32_t)rdr->slotCount || rdr->slots[id].kind != kind ) + // Mesh is a self-contained blob used by reference, with no pointer fixup. Hand back the pristine + // bytes directly: they already outlive the world and are freed at teardown, so a copy would just + // double the memory. Compound can't do this, see b3RecGetLiveCompound. + return slot->bytes; +} + +static void* b3RecGetLiveHeightField( b3RegistrySlot* slot ) +{ + // Self-contained blob used by reference, like b3RecGetLiveMesh. The bytes already are a + // valid b3HeightFieldData with no pointer fixup, so hand them back directly. + return slot->bytes; +} + +static void* b3RecGetLiveCompound( b3RegistrySlot* slot ) +{ + if ( slot->live != NULL ) { - return NULL; + return slot->live; } - return rdr->slots + id; + // The copy is unavoidable here: b3ConvertBytesToCompound rewrites its input in place, while the + // pristine bytes must survive for keyframe registry seeding (b3RecSeedKeyframeRegistry). So we + // keep both the serialized bytes and a separate converted live object. + slot->live = b3Alloc( (size_t)slot->byteCount ); + memcpy( slot->live, slot->bytes, (size_t)slot->byteCount ); + b3ConvertBytesToCompound( (uint8_t*)slot->live, slot->byteCount ); + return slot->live; } // Dispatch functions, one per op @@ -819,23 +812,6 @@ static void b3RecDispatch_WorldEnableSpeculative( const b3RecArgs_WorldEnableSpe b3World_EnableSpeculative( rdr->replayWorldId, a->flag ); } -static void b3RecDispatch_WorldSetRestitutionIterations( const b3RecArgs_WorldSetRestitutionIterations* a, b3RecReader* rdr ) -{ - b3World_SetRestitutionIterations( rdr->replayWorldId, a->iterations ); -} - -static void b3RecDispatch_WorldEnableRestitutionPropagation( const b3RecArgs_WorldEnableRestitutionPropagation* a, - b3RecReader* rdr ) -{ - b3World_EnableRestitutionPropagation( rdr->replayWorldId, a->flag ); -} - -static void b3RecDispatch_WorldSetIsotropicInertiaTolerance( const b3RecArgs_WorldSetIsotropicInertiaTolerance* a, - b3RecReader* rdr ) -{ - b3World_SetIsotropicInertiaTolerance( rdr->replayWorldId, a->tolerance ); -} - static void b3RecDispatch_CreateBody( const b3RecArgs_CreateBody* a, b3RecReader* rdr ) { b3BodyId recId = b3RecR_BODYID( rdr ); @@ -957,11 +933,6 @@ static void b3RecDispatch_BodySetSleepThreshold( const b3RecArgs_BodySetSleepThr b3Body_SetSleepThreshold( b3RecMakeBodyId( rdr, a->body ), a->threshold ); } -static void b3RecDispatch_BodySetSafetyFactor( const b3RecArgs_BodySetSafetyFactor* a, b3RecReader* rdr ) -{ - b3Body_SetSafetyFactor( b3RecMakeBodyId( rdr, a->body ), a->value ); -} - static void b3RecDispatch_BodyDisable( const b3RecArgs_BodyDisable* a, b3RecReader* rdr ) { b3Body_Disable( b3RecMakeBodyId( rdr, a->body ) ); @@ -982,11 +953,6 @@ static void b3RecDispatch_BodySetBullet( const b3RecArgs_BodySetBullet* a, b3Rec b3Body_SetBullet( b3RecMakeBodyId( rdr, a->body ), a->flag ); } -static void b3RecDispatch_BodyAllowFastRotation( const b3RecArgs_BodyAllowFastRotation* a, b3RecReader* rdr ) -{ - b3Body_AllowFastRotation( b3RecMakeBodyId( rdr, a->body ), a->flag ); -} - static void b3RecDispatch_BodyEnableContactRecycling( const b3RecArgs_BodyEnableContactRecycling* a, b3RecReader* rdr ) { b3Body_EnableContactRecycling( b3RecMakeBodyId( rdr, a->body ), a->flag ); @@ -1021,13 +987,13 @@ static void b3RecDispatch_CreateHullShape( const b3RecArgs_CreateHullShape* a, b return; } uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryHull ); - if ( slot == NULL ) + if ( id >= (uint32_t)rdr->slotCount ) { - printf( "b3ReplayFile: hull geometryId %u is invalid\n", id ); + printf( "b3ReplayFile: hull geometryId %u out of range\n", id ); rdr->ok = false; return; } + b3RegistrySlot* slot = rdr->slots + id; b3BodyId bodyId = b3RecMakeBodyId( rdr, a->body ); // Hull is cloned by b3CreateHullShape into the world DB; no caching needed. b3ShapeId gotId = b3CreateHullShape( bodyId, &a->def, (const b3HullData*)slot->bytes ); @@ -1042,14 +1008,14 @@ static void b3RecDispatch_CreateMeshShape( const b3RecArgs_CreateMeshShape* a, b return; } uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryMesh ); - if ( slot == NULL ) + if ( id >= (uint32_t)rdr->slotCount ) { - printf( "b3ReplayFile: mesh geometryId %u is invalid\n", id ); + printf( "b3ReplayFile: mesh geometryId %u out of range\n", id ); rdr->ok = false; return; } - const b3MeshData* mesh = (const b3MeshData*)slot->bytes; + b3RegistrySlot* slot = rdr->slots + id; + const b3MeshData* mesh = (const b3MeshData*)b3RecGetLiveMesh( slot ); b3BodyId bodyId = b3RecMakeBodyId( rdr, a->body ); b3ShapeId gotId = b3CreateMeshShape( bodyId, &a->def, mesh, a->scale ); b3RecCheckShapeId( rdr, gotId, recId ); @@ -1063,14 +1029,20 @@ static void b3RecDispatch_CreateHeightFieldShape( const b3RecArgs_CreateHeightFi return; } uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryHeightField ); - if ( slot == NULL ) + if ( id >= (uint32_t)rdr->slotCount ) { - printf( "b3ReplayFile: heightfield geometryId %u is invalid\n", id ); + printf( "b3ReplayFile: heightfield geometryId %u out of range\n", id ); + rdr->ok = false; + return; + } + b3RegistrySlot* slot = rdr->slots + id; + const b3HeightFieldData* hf = (const b3HeightFieldData*)b3RecGetLiveHeightField( slot ); + if ( hf == NULL ) + { + printf( "b3ReplayFile: heightfield geometry %u is corrupt\n", id ); rdr->ok = false; return; } - const b3HeightFieldData* hf = (const b3HeightFieldData*)slot->bytes; b3BodyId bodyId = b3RecMakeBodyId( rdr, a->body ); b3ShapeId gotId = b3CreateHeightFieldShape( bodyId, &a->def, hf ); b3RecCheckShapeId( rdr, gotId, recId ); @@ -1084,18 +1056,18 @@ static void b3RecDispatch_CreateCompoundShape( const b3RecArgs_CreateCompoundSha return; } uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryCompound ); - if ( slot == NULL ) + if ( id >= (uint32_t)rdr->slotCount ) { - printf( "b3ReplayFile: compound geometryId %u is invalid\n", id ); + printf( "b3ReplayFile: compound geometryId %u out of range\n", id ); rdr->ok = false; return; } - const b3CompoundData* compound = (const b3CompoundData*)slot->bytes; + b3RegistrySlot* slot = rdr->slots + id; + const b3CompoundData* compound = (const b3CompoundData*)b3RecGetLiveCompound( slot ); b3BodyId bodyId = b3RecMakeBodyId( rdr, a->body ); // b3CreateCompoundShape takes a non-const def pointer; cast away const for the scratch def b3ShapeDef shapeDef = a->def; - b3ShapeId gotId = b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); + b3ShapeId gotId = b3CreateCompoundShape( bodyId, &shapeDef, compound ); b3RecCheckShapeId( rdr, gotId, recId ); } @@ -1104,11 +1076,6 @@ static void b3RecDispatch_DestroyShape( const b3RecArgs_DestroyShape* a, b3RecRe b3DestroyShape( b3RecMakeShapeId( rdr, a->shape ), a->updateBodyMass ); } -static void b3RecDispatch_ShapeSetName( const b3RecArgs_ShapeSetName* a, b3RecReader* rdr ) -{ - b3Shape_SetName( b3RecMakeShapeId( rdr, a->shape ), a->name ); -} - static void b3RecDispatch_ShapeSetDensity( const b3RecArgs_ShapeSetDensity* a, b3RecReader* rdr ) { b3Shape_SetDensity( b3RecMakeShapeId( rdr, a->shape ), a->density, a->updateBodyMass ); @@ -1129,11 +1096,6 @@ static void b3RecDispatch_ShapeSetSurfaceMaterial( const b3RecArgs_ShapeSetSurfa b3Shape_SetSurfaceMaterial( b3RecMakeShapeId( rdr, a->shape ), a->material ); } -static void b3RecDispatch_ShapeSetMeshMaterial( const b3RecArgs_ShapeSetMeshMaterial* a, b3RecReader* rdr ) -{ - b3Shape_SetMeshMaterial( b3RecMakeShapeId( rdr, a->shape ), a->material, a->index ); -} - static void b3RecDispatch_ShapeSetFilter( const b3RecArgs_ShapeSetFilter* a, b3RecReader* rdr ) { b3Shape_SetFilter( b3RecMakeShapeId( rdr, a->shape ), a->filter, a->invokeContacts ); @@ -1169,35 +1131,6 @@ static void b3RecDispatch_ShapeSetCapsule( const b3RecArgs_ShapeSetCapsule* a, b b3Shape_SetCapsule( b3RecMakeShapeId( rdr, a->shape ), &a->capsule ); } -static void b3RecDispatch_ShapeSetHull( const b3RecArgs_ShapeSetHull* a, b3RecReader* rdr ) -{ - uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryHull ); - if ( slot == NULL ) - { - printf( "b3ReplayFile: hull geometryId %u is invalid\n", id ); - rdr->ok = false; - return; - } - b3ShapeId shapeId = b3RecMakeShapeId( rdr, a->shape ); - b3Shape_SetHull( shapeId, (const b3HullData*)slot->bytes ); -} - -static void b3RecDispatch_ShapeSetMesh( const b3RecArgs_ShapeSetMesh* a, b3RecReader* rdr ) -{ - uint32_t id = a->geometryId; - b3RegistrySlot* slot = b3RecGetSlot( rdr, id, b3_geometryMesh ); - if ( slot == NULL ) - { - printf( "b3ReplayFile: mesh geometryId %u is invalid\n", id ); - rdr->ok = false; - return; - } - b3ShapeId shapeId = b3RecMakeShapeId( rdr, a->shape ); - const b3MeshData* mesh = (const b3MeshData*)slot->bytes; - b3Shape_SetMesh( shapeId, mesh, a->scale ); -} - static void b3RecDispatch_ShapeApplyWind( const b3RecArgs_ShapeApplyWind* a, b3RecReader* rdr ) { b3Shape_ApplyWind( b3RecMakeShapeId( rdr, a->shape ), a->wind, a->drag, a->lift, a->maxSpeed, a->wake ); @@ -1286,24 +1219,6 @@ static void b3RecDispatch_CreateWheelJoint( const b3RecArgs_CreateWheelJoint* a, b3RecCheckJointId( rdr, b3CreateWheelJoint( rdr->replayWorldId, &def ), recId ); } -static void b3RecDispatch_CreateMoverJoint( const b3RecArgs_CreateMoverJoint* a, b3RecReader* rdr ) -{ - b3JointId recId = b3RecR_JOINTID( rdr ); - b3MoverJointDef def = a->def; - def.base.bodyIdA = b3RecMakeBodyId( rdr, def.base.bodyIdA ); - def.base.bodyIdB = b3RecMakeBodyId( rdr, def.base.bodyIdB ); - b3RecCheckJointId( rdr, b3CreateMoverJoint( rdr->replayWorldId, &def ), recId ); -} - -static void b3RecDispatch_CreatePogoJoint( const b3RecArgs_CreatePogoJoint* a, b3RecReader* rdr ) -{ - b3JointId recId = b3RecR_JOINTID( rdr ); - b3PogoJointDef def = a->def; - def.base.bodyIdA = b3RecMakeBodyId( rdr, def.base.bodyIdA ); - def.base.bodyIdB = b3RecMakeBodyId( rdr, def.base.bodyIdB ); - b3RecCheckJointId( rdr, b3CreatePogoJoint( rdr->replayWorldId, &def ), recId ); -} - static void b3RecDispatch_DestroyJoint( const b3RecArgs_DestroyJoint* a, b3RecReader* rdr ) { b3DestroyJoint( b3RecMakeJointId( rdr, a->joint ), a->wakeAttached ); @@ -1710,60 +1625,14 @@ static void b3RecDispatch_WheelJointSetTargetSteeringAngle( const b3RecArgs_Whee b3WheelJoint_SetTargetSteeringAngle( b3RecMakeJointId( rdr, a->joint ), a->radians ); } -static void b3RecDispatch_MoverJointSetLinearVelocity( - const b3RecArgs_MoverJointSetLinearVelocity* a, b3RecReader* rdr ) -{ - b3MoverJoint_SetLinearVelocity( b3RecMakeJointId( rdr, a->joint ), a->velocity ); -} - -static void b3RecDispatch_MoverJointSetMaxVelocityForce( - const b3RecArgs_MoverJointSetMaxVelocityForce* a, b3RecReader* rdr ) -{ - b3MoverJoint_SetMaxVelocityForce( b3RecMakeJointId( rdr, a->joint ), a->maxForce ); -} - -static void b3RecDispatch_PogoJointSetRestLength( const b3RecArgs_PogoJointSetRestLength* a, - b3RecReader* rdr ) -{ - b3PogoJoint_SetRestLength( b3RecMakeJointId( rdr, a->joint ), a->length ); -} - -static void b3RecDispatch_PogoJointSetSpringHertz( const b3RecArgs_PogoJointSetSpringHertz* a, - b3RecReader* rdr ) -{ - b3PogoJoint_SetSpringHertz( b3RecMakeJointId( rdr, a->joint ), a->hertz ); -} - -static void b3RecDispatch_PogoJointSetSpringDampingRatio( - const b3RecArgs_PogoJointSetSpringDampingRatio* a, b3RecReader* rdr ) -{ - b3PogoJoint_SetSpringDampingRatio( b3RecMakeJointId( rdr, a->joint ), a->dampingRatio ); -} - -static void b3RecDispatch_PogoJointSetMaxTensionForce( - const b3RecArgs_PogoJointSetMaxTensionForce* a, b3RecReader* rdr ) -{ - b3PogoJoint_SetMaxTensionForce( b3RecMakeJointId( rdr, a->joint ), a->force ); -} - -static void b3RecDispatch_PogoJointSetMaxCompressionForce( - const b3RecArgs_PogoJointSetMaxCompressionForce* a, b3RecReader* rdr ) -{ - b3PogoJoint_SetMaxCompressionForce( b3RecMakeJointId( rdr, a->joint ), a->force ); -} - -static void b3RecDispatch_PogoJointSetNormal( const b3RecArgs_PogoJointSetNormal* a, b3RecReader* rdr ) -{ - b3PogoJoint_SetNormal( b3RecMakeJointId( rdr, a->joint ), a->normal ); -} - static void b3RecDispatch_StateHash( const b3RecArgs_StateHash* a, b3RecReader* rdr ) { b3World* world = b3GetWorldFromId( rdr->replayWorldId ); uint64_t computed = b3HashWorldState( world ); if ( computed != a->hash ) { - printf( "b3ReplayFile: StateHash mismatch (recorded=0x%" PRIx64 ", computed=0x%" PRIx64 ")\n", a->hash, computed ); + printf( "b3ReplayFile: StateHash mismatch (recorded=0x%llX, computed=0x%llX)\n", (unsigned long long)a->hash, + (unsigned long long)computed ); rdr->diverged = true; } } @@ -1886,8 +1755,7 @@ static bool b3RecReplayPlaneTrampoline( b3ShapeId id, const b3PlaneResult* plane const b3RecRecordedHit* h = &rc->hits[rc->cursor + i]; if ( b3RecVec3Differs( h->plane.plane.normal, planes[i].plane.normal ) || b3RecF32Differs( h->plane.plane.offset, planes[i].plane.offset ) || - b3RecVec3Differs( h->plane.point, planes[i].point ) || h->plane.triangleIndex != planes[i].triangleIndex || - h->plane.childIndex != planes[i].childIndex || h->plane.materialIndex != planes[i].materialIndex ) + b3RecVec3Differs( h->plane.point, planes[i].point ) ) { rc->rdr->diverged = true; } @@ -1957,7 +1825,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] = { 0 }; + b3Vec3 world[2 * B3_MAX_SHAPE_CAST_POINTS]; int n = 0; for ( int i = 0; i < count; ++i ) { @@ -2220,7 +2088,6 @@ static int b3RecDispatchOne( b3RecReader* rdr ) { return -1; } - int payloadStart = rdr->cursor; switch ( opcode ) @@ -2261,7 +2128,7 @@ static int b3RecDispatchOne( b3RecReader* rdr ) bool b3ValidateReplay( const void* data, int size, int workerCount ) { - b3RecPlayer* player = b3CreatePlayer( data, size, workerCount ); + b3RecPlayer* player = b3RecPlayer_Create( data, size, workerCount ); if ( player == NULL ) { return false; @@ -2276,7 +2143,7 @@ bool b3ValidateReplay( const void* data, int size, int workerCount ) } bool ok = player->rdr.ok && player->rdr.diverged == false; - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); return ok; } @@ -2465,14 +2332,14 @@ static void b3RecLoadTags( b3RecReader* rdr, const uint8_t* rp, const uint8_t* d { break; } - int n = len > B3_MAX_QUERY_NAME_LENGTH ? B3_MAX_QUERY_NAME_LENGTH : (int)len; + int n = len > B3_BODY_NAME_LENGTH ? B3_BODY_NAME_LENGTH : (int)len; tags[loaded].key = key; tags[loaded].id = id; if ( n > 0 ) { - memcpy( tags[loaded].queryName, sub.data + sub.cursor, (size_t)n ); + memcpy( tags[loaded].name, sub.data + sub.cursor, (size_t)n ); } - tags[loaded].queryName[n] = '\0'; + tags[loaded].name[n] = '\0'; sub.cursor += len; b3RecTagLookup_insert( map, key, loaded ); loaded += 1; @@ -2484,24 +2351,6 @@ static void b3RecLoadTags( b3RecReader* rdr, const uint8_t* rp, const uint8_t* d rdr->tagMap = map; } -// Free slots loaded by b3RecLoadSlots. -static void b3RecFreeSlots( b3RegistrySlot* slots, int slotCount ) -{ - if ( slots == NULL ) - { - return; - } - for ( int i = 0; i < slotCount; ++i ) - { - b3RegistrySlot* slot = slots + i; - if ( slot->bytes != NULL ) - { - b3Free( slot->bytes, (size_t)slot->byteCount ); - } - } - b3Free( slots, (size_t)slotCount * sizeof( b3RegistrySlot ) ); -} - // Load the trailing registry block and fill rdr->slots/slotCount, then the optional tag table. // Returns true on success. On failure sets rdr->ok = false and returns false. static bool b3RecLoadSlots( b3RecReader* rdr, const void* data, int size, uint64_t registryOffset, uint64_t registryByteCount ) @@ -2555,43 +2404,42 @@ static bool b3RecLoadSlots( b3RecReader* rdr, const void* data, int size, uint64 if ( rp + 5 > dataEnd ) { printf( "b3ReplayFile: registry truncated at entry %u\n", i ); - b3RecFreeSlots( slots, (int)count ); + for ( uint32_t j = 0; j < i; ++j ) + { + if ( slots[j].bytes != NULL ) + { + b3Free( slots[j].bytes, (size_t)slots[j].byteCount ); + } + } + b3Free( slots, (size_t)count * sizeof( b3RegistrySlot ) ); return false; } uint8_t kind = rp[0]; uint32_t byteCount = (uint32_t)rp[1] | ( (uint32_t)rp[2] << 8 ) | ( (uint32_t)rp[3] << 16 ) | ( (uint32_t)rp[4] << 24 ); rp += 5; - const char* error = NULL; - if ( byteCount == 0 || byteCount > INT32_MAX ) + if ( rp + byteCount > dataEnd ) { - error = "has an invalid byte count"; - } - else if ( (size_t)byteCount > (size_t)( dataEnd - rp ) ) - { - error = "bytes out of bounds"; - } - else - { - uint8_t* bytes = (uint8_t*)b3Alloc( (size_t)byteCount ); - memcpy( bytes, rp, (size_t)byteCount ); - slots[i].kind = (b3GeometryKind)kind; - slots[i].byteCount = (int)byteCount; - slots[i].bytes = bytes; - - // Validate the compound. - // todo validate other types? - if ( kind == b3_geometryCompound && b3ValidateCompound( bytes, (int)byteCount ) == NULL ) + printf( "b3ReplayFile: registry entry %u bytes out of bounds\n", i ); + for ( uint32_t j = 0; j < i; ++j ) { - error = "is not a valid compound"; + if ( slots[j].bytes != NULL ) + { + b3Free( slots[j].bytes, (size_t)slots[j].byteCount ); + } } - } - if ( error != NULL ) - { - printf( "b3ReplayFile: registry entry %u %s\n", i, error ); - b3RecFreeSlots( slots, (int)count ); + b3Free( slots, (size_t)count * sizeof( b3RegistrySlot ) ); return false; } + uint8_t* bytes = (uint8_t*)b3Alloc( byteCount > 0 ? (size_t)byteCount : 1u ); + if ( byteCount > 0 ) + { + memcpy( bytes, rp, (size_t)byteCount ); + } rp += byteCount; + slots[i].kind = (b3GeometryKind)kind; + slots[i].byteCount = (int)byteCount; + slots[i].bytes = bytes; + slots[i].live = NULL; } rdr->slots = slots; @@ -2600,6 +2448,36 @@ static bool b3RecLoadSlots( b3RecReader* rdr, const void* data, int size, uint64 return true; } +// Free slots loaded by b3RecLoadSlots. +static void b3RecFreeSlots( b3RegistrySlot* slots, int slotCount ) +{ + if ( slots == NULL ) + { + return; + } + for ( int i = 0; i < slotCount; ++i ) + { + b3RegistrySlot* slot = slots + i; + if ( slot->live != NULL ) + { + switch ( slot->kind ) + { + // Mesh and height field have no separate live object; they borrow the bytes freed below. + case b3_geometryCompound: + b3Free( slot->live, (size_t)slot->byteCount ); + break; + default: + break; + } + } + if ( slot->bytes != NULL ) + { + b3Free( slot->bytes, slot->byteCount > 0 ? (size_t)slot->byteCount : 1u ); + } + } + b3Free( slots, (size_t)slotCount * sizeof( b3RegistrySlot ) ); +} + // Walk the op stream once without dispatching: count Step ops and grab the first step's tuning. static void b3RecScanFile( b3RecPlayer* player ) { @@ -2667,8 +2545,15 @@ static void b3RecSeedKeyframeRegistry( b3RecPlayer* player ) for ( int i = 0; i < player->rdr.slotCount; ++i ) { b3RegistrySlot* slot = player->rdr.slots + i; - uint64_t h = b3Hash64NonZero( slot->bytes, slot->byteCount ); - uint32_t id = b3AppendGeometry( reg, slot->kind, h, slot->bytes, slot->byteCount ); + // Copy so the registry can take ownership. + int n = slot->byteCount > 0 ? slot->byteCount : 1; + uint8_t* copy = (uint8_t*)b3Alloc( (size_t)n ); + if ( slot->byteCount > 0 ) + { + memcpy( copy, slot->bytes, (size_t)slot->byteCount ); + } + uint64_t h = b3Hash64Blob( slot->bytes, slot->byteCount ); + uint32_t id = b3AppendGeometry( reg, slot->kind, h, copy, slot->byteCount ); // Seeding in order without dedup keeps id == slot index. B3_ASSERT( id == (uint32_t)i ); (void)id; @@ -2682,12 +2567,12 @@ static void b3RecCaptureKeyframe( b3RecPlayer* player ) b3World* world = b3GetWorldFromId( player->rdr.replayWorldId ); b3RecBuffer buf = { 0 }; - int regCountBefore = player->keyframeRec->registry.entries.count; + int regCountBefore = player->keyframeRec->registry.count; B3_UNUSED( regCountBefore ); b3SerializeWorld( world, &buf, player->keyframeRec ); // Registry must not grow: all geometry was pre-seeded and the registry dedups exactly. - B3_ASSERT( player->keyframeRec->registry.entries.count == regCountBefore ); + B3_ASSERT( player->keyframeRec->registry.count == regCountBefore ); size_t bodyBytes = (size_t)player->bodyIdCount * sizeof( b3BodyId ); size_t newBytes = (size_t)buf.capacity + bodyBytes; @@ -2766,7 +2651,6 @@ static void b3RecPlayerRestoreKeyframe( b3RecPlayer* player, const b3RecKeyframe player->frame = kf->frame; player->divergeFrame = kf->divergeFrame; player->atEnd = false; - player->atPreStep = false; // Restore the outliner list verbatim so ordinals match this frame. b3RecGrow( (void**)&player->bodyIds, &player->bodyIdCap, kf->bodyIdCount, 0, (int)sizeof( b3BodyId ) ); @@ -2791,7 +2675,7 @@ static b3WorldId b3RecPlayerCreateWorld( const b3RecPlayer* player ) return b3CreateWorld( &worldDef ); } -b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount ) +b3RecPlayer* b3RecPlayer_Create( const void* data, int size, int workerCount ) { if ( data == NULL || size < (int)sizeof( b3RecHeader ) ) { @@ -2848,10 +2732,10 @@ b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount ) int registryEnd = (int)registryEnd64; // Own a private copy so the caller can free their buffer right away. - uint8_t* copy = b3Alloc( (size_t)size ); + uint8_t* copy = (uint8_t*)b3Alloc( (size_t)size ); memcpy( copy, data, (size_t)size ); - b3RecPlayer* player = b3Alloc( sizeof( b3RecPlayer ) ); + b3RecPlayer* player = (b3RecPlayer*)b3Alloc( sizeof( b3RecPlayer ) ); memset( player, 0, sizeof( b3RecPlayer ) ); player->data = copy; @@ -2866,7 +2750,6 @@ b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount ) player->recordedSubStepCount = 0; player->recordedWorkerCount = workerCount; player->atEnd = false; - player->atPreStep = false; player->divergeFrame = -1; player->keyframeMinInterval = B3_REC_KEYFRAME_INTERVAL_DEFAULT; player->keyframeInterval = B3_REC_KEYFRAME_INTERVAL_DEFAULT; @@ -2945,7 +2828,7 @@ b3RecPlayer* b3CreatePlayer( const void* data, int size, int workerCount ) return player; } -void b3DestroyPlayer( b3RecPlayer* player ) +void b3RecPlayer_Destroy( b3RecPlayer* player ) { if ( player == NULL ) { @@ -2957,7 +2840,7 @@ void b3DestroyPlayer( b3RecPlayer* player ) b3DestroyWorld( player->rdr.replayWorldId ); } - // Free shape data. + // Free live geometry after destroying the world (slot->live may be used by the world). b3RecFreeSlots( player->rdr.slots, player->rdr.slotCount ); // Free reader scratch. @@ -3031,9 +2914,6 @@ void b3DestroyPlayer( b3RecPlayer* player ) bool b3RecPlayer_StepFrame( b3RecPlayer* player ) { - // This is never true when full stepping - player->atPreStep = false; - if ( player->atEnd ) { return false; @@ -3095,91 +2975,6 @@ bool b3RecPlayer_StepFrame( b3RecPlayer* player ) } } -void b3RecPlayer_SubStepFrame( b3RecPlayer* player ) -{ - if ( player->atEnd ) - { - return; - } - - // Reset the per-frame query store before this frame's records are dispatched. - if ( player->atPreStep == false ) - { - player->frameQueryCount = 0; - player->frameHitCount = 0; - } - - // A frame is its leading inputs (queries and between-step mutators), one Step, and the Step's - // trailing StateHash. Queries are recorded before the Step they belong to, so they stash here - // against the world state they were computed for. - bool stepped = false; - bool haveCreateBodyOp = false; - for ( ;; ) - { - if ( player->rdr.cursor >= player->registryEnd || !player->rdr.ok ) - { - player->atEnd = true; - player->atPreStep = false; - return; - } - - // Once stepped, the StateHash is the only record still belonging to this frame. Anything else - // begins the next frame, so stop and let the next StepFrame consume it. Capture a keyframe at - // the boundary. - uint8_t currentOpCode = player->rdr.data[player->rdr.cursor]; - if ( stepped && currentOpCode != b3_recOpStateHash ) - { - if ( player->frame > player->lastKeyframeFrame && player->frame % player->keyframeInterval == 0 ) - { - b3RecCaptureKeyframe( player ); - } - return; - } - - if ( player->atPreStep == false && haveCreateBodyOp == true && currentOpCode == b3_recOpStep ) - { - player->atPreStep = true; - return; - } - - int op = b3RecDispatchOne( &player->rdr ); - if ( op < 0 ) - { - player->atEnd = true; - player->atPreStep = false; - return; - } - if ( op == b3_recOpDestroyWorld ) // end of recording - { - player->atEnd = true; - player->atPreStep = false; - return; - } - - if ( op == b3_recOpCreateBody ) - { - B3_ASSERT( player->atPreStep == false ); - haveCreateBodyOp = true; - } - - if ( op == b3_recOpStep ) - { - player->atPreStep = false; - player->frame += 1; - stepped = true; - } - else if ( op == b3_recOpStateHash ) // trailing record of the frame just stepped - { - // Latch the first frame whose state hash diverged. The hash belongs to the frame Step just - // advanced, so latch against the current frame, not the next Step which would be one late. - if ( player->divergeFrame < 0 && player->rdr.diverged ) - { - player->divergeFrame = player->frame; - } - } - } -} - void b3RecPlayer_Restart( b3RecPlayer* player ) { // Restore the frame-0 image in place so the replay world id stays stable across a restart or @@ -3196,7 +2991,6 @@ void b3RecPlayer_Restart( b3RecPlayer* player ) player->frame = 0; player->divergeFrame = -1; player->atEnd = false; - player->atPreStep = false; // Frame 0 is the pre-step snapshot with no recorded queries, so clear the per-frame store. This // keeps the last stepped frame's queries from lingering on a restart or a backward scrub to 0. @@ -3218,9 +3012,6 @@ void b3RecPlayer_SeekFrame( b3RecPlayer* player, int targetFrame ) { return; } - - player->atPreStep = false; - if ( targetFrame < 0 ) { targetFrame = 0; @@ -3280,11 +3071,6 @@ bool b3RecPlayer_IsAtEnd( const b3RecPlayer* player ) return player != NULL ? player->atEnd : true; } -bool b3RecPlayer_IsAtPreStep( const b3RecPlayer* player ) -{ - return player != NULL ? player->atPreStep : false; -} - bool b3RecPlayer_HasDiverged( const b3RecPlayer* player ) { return player != NULL ? player->rdr.diverged : false; @@ -3529,7 +3315,7 @@ void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int q { b3Pos c1 = b3OffsetPos( q->origin, q->mover.center1 ); b3Pos c2 = b3OffsetPos( q->origin, q->mover.center2 ); - b3HexColor c = b3_colorLightSkyBlue; + b3HexColor c = q->kind == b3_colorLightSkyBlue; if ( draw->DrawCapsuleFcn ) { draw->DrawCapsuleFcn( c1, c2, q->mover.radius, b3RecQuerySelColor( selected, c ), 0.6f, draw->context ); @@ -3549,7 +3335,7 @@ void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int q { b3Pos c1 = b3OffsetPos( q->origin, q->mover.center1 ); b3Pos c2 = b3OffsetPos( q->origin, q->mover.center2 ); - b3HexColor c = b3_colorTan; + b3HexColor c = q->kind == b3_colorTan; if ( draw->DrawCapsuleFcn ) { draw->DrawCapsuleFcn( c1, c2, q->mover.radius, b3RecQuerySelColor( selected, c ), 0.6f, draw->context ); @@ -3600,22 +3386,22 @@ void b3RecPlayer_DrawFrameQueries( b3RecPlayer* player, b3DebugDraw* draw, int q if ( b3RecTagLookup_is_end( it ) == false ) { const b3RecTag* tag = &player->rdr.tags[it.data->val]; - name = tag->queryName; + name = tag->name; id = tag->id; } } char label[64]; if ( name != NULL && name[0] != '\0' && id != 0 ) { - snprintf( label, sizeof( label ), "%.40s (%" PRIu64 ")", name, id ); + snprintf( label, sizeof( label ), "%s (%llu)", name, (unsigned long long)id ); } else if ( name != NULL && name[0] != '\0' ) { - snprintf( label, sizeof( label ), "%.40s", name ); + snprintf( label, sizeof( label ), "%s", name ); } else { - snprintf( label, sizeof( label ), "#%" PRIu64, id ); + snprintf( label, sizeof( label ), "#%llu", (unsigned long long)id ); } b3Pos labelPos = q->origin; if ( q->kind == B3_RECQ_OVERLAP_AABB ) @@ -3671,7 +3457,7 @@ b3RecQueryInfo b3RecPlayer_GetFrameQuery( const b3RecPlayer* player, int index ) const b3RecTag* tag = &player->rdr.tags[it.data->val]; info.id = tag->id; // An id-only tag interns an empty name; report it as none so the viewer shows the id alone. - info.name = tag->queryName[0] != '\0' ? tag->queryName : NULL; + info.name = tag->name[0] != '\0' ? tag->name : NULL; } } return info; diff --git a/src/replay.h b/src/recording_replay.h similarity index 92% rename from src/replay.h rename to src/recording_replay.h index 8aeddd9..e343d2b 100644 --- a/src/replay.h +++ b/src/recording_replay.h @@ -63,18 +63,15 @@ typedef struct b3RecDrawQuery } b3RecDrawQuery; // One slot in the preloaded geometry registry. Loaded from the trailing block before any -// ops run. +// ops run; live pointer built lazily on first shape create that references the id. typedef struct b3RegistrySlot { b3GeometryKind kind; int byteCount; uint8_t* bytes; // raw bytes from the file (always freed at teardown) + void* live; // reconstructed live object, freed after b3DestroyWorld } b3RegistrySlot; -// This is used to simplify the scratch buffer lifetime. Names longer than this probably -// indicate a bug. -#define B3_MAX_NAME_LENGTH 256 - // Reader state threaded through the replay loop and all dispatch functions typedef struct b3RecReader { @@ -93,9 +90,9 @@ typedef struct b3RecReader b3SurfaceMaterial* matScratch; int matScratchCap; - // Scratch for string reads. Used by b3RecR_STR to pass names to b3BodyDef and b3ShapeDef. - char stringBuffers[4][B3_MAX_NAME_LENGTH + 1]; - int nextString; + // Scratch for string reads: rotating slots, valid until the next 4 STR reads + char strBufs[4][B3_BODY_NAME_LENGTH + 1]; + int strNext; // Preloaded geometry registry b3RegistrySlot* slots; @@ -137,7 +134,7 @@ typedef struct b3RecKeyframe int bodyIdCount; } b3RecKeyframe; -typedef struct b3RecPlayer +struct b3RecPlayer { uint8_t* data; // owned copy of recording bytes int size; @@ -152,9 +149,6 @@ typedef struct b3RecPlayer int recordedWorkerCount; // worker count requested for the replay world b3AABB bounds; // accumulated world bounds, decoded from the trailing record bool atEnd; - // Indicates all ops for the step have been consumed up to the world step op. The next sub-step - // will clear this and perform the world step. - bool atPreStep; int divergeFrame; // first frame that diverged, -1 until then // Outliner body list, indexed by creation ordinal. Holes (null ids) mark destroyed bodies so @@ -203,7 +197,7 @@ typedef struct b3RecPlayer // Pre-populated recording used by b3SerializeWorld during keyframe capture. // Its registry mirrors rdr.slots so geometry ids stay stable. b3Recording* keyframeRec; -} b3RecPlayer; +}; // Read primitives uint8_t b3RecR_U8( b3RecReader* rdr ); @@ -246,8 +240,6 @@ b3RevoluteJointDef b3RecR_REVOLUTEJOINTDEF( b3RecReader* rdr ); b3SphericalJointDef b3RecR_SPHERICALJOINTDEF( b3RecReader* rdr ); b3WeldJointDef b3RecR_WELDJOINTDEF( b3RecReader* rdr ); b3WheelJointDef b3RecR_WHEELJOINTDEF( b3RecReader* rdr ); -b3MoverJointDef b3RecR_MOVERJOINTDEF( b3RecReader* rdr ); -b3PogoJointDef b3RecR_POGOJOINTDEF( b3RecReader* rdr ); b3QueryFilter b3RecR_QUERYFILTER( b3RecReader* rdr ); b3ShapeProxy b3RecR_SHAPEPROXY( b3RecReader* rdr ); b3TreeStats b3RecR_TREESTATS( b3RecReader* rdr ); @@ -257,6 +249,3 @@ b3PlaneResult b3RecR_PLANERESULT( b3RecReader* rdr ); // Grow the reader's hit scratch to at least n entries, preserving contents. n is bounded by the // file size since every recorded hit consumes at least one byte. void b3RecEnsureHits( b3RecReader* rdr, int n ); - -// Get a geometry slot with kind validation. -b3RegistrySlot* b3RecGetSlot( b3RecReader* rdr, uint32_t id, b3GeometryKind kind ); diff --git a/src/revolute_joint.c b/src/revolute_joint.c index 899d2d8..7856a83 100644 --- a/src/revolute_joint.c +++ b/src/revolute_joint.c @@ -267,8 +267,8 @@ void b3PrepareRevoluteJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -411,111 +411,106 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia b3Quat relQ = b3InvMulQuat( quatA, quatB ); - if ( fixedRotation == false && ( joint->enableSpring || joint->enableMotor || joint->enableLimit ) ) + // Solve spring + if ( joint->enableSpring && fixedRotation == false ) { + // Get the substep relative rotation + float targetAngle = joint->targetAngle; + float angle = b3GetTwistAngle( relQ ); + float c = angle - targetAngle; + + float bias = joint->springSoftness.biasRate * c; + float massScale = joint->springSoftness.massScale; + float impulseScale = joint->springSoftness.impulseScale; + float cdot = b3Dot( b3Sub( wB, wA ), joint->rotationAxisZ ); + + float deltaImpulse = -massScale * joint->axialMass * ( cdot + bias ) - impulseScale * joint->springImpulse; + joint->springImpulse += deltaImpulse; + + wA = b3MulSub( wA, deltaImpulse, b3MulMV( iA, joint->rotationAxisZ ) ); + wB = b3MulAdd( wB, deltaImpulse, b3MulMV( iB, joint->rotationAxisZ ) ); + } + + if ( joint->enableMotor && fixedRotation == false ) + { + float cdot = b3Dot( b3Sub( wB, wA ), joint->rotationAxisZ ) - joint->motorSpeed; + + float deltaImpulse = -joint->axialMass * cdot; + float newImpulse = joint->motorImpulse + deltaImpulse; + float maxImpulse = joint->maxMotorTorque * context->h; + newImpulse = b3ClampFloat( newImpulse, -maxImpulse, maxImpulse ); + deltaImpulse = newImpulse - joint->motorImpulse; + joint->motorImpulse = newImpulse; + + wA = b3MulSub( wA, deltaImpulse, b3MulMV( iA, joint->rotationAxisZ ) ); + wB = b3MulAdd( wB, deltaImpulse, b3MulMV( iB, joint->rotationAxisZ ) ); + } + + if ( joint->enableLimit && fixedRotation == false ) + { + float angle = b3GetTwistAngle( relQ ); + + // todo does an updated twist axis help? + b3Vec3 axis = joint->rotationAxisZ; - b3Vec3 gA = b3MulMV( iA, axis ); - b3Vec3 gB = b3MulMV( iB, axis ); - float k = b3Dot( axis, b3Add( gA, gB ) ); - float axialCdot = b3Dot( b3Sub( wB, wA ), axis ); - float axialImpulse = 0.0f; - // Solve spring - if ( joint->enableSpring ) + // Lower limit { - // Get the substep relative rotation - float targetAngle = joint->targetAngle; - float angle = b3GetTwistAngle( relQ ); - float c = angle - targetAngle; - - float bias = joint->springSoftness.biasRate * c; - float massScale = joint->springSoftness.massScale; - float impulseScale = joint->springSoftness.impulseScale; - - float deltaImpulse = -massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * joint->springImpulse; - joint->springImpulse += deltaImpulse; - - axialCdot += k * deltaImpulse; - axialImpulse += deltaImpulse; - } - - if ( joint->enableMotor ) - { - float cdot = axialCdot - joint->motorSpeed; - float oldImpulse = joint->motorImpulse; - float maxImpulse = joint->maxMotorTorque * context->h; - float deltaImpulse = b3ClampFloat( -joint->axialMass * cdot, -maxImpulse - oldImpulse, maxImpulse - oldImpulse ); - joint->motorImpulse = oldImpulse + deltaImpulse; - - axialCdot += k * deltaImpulse; - axialImpulse += deltaImpulse; - } - - if ( joint->enableLimit ) - { - float angle = b3GetTwistAngle( relQ ); - - // todo does an updated twist axis help? - - // Lower limit + float c = angle - joint->lowerAngle; + float bias = 0.0f; + float massScale = 1.0f; + float impulseScale = 0.0f; + if ( c > 0.0f ) { - float c = angle - joint->lowerAngle; - float bias = 0.0f; - float massScale = 1.0f; - float impulseScale = 0.0f; - if ( c > 0.0f ) - { - // speculation - bias = c * context->inv_h; - } - else if ( useBias ) - { - bias = base->constraintSoftness.biasRate * c; - massScale = base->constraintSoftness.massScale; - impulseScale = base->constraintSoftness.impulseScale; - } - - float oldImpulse = joint->lowerImpulse; - float deltaImpulse = - b3MaxFloat( -massScale * joint->axialMass * ( axialCdot + bias ) - impulseScale * oldImpulse, -oldImpulse ); - joint->lowerImpulse = oldImpulse + deltaImpulse; - - axialCdot += k * deltaImpulse; - axialImpulse += deltaImpulse; + // speculation + bias = c * context->inv_h; + } + else if ( useBias ) + { + bias = base->constraintSoftness.biasRate * c; + massScale = base->constraintSoftness.massScale; + impulseScale = base->constraintSoftness.impulseScale; } - // Upper limit - { - float c = joint->upperAngle - angle; - float bias = 0.0f; - float massScale = 1.0f; - float impulseScale = 0.0f; - if ( c > 0.0f ) - { - // speculation - bias = c * context->inv_h; - } - else if ( useBias ) - { - bias = base->constraintSoftness.biasRate * c; - massScale = base->constraintSoftness.massScale; - impulseScale = base->constraintSoftness.impulseScale; - } + float cdot = b3Dot( b3Sub( wB, wA ), axis ); + float oldImpulse = joint->lowerImpulse; + float deltaImpulse = -massScale * joint->axialMass * ( cdot + bias ) - impulseScale * oldImpulse; + joint->lowerImpulse = b3MaxFloat( oldImpulse + deltaImpulse, 0.0f ); + deltaImpulse = joint->lowerImpulse - oldImpulse; - // sign flipped on Cdot - float cdot = -axialCdot; - float oldImpulse = joint->upperImpulse; - float deltaImpulse = - b3MaxFloat( -massScale * joint->axialMass * ( cdot + bias ) - impulseScale * oldImpulse, -oldImpulse ); - joint->upperImpulse = oldImpulse + deltaImpulse; - - // sign flipped on applied impulse - axialImpulse -= deltaImpulse; - } + wA = b3MulSub( wA, deltaImpulse, b3MulMV( iA, axis ) ); + wB = b3MulAdd( wB, deltaImpulse, b3MulMV( iB, axis ) ); } - wA = b3MulSub( wA, axialImpulse, gA ); - wB = b3MulAdd( wB, axialImpulse, gB ); + // Upper limit + { + float c = joint->upperAngle - angle; + float bias = 0.0f; + float massScale = 1.0f; + float impulseScale = 0.0f; + if ( c > 0.0f ) + { + // speculation + bias = c * context->inv_h; + } + else if ( useBias ) + { + bias = base->constraintSoftness.biasRate * c; + massScale = base->constraintSoftness.massScale; + impulseScale = base->constraintSoftness.impulseScale; + } + + // sign flipped on Cdot + float cdot = b3Dot( b3Sub( wA, wB ), axis ); + float oldImpulse = joint->upperImpulse; + float deltaImpulse = -massScale * joint->axialMass * ( cdot + bias ) - impulseScale * oldImpulse; + joint->upperImpulse = b3MaxFloat( oldImpulse + deltaImpulse, 0.0f ); + deltaImpulse = joint->upperImpulse - oldImpulse; + + // sign flipped on applied impulse + wA = b3MulAdd( wA, deltaImpulse, b3MulMV( iA, axis ) ); + wB = b3MulSub( wB, deltaImpulse, b3MulMV( iB, axis ) ); + } } // Collinearity constraint @@ -582,7 +577,17 @@ void b3SolveRevoluteJoint( b3JointSim* base, b3StepContext* context, bool useBia impulseScale = base->constraintSoftness.impulseScale; } - b3Vec3 b = b3SolvePointConstraint( mA, mB, base->invIA, base->invIB, rA, rB, b3Add( cdot, bias ) ); + //// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] + b3Matrix3 sA = b3Skew( rA ); + b3Matrix3 sB = b3Skew( rB ); + b3Matrix3 kA = b3MulMM( sA, b3MulMM( base->invIA, sA ) ); + b3Matrix3 kB = b3MulMM( sB, b3MulMM( base->invIB, sB ) ); + b3Matrix3 k = b3NegateMat3( b3AddMM( kA, kB ) ); + k.cx.x += mA + mB; + k.cy.y += mA + mB; + k.cz.z += mA + mB; + + b3Vec3 b = b3Solve3( k, b3Add( cdot, bias ) ); b3Vec3 impulse = b3Sub( b3MulSV( -massScale, b ), b3MulSV( impulseScale, joint->linearImpulse ) ); joint->linearImpulse = b3Add( joint->linearImpulse, impulse ); diff --git a/src/scheduler.c b/src/scheduler.c index 9a2cdc9..7bcde42 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -7,7 +7,6 @@ #include "box3d/base.h" #include "box3d/constants.h" -#include "box3d/types.h" #include #include @@ -123,7 +122,7 @@ b3Scheduler* b3CreateScheduler( int workerCount ) scheduler->workerContexts[i].threadIndex = i + 1; char name[16]; - snprintf( name, sizeof( name ), "box3d_worker_%02d", i + 1 ); + snprintf( name, sizeof( name ), "box2d_worker_%02d", i + 1 ); scheduler->threads[i] = b3CreateThread( b3SchedulerWorkerMain, scheduler->workerContexts + i, name ); } @@ -155,9 +154,9 @@ void b3ResetScheduler( b3Scheduler* scheduler ) b3AtomicStoreInt( &scheduler->nextSlot, 0 ); } -void* b3SchedulerEnqueueTask( b3TaskCallback* task, void* taskContext, void* userContext, b3TaskType taskType ) +void* b3SchedulerEnqueueTask( b3TaskCallback* task, void* taskContext, void* userContext, const char* name ) { - B3_UNUSED( taskType ); + B3_UNUSED( name ); b3Scheduler* scheduler = userContext; int slot = b3AtomicFetchAddInt( &scheduler->nextSlot, 1 ); diff --git a/src/scheduler.h b/src/scheduler.h index b5963c5..f9aeff7 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -2,7 +2,6 @@ // SPDX-License-Identifier: MIT #pragma once -#include "box3d/types.h" typedef void b3TaskCallback( void* taskContext ); typedef struct b3Scheduler b3Scheduler; @@ -12,5 +11,5 @@ void b3DestroyScheduler( b3Scheduler* scheduler ); void b3ResetScheduler( b3Scheduler* scheduler ); // See b3EnqueueTaskCallback and b3FinishTaskCallback -void* b3SchedulerEnqueueTask( b3TaskCallback* task, void* taskContext, void* userContext, b3TaskType taskType ); +void* b3SchedulerEnqueueTask( b3TaskCallback* task, void* taskContext, void* userContext, const char* name ); void b3SchedulerFinishTask( void* userTask, void* userContext ); diff --git a/src/sensor.c b/src/sensor.c index 8dc1e26..e0221f5 100644 --- a/src/sensor.c +++ b/src/sensor.c @@ -53,7 +53,7 @@ static bool b3OverlapSensor( b3Shape* sensorShape, b3Transform sensorTransform, return b3OverlapCapsule( &sensorShape->capsule, b3Transform_identity, &localProxy ); case b3_compoundShape: - return b3OverlapCompound( sensorShape->compound, b3Transform_identity, &localProxy ); + return b3OverlapCompound( sensorShape->compound , b3Transform_identity, &localProxy ); case b3_heightShape: return b3OverlapHeightField( sensorShape->heightField, b3Transform_identity, &localProxy ); @@ -107,14 +107,15 @@ static bool b3SensorQueryCallback( int proxyId, uint64_t userData, void* context b3World* world = queryContext->world; b3Shape* otherShape = b3Array_Get( world->shapes, shapeId ); - // Visitors must be convex. - if ( b3IsConvex( otherShape->type ) == false ) + // Mesh vs mesh is not supported + if ( ( otherShape->type == b3_meshShape || otherShape->type == b3_heightShape ) && + ( sensorShape->type == b3_meshShape || sensorShape->type == b3_heightShape ) ) { return true; } // Are sensor events enabled on the other shape? - if ( ( otherShape->flags & b3_enableSensorEvents ) == 0 ) + if ( otherShape->enableSensorEvents == false ) { return true; } @@ -132,7 +133,7 @@ static bool b3SensorQueryCallback( int proxyId, uint64_t userData, void* context } // Custom user filter - if ( ( sensorShape->flags & b3_enableCustomFiltering ) || ( otherShape->flags & b3_enableCustomFiltering ) ) + if ( sensorShape->enableCustomFiltering || otherShape->enableCustomFiltering ) { b3CustomFilterFcn* customFilterFcn = queryContext->world->customFilterFcn; if ( customFilterFcn != NULL ) @@ -206,7 +207,7 @@ static void b3SensorTask( int startIndex, int endIndex, int workerIndex, void* c b3Array_Clear( sensor->hits ); b3Body* body = b3Array_Get( world->bodies, sensorShape->bodyId ); - if ( body->setIndex == b3_disabledSet || ( sensorShape->flags & b3_enableSensorEvents ) == 0 ) + if ( body->setIndex == b3_disabledSet || sensorShape->enableSensorEvents == false ) { if ( sensor->overlaps1.count != 0 ) { @@ -278,7 +279,7 @@ static void b3SensorTask( int startIndex, int endIndex, int workerIndex, void* c b3TracyCZoneEnd( sensor_task ); } -void b3BeginSensors( b3World* world ) +void b3OverlapSensors( b3World* world ) { int sensorCount = world->sensors.count; if ( sensorCount == 0 ) @@ -288,6 +289,8 @@ void b3BeginSensors( b3World* world ) B3_ASSERT( world->workerCount > 0 ); + b3TracyCZoneNC( overlap_sensors, "Sensors", b3_colorMediumPurple, true ); + for ( int i = 0; i < world->workerCount; ++i ) { b3SetBitCountAndClear( &world->sensorTaskContexts.data[i].eventBits, sensorCount ); @@ -295,18 +298,9 @@ void b3BeginSensors( b3World* world ) // Parallel-for sensors overlaps int minRange = 16; - b3StageParallelFor( world, b3_taskSensors, b3SensorTask, sensorCount, minRange, world ); -} + b3ParallelFor( world, b3SensorTask, sensorCount, minRange, world, "sensors" ); -void b3EndSensors( b3World* world ) -{ - int sensorCount = world->sensors.count; - if ( sensorCount == 0 ) - { - return; - } - - b3TracyCZoneNC( sensor_state, "Sensor Events", b3_colorLightSlateGray, true ); + b3TracyCZoneNC( sensor_state, "Events", b3_colorLightSlateGray, true ); b3BitSet* bitSet = &world->sensorTaskContexts.data[0].eventBits; for ( int i = 1; i < world->workerCount; ++i ) @@ -415,6 +409,7 @@ void b3EndSensors( b3World* world ) } b3TracyCZoneEnd( sensor_state ); + b3TracyCZoneEnd( overlap_sensors ); } void b3DestroySensor( b3World* world, b3Shape* sensorShape ) diff --git a/src/sensor.h b/src/sensor.h index 3928719..1a17366 100644 --- a/src/sensor.h +++ b/src/sensor.h @@ -37,6 +37,5 @@ typedef struct b3SensorTaskContext b3BitSet eventBits; } b3SensorTaskContext; -void b3BeginSensors( b3World* world ); -void b3EndSensors( b3World* world ); +void b3OverlapSensors( b3World* world ); void b3DestroySensor( b3World* world, b3Shape* sensorShape ); diff --git a/src/shape.c b/src/shape.c index 7b21700..14464f5 100644 --- a/src/shape.c +++ b/src/shape.c @@ -16,6 +16,9 @@ #include "box3d/box3d.h" +#include +#include + static b3Shape* b3GetShape( b3World* world, b3ShapeId shapeId ) { int id = shapeId.index1 - 1; @@ -75,7 +78,7 @@ static float b3ComputeShapeMargin( b3Shape* shape ) return b3MinFloat( B3_MAX_AABB_MARGIN, B3_AABB_MARGIN_FRACTION * margin ); } -static void b3UpdateShapeAABBs( b3Shape* shape, b3AABB* fatAABB, b3WorldTransform transform, b3BodyType proxyType ) +static void b3UpdateShapeAABBs( b3Shape* shape, b3WorldTransform transform, b3BodyType proxyType ) { // Compute a bounding box with a speculative margin const float speculativeDistance = B3_SPECULATIVE_DISTANCE; @@ -86,7 +89,14 @@ static void b3UpdateShapeAABBs( b3Shape* shape, b3AABB* fatAABB, b3WorldTransfor // Smaller margin for static bodies. Cannot be zero due to TOI tolerance. float margin = proxyType == b3_staticBody ? speculativeDistance : aabbMargin; - *fatAABB = b3AABB_Inflate( aabb, margin ); + b3AABB fatAABB; + fatAABB.lowerBound.x = aabb.lowerBound.x - margin; + fatAABB.lowerBound.y = aabb.lowerBound.y - margin; + fatAABB.lowerBound.z = aabb.lowerBound.z - margin; + fatAABB.upperBound.x = aabb.upperBound.x + margin; + fatAABB.upperBound.y = aabb.upperBound.y + margin; + fatAABB.upperBound.z = aabb.upperBound.z + margin; + shape->fatAABB = fatAABB; } static b3Shape* b3CreateShapeInternal( b3World* world, b3Body* body, b3WorldTransform bodyTransform, const b3ShapeDef* def, @@ -98,15 +108,12 @@ static b3Shape* b3CreateShapeInternal( b3World* world, b3Body* body, b3WorldTran if ( shapeId == world->shapes.count ) { b3Array_Push( world->shapes, (b3Shape){ 0 } ); - b3Array_Push( world->fatAABBs, (b3AABB){ 0 } ); } else { B3_ASSERT( world->shapes.data[shapeId].id == B3_NULL_INDEX ); } - B3_ASSERT( world->fatAABBs.count == world->shapes.count ); - b3Shape* shape = b3Array_Get( world->shapes, shapeId ); switch ( shapeType ) @@ -171,25 +178,21 @@ static b3Shape* b3CreateShapeInternal( b3World* world, b3Body* body, b3WorldTran shape->filter = def->filter; shape->userData = def->userData; shape->userShape = NULL; - shape->flags = 0; - shape->flags |= def->enableSensorEvents ? b3_enableSensorEvents : 0; - shape->flags |= def->enableContactEvents ? b3_enableContactEvents : 0; - shape->flags |= def->enableCustomFiltering ? b3_enableCustomFiltering : 0; - shape->flags |= def->enableHitEvents ? b3_enableHitEvents : 0; - shape->flags |= def->enablePreSolveEvents ? b3_enablePreSolveEvents : 0; - shape->flags |= def->enableSpeculativeContact ? b3_enableSpeculative : 0; + shape->enlargedAABB = false; + shape->enableSensorEvents = def->enableSensorEvents; + shape->enableContactEvents = def->enableContactEvents; + shape->enableCustomFiltering = def->enableCustomFiltering; + shape->enableHitEvents = def->enableHitEvents; + shape->enablePreSolveEvents = def->enablePreSolveEvents; shape->proxyKey = B3_NULL_INDEX; shape->localCentroid = b3GetShapeCentroid( shape ); shape->aabbMargin = b3ComputeShapeMargin( shape ); shape->aabb = (b3AABB){ b3Vec3_zero, b3Vec3_zero }; - world->fatAABBs.data[shapeId] = (b3AABB){ b3Vec3_zero, b3Vec3_zero }; - shape->nameId = b3AddName( &world->names, def->name ); + shape->fatAABB = (b3AABB){ b3Vec3_zero, b3Vec3_zero }; shape->generation += 1; if ( shape->type == b3_compoundShape ) { - world->compoundShapeCount += 1; - // Own a copy of the compound materials so every shape frees its array the same way. Compounds // are few, so the copy is cheap and avoids aliasing the geometry blob. int materialCount = shape->compound->materialCount; @@ -216,7 +219,7 @@ static b3Shape* b3CreateShapeInternal( b3World* world, b3Body* body, b3WorldTran { b3BodyType proxyType = body->type; bool forcePairCreation = def->invokeContactCreation && shape->type != b3_compoundShape; - b3CreateShapeProxy( world, shape, proxyType, bodyTransform, forcePairCreation ); + b3CreateShapeProxy( shape, &world->broadPhase, proxyType, bodyTransform, forcePairCreation ); } // Add to shape doubly linked list @@ -294,11 +297,6 @@ static b3ShapeId b3CreateShape( b3BodyId bodyId, const b3ShapeDef* def, const vo { b3UpdateBodyMassData( world, body ); } - else if ( ( body->flags & b3_dirtyMass ) == 0 ) - { - body->flags |= b3_dirtyMass; - b3SyncBodyFlags( world, body ); - } b3ValidateSolverSets( world ); @@ -350,14 +348,7 @@ b3ShapeId b3CreateCapsuleShape( b3BodyId bodyId, const b3ShapeDef* def, const b3 b3ShapeId b3CreateHullShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HullData* hull ) { B3_VALIDATE( b3IsValidHull( hull ) ); - B3_ASSERT( hull->version == B3_HULL_VERSION ); - B3_ASSERT( hull->hash != 0 ); - - if ( hull->version != B3_HULL_VERSION ) - { - return b3_nullShapeId; - } - + B3_VALIDATE( hull->hash != 0 ); b3ShapeId shapeId = b3CreateShape( bodyId, def, hull, b3_hullShape, b3Transform_identity, b3Vec3_one, false ); if ( shapeId.index1 != 0 ) { @@ -376,14 +367,6 @@ b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef* def, b3Vec3 scale ) { B3_VALIDATE( b3IsValidHull( hull ) ); - B3_ASSERT( hull->version == B3_HULL_VERSION ); - B3_ASSERT( hull->hash != 0 ); - - if ( hull->version != B3_HULL_VERSION ) - { - return b3_nullShapeId; - } - b3ShapeId shapeId = b3CreateShape( bodyId, def, hull, b3_hullShape, transform, scale, true ); if ( shapeId.index1 != 0 ) { @@ -405,14 +388,7 @@ b3ShapeId b3CreateTransformedHullShape( b3BodyId bodyId, const b3ShapeDef* def, b3ShapeId b3CreateMeshShape( b3BodyId bodyId, const b3ShapeDef* def, const b3MeshData* mesh, b3Vec3 scale ) { B3_VALIDATE( b3IsValidMesh( mesh ) ); - B3_ASSERT( mesh->version == B3_MESH_VERSION ); - B3_ASSERT( mesh->hash != 0 ); - - if ( mesh->version != B3_MESH_VERSION ) - { - return b3_nullShapeId; - } - + B3_VALIDATE( mesh->hash != 0 ); b3ShapeId shapeId = b3CreateShape( bodyId, def, mesh, b3_meshShape, b3Transform_identity, scale, true ); if ( shapeId.index1 != 0 ) { @@ -429,14 +405,7 @@ b3ShapeId b3CreateMeshShape( b3BodyId bodyId, const b3ShapeDef* def, const b3Mes b3ShapeId b3CreateHeightFieldShape( b3BodyId bodyId, const b3ShapeDef* def, const b3HeightFieldData* heightField ) { - B3_ASSERT( heightField->version == B3_HEIGHT_FIELD_VERSION ); - B3_ASSERT( heightField->hash != 0 ); - - if ( heightField->version != B3_HEIGHT_FIELD_VERSION ) - { - return b3_nullShapeId; - } - + B3_VALIDATE( heightField->hash != 0 ); b3ShapeId shapeId = b3CreateShape( bodyId, def, heightField, b3_heightShape, b3Transform_identity, b3Vec3_one, false ); if ( shapeId.index1 != 0 ) { @@ -451,15 +420,8 @@ b3ShapeId b3CreateHeightFieldShape( b3BodyId bodyId, const b3ShapeDef* def, cons return shapeId; } -b3ShapeId b3CreateBakedCompoundShape( b3BodyId bodyId, b3ShapeDef* def, const b3CompoundData* compound ) +b3ShapeId b3CreateCompoundShape( b3BodyId bodyId, b3ShapeDef* def, const b3CompoundData* compound ) { - B3_ASSERT( compound->version == B3_COMPOUND_VERSION ); - - if ( compound->version != B3_COMPOUND_VERSION ) - { - return b3_nullShapeId; - } - b3ShapeId shapeId = b3CreateShape( bodyId, def, compound, b3_compoundShape, b3Transform_identity, b3Vec3_one, false ); if ( shapeId.index1 != 0 ) { @@ -479,12 +441,6 @@ static void b3DestroyShapeInternal( b3World* world, b3Shape* shape, b3Body* body { int shapeId = shape->id; - if ( shape->type == b3_compoundShape ) - { - B3_ASSERT( world->compoundShapeCount > 0 ); - world->compoundShapeCount -= 1; - } - // Remove the shape from the body's doubly linked list. if ( shape->prevShapeId != B3_NULL_INDEX ) { @@ -782,7 +738,7 @@ b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter ) b3Vec3 c1 = b3Sub( shape->capsule.center1, localCenter ); b3Vec3 c2 = b3Sub( shape->capsule.center2, localCenter ); b3Vec3 r = { radius, radius, radius }; - extent.maxExtent = b3Add( b3Max( b3Abs( c1 ), b3Abs( c2 ) ), r ); + extent.maxExtent = b3Add( b3Max( c1, c2 ), r ); } break; @@ -802,9 +758,9 @@ b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter ) { float radius = shape->sphere.radius; extent.minExtent = radius; - b3Vec3 h = b3Abs( b3Sub( shape->sphere.center, localCenter ) ); b3Vec3 r = { radius, radius, radius }; - extent.maxExtent = b3Add( h, r ); + b3Vec3 p = b3Add( b3Sub( shape->sphere.center, localCenter ), r ); + extent.maxExtent = b3Abs( b3Sub( p, localCenter ) ); } break; @@ -820,7 +776,7 @@ b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter ) float r2 = b3Length( b3Sub( aabb.upperBound, localCenter ) ); extent.minExtent = b3MinFloat( r1, r2 ); b3Vec3 p = b3FarthestPointOnAABB( aabb, localCenter ); - extent.maxExtent = b3Abs( b3Sub( p, localCenter ) ); + extent.maxExtent = b3Abs( p ); } break; @@ -831,24 +787,6 @@ b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter ) return extent; } -float b3ComputeShapeMinExtent( const b3Shape* shape, b3Vec3 localCenter ) -{ - switch ( shape->type ) - { - case b3_capsuleShape: - return shape->capsule.radius; - - case b3_sphereShape: - return shape->sphere.radius; - - case b3_hullShape: - return shape->hull->innerRadius; - - default: - return b3ComputeShapeExtent( shape, localCenter ).minExtent; - } -} - b3CastOutput b3RayCastShape( const b3Shape* shape, b3Transform transform, const b3RayCastInput* input ) { b3RayCastInput localInput = *input; @@ -961,6 +899,32 @@ bool b3OverlapShape( const b3Shape* shape, b3Transform transform, const b3ShapeP B3_ASSERT( false ); return false; } + +#if 0 + b3Vec3 localPoints[B3_MAX_SHAPE_CAST_POINTS]; + b3ShapeProxy localProxy; + + b3Transform invTransform = b3InvertTransform( transform ); + b3Matrix3 R = b3MakeMatrixFromQuat( invTransform.q ); + + localProxy.count = b3MinInt( proxy->count, B3_MAX_SHAPE_CAST_POINTS ); + for ( int i = 0; i < localProxy.count; ++i ) + { + localPoints[i] = b3Add( b3MulMV( R, proxy->points[i] ), invTransform.p ); + } + + localProxy.points = localPoints; + localProxy.radius = proxy->radius; + + if ( type == b3_meshShape ) + { + return b3OverlapMesh( &localProxy, shape->mesh.data, shape->mesh.scale ); + } + + B3_ASSERT( type == b3_heightShape ); + + return b3OverlapHeightField( &localProxy, shape->heightField ); +#endif } int b3CollideMover( b3PlaneResult* planes, int planeCapacity, const b3Shape* shape, b3Transform transform, @@ -1012,22 +976,20 @@ int b3CollideMover( b3PlaneResult* planes, int planeCapacity, const b3Shape* sha { planes[i].plane.normal = b3RotateVector( transform.q, planes[i].plane.normal ); planes[i].point = b3TransformPoint( transform, planes[i].point ); - planes[i].materialIndex = b3ClampInt( planes[i].materialIndex, 0, shape->materialCount - 1 ); } return planeCount; } -void b3CreateShapeProxy( b3World* world, b3Shape* shape, b3BodyType type, b3WorldTransform transform, bool forcePairCreation ) +void b3CreateShapeProxy( b3Shape* shape, b3BroadPhase* bp, b3BodyType type, b3WorldTransform transform, bool forcePairCreation ) { B3_ASSERT( shape->proxyKey == B3_NULL_INDEX ); - b3AABB* fatAABB = world->fatAABBs.data + shape->id; - b3UpdateShapeAABBs( shape, fatAABB, transform, type ); + b3UpdateShapeAABBs( shape, transform, type ); // Create proxies in the broad-phase. - shape->proxyKey = b3BroadPhase_CreateProxy( &world->broadPhase, type, *fatAABB, shape->filter.categoryBits, shape->id, - forcePairCreation ); + shape->proxyKey = + b3BroadPhase_CreateProxy( bp, type, shape->fatAABB, shape->filter.categoryBits, shape->id, forcePairCreation ); B3_ASSERT( B3_PROXY_TYPE( shape->proxyKey ) < b3_bodyTypeCount ); } @@ -1166,23 +1128,6 @@ void* b3Shape_GetUserData( b3ShapeId shapeId ) return shape->userData; } -void b3Shape_SetName( b3ShapeId shapeId, const char* name ) -{ - b3World* world = b3GetWorld( shapeId.world0 ); - - B3_REC( world, ShapeSetName, shapeId, name ); - - b3Shape* shape = b3GetShape( world, shapeId ); - shape->nameId = b3AddName( &world->names, name ); -} - -const char* b3Shape_GetName( b3ShapeId shapeId ) -{ - b3World* world = b3GetWorld( shapeId.world0 ); - b3Shape* shape = b3GetShape( world, shapeId ); - return b3FindNameWithDefault( &world->names, shape->nameId, "" ); -} - bool b3Shape_IsSensor( b3ShapeId shapeId ) { b3World* world = b3GetWorld( shapeId.world0 ); @@ -1329,8 +1274,6 @@ void b3Shape_SetMeshMaterial( b3ShapeId shapeId, b3SurfaceMaterial surfaceMateri B3_ASSERT( 0 <= index && index < shape->materialCount ); B3_ASSERT( shape->type != b3_compoundShape ); - - B3_REC( world, ShapeSetMeshMaterial, shapeId, surfaceMaterial, index ); b3GetShapeMaterials( shape )[index] = surfaceMaterial; } @@ -1375,26 +1318,25 @@ static void b3ResetProxy( b3World* world, b3Shape* shape, bool wakeBodies, bool if ( shape->proxyKey != B3_NULL_INDEX ) { b3BodyType proxyType = B3_PROXY_TYPE( shape->proxyKey ); - b3AABB* fatAABB = world->fatAABBs.data + shapeId; - b3UpdateShapeAABBs( shape, fatAABB, transform, proxyType ); + b3UpdateShapeAABBs( shape, transform, proxyType ); if ( destroyProxy ) { b3BroadPhase_DestroyProxy( &world->broadPhase, shape->proxyKey ); bool forcePairCreation = true; - shape->proxyKey = b3BroadPhase_CreateProxy( &world->broadPhase, proxyType, *fatAABB, shape->filter.categoryBits, + shape->proxyKey = b3BroadPhase_CreateProxy( &world->broadPhase, proxyType, shape->fatAABB, shape->filter.categoryBits, shapeId, forcePairCreation ); } else { - b3BroadPhase_MoveProxy( &world->broadPhase, shape->proxyKey, *fatAABB ); + b3BroadPhase_MoveProxy( &world->broadPhase, shape->proxyKey, shape->fatAABB ); } } else { b3BodyType proxyType = body->type; - b3UpdateShapeAABBs( shape, world->fatAABBs.data + shapeId, transform, proxyType ); + b3UpdateShapeAABBs( shape, transform, proxyType ); } b3ValidateSolverSets( world ); @@ -1447,14 +1389,14 @@ void b3Shape_EnableSensorEvents( b3ShapeId shapeId, bool flag ) B3_REC( world, ShapeEnableSensorEvents, shapeId, flag ); b3Shape* shape = b3GetShape( world, shapeId ); - shape->flags = flag ? shape->flags | b3_enableSensorEvents : shape->flags & ~b3_enableSensorEvents; + shape->enableSensorEvents = flag; } bool b3Shape_AreSensorEventsEnabled( b3ShapeId shapeId ) { b3World* world = b3GetWorld( shapeId.world0 ); b3Shape* shape = b3GetShape( world, shapeId ); - return shape->flags & b3_enableSensorEvents; + return shape->enableSensorEvents; } void b3Shape_EnableContactEvents( b3ShapeId shapeId, bool flag ) @@ -1468,14 +1410,14 @@ void b3Shape_EnableContactEvents( b3ShapeId shapeId, bool flag ) B3_REC( world, ShapeEnableContactEvents, shapeId, flag ); b3Shape* shape = b3GetShape( world, shapeId ); - shape->flags = flag ? shape->flags | b3_enableContactEvents : shape->flags & ~b3_enableContactEvents; + shape->enableContactEvents = flag; } bool b3Shape_AreContactEventsEnabled( b3ShapeId shapeId ) { b3World* world = b3GetWorld( shapeId.world0 ); b3Shape* shape = b3GetShape( world, shapeId ); - return shape->flags & b3_enableContactEvents; + return shape->enableContactEvents; } void b3Shape_EnablePreSolveEvents( b3ShapeId shapeId, bool flag ) @@ -1489,14 +1431,14 @@ void b3Shape_EnablePreSolveEvents( b3ShapeId shapeId, bool flag ) B3_REC( world, ShapeEnablePreSolveEvents, shapeId, flag ); b3Shape* shape = b3GetShape( world, shapeId ); - shape->flags = flag ? shape->flags | b3_enablePreSolveEvents : shape->flags & ~b3_enablePreSolveEvents; + shape->enablePreSolveEvents = flag; } bool b3Shape_ArePreSolveEventsEnabled( b3ShapeId shapeId ) { b3World* world = b3GetWorld( shapeId.world0 ); b3Shape* shape = b3GetShape( world, shapeId ); - return shape->flags & b3_enablePreSolveEvents; + return shape->enablePreSolveEvents; } void b3Shape_EnableHitEvents( b3ShapeId shapeId, bool flag ) @@ -1510,14 +1452,14 @@ void b3Shape_EnableHitEvents( b3ShapeId shapeId, bool flag ) B3_REC( world, ShapeEnableHitEvents, shapeId, flag ); b3Shape* shape = b3GetShape( world, shapeId ); - shape->flags = flag ? shape->flags | b3_enableHitEvents : shape->flags & ~b3_enableHitEvents; + shape->enableHitEvents = flag; } bool b3Shape_AreHitEventsEnabled( b3ShapeId shapeId ) { b3World* world = b3GetWorld( shapeId.world0 ); b3Shape* shape = b3GetShape( world, shapeId ); - return shape->flags & b3_enableHitEvents; + return shape->enableHitEvents; } b3ShapeType b3Shape_GetType( b3ShapeId shapeId ) @@ -1567,14 +1509,6 @@ const b3HeightFieldData* b3Shape_GetHeightField( b3ShapeId shapeId ) return shape->heightField; } -const b3CompoundData* b3Shape_GetCompound( b3ShapeId shapeId ) -{ - b3World* world = b3GetWorld( shapeId.world0 ); - b3Shape* shape = b3GetShape( world, shapeId ); - B3_ASSERT( shape->type == b3_compoundShape ); - return shape->compound; -} - void b3Shape_SetSphere( b3ShapeId shapeId, const b3Sphere* sphere ) { b3World* world = b3GetUnlockedWorld( shapeId.world0 ); @@ -1658,14 +1592,6 @@ void b3Shape_SetHull( b3ShapeId shapeId, const b3HullData* hull ) return; } - if ( world->recording != NULL ) - { - // Intern the shared hull. - uint32_t geometryId = b3RecInternHull( world->recording, data ); - b3RecArgs_ShapeSetHull setArgs = { shapeId, geometryId }; - b3RecWrite_ShapeSetHull( world->recording, &setArgs ); - } - b3DestroyShapeAllocationForShapeChange( world, shape ); shape->hull = data; @@ -1693,13 +1619,6 @@ void b3Shape_SetMesh( b3ShapeId shapeId, const b3MeshData* meshData, b3Vec3 scal world->locked = true; - if ( world->recording != NULL ) - { - uint32_t geometryId = b3RecInternMesh( world->recording, meshData ); - b3RecArgs_ShapeSetMesh setArgs = { shapeId, geometryId, scale }; - b3RecWrite_ShapeSetMesh( world->recording, &setArgs ); - } - b3Shape* shape = b3GetShape( world, shapeId ); b3DestroyShapeAllocationForShapeChange( world, shape ); @@ -2105,6 +2024,8 @@ typedef struct b3MeshImpactContext b3Vec3 meshLocalCentroidB1, meshLocalCentroidB2; float fallbackRadius; bool isSensor; + + int visitCount; } b3MeshImpactContext; static bool b3MeshTimeOfImpactFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleIndex, void* context ) @@ -2113,6 +2034,8 @@ static bool b3MeshTimeOfImpactFcn( b3Vec3 a, b3Vec3 b, b3Vec3 c, int triangleInd b3MeshImpactContext* toiContext = context; + toiContext->visitCount += 1; + // Early out for parallel movement b3Vec3 c1 = toiContext->meshLocalCentroidB1; b3Vec3 c2 = toiContext->meshLocalCentroidB2; @@ -2292,8 +2215,8 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee b3Vec3 localCentroidB = b3GetShapeCentroid( shapeB ); context.localCentroidB = localCentroidB; - float minExtent = b3ComputeShapeMinExtent( shapeB, context.localCentroidB ); - context.fallbackRadius = b3MaxFloat( 0.75f * minExtent, B3_SPECULATIVE_DISTANCE ); + b3ShapeExtent extents = b3ComputeShapeExtent( shapeB, context.localCentroidB ); + context.fallbackRadius = b3MaxFloat( 0.75f * extents.minExtent, B3_SPECULATIVE_DISTANCE ); // Swept bounds of shapeB b3AABB bounds = b3ComputeSweptShapeAABB( shapeB, sweepB, maxFraction ); @@ -2312,6 +2235,8 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee // todo implement b3MeshTimeOfImpact and b3HeightFieldTimeOfImpact // Note: assuming mesh is static + uint64_t ticks = b3GetTicks(); + b3MeshImpactContext context = { 0 }; context.toiInput.sweepA = *sweepA; context.toiInput.proxyA.count = 3; @@ -2342,8 +2267,8 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee context.meshLocalCentroidB1 = b3InvTransformPoint( xfA, b3TransformPoint( xfB1, localCentroidB ) ); context.meshLocalCentroidB2 = b3InvTransformPoint( xfA, b3TransformPoint( xfB2, localCentroidB ) ); - float minExtent = b3ComputeShapeMinExtent( shapeB, context.localCentroidB ); - context.fallbackRadius = b3MaxFloat( 0.5f * minExtent, B3_LINEAR_SLOP ); + b3ShapeExtent extents = b3ComputeShapeExtent( shapeB, context.localCentroidB ); + context.fallbackRadius = b3MaxFloat( 0.5f * extents.minExtent, B3_LINEAR_SLOP ); // Swept bounds of shapeB // todo pass in xfA to get local bounds directly @@ -2361,6 +2286,12 @@ b3TOIOutput b3ShapeTimeOfImpact( b3Shape* shapeA, b3Shape* shapeB, b3Sweep* swee b3QueryHeightField( shapeA->heightField, localBounds, b3MeshTimeOfImpactFcn, &context ); } + float ms = b3GetMilliseconds( ticks ); + if ( ms > 1000.0f * b3GetStallThreshold() ) + { + b3Log( "CCD stall: visited %d triangles", context.visitCount ); + } + return context.toiOutput; } @@ -2427,7 +2358,7 @@ uint64_t b3GetShapeUserMaterialId( const b3Shape* shape, int childIndex, int tri { const uint8_t* indices = b3GetMeshMaterialIndices( child.mesh.data ); int meshMaterialIndex = indices != NULL ? indices[triangleIndex] : 0; - B3_ASSERT( 0 <= meshMaterialIndex && meshMaterialIndex < child.materialCount ); + meshMaterialIndex = b3ClampInt( meshMaterialIndex, 0, B3_MAX_COMPOUND_MESH_MATERIALS - 1 ); materialIndex = child.materialIndices[meshMaterialIndex]; } else @@ -2439,3 +2370,100 @@ uint64_t b3GetShapeUserMaterialId( const b3Shape* shape, int childIndex, int tri materialIndex = b3ClampInt( materialIndex, 0, shape->materialCount - 1 ); return b3GetShapeMaterials( shape )[materialIndex].userMaterialId; } + +void b3DumpShape( b3World* world, int shapeIndex ) +{ + b3Shape* shape = b3Array_Get( world->shapes, shapeIndex ); + + b3Dump( " b3ShapeDef sd = b3DefaultShapeDef();\n" ); + + // printf("%" PRIx64 ";\n", t); + b3Dump( " sd.density = %.9g;\n", shape->density ); + b3Dump( " sd.isSensor = bool(%d);\n", shape->sensorIndex != B3_NULL_INDEX ); + b3Dump( " sd.filter.categoryBits = 0x%" PRIx64 ";\n", shape->filter.categoryBits ); + b3Dump( " sd.filter.maskBits = 0x%" PRIx64 ";\n", shape->filter.maskBits ); + b3Dump( " sd.filter.groupIndex = %d;\n", shape->filter.groupIndex ); + + B3_ASSERT( shape->materialCount >= 1 ); + const b3SurfaceMaterial* m = b3GetShapeMaterials( shape ); + b3Dump( " sd.baseMaterial.friction = %.9g;\n", m->friction ); + b3Dump( " sd.baseMaterial.restitution = %.9g;\n", m->restitution ); + b3Dump( " sd.baseMaterial.rollingResistance = %.9g;\n", m->rollingResistance ); + + switch ( shape->type ) + { + case b3_capsuleShape: + { + b3Capsule* s = &shape->capsule; + b3Dump( " b3CapsuleShape shape;\n" ); + b3Dump( " shape.center1 = {%.9g, %.9g, %.9g};\n", s->center1.x, s->center1.y, s->center1.z ); + b3Dump( " shape.center2 = {%.9g, %.9g, %.9g};\n", s->center2.x, s->center2.y, s->center2.z ); + b3Dump( " shape.radius = %.9g;\n", s->radius ); + b3Dump( " b3CreateCapsuleShape(bodyId, &sd, &shape);\n" ); + } + break; + + case b3_compoundShape: + { + // todo + } + break; + + case b3_heightShape: + { + // todo + } + break; + + case b3_hullShape: + { + const b3HullData* s = shape->hull; + int vertexCount = s->vertexCount; + const b3Vec3* vs = b3GetHullPoints( s ); + b3Dump( " b3Vec3 vs[%d];\n", vertexCount ); + for ( int i = 0; i < vertexCount; ++i ) + { + b3Dump( " vs[%d] = {%.9g, %.9g, %.9g};\n", i, vs[i].x, vs[i].y, vs[i].z ); + } + b3Dump( " b3HullData* hullData = b3CreateHull(vs, %d, %d);\n", vertexCount, vertexCount ); + b3Dump( " b3CreateHullShape(bodyId, &sd, hullData);\n" ); + b3Dump( " b3DestroyHull(hullData);\n" ); + } + break; + + case b3_meshShape: + { + const b3MeshData* s = shape->mesh.data; + b3Vec3 scale = shape->mesh.scale; + int meshIndex = b3FetchAddMeshDumpIndex(); + char buffer[64]; + snprintf( buffer, 64, "mesh_dump_%d.b3m", meshIndex ); + b3WriteBinaryFile( (void*)s, s->byteCount, buffer ); + + b3Dump( " int dataSize = 0;\n" ); + b3Dump( " b3MeshData* data = (b3MeshData*)b3ReadBinaryFile(dumpPrefix, \"%s\", &dataSize);\n", buffer ); + b3Dump( " if (data == nullptr || data->version != B3_MESH_VERSION || data->byteCount != dataSize)\n" ); + b3Dump( " {\n" ); + b3Dump( " return;\n" ); + b3Dump( " }\n" ); + b3Dump( " b3Vec3 scale = { %.9g, %.9g, %.9g };\n", scale.x, scale.y, scale.z ); + b3Dump( " b3CreateMeshShape(bodyId, &sd, data, scale);\n" ); + // Host code must have this container and destroy the mesh data when the world is destroyed. + b3Dump( " m_meshes.push_back(data);\n" ); + } + break; + + case b3_sphereShape: + { + b3Sphere* s = &shape->sphere; + b3Dump( " b3SphereShape shape;\n" ); + b3Dump( " shape.center = {%.9g, %.9g, %.9g};\n", s->center.x, s->center.y, s->center.z ); + b3Dump( " shape.radius = %.9g;\n", s->radius ); + b3Dump( " b3CreateSphereShape(bodyId, &sd, &shape);\n" ); + } + break; + + default: + return; + } +} diff --git a/src/shape.h b/src/shape.h index 4f6ee87..f55ca0f 100644 --- a/src/shape.h +++ b/src/shape.h @@ -5,7 +5,6 @@ #include "math_internal.h" -#include "box3d/collision.h" #include "box3d/types.h" #include @@ -13,17 +12,6 @@ typedef struct b3BroadPhase b3BroadPhase; typedef struct b3World b3World; -typedef enum b3ShapeFlags -{ - b3_enableSensorEvents = 0x01, - b3_enableContactEvents = 0x02, - b3_enableCustomFiltering = 0x04, - b3_enableHitEvents = 0x08, - b3_enablePreSolveEvents = 0x10, - // 0x20 is free, it was the enlarged AABB flag before the broad-phase marked the tree - b3_enableSpeculative = 0x40, -} b3ShapeFlags; - typedef struct b3Shape { int id; @@ -38,21 +26,24 @@ typedef struct b3Shape float aabbMargin; b3AABB aabb; + b3AABB fatAABB; b3Vec3 localCentroid; - int materialCount; b3SurfaceMaterial material; + int materialCount; b3SurfaceMaterial* materials; b3Filter filter; void* userData; void* userShape; - uint32_t nameId; uint16_t generation; - - // b3ShapeFlags - uint8_t flags; + bool enableSensorEvents; + bool enableContactEvents; + bool enableCustomFiltering; + bool enableHitEvents; + bool enablePreSolveEvents; + bool enlargedAABB; union { @@ -74,14 +65,13 @@ static inline b3SurfaceMaterial* b3GetShapeMaterials( const b3Shape* shape ) return shape->materials != NULL ? shape->materials : (b3SurfaceMaterial*)&shape->material; } -void b3CreateShapeProxy( b3World* world, b3Shape* shape, b3BodyType type, b3WorldTransform transform, bool forcePairCreation ); +void b3CreateShapeProxy( b3Shape* shape, b3BroadPhase* bp, b3BodyType type, b3WorldTransform transform, bool forcePairCreation ); void b3DestroyShapeProxy( b3Shape* shape, b3BroadPhase* bp ); void b3DestroyShapeAllocations( b3World* world, b3Shape* shape ); b3MassData b3ComputeShapeMass( const b3Shape* shape ); b3ShapeExtent b3ComputeShapeExtent( const b3Shape* shape, b3Vec3 localCenter ); -float b3ComputeShapeMinExtent( const b3Shape* shape, b3Vec3 localCenter ); b3AABB b3ComputeSweptSphereAABB( const b3Sphere* shape, b3Transform xf1, b3Transform xf2 ); b3AABB b3ComputeSweptCapsuleAABB( const b3Capsule* shape, b3Transform xf1, b3Transform xf2 ); @@ -129,10 +119,6 @@ float b3ComputeHullProjectedArea( const b3HullData* hull, b3Vec3 direction ); b3Triangle b3GetHeightFieldTriangle( const b3HeightFieldData* heightField, int triangleIndex ); int b3GetHeightFieldMaterial( const b3HeightFieldData* heightField, int triangleIndex ); -bool b3GetHeightFieldNeighborNormal( const b3HeightFieldData* heightField, int triangleIndex, int edgeIndex, b3Vec3* normal ); -bool b3IsHeightFieldVertexConvex( const b3HeightFieldData* heightField, int triangleIndex, int vertexIndex ); -int b3GetHeightFieldVertexTriangles( const b3HeightFieldData* heightField, int vertex, int triangles[6] ); - static inline int b3GetHeightFieldTriangleCount( const b3HeightFieldData* heightField ) { int cellCount = ( heightField->rowCount - 1 ) * ( heightField->columnCount - 1 ); @@ -140,75 +126,9 @@ static inline int b3GetHeightFieldTriangleCount( const b3HeightFieldData* height } // Mesh - -// Making this inline made the tree benchmarks faster. -static inline b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleIndex ) -{ - B3_ASSERT( 0 <= triangleIndex && triangleIndex < mesh->data->triangleCount ); - - const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh->data ); - const b3Vec3* vertices = b3GetMeshVertices( mesh->data ); - - b3Triangle result; - b3MeshTriangle triangle = triangles[triangleIndex]; - - b3Vec3 scale = mesh->scale; - - result.vertices[0] = b3Mul( scale, vertices[triangle.index1] ); - result.i1 = triangle.index1; - - if ( scale.x * scale.y * scale.z < 0.0f ) - { - result.vertices[1] = b3Mul( scale, vertices[triangle.index3] ); - result.vertices[2] = b3Mul( scale, vertices[triangle.index2] ); - - result.i2 = triangle.index3; - result.i3 = triangle.index2; - - } - else - { - result.vertices[1] = b3Mul( scale, vertices[triangle.index2] ); - result.vertices[2] = b3Mul( scale, vertices[triangle.index3] ); - - result.i2 = triangle.index2; - result.i3 = triangle.index3; - } - - return result; -} - -bool b3GetMeshNeighborNormal( const b3Mesh* mesh, int triangleIndex, int edgeIndex, b3Vec3* normal ); - -// Returns false if edge is isolated. -static inline bool b3GetNeighborNormal( const b3Shape* shape, int triangleIndex, int edgeIndex, b3Vec3* normal ) -{ - if ( shape->type == b3_meshShape ) - { - return b3GetMeshNeighborNormal( &shape->mesh, triangleIndex, edgeIndex, normal ); - } - - B3_ASSERT( shape->type == b3_heightShape ); - return b3GetHeightFieldNeighborNormal( shape->heightField, triangleIndex, edgeIndex, normal ); -} - -int b3GetMeshVertexFlag( const b3Mesh* mesh, int triangleIndex, int vertexIndex ); -bool b3IsInMeshVertexRing( const b3Mesh* mesh, int triangleIndex, int vertexIndex, b3Vec3 normal, float tolerance ); -int8_t b3QuantizeEdgeAngle( float radians ); - -static inline bool b3IsConvexVertex( const b3Shape* shape, int triangleIndex, int vertexIndex ) -{ - if ( shape->type == b3_meshShape ) - { - int flags = b3GetMeshVertexFlag( &shape->mesh, triangleIndex, vertexIndex ); - return ( flags & ( b3_flatVertex | b3_concaveVertex ) ) == 0; - } - - B3_ASSERT( shape->type == b3_heightShape ); - return b3IsHeightFieldVertexConvex( shape->heightField, triangleIndex, vertexIndex ); -} - +b3Triangle b3GetMeshTriangle( const b3Mesh* mesh, int triangleIndex ); bool b3IsValidMesh( const b3MeshData* meshData ); +void b3DumpShape( b3World* world, int shapeIndex ); static inline bool b3ShouldShapesCollide( b3Filter filterA, b3Filter filterB ) { @@ -225,8 +145,3 @@ static inline bool b3ShouldQueryCollide( const b3Filter* shapeFilter, const b3Qu return ( shapeFilter->categoryBits & queryFilter->maskBits ) != 0 && ( shapeFilter->maskBits & queryFilter->categoryBits ) != 0; } - -static inline bool b3IsConvex( b3ShapeType type ) -{ - return type == b3_sphereShape || type == b3_capsuleShape || type == b3_hullShape; -} diff --git a/src/simd.c b/src/simd.c index 30ad2e6..6a9faac 100644 --- a/src/simd.c +++ b/src/simd.c @@ -5,114 +5,6 @@ #include "simd.h" -#include "platform.h" - -#include -#include - -static b3AtomicInt b3_simdWidth; - -#if defined( B3_SIMD_HAS_WIDTH_8 ) - -#if defined( _MSC_VER ) -#include -#endif - -// This code enables runtime dispatch to AVX2. -// Inspired by https://github.com/simdjson/simdjson/blob/master/src/internal/isadetection.h - -static void b3CpuId( unsigned int leaf, unsigned int subLeaf, unsigned int registers[4] ) -{ -#if defined( _MSC_VER ) - int info[4]; - __cpuidex( info, (int)leaf, (int)subLeaf ); - registers[0] = (unsigned int)info[0]; - registers[1] = (unsigned int)info[1]; - registers[2] = (unsigned int)info[2]; - registers[3] = (unsigned int)info[3]; -#else - // clang cpuid.h can give the rbx swap register the same register as the leaf input, clobbering rbx - __asm__ volatile( "cpuid" - : "=a"( registers[0] ), "=b"( registers[1] ), "=c"( registers[2] ), "=d"( registers[3] ) - : "a"( leaf ), "c"( subLeaf ) ); -#endif -} - -static uint64_t b3GetExtendedControlRegister( void ) -{ -#if defined( _MSC_VER ) && !defined( __clang__ ) - return _xgetbv( 0 ); -#else - uint32_t low, high; - __asm__ volatile( "xgetbv" : "=a"( low ), "=d"( high ) : "c"( 0 ) ); - return ( (uint64_t)high << 32 ) | low; -#endif -} - -static bool b3HasAVX2( void ) -{ - unsigned int registers[4]; - b3CpuId( 0, 0, registers ); - if ( registers[0] < 7 ) - { - return false; - } - - b3CpuId( 1, 0, registers ); - unsigned int osxsaveAndAvx = ( 1u << 27 ) | ( 1u << 28 ); - if ( ( registers[2] & osxsaveAndAvx ) != osxsaveAndAvx ) - { - return false; - } - - if ( ( b3GetExtendedControlRegister() & 6 ) != 6 ) - { - return false; - } - - b3CpuId( 7, 0, registers ); - return ( registers[1] & ( 1u << 5 ) ) != 0; -} - -#endif - -static int b3DetectSIMDWidth( void ) -{ -#if defined( B3_SIMD_HAS_WIDTH_8 ) - return b3HasAVX2() ? 8 : 4; -#else - return 4; -#endif -} - -int b3GetSIMDWidth( void ) -{ - int width = b3AtomicLoadInt( &b3_simdWidth ); - if ( width == 0 ) - { - width = b3DetectSIMDWidth(); - b3AtomicStoreInt( &b3_simdWidth, width ); - } - - return width; -} - -bool b3IsAVX2Available( void ) -{ - return b3DetectSIMDWidth() == 8; -} - -void b3SetSIMDWidth( int width ) -{ - B3_ASSERT( width == 0 || width == 4 || width == 8 ); - if ( width == 8 && b3DetectSIMDWidth() != 8 ) - { - width = 4; - } - - b3AtomicStoreInt( &b3_simdWidth, width ); -} - #if defined( B3_SIMD_SSE2 ) #define B3_TRANSPOSE3( C1, C2, C3 ) \ diff --git a/src/simd.h b/src/simd.h index 8250f6f..ac7e9e8 100644 --- a/src/simd.h +++ b/src/simd.h @@ -5,62 +5,168 @@ #include "core.h" -#include "box3d/types.h" - #include -#if defined( B3_SIMD_ENABLED ) - -#if defined( B3_SIMD_NEON ) -#include "simd_neon.h" -#endif - #if defined( B3_SIMD_SSE2 ) -#include "simd_sse2.h" -#endif -#if defined( B3_SIMD_AVX2 ) -#include "simd_avx2.h" -#endif +#include + +// wide float holds 4 numbers +typedef __m128 b3V32; + +typedef union b3128 +{ + b3V32 v; + float f[4]; +} b3128; + +#if defined( _MSC_VER ) && !defined( __clang__ ) + +static const b3V32 b3_zeroV = { { 0.0f, 0.0f, 0.0f, 0.0f } }; +static const b3V32 b3_halfV = { { 0.5f, 0.5f, 0.5f, 0.5f } }; +static const b3V32 b3_oneV = { { 1.0f, 1.0f, 1.0f, 1.0f } }; #else -#include "simd_scalar.h" +static const b3V32 b3_zeroV = { 0.0f, 0.0f, 0.0f, 0.0f }; +static const b3V32 b3_halfV = { 0.5f, 0.5f, 0.5f, 0.5f }; +static const b3V32 b3_oneV = { 1.0f, 1.0f, 1.0f, 1.0f }; #endif -static inline b3FloatW4 b3Atan2W4( b3FloatW4 y, b3FloatW4 x ) +static inline b3V32 b3AddV( b3V32 a, b3V32 b ) { - b3FloatW4 zero = b3ZeroW4(); - b3FloatW4 ax = b3AbsW4( x ); - b3FloatW4 ay = b3AbsW4( y ); - b3FloatW4 mx = b3MaxW4( ay, ax ); - b3FloatW4 mn = b3MinW4( ay, ax ); - b3FloatW4 a = b3DivW4( mn, mx ); - - b3FloatW4 s = b3MulW4( a, a ); - b3FloatW4 c = b3MulW4( s, a ); - b3FloatW4 q = b3MulW4( s, s ); - b3FloatW4 r = b3MulAddW4( b3SplatW4( 0.18681418f ), b3SplatW4( 0.024840285f ), q ); - b3FloatW4 t = b3SubW4( b3MulW4( b3SplatW4( -0.094097948f ), q ), b3SplatW4( 0.33213072f ) ); - r = b3MulAddW4( t, r, s ); - r = b3MulAddW4( a, r, c ); - - r = b3BlendW4( r, b3SubW4( b3SplatW4( 1.57079637f ), r ), b3GreaterThanW4( ay, ax ) ); - r = b3BlendW4( r, b3SubW4( b3SplatW4( 3.14159274f ), r ), b3LessThanW4( x, zero ) ); - r = b3BlendW4( r, b3NegW4( r ), b3LessThanW4( y, zero ) ); - - return b3BlendW4( r, zero, b3EqualsW4( b3AddW4( ax, ay ), zero ) ); + return _mm_add_ps( a, b ); } -#if !defined( B3_SIMD_SSE2 ) +static inline b3V32 b3SubV( b3V32 a, b3V32 b ) +{ + return _mm_sub_ps( a, b ); +} + +static inline b3V32 b3MulV( b3V32 a, b3V32 b ) +{ + return _mm_mul_ps( a, b ); +} + +static inline b3V32 b3DivV( b3V32 a, b3V32 b ) +{ + return _mm_div_ps( a, b ); +} + +static inline b3V32 b3NegV( b3V32 a ) +{ + return _mm_sub_ps( _mm_setzero_ps(), a ); +} + +static inline b3V32 b3LoadV( const float* src ) +{ + // Loads exactly 12 bytes: 8 via movsd, 4 via movss. + // Result lane 3 is implicitly zero from the partial loads. + __m128 xy = _mm_castpd_ps( _mm_load_sd( (const double*)( src ) ) ); + __m128 z = _mm_load_ss( src + 2 ); + return _mm_movelh_ps( xy, z ); // { src[0], src[1], src[2], 0.0f } +} + +static inline b3V32 b3ZeroV( void ) +{ + return _mm_setzero_ps(); +} + +static inline float b3GetXV( b3V32 a ) +{ + return _mm_cvtss_f32( a ); +} + +static inline float b3GetYV( b3V32 a ) +{ + return _mm_cvtss_f32( _mm_shuffle_ps( a, a, _MM_SHUFFLE( 1, 1, 1, 1 ) ) ); +} + +static inline float b3GetZV( b3V32 a ) +{ + return _mm_cvtss_f32( _mm_shuffle_ps( a, a, _MM_SHUFFLE( 2, 2, 2, 2 ) ) ); +} + +static inline float b3GetV( b3V32 a, int index ) +{ + b3128 b; + b.v = a; + return b.f[index]; +} + +static inline b3V32 b3SplatV( float x ) +{ + return _mm_set_ps1( x ); +} + +static inline b3V32 b3AbsV( b3V32 a ) +{ + // Abs( V ) = Max( -V, V ) + b3V32 zero = _mm_setzero_ps(); + return _mm_max_ps( _mm_sub_ps( zero, a ), a ); +} + +static inline b3V32 b3MinV( b3V32 a, b3V32 b ) +{ + return _mm_min_ps( a, b ); +} + +static inline b3V32 b3MaxV( b3V32 a, b3V32 b ) +{ + return _mm_max_ps( a, b ); +} + +static inline b3V32 b3CrossV( b3V32 a, b3V32 b ) +{ + b3V32 yzX1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 0, 2, 1 ) ); + b3V32 zxY1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 1, 0, 2 ) ); + b3V32 yzX2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 0, 2, 1 ) ); + b3V32 zxY2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 1, 0, 2 ) ); + + return _mm_sub_ps( _mm_mul_ps( yzX1, zxY2 ), _mm_mul_ps( zxY1, yzX2 ) ); +} + +static inline b3V32 b3ModifiedCrossV( b3V32 a, b3V32 b ) +{ + b3V32 yzX1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 0, 2, 1 ) ); + b3V32 zxY1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 1, 0, 2 ) ); + b3V32 yzX2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 0, 2, 1 ) ); + b3V32 zxY2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 1, 0, 2 ) ); + + return _mm_add_ps( _mm_mul_ps( yzX1, zxY2 ), _mm_mul_ps( zxY1, yzX2 ) ); +} + +static inline bool b3AnyLess3V( b3V32 a, b3V32 b ) +{ + b3V32 v = _mm_cmplt_ps( a, b ); + return ( _mm_movemask_ps( v ) & 0x07 ) != 0; +} + +static inline bool b3AnyLessEq3V( b3V32 a, b3V32 b ) +{ + b3V32 v = _mm_cmple_ps( a, b ); + return ( _mm_movemask_ps( v ) & 0x07 ) != 0; +} + +static inline bool b3AnyGreater3V( b3V32 a, b3V32 b ) +{ + b3V32 v = _mm_cmpgt_ps( a, b ); + return ( _mm_movemask_ps( v ) & 0x07 ) != 0; +} + +static inline bool b3AllLessEq3V( b3V32 a, b3V32 b ) +{ + b3V32 v = _mm_cmple_ps( a, b ); + return ( _mm_movemask_ps( v ) & 0x07 ) == 0x07; +} + +#else // I don't expect the use case of b3V32 to benefit from Neon code. // In particular the cross product is very complex in Neon. -#include -#include - +// scalar math typedef struct b3V32 { float x, y, z; @@ -226,173 +332,6 @@ static inline bool b3AllLessEq3V( b3V32 a, b3V32 b ) #endif -int b3GetSIMDWidth( void ); -void b3SetSIMDWidth( int width ); - -// Wide vec3 -typedef struct b3Vec3W4 -{ - b3FloatW4 X, Y, Z; -} b3Vec3W4; - -static inline b3Vec3W4 b3LoadVW4( const float* x, const float* y, const float* z ) -{ - return (b3Vec3W4){ b3LoadW4( x ), b3LoadW4( y ), b3LoadW4( z ) }; -} - -static inline void b3StoreVW4( float* x, float* y, float* z, b3Vec3W4 v ) -{ - b3StoreW4( x, v.X ); - b3StoreW4( y, v.Y ); - b3StoreW4( z, v.Z ); -} - -static inline b3Vec3W4 b3SplatVW4( b3Vec3 v ) -{ - return (b3Vec3W4){ b3SplatW4( v.x ), b3SplatW4( v.y ), b3SplatW4( v.z ) }; -} - -static inline b3Vec3W4 b3NegVW4( b3Vec3W4 a ) -{ - return (b3Vec3W4){ b3NegW4( a.X ), b3NegW4( a.Y ), b3NegW4( a.Z ) }; -} - -// s * a -static inline b3Vec3W4 b3MulSVW4( b3FloatW4 s, b3Vec3W4 a ) -{ - return (b3Vec3W4){ b3MulW4( s, a.X ), b3MulW4( s, a.Y ), b3MulW4( s, a.Z ) }; -} - -// a - s * b -static inline b3Vec3W4 b3MulSubSVW4( b3Vec3W4 a, b3FloatW4 s, b3Vec3W4 b ) -{ - return (b3Vec3W4){ b3SubW4( a.X, b3MulW4( s, b.X ) ), b3SubW4( a.Y, b3MulW4( s, b.Y ) ), b3SubW4( a.Z, b3MulW4( s, b.Z ) ) }; -} - -// a + s * b -static inline b3Vec3W4 b3MulAddSVW4( b3Vec3W4 a, b3FloatW4 s, b3Vec3W4 b ) -{ - return (b3Vec3W4){ b3AddW4( a.X, b3MulW4( s, b.X ) ), b3AddW4( a.Y, b3MulW4( s, b.Y ) ), b3AddW4( a.Z, b3MulW4( s, b.Z ) ) }; -} - -// a - b -static inline b3Vec3W4 b3SubVW4( b3Vec3W4 a, b3Vec3W4 b ) -{ - return (b3Vec3W4){ - b3SubW4( a.X, b.X ), - b3SubW4( a.Y, b.Y ), - b3SubW4( a.Z, b.Z ), - }; -} - -// a + b -static inline b3Vec3W4 b3AddVW4( b3Vec3W4 a, b3Vec3W4 b ) -{ - return (b3Vec3W4){ - b3AddW4( a.X, b.X ), - b3AddW4( a.Y, b.Y ), - b3AddW4( a.Z, b.Z ), - }; -} - -static inline b3FloatW4 b3DotW4( b3Vec3W4 a, b3Vec3W4 b ) -{ - return b3AddW4( b3AddW4( b3MulW4( a.X, b.X ), b3MulW4( a.Y, b.Y ) ), b3MulW4( a.Z, b.Z ) ); -} - -static inline b3Vec3W4 b3CrossW4( b3Vec3W4 a, b3Vec3W4 b ) -{ - b3Vec3W4 c; - c.X = b3SubW4( b3MulW4( a.Y, b.Z ), b3MulW4( a.Z, b.Y ) ); - c.Y = b3SubW4( b3MulW4( a.Z, b.X ), b3MulW4( a.X, b.Z ) ); - c.Z = b3SubW4( b3MulW4( a.X, b.Y ), b3MulW4( a.Y, b.X ) ); - return c; -} - -#if defined( B3_SIMD_AVX2 ) - -// Wide vec3 -typedef struct b3Vec3W8 -{ - b3FloatW8 X, Y, Z; -} b3Vec3W8; - -static inline b3Vec3W8 b3LoadVW8( const float* x, const float* y, const float* z ) -{ - return (b3Vec3W8){ b3LoadW8( x ), b3LoadW8( y ), b3LoadW8( z ) }; -} - -static inline void b3StoreVW8( float* x, float* y, float* z, b3Vec3W8 v ) -{ - b3StoreW8( x, v.X ); - b3StoreW8( y, v.Y ); - b3StoreW8( z, v.Z ); -} - -static inline b3Vec3W8 b3SplatVW8( b3Vec3 v ) -{ - return (b3Vec3W8){ b3SplatW8( v.x ), b3SplatW8( v.y ), b3SplatW8( v.z ) }; -} - -static inline b3Vec3W8 b3NegVW8( b3Vec3W8 a ) -{ - return (b3Vec3W8){ b3NegW8( a.X ), b3NegW8( a.Y ), b3NegW8( a.Z ) }; -} - -// s * a -static inline b3Vec3W8 b3MulSVW8( b3FloatW8 s, b3Vec3W8 a ) -{ - return (b3Vec3W8){ b3MulW8( s, a.X ), b3MulW8( s, a.Y ), b3MulW8( s, a.Z ) }; -} - -// a - s * b -static inline b3Vec3W8 b3MulSubSVW8( b3Vec3W8 a, b3FloatW8 s, b3Vec3W8 b ) -{ - return (b3Vec3W8){ b3SubW8( a.X, b3MulW8( s, b.X ) ), b3SubW8( a.Y, b3MulW8( s, b.Y ) ), b3SubW8( a.Z, b3MulW8( s, b.Z ) ) }; -} - -// a + s * b -static inline b3Vec3W8 b3MulAddSVW8( b3Vec3W8 a, b3FloatW8 s, b3Vec3W8 b ) -{ - return (b3Vec3W8){ b3AddW8( a.X, b3MulW8( s, b.X ) ), b3AddW8( a.Y, b3MulW8( s, b.Y ) ), b3AddW8( a.Z, b3MulW8( s, b.Z ) ) }; -} - -// a - b -static inline b3Vec3W8 b3SubVW8( b3Vec3W8 a, b3Vec3W8 b ) -{ - return (b3Vec3W8){ - b3SubW8( a.X, b.X ), - b3SubW8( a.Y, b.Y ), - b3SubW8( a.Z, b.Z ), - }; -} - -// a + b -static inline b3Vec3W8 b3AddVW8( b3Vec3W8 a, b3Vec3W8 b ) -{ - return (b3Vec3W8){ - b3AddW8( a.X, b.X ), - b3AddW8( a.Y, b.Y ), - b3AddW8( a.Z, b.Z ), - }; -} - -static inline b3FloatW8 b3DotW8( b3Vec3W8 a, b3Vec3W8 b ) -{ - return b3AddW8( b3AddW8( b3MulW8( a.X, b.X ), b3MulW8( a.Y, b.Y ) ), b3MulW8( a.Z, b.Z ) ); -} - -static inline b3Vec3W8 b3CrossW8( b3Vec3W8 a, b3Vec3W8 b ) -{ - b3Vec3W8 c; - c.X = b3SubW8( b3MulW8( a.Y, b.Z ), b3MulW8( a.Z, b.Y ) ); - c.Y = b3SubW8( b3MulW8( a.Z, b.X ), b3MulW8( a.X, b.Z ) ); - c.Z = b3SubW8( b3MulW8( a.X, b.Y ), b3MulW8( a.Y, b.X ) ); - return c; -} - -#endif - static inline bool b3TestBoundsOverlap( b3V32 nodeMin1, b3V32 nodeMax1, b3V32 nodeMin2, b3V32 nodeMax2 ) { b3V32 separation = b3MaxV( b3SubV( nodeMin2, nodeMax1 ), b3SubV( nodeMin1, nodeMax2 ) ); @@ -416,10 +355,3 @@ static inline bool b3TestBoundsRayOverlap( b3V32 nodeMin, b3V32 nodeMax, b3V32 r bool b3TestBoundsTriangleOverlap( b3V32 nodeCenter, b3V32 nodeExtent, b3V32 vertex1, b3V32 vertex2, b3V32 vertex3 ); float b3IntersectRayTriangle( b3V32 rayStart, b3V32 rayDelta, b3V32 vertex1, b3V32 vertex2, b3V32 vertex3 ); - -B3_FORCE_INLINE b3AABB b3UnionV( b3AABB a, b3AABB b ) -{ - b3AABB result = { 0 }; - b3StoreAABBV( &result, b3UnionAABBV( b3LoadAABBV( &a ), b3LoadAABBV( &b ) ), true ); - return result; -} diff --git a/src/simd_avx2.h b/src/simd_avx2.h deleted file mode 100644 index 36c79d6..0000000 --- a/src/simd_avx2.h +++ /dev/null @@ -1,208 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "core.h" - -#include "box3d/types.h" - -#include - -// wide float holds 8 numbers -typedef __m256 b3FloatW8; - -static inline b3FloatW8 b3ZeroW8( void ) -{ - return _mm256_setzero_ps(); -} - -static inline b3FloatW8 b3SplatW8( float scalar ) -{ - return _mm256_set1_ps( scalar ); -} - -static inline b3FloatW8 b3SetW8( float a, float b, float c, float d, float e, float f, float g, float h ) -{ - return _mm256_setr_ps( a, b, c, d, e, f, g, h ); -} - -static inline b3FloatW8 b3LoadW8( const float* data ) -{ - return _mm256_loadu_ps( data ); -} - -static inline void b3StoreW8( float* data, b3FloatW8 a ) -{ - _mm256_storeu_ps( data, a ); -} - -static inline b3FloatW8 b3NegW8( b3FloatW8 a ) -{ - // Create a mask with the sign bit set for each element. - __m256 mask = _mm256_set1_ps( -0.0f ); - - // XOR the input with the mask to negate each element. - return _mm256_xor_ps( a, mask ); -} - -static inline b3FloatW8 b3AbsW8( b3FloatW8 a ) -{ - return _mm256_andnot_ps( _mm256_set1_ps( -0.0f ), a ); -} - -static inline b3FloatW8 b3AddW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_add_ps( a, b ); -} - -static inline b3FloatW8 b3SubW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_sub_ps( a, b ); -} - -static inline b3FloatW8 b3MulW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_mul_ps( a, b ); -} - -static inline b3FloatW8 b3DivW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_div_ps( a, b ); -} - -static inline b3FloatW8 b3SqrtW8( b3FloatW8 a ) -{ - return _mm256_sqrt_ps( a ); -} - -// a + b * c -static inline b3FloatW8 b3MulAddW8( b3FloatW8 a, b3FloatW8 b, b3FloatW8 c ) -{ - return _mm256_add_ps( a, _mm256_mul_ps( b, c ) ); -} - -static inline b3FloatW8 b3MinW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_min_ps( a, b ); -} - -static inline b3FloatW8 b3MaxW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_max_ps( a, b ); -} - -static inline b3FloatW8 b3AndW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_and_ps( a, b ); -} - -static inline b3FloatW8 b3OrW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_or_ps( a, b ); -} - -// a & ~b -static inline b3FloatW8 b3AndNotW8( b3FloatW8 a, b3FloatW8 b ) -{ - // Arguments are reversed - return _mm256_andnot_ps( b, a ); -} - -// This is used to optimize selection of contact softness. -static inline b3FloatW8 b3SoftMaskW8( const int* indexA, const int* indexB ) -{ - __m256i zero = _mm256_setzero_si256(); - __m256i a = _mm256_cmpeq_epi32( _mm256_loadu_si256( (const __m256i*)indexA ), zero ); - __m256i b = _mm256_cmpeq_epi32( _mm256_loadu_si256( (const __m256i*)indexB ), zero ); - return _mm256_castsi256_ps( _mm256_or_si256( a, b ) ); -} - -static inline b3FloatW8 b3GreaterThanW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_cmp_ps( a, b, _CMP_GT_OQ ); -} - -static inline b3FloatW8 b3LessThanW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_cmp_ps( a, b, _CMP_LT_OQ ); -} - -static inline b3FloatW8 b3EqualsW8( b3FloatW8 a, b3FloatW8 b ) -{ - return _mm256_cmp_ps( a, b, _CMP_EQ_OQ ); -} - -static inline bool b3AllZeroW8( b3FloatW8 a ) -{ - // Compare each element with zero - b3FloatW8 zero = _mm256_setzero_ps(); - b3FloatW8 cmp = _mm256_cmp_ps( a, zero, _CMP_EQ_OQ ); - - // Create a mask from the comparison results - int mask = _mm256_movemask_ps( cmp ); - - // If all elements are zero, the mask will be 0xFF (11111111 in binary) - return mask == 0xFF; -} - -static inline bool b3AnyTrueW8( b3FloatW8 mask ) -{ - return _mm256_movemask_ps( mask ) != 0; -} - -// Component-wise returns mask ? b : a -static inline b3FloatW8 b3BlendW8( b3FloatW8 a, b3FloatW8 b, b3FloatW8 mask ) -{ - return _mm256_or_ps( _mm256_and_ps( mask, b ), _mm256_andnot_ps( mask, a ) ); -} - -// Replace the low bitCount mantissa bits of each lane with baseIndex + lane. The value must be -// positive so the embedded index sorts with the value, and ties fall to the lower index. -static inline b3FloatW8 b3EmbedIndexW8( b3FloatW8 value, int baseIndex, int bitCount ) -{ - int mask = ( 1 << bitCount ) - 1; - __m256i index = _mm256_add_epi32( _mm256_set1_epi32( baseIndex ), _mm256_setr_epi32( 0, 1, 2, 3, 4, 5, 6, 7 ) ); - __m256 clearLow = _mm256_castsi256_ps( _mm256_set1_epi32( ~mask ) ); - return _mm256_or_ps( _mm256_and_ps( value, clearLow ), _mm256_castsi256_ps( index ) ); -} - -// Recovers the index embedded by b3EmbedIndexW8 from the lane holding the minimum. -static inline int b3MinIndexW8( b3FloatW8 a, int bitCount ) -{ - __m128 min = _mm_min_ps( _mm256_castps256_ps128( a ), _mm256_extractf128_ps( a, 1 ) ); - min = _mm_min_ps( _mm_shuffle_ps( min, min, _MM_SHUFFLE( 2, 3, 0, 1 ) ), min ); - min = _mm_min_ps( _mm_shuffle_ps( min, min, _MM_SHUFFLE( 1, 0, 3, 2 ) ), min ); - return _mm_cvtsi128_si32( _mm_castps_si128( min ) ) & ( ( 1 << bitCount ) - 1 ); -} - -B3_FORCE_INLINE void b3TransposeW8( b3FloatW8 r0, b3FloatW8 r1, b3FloatW8 r2, b3FloatW8 r3, b3FloatW8 r4, b3FloatW8 r5, - b3FloatW8 r6, b3FloatW8 r7, b3FloatW8* c0, b3FloatW8* c1, b3FloatW8* c2, b3FloatW8* c3, - b3FloatW8* c4, b3FloatW8* c5, b3FloatW8* c6, b3FloatW8* c7 ) -{ - b3FloatW8 t0 = _mm256_unpacklo_ps( r0, r1 ); - b3FloatW8 t1 = _mm256_unpackhi_ps( r0, r1 ); - b3FloatW8 t2 = _mm256_unpacklo_ps( r2, r3 ); - b3FloatW8 t3 = _mm256_unpackhi_ps( r2, r3 ); - b3FloatW8 t4 = _mm256_unpacklo_ps( r4, r5 ); - b3FloatW8 t5 = _mm256_unpackhi_ps( r4, r5 ); - b3FloatW8 t6 = _mm256_unpacklo_ps( r6, r7 ); - b3FloatW8 t7 = _mm256_unpackhi_ps( r6, r7 ); - b3FloatW8 tt0 = _mm256_shuffle_ps( t0, t2, _MM_SHUFFLE( 1, 0, 1, 0 ) ); - b3FloatW8 tt1 = _mm256_shuffle_ps( t0, t2, _MM_SHUFFLE( 3, 2, 3, 2 ) ); - b3FloatW8 tt2 = _mm256_shuffle_ps( t1, t3, _MM_SHUFFLE( 1, 0, 1, 0 ) ); - b3FloatW8 tt3 = _mm256_shuffle_ps( t1, t3, _MM_SHUFFLE( 3, 2, 3, 2 ) ); - b3FloatW8 tt4 = _mm256_shuffle_ps( t4, t6, _MM_SHUFFLE( 1, 0, 1, 0 ) ); - b3FloatW8 tt5 = _mm256_shuffle_ps( t4, t6, _MM_SHUFFLE( 3, 2, 3, 2 ) ); - b3FloatW8 tt6 = _mm256_shuffle_ps( t5, t7, _MM_SHUFFLE( 1, 0, 1, 0 ) ); - b3FloatW8 tt7 = _mm256_shuffle_ps( t5, t7, _MM_SHUFFLE( 3, 2, 3, 2 ) ); - - *c0 = _mm256_permute2f128_ps( tt0, tt4, 0x20 ); - *c1 = _mm256_permute2f128_ps( tt1, tt5, 0x20 ); - *c2 = _mm256_permute2f128_ps( tt2, tt6, 0x20 ); - *c3 = _mm256_permute2f128_ps( tt3, tt7, 0x20 ); - *c4 = _mm256_permute2f128_ps( tt0, tt4, 0x31 ); - *c5 = _mm256_permute2f128_ps( tt1, tt5, 0x31 ); - *c6 = _mm256_permute2f128_ps( tt2, tt6, 0x31 ); - *c7 = _mm256_permute2f128_ps( tt3, tt7, 0x31 ); -} diff --git a/src/simd_neon.h b/src/simd_neon.h deleted file mode 100644 index ce9b560..0000000 --- a/src/simd_neon.h +++ /dev/null @@ -1,265 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "core.h" - -#include "box3d/types.h" - -#include - -// wide float holds 4 numbers -typedef float32x4_t b3FloatW4; - -static inline b3FloatW4 b3ZeroW4( void ) -{ - return vdupq_n_f32( 0.0f ); -} - -static inline b3FloatW4 b3SplatW4( float scalar ) -{ - return vdupq_n_f32( scalar ); -} - -static inline b3FloatW4 b3SetW4( float a, float b, float c, float d ) -{ - float32_t array[4] = { a, b, c, d }; - return vld1q_f32( array ); -} - -static inline b3FloatW4 b3LoadW4( const float* data ) -{ - return vld1q_f32( data ); -} - -static inline void b3StoreW4( float* data, b3FloatW4 a ) -{ - vst1q_f32( data, a ); -} - -static inline b3FloatW4 b3NegW4( b3FloatW4 a ) -{ - return vnegq_f32( a ); -} - -static inline b3FloatW4 b3AbsW4( b3FloatW4 a ) -{ - return vabsq_f32( a ); -} - -static inline b3FloatW4 b3AddW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vaddq_f32( a, b ); -} - -static inline b3FloatW4 b3SubW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vsubq_f32( a, b ); -} - -static inline b3FloatW4 b3MulW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vmulq_f32( a, b ); -} - -static inline b3FloatW4 b3DivW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vdivq_f32( a, b ); -} - -static inline b3FloatW4 b3SqrtW4( b3FloatW4 a ) -{ - return vsqrtq_f32( a ); -} - -// Cannot use real FMA because it doesn't match the non-SIMD path -static inline b3FloatW4 b3MulAddW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 c ) -{ - return vaddq_f32( a, vmulq_f32( b, c ) ); -} - -static inline b3FloatW4 b3MinW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vminq_f32( a, b ); -} - -static inline b3FloatW4 b3MaxW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vmaxq_f32( a, b ); -} - -static inline b3FloatW4 b3AndW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vandq_u32( vreinterpretq_u32_f32( a ), vreinterpretq_u32_f32( b ) ) ); -} - -static inline b3FloatW4 b3OrW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vorrq_u32( vreinterpretq_u32_f32( a ), vreinterpretq_u32_f32( b ) ) ); -} - -// a & ~b -static inline b3FloatW4 b3AndNotW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vbicq_u32( vreinterpretq_u32_f32( a ), vreinterpretq_u32_f32( b ) ) ); -} - -static inline b3FloatW4 b3SoftMaskW4( const int* indexA, const int* indexB ) -{ - int32x4_t zero = vdupq_n_s32( 0 ); - uint32x4_t a = vceqq_s32( vld1q_s32( (const int32_t*)indexA ), zero ); - uint32x4_t b = vceqq_s32( vld1q_s32( (const int32_t*)indexB ), zero ); - return vreinterpretq_f32_u32( vorrq_u32( a, b ) ); -} - -static inline b3FloatW4 b3GreaterThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vcgtq_f32( a, b ) ); -} - -static inline b3FloatW4 b3LessThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vcltq_f32( a, b ) ); -} - -static inline b3FloatW4 b3EqualsW4( b3FloatW4 a, b3FloatW4 b ) -{ - return vreinterpretq_f32_u32( vceqq_f32( a, b ) ); -} - -static inline bool b3AllZeroW4( b3FloatW4 a ) -{ - // Create a zero vector for comparison - b3FloatW4 zero = vdupq_n_f32( 0.0f ); - - // Compare the input vector with zero - uint32x4_t cmp_result = vceqq_f32( a, zero ); - -// Check if all comparison results are non-zero using vminvq -#ifdef __ARM_FEATURE_SVE - // ARM v8.2+ has horizontal minimum instruction - return vminvq_u32( cmp_result ) != 0; -#else - // For older ARM architectures, we need to manually check all lanes - return vgetq_lane_u32( cmp_result, 0 ) != 0 && vgetq_lane_u32( cmp_result, 1 ) != 0 && vgetq_lane_u32( cmp_result, 2 ) != 0 && - vgetq_lane_u32( cmp_result, 3 ) != 0; -#endif -} - -// _mm_movemask_ps equivalent, compatible with ARM v7. -static inline bool b3AnyTrueW4( b3FloatW4 mask ) -{ - uint32x4_t m = vreinterpretq_u32_f32( mask ); - uint32x2_t p = vorr_u32( vget_low_u32( m ), vget_high_u32( m ) ); - return ( vget_lane_u32( p, 0 ) | vget_lane_u32( p, 1 ) ) != 0; -} - -static inline int b3MoveMaskW4( b3FloatW4 mask ) -{ - const int32_t shifts[4] = { 0, 1, 2, 3 }; - uint32x4_t bits = vshlq_u32( vshrq_n_u32( vreinterpretq_u32_f32( mask ), 31 ), vld1q_s32( shifts ) ); - uint32x2_t p = vorr_u32( vget_low_u32( bits ), vget_high_u32( bits ) ); - return (int)( vget_lane_u32( p, 0 ) | vget_lane_u32( p, 1 ) ); -} - -// component-wise returns mask ? b : a -static inline b3FloatW4 b3BlendW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 mask ) -{ - uint32x4_t mask32 = vreinterpretq_u32_f32( mask ); - return vbslq_f32( mask32, b, a ); -} - -static inline b3FloatW4 b3EmbedIndexW4( b3FloatW4 value, int baseIndex, int bitCount ) -{ - uint32_t mask = ( 1u << bitCount ) - 1; - const int32_t lanes[4] = { 0, 1, 2, 3 }; - int32x4_t index = vaddq_s32( vdupq_n_s32( baseIndex ), vld1q_s32( lanes ) ); - uint32x4_t clearLow = vdupq_n_u32( ~mask ); - uint32x4_t bits = vorrq_u32( vandq_u32( vreinterpretq_u32_f32( value ), clearLow ), vreinterpretq_u32_s32( index ) ); - return vreinterpretq_f32_u32( bits ); -} - -static inline int b3MinIndexW4( b3FloatW4 a, int bitCount ) -{ - float32x2_t m = vmin_f32( vget_low_f32( a ), vget_high_f32( a ) ); - m = vpmin_f32( m, m ); - uint32_t bits = vget_lane_u32( vreinterpret_u32_f32( m ), 0 ); - return (int)( bits & ( ( 1u << bitCount ) - 1 ) ); -} - -typedef struct b3AABBV -{ - float32x4_t lower; - float32x4_t upper; -} b3AABBV; - -B3_FORCE_INLINE b3AABBV b3LoadAABBV( const b3AABB* aabb ) -{ - const float* base = &aabb->lowerBound.x; - - // Offset to avoid reading off the end (avoid UB). - // [lz ux uy uz] - float32x4_t v1 = vld1q_f32( base + 2 ); - b3AABBV result; - // [lx ly lz -] - result.lower = vld1q_f32( base ); - // [ux uy uz -] - result.upper = vextq_f32( v1, v1, 1 ); - return result; -} - -B3_FORCE_INLINE bool b3OverlapAABBV( b3AABBV a, b3AABBV b ) -{ - static const uint32_t laneMask[4] = { 0, 0, 0, 0xFFFFFFFFu }; - uint32x4_t test = vandq_u32( vcleq_f32( a.lower, b.upper ), vcleq_f32( b.lower, a.upper ) ); - return vminvq_u32( vorrq_u32( test, vld1q_u32( laneMask ) ) ) != 0; -} - -B3_FORCE_INLINE bool b3OverlapNode( b3AABBV av, const b3TreeNode* node ) -{ - return b3OverlapAABBV( av, b3LoadAABBV( &node->aabb ) ); -} - -B3_FORCE_INLINE bool b3OverlapV( const b3AABB* a, const b3AABB* b ) -{ - return b3OverlapAABBV( b3LoadAABBV( a ), b3LoadAABBV( b ) ); -} - -B3_FORCE_INLINE b3AABBV b3UnionAABBV( b3AABBV a, b3AABBV b ) -{ - b3AABBV result; - result.lower = vminq_f32( a.lower, b.lower ); - result.upper = vmaxq_f32( a.upper, b.upper ); - return result; -} - -B3_FORCE_INLINE b3AABBV b3UnionPairV( const b3TreeNode* pair ) -{ - return b3UnionAABBV( b3LoadAABBV( &pair[0].aabb ), b3LoadAABBV( &pair[1].aabb ) ); -} - -B3_FORCE_INLINE void b3StoreAABBV( b3AABB* aabb, b3AABBV value, bool condition ) -{ - float32x4_t raw0 = vsetq_lane_f32( vgetq_lane_f32( value.upper, 0 ), value.lower, 3 ); - float32x4_t rotated = vextq_f32( value.upper, value.upper, 1 ); - float32x4_t raw1 = vcombine_f32( vget_high_f32( raw0 ), vget_low_f32( rotated ) ); - - float* base = &aabb->lowerBound.x; - uint32x4_t mask = vdupq_n_u32( condition ? 0xFFFFFFFFu : 0u ); - vst1q_f32( base, vbslq_f32( mask, raw0, vld1q_f32( base ) ) ); - vst1q_f32( base + 2, vbslq_f32( mask, raw1, vld1q_f32( base + 2 ) ) ); -} - -B3_FORCE_INLINE void b3TransposeW4( b3FloatW4 r0, b3FloatW4 r1, b3FloatW4 r2, b3FloatW4 r3, b3FloatW4* c0, b3FloatW4* c1, - b3FloatW4* c2, b3FloatW4* c3 ) -{ - b3FloatW4 t0 = vzip1q_f32( r0, r2 ); - b3FloatW4 t1 = vzip1q_f32( r1, r3 ); - b3FloatW4 t2 = vzip2q_f32( r0, r2 ); - b3FloatW4 t3 = vzip2q_f32( r1, r3 ); - *c0 = vzip1q_f32( t0, t1 ); - *c1 = vzip2q_f32( t0, t1 ); - *c2 = vzip1q_f32( t2, t3 ); - *c3 = vzip2q_f32( t2, t3 ); -} diff --git a/src/simd_scalar.h b/src/simd_scalar.h deleted file mode 100644 index 8ae1b85..0000000 --- a/src/simd_scalar.h +++ /dev/null @@ -1,286 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "core.h" - -#include "box3d/types.h" - -#include -#include - -// scalar math -typedef struct b3FloatW4 -{ - float x, y, z, w; -} b3FloatW4; - -static inline b3FloatW4 b3ZeroW4( void ) -{ - return (b3FloatW4){ 0.0f, 0.0f, 0.0f, 0.0f }; -} - -static inline b3FloatW4 b3SplatW4( float scalar ) -{ - return (b3FloatW4){ scalar, scalar, scalar, scalar }; -} - -static inline b3FloatW4 b3SetW4( float a, float b, float c, float d ) -{ - return (b3FloatW4){ a, b, c, d }; -} - -static inline b3FloatW4 b3LoadW4( const float* data ) -{ - return (b3FloatW4){ data[0], data[1], data[2], data[3] }; -} - -static inline void b3StoreW4( float* data, b3FloatW4 a ) -{ - data[0] = a.x; - data[1] = a.y; - data[2] = a.z; - data[3] = a.w; -} - -static inline b3FloatW4 b3NegW4( b3FloatW4 a ) -{ - return (b3FloatW4){ -a.x, -a.y, -a.z, -a.w }; -} - -static inline b3FloatW4 b3AbsW4( b3FloatW4 a ) -{ - return (b3FloatW4){ a.x < 0.0f ? -a.x : a.x, a.y < 0.0f ? -a.y : a.y, a.z < 0.0f ? -a.z : a.z, a.w < 0.0f ? -a.w : a.w }; -} - -static inline b3FloatW4 b3AddW4( b3FloatW4 a, b3FloatW4 b ) -{ - return (b3FloatW4){ a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w }; -} - -static inline b3FloatW4 b3SubW4( b3FloatW4 a, b3FloatW4 b ) -{ - return (b3FloatW4){ a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w }; -} - -static inline b3FloatW4 b3MulW4( b3FloatW4 a, b3FloatW4 b ) -{ - return (b3FloatW4){ a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w }; -} - -static inline b3FloatW4 b3DivW4( b3FloatW4 a, b3FloatW4 b ) -{ - return (b3FloatW4){ a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w }; -} - -static inline b3FloatW4 b3SqrtW4( b3FloatW4 a ) -{ - return (b3FloatW4){ sqrtf( a.x ), sqrtf( a.y ), sqrtf( a.z ), sqrtf( a.w ) }; -} - -static inline b3FloatW4 b3MulAddW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 c ) -{ - return (b3FloatW4){ a.x + b.x * c.x, a.y + b.y * c.y, a.z + b.z * c.z, a.w + b.w * c.w }; -} - -static inline b3FloatW4 b3MinW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x <= b.x ? a.x : b.x; - r.y = a.y <= b.y ? a.y : b.y; - r.z = a.z <= b.z ? a.z : b.z; - r.w = a.w <= b.w ? a.w : b.w; - return r; -} - -static inline b3FloatW4 b3MaxW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x >= b.x ? a.x : b.x; - r.y = a.y >= b.y ? a.y : b.y; - r.z = a.z >= b.z ? a.z : b.z; - r.w = a.w >= b.w ? a.w : b.w; - return r; -} - -// Logical operations on the scalar path are 0/1 float values. Not bit-wise like SIMD. - -static inline b3FloatW4 b3AndW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x != 0.0f && b.x != 0.0f ? 1.0f : 0.0f; - r.y = a.y != 0.0f && b.y != 0.0f ? 1.0f : 0.0f; - r.z = a.z != 0.0f && b.z != 0.0f ? 1.0f : 0.0f; - r.w = a.w != 0.0f && b.w != 0.0f ? 1.0f : 0.0f; - return r; -} - -static inline b3FloatW4 b3OrW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x != 0.0f || b.x != 0.0f ? 1.0f : 0.0f; - r.y = a.y != 0.0f || b.y != 0.0f ? 1.0f : 0.0f; - r.z = a.z != 0.0f || b.z != 0.0f ? 1.0f : 0.0f; - r.w = a.w != 0.0f || b.w != 0.0f ? 1.0f : 0.0f; - return r; -} - -// a & ~b -static inline b3FloatW4 b3AndNotW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x != 0.0f && b.x == 0.0f ? 1.0f : 0.0f; - r.y = a.y != 0.0f && b.y == 0.0f ? 1.0f : 0.0f; - r.z = a.z != 0.0f && b.z == 0.0f ? 1.0f : 0.0f; - r.w = a.w != 0.0f && b.w == 0.0f ? 1.0f : 0.0f; - return r; -} - -static inline b3FloatW4 b3SoftMaskW4( const int* indexA, const int* indexB ) -{ - b3FloatW4 r; - r.x = indexA[0] == 0 || indexB[0] == 0 ? 1.0f : 0.0f; - r.y = indexA[1] == 0 || indexB[1] == 0 ? 1.0f : 0.0f; - r.z = indexA[2] == 0 || indexB[2] == 0 ? 1.0f : 0.0f; - r.w = indexA[3] == 0 || indexB[3] == 0 ? 1.0f : 0.0f; - return r; -} - -static inline b3FloatW4 b3GreaterThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x > b.x ? 1.0f : 0.0f; - r.y = a.y > b.y ? 1.0f : 0.0f; - r.z = a.z > b.z ? 1.0f : 0.0f; - r.w = a.w > b.w ? 1.0f : 0.0f; - return r; -} - -static inline b3FloatW4 b3LessThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x < b.x ? 1.0f : 0.0f; - r.y = a.y < b.y ? 1.0f : 0.0f; - r.z = a.z < b.z ? 1.0f : 0.0f; - r.w = a.w < b.w ? 1.0f : 0.0f; - return r; -} - -static inline b3FloatW4 b3EqualsW4( b3FloatW4 a, b3FloatW4 b ) -{ - b3FloatW4 r; - r.x = a.x == b.x ? 1.0f : 0.0f; - r.y = a.y == b.y ? 1.0f : 0.0f; - r.z = a.z == b.z ? 1.0f : 0.0f; - r.w = a.w == b.w ? 1.0f : 0.0f; - return r; -} - -static inline bool b3AllZeroW4( b3FloatW4 a ) -{ - return a.x == 0.0f && a.y == 0.0f && a.z == 0.0f && a.w == 0.0f; -} - -static inline bool b3AnyTrueW4( b3FloatW4 mask ) -{ - return mask.x != 0.0f || mask.y != 0.0f || mask.z != 0.0f || mask.w != 0.0f; -} - -static inline int b3MoveMaskW4( b3FloatW4 mask ) -{ - return ( mask.x != 0.0f ? 1 : 0 ) | ( mask.y != 0.0f ? 2 : 0 ) | ( mask.z != 0.0f ? 4 : 0 ) | ( mask.w != 0.0f ? 8 : 0 ); -} - -// component-wise returns mask ? b : a -static inline b3FloatW4 b3BlendW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 mask ) -{ - b3FloatW4 r; - r.x = mask.x != 0.0f ? b.x : a.x; - r.y = mask.y != 0.0f ? b.y : a.y; - r.z = mask.z != 0.0f ? b.z : a.z; - r.w = mask.w != 0.0f ? b.w : a.w; - return r; -} - -static inline b3FloatW4 b3EmbedIndexW4( b3FloatW4 value, int baseIndex, int bitCount ) -{ - uint32_t mask = ( 1u << bitCount ) - 1; - float lanes[4] = { value.x, value.y, value.z, value.w }; - - for ( int i = 0; i < 4; ++i ) - { - uint32_t bits; - memcpy( &bits, lanes + i, sizeof( bits ) ); - bits = ( bits & ~mask ) | (uint32_t)( baseIndex + i ); - memcpy( lanes + i, &bits, sizeof( bits ) ); - } - - return (b3FloatW4){ lanes[0], lanes[1], lanes[2], lanes[3] }; -} - -static inline int b3MinIndexW4( b3FloatW4 a, int bitCount ) -{ - float m = a.x; - m = a.y < m ? a.y : m; - m = a.z < m ? a.z : m; - m = a.w < m ? a.w : m; - - uint32_t bits; - memcpy( &bits, &m, sizeof( bits ) ); - return (int)( bits & ( ( 1u << bitCount ) - 1 ) ); -} - -typedef b3AABB b3AABBV; - -B3_FORCE_INLINE b3AABBV b3LoadAABBV( const b3AABB* aabb ) -{ - return *aabb; -} - -B3_FORCE_INLINE bool b3OverlapAABBV( b3AABBV a, b3AABBV b ) -{ - return a.lowerBound.x <= b.upperBound.x && a.lowerBound.y <= b.upperBound.y && a.lowerBound.z <= b.upperBound.z && - b.lowerBound.x <= a.upperBound.x && b.lowerBound.y <= a.upperBound.y && b.lowerBound.z <= a.upperBound.z; -} - -B3_FORCE_INLINE bool b3OverlapNode( b3AABBV av, const b3TreeNode* node ) -{ - return b3OverlapAABBV( av, node->aabb ); -} - -B3_FORCE_INLINE bool b3OverlapV( const b3AABB* a, const b3AABB* b ) -{ - return b3OverlapAABBV( *a, *b ); -} - -B3_FORCE_INLINE b3AABBV b3UnionAABBV( b3AABBV a, b3AABBV b ) -{ - return b3AABB_Union( a, b ); -} - -B3_FORCE_INLINE b3AABBV b3UnionPairV( const b3TreeNode* pair ) -{ - return b3AABB_Union( pair[0].aabb, pair[1].aabb ); -} - -B3_FORCE_INLINE void b3StoreAABBV( b3AABB* aabb, b3AABBV value, bool condition ) -{ - if ( condition ) - { - *aabb = value; - } -} - -B3_FORCE_INLINE void b3TransposeW4( b3FloatW4 r0, b3FloatW4 r1, b3FloatW4 r2, b3FloatW4 r3, b3FloatW4* c0, b3FloatW4* c1, - b3FloatW4* c2, b3FloatW4* c3 ) -{ - b3FloatW4 t0 = (b3FloatW4){ r0.x, r2.x, r0.y, r2.y }; - b3FloatW4 t1 = (b3FloatW4){ r1.x, r3.x, r1.y, r3.y }; - b3FloatW4 t2 = (b3FloatW4){ r0.z, r2.z, r0.w, r2.w }; - b3FloatW4 t3 = (b3FloatW4){ r1.z, r3.z, r1.w, r3.w }; - *c0 = (b3FloatW4){ t0.x, t1.x, t0.y, t1.y }; - *c1 = (b3FloatW4){ t0.z, t1.z, t0.w, t1.w }; - *c2 = (b3FloatW4){ t2.x, t3.x, t2.y, t3.y }; - *c3 = (b3FloatW4){ t2.z, t3.z, t2.w, t3.w }; -} diff --git a/src/simd_sse2.h b/src/simd_sse2.h deleted file mode 100644 index 8041c47..0000000 --- a/src/simd_sse2.h +++ /dev/null @@ -1,411 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "core.h" - -#include "box3d/types.h" - -#include - -// wide float holds 4 numbers -typedef __m128 b3FloatW4; - -static inline b3FloatW4 b3ZeroW4( void ) -{ - return _mm_setzero_ps(); -} - -static inline b3FloatW4 b3SplatW4( float scalar ) -{ - return _mm_set1_ps( scalar ); -} - -static inline b3FloatW4 b3SetW4( float a, float b, float c, float d ) -{ - return _mm_setr_ps( a, b, c, d ); -} - -static inline b3FloatW4 b3LoadW4( const float* data ) -{ - return _mm_loadu_ps( data ); -} - -static inline void b3StoreW4( float* data, b3FloatW4 a ) -{ - _mm_storeu_ps( data, a ); -} - -static inline b3FloatW4 b3NegW4( b3FloatW4 a ) -{ - // Create a mask with the sign bit set for each element - __m128 mask = _mm_set1_ps( -0.0f ); - - // XOR the input with the mask to negate each element - return _mm_xor_ps( a, mask ); -} - -static inline b3FloatW4 b3AbsW4( b3FloatW4 a ) -{ - return _mm_andnot_ps( _mm_set1_ps( -0.0f ), a ); -} - -static inline b3FloatW4 b3AddW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_add_ps( a, b ); -} - -static inline b3FloatW4 b3SubW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_sub_ps( a, b ); -} - -static inline b3FloatW4 b3MulW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_mul_ps( a, b ); -} - -static inline b3FloatW4 b3DivW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_div_ps( a, b ); -} - -static inline b3FloatW4 b3SqrtW4( b3FloatW4 a ) -{ - return _mm_sqrt_ps( a ); -} - -// a + b * c -static inline b3FloatW4 b3MulAddW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 c ) -{ - return _mm_add_ps( a, _mm_mul_ps( b, c ) ); -} - -static inline b3FloatW4 b3MinW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_min_ps( a, b ); -} - -static inline b3FloatW4 b3MaxW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_max_ps( a, b ); -} - -static inline b3FloatW4 b3AndW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_and_ps( a, b ); -} - -static inline b3FloatW4 b3OrW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_or_ps( a, b ); -} - -// a & ~b -static inline b3FloatW4 b3AndNotW4( b3FloatW4 a, b3FloatW4 b ) -{ - // Arguments are reversed - return _mm_andnot_ps( b, a ); -} - -// This is used to optimize selection of contact softness. -static inline b3FloatW4 b3SoftMaskW4( const int* indexA, const int* indexB ) -{ - __m128i zero = _mm_setzero_si128(); - __m128i a = _mm_cmpeq_epi32( _mm_loadu_si128( (const __m128i*)indexA ), zero ); - __m128i b = _mm_cmpeq_epi32( _mm_loadu_si128( (const __m128i*)indexB ), zero ); - return _mm_castsi128_ps( _mm_or_si128( a, b ) ); -} - -static inline b3FloatW4 b3GreaterThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_cmpgt_ps( a, b ); -} - -static inline b3FloatW4 b3LessThanW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_cmplt_ps( a, b ); -} - -static inline b3FloatW4 b3EqualsW4( b3FloatW4 a, b3FloatW4 b ) -{ - return _mm_cmpeq_ps( a, b ); -} - -static inline bool b3AllZeroW4( b3FloatW4 a ) -{ - // Compare each element with zero - b3FloatW4 zero = _mm_setzero_ps(); - b3FloatW4 cmp = _mm_cmpeq_ps( a, zero ); - - // Create a mask from the comparison results - int mask = _mm_movemask_ps( cmp ); - - // If all elements are zero, the mask will be 0xF (1111 in binary) - return mask == 0xF; -} - -static inline bool b3AnyTrueW4( b3FloatW4 mask ) -{ - return _mm_movemask_ps( mask ) != 0; -} - -static inline int b3MoveMaskW4( b3FloatW4 mask ) -{ - return _mm_movemask_ps( mask ); -} - -// component-wise returns mask ? b : a -static inline b3FloatW4 b3BlendW4( b3FloatW4 a, b3FloatW4 b, b3FloatW4 mask ) -{ - return _mm_or_ps( _mm_and_ps( mask, b ), _mm_andnot_ps( mask, a ) ); -} - -// Replace the low bitCount mantissa bits of each lane with baseIndex + lane. The value must be -// positive so the embedded index sorts with the value, and ties fall to the lower index. -static inline b3FloatW4 b3EmbedIndexW4( b3FloatW4 value, int baseIndex, int bitCount ) -{ - int mask = ( 1 << bitCount ) - 1; - __m128i index = _mm_add_epi32( _mm_set1_epi32( baseIndex ), _mm_setr_epi32( 0, 1, 2, 3 ) ); - __m128 clearLow = _mm_castsi128_ps( _mm_set1_epi32( ~mask ) ); - return _mm_or_ps( _mm_and_ps( value, clearLow ), _mm_castsi128_ps( index ) ); -} - -// Recovers the index embedded by b3EmbedIndexW4 from the lane holding the minimum. -static inline int b3MinIndexW4( b3FloatW4 a, int bitCount ) -{ - a = _mm_min_ps( a, _mm_shuffle_ps( a, a, _MM_SHUFFLE( 2, 3, 0, 1 ) ) ); - a = _mm_min_ps( a, _mm_shuffle_ps( a, a, _MM_SHUFFLE( 1, 0, 3, 2 ) ) ); - return _mm_cvtsi128_si32( _mm_castps_si128( a ) ) & ( ( 1 << bitCount ) - 1 ); -} - -B3_FORCE_INLINE void b3TransposeW4( b3FloatW4 r0, b3FloatW4 r1, b3FloatW4 r2, b3FloatW4 r3, b3FloatW4* c0, b3FloatW4* c1, - b3FloatW4* c2, b3FloatW4* c3 ) -{ - b3FloatW4 t0 = _mm_unpacklo_ps( r0, r2 ); - b3FloatW4 t1 = _mm_unpacklo_ps( r1, r3 ); - b3FloatW4 t2 = _mm_unpackhi_ps( r0, r2 ); - b3FloatW4 t3 = _mm_unpackhi_ps( r1, r3 ); - *c0 = _mm_unpacklo_ps( t0, t1 ); - *c1 = _mm_unpackhi_ps( t0, t1 ); - *c2 = _mm_unpacklo_ps( t2, t3 ); - *c3 = _mm_unpackhi_ps( t2, t3 ); -} - -// The following are SIMD definitions for operations where a wide register is -// used to store a single 3D vector, rather than SOA data for proper "wide" SIMD. -// For such uses, there's no benefit to using AVX2 8-wide registers; we're only using 3 lanes. -// For that reason, we unconditionally use SSE, even if AVX2 is available. - -// wide float holds 4 numbers -typedef __m128 b3V32; - -typedef union b3128 -{ - b3V32 v; - float f[4]; -} b3128; - -#if defined( _MSC_VER ) && !defined( __clang__ ) - -static const b3V32 b3_zeroV = { { 0.0f, 0.0f, 0.0f, 0.0f } }; -static const b3V32 b3_halfV = { { 0.5f, 0.5f, 0.5f, 0.5f } }; -static const b3V32 b3_oneV = { { 1.0f, 1.0f, 1.0f, 1.0f } }; - -#else - -static const b3V32 b3_zeroV = { 0.0f, 0.0f, 0.0f, 0.0f }; -static const b3V32 b3_halfV = { 0.5f, 0.5f, 0.5f, 0.5f }; -static const b3V32 b3_oneV = { 1.0f, 1.0f, 1.0f, 1.0f }; - -#endif - -static inline b3V32 b3AddV( b3V32 a, b3V32 b ) -{ - return _mm_add_ps( a, b ); -} - -static inline b3V32 b3SubV( b3V32 a, b3V32 b ) -{ - return _mm_sub_ps( a, b ); -} - -static inline b3V32 b3MulV( b3V32 a, b3V32 b ) -{ - return _mm_mul_ps( a, b ); -} - -static inline b3V32 b3DivV( b3V32 a, b3V32 b ) -{ - return _mm_div_ps( a, b ); -} - -static inline b3V32 b3NegV( b3V32 a ) -{ - return _mm_sub_ps( _mm_setzero_ps(), a ); -} - -static inline b3V32 b3LoadV( const float* src ) -{ - // Loads exactly 12 bytes: 8 via movsd, 4 via movss. - // Result lane 3 is implicitly zero from the partial loads. - __m128 xy = _mm_castpd_ps( _mm_load_sd( (const double*)( src ) ) ); - __m128 z = _mm_load_ss( src + 2 ); - return _mm_movelh_ps( xy, z ); // { src[0], src[1], src[2], 0.0f } -} - -static inline b3V32 b3ZeroV( void ) -{ - return _mm_setzero_ps(); -} - -static inline float b3GetXV( b3V32 a ) -{ - return _mm_cvtss_f32( a ); -} - -static inline float b3GetYV( b3V32 a ) -{ - return _mm_cvtss_f32( _mm_shuffle_ps( a, a, _MM_SHUFFLE( 1, 1, 1, 1 ) ) ); -} - -static inline float b3GetZV( b3V32 a ) -{ - return _mm_cvtss_f32( _mm_shuffle_ps( a, a, _MM_SHUFFLE( 2, 2, 2, 2 ) ) ); -} - -static inline float b3GetV( b3V32 a, int index ) -{ - b3128 b; - b.v = a; - return b.f[index]; -} - -static inline b3V32 b3SplatV( float x ) -{ - return _mm_set_ps1( x ); -} - -static inline b3V32 b3AbsV( b3V32 a ) -{ - // Abs( V ) = Max( -V, V ) - b3V32 zero = _mm_setzero_ps(); - return _mm_max_ps( _mm_sub_ps( zero, a ), a ); -} - -static inline b3V32 b3MinV( b3V32 a, b3V32 b ) -{ - return _mm_min_ps( a, b ); -} - -static inline b3V32 b3MaxV( b3V32 a, b3V32 b ) -{ - return _mm_max_ps( a, b ); -} - -static inline b3V32 b3CrossV( b3V32 a, b3V32 b ) -{ - b3V32 yzX1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 0, 2, 1 ) ); - b3V32 zxY1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 1, 0, 2 ) ); - b3V32 yzX2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 0, 2, 1 ) ); - b3V32 zxY2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 1, 0, 2 ) ); - - return _mm_sub_ps( _mm_mul_ps( yzX1, zxY2 ), _mm_mul_ps( zxY1, yzX2 ) ); -} - -static inline b3V32 b3ModifiedCrossV( b3V32 a, b3V32 b ) -{ - b3V32 yzX1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 0, 2, 1 ) ); - b3V32 zxY1 = _mm_shuffle_ps( a, a, _MM_SHUFFLE( 3, 1, 0, 2 ) ); - b3V32 yzX2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 0, 2, 1 ) ); - b3V32 zxY2 = _mm_shuffle_ps( b, b, _MM_SHUFFLE( 3, 1, 0, 2 ) ); - - return _mm_add_ps( _mm_mul_ps( yzX1, zxY2 ), _mm_mul_ps( zxY1, yzX2 ) ); -} - -static inline bool b3AnyLess3V( b3V32 a, b3V32 b ) -{ - b3V32 v = _mm_cmplt_ps( a, b ); - return ( _mm_movemask_ps( v ) & 0x07 ) != 0; -} - -static inline bool b3AnyLessEq3V( b3V32 a, b3V32 b ) -{ - b3V32 v = _mm_cmple_ps( a, b ); - return ( _mm_movemask_ps( v ) & 0x07 ) != 0; -} - -static inline bool b3AnyGreater3V( b3V32 a, b3V32 b ) -{ - b3V32 v = _mm_cmpgt_ps( a, b ); - return ( _mm_movemask_ps( v ) & 0x07 ) != 0; -} - -static inline bool b3AllLessEq3V( b3V32 a, b3V32 b ) -{ - b3V32 v = _mm_cmple_ps( a, b ); - return ( _mm_movemask_ps( v ) & 0x07 ) == 0x07; -} - -typedef struct b3AABBV -{ - __m128 lower; - __m128 upper; -} b3AABBV; - -B3_FORCE_INLINE b3AABBV b3LoadAABBV( const b3AABB* aabb ) -{ - const float* base = &aabb->lowerBound.x; - // Same offset as Neon to avoid UB. - __m128 v1 = _mm_loadu_ps( base + 2 ); - b3AABBV result; - result.lower = _mm_loadu_ps( base ); - result.upper = _mm_shuffle_ps( v1, v1, _MM_SHUFFLE( 3, 3, 2, 1 ) ); - return result; -} - -B3_FORCE_INLINE bool b3OverlapAABBV( b3AABBV a, b3AABBV b ) -{ - __m128 test = _mm_and_ps( _mm_cmple_ps( a.lower, b.upper ), _mm_cmple_ps( b.lower, a.upper ) ); - return ( _mm_movemask_ps( test ) & 0x7 ) == 0x7; -} - -B3_FORCE_INLINE bool b3OverlapNode( b3AABBV av, const b3TreeNode* node ) -{ - return b3OverlapAABBV( av, b3LoadAABBV( &node->aabb ) ); -} - -B3_FORCE_INLINE bool b3OverlapV( const b3AABB* a, const b3AABB* b ) -{ - return b3OverlapAABBV( b3LoadAABBV( a ), b3LoadAABBV( b ) ); -} - -B3_FORCE_INLINE b3AABBV b3UnionAABBV( b3AABBV a, b3AABBV b ) -{ - b3AABBV result; - result.lower = _mm_min_ps( a.lower, b.lower ); - result.upper = _mm_max_ps( a.upper, b.upper ); - return result; -} - -B3_FORCE_INLINE b3AABBV b3UnionPairV( const b3TreeNode* pair ) -{ - return b3UnionAABBV( b3LoadAABBV( &pair[0].aabb ), b3LoadAABBV( &pair[1].aabb ) ); -} - -// Conditionally store an AABB. Avoids a branch. -B3_FORCE_INLINE void b3StoreAABBV( b3AABB* aabb, b3AABBV value, bool condition ) -{ - __m128 lane3 = _mm_castsi128_ps( _mm_set_epi32( -1, 0, 0, 0 ) ); - __m128 uxSplat = _mm_shuffle_ps( value.upper, value.upper, _MM_SHUFFLE( 0, 0, 0, 0 ) ); - __m128 raw0 = _mm_or_ps( _mm_andnot_ps( lane3, value.lower ), _mm_and_ps( lane3, uxSplat ) ); - __m128 raw1 = _mm_shuffle_ps( raw0, value.upper, _MM_SHUFFLE( 2, 1, 3, 2 ) ); - - float* base = &aabb->lowerBound.x; - __m128 mask = _mm_castsi128_ps( _mm_set1_epi32( condition ? -1 : 0 ) ); - __m128 old0 = _mm_loadu_ps( base ); - __m128 old1 = _mm_loadu_ps( base + 2 ); - _mm_storeu_ps( base, _mm_or_ps( _mm_and_ps( mask, raw0 ), _mm_andnot_ps( mask, old0 ) ) ); - _mm_storeu_ps( base + 2, _mm_or_ps( _mm_and_ps( mask, raw1 ), _mm_andnot_ps( mask, old1 ) ) ); -} diff --git a/src/simd_wide.h b/src/simd_wide.h deleted file mode 100644 index f7c8879..0000000 --- a/src/simd_wide.h +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#pragma once - -#include "simd.h" - -// Macros to avoid name clashes between W4 and W8 functions existing in the same code base. -// At the same time this helps to avoid code duplication. - -// Help Intellisense from being confused. -#if defined( __INTELLISENSE__ ) && !defined( B3_SIMD_WIDTH ) -#define B3_SIMD_WIDTH 8 -#endif - -#if B3_SIMD_WIDTH == 8 -#define B3_WIDE( name ) name##W8 -#elif B3_SIMD_WIDTH == 4 -#define B3_WIDE( name ) name##W4 -#else -#error "B3_SIMD_WIDTH must be 4 or 8" -#endif - -#define B3_WIDE_ALIGNMENT ( 4 * B3_SIMD_WIDTH ) - -typedef B3_WIDE( b3Float ) b3FloatW; -typedef B3_WIDE( b3Vec3 ) b3Vec3W; - -#define b3ZeroW B3_WIDE( b3Zero ) -#define b3SplatW B3_WIDE( b3Splat ) -#define b3SetW B3_WIDE( b3Set ) -#define b3LoadW B3_WIDE( b3Load ) -#define b3StoreW B3_WIDE( b3Store ) -#define b3NegW B3_WIDE( b3Neg ) -#define b3AbsW B3_WIDE( b3Abs ) -#define b3AddW B3_WIDE( b3Add ) -#define b3SubW B3_WIDE( b3Sub ) -#define b3MulW B3_WIDE( b3Mul ) -#define b3DivW B3_WIDE( b3Div ) -#define b3SqrtW B3_WIDE( b3Sqrt ) -#define b3MulAddW B3_WIDE( b3MulAdd ) -#define b3MinW B3_WIDE( b3Min ) -#define b3MaxW B3_WIDE( b3Max ) -#define b3AndW B3_WIDE( b3And ) -#define b3OrW B3_WIDE( b3Or ) -#define b3AndNotW B3_WIDE( b3AndNot ) -#define b3SoftMaskW B3_WIDE( b3SoftMask ) -#define b3GreaterThanW B3_WIDE( b3GreaterThan ) -#define b3LessThanW B3_WIDE( b3LessThan ) -#define b3EqualsW B3_WIDE( b3Equals ) -#define b3AllZeroW B3_WIDE( b3AllZero ) -#define b3AnyTrueW B3_WIDE( b3AnyTrue ) -#define b3BlendW B3_WIDE( b3Blend ) -#define b3EmbedIndexW B3_WIDE( b3EmbedIndex ) -#define b3MinIndexW B3_WIDE( b3MinIndex ) -#define b3TransposeW B3_WIDE( b3Transpose ) -#define b3LoadVW B3_WIDE( b3LoadV ) -#define b3StoreVW B3_WIDE( b3StoreV ) -#define b3SplatVW B3_WIDE( b3SplatV ) -#define b3NegVW B3_WIDE( b3NegV ) -#define b3MulSVW B3_WIDE( b3MulSV ) -#define b3MulSubSVW B3_WIDE( b3MulSubSV ) -#define b3MulAddSVW B3_WIDE( b3MulAddSV ) -#define b3SubVW B3_WIDE( b3SubV ) -#define b3AddVW B3_WIDE( b3AddV ) -#define b3DotW B3_WIDE( b3Dot ) -#define b3CrossW B3_WIDE( b3Cross ) diff --git a/src/solver.c b/src/solver.c index 46212a4..5e208b6 100644 --- a/src/solver.c +++ b/src/solver.c @@ -3,7 +3,6 @@ #include "solver.h" -#include "aabb.h" #include "arena_allocator.h" #include "bitset.h" #include "body.h" @@ -29,6 +28,10 @@ #define ITERATIONS 1 #define RELAX_ITERATIONS 1 +// stepNormalImpulse (contact_solver.c) sums the impulse applied after each relax pass; it is the step +// impulse only with one relax pass per sub-step +_Static_assert( RELAX_ITERATIONS == 1, "stepNormalImpulse is exact only with one relax iteration" ); + #if ( defined( __GNUC__ ) || defined( __clang__ ) ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) static void b3Pause( void ) { @@ -55,12 +58,19 @@ static void b3Pause( void ) } #endif +typedef struct b3WorkerContext +{ + b3StepContext* context; + int workerIndex; + void* userTask; +} b3WorkerContext; + // Integrate velocities, apply damping, and gyroscopic torque static void b3IntegrateVelocitiesTask( b3SolverBlock block, b3StepContext* context ) { b3TracyCZoneNC( integrate_velocity, "IntVel", b3_colorDeepPink, true ); - B3_VALIDATE( block.startIndex + block.count <= b3GetSolverSet( context->world, b3_awakeSet )->bodyStates.count ); + B3_VALIDATE( block.startIndex + block.count <= context->world->solverSets.data[b3_awakeSet].bodyStates.count ); b3BodyState* states = context->states; b3BodySim* sims = context->sims; @@ -99,46 +109,46 @@ static void b3IntegrateVelocitiesTask( b3SolverBlock block, b3StepContext* conte // I * (w2 - w1) + h * cross(w2, I * w2) = 0 // This is all done in local coordinates where the Jacobian is easier to compute. // This improves the simulation of long skinny bodies. - // If the principal inertia values of I are roughly equal (isotropic) then - // cross(w2, I * w2) ~= 0, so this can be skipped. - if ( sim->flags & b3_enableGyroscopicTorque ) { // Get current rotation. b3Quat q0 = sim->transform.q; b3Quat q = b3MulQuat( state->deltaRotation, q0 ); + // todo wasteful computation + b3Matrix3 inertiaLocal = b3InvertMatrix( sim->invInertiaLocal ); + // Compute local angular velocity b3Vec3 omega1 = b3InvRotateVector( q, w ); b3Vec3 omega2 = omega1; // Symmetric inertia tensor: 6 unique entries (column-major) - float i00 = sim->inertia.cx.x; - float i01 = sim->inertia.cy.x; - float i02 = sim->inertia.cz.x; - float i11 = sim->inertia.cy.y; - float i12 = sim->inertia.cz.y; - float i22 = sim->inertia.cz.z; + const float i00 = inertiaLocal.cx.x; + const float i01 = inertiaLocal.cy.x; + const float i02 = inertiaLocal.cz.x; + const float i11 = inertiaLocal.cy.y; + const float i12 = inertiaLocal.cz.y; + const float i22 = inertiaLocal.cz.z; - for ( int gyroIteration = 0; gyroIteration < B3_GYROSCOPIC_ITERATIONS; ++gyroIteration ) + for ( int gyroIteration = 0; gyroIteration < 1; ++gyroIteration ) { - float w1 = omega2.x; - float w2 = omega2.y; - float w3 = omega2.z; + const float w1 = omega2.x; + const float w2 = omega2.y; + const float w3 = omega2.z; // Iw = I * omega2 (shared between residual and Jacobian) - float Iw1 = i00 * w1 + i01 * w2 + i02 * w3; - float Iw2 = i01 * w1 + i11 * w2 + i12 * w3; - float Iw3 = i02 * w1 + i12 * w2 + i22 * w3; + const float Iw1 = i00 * w1 + i01 * w2 + i02 * w3; + const float Iw2 = i01 * w1 + i11 * w2 + i12 * w3; + const float Iw3 = i02 * w1 + i12 * w2 + i22 * w3; - // Residual: b = I * (omega2 - omega1) + h * cross(omega2, I * omega2) - b3Vec3 dw = b3Sub( omega2, omega1 ); + // Residual: b = I*(omega2 - omega1) + h * (omega2 × I*omega2) + const b3Vec3 dw = b3Sub( omega2, omega1 ); b3Vec3 b = { i00 * dw.x + i01 * dw.y + i02 * dw.z + h * ( w2 * Iw3 - w3 * Iw2 ), i01 * dw.x + i11 * dw.y + i12 * dw.z + h * ( w3 * Iw1 - w1 * Iw3 ), i02 * dw.x + i12 * dw.y + i22 * dw.z + h * ( w1 * Iw2 - w2 * Iw1 ), }; - // Jacobian J = I + h * (skew(omega2) * I - skew(I * omega2)) + // Jacobian J = I + h * (skew(omega2) * I - skew(I*omega2)) // Jacobian derived by Erin Catto, Ph.D. Do not attempt to do this without a Ph.D. // Doubled inertia terms above fold into Iw, e.g. row 2 col 1: i00*w3 - i02*w1 - Iw3. b3Matrix3 J = { @@ -167,7 +177,7 @@ static void b3IntegratePositionsTask( b3SolverBlock block, b3StepContext* contex { b3TracyCZoneNC( integrate_positions, "IntPos", b3_colorDarkSeaGreen, true ); - B3_VALIDATE( block.startIndex + block.count <= b3GetSolverSet( context->world, b3_awakeSet )->bodyStates.count ); + B3_VALIDATE( block.startIndex + block.count <= context->world->solverSets.data[b3_awakeSet].bodyStates.count ); b3BodyState* states = context->states; float h = context->h; @@ -320,6 +330,8 @@ typedef struct b3ContinuousContext float sensorFractions[B2_MAX_CONTINUOUS_SENSOR_HITS]; int sensorCount; + int visitCount; + int distanceIterations; int pushBackIterations; int rootIterations; @@ -332,6 +344,7 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con int shapeId = (int)userData; b3ContinuousContext* continuousContext = context; + continuousContext->visitCount += 1; b3Shape* fastShape = continuousContext->fastShape; b3BodySim* fastBodySim = continuousContext->fastBodySim; @@ -353,9 +366,9 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con return true; } - // Skip sensors unless both shapes want sensor events + // Skip sensors unless the shapes want sensor events bool isSensor = shape->sensorIndex != B3_NULL_INDEX; - if ( isSensor && ( ( shape->flags & b3_enableSensorEvents ) == 0 || ( fastShape->flags & b3_enableSensorEvents ) == 0 ) ) + if ( isSensor && ( shape->enableSensorEvents == false || fastShape->enableSensorEvents == false ) ) { return true; } @@ -373,7 +386,7 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con B3_ASSERT( body->type == b3_staticBody || ( fastBodySim->flags & b3_isBullet ) ); // Skip bullets - if ( body->flags & b3_isBullet ) + if ( bodySim->flags & b3_isBullet ) { return true; } @@ -387,7 +400,7 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con } // Custom user filtering - if ( ( shape->flags & b3_enableCustomFiltering ) != 0 || ( fastShape->flags & b3_enableCustomFiltering ) != 0 ) + if ( shape->enableCustomFiltering || fastShape->enableCustomFiltering ) { b3CustomFilterFcn* customFilterFcn = world->customFilterFcn; if ( customFilterFcn != NULL ) @@ -402,6 +415,8 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con } } + uint64_t ticks = b3GetTicks(); + // todo does having a sweep on shapeA help with bullets? b3Sweep sweepA = b3MakeRelativeSweep( bodySim, continuousContext->base ); @@ -429,7 +444,7 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con { bool didHit = true; - if ( didHit && ( ( shape->flags & b3_enablePreSolveEvents ) || ( fastShape->flags & b3_enablePreSolveEvents ) ) ) + if ( didHit && ( shape->enablePreSolveEvents || fastShape->enablePreSolveEvents ) ) { b3ShapeId shapeIdA = { shape->id + 1, world->worldId, shape->generation }; b3ShapeId shapeIdB = { fastShape->id + 1, world->worldId, fastShape->generation }; @@ -439,6 +454,7 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con if ( didHit ) { + fastBodySim->flags |= b3_hadTimeOfImpact; continuousContext->fraction = output.fraction; continuousContext->distanceIterations = b3MaxInt( continuousContext->distanceIterations, output.distanceIterations ); continuousContext->pushBackIterations = b3MaxInt( continuousContext->pushBackIterations, output.pushBackIterations ); @@ -446,47 +462,26 @@ static bool b3ContinuousQueryCallback( int proxyId, uint64_t userData, void* con } } + float ms = b3GetMilliseconds( ticks ); + if ( ms > 1000.0f * b3GetStallThreshold() ) + { + b3Log( "CCD stall: duration %.1f ms for %s versus %s", ms, fastBody->name, body->name ); + } + // Continue query return true; } -static bool b3IsShapeFast( const b3Shape* shape, b3Vec3 centroid1, b3Vec3 centroid2, float rotationChord, float safetyFactor ) -{ - float radius; - switch ( shape->type ) - { - case b3_sphereShape: - radius = shape->sphere.radius; - break; - - case b3_capsuleShape: - radius = 0.5f * b3Distance( shape->capsule.center1, shape->capsule.center2 ) + shape->capsule.radius; - break; - - case b3_hullShape: - { - b3Vec3 farthestPoint = b3FarthestPointOnAABB( shape->hull->aabb, shape->localCentroid ); - radius = b3Distance( farthestPoint, shape->localCentroid ); - } - break; - - default: - return true; - } - - float minExtent = b3ComputeShapeMinExtent( shape, shape->localCentroid ); - float maxMotion = b3Distance( centroid1, centroid2 ) + rotationChord * radius; - return maxMotion > safetyFactor * minExtent; -} - // Continuous collision of dynamic versus static -static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* taskContext, float dt ) +static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* taskContext ) { b3TracyCZoneNC( ccd, "CCD", b3_colorDarkGoldenRod, true ); - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); + uint64_t ticks = b3GetTicks(); + + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); b3BodySim* fastBodySim = b3Array_Get( awakeSet->bodySims, bodySimIndex ); - B3_VALIDATE( fastBodySim->flags & b3_isFast ); + B3_ASSERT( fastBodySim->flags & b3_isFast ); // Re-center the sweep on the fast body so the TOI and the swept query stay in float precision b3Pos base = fastBodySim->center0; @@ -514,8 +509,6 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* context.fraction = 1.0f; bool isBullet = ( fastBodySim->flags & b3_isBullet ) != 0; - float safetyFactor = fastBody->safetyFactor; - float rotationChord = 2.0f * b3Length( b3InvMulQuat( sweep.q1, sweep.q2 ).v ); int shapeId = fastBody->headShapeId; while ( shapeId != B3_NULL_INDEX ) @@ -546,15 +539,6 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* continue; } - if ( isBullet == false ) - { - bool isShapeFast = b3IsShapeFast( fastShape, context.centroid1, context.centroid2, rotationChord, safetyFactor ); - if ( isShapeFast == false ) - { - continue; - } - } - b3AABB sweptBox = b3AABB_Union( box1, box2 ); b3DynamicTree_Query( staticTree, sweptBox, B3_DEFAULT_MASK_BITS, false, b3ContinuousQueryCallback, &context ); @@ -582,21 +566,6 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* fastBodySim->center = center; fastBodySim->rotation0 = q; fastBodySim->center0 = center; - fastBodySim->flags |= b3_hadTimeOfImpact; - - // Timeloss means there is a lost gravity contribution. Other forces and torques are ignored for now. - b3BodyState* fastBodyState = b3Array_Get( awakeSet->bodyStates, bodySimIndex ); - b3Vec3 v = fastBodyState->linearVelocity; - float timeLoss = ( 1.0f - context.fraction ) * dt; - b3Vec3 dv = b3MulSV( -timeLoss * fastBodySim->gravityScale, world->gravity ); - dv.x = ( fastBodyState->flags & b3_lockLinearX ) ? 0.0f : dv.x; - dv.y = ( fastBodyState->flags & b3_lockLinearY ) ? 0.0f : dv.y; - dv.z = ( fastBodyState->flags & b3_lockLinearZ ) ? 0.0f : dv.z; - fastBodyState->linearVelocity = b3Add( v, dv ); - - // The move event was written before CCD, so correct it with the impact pose - b3BodyMoveEvent* event = b3Array_Get( world->bodyMoveEvents, bodySimIndex ); - event->transform = fastBodySim->transform; // Prepare AABBs for broad-phase. // Even though a body is fast, it may not move much. So the AABB may not need enlargement. @@ -610,21 +579,14 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* b3AABB aabb = b3ComputeFatShapeAABB( shape, transform, speculativeScalar ); shape->aabb = aabb; - b3AABB* shapeFatAABB = world->fatAABBs.data + shapeId; - if ( b3AABB_Contains( *shapeFatAABB, aabb ) == false ) + if ( b3AABB_Contains( shape->fatAABB, aabb ) == false ) { - *shapeFatAABB = b3AABB_Inflate( aabb, shape->aabbMargin ); + float marginScalar = shape->aabbMargin; + b3Vec3 aabbMargin = { marginScalar, marginScalar, marginScalar }; + shape->fatAABB = (b3AABB){ b3Sub( aabb.lowerBound, aabbMargin ), b3Add( aabb.upperBound, aabbMargin ) }; - // Regular bodies mark the hierarchy as moved using atomic operations. - // Bullets are handled separately at a later stage. - if ( isBullet == false ) - { - b3BroadPhase_MarkProxyMoved( &world->broadPhase, shape->proxyKey, *shapeFatAABB ); - } - else - { - fastBodySim->flags |= b3_enlargeBulletBounds; - } + shape->enlargedAABB = true; + fastBodySim->flags |= b3_enlargeBounds; } shapeId = shape->nextShapeId; @@ -646,19 +608,17 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* // shape->aabb is still valid from above - b3AABB* shapeFatAABB = world->fatAABBs.data + shapeId; - if ( b3AABB_Contains( *shapeFatAABB, shape->aabb ) == false ) + if ( b3AABB_Contains( shape->fatAABB, shape->aabb ) == false ) { - *shapeFatAABB = b3AABB_Inflate( shape->aabb, shape->aabbMargin ); + float marginScalar = shape->aabbMargin; + b3Vec3 aabbMargin = { marginScalar, marginScalar, marginScalar }; + shape->fatAABB = (b3AABB){ + .lowerBound = b3Sub( shape->aabb.lowerBound, aabbMargin ), + .upperBound = b3Add( shape->aabb.upperBound, aabbMargin ), + }; - if ( isBullet == false ) - { - b3BroadPhase_MarkProxyMoved( &world->broadPhase, shape->proxyKey, *shapeFatAABB ); - } - else - { - fastBodySim->flags |= b3_enlargeBulletBounds; - } + shape->enlargedAABB = true; + fastBodySim->flags |= b3_enlargeBounds; } shapeId = shape->nextShapeId; @@ -679,6 +639,16 @@ static void b3SolveContinuous( b3World* world, int bodySimIndex, b3TaskContext* taskContext->pushBackIterations = b3MaxInt( taskContext->pushBackIterations, context.pushBackIterations ); taskContext->rootIterations = b3MaxInt( taskContext->rootIterations, context.rootIterations ); + float ms = b3GetMilliseconds( ticks ); + if ( ms > 1000.0f * b3GetStallThreshold() ) + { + b3Vec3 c1 = sweep.c1; + b3Vec3 c2 = sweep.c2; + int vc = context.visitCount; + b3Log( "CCD stall: duration %.1f ms and visit count %d for %s: c1 = (%g, %g, %g), c2 = (%g, %g, %g)", ms, vc, + fastBody->name, c1.x, c1.y, c1.z, c2.x, c2.y, c2.z ); + } + b3TracyCZoneEnd( ccd ); } @@ -705,6 +675,7 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, b3BodyMoveEvent* moveEvents = world->bodyMoveEvents.data; b3TaskContext* taskContext = world->taskContexts.data + workerIndex; + b3BitSet* enlargedSimBitSet = &taskContext->enlargedSimBitSet; b3BitSet* awakeIslandBitSet = &taskContext->awakeIslandBitSet; const float speculativeScalar = B3_SPECULATIVE_DISTANCE; @@ -721,8 +692,7 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, if ( b3IsValidVec3( v ) == false || b3IsValidVec3( w ) == false ) { - const char* name = b3FindNameWithDefault( &world->names, bodies[sim->bodyId].nameId, "NULL" ); - b3Log( "unstable: %s", name ); + b3Log( "unstable: %s", bodies[sim->bodyId].name ); } B3_ASSERT( b3IsValidVec3( v ) ); @@ -754,8 +724,6 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, // cache miss here, however I need the shape list below b3Body* body = bodies + sim->bodyId; body->bodyMoveIndex = simIndex; - body->sleepVelocity = sleepVelocity; - moveEvents[simIndex].userData = body->userData; moveEvents[simIndex].transform = sim->transform; moveEvents[simIndex].bodyId = (b3BodyId){ sim->bodyId + 1, worldId, body->generation }; @@ -765,17 +733,10 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, sim->force = b3Vec3_zero; sim->torque = b3Vec3_zero; - // If you hit this then it means you deferred mass computation but never called b3Body_ApplyMassFromShapes - // or b3Body_SetMassData. - B3_ASSERT( ( body->flags & b3_dirtyMass ) == 0 ); - - // Clear the transient flags (fast, speed capped, had TOI). These flags are conditionally set - // as part of the code below. body->flags &= ~b3_bodyTransientFlags; - sim->flags &= ~( b3_isFast | b3_bodyTransientFlags ); - - // The body state flag knows about speed capping (used for debug draw). - body->flags |= ( state->flags & b3_isSpeedCapped ); + body->flags |= ( sim->flags & ( b3_isSpeedCapped | b3_hadTimeOfImpact ) ); + body->flags |= ( state->flags & ( b3_isSpeedCapped | b3_hadTimeOfImpact ) ); + sim->flags &= ~b3_bodyTransientFlags; state->flags &= ~b3_bodyTransientFlags; if ( enableSleep == false || ( body->flags & b3_enableSleep ) == 0 || sleepVelocity > body->sleepThreshold ) @@ -783,11 +744,11 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, // Body is not sleepy body->sleepTime = 0.0f; - float safetyFactor = body->safetyFactor; + const float safetyFactor = 0.5f; float maxMotion = b3MaxFloat( maxDeltaPosition, maxVelocity * timeStep ); if ( body->type == b3_dynamicBody && enableContinuous && maxMotion > safetyFactor * sim->minExtent ) { - // This flag is used for debug draw and contact recycling. + // This flag is only retained for debug draw sim->flags |= b3_isFast; // Store in fast array for the continuous collision stage @@ -799,7 +760,7 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, } else { - b3SolveContinuous( world, simIndex, taskContext, timeStep ); + b3SolveContinuous( world, simIndex, taskContext ); } } else @@ -844,30 +805,42 @@ static void b3FinalizeBodiesTask( int startIndex, int endIndex, int workerIndex, } // Update shapes AABBs - // For fast non-bullet bodies the AABB has already been updated in b3SolveContinuous - // For fast bullet bodies the AABB will be updated at a later stage - if ( ( sim->flags & b3_isFast ) == 0 ) + b3WorldTransform transform = sim->transform; + bool isFast = ( sim->flags & b3_isFast ) != 0; + int shapeId = body->headShapeId; + while ( shapeId != B3_NULL_INDEX ) { - b3WorldTransform transform = sim->transform; - int shapeId = body->headShapeId; - while ( shapeId != B3_NULL_INDEX ) - { - b3Shape* shape = b3Array_Get( world->shapes, shapeId ); + b3Shape* shape = b3Array_Get( world->shapes, shapeId ); + if ( isFast ) + { + // For fast non-bullet bodies the AABB has already been updated in b3SolveContinuous + // For fast bullet bodies the AABB will be updated at a later stage + + // Add to enlarged shapes regardless of AABB changes. + // Bit-set to keep the move array sorted + b3SetBit( enlargedSimBitSet, simIndex ); + } + else + { b3AABB aabb = b3ComputeFatShapeAABB( shape, transform, speculativeScalar ); shape->aabb = aabb; - b3AABB* shapeFatAABB = world->fatAABBs.data + shapeId; - if ( b3AABB_Contains( *shapeFatAABB, aabb ) == false ) + B3_ASSERT( shape->enlargedAABB == false ); + + if ( b3AABB_Contains( shape->fatAABB, aabb ) == false ) { - *shapeFatAABB = b3AABB_Inflate( aabb, shape->aabbMargin ); + float marginScalar = shape->aabbMargin; + b3Vec3 aabbMargin = { marginScalar, marginScalar, marginScalar }; + shape->fatAABB = (b3AABB){ b3Sub( aabb.lowerBound, aabbMargin ), b3Add( aabb.upperBound, aabbMargin ) }; + shape->enlargedAABB = true; - // Mark the hierarchy as moved using atomic operations. - b3BroadPhase_MarkProxyMoved( &world->broadPhase, shape->proxyKey, *shapeFatAABB ); + // Bit-set to keep the move array sorted + b3SetBit( enlargedSimBitSet, simIndex ); } - - shapeId = shape->nextShapeId; } + + shapeId = shape->nextShapeId; } } @@ -993,7 +966,7 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv break; case b3_stagePrepareContacts: - b3PrepareContacts_MeshWide( block, context ); + b3PrepareContacts_Mesh( block, context ); break; case b3_stageIntegrateVelocities: @@ -1011,7 +984,7 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv } else { - b3WarmStartContacts_MeshWide( block, context ); + b3WarmStartContacts_Mesh( block, context ); } break; @@ -1023,11 +996,13 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv } else if ( blockType == b3_graphWideContactBlock ) { - b3PushContacts_Convex( block, context ); + bool useBias = true; + b3SolveContacts_Convex( block, context, useBias ); } else { - b3PushContacts_MeshWide( block, context ); + bool useBias = true; + b3SolveContacts_Mesh( block, context, useBias ); } break; @@ -1043,11 +1018,13 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv } else if ( blockType == b3_graphWideContactBlock ) { - b3SolveContacts_Convex( block, context ); + bool useBias = false; + b3SolveContacts_Convex( block, context, useBias ); } else { - b3SolveContacts_MeshWide( block, context ); + bool useBias = false; + b3SolveContacts_Mesh( block, context, useBias ); } break; @@ -1058,7 +1035,7 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv } else if ( blockType == b3_graphContactBlock ) { - b3ApplyRestitution_MeshWide( block, context ); + b3ApplyRestitution_Mesh( block, context ); } break; @@ -1067,7 +1044,7 @@ static void b3ExecuteBlock( b3SolverStage* stage, b3StepContext* context, b3Solv break; case b3_stageStoreImpulses: - b3StoreImpulses_MeshWide( block, context, workerIndex ); + b3StoreImpulses_Mesh( block, context, workerIndex ); break; } } @@ -1096,12 +1073,7 @@ static void b3ExecuteStage( b3SolverStage* stage, b3StepContext* context, int pr int startIndex = GetWorkerStartIndex( workerIndex, blockCount, context->workerCount ); if ( startIndex == B3_NULL_INDEX ) { - if ( workerIndex != context->orchestratorIndex ) - { - return; - } - - startIndex = 0; + return; } B3_ASSERT( 0 <= startIndex && startIndex < blockCount ); @@ -1129,7 +1101,7 @@ static void b3ExecuteStage( b3SolverStage* stage, b3StepContext* context, int pr (void)b3AtomicFetchAddInt( &stage->completionCount, completedCount ); } -// Execute a stage on the orchestrator, whichever solver task claimed that role. +// Execute a stage on worker 0 (main thread). static void b3ExecuteMainStage( b3SolverStage* stage, b3StepContext* context, uint32_t syncBits ) { int blockCount = stage->blockCount; @@ -1138,7 +1110,7 @@ static void b3ExecuteMainStage( b3SolverStage* stage, b3StepContext* context, ui return; } - int workerIndex = context->orchestratorIndex; + const int workerIndex = 0; if ( blockCount == 1 ) { @@ -1174,11 +1146,19 @@ static void b3SolverTask( void* taskContext ) b3SolverStage* stages = context->stages; b3Profile* profile = &context->world->profile; - if ( b3AtomicCompareExchangeInt( &context->orchestratorClaimed, 0, 1 ) ) + if ( workerIndex == 0 ) { - context->orchestratorIndex = workerIndex; + // The orchestrator slot is a race. The calling thread of b3World_Step also enters here + // as worker 0, so progress is guaranteed even if the user's task system schedules tasks + // out of order, has fewer threads than workerCount, or runs the task synchronously + // inside enqueueTaskFcn. Whoever wins the CAS becomes the orchestrator; the loser + // returns and lets the spinner-only path handle workers >0. + if ( b3AtomicCompareExchangeInt( &context->mainClaimed, 0, 1 ) == false ) + { + return; + } - // The orchestrator synchronizes the workers and does work itself. + // Main thread synchronizes the workers and does work itself. // // This needs to be a task for the main thread because the user's task system may execute // the tasks serially and this is the first task. This single task is able to fully @@ -1198,6 +1178,7 @@ static void b3SolverTask( void* taskContext ) b3_stageSolve, b3_stageIntegratePositions, b3_stageRelax, + b3_stageRestitution, b3_stageStoreImpulses */ @@ -1274,7 +1255,7 @@ static void b3SolverTask( void* taskContext ) { // Overflow constraints have lower priority. Typically these are dynamic-vs-dynamic. b3SolveJoints_Overflow( context, useBias ); - b3PushContacts_Overflow( context ); + b3SolveContacts_Overflow( context, useBias ); for ( int colorIndex = 0; colorIndex < activeColorCount; ++colorIndex ) { @@ -1302,7 +1283,7 @@ static void b3SolverTask( void* taskContext ) for ( int j = 0; j < RELAX_ITERATIONS; ++j ) { b3SolveJoints_Overflow( context, useBias ); - b3SolveContacts_Overflow( context ); + b3SolveContacts_Overflow( context, useBias ); for ( int colorIndex = 0; colorIndex < activeColorCount; ++colorIndex ) { @@ -1321,28 +1302,23 @@ static void b3SolverTask( void* taskContext ) // integrate velocities / warm start / solve / integrate positions / relax stageIndex += 1 + activeColorCount + ITERATIONS * activeColorCount + 1 + RELAX_ITERATIONS * activeColorCount; - int restitutionIterations = context->world->restitutionIterations; - if ( restitutionIterations > 0 && b3AtomicLoadInt( &context->anyRestitution ) != 0 ) + // Restitution { - for ( int j = 0; j < restitutionIterations; ++j ) + b3ApplyRestitution_Overflow( context ); + + int iterStageIndex = stageIndex; + for ( int colorIndex = 0; colorIndex < activeColorCount; ++colorIndex ) { - b3ApplyRestitution_Overflow( context ); - - int iterationStageIndex = stageIndex; - for ( int colorIndex = 0; colorIndex < activeColorCount; ++colorIndex ) - { - syncBits = ( graphSyncIndex << 16 ) | iterationStageIndex; - B3_ASSERT( stages[iterationStageIndex].type == b3_stageRestitution ); - b3ExecuteMainStage( stages + iterationStageIndex, context, syncBits ); - iterationStageIndex += 1; - } - graphSyncIndex += 1; + syncBits = ( graphSyncIndex << 16 ) | iterStageIndex; + B3_ASSERT( stages[iterStageIndex].type == b3_stageRestitution ); + b3ExecuteMainStage( stages + iterStageIndex, context, syncBits ); + iterStageIndex += 1; } - - profile->restitution += b3GetMillisecondsAndReset( &ticks ); + // graphSyncIndex += 1; + stageIndex += activeColorCount; } - stageIndex += activeColorCount; + profile->applyRestitution += b3GetMillisecondsAndReset( &ticks ); // Store impulses b3StoreImpulses_Overflow( context ); @@ -1433,29 +1409,32 @@ static void b3BulletBodyTask( int startIndex, int endIndex, int workerIndex, voi for ( int i = startIndex; i < endIndex; ++i ) { int simIndex = stepContext->bulletBodies[i]; - b3SolveContinuous( stepContext->world, simIndex, taskContext, stepContext->dt ); + b3SolveContinuous( stepContext->world, simIndex, taskContext ); } b3TracyCZoneEnd( bullet_body_task ); } -// Solve with graph coloring -bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) -{ - int simdShift = world->simdWidth == 8 ? 3 : 2; +#if B3_SIMD_WIDTH == 4 +#define B3_SIMD_SHIFT 2 +#else +#define B3_SIMD_SHIFT 0 +#endif +// Solve with graph coloring +void b3Solve( b3World* world, b3StepContext* stepContext ) +{ // Only count steps that advance the simulation world->stepIndex += 1; - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); int awakeBodyCount = awakeSet->bodySims.count; if ( awakeBodyCount == 0 ) { - return false; + b3ValidateNoEnlarged( &world->broadPhase ); + return; } - stepContext->awakeBodyCount = awakeBodyCount; - // Solve constraints using graph coloring { b3TracyCZoneNC( solver_setup, "Solver Setup", b3_colorDarkOrange, true ); @@ -1463,7 +1442,7 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) // Prepare buffers for continuous collision (fast bodies) b3AtomicStoreInt( &stepContext->bulletBodyCount, 0 ); - stepContext->bulletBodies = b3StackAlloc( &world->stack, awakeBodyCount * sizeof( int ), "bullet bodies" ); + stepContext->bulletBodies = (int*)b3StackAlloc( &world->stack, awakeBodyCount * sizeof( int ), "bullet bodies" ); b3ConstraintGraph* graph = &world->constraintGraph; b3GraphColor* colors = graph->colors; @@ -1500,28 +1479,28 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) // The blocks are a mix of convex contact, mesh contact, and joint blocks int activeColorIndices[B3_GRAPH_COLOR_COUNT]; int colorWideContactCounts[B3_GRAPH_COLOR_COUNT]; - int colorMeshContactCounts[B3_GRAPH_COLOR_COUNT]; - int colorMeshGroupCounts[B3_GRAPH_COLOR_COUNT]; + int colorContactCounts[B3_GRAPH_COLOR_COUNT]; + // int colorManifoldCounts[B3_GRAPH_COLOR_COUNT]; int colorJointCounts[B3_GRAPH_COLOR_COUNT]; b3BlockDim graphWideContactDims[B3_GRAPH_COLOR_COUNT]; - b3BlockDim graphMeshContactDims[B3_GRAPH_COLOR_COUNT]; + b3BlockDim graphContactDims[B3_GRAPH_COLOR_COUNT]; b3BlockDim graphJointDims[B3_GRAPH_COLOR_COUNT]; int graphBlockCount = 0; // c is the active color index int wideContactCount = 0; - int meshContactCount = 0; - int meshGroupCount = 0; + int contactCount = 0; + int manifoldCount = 0; int jointCount = 0; int c = 0; for ( int i = 0; i < B3_GRAPH_COLOR_COUNT - 1; ++i ) { b3GraphColor* color = colors + i; int colorConvexContactCount = color->convexContacts.count; - int colorMeshContactCount = color->contacts.count; + int colorContactCount = color->contacts.count; int colorJointCount = color->jointSims.count; - if ( colorConvexContactCount + colorMeshContactCount + colorJointCount == 0 ) + if ( colorConvexContactCount + colorContactCount + colorJointCount == 0 ) { continue; } @@ -1529,25 +1508,29 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) activeColorIndices[c] = i; // Ceiling for wide constraint count - int colorWideConstraintCount = colorConvexContactCount > 0 ? ( ( colorConvexContactCount - 1 ) >> simdShift ) + 1 : 0; + int colorWideConstraintCount = + colorConvexContactCount > 0 ? ( ( colorConvexContactCount - 1 ) >> B3_SIMD_SHIFT ) + 1 : 0; wideContactCount += colorWideConstraintCount; colorWideContactCounts[c] = colorWideConstraintCount; - colorMeshContactCounts[c] = colorMeshContactCount; - meshContactCount += colorMeshContactCount; + colorContactCounts[c] = colorContactCount; + contactCount += colorContactCount; - int colorMeshGroupCount = colorMeshContactCount > 0 ? ( ( colorMeshContactCount - 1 ) >> simdShift ) + 1 : 0; - colorMeshGroupCounts[c] = colorMeshGroupCount; - meshGroupCount += colorMeshGroupCount; + // Compute manifold starts and accumulate manifold count + for ( int j = 0; j < colorContactCount; ++j ) + { + color->contacts.data[j].manifoldStart = manifoldCount; + manifoldCount += color->contacts.data[j].manifoldCount; + } colorJointCounts[c] = colorJointCount; jointCount += colorJointCount; // Solver block dimensions graphWideContactDims[c] = b3ComputeBlockCount( colorWideConstraintCount, minContactsPerBlock, maxBlockCount ); - graphMeshContactDims[c] = b3ComputeBlockCount( colorMeshGroupCount, minContactsPerBlock, maxBlockCount ); + graphContactDims[c] = b3ComputeBlockCount( colorContactCount, minContactsPerBlock, maxBlockCount ); graphJointDims[c] = b3ComputeBlockCount( colorJointCount, minJointsPerBlock, maxBlockCount ); - graphBlockCount += graphWideContactDims[c].count + graphMeshContactDims[c].count + graphJointDims[c].count; + graphBlockCount += graphWideContactDims[c].count + graphContactDims[c].count + graphJointDims[c].count; c += 1; } @@ -1557,94 +1540,16 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) // partitioned into uniformly sized blocks. Color info is consulted inside the task via // a small span array, so blocks do not need to honor color boundaries here. b3BlockDim convexPrepareDim = b3ComputeBlockCount( wideContactCount, minContactsPerBlock, maxBlockCount ); - b3BlockDim meshPrepareDim = b3ComputeBlockCount( meshGroupCount, minContactsPerBlock, maxBlockCount ); + b3BlockDim meshPrepareDim = b3ComputeBlockCount( contactCount, minContactsPerBlock, maxBlockCount ); b3BlockDim jointPrepareDim = b3ComputeBlockCount( jointCount, minJointsPerBlock, maxBlockCount ); - int wideContactByteCount = b3GetWideContactConstraintByteCount( world->simdWidth ); - void* wideConstraints = b3StackAlloc( &world->stack, wideContactCount * wideContactByteCount, "wide contacts" ); - - int* meshLaneOrder = b3StackAlloc( &world->stack, meshContactCount * sizeof( int ), "mesh lane order" ); - int* meshManifoldStarts = b3StackAlloc( &world->stack, ( meshGroupCount + 1 ) * sizeof( int ), "mesh manifold starts" ); - - // Sort mesh contacts by manifold count so that contacts with more manifolds are solved - // together keeping the SIMD lanes fuller and less ragged. - int meshSlotCount = 0; - { - int maxManifoldCount = 0; - for ( int i = 0; i < activeColorCount; ++i ) - { - b3GraphColor* color = colors + activeColorIndices[i]; - const b3ContactSpec* specs = color->contacts.data; - int colorContactCount = colorMeshContactCounts[i]; - for ( int j = 0; j < colorContactCount; ++j ) - { - maxManifoldCount = b3MaxInt( maxManifoldCount, specs[j].manifoldCount ); - } - } - - int* bucketStarts = b3StackAlloc( &world->stack, ( maxManifoldCount + 1 ) * sizeof( int ), "mesh buckets" ); - - int orderBase = 0; - int groupBase = 0; - for ( int i = 0; i < activeColorCount; ++i ) - { - b3GraphColor* color = colors + activeColorIndices[i]; - int colorContactCount = colorMeshContactCounts[i]; - if ( colorContactCount == 0 ) - { - continue; - } - - const b3ContactSpec* specs = color->contacts.data; - int* order = meshLaneOrder + orderBase; - - for ( int k = 0; k <= maxManifoldCount; ++k ) - { - bucketStarts[k] = 0; - } - - for ( int j = 0; j < colorContactCount; ++j ) - { - bucketStarts[specs[j].manifoldCount] += 1; - } - - int start = 0; - for ( int k = maxManifoldCount; k >= 0; --k ) - { - int count = bucketStarts[k]; - bucketStarts[k] = start; - start += count; - } - - for ( int j = 0; j < colorContactCount; ++j ) - { - order[bucketStarts[specs[j].manifoldCount]++] = j; - } - - int colorMeshGroupCount = colorMeshGroupCounts[i]; - for ( int g = 0; g < colorMeshGroupCount; ++g ) - { - int slotCount = specs[order[g << simdShift]].manifoldCount; - meshManifoldStarts[groupBase + g] = meshSlotCount; - meshSlotCount += slotCount; - } - - orderBase += colorContactCount; - groupBase += colorMeshGroupCount; - } - - B3_ASSERT( orderBase == meshContactCount ); - B3_ASSERT( groupBase == meshGroupCount ); - meshManifoldStarts[meshGroupCount] = meshSlotCount; - - b3StackFree( &world->stack, bucketStarts ); - } - - int wideMeshConstraintByteCount = b3GetWideMeshConstraintByteCount( world->simdWidth ); - int wideMeshManifoldByteCount = b3GetWideMeshManifoldByteCount( world->simdWidth ); - void* wideMeshConstraints = - b3StackAlloc( &world->stack, meshGroupCount * wideMeshConstraintByteCount + meshSlotCount * wideMeshManifoldByteCount, - "wide mesh constraints" ); + int wideContactByteCount = b3GetWideContactConstraintByteCount(); + b3ContactConstraintWide* wideConstraints = + (b3ContactConstraintWide*)b3StackAlloc( &world->stack, wideContactCount * wideContactByteCount, "wide contacts" ); + b3ContactConstraint* contactConstraints = + (b3ContactConstraint*)b3StackAlloc( &world->stack, contactCount * sizeof( b3ContactConstraint ), "contacts" ); + b3ManifoldConstraint* manifoldConstraints = (b3ManifoldConstraint*)b3StackAlloc( + &world->stack, manifoldCount * sizeof( b3ManifoldConstraint ), "manifold constraints" ); b3GraphColor* overflow = colors + B3_OVERFLOW_INDEX; int overflowCount = overflow->contacts.count; @@ -1655,23 +1560,23 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) overflowManifoldCount += overflow->contacts.data[i].manifoldCount; } - overflow->contactConstraints = - b3StackAlloc( &world->stack, overflowCount * sizeof( b3ContactConstraint ), "overflow contacts" ); - overflow->manifoldConstraints = - b3StackAlloc( &world->stack, overflowManifoldCount * sizeof( b3ManifoldConstraint ), "overflow manifolds" ); + overflow->contactConstraints = (b3ContactConstraint*)b3StackAlloc( + &world->stack, overflowCount * sizeof( b3ContactConstraint ), "overflow contacts" ); + overflow->manifoldConstraints = (b3ManifoldConstraint*)b3StackAlloc( + &world->stack, overflowManifoldCount * sizeof( b3ManifoldConstraint ), "overflow manifolds" ); // Build the span table for the flat prepare/store parallel-for while I slice the // wide constraint buffer across colors. One entry per active color plus a sentinel // at wideContactCount. - b3WidePrepareSpan* widePrepareSpans = stepContext->widePrepareSpans; - b3MeshPrepareSpan* meshPrepareSpans = stepContext->meshPrepareSpans; - b3JointPrepareSpan* jointPrepareSpans = stepContext->jointPrepareSpans; + b3WidePrepareSpan widePrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; + b3ContactPrepareSpan contactPrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; + b3JointPrepareSpan jointPrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; // Distribute transient constraints to each graph color and prepare spans + // todo it might be simpler for solver blocks to index into the global arrays { int wideBase = 0; int contactBase = 0; - int meshGroupBase = 0; int jointBase = 0; for ( int i = 0; i < activeColorCount; ++i ) { @@ -1690,33 +1595,37 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) } else { - color->wideConstraints = ( (uint8_t*)wideConstraints + wideBase * wideContactByteCount ); + color->wideConstraints = + (b3ContactConstraintWide*)( (uint8_t*)wideConstraints + wideBase * wideContactByteCount ); - int colorContactCountW = ( ( colorConvexContactCount - 1 ) >> simdShift ) + 1; + int colorContactCountW = ( ( colorConvexContactCount - 1 ) >> B3_SIMD_SHIFT ) + 1; color->wideConstraintCount = colorContactCountW; + + // Zero remainder lanes in the tail wide slot so prepare workers don't need to + // initialize them. + if ( ( colorConvexContactCount & ( B3_SIMD_WIDTH - 1 ) ) != 0 ) + { + memset( (uint8_t*)color->wideConstraints + ( colorContactCountW - 1 ) * wideContactByteCount, 0, + wideContactByteCount ); + } + wideBase += colorContactCountW; } int colorContactCount = color->contacts.count; - meshPrepareSpans[i].start = meshGroupBase; - meshPrepareSpans[i].count = colorContactCount; - meshPrepareSpans[i].contacts = color->contacts.data; - meshPrepareSpans[i].order = meshLaneOrder + contactBase; + contactPrepareSpans[i].start = contactBase; + contactPrepareSpans[i].count = colorContactCount; + contactPrepareSpans[i].contacts = color->contacts.data; if ( colorContactCount == 0 ) { - color->wideMeshConstraints = NULL; - color->wideMeshManifoldStarts = NULL; - color->wideMeshConstraintCount = 0; + color->contactConstraints = NULL; + color->contactConstraintCount = 0; } else { - int colorMeshGroupCount = colorMeshGroupCounts[i]; - color->wideMeshConstraints = (uint8_t*)wideMeshConstraints + meshGroupBase * wideMeshConstraintByteCount + - meshManifoldStarts[meshGroupBase] * wideMeshManifoldByteCount; - color->wideMeshManifoldStarts = meshManifoldStarts + meshGroupBase; - color->wideMeshConstraintCount = colorMeshGroupCount; - meshGroupBase += colorMeshGroupCount; + color->contactConstraints = contactConstraints + contactBase; + color->contactConstraintCount = colorContactCount; contactBase += colorContactCount; } @@ -1732,12 +1641,10 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) widePrepareSpans[activeColorCount].contacts = NULL; B3_ASSERT( wideBase == wideContactCount ); - meshPrepareSpans[activeColorCount].start = meshGroupCount; - meshPrepareSpans[activeColorCount].count = 0; - meshPrepareSpans[activeColorCount].contacts = NULL; - meshPrepareSpans[activeColorCount].order = NULL; - B3_ASSERT( contactBase == meshContactCount ); - B3_ASSERT( meshGroupBase == meshGroupCount ); + contactPrepareSpans[activeColorCount].start = contactCount; + contactPrepareSpans[activeColorCount].count = 0; + contactPrepareSpans[activeColorCount].contacts = NULL; + B3_ASSERT( contactBase == contactCount ); jointPrepareSpans[activeColorCount].start = jointCount; jointPrepareSpans[activeColorCount].count = 0; @@ -1746,7 +1653,7 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) } //// Special span for overflow to allow for function re-use - b3ContactPrepareSpan* overflowSpans = stepContext->overflowSpans; + b3ContactPrepareSpan overflowSpans[2] = { 0 }; overflowSpans[0].start = 0; overflowSpans[0].count = overflow->contacts.count; overflowSpans[0].contacts = overflow->contacts.data; @@ -1779,13 +1686,38 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) // b3_stageStoreImpulses stageCount += 1; - b3SolverStage* stages = b3StackAlloc( &world->stack, stageCount * sizeof( b3SolverStage ), "stages" ); - b3SyncBlock* bodyBlocks = b3StackAlloc( &world->stack, bodyDim.count * sizeof( b3SyncBlock ), "body blocks" ); + b3SolverStage* stages = (b3SolverStage*)b3StackAlloc( &world->stack, stageCount * sizeof( b3SolverStage ), "stages" ); + b3SyncBlock* bodyBlocks = + (b3SyncBlock*)b3StackAlloc( &world->stack, bodyDim.count * sizeof( b3SyncBlock ), "body blocks" ); b3SyncBlock* convexBlocks = - b3StackAlloc( &world->stack, convexPrepareDim.count * sizeof( b3SyncBlock ), "convex blocks" ); - b3SyncBlock* meshBlocks = b3StackAlloc( &world->stack, meshPrepareDim.count * sizeof( b3SyncBlock ), "mesh blocks" ); - b3SyncBlock* jointBlocks = b3StackAlloc( &world->stack, jointPrepareDim.count * sizeof( b3SyncBlock ), "joint blocks" ); - b3SyncBlock* graphBlocks = b3StackAlloc( &world->stack, graphBlockCount * sizeof( b3SyncBlock ), "graph blocks" ); + (b3SyncBlock*)b3StackAlloc( &world->stack, convexPrepareDim.count * sizeof( b3SyncBlock ), "convex blocks" ); + b3SyncBlock* meshBlocks = + (b3SyncBlock*)b3StackAlloc( &world->stack, meshPrepareDim.count * sizeof( b3SyncBlock ), "mesh blocks" ); + b3SyncBlock* jointBlocks = + (b3SyncBlock*)b3StackAlloc( &world->stack, jointPrepareDim.count * sizeof( b3SyncBlock ), "joint blocks" ); + b3SyncBlock* graphBlocks = + (b3SyncBlock*)b3StackAlloc( &world->stack, graphBlockCount * sizeof( b3SyncBlock ), "graph blocks" ); + + // Split an awake island. This modifies: + // - stack allocator + // - world island array and solver set + // - island indices on bodies, contacts, and joints + // I'm squeezing this task in here because it may be expensive and this is a safe place to put it. + // Note: cannot split islands in parallel with FinalizeBodies + void* splitIslandTask = NULL; + if ( world->splitIslandId != B3_NULL_INDEX ) + { + if ( world->taskCount < B3_MAX_TASKS ) + { + splitIslandTask = world->enqueueTaskFcn( &b3SplitIslandTask, world, world->userTaskContext, "split" ); + world->taskCount += 1; + world->activeTaskCount += splitIslandTask == NULL ? 0 : 1; + } + else + { + b3SplitIslandTask( world ); + } + } // Prepare body blocks b3InitBlocks( bodyBlocks, bodyDim, awakeBodyCount, b3_bodyBlock, UINT8_MAX ); @@ -1793,7 +1725,7 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) // Prepare blocks as a single flat parallel-for over the whole constraint range. // The task walks spans to decode flat slot indices back to per-color arrays. b3InitBlocks( convexBlocks, convexPrepareDim, wideContactCount, b3_wideContactBlock, UINT8_MAX ); - b3InitBlocks( meshBlocks, meshPrepareDim, meshGroupCount, b3_contactBlock, UINT8_MAX ); + b3InitBlocks( meshBlocks, meshPrepareDim, contactCount, b3_contactBlock, UINT8_MAX ); b3InitBlocks( jointBlocks, jointPrepareDim, jointCount, b3_jointBlock, UINT8_MAX ); // Prepare graph work blocks. Each color gets joint blocks followed by contact blocks. @@ -1812,10 +1744,10 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) colorIndex ); baseGraphBlock += graphWideContactDims[i].count; - b3InitBlocks( baseGraphBlock, graphMeshContactDims[i], colorMeshGroupCounts[i], b3_graphContactBlock, colorIndex ); - baseGraphBlock += graphMeshContactDims[i].count; + b3InitBlocks( baseGraphBlock, graphContactDims[i], colorContactCounts[i], b3_graphContactBlock, colorIndex ); + baseGraphBlock += graphContactDims[i].count; - graphBlockCounts[i] = graphJointDims[i].count + graphWideContactDims[i].count + graphMeshContactDims[i].count; + graphBlockCounts[i] = graphJointDims[i].count + graphWideContactDims[i].count + graphContactDims[i].count; } B3_ASSERT( (ptrdiff_t)( baseGraphBlock - graphBlocks ) == graphBlockCount ); @@ -1832,6 +1764,7 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) stage = b3InitStage( stage, b3_stageIntegratePositions, bodyBlocks, bodyDim.count, UINT8_MAX ); stage = b3InitColorStages( stage, b3_stageRelax, RELAX_ITERATIONS, activeColorCount, graphColorBlocks, graphBlockCounts, activeColorIndices ); + // Note: joint blocks mixed in, could have joint limit restitution stage = b3InitColorStages( stage, b3_stageRestitution, 1, activeColorCount, graphColorBlocks, graphBlockCounts, activeColorIndices ); stage = b3InitStage( stage, b3_stageStoreWideImpulses, convexBlocks, convexPrepareDim.count, UINT8_MAX ); @@ -1840,30 +1773,29 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) B3_ASSERT( (int)( stage - stages ) == stageCount ); B3_ASSERT( workerCount <= B3_MAX_WORKERS ); + b3WorkerContext workerContext[B3_MAX_WORKERS]; stepContext->graph = graph; stepContext->activeColorCount = activeColorCount; stepContext->workerCount = workerCount; stepContext->stageCount = stageCount; stepContext->stages = stages; - stepContext->bodyBlocks = bodyBlocks; - stepContext->convexBlocks = convexBlocks; - stepContext->meshBlocks = meshBlocks; - stepContext->jointBlocks = jointBlocks; - stepContext->graphBlocks = graphBlocks; stepContext->wideConstraints = wideConstraints; + stepContext->widePrepareSpans = widePrepareSpans; stepContext->wideContactCount = wideContactCount; - stepContext->wideMeshConstraints = wideMeshConstraints; - stepContext->wideMeshManifoldStarts = meshManifoldStarts; - stepContext->meshLaneOrder = meshLaneOrder; - stepContext->orchestratorIndex = B3_NULL_INDEX; + stepContext->manifoldConstraints = manifoldConstraints; + stepContext->contactConstraints = contactConstraints; + stepContext->contactPrepareSpans = contactPrepareSpans; + stepContext->overflowSpans = overflowSpans; + stepContext->jointPrepareSpans = jointPrepareSpans; b3AtomicStoreU32( &stepContext->atomicSyncBits, 0 ); - b3AtomicStoreInt( &stepContext->orchestratorClaimed, 0 ); + b3AtomicStoreInt( &stepContext->mainClaimed, 0 ); world->profile.solverSetup = b3GetMillisecondsAndReset( &setupTicks ); b3TracyCZoneEnd( solver_setup ); - stepContext->constraintTicks = b3GetTicks(); + b3TracyCZoneNC( solve_constraints, "Solve Constraints", b3_colorIndigo, true ); + uint64_t constraintTicks = b3GetTicks(); int jointIdCapacity = b3GetIdCapacity( &world->jointIdPool ); int contactIdCapacity = b3GetIdCapacity( &world->contactIdPool ); @@ -1873,91 +1805,91 @@ bool b3BeginSolve( b3World* world, b3StepContext* stepContext ) b3SetBitCountAndClear( &taskContext->jointStateBitSet, jointIdCapacity ); b3SetBitCountAndClear( &taskContext->hitEventBitSet, contactIdCapacity ); taskContext->hasHitEvents = false; + + workerContext[i].context = stepContext; + workerContext[i].workerIndex = i; + + if ( world->taskCount < B3_MAX_TASKS ) + { + char buffer[16]; + snprintf( buffer, sizeof( buffer ), "solve[%d]", i ); + workerContext[i].userTask = + world->enqueueTaskFcn( &b3SolverTask, workerContext + i, world->userTaskContext, buffer ); + world->taskCount += 1; + world->activeTaskCount += workerContext[i].userTask == NULL ? 0 : 1; + } + else + { + workerContext[i].userTask = NULL; + b3SolverTask( workerContext + i ); + } } - // Split an awake island. This modifies: - // - stack allocator - // - world island array and solver set - // - island indices on bodies, contacts, and joints - // I'm squeezing this task in here because it may be expensive and this is a safe place to put it. - // Note: cannot split islands in parallel with FinalizeBodies - if ( world->splitIslandId != B3_NULL_INDEX ) - { - b3AddTask( stepContext, b3_taskIslandSplit, &b3SplitIslandTask, world ); - } + // The calling thread of b3World_Step also enters b3SolverTask as worker 0 and races for the + // orchestrator slot via the CAS inside. This guarantees progress even when the user's task + // system can't run the queued worker 0 promptly: it might schedule out of order, have fewer + // threads than workerCount, or invert priority by parking the calling thread in finishTaskFcn. + // Whoever wins the CAS becomes the orchestrator; the loser returns and lets the spinner-only + // path handle workers >0. + b3WorkerContext callerContext = { stepContext, 0, NULL }; + b3SolverTask( &callerContext ); + // Finish constraint solve for ( int i = 0; i < workerCount; ++i ) { - b3WorkerContext* workerContext = stepContext->workerContexts + i; - workerContext->context = stepContext; - workerContext->workerIndex = i; - - b3AddTask( stepContext, b3_taskSolver, &b3SolverTask, workerContext ); + if ( workerContext[i].userTask != NULL ) + { + world->finishTaskFcn( workerContext[i].userTask, world->userTaskContext ); + world->activeTaskCount -= 1; + } } + + // Finish island split + if ( splitIslandTask != NULL ) + { + world->finishTaskFcn( splitIslandTask, world->userTaskContext ); + world->activeTaskCount -= 1; + } + world->splitIslandId = B3_NULL_INDEX; + + world->profile.constraints = b3GetMillisecondsAndReset( &constraintTicks ); + b3TracyCZoneEnd( solve_constraints ); + + b3TracyCZoneNC( update_transforms, "Update Transforms", b3_colorMediumSeaGreen, true ); + uint64_t transformTicks = b3GetTicks(); + + // Prepare contact, enlarged body, and island bit sets used in body finalization. + int awakeIslandCount = awakeSet->islandSims.count; + for ( int i = 0; i < world->workerCount; ++i ) + { + b3TaskContext* taskContext = world->taskContexts.data + i; + b3Array_Clear( taskContext->sensorHits ); + b3SetBitCountAndClear( &taskContext->enlargedSimBitSet, awakeBodyCount ); + b3SetBitCountAndClear( &taskContext->awakeIslandBitSet, awakeIslandCount ); + taskContext->splitIslandId = B3_NULL_INDEX; + taskContext->splitSleepTime = 0.0f; + } + + // Finalize bodies. Must happen after the constraint solver and after island splitting. + b3ParallelFor( world, &b3FinalizeBodiesTask, awakeBodyCount, 16, stepContext, "ccd" ); + + // Free in reverse order + b3StackFree( &world->stack, graphBlocks ); + b3StackFree( &world->stack, jointBlocks ); + b3StackFree( &world->stack, meshBlocks ); + b3StackFree( &world->stack, convexBlocks ); + b3StackFree( &world->stack, bodyBlocks ); + b3StackFree( &world->stack, stages ); + b3StackFree( &world->stack, overflow->manifoldConstraints ); + b3StackFree( &world->stack, overflow->contactConstraints ); + b3StackFree( &world->stack, manifoldConstraints ); + b3StackFree( &world->stack, contactConstraints ); + b3StackFree( &world->stack, wideConstraints ); + + world->profile.transforms = b3GetMilliseconds( transformTicks ); + b3TracyCZoneEnd( update_transforms ); } - return true; -} - -void b3BeginFinalize( b3World* world, b3StepContext* stepContext ) -{ - world->splitIslandId = B3_NULL_INDEX; - world->profile.constraints = b3GetMilliseconds( stepContext->constraintTicks ); - - stepContext->transformTicks = b3GetTicks(); - - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); - int awakeBodyCount = stepContext->awakeBodyCount; - B3_ASSERT( awakeBodyCount == awakeSet->bodySims.count ); - - // Prepare the island bit set used in body finalization. - int awakeIslandCount = awakeSet->islandSims.count; - for ( int i = 0; i < world->workerCount; ++i ) - { - b3TaskContext* taskContext = world->taskContexts.data + i; - b3Array_Clear( taskContext->sensorHits ); - b3SetBitCountAndClear( &taskContext->awakeIslandBitSet, awakeIslandCount ); - taskContext->splitIslandId = B3_NULL_INDEX; - taskContext->splitSleepTime = 0.0f; - } - - b3ValidateNoMoved( &world->broadPhase ); - - // Finalize bodies. Must happen after the constraint solver and after island splitting. - b3StageParallelFor( world, b3_taskFinalize, &b3FinalizeBodiesTask, awakeBodyCount, 8, stepContext ); -} - -void b3BeginBullets( b3World* world, b3StepContext* stepContext ) -{ - // Free in reverse order - b3GraphColor* overflow = world->constraintGraph.colors + B3_OVERFLOW_INDEX; - - b3StackFree( &world->stack, stepContext->graphBlocks ); - b3StackFree( &world->stack, stepContext->jointBlocks ); - b3StackFree( &world->stack, stepContext->meshBlocks ); - b3StackFree( &world->stack, stepContext->convexBlocks ); - b3StackFree( &world->stack, stepContext->bodyBlocks ); - b3StackFree( &world->stack, stepContext->stages ); - b3StackFree( &world->stack, overflow->manifoldConstraints ); - b3StackFree( &world->stack, overflow->contactConstraints ); - b3StackFree( &world->stack, stepContext->wideMeshConstraints ); - b3StackFree( &world->stack, stepContext->wideMeshManifoldStarts ); - b3StackFree( &world->stack, stepContext->meshLaneOrder ); - b3StackFree( &world->stack, stepContext->wideConstraints ); - - stepContext->graphBlocks = NULL; - stepContext->jointBlocks = NULL; - stepContext->meshBlocks = NULL; - stepContext->convexBlocks = NULL; - stepContext->bodyBlocks = NULL; - stepContext->stages = NULL; - stepContext->wideMeshConstraints = NULL; - stepContext->wideMeshManifoldStarts = NULL; - stepContext->meshLaneOrder = NULL; - stepContext->wideConstraints = NULL; - - world->profile.transforms = b3GetMilliseconds( stepContext->transformTicks ); - // Report joint events { b3TracyCZoneNC( joint_events, "Joint Events", b3_colorPeru, true ); @@ -2129,8 +2061,90 @@ void b3BeginBullets( b3World* world, b3StepContext* stepContext ) b3TracyCZoneNC( refit_bvh, "Refit BVH", b3_colorFireBrick, true ); uint64_t refitTicks = b3GetTicks(); - b3DynamicTree_Refit( world->broadPhase.trees + b3_kinematicBody ); - b3DynamicTree_Refit( world->broadPhase.trees + b3_dynamicBody ); + // Finish the user tree task that was queued earlier in the time step. This must be complete before touching the + // broad-phase. + if ( world->userTreeTask != NULL ) + { + world->finishTaskFcn( world->userTreeTask, world->userTaskContext ); + world->userTreeTask = NULL; + world->activeTaskCount -= 1; + } + + b3ValidateNoEnlarged( &world->broadPhase ); + + // Gather bits for all sim bodies that have enlarged AABBs + b3BitSet* enlargedBodyBitSet = &world->taskContexts.data[0].enlargedSimBitSet; + for ( int i = 1; i < world->workerCount; ++i ) + { + b3InPlaceUnion( enlargedBodyBitSet, &world->taskContexts.data[i].enlargedSimBitSet ); + } + + // Enlarge broad-phase proxies and build move array + // Apply shape AABB changes to broad-phase. This also create the move array which must be + // in deterministic order. I'm tracking sim bodies because the number of shape ids can be huge. + // This has to happen before bullets are processed. + { + b3BroadPhase* broadPhase = &world->broadPhase; + uint32_t wordCount = enlargedBodyBitSet->blockCount; + uint64_t* bits = enlargedBodyBitSet->bits; + + // Fast array access is important here + b3Body* bodyArray = world->bodies.data; + b3BodySim* bodySimArray = awakeSet->bodySims.data; + b3Shape* shapeArray = world->shapes.data; + + for ( uint32_t k = 0; k < wordCount; ++k ) + { + uint64_t word = bits[k]; + while ( word != 0 ) + { + uint32_t ctz = b3CTZ64( word ); + uint32_t bodySimIndex = 64 * k + ctz; + + b3BodySim* bodySim = bodySimArray + bodySimIndex; + + b3Body* body = bodyArray + bodySim->bodyId; + + int shapeId = body->headShapeId; + if ( ( bodySim->flags & ( b3_isBullet | b3_isFast ) ) == ( b3_isBullet | b3_isFast ) ) + { + // Fast bullet bodies don't have their final AABB yet + while ( shapeId != B3_NULL_INDEX ) + { + b3Shape* shape = shapeArray + shapeId; + + // Shape is fast. It's aabb will be enlarged in continuous collision. + // Update the move array here for determinism because bullets are processed + // below in non-deterministic order. + b3BufferMove( broadPhase, shape->proxyKey ); + + shapeId = shape->nextShapeId; + } + } + else + { + while ( shapeId != B3_NULL_INDEX ) + { + b3Shape* shape = shapeArray + shapeId; + + // The AABB may not have been enlarged, despite the body being flagged as enlarged. + // For example, a body with multiple shapes may have not have all shapes enlarged. + // A fast body may have been flagged as enlarged despite having no shapes enlarged. + if ( shape->enlargedAABB ) + { + b3BroadPhase_EnlargeProxy( broadPhase, shape->proxyKey, shape->fatAABB ); + shape->enlargedAABB = false; + } + + shapeId = shape->nextShapeId; + } + } + + // Clear the smallest set bit + word = word & ( word - 1 ); + } + } + } b3ValidateBroadPhase( &world->broadPhase ); @@ -2141,23 +2155,13 @@ void b3BeginBullets( b3World* world, b3StepContext* stepContext ) int bulletBodyCount = b3AtomicLoadInt( &stepContext->bulletBodyCount ); if ( bulletBodyCount > 0 ) { - stepContext->bulletTicks = b3GetTicks(); + b3TracyCZoneNC( bullets, "Bullets", b3_colorDarkGoldenRod, true ); + uint64_t bulletTicks = b3GetTicks(); // Fast bullet bodies // Note: a bullet body may be moving slow int minRange = 8; - b3StageParallelFor( world, b3_taskContinuous, &b3BulletBodyTask, bulletBodyCount, minRange, stepContext ); - } -} - -void b3EndBullets( b3World* world, b3StepContext* stepContext ) -{ - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); - - int bulletBodyCount = b3AtomicLoadInt( &stepContext->bulletBodyCount ); - if ( bulletBodyCount > 0 ) - { - b3TracyCZoneNC( bullets, "Bullet Proxies", b3_colorDarkGoldenRod, true ); + b3ParallelFor( world, &b3BulletBodyTask, bulletBodyCount, minRange, stepContext, "bullets" ); // Serially enlarge broad-phase proxies for bullet shapes b3BroadPhase* broadPhase = &world->broadPhase; @@ -2175,13 +2179,13 @@ void b3EndBullets( b3World* world, b3StepContext* stepContext ) for ( int i = 0; i < bulletBodyCount; ++i ) { b3BodySim* bulletBodySim = bodySimArray + bulletBodySimIndices[i]; - if ( ( bulletBodySim->flags & b3_enlargeBulletBounds ) == 0 ) + if ( ( bulletBodySim->flags & b3_enlargeBounds ) == 0 ) { continue; } // Clear flag - bulletBodySim->flags &= ~b3_enlargeBulletBounds; + bulletBodySim->flags &= ~b3_enlargeBounds; int bodyId = bulletBodySim->bodyId; B3_ASSERT( 0 <= bodyId && bodyId < world->bodies.count ); @@ -2191,24 +2195,29 @@ void b3EndBullets( b3World* world, b3StepContext* stepContext ) while ( shapeId != B3_NULL_INDEX ) { b3Shape* shape = shapeArray + shapeId; + if ( shape->enlargedAABB == false ) + { + shapeId = shape->nextShapeId; + continue; + } + + // clear flag + shape->enlargedAABB = false; int proxyKey = shape->proxyKey; int proxyId = B3_PROXY_ID( proxyKey ); - B3_VALIDATE( B3_PROXY_TYPE( proxyKey ) == b3_dynamicBody ); + B3_ASSERT( B3_PROXY_TYPE( proxyKey ) == b3_dynamicBody ); - b3AABB treeAABB = b3DynamicTree_GetAABB( dynamicTree, proxyId ); - b3AABB shapeFatAABB = world->fatAABBs.data[shapeId]; + // all fast bullet shapes should already be in the move buffer + B3_ASSERT( b3GetBit( &broadPhase->movedProxies[b3_dynamicBody], proxyId ) ); - if ( b3AABB_Contains( treeAABB, shapeFatAABB ) == false ) - { - b3DynamicTree_EnlargeProxy( dynamicTree, proxyId, shapeFatAABB ); - } + b3DynamicTree_EnlargeProxy( dynamicTree, proxyId, shape->fatAABB ); shapeId = shape->nextShapeId; } } - world->profile.bullets = b3GetMilliseconds( stepContext->bulletTicks ); + world->profile.bullets = b3GetMilliseconds( bulletTicks ); b3TracyCZoneEnd( bullets ); } diff --git a/src/solver.h b/src/solver.h index f7ae1ab..7c8a1c7 100644 --- a/src/solver.h +++ b/src/solver.h @@ -50,52 +50,21 @@ #include "container.h" #include "core.h" -#include "parallel_for.h" -#include "box3d/constants.h" #include "box3d/math_functions.h" -#include "box3d/types.h" -#include #include typedef struct b3BodySim b3BodySim; typedef struct b3BodyState b3BodyState; typedef struct b3ContactConstraint b3ContactConstraint; +typedef struct b3ContactConstraintWide b3ContactConstraintWide; typedef struct b3ContactSpec b3ContactSpec; typedef struct b3JointSim b3JointSim; typedef struct b3Manifold b3Manifold; typedef struct b3ManifoldConstraint b3ManifoldConstraint; typedef struct b3World b3World; -typedef enum b3StepPhase -{ - b3_stepIdle, - b3_stepBegin, - b3_stepCrossPairs, - b3_stepSelfPairs, - b3_stepCollide, - b3_stepSolve, - b3_stepFinalize, - b3_stepBullets, - b3_stepSensors, -} b3StepPhase; - -typedef struct b3StepTask -{ - b3TaskCallback* fcn; - void* context; - b3StepContext* stepContext; -} b3StepTask; - -typedef struct b3WorkerContext -{ - b3StepContext* context; - int workerIndex; -} b3WorkerContext; - -#define B3_STEP_TASK_CAPACITY ( B3_MAX_WORKERS + 2 ) - // Solver stages typedef enum b3SolverStageType { @@ -195,14 +164,6 @@ typedef struct b3ContactPrepareSpan b3ContactSpec* contacts; } b3ContactPrepareSpan; -typedef struct b3MeshPrepareSpan -{ - int start; - int count; - b3ContactSpec* contacts; - int* order; -} b3MeshPrepareSpan; - typedef struct b3JointPrepareSpan { int start; @@ -213,48 +174,6 @@ typedef struct b3JointPrepareSpan // Context for a time step. Recreated each time step. typedef struct b3StepContext { - b3StepPhase phase; - bool pairsUpdated; - bool treeStaged; - bool treeLaunched; - bool solveSkipped; - bool joinTree; - bool signalSemaphores; - - int batchTaskBase; - int batchTaskCount; - int taskCount; - int enqueueCount; - - b3Task tasks[B3_STEP_TASK_CAPACITY]; - b3StepTask stepTasks[B3_STEP_TASK_CAPACITY]; - - b3ParallelForShared parallelFor; - b3ParallelForTask parallelForTasks[B3_MAX_WORKERS]; - b3WorkerContext workerContexts[B3_MAX_WORKERS]; - - b3Semaphore* batchSemaphore; - b3Semaphore* treeSemaphore; - - uint64_t stepTicks; - uint64_t pairTicks; - uint64_t collideTicks; - uint64_t solveTicks; - uint64_t constraintTicks; - uint64_t transformTicks; - uint64_t bulletTicks; - uint64_t sensorTicks; - - int awakeBodyCount; - int collideContactCount; - - b3SyncBlock* bodyBlocks; - b3SyncBlock* convexBlocks; - b3SyncBlock* meshBlocks; - b3SyncBlock* jointBlocks; - b3SyncBlock* graphBlocks; - int* meshLaneOrder; - // time step float dt; @@ -270,6 +189,7 @@ typedef struct b3StepContext b3Softness contactSoftness; b3Softness staticSoftness; + float restitutionThreshold; float maxLinearVelocity; struct b3World* world; @@ -289,33 +209,30 @@ typedef struct b3StepContext int* bulletBodies; b3AtomicInt bulletBodyCount; - b3AtomicInt anyRestitution; - // Contact ids for simplified parallel-for access. Used in narrow-phase. // These contacts may or may not be touching. They are associated with awake bodies. int* awakeContactIndices; // Flat view of the wide contact constraint array used by prepare and store. - // widePrepareSpans has activeColorCount + 1 entries, the last being a sentinel - // at wideContactCount. wideConstraints is the contiguous base - // pointer. Per-color slices live at colors[i].wideConstraints. - void* wideConstraints; - b3WidePrepareSpan widePrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; + // prepareSpans has activeColorCount + 1 entries, the last being a sentinel + // at wideContactCount. wideContactConstraints is the contiguous base + // pointer; per-color slices live at colors[i].wideConstraints. + struct b3ContactConstraintWide* wideConstraints; + b3WidePrepareSpan* widePrepareSpans; int wideContactCount; - // Similar for overflow contact constraints. - b3ContactPrepareSpan overflowSpans[2]; - void* wideMeshConstraints; - int* wideMeshManifoldStarts; - b3MeshPrepareSpan meshPrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; - b3JointPrepareSpan jointPrepareSpans[B3_GRAPH_COLOR_COUNT + 1]; + // Similar for mesh/overflow contact constraints + struct b3ManifoldConstraint* manifoldConstraints; + struct b3ContactConstraint* contactConstraints; + b3ContactPrepareSpan* contactPrepareSpans; + b3ContactPrepareSpan* overflowSpans; + b3JointPrepareSpan* jointPrepareSpans; int activeColorCount; int workerCount; b3SolverStage* stages; int stageCount; - int orchestratorIndex; bool enableWarmStarting; // padding to prevent false sharing @@ -331,19 +248,18 @@ typedef struct b3StepContext // padding to prevent false sharing char padding2[64]; - b3AtomicInt orchestratorClaimed; + // Race flag claimed by whichever runner reaches b3SolverTask with workerIndex 0 first. + // The calling thread of b3World_Step also races for this slot so the orchestrator can + // always make progress, regardless of how the user's task system schedules tasks (out + // of order, fewer threads than workers, or synchronously inside enqueueTaskFcn). The + // loser of the race no-ops as workerIndex 0. + b3AtomicInt mainClaimed; // padding to prevent false sharing char padding3[64]; - - b3AtomicInt pendingCount; - b3AtomicInt treePending; } b3StepContext; -bool b3BeginSolve( b3World* world, b3StepContext* stepContext ); -void b3BeginFinalize( b3World* world, b3StepContext* stepContext ); -void b3BeginBullets( b3World* world, b3StepContext* stepContext ); -void b3EndBullets( b3World* world, b3StepContext* stepContext ); +void b3Solve( b3World* world, b3StepContext* stepContext ); static inline b3Softness b3MakeSoft( float hertz, float zeta, float h ) { diff --git a/src/solver_set.c b/src/solver_set.c index ff0ec53..f050a86 100644 --- a/src/solver_set.c +++ b/src/solver_set.c @@ -14,7 +14,7 @@ void b3DestroySolverSet( b3World* world, int setIndex ) { - b3SolverSet* set = b3GetSolverSet( world, setIndex ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); b3Array_Destroy( set->bodySims ); b3Array_Destroy( set->bodyStates ); @@ -36,9 +36,9 @@ void b3DestroySolverSet( b3World* world, int setIndex ) void b3WakeSolverSet( b3World* world, int setIndex ) { B3_ASSERT( setIndex >= b3_firstSleepingSet ); - b3SolverSet* set = b3GetSolverSet( world, setIndex ); - b3SolverSet* awakeSet = b3GetSolverSet( world, b3_awakeSet ); - b3SolverSet* disabledSet = b3GetSolverSet( world, b3_disabledSet ); + b3SolverSet* set = b3Array_Get( world->solverSets, setIndex ); + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); + b3SolverSet* disabledSet = b3Array_Get( world->solverSets, b3_disabledSet ); b3Body* bodies = world->bodies.data; @@ -62,8 +62,7 @@ void b3WakeSolverSet( b3World* world, int setIndex ) *state = b3_identityBodyState; state->flags = body->flags; - // Move non-touching contacts from disabled set to awake set. - int encodedBodySimIndex = body->localIndex; + // move non-touching contacts from disabled set to awake set int contactKey = body->headContactKey; while ( contactKey != B3_NULL_INDEX ) { @@ -76,21 +75,6 @@ void b3WakeSolverSet( b3World* world, int setIndex ) if ( contact->setIndex != b3_disabledSet ) { B3_ASSERT( contact->setIndex == b3_awakeSet || contact->setIndex == setIndex ); - - // If this contact is awake but not touching I need to fixup the body sim index here. - if ( contact->setIndex == b3_awakeSet ) - { - B3_ASSERT( contact->colorIndex == B3_NULL_INDEX ); - if ( edgeIndex == 0 ) - { - contact->encodedBodySimA = encodedBodySimIndex; - } - else - { - contact->encodedBodySimB = encodedBodySimIndex; - } - } - continue; } @@ -105,15 +89,6 @@ void b3WakeSolverSet( b3World* world, int setIndex ) contact->localIndex = awakeSet->contactIndices.count; b3Array_Push( awakeSet->contactIndices, contactId ); - if ( edgeIndex == 0 ) - { - contact->encodedBodySimA = encodedBodySimIndex; - } - else - { - contact->encodedBodySimB = encodedBodySimIndex; - } - int movedLocalIndex = b3Array_RemoveSwap( disabledSet->contactIndices, localIndex ); if ( movedLocalIndex != B3_NULL_INDEX ) { @@ -193,18 +168,19 @@ void b3TrySleepIsland( b3World* world, int islandId ) // - remove old island // - fix island int sleepSetId = b3AllocId( &world->solverSetIdPool ); - if ( sleepSetId == b3GetSolverSetCount( world ) ) + if ( sleepSetId == world->solverSets.count ) { b3SolverSet set = { 0 }; set.setIndex = B3_NULL_INDEX; - b3Array_Push( world->sleepingSets, set ); + b3Array_Push( world->solverSets, set ); } - b3SolverSet* sleepSet = b3GetSolverSet( world, sleepSetId ); + b3SolverSet* sleepSet = b3Array_Get( world->solverSets, sleepSetId ); *sleepSet = (b3SolverSet){ 0 }; - b3SolverSet* awakeSet = b3GetFixedSolverSet( world, b3_awakeSet ); - b3SolverSet* disabledSet = b3GetFixedSolverSet( world, b3_disabledSet ); + // grab awake set after creating the sleep set because the solver set array may have been resized + b3SolverSet* awakeSet = b3Array_Get( world->solverSets, b3_awakeSet ); + b3SolverSet* disabledSet = b3Array_Get( world->solverSets, b3_disabledSet ); B3_ASSERT( 0 <= island->localIndex && island->localIndex < awakeSet->islandSims.count ); sleepSet->setIndex = sleepSetId; @@ -251,11 +227,6 @@ void b3TrySleepIsland( b3World* world, int islandId ) b3Body* movedBody = b3Array_Get( world->bodies, movedId ); B3_ASSERT( movedBody->localIndex == movedIndex ); movedBody->localIndex = awakeBodyIndex; - - if ( movedBody->islandId != islandId ) - { - b3RefreshBodyContactIndices( world, movedBody ); - } } // destroy state, no need to clone @@ -274,10 +245,15 @@ void b3TrySleepIsland( b3World* world, int islandId ) b3Contact* contact = b3Array_Get( world->contacts, contactId ); - B3_ASSERT( contact->setIndex == b3_awakeSet ); - + B3_ASSERT( contact->setIndex == b3_awakeSet || contact->setIndex == b3_disabledSet ); contactKey = contact->edges[edgeIndex].nextKey; + if ( contact->setIndex == b3_disabledSet ) + { + // already moved to disabled set by another body in the island + continue; + } + if ( contact->colorIndex != B3_NULL_INDEX ) { // contact is touching and will be moved separately @@ -285,15 +261,6 @@ void b3TrySleepIsland( b3World* world, int islandId ) continue; } - if ( edgeIndex == 0 ) - { - contact->encodedBodySimA = B3_NULL_INDEX; - } - else - { - contact->encodedBodySimB = B3_NULL_INDEX; - } - // the other body may still be awake, it still may go to sleep and then it will be responsible // for moving this contact to the disabled set. int otherEdgeIndex = edgeIndex ^ 1; @@ -385,8 +352,6 @@ void b3TrySleepIsland( b3World* world, int islandId ) contact->setIndex = sleepSetId; contact->colorIndex = B3_NULL_INDEX; contact->localIndex = sleepContactIndex; - contact->encodedBodySimA = b3SleepBodySimIndex( contact->encodedBodySimA ); - contact->encodedBodySimB = b3SleepBodySimIndex( contact->encodedBodySimB ); } } @@ -475,8 +440,8 @@ void b3MergeSolverSets( b3World* world, int setId1, int setId2 ) { B3_ASSERT( setId1 >= b3_firstSleepingSet ); B3_ASSERT( setId2 >= b3_firstSleepingSet ); - b3SolverSet* set1 = b3GetSolverSet( world, setId1 ); - b3SolverSet* set2 = b3GetSolverSet( world, setId2 ); + b3SolverSet* set1 = b3Array_Get( world->solverSets, setId1 ); + b3SolverSet* set2 = b3Array_Get( world->solverSets, setId2 ); // Move the fewest number of bodies if ( set1->bodySims.count < set2->bodySims.count ) @@ -565,8 +530,6 @@ void b3MergeSolverSets( b3World* world, int setId1, int setId2 ) void b3TransferBody( b3World* world, b3SolverSet* targetSet, b3SolverSet* sourceSet, b3Body* body ) { - B3_ASSERT( body->headContactKey == B3_NULL_INDEX ); - if ( targetSet == sourceSet ) { return; @@ -580,8 +543,7 @@ void b3TransferBody( b3World* world, b3SolverSet* targetSet, b3SolverSet* source memcpy( targetSim, sourceSim, sizeof( b3BodySim ) ); // Clear transient body flags - body->flags &= ~b3_bodyTransientFlags; - targetSim->flags &= ~(b3_isFast | b3_bodyTransientFlags); + targetSim->flags &= ~( b3_isFast | b3_isSpeedCapped | b3_hadTimeOfImpact ); // Remove body sim from solver set that owns it int movedIndex = b3Array_RemoveSwap( sourceSet->bodySims, sourceIndex ); @@ -593,7 +555,6 @@ void b3TransferBody( b3World* world, b3SolverSet* targetSet, b3SolverSet* source b3Body* movedBody = b3Array_Get( world->bodies, movedId ); B3_ASSERT( movedBody->localIndex == movedIndex ); movedBody->localIndex = sourceIndex; - b3RefreshBodyContactIndices( world, movedBody ); } if ( sourceSet->setIndex == b3_awakeSet ) diff --git a/src/sphere.c b/src/sphere.c index 7b2e6cd..9e4bdaa 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -242,6 +242,6 @@ int b3CollideMoverAndSphere( b3PlaneResult* result, const b3Sphere* shape, const } b3Plane plane = { normal, totalRadius - distance }; - *result = (b3PlaneResult){ plane, shape->center, 0, 0, 0 }; + *result = ( b3PlaneResult ){ plane, shape->center }; return 1; } diff --git a/src/spherical_joint.c b/src/spherical_joint.c index 2058858..3f699ac 100644 --- a/src/spherical_joint.c +++ b/src/spherical_joint.c @@ -301,8 +301,8 @@ void b3PrepareSphericalJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -454,132 +454,85 @@ void b3SolveSphericalJoint( b3JointSim* base, b3StepContext* context, bool useBi b3Quat relQ = b3InvMulQuat( quatA, quatB ); - if ( fixedRotation == false && - ( joint->enableSpring || joint->enableMotor || joint->enableTwistLimit || joint->enableConeLimit ) ) + // Solve spring + if ( joint->enableSpring && fixedRotation == false ) { - b3Matrix3 invInertiaSum = b3AddMM( iA, iB ); + // Rotation constraint error + b3Vec3 deltaRotation = b3DeltaQuatToRotation( relQ, joint->targetRotation ); + b3Vec3 c = b3Neg( b3RotateVector( quatA, deltaRotation ) ); + + b3Vec3 bias = b3MulSV( joint->springSoftness.biasRate, c ); + float massScale = joint->springSoftness.massScale; + float impulseScale = joint->springSoftness.impulseScale; b3Vec3 cdot = b3Sub( wB, wA ); - b3Vec3 angularImpulse = b3Vec3_zero; - // Solve spring - if ( joint->enableSpring ) + b3Vec3 impulse = b3MulSub( b3MulSV( -massScale, b3MulMV( joint->rotationMass, b3Add( cdot, bias ) ) ), + impulseScale, joint->springImpulse ); + joint->springImpulse = b3Add( joint->springImpulse, impulse ); + + wA = b3Sub( wA, b3MulMV( iA, impulse ) ); + wB = b3Add( wB, b3MulMV( iB, impulse ) ); + } + + if ( joint->enableMotor && fixedRotation == false ) + { + b3Vec3 cdot = b3Sub( wB, wA ); + + b3Vec3 lambda = b3Neg( b3MulMV( joint->rotationMass, b3Sub( cdot, joint->motorVelocity ) ) ); + b3Vec3 newImpulse = b3Add( joint->motorImpulse, lambda ); + float length = b3Length( newImpulse ); + float maxImpulse = joint->maxMotorTorque * context->h; + if ( length > maxImpulse ) { - // Rotation constraint error - b3Vec3 deltaRotation = b3DeltaQuatToRotation( relQ, joint->targetRotation ); - b3Vec3 c = b3Neg( b3RotateVector( quatA, deltaRotation ) ); - - b3Vec3 bias = b3MulSV( joint->springSoftness.biasRate, c ); - float massScale = joint->springSoftness.massScale; - float impulseScale = joint->springSoftness.impulseScale; - - b3Vec3 impulse = b3MulSub( b3MulSV( -massScale, b3MulMV( joint->rotationMass, b3Add( cdot, bias ) ) ), - impulseScale, joint->springImpulse ); - joint->springImpulse = b3Add( joint->springImpulse, impulse ); - - cdot = b3Add( cdot, b3MulMV( invInertiaSum, impulse ) ); - angularImpulse = b3Add( angularImpulse, impulse ); + newImpulse = b3MulSV( maxImpulse / length, newImpulse ); } - if ( joint->enableMotor ) + lambda = b3Sub( newImpulse, joint->motorImpulse ); + joint->motorImpulse = newImpulse; + + wA = b3Sub( wA, b3MulMV( iA, lambda ) ); + wB = b3Add( wB, b3MulMV( iB, lambda ) ); + } + + if ( joint->enableTwistLimit && fixedRotation == false ) + { + float twistAngle = b3GetTwistAngle( relQ ); + + // todo does an updated twist axis help? + + b3Vec3 twistJacobian = joint->twistJacobian; + + // Lower limit { - // todo it might be more accurate to have the motor velocity in frameA due to sub-stepping. - b3Vec3 lambda = b3Neg( b3MulMV( joint->rotationMass, b3Sub( cdot, joint->motorVelocity ) ) ); - b3Vec3 newImpulse = b3Add( joint->motorImpulse, lambda ); - float length = b3Length( newImpulse ); - float maxImpulse = joint->maxMotorTorque * context->h; - if ( length > maxImpulse ) + float c = twistAngle - joint->lowerTwistAngle; + float bias = 0.0f; + float massScale = 1.0f; + float impulseScale = 0.0f; + if ( c > 0.0f ) { - newImpulse = b3MulSV( maxImpulse / length, newImpulse ); + // speculation + bias = c * context->inv_h; + } + else if ( useBias ) + { + bias = base->constraintSoftness.biasRate * c; + massScale = base->constraintSoftness.massScale; + impulseScale = base->constraintSoftness.impulseScale; } - lambda = b3Sub( newImpulse, joint->motorImpulse ); - joint->motorImpulse = newImpulse; + float cdot = b3Dot( b3Sub( wB, wA ), twistJacobian ); + float oldImpulse = joint->lowerTwistImpulse; + float deltaImpulse = -massScale * joint->twistMass * ( cdot + bias ) - impulseScale * oldImpulse; + joint->lowerTwistImpulse = b3MaxFloat( oldImpulse + deltaImpulse, 0.0f ); + deltaImpulse = joint->lowerTwistImpulse - oldImpulse; - cdot = b3Add( cdot, b3MulMV( invInertiaSum, lambda ) ); - angularImpulse = b3Add( angularImpulse, lambda ); + wA = b3MulSub( wA, deltaImpulse, b3MulMV( iA, twistJacobian ) ); + wB = b3MulAdd( wB, deltaImpulse, b3MulMV( iB, twistJacobian ) ); } - if ( joint->enableTwistLimit ) + // Upper limit { - float twistAngle = b3GetTwistAngle( relQ ); - - // todo does an updated twist axis help? - - b3Vec3 twistJacobian = joint->twistJacobian; - b3Vec3 twistResponse = b3MulMV( invInertiaSum, twistJacobian ); - - // Lower limit - { - float c = twistAngle - joint->lowerTwistAngle; - float bias = 0.0f; - float massScale = 1.0f; - float impulseScale = 0.0f; - if ( c > 0.0f ) - { - // speculation - bias = c * context->inv_h; - } - else if ( useBias ) - { - bias = base->constraintSoftness.biasRate * c; - massScale = base->constraintSoftness.massScale; - impulseScale = base->constraintSoftness.impulseScale; - } - - float twistCdot = b3Dot( cdot, twistJacobian ); - float oldImpulse = joint->lowerTwistImpulse; - float deltaImpulse = - b3MaxFloat( -massScale * joint->twistMass * ( twistCdot + bias ) - impulseScale * oldImpulse, -oldImpulse ); - joint->lowerTwistImpulse = oldImpulse + deltaImpulse; - - cdot = b3MulAdd( cdot, deltaImpulse, twistResponse ); - angularImpulse = b3MulAdd( angularImpulse, deltaImpulse, twistJacobian ); - } - - // Upper limit - { - float c = joint->upperTwistAngle - twistAngle; - float bias = 0.0f; - float massScale = 1.0f; - float impulseScale = 0.0f; - if ( c > 0.0f ) - { - // speculation - bias = c * context->inv_h; - } - else if ( useBias ) - { - bias = base->constraintSoftness.biasRate * c; - massScale = base->constraintSoftness.massScale; - impulseScale = base->constraintSoftness.impulseScale; - } - - // sign flipped on Cdot - float twistCdot = -b3Dot( cdot, twistJacobian ); - float oldImpulse = joint->upperTwistImpulse; - float deltaImpulse = - b3MaxFloat( -massScale * joint->twistMass * ( twistCdot + bias ) - impulseScale * oldImpulse, -oldImpulse ); - joint->upperTwistImpulse = oldImpulse + deltaImpulse; - - // sign flipped on applied impulse - cdot = b3MulSub( cdot, deltaImpulse, twistResponse ); - angularImpulse = b3MulSub( angularImpulse, deltaImpulse, twistJacobian ); - } - } - - if ( joint->enableConeLimit ) - { - float swingAngle = b3GetSwingAngle( relQ ); - - // todo does an updated swing axis help? - // b3Vec3 axisA = b3RotateVector( quatA, b3Vec3_axisZ ); - // b3Vec3 axisB = b3RotateVector( quatB, b3Vec3_axisZ ); - // b3Vec3 swingAxis = b3Normalize( b3Cross( axisA, axisB ) ); - // joint->swingAxis = swingAxis; - - b3Vec3 swingAxis = joint->swingAxis; - - float c = joint->coneAngle - swingAngle; + float c = joint->upperTwistAngle - twistAngle; float bias = 0.0f; float massScale = 1.0f; float impulseScale = 0.0f; @@ -596,18 +549,56 @@ void b3SolveSphericalJoint( b3JointSim* base, b3StepContext* context, bool useBi } // sign flipped on Cdot - float swingCdot = -b3Dot( cdot, swingAxis ); - float oldImpulse = joint->swingImpulse; - float deltaImpulse = - b3MaxFloat( -massScale * joint->swingMass * ( swingCdot + bias ) - impulseScale * oldImpulse, -oldImpulse ); - joint->swingImpulse = oldImpulse + deltaImpulse; + float cdot = b3Dot( b3Sub( wA, wB ), twistJacobian ); + float oldImpulse = joint->upperTwistImpulse; + float deltaImpulse = -massScale * joint->twistMass * ( cdot + bias ) - impulseScale * oldImpulse; + joint->upperTwistImpulse = b3MaxFloat( oldImpulse + deltaImpulse, 0.0f ); + deltaImpulse = joint->upperTwistImpulse - oldImpulse; // sign flipped on applied impulse - angularImpulse = b3MulSub( angularImpulse, deltaImpulse, swingAxis ); + wA = b3MulAdd( wA, deltaImpulse, b3MulMV( iA, twistJacobian ) ); + wB = b3MulSub( wB, deltaImpulse, b3MulMV( iB, twistJacobian ) ); + } + } + + if ( joint->enableConeLimit && fixedRotation == false ) + { + float swingAngle = b3GetSwingAngle( relQ ); + + // todo does an updated swing axis help? + // b3Vec3 axisA = b3RotateVector( quatA, b3Vec3_axisZ ); + // b3Vec3 axisB = b3RotateVector( quatB, b3Vec3_axisZ ); + // b3Vec3 swingAxis = b3Normalize( b3Cross( axisA, axisB ) ); + // joint->swingAxis = swingAxis; + + b3Vec3 swingAxis = joint->swingAxis; + + float c = joint->coneAngle - swingAngle; + float bias = 0.0f; + float massScale = 1.0f; + float impulseScale = 0.0f; + if ( c > 0.0f ) + { + // speculation + bias = c * context->inv_h; + } + else if ( useBias ) + { + bias = base->constraintSoftness.biasRate * c; + massScale = base->constraintSoftness.massScale; + impulseScale = base->constraintSoftness.impulseScale; } - wA = b3Sub( wA, b3MulMV( iA, angularImpulse ) ); - wB = b3Add( wB, b3MulMV( iB, angularImpulse ) ); + // sign flipped on Cdot + float cdot = b3Dot( b3Sub( wA, wB ), swingAxis ); + float oldImpulse = joint->swingImpulse; + float deltaImpulse = -massScale * joint->swingMass * ( cdot + bias ) - impulseScale * oldImpulse; + joint->swingImpulse = b3MaxFloat( oldImpulse + deltaImpulse, 0.0f ); + deltaImpulse = joint->swingImpulse - oldImpulse; + + // sign flipped on applied impulse + wA = b3MulAdd( wA, deltaImpulse, b3MulMV( iA, swingAxis ) ); + wB = b3MulSub( wB, deltaImpulse, b3MulMV( iB, swingAxis ) ); } // Solve point-to-point constraint @@ -633,7 +624,17 @@ void b3SolveSphericalJoint( b3JointSim* base, b3StepContext* context, bool useBi impulseScale = base->constraintSoftness.impulseScale; } - b3Vec3 b = b3SolvePointConstraint( mA, mB, base->invIA, base->invIB, rA, rB, b3Add( cdot, bias ) ); + //// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] + b3Matrix3 sA = b3Skew( rA ); + b3Matrix3 sB = b3Skew( rB ); + b3Matrix3 kA = b3MulMM( sA, b3MulMM( base->invIA, sA ) ); + b3Matrix3 kB = b3MulMM( sB, b3MulMM( base->invIB, sB ) ); + b3Matrix3 k = b3NegateMat3( b3AddMM( kA, kB ) ); + k.cx.x += mA + mB; + k.cy.y += mA + mB; + k.cz.z += mA + mB; + + b3Vec3 b = b3Solve3( k, b3Add( cdot, bias ) ); b3Vec3 impulse = b3MulSub( b3MulSV( -massScale, b ), impulseScale, joint->linearImpulse ); joint->linearImpulse = b3Add( joint->linearImpulse, impulse ); diff --git a/src/table.c b/src/table.c index dc13c33..fb066b8 100644 --- a/src/table.c +++ b/src/table.c @@ -52,6 +52,25 @@ void b3ClearSet( b3HashSet* set ) memset( set->items, 0, set->capacity * sizeof( b3SetItem ) ); } +// I need a good hash because the keys are built from pairs of increasing integers. +// A simple hash like hash = (integer1 XOR integer2) has many collisions. +// https://lemire.me/blog/2018/08/15/fast-strongly-universal-64-bit-hashing-everywhere/ +// https://preshing.com/20130107/this-hash-set-is-faster-than-a-judy-array/ +// todo try: https://www.jandrewrogers.com/2019/02/12/fast-perfect-hashing/ +// todo try: +// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/ +static inline uint32_t b3KeyHash( uint64_t key ) +{ + uint64_t h = key; + h ^= h >> 33; + h *= 0xff51afd7ed558ccdL; + h ^= h >> 33; + h *= 0xc4ceb9fe1a85ec53L; + h ^= h >> 33; + + return (uint32_t)h; +} + static int32_t b3FindSlot( const b3HashSet* set, uint64_t key, uint32_t hash ) { uint32_t capacity = set->capacity; @@ -120,15 +139,6 @@ bool b3ContainsKey( const b3HashSet* set, uint64_t key ) return set->items[index].key == key; } -// The caller already has the hash, which lets a batch prefetch the slots before probing them. -bool b3ContainsHashedKey( const b3HashSet* set, uint64_t key, uint32_t hash ) -{ - B3_ASSERT( key != 0 ); - B3_ASSERT( hash == b3KeyHash( key ) ); - int32_t index = b3FindSlot( set, key, hash ); - return set->items[index].key == key; -} - int b3GetHashSetBytes( b3HashSet* set ) { return set->capacity * (int)sizeof( b3SetItem ); diff --git a/src/table.h b/src/table.h index 9e12b99..ec8f397 100644 --- a/src/table.h +++ b/src/table.h @@ -3,31 +3,11 @@ #pragma once -#include "box3d/base.h" #include "box3d/constants.h" #include #include -// I need a good hash because the keys are built from pairs of increasing integers. -// A simple hash like hash = (integer1 XOR integer2) has many collisions. -// https://lemire.me/blog/2018/08/15/fast-strongly-universal-64-bit-hashing-everywhere/ -// https://preshing.com/20130107/this-hash-set-is-faster-than-a-judy-array/ -// todo try: https://www.jandrewrogers.com/2019/02/12/fast-perfect-hashing/ -// todo try: -// https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/ -B3_FORCE_INLINE uint32_t b3KeyHash( uint64_t key ) -{ - uint64_t h = key; - h ^= h >> 33; - h *= 0xff51afd7ed558ccdL; - h ^= h >> 33; - h *= 0xc4ceb9fe1a85ec53L; - h ^= h >> 33; - - return (uint32_t)h; -} - typedef struct b3SetItem { uint64_t key; @@ -69,6 +49,5 @@ bool b3AddKey( b3HashSet* set, uint64_t key ); bool b3RemoveKey( b3HashSet* set, uint64_t key ); bool b3ContainsKey( const b3HashSet* set, uint64_t key ); -bool b3ContainsHashedKey( const b3HashSet* set, uint64_t key, uint32_t hash ); int b3GetHashSetBytes( b3HashSet* set ); diff --git a/src/timer.c b/src/timer.c index 3fb46f7..826b149 100644 --- a/src/timer.c +++ b/src/timer.c @@ -23,8 +23,7 @@ #define WIN32_LEAN_AND_MEAN 1 #endif -// Lower-case windows.h intentionally for cross compiling on mingw. -#include +#include #include static double s_invFrequency = 0.0; @@ -169,27 +168,12 @@ static void b3SetCurrentThreadName( const char* name ) HMODULE kernel = GetModuleHandleW( L"kernel32.dll" ); if ( kernel != NULL ) { - // 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 ) + // MSVC /Wall warns C4191 on every FARPROC function-pointer cast. + // This is the intended use of GetProcAddress, so suppress locally. #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; } @@ -533,7 +517,7 @@ typedef struct b3Thread char name[NAME_LENGTH]; } b3Thread; -// macOS pthread_setname_np takes only the name, it always names the calling thread. +// macOS pthread_setname_np takes only the name — it always names the calling thread. static void b3SetCurrentThreadName( const char* name ) { if ( name == NULL || name[0] == 0 ) diff --git a/src/triangle_manifold.c b/src/triangle_manifold.c index 9bf5196..001ae05 100644 --- a/src/triangle_manifold.c +++ b/src/triangle_manifold.c @@ -14,14 +14,13 @@ #include #include -// cosine of hull normal versus edge axis tolerance. -#define B3_CROSSING_TOLERANCE 0.1f - typedef struct b3TriangleData { b3Vec3 v1, v2, v3; b3Vec3 e1, e2, e3; + b3Vec3 center; b3Plane plane; + int flags; } b3TriangleData; // Indexed by the 3-bit vertex mask @@ -52,7 +51,7 @@ static b3TriangleFeature b3GetTriangleFeature( const b3SimplexCache* cache ) return s_triangleFeatures[mask]; } -void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA, const b3Sphere* sphereB ) +void b3CollideSphereAndTriangle( b3LocalManifold* manifold, int capacity, const b3Sphere* sphereA, const b3Vec3* triangleB ) { manifold->pointCount = 0; @@ -61,8 +60,8 @@ void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const return; } - b3Vec3 center = sphereB->center; - b3Vec3 v1 = triangleA[0], v2 = triangleA[1], v3 = triangleA[2]; + b3Vec3 center = sphereA->center; + b3Vec3 v1 = triangleB[0], v2 = triangleB[1], v3 = triangleB[2]; b3Plane plane = b3MakePlaneFromPoints( v1, v2, v3 ); float offset = b3PlaneSeparation( plane, center ); @@ -72,23 +71,19 @@ void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const return; } - float radius = sphereB->radius; - // Closest point on triangle to sphere center b3TrianglePoint closest = b3ClosestPointOnTriangle( v1, v2, v3, center ); // Test separating axis float squaredDistance = b3DistanceSquared( closest.point, center ); float speculativeDistance = B3_SPECULATIVE_DISTANCE; - float maxDistance = radius + speculativeDistance; + float maxDistance = sphereA->radius + speculativeDistance; if ( squaredDistance > maxDistance * maxDistance ) { return; } float distance = sqrtf( squaredDistance ); - - // Normal points from triangle to sphere b3Vec3 normal; if ( distance * distance > 1000.0f * FLT_MIN ) { @@ -100,16 +95,16 @@ void b3CollideTriangleAndSphere( b3LocalManifold* manifold, int capacity, const } // contact point mid-way - // p = 0.5 * (c + q) - 0.5 * r * n - b3Vec3 contactPoint = b3MulSV( 0.5f, b3Add( b3Sub( center, b3MulSV( radius, normal ) ), closest.point ) ); + b3Vec3 contactPoint = b3MulSV( 0.5f, b3Add( b3Sub( center, b3MulSV( sphereA->radius, normal ) ), closest.point ) ); manifold->normal = normal; manifold->pointCount = 1; manifold->feature = closest.feature; + manifold->squaredDistance = squaredDistance; b3LocalManifoldPoint* mp = manifold->points + 0; mp->point = contactPoint; - mp->separation = distance - radius; + mp->separation = distance - sphereA->radius; mp->pair = b3FeaturePair_single; } @@ -142,7 +137,7 @@ static bool b3ClipSegmentToTriangleFace( b3ClipVertex segment[2], const b3Vec3* } // If the points are on different sides of the plane - if ( ( distance1 > 0.0f ) != ( distance2 > 0.0f ) ) + if ( distance1 * distance2 < 0.0f ) { // Find intersection point of edge and plane float t = distance1 / ( distance1 - distance2 ); @@ -162,87 +157,56 @@ static bool b3ClipSegmentToTriangleFace( b3ClipVertex segment[2], const b3Vec3* return true; } -static b3SeparatingAxis b3QueryTriangleFaceAndCapsule( b3Plane plane, const b3Capsule* capsule ) +static b3FaceQuery b3QueryTriangleFaceAndCapsule( b3Plane plane, const b3Capsule* capsule ) { float separation1 = b3PlaneSeparation( plane, capsule->center1 ); float separation2 = b3PlaneSeparation( plane, capsule->center2 ); if ( separation1 < separation2 ) { - return (b3SeparatingAxis){ - .normal = plane.normal, + return (b3FaceQuery){ .separation = separation1, - .indexA = 0, - .indexB = 0, + .faceIndex = 0, + .vertexIndex = 0, }; } - return (b3SeparatingAxis){ - .normal = plane.normal, + return (b3FaceQuery){ .separation = separation2, - .indexA = 0, - .indexB = 1, + .faceIndex = 0, + .vertexIndex = 1, }; } -static b3SeparatingAxis b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices, b3Plane plane, const b3Capsule* capsule ) +static b3EdgeQuery b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices, const b3Capsule* capsule ) { // Work in the local space of the capsule b3Vec3 p1 = capsule->center1; b3Vec3 p2 = capsule->center2; b3Vec3 capsuleEdge = b3Sub( p2, p1 ); + b3Vec3 capsuleCenter = b3Lerp( p1, p2, 0.5f ); + + b3Vec3 triangleCenter = b3MulSV( 1.0f / 3.0f, b3Add( vertices[0], b3Add( vertices[1], vertices[2] ) ) ); + // Find axis of minimum penetration - b3Vec3 maxNormal = b3Vec3_zero; float maxSeparation = -FLT_MAX; - int maxIndex1 = B3_NULL_INDEX; - int maxIndex2 = B3_NULL_INDEX; - float squaredTolerance = 0.005f * 0.005f; + int maxIndex1 = UINT8_MAX; + int maxIndex2 = UINT8_MAX; int edgeIndex = 2; - float a = b3Dot( capsuleEdge, plane.normal ); b3Vec3 v1 = vertices[2]; for ( int index = 0; index < 3; ++index ) { b3Vec3 v2 = vertices[index]; + b3Vec3 triangleEdge = b3Sub( v2, v1 ); - b3Vec3 sideNormal = b3Normalize( b3Cross( triangleEdge, plane.normal ) ); - - // Pretend the triangle edge embeds a zero area face with a side normal. This - // provides a way to find an edge-edge normal that points outward from - // the triangle. - float b = b3Dot( capsuleEdge, sideNormal ); - - // Is the capsule edge parallel to the triangle edge? If so, face contact can handle it. - if ( a * a + b * b < squaredTolerance * b3LengthSquared( capsuleEdge ) ) - { - v1 = v2; - edgeIndex = index; - continue; - } - - // Similar to hull vs hull (b3QueryEdgeDirections) - b3Vec3 axis; - if ( a * b <= 0.0f ) - { - float t = b / ( b - a ); - axis = b3Lerp( sideNormal, plane.normal, t ); - } - else - { - float t = b / ( a + b ); - axis = b3Lerp( sideNormal, b3Neg( plane.normal ), t ); - } - - B3_VALIDATE( b3LengthSquared( axis ) > 1000.0f * FLT_MIN ); - axis = b3Normalize( axis ); - float separation = b3Dot( axis, b3Sub( p1, v1 ) ); + float separation = b3EdgeEdgeSeparation( p1, capsuleEdge, capsuleCenter, v1, triangleEdge, triangleCenter ); if ( separation > maxSeparation ) { // Note: We don't exit early if we find a separating axis here since we want to // find the best one for caching and account for the convex radius later. - maxNormal = axis; maxSeparation = separation; maxIndex1 = edgeIndex; maxIndex2 = 0; @@ -253,16 +217,15 @@ static b3SeparatingAxis b3QueryTriangleAndCapsuleEdges( const b3Vec3* vertices, } // Save result - return (b3SeparatingAxis){ - .normal = maxNormal, + return (b3EdgeQuery){ .separation = maxSeparation, - .indexA = maxIndex1, - .indexB = maxIndex2, + .indexA = (uint8_t)maxIndex1, + .indexB = (uint8_t)maxIndex2, }; } -void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane, - const b3Capsule* capsule ) +static void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane, + const b3Capsule* capsule ) { B3_ASSERT( manifold->pointCount == 0 ); @@ -309,8 +272,8 @@ void b3BuildTriangleAndCapsuleFaceContact( b3LocalManifold* manifold, const b3Ve pt->pair = segment[1].pair; } -static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, const b3Vec3* triangle, b3Plane plane, - const b3Capsule* capsule, b3SeparatingAxis query ) +static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, const b3Vec3* triangle, const b3Capsule* capsule, + b3EdgeQuery query ) { B3_ASSERT( 0 <= query.indexA && query.indexA < 3 ); @@ -320,27 +283,20 @@ static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, con const b3Vec3* vs = triangle; + b3Vec3 triangleCenter = b3MulSV( 1.0f / 3.0f, b3Add( vs[0], b3Add( vs[1], vs[2] ) ) ); b3Vec3 v1 = vs[query.indexA]; b3Vec3 v2 = vs[( query.indexA + 1 ) % 3]; b3Vec3 triangleEdge = b3Sub( v2, v1 ); - b3Vec3 sideNormal = b3Normalize( b3Cross( triangleEdge, plane.normal ) ); + b3Vec3 normal = b3Cross( capsuleEdge, triangleEdge ); + normal = b3Normalize( normal ); - // Pretend the triangle edge embeds a zero area face with a side normal. This - // provides a way to find an edge-edge normal that points outward from - // the triangle. - float a = b3Dot( capsuleEdge, plane.normal ); - float b = b3Dot( capsuleEdge, sideNormal ); - - // Is the capsule edge parallel to the triangle edge? If so, face contact can handle it. - float squaredTolerance = 0.005f * 0.005f; - if ( a * a + b * b < squaredTolerance * b3LengthSquared( capsuleEdge ) ) + // Normal should point away from triangle center + if ( b3Dot( normal, b3Sub( v1, triangleCenter ) ) < 0.0f ) { - return; + normal = b3Neg( normal ); } - // Similar to hull vs hull (b3QueryEdgeDirections) - b3Vec3 normal = query.normal; b3SegmentDistanceResult result = b3LineDistance( v1, triangleEdge, p1, capsuleEdge ); if ( result.fraction1 < 0.0f || 1.0f < result.fraction1 || result.fraction2 < 0.0f || 1.0f < result.fraction2 ) @@ -349,8 +305,10 @@ static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, con return; } - b3Vec3 point = b3Lerp( result.point1, b3MulSub( result.point2, capsule->radius, normal ), 0.5f ); - float separation = b3Dot( normal, b3Sub( p1, v1 ) ); + b3Vec3 point = b3Lerp( b3MulSub( result.point1, capsule->radius, normal ), result.point2, 0.5f ); + + float separation = b3Dot( normal, b3Sub( result.point2, result.point1 ) ); + B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP ); manifold->normal = normal; manifold->pointCount = 1; @@ -364,7 +322,7 @@ static void b3BuildTriangleAndCapsuleEdgeContact( b3LocalManifold* manifold, con pt->pair = b3MakeFeaturePair( b3_featureShapeA, query.indexA, b3_featureShapeB, query.indexB ); } -void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const b3Vec3* triangleA, const b3Capsule* capsuleB, +void b3CollideCapsuleAndTriangle( b3LocalManifold* manifold, int capacity, const b3Capsule* capsuleA, const b3Vec3* triangleB, b3SimplexCache* cache ) { manifold->pointCount = 0; @@ -374,9 +332,9 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const return; } - b3Vec3 v1 = triangleA[0], v2 = triangleA[1], v3 = triangleA[2]; + b3Vec3 v1 = triangleB[0], v2 = triangleB[1], v3 = triangleB[2]; b3Plane plane = b3MakePlaneFromPoints( v1, v2, v3 ); - b3Vec3 capsuleCenter = b3Lerp( capsuleB->center1, capsuleB->center2, 0.5f ); + b3Vec3 capsuleCenter = b3Lerp( capsuleA->center1, capsuleA->center2, 0.5f ); float offset = b3PlaneSeparation( plane, capsuleCenter ); if ( offset < 0.0f ) @@ -386,15 +344,15 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const } b3DistanceInput distanceInput; - distanceInput.proxyA = (b3ShapeProxy){ triangleA, 3, 0.0f }; - distanceInput.proxyB = (b3ShapeProxy){ &capsuleB->center1, 2, 0.0f }; + distanceInput.proxyA = (b3ShapeProxy){ triangleB, 3, 0.0f }; + distanceInput.proxyB = (b3ShapeProxy){ &capsuleA->center1, 2, 0.0f }; distanceInput.transform = b3Transform_identity; distanceInput.useRadii = false; b3DistanceOutput distanceOutput = b3ShapeDistance( &distanceInput, cache, NULL, 0 ); - float speculativeDistance = B3_SPECULATIVE_DISTANCE; - float radius = capsuleB->radius; - if ( distanceOutput.distance > radius + speculativeDistance ) + + float radius = capsuleA->radius; + if ( distanceOutput.distance > radius + B3_SPECULATIVE_DISTANCE ) { // Shapes are separated, persist the cache return; @@ -412,14 +370,14 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const { // Clip capsule segment against side planes of reference face b3ClipVertex segment[2]; - segment[0].position = capsuleB->center1; + segment[0].position = capsuleA->center1; segment[0].separation = 0.0f; segment[0].pair = b3MakeFeaturePair( b3_featureShapeA, 0, b3_featureShapeA, 0 ); - segment[1].position = capsuleB->center2; + segment[1].position = capsuleA->center2; segment[1].separation = 0.0f; segment[1].pair = b3MakeFeaturePair( b3_featureShapeA, 1, b3_featureShapeA, 1 ); - bool havePoints = b3ClipSegmentToTriangleFace( segment, triangleA, plane ); + bool havePoints = b3ClipSegmentToTriangleFace( segment, triangleB, plane ); if ( havePoints == true ) { @@ -430,7 +388,6 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const b3Vec3 point1 = b3MulSub( segment[0].position, 0.5f * ( radius + distance1 ), normal ); b3Vec3 point2 = b3MulSub( segment[1].position, 0.5f * ( radius + distance2 ), normal ); - // Normal points from triangle to capsule manifold->normal = normal; manifold->feature = b3_featureTriangleFace; manifold->pointCount = 2; @@ -449,10 +406,9 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const } } - // Create contact from closest points. - b3Vec3 point = b3Lerp( distanceOutput.pointA, b3MulSub( distanceOutput.pointB, radius, delta ), 0.5f ); + // Create contact from closest points + b3Vec3 point = b3MulSV( 0.5f, b3Add( b3Sub( distanceOutput.pointA, b3MulSV( radius, delta ) ), distanceOutput.pointB ) ); - // Normal points from triangle to capsule. manifold->normal = delta; manifold->pointCount = 1; manifold->feature = b3GetTriangleFeature( cache ); @@ -467,44 +423,38 @@ void b3CollideTriangleAndCapsule( b3LocalManifold* manifold, int capacity, const // Deep penetration - b3SeparatingAxis faceQuery = b3QueryTriangleFaceAndCapsule( plane, capsuleB ); + b3FaceQuery faceQuery = b3QueryTriangleFaceAndCapsule( plane, capsuleA ); if ( faceQuery.separation > radius ) { - // Shapes are separated. Should be impossible for a reasonable capsule radius. + // Shapes are separated return; } - b3SeparatingAxis edgeQuery = b3QueryTriangleAndCapsuleEdges( triangleA, plane, capsuleB ); + b3EdgeQuery edgeQuery = b3QueryTriangleAndCapsuleEdges( triangleB, capsuleA ); if ( edgeQuery.separation > radius ) { - // Shapes are separated. Should be impossible for a reasonable capsule radius. + // Shapes are separated return; } // Create face contact float faceSeparation = faceQuery.separation - radius; - b3BuildTriangleAndCapsuleFaceContact( manifold, triangleA, plane, capsuleB ); - B3_VALIDATE( manifold->pointCount == 0 || manifold->pointCount == 2 ); + b3BuildTriangleAndCapsuleFaceContact( manifold, triangleB, plane, capsuleA ); if ( manifold->pointCount == 2 ) { - // This becomes the clipped separation. faceSeparation = b3MinFloat( manifold->points[0].separation, manifold->points[1].separation ); } - - if ( edgeQuery.indexA == B3_NULL_INDEX ) - { - // No valid edge contact. - return; - } + B3_VALIDATE( faceSeparation <= 0.0f ); // Face contact can be empty if it does not realize the axis of minimum penetration. // Create edge contact if face contact fails or edge contact is significantly better! - float linearSlop = B3_LINEAR_SLOP; + const float kRelEdgeTolerance = 0.50f; + const float kAbsTolerance = 1.0f * B3_LINEAR_SLOP; float edgeSeparation = edgeQuery.separation - radius; - if ( manifold->pointCount == 0 || edgeSeparation > faceSeparation + linearSlop ) + if ( manifold->pointCount == 0 || edgeSeparation > kRelEdgeTolerance * faceSeparation + kAbsTolerance ) { // Edge contact - b3BuildTriangleAndCapsuleEdgeContact( manifold, triangleA, plane, capsuleB, edgeQuery ); + b3BuildTriangleAndCapsuleEdgeContact( manifold, triangleB, capsuleA, edgeQuery ); } } @@ -529,35 +479,31 @@ static inline int b3GetTriangleSupport( b3Vec3* points, b3Vec3 direction ) return index; } -static b3SeparatingAxis b3QueryTriangleFace( const b3TriangleData* triangle, const b3HullData* hull ) +static b3FaceQuery b3QueryTriangleFace( const b3TriangleData* triangle, const b3HullData* hull ) { const b3Vec3* hullPoints = b3GetHullPoints( hull ); b3Plane plane = triangle->plane; - b3Vec3 normal = b3Neg( plane.normal ); - int vertexIndex = b3FindHullSupportVertex( hull, normal ); + int vertexIndex = b3FindHullSupportVertex( hull, b3Neg( plane.normal ) ); b3Vec3 support = hullPoints[vertexIndex]; float separation = b3PlaneSeparation( plane, support ); - return (b3SeparatingAxis){ - .normal = plane.normal, + return (b3FaceQuery){ .separation = separation, - .indexA = 0, - .indexB = vertexIndex, - .type = b3_faceAxisA, + .faceIndex = 0, + .vertexIndex = (uint8_t)vertexIndex, }; } -static b3SeparatingAxis b3QueryHullFace( const b3TriangleData* triangle, const b3HullData* hull ) +static b3FaceQuery b3QueryHullFace( const b3TriangleData* triangle, const b3HullData* hull ) { const b3Plane* hullPlanes = b3GetHullPlanes( hull ); int faceCount = hull->faceCount; b3Vec3 trianglePoints[] = { triangle->v1, triangle->v2, triangle->v3 }; - b3Vec3 maxNormal = b3Vec3_zero; - float maxFaceSeparation = -INFINITY; - int maxFaceIndex = B3_NULL_INDEX; - int maxVertexIndex = B3_NULL_INDEX; + int maxFaceIndex = -1; + int maxVertexIndex = -1; + float maxFaceSeparation = -FLT_MAX; for ( int faceIndex = 0; faceIndex < faceCount; ++faceIndex ) { @@ -568,43 +514,44 @@ static b3SeparatingAxis b3QueryHullFace( const b3TriangleData* triangle, const b float separation = b3PlaneSeparation( plane, support ); if ( separation > maxFaceSeparation ) { - maxNormal = plane.normal; - maxFaceSeparation = separation; maxFaceIndex = faceIndex; maxVertexIndex = vertexIndex; + maxFaceSeparation = separation; } } - // Normal points from triangle to hull - return (b3SeparatingAxis){ - .normal = b3Neg( maxNormal ), + return (b3FaceQuery){ .separation = maxFaceSeparation, - .indexA = maxVertexIndex, - .indexB = maxFaceIndex, - .type = b3_faceAxisB, + .faceIndex = maxFaceIndex, + .vertexIndex = maxVertexIndex, }; } -// A: hull, B: triangle -static b3SeparatingAxis b3QueryTriangleAndHullEdges( const b3TriangleData* triangle, const b3HullData* hull ) +static b3EdgeQuery b3TestEdgePairs( const b3TriangleData* triangle, const b3HullData* hull ) { - b3SeparatingAxis result = { - .normal = b3Vec3_zero, - .separation = -INFINITY, + b3EdgeQuery result = { + .separation = -FLT_MAX, .indexA = B3_NULL_INDEX, .indexB = B3_NULL_INDEX, - .type = b3_edgePairAxis, }; b3Vec3 trianglePoints[] = { triangle->v1, triangle->v2, triangle->v3 }; b3Vec3 triangleEdges[] = { triangle->e1, triangle->e2, triangle->e3 }; + // int edgeFlags[] = { b3_concaveEdge1, b3_concaveEdge1, b3_concaveEdge3 }; + +#if B3_FORCE_GHOST_COLLISIONS + int triangleFlags = 0xFF; +#else + int triangleFlags = triangle->flags; +#endif + (void)triangleFlags; + b3Vec3 triNormal = triangle->plane.normal; const b3HullHalfEdge* hullEdges = b3GetHullEdges( hull ); const b3Vec3* hullPoints = b3GetHullPoints( hull ); const b3Plane* hullPlanes = b3GetHullPlanes( hull ); int edgeCount = hull->edgeCount; - float squaredTolerance = 0.005f * 0.005f; for ( int i = 0; i < edgeCount; i += 2 ) { @@ -630,27 +577,14 @@ static b3SeparatingAxis b3QueryTriangleAndHullEdges( const b3TriangleData* trian continue; } - // Avoid nearly parallel edges that may lead to invalid separation values at the noise floor. - if ( b3MaxFloat( cab * cab, dab * dab ) < squaredTolerance * b3LengthSquared( triEdge ) ) - { - continue; - } - - // Similar to hull vs hull (b3QueryEdgeDirections) - // dot(hullNormal1 + t * (hullNormal2 - hullNormal1), triEdge) = 0 - // Normal points out of hull by construction. - float t = cab / ( cab - dab ); - b3Vec3 axis = b3Lerp( hullNormal1, hullNormal2, t ); - B3_VALIDATE( b3LengthSquared( axis ) > 1000.0f * FLT_MIN ); - axis = b3Normalize( axis ); - float separation = b3Dot( axis, b3Sub( trianglePoints[j], hullPoint ) ); + b3Vec3 triPoint = trianglePoints[j]; + float separation = b3EdgeEdgeSeparation( triPoint, triEdge, triangle->center, hullPoint, hullEdge, hull->center ); + // if ( separation > result.separation && ( edgeFlags[j] & triangleFlags ) == 0 ) if ( separation > result.separation ) { // Note: We don't exit early if we find a separating axis here since we want to // find the best one for caching. - // Flip normal to point from triangle to hull. - result.normal = b3Neg( axis ); result.separation = separation; result.indexA = j; result.indexB = i; @@ -661,13 +595,9 @@ static b3SeparatingAxis b3QueryTriangleAndHullEdges( const b3TriangleData* trian return result; } -static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, const b3TriangleData* triangle, - const b3HullData* hull, b3SeparatingAxis query, b3SATCache* cache, bool enableSpeculative ) +static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, const b3TriangleData* triangle, const b3HullData* hull, + b3FaceQuery query, b3SATCache* cache ) { - B3_VALIDATE( query.type == b3_faceAxisB ); - B3_VALIDATE( 0 <= query.indexA && query.indexA < 3 ); - B3_VALIDATE( 0 <= query.indexB && query.indexB < hull->faceCount ); - manifold->pointCount = 0; const b3HullFace* hullFaces = b3GetHullFaces( hull ); @@ -676,7 +606,8 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co const b3Vec3* hullPoints = b3GetHullPoints( hull ); // Reference hull face - b3Plane refPlane = hullPlanes[query.indexB]; + int refFace = query.faceIndex; + b3Plane refPlane = hullPlanes[refFace]; // Build clip polygon from triangle face (the incident face) b3ClipVertex buffer1[B3_MAX_CLIP_POINTS], buffer2[B3_MAX_CLIP_POINTS]; @@ -699,7 +630,7 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co b3ClipVertex* input = buffer1; b3ClipVertex* output = buffer2; - const b3HullFace* face = hullFaces + query.indexB; + const b3HullFace* face = hullFaces + refFace; int edgeIndex = face->edge; do @@ -732,31 +663,23 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co pointCount = b3MinInt( pointCount, pointCapacity ); float minSeparation = FLT_MAX; - int finalPointCount = 0; for ( int i = 0; i < pointCount; ++i ) { b3ClipVertex* clipPoint = input + i; - minSeparation = b3MinFloat( minSeparation, clipPoint->separation ); - - if ( enableSpeculative == false && clipPoint->separation > B3_MESH_REST_OFFSET ) - { - continue; - } // Move point onto hull face improved culling b3Vec3 point = b3MulSub( clipPoint->position, clipPoint->separation, refPlane.normal ); - b3LocalManifoldPoint* pt = manifold->points + finalPointCount; + b3LocalManifoldPoint* pt = manifold->points + i; pt->point = point; pt->separation = clipPoint->separation; pt->pair = b3FlipPair( clipPoint->pair ); - finalPointCount += 1; + minSeparation = b3MinFloat( minSeparation, clipPoint->separation ); } - float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET; - if ( minSeparation > speculativeDistance ) + if ( minSeparation > B3_SPECULATIVE_DISTANCE ) { // This can occur with a stale SAT cache manifold->pointCount = 0; @@ -764,24 +687,21 @@ static float b3CollideHullFace( b3LocalManifold* manifold, int pointCapacity, co return minSeparation; } - manifold->pointCount = finalPointCount; + manifold->pointCount = pointCount; manifold->normal = b3Neg( refPlane.normal ); manifold->feature = b3_featureHullFace; // Save cache cache->separation = minSeparation; cache->type = b3_faceAxisB; - cache->indexA = (uint8_t)query.indexA; - cache->indexB = (uint8_t)query.indexB; + cache->indexA = (uint8_t)query.vertexIndex; + cache->indexB = (uint8_t)query.faceIndex; return minSeparation; } static float b3CollideTriangleFace( b3LocalManifold* manifold, int pointCapacity, const b3TriangleData* triangle, - const b3HullData* hull, b3SeparatingAxis query, b3SATCache* cache, bool enableSpeculative ) + const b3HullData* hull, b3FaceQuery query, b3SATCache* cache ) { - B3_VALIDATE( query.type == b3_faceAxisA ); - B3_VALIDATE( query.indexA == 0 ); - B3_VALIDATE( 0 <= query.indexB && query.indexB < hull->vertexCount ); B3_VALIDATE( manifold->pointCount == 0 ); const b3HullFace* hullFaces = b3GetHullFaces( hull ); @@ -789,9 +709,10 @@ static float b3CollideTriangleFace( b3LocalManifold* manifold, int pointCapacity const b3Vec3* hullPoints = b3GetHullPoints( hull ); // Find incident face + B3_ASSERT( query.faceIndex == 0 ); b3Plane refPlane = triangle->plane; - int incFace = b3FindIncidentFace( hull, refPlane.normal, query.indexB ); + int incFace = b3FindIncidentFace( hull, refPlane.normal, query.vertexIndex ); // Build clip polygon from incident face b3ClipVertex buffer1[2 * B3_MAX_CLIP_POINTS], buffer2[2 * B3_MAX_CLIP_POINTS]; @@ -849,57 +770,48 @@ static float b3CollideTriangleFace( b3LocalManifold* manifold, int pointCapacity float minSeparation = FLT_MAX; - int finalPointCount = 0; for ( int i = 0; i < pointCount; ++i ) { b3ClipVertex* clipPoint = input + i; - minSeparation = b3MinFloat( minSeparation, clipPoint->separation ); - - if ( enableSpeculative == false && clipPoint->separation > B3_MESH_REST_OFFSET ) - { - continue; - } // Move point onto triangle surface for improved culling // b3Vec3 point = b3MulSub( clipPoint->position, clipPoint->separation, refPlane.normal ); b3Vec3 point = clipPoint->position; - b3LocalManifoldPoint* pt = manifold->points + finalPointCount; + b3LocalManifoldPoint* pt = manifold->points + i; pt->point = point; pt->separation = clipPoint->separation; pt->pair = clipPoint->pair; - finalPointCount += 1; + minSeparation = b3MinFloat( minSeparation, clipPoint->separation ); } - float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET; - if ( minSeparation >= speculativeDistance ) + if ( minSeparation >= B3_SPECULATIVE_DISTANCE ) { // This can happens if the objects move a part while re-using a cached axis *cache = (b3SATCache){ 0 }; return minSeparation; } - manifold->pointCount = finalPointCount; + manifold->pointCount = pointCount; manifold->normal = refPlane.normal; manifold->feature = b3_featureTriangleFace; // Save cache cache->separation = minSeparation; cache->type = b3_faceAxisA; - cache->indexA = (uint8_t)query.indexA; - cache->indexB = (uint8_t)query.indexB; + cache->indexA = (uint8_t)query.faceIndex; + cache->indexB = (uint8_t)query.vertexIndex; return minSeparation; } -static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capacity, b3Vec3 trianglePoint, b3Vec3 triangleEdge, - const b3HullData* hull, b3SeparatingAxis query, b3SATCache* cache ) +static void b3CollideHullAndTriangleEdges( b3LocalManifold* manifold, int capacity, b3Vec3 trianglePoint, b3Vec3 triangleEdge, + b3Vec3 triangleCenter, const b3HullData* hull, b3EdgeQuery query, b3SATCache* cache ) { - B3_VALIDATE( query.type == b3_edgePairAxis ); - B3_VALIDATE( 0 <= query.indexA && query.indexA < 3 ); - B3_VALIDATE( 0 <= query.indexB && query.indexB < hull->edgeCount ); B3_VALIDATE( query.separation <= 2.0f * B3_SPECULATIVE_DISTANCE ); + B3_ASSERT( query.indexA < 3 ); + b3Vec3 cA = triangleCenter; b3Vec3 pA = trianglePoint; b3Vec3 eA = triangleEdge; @@ -911,12 +823,37 @@ static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capaci b3Vec3 qB = pointsB[twinB->origin]; b3Vec3 eB = b3Sub( qB, pB ); + b3Vec3 normal = b3Cross( eA, eB ); + normal = b3Normalize( normal ); + + // Ensure normal points outward from triangle center + float outwardA = b3Dot( normal, b3Sub( pA, cA ) ); + + // Ensure normal points towards hull center + float outwardB = b3Dot( normal, b3Sub( hull->center, pB ) ); + + // Use the largest magnitude. The triangle outward value + // may be unreliable as some angles. + if ( b3AbsFloat( outwardA ) > b3AbsFloat( outwardB ) ) + { + if ( outwardA < 0.0f ) + { + normal = b3Neg( normal ); + } + } + else + { + if ( outwardB < 0.0f ) + { + normal = b3Neg( normal ); + } + } + // Get the closest points between the infinite edge lines b3SegmentDistanceResult result = b3LineDistance( pA, eA, pB, eB ); // Is one of the closest points outside of the associated edge segment? - if ( capacity == 0 || result.fraction1 < 0.0f || 1.0f < result.fraction1 || result.fraction2 < 0.0f || - 1.0f < result.fraction2 ) + if ( capacity == 0 || result.fraction1 < 0.0f || 1.0f < result.fraction1 || result.fraction2 < 0.0f || 1.0f < result.fraction2 ) { // Invalid edge pair, no points generated B3_ASSERT( manifold->pointCount == 0 ); @@ -924,7 +861,10 @@ static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capaci return; } - float separation = b3Dot( query.normal, b3Sub( pB, pA ) ); + // This can slide off the end from caching + float separation = b3Dot( normal, b3Sub( result.point2, result.point1 ) ); + B3_VALIDATE( b3AbsFloat( separation - query.separation ) < B3_LINEAR_SLOP ); + b3Vec3 point = b3MulSV( 0.5f, b3Add( result.point1, result.point2 ) ); b3LocalManifoldPoint* pt = manifold->points + 0; @@ -938,45 +878,30 @@ static void b3CollideTriangleAndHullEdges( b3LocalManifold* manifold, int capaci cache->indexA = (uint8_t)query.indexA; cache->indexB = (uint8_t)query.indexB; - manifold->normal = query.normal; + manifold->normal = normal; manifold->pointCount = 1; b3TriangleFeature edgesFeatures[] = { b3_featureEdge1, b3_featureEdge2, b3_featureEdge3 }; manifold->feature = edgesFeatures[query.indexA]; } -// Triangle face contact wrapper. -void b3BuildTriangleAndHullFaceContact( b3LocalManifold* manifold, int capacity, const b3Vec3* triangle, const b3HullData* hull, - b3SATCache* cache, bool enableSpeculative ) +// See "Collision Detection of Convex Polyhedra Based on Duality Transformation" +// Simplified for triangle versus hull +static inline bool b3IsTriangleMinkowskiFace( b3Vec3 triNormal, b3Vec3 triEdge, b3Vec3 hullNormal1, b3Vec3 hullNormal2, + b3Vec3 hullEdge ) { - manifold->pointCount = 0; - - b3TriangleData triangleData = { - .v1 = triangle[0], - .v2 = triangle[1], - .v3 = triangle[2], - .e1 = b3Sub( triangle[1], triangle[0] ), - .e2 = b3Sub( triangle[2], triangle[1] ), - .e3 = b3Sub( triangle[0], triangle[2] ), - .plane = b3MakePlaneFromPoints( triangle[0], triangle[1], triangle[2] ), - }; - - b3SeparatingAxis query = b3QueryTriangleFace( &triangleData, hull ); - b3SATCache faceCache = { 0 }; - b3CollideTriangleFace( manifold, capacity, &triangleData, hull, query, &faceCache, enableSpeculative ); - - if ( manifold->pointCount > 0 ) - { - *cache = faceCache; - } + float cab = b3Dot( hullNormal1, triEdge ); + float dab = b3Dot( hullNormal2, triEdge ); + float bcd = b3Dot( triNormal, hullEdge ); + return cab * dab < 0.0f && cab * bcd > 0.0f; } b3AtomicInt b3_triangleConvexCalls; b3AtomicInt b3_triangleCacheHits; -// Triangle is in the local space of the hull for efficiency. -void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, - const b3HullData* hullB, b3SATCache* cache, bool enableSpeculative ) +// Computes the manifold in the local space of the hull +void b3CollideHullAndTriangle( b3LocalManifold* manifold, int capacity, const b3HullData* hullA, b3Vec3 v1, b3Vec3 v2, b3Vec3 v3, + int triangleFlags, b3SATCache* cache ) { manifold->pointCount = 0; manifold->feature = b3_featureNone; @@ -989,7 +914,7 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v b3Plane trianglePlane = b3MakePlaneFromPoints( v1, v2, v3 ); float linearSlop = B3_LINEAR_SLOP; - float offset = b3PlaneSeparation( trianglePlane, hullB->center ); + float offset = b3PlaneSeparation( trianglePlane, hullA->center ); if ( cache->type == b3_backsideAxis ) { // Use hysteresis to avoid jitter on wavy meshes @@ -1009,6 +934,7 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v return; } + b3Vec3 triangleCenter = b3MulSV( 1.0f / 3.0f, b3Add( v1, b3Add( v2, v3 ) ) ); b3Vec3 trianglePoints[] = { v1, v2, v3 }; b3Vec3 triangleEdges[] = { b3Sub( v2, v1 ), b3Sub( v3, v2 ), b3Sub( v1, v3 ) }; @@ -1019,14 +945,16 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v .e1 = triangleEdges[0], .e2 = triangleEdges[1], .e3 = triangleEdges[2], + .center = triangleCenter, .plane = trianglePlane, + .flags = triangleFlags, }; - const b3HullHalfEdge* edges = b3GetHullEdges( hullB ); - const b3Plane* hullPlanes = b3GetHullPlanes( hullB ); - const b3Vec3* hullPoints = b3GetHullPoints( hullB ); + const b3HullHalfEdge* edges = b3GetHullEdges( hullA ); + const b3Plane* hullPlanes = b3GetHullPlanes( hullA ); + const b3Vec3* hullPoints = b3GetHullPoints( hullA ); - float speculativeDistance = enableSpeculative ? B3_SPECULATIVE_DISTANCE : B3_MESH_REST_OFFSET; + float speculativeDistance = B3_SPECULATIVE_DISTANCE; cache->hit = 1; // Attempt to use the cache to speed up collision @@ -1036,26 +964,23 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v { B3_ASSERT( cache->indexA == 0 ); - int vertexIndex = b3FindHullSupportVertex( hullB, b3Neg( trianglePlane.normal ) ); + int vertexIndex = b3FindHullSupportVertex( hullA, b3Neg( trianglePlane.normal ) ); b3Vec3 support = hullPoints[vertexIndex]; float separation = b3PlaneSeparation( trianglePlane, support ); - if ( separation > speculativeDistance ) + if ( separation >= speculativeDistance ) { // Cache hit, shapes are separated return; } - b3SeparatingAxis faceQuery; - faceQuery.normal = trianglePlane.normal; + b3FaceQuery faceQuery; faceQuery.separation = separation; - faceQuery.indexA = cache->indexA; - faceQuery.indexB = vertexIndex; - faceQuery.type = b3_faceAxisA; + faceQuery.faceIndex = cache->indexA; + faceQuery.vertexIndex = vertexIndex; // Read cache but don't modify it b3SATCache localCache = *cache; - float clippedSeparation = - b3CollideTriangleFace( manifold, capacity, &triangle, hullB, faceQuery, &localCache, enableSpeculative ); + float clippedSeparation = b3CollideTriangleFace( manifold, capacity, &triangle, hullA, faceQuery, &localCache ); if ( manifold->pointCount > 0 && b3AbsFloat( cache->separation - clippedSeparation ) < linearSlop ) { @@ -1071,7 +996,7 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v case b3_faceAxisB: { - B3_ASSERT( cache->indexB < hullB->faceCount ); + B3_ASSERT( cache->indexB < hullA->faceCount ); b3Plane plane = hullPlanes[cache->indexB]; @@ -1092,15 +1017,12 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v // Separation of triangle support point with hull plane float separation = b3PlaneSeparation( plane, support ); - if ( separation > speculativeDistance ) + if ( separation >= speculativeDistance ) { // Cache hit, shapes are separated return; } - // Note: it is possible for a hull face to lean into an edge direction while mainting - // a valid cache. But this has never been observed. - // Deep overlap may lead to an invalid cache // todo confirm bool isDeep = separation < -2.0f * linearSlop; @@ -1109,17 +1031,14 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v if ( isDeep == false ) { // Try to rebuild contact from last features - b3SeparatingAxis faceQuery; - faceQuery.normal = b3Neg( plane.normal ); + b3FaceQuery faceQuery; faceQuery.separation = separation; - faceQuery.indexA = vertexIndex; - faceQuery.indexB = cache->indexB; - faceQuery.type = b3_faceAxisB; + faceQuery.faceIndex = cache->indexB; + faceQuery.vertexIndex = vertexIndex; // Read cache but don't modify it b3SATCache localCache = *cache; - float clippedSeparation = - b3CollideHullFace( manifold, capacity, &triangle, hullB, faceQuery, &localCache, enableSpeculative ); + float clippedSeparation = b3CollideHullFace( manifold, capacity, &triangle, hullA, faceQuery, &localCache ); // Cache reuse is only successful if it creates contact points and the clipped separation didn't change much. if ( manifold->pointCount > 0 && b3AbsFloat( cache->separation - clippedSeparation ) < linearSlop ) @@ -1143,7 +1062,7 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v b3Vec3 triPoint = trianglePoints[indexA]; b3Vec3 triEdge = triangleEdges[indexA]; - B3_ASSERT( cache->indexB < hullB->edgeCount - 1 ); + B3_ASSERT( cache->indexB < hullA->edgeCount - 1 ); int indexB = cache->indexB; const b3HullHalfEdge* edge2 = edges + indexB; @@ -1155,55 +1074,36 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v b3Vec3 hullNormal1 = hullPlanes[edge2->face].normal; b3Vec3 hullNormal2 = hullPlanes[twin2->face].normal; - // Confirm the edge pair is still a Minkowski face. - // See "Collision Detection of Convex Polyhedra Based on Duality Transformation" - // Simplified for triangle versus hull. - float cab = b3Dot( hullNormal1, triEdge ); - float dab = b3Dot( hullNormal2, triEdge ); - float bcd = b3Dot( trianglePlane.normal, hullEdge ); - - if ( cab * dab < 0.0f && cab * bcd > 0.0f ) + // Confirm the edge pair is still a Minkowski face + bool isMinkowski = b3IsTriangleMinkowskiFace( trianglePlane.normal, triEdge, hullNormal1, hullNormal2, hullEdge ); + if ( isMinkowski ) { - float squaredTolerance = 0.005f * 0.005f; - - // Avoid nearly parallel edges that may lead to invalid separation values at the noise floor. - if ( b3MaxFloat( cab * cab, dab * dab ) >= squaredTolerance * b3LengthSquared( triEdge ) ) + // Transform reference center of the first hull into local space of the second hull + float separation = b3EdgeEdgeSeparation( triPoint, triEdge, triangleCenter, hullPoint, hullEdge, hullA->center ); + if ( separation > speculativeDistance ) { - // Similar to hull vs hull (b3QueryEdgeDirections) - // dot(hullNormal1 + t * (hullNormal2 - hullNormal1), triEdge) = 0 - // Normal points out of hull by construction. - float t = cab / ( cab - dab ); - b3Vec3 axis = b3Lerp( hullNormal1, hullNormal2, t ); - B3_VALIDATE( b3LengthSquared( axis ) > 1000.0f * FLT_MIN ); - axis = b3Normalize( axis ); - float separation = b3Dot( axis, b3Sub( triPoint, hullPoint ) ); - if ( separation > speculativeDistance ) + // Cache hit, shapes are separated + return; + } + + if ( b3AbsFloat( cache->separation - separation ) < linearSlop ) + { + // Try to rebuild contact from last features + b3EdgeQuery edgeQuery; + edgeQuery.indexA = indexA; + edgeQuery.indexB = indexB; + edgeQuery.separation = separation; + + // Read cache but don't modify it + b3SATCache localCache = *cache; + b3CollideHullAndTriangleEdges( manifold, capacity, triPoint, triEdge, triangleCenter, hullA, edgeQuery, + &localCache ); + + if ( manifold->pointCount > 0 ) { - // Cache hit, shapes are separated + // Cache hit, contact point generated return; } - - if ( b3AbsFloat( cache->separation - separation ) < linearSlop ) - { - // Try to rebuild contact from last features - // Flip normal to point from triangle to hull - b3SeparatingAxis edgeQuery; - edgeQuery.normal = b3Neg( axis ); - edgeQuery.indexA = indexA; - edgeQuery.indexB = indexB; - edgeQuery.separation = separation; - edgeQuery.type = b3_edgePairAxis; - - // Read cache but don't modify it - b3SATCache localCache = *cache; - b3CollideTriangleAndHullEdges( manifold, capacity, triPoint, triEdge, hullB, edgeQuery, &localCache ); - - if ( manifold->pointCount > 0 ) - { - // Cache hit, contact point generated - return; - } - } } } @@ -1215,28 +1115,29 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v // This case is for testing case b3_manualFaceAxisA: { - b3SeparatingAxis query = b3QueryTriangleFace( &triangle, hullB ); - b3CollideTriangleFace( manifold, capacity, &triangle, hullB, query, cache, enableSpeculative ); + b3FaceQuery faceQueryA = b3QueryTriangleFace( &triangle, hullA ); + b3CollideTriangleFace( manifold, capacity, &triangle, hullA, faceQueryA, cache ); return; } // This case is for testing case b3_manualFaceAxisB: { - b3SeparatingAxis query = b3QueryHullFace( &triangle, hullB ); - b3CollideHullFace( manifold, capacity, &triangle, hullB, query, cache, enableSpeculative ); + b3FaceQuery faceQueryB = b3QueryHullFace( &triangle, hullA ); + b3CollideHullFace( manifold, capacity, &triangle, hullA, faceQueryB, cache ); return; } // This case is for testing case b3_manualEdgePairAxis: { - b3SeparatingAxis query = b3QueryTriangleAndHullEdges( &triangle, hullB ); - if ( query.indexA != B3_NULL_INDEX ) + b3EdgeQuery edgeQuery = b3TestEdgePairs( &triangle, hullA ); + if ( edgeQuery.indexA != B3_NULL_INDEX ) { - b3Vec3 trianglePoint = trianglePoints[query.indexA]; - b3Vec3 triangleEdge = triangleEdges[query.indexA]; - b3CollideTriangleAndHullEdges( manifold, capacity, trianglePoint, triangleEdge, hullB, query, cache ); + b3Vec3 trianglePoint = trianglePoints[edgeQuery.indexA]; + b3Vec3 triangleEdge = triangleEdges[edgeQuery.indexA]; + b3CollideHullAndTriangleEdges( manifold, capacity, trianglePoint, triangleEdge, triangleCenter, hullA, edgeQuery, + cache ); } return; } @@ -1250,29 +1151,29 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v cache->hit = 0; // Find axis of minimum penetration - b3SeparatingAxis faceQueryA = b3QueryTriangleFace( &triangle, hullB ); + b3FaceQuery faceQueryA = b3QueryTriangleFace( &triangle, hullA ); if ( faceQueryA.separation > speculativeDistance ) { // Separating axis found cache->separation = faceQueryA.separation; cache->type = b3_faceAxisA; - cache->indexA = (uint8_t)faceQueryA.indexA; - cache->indexB = (uint8_t)faceQueryA.indexB; + cache->indexA = 0; + cache->indexB = UINT8_MAX; return; } - b3SeparatingAxis faceQueryB = b3QueryHullFace( &triangle, hullB ); + b3FaceQuery faceQueryB = b3QueryHullFace( &triangle, hullA ); if ( faceQueryB.separation > speculativeDistance ) { // Separating axis found cache->separation = faceQueryB.separation; cache->type = b3_faceAxisB; - cache->indexA = (uint8_t)faceQueryB.indexA; - cache->indexB = (uint8_t)faceQueryB.indexB; + cache->indexA = UINT8_MAX; + cache->indexB = (uint8_t)faceQueryB.faceIndex; return; } - b3SeparatingAxis edgeQuery = b3QueryTriangleAndHullEdges( &triangle, hullB ); + b3EdgeQuery edgeQuery = b3TestEdgePairs( &triangle, hullA ); if ( edgeQuery.separation > speculativeDistance ) { // Separating axis found @@ -1283,18 +1184,18 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v return; } - float clipSeparation; + float clippedFaceSeparation; - // Don't admit a hull face significantly opposed to the triangle face. - // Need a tolerance to avoid ghost collisions. - bool pushingDown = b3Dot( faceQueryB.normal, trianglePlane.normal ) < -0.25f; - if ( faceQueryB.separation >= faceQueryA.separation && pushingDown == false ) + // Don't allow a hull face opposed to the triangle face. + b3Vec3 hullNormal = hullPlanes[faceQueryB.faceIndex].normal; + bool pushingUp = b3Dot( hullNormal, trianglePlane.normal ) < 0.0f; + if ( faceQueryB.separation > faceQueryA.separation + linearSlop && pushingUp ) { - clipSeparation = b3CollideHullFace( manifold, capacity, &triangle, hullB, faceQueryB, cache, enableSpeculative ); + clippedFaceSeparation = b3CollideHullFace( manifold, capacity, &triangle, hullA, faceQueryB, cache ); } else { - clipSeparation = b3CollideTriangleFace( manifold, capacity, &triangle, hullB, faceQueryA, cache, enableSpeculative ); + clippedFaceSeparation = b3CollideTriangleFace( manifold, capacity, &triangle, hullA, faceQueryA, cache ); } // Does an edge axis exist? @@ -1304,29 +1205,15 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v // If a face axis has positive separation there may be no points. float maxFaceSeparation = b3MaxFloat( faceQueryA.separation, faceQueryB.separation ); - // The edge axis can win if the hull face axis is significantly aligned with the edge axis. - bool crossesEdge = false; - if ( manifold->pointCount >= 1 && manifold->feature == b3_featureHullFace && edgeQuery.separation > clipSeparation ) - { - b3Vec3 edgeAxis = b3Normalize( triangleEdges[edgeQuery.indexA] ); - - // Is the angle less than ~84 degrees? - crossesEdge = b3AbsFloat( b3Dot( faceQueryB.normal, edgeAxis ) ) > B3_CROSSING_TOLERANCE; - } - if ( ( manifold->pointCount == 0 && edgeQuery.separation > maxFaceSeparation ) || - ( manifold->pointCount == 1 && edgeQuery.separation > clipSeparation + linearSlop ) || crossesEdge ) + ( manifold->pointCount == 1 && edgeQuery.separation > clippedFaceSeparation + linearSlop ) ) { B3_ASSERT( 0 <= edgeQuery.indexA && edgeQuery.indexA < 3 ); b3Vec3 trianglePoint = trianglePoints[edgeQuery.indexA]; b3Vec3 triangleEdge = triangleEdges[edgeQuery.indexA]; manifold->pointCount = 0; - b3CollideTriangleAndHullEdges( manifold, capacity, trianglePoint, triangleEdge, hullB, edgeQuery, cache ); - - if ( crossesEdge && manifold->pointCount == 0 ) - { - b3CollideHullFace( manifold, capacity, &triangle, hullB, faceQueryB, cache, enableSpeculative ); - } + b3CollideHullAndTriangleEdges( manifold, capacity, trianglePoint, triangleEdge, triangleCenter, hullA, edgeQuery, + cache ); } } @@ -1341,14 +1228,14 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v .count = 3, .radius = 0.0f, }; - input.proxyB = (b3ShapeProxy){ .points = hullPoints, .count = hullB->vertexCount, .radius = 0.0f }; + input.proxyB = (b3ShapeProxy){ .points = hullPoints, .count = hullA->vertexCount, .radius = 0.0f }; input.transform = b3Transform_identity; input.useRadii = false; b3SimplexCache simplexCache = { 0 }; b3DistanceOutput output = b3ShapeDistance( &input, &simplexCache, NULL, 0 ); - if ( 0.0f < output.distance && output.distance <= speculativeDistance ) + if ( output.distance > 0.0f ) { B3_ASSERT( 0 < simplexCache.count && simplexCache.count <= 3 ); @@ -1361,8 +1248,5 @@ void b3CollideTriangleAndHull( b3LocalManifold* manifold, int capacity, b3Vec3 v // This feature pair not accurate but maybe it doesn't matter manifold->points[0].pair = b3FeaturePair_single; } - - // No way to cache this scenario - *cache = (b3SATCache){ 0 }; } } diff --git a/src/types.c b/src/types.c index 284e6e1..8b3f38e 100644 --- a/src/types.c +++ b/src/types.c @@ -7,39 +7,6 @@ #include "box3d/constants.h" -const char* b3GetTaskTypeName( b3TaskType type ) -{ - switch ( type ) - { - case b3_taskPairs: - return "pairs"; - - case b3_taskCollide: - return "collide"; - - case b3_taskTreeRebuild: - return "tree"; - - case b3_taskIslandSplit: - return "split"; - - case b3_taskSolver: - return "solve"; - - case b3_taskFinalize: - return "finalize"; - - case b3_taskContinuous: - return "continuous"; - - case b3_taskSensors: - return "sensors"; - - default: - return ""; - } -} - b3WorldDef b3DefaultWorldDef( void ) { float lengthUnits = b3GetLengthUnitsPerMeter(); @@ -49,8 +16,6 @@ b3WorldDef b3DefaultWorldDef( void ) def.gravity.y = -10.0f; def.hitEventThreshold = 1.0f * lengthUnits; def.restitutionThreshold = 1.0f * lengthUnits; - def.restitutionIterations = 2; - def.enableRestitutionPropagation = false; def.contactSpeed = 3.0f * lengthUnits; def.contactHertz = 30.0f; def.contactDampingRatio = 10.0f; @@ -58,8 +23,6 @@ b3WorldDef b3DefaultWorldDef( void ) // 400 meters per second, faster than the speed of sound def.maximumLinearSpeed = 400.0f * lengthUnits; - def.isotropicInertiaTolerance = 0.2f; - def.enableSleep = true; def.enableContinuous = true; def.internalValue = B3_SECRET_COOKIE; @@ -72,7 +35,6 @@ b3BodyDef b3DefaultBodyDef( void ) def.type = b3_staticBody; def.rotation = b3Quat_identity; def.sleepThreshold = 0.05f * b3GetLengthUnitsPerMeter(); - def.safetyFactor = 0.5f; def.gravityScale = 1.0f; def.enableSleep = true; def.isAwake = true; @@ -113,14 +75,14 @@ b3ShapeDef b3DefaultShapeDef( void ) def.filter = b3DefaultFilter(); def.updateBodyMass = true; def.invokeContactCreation = true; - def.enableSpeculativeContact = true; def.internalValue = B3_SECRET_COOKIE; return def; } -static void b3EmptyDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, void* context ) +static bool b3EmptyDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, void* context ) { B3_UNUSED( userShape, transform, color, context ); + return false; } static void b3EmptyDrawSegment( b3Pos p1, b3Pos p2, b3HexColor color, void* context ) @@ -186,7 +148,7 @@ b3DebugDraw b3DefaultDebugDraw( void ) }; draw.jointScale = 1.0f; - draw.forceScale = 0.001f; + draw.forceScale = 1.0f; return draw; } diff --git a/src/weld_joint.c b/src/weld_joint.c index 21d7d35..611b714 100644 --- a/src/weld_joint.c +++ b/src/weld_joint.c @@ -91,9 +91,9 @@ void b3PrepareWeldJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyA = b3Array_Get( world->bodies, base->bodyIdA ); b3Body* bodyB = b3Array_Get( world->bodies, base->bodyIdB ); - B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + B3_ASSERT( bodyB->setIndex == b3_awakeSet ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -269,7 +269,17 @@ void b3SolveWeldJoint( b3JointSim* base, b3StepContext* context, bool useBias ) impulseScale = joint->linearSpring.impulseScale; } - b3Vec3 b = b3SolvePointConstraint( mA, mB, base->invIA, base->invIB, rA, rB, b3Add( cdot, bias ) ); + //// K = [(1/m1 + 1/m2) * eye(2) - skew(r1) * invI1 * skew(r1) - skew(r2) * invI2 * skew(r2)] + b3Matrix3 sA = b3Skew( rA ); + b3Matrix3 sB = b3Skew( rB ); + b3Matrix3 kA = b3MulMM( sA, b3MulMM( base->invIA, sA ) ); + b3Matrix3 kB = b3MulMM( sB, b3MulMM( base->invIB, sB ) ); + b3Matrix3 k = b3NegateMat3( b3AddMM( kA, kB ) ); + k.cx.x += mA + mB; + k.cy.y += mA + mB; + k.cz.z += mA + mB; + + b3Vec3 b = b3Solve3( k, b3Add( cdot, bias ) ); b3Vec3 impulse = b3MulSub( b3MulSV( -massScale, b ), impulseScale, joint->linearImpulse ); joint->linearImpulse = b3Add( joint->linearImpulse, impulse ); diff --git a/src/wheel_joint.c b/src/wheel_joint.c index 6201cff..05665e9 100644 --- a/src/wheel_joint.c +++ b/src/wheel_joint.c @@ -278,7 +278,7 @@ float b3WheelJoint_GetSpinSpeed( b3JointId jointId ) b3Body* bodyA = b3Array_Get( world->bodies, idA ); b3Body* bodyB = b3Array_Get( world->bodies, idB ); - b3SolverSet* setB = b3GetSolverSet( world, bodyB->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexB = bodyB->localIndex; b3BodySim* bodySimB = b3Array_Get( setB->bodySims, localIndexB ); @@ -321,8 +321,8 @@ float b3WheelJoint_GetSteeringAngle( b3JointId jointId ) b3Body* bodyA = b3Array_Get( world->bodies, idA ); b3Body* bodyB = b3Array_Get( world->bodies, idB ); - b3SolverSet* setA = b3GetSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -384,8 +384,8 @@ b3Vec3 b3GetWheelJointTorque( b3World* world, b3JointSim* base ) b3Body* bodyA = b3Array_Get( world->bodies, idA ); // b3Body* bodyB = b3Array_Get( world->bodies, idB ); - b3SolverSet* setA = b3GetSolverSet( world, bodyA->setIndex ); - // b3SolverSet* setB = b3GetSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + // b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; // int localIndexB = bodyB->localIndex; @@ -416,8 +416,8 @@ void b3PrepareWheelJoint( b3JointSim* base, b3StepContext* context ) b3Body* bodyB = b3Array_Get( world->bodies, idB ); B3_ASSERT( bodyA->setIndex == b3_awakeSet || bodyB->setIndex == b3_awakeSet ); - b3SolverSet* setA = b3GetFixedSolverSet( world, bodyA->setIndex ); - b3SolverSet* setB = b3GetFixedSolverSet( world, bodyB->setIndex ); + b3SolverSet* setA = b3Array_Get( world->solverSets, bodyA->setIndex ); + b3SolverSet* setB = b3Array_Get( world->solverSets, bodyB->setIndex ); int localIndexA = bodyA->localIndex; int localIndexB = bodyB->localIndex; @@ -1072,16 +1072,14 @@ void b3DrawWheelJoint( b3DebugDraw* draw, b3JointSim* base, b3WorldTransform tra float upper = joint->upperSteeringLimit; b3CosSin cs = b3ComputeCosSin( lower ); - b3CosSin delta = b3ComputeCosSin( ( upper - lower ) / sliceCount ); b3Pos vertex1 = b3TransformWorldPoint( frame, (b3Vec3){ 0.0f, -radius * cs.sine, radius * cs.cosine } ); for ( int index = 0; index < sliceCount; ++index ) { - float cosine = delta.cosine * cs.cosine - delta.sine * cs.sine; - float sine = delta.sine * cs.cosine + delta.cosine * cs.sine; - cs.cosine = cosine; - cs.sine = sine; + float t2 = ( index + 1.0f ) / sliceCount; + float phi = b3LerpFloat( lower, upper, t2 ); + cs = b3ComputeCosSin( phi ); b3Pos vertex2 = b3TransformWorldPoint( frame, (b3Vec3){ 0.0f, -radius * cs.sine, radius * cs.cosine } ); if ( index == 0 ) diff --git a/src/wide4.c b/src/wide4.c deleted file mode 100644 index e2132ec..0000000 --- a/src/wide4.c +++ /dev/null @@ -1,6 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#define B3_SIMD_WIDTH 4 -#include "contact_solver_wide.inl" -#include "convex_manifold_wide.inl" diff --git a/src/wide8.c b/src/wide8.c deleted file mode 100644 index cb89f92..0000000 --- a/src/wide8.c +++ /dev/null @@ -1,23 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#define B3_SIMD_WIDTH 8 - -#include "core.h" - -#if defined( B3_SIMD_AVX2 ) - -#if defined( _MSC_VER ) && !defined( __clang__ ) && !defined( __AVX2__ ) -#error "MSVC must compile this file with /arch:AVX2, or define BOX3D_DISABLE_AVX2" -#endif - -#include - -B3_AVX2_BEGIN - -#include "contact_solver_wide.inl" -#include "convex_manifold_wide.inl" - -B3_AVX2_END - -#endif diff --git a/src/world_snapshot.c b/src/world_snapshot.c index 1faf2d1..880c9ed 100644 --- a/src/world_snapshot.c +++ b/src/world_snapshot.c @@ -33,7 +33,7 @@ // Snapshot image magic 'BNS3' and version #define B3_SNAP_MAGIC 0x33534E42u -#define B3_SNAP_VERSION 11u // isotropic inertia tolerance +#define B3_SNAP_VERSION 1u #define B3_SNAP_FLAG_VALIDATION 0x1u #define B3_SNAP_FLAG_DOUBLE_PRECISION 0x2u @@ -64,27 +64,6 @@ static uint32_t b3ComputeLayoutHash( void ) MIX( sizeof( b3GraphColor ) ) MIX( sizeof( b3DynamicTree ) ) MIX( sizeof( b3TreeNode ) ) - MIX( sizeof( b3TreeProxy ) ) - MIX( sizeof( b3HullData ) ) - MIX( sizeof( b3HullVertex ) ) - MIX( sizeof( b3HullHalfEdge ) ) - MIX( sizeof( b3HullFace ) ) - MIX( sizeof( b3Plane ) ) - MIX( sizeof( b3MeshData ) ) - MIX( sizeof( b3MeshNode ) ) - MIX( sizeof( b3MeshTriangle ) ) - MIX( sizeof( b3HeightFieldData ) ) - MIX( sizeof( b3CompoundData ) ) - MIX( sizeof( b3CompoundCapsule ) ) - MIX( sizeof( b3CompoundSphere ) ) - MIX( B3_HULL_VERSION & 0xFFFFFFFFu ) - MIX( B3_HULL_VERSION >> 32 ) - MIX( B3_MESH_VERSION & 0xFFFFFFFFu ) - MIX( B3_MESH_VERSION >> 32 ) - MIX( B3_HEIGHT_FIELD_VERSION & 0xFFFFFFFFu ) - MIX( B3_HEIGHT_FIELD_VERSION >> 32 ) - MIX( B3_COMPOUND_VERSION & 0xFFFFFFFFu ) - MIX( B3_COMPOUND_VERSION >> 32 ) MIX( sizeof( b3SetItem ) ) MIX( sizeof( b3IdPool ) ) MIX( sizeof( b3SurfaceMaterial ) ) @@ -298,77 +277,48 @@ static void b3DesHashSet( b3SnapReader* r, b3HashSet* hs ) } } -// DynamicTree: version, scalars, then nodes and parents to nodeEnd and proxies at capacity. -// The empty node and the free pairs are sentinels below the end and travel as they are. Only the -// stale tail above the end, the spare array and the rebuild scratch are skipped. +// DynamicTree: version, scalars, full nodeCapacity nodes (rebuild scratch excluded) static void b3SerTree( b3RecBuffer* buf, const b3DynamicTree* tree ) { b3SnapW_Bytes( buf, &tree->version, sizeof( uint64_t ) ); - b3SnapW_I32( buf, tree->nodeEnd ); - b3SnapW_I32( buf, tree->pairFreeList ); + b3SnapW_I32( buf, tree->root ); + b3SnapW_I32( buf, tree->nodeCount ); + b3SnapW_I32( buf, tree->nodeCapacity ); + b3SnapW_I32( buf, tree->freeList ); b3SnapW_I32( buf, tree->proxyCount ); - b3SnapW_I32( buf, tree->proxyCapacity ); - b3SnapW_I32( buf, tree->proxyFreeList ); - b3SnapW_I32( buf, tree->dfsOrdered ? 1 : 0 ); - if ( tree->nodeEnd > 0 ) + if ( tree->nodeCapacity > 0 ) { - b3SnapW_Bytes( buf, tree->nodes, tree->nodeEnd * (int)sizeof( b3TreeNode ) ); - b3SnapW_Bytes( buf, tree->parents, tree->nodeEnd * (int)sizeof( int32_t ) ); - } - if ( tree->proxyCapacity > 0 ) - { - b3SnapW_Bytes( buf, tree->proxies, tree->proxyCapacity * (int)sizeof( b3TreeProxy ) ); + b3SnapW_Bytes( buf, tree->nodes, tree->nodeCapacity * (int)sizeof( b3TreeNode ) ); } } static void b3DesTree( b3SnapReader* r, b3DynamicTree* tree ) { - uint64_t version = 0; + uint64_t version; b3SnapR_Bytes( r, &version, sizeof( uint64_t ) ); - int nodeEnd = b3SnapR_I32( r ); - int pairFreeList = b3SnapR_I32( r ); + int root = b3SnapR_I32( r ); + int nodeCount = b3SnapR_I32( r ); + int nodeCapacity = b3SnapR_I32( r ); + int freeList = b3SnapR_I32( r ); int proxyCount = b3SnapR_I32( r ); - int proxyCapacity = b3SnapR_I32( r ); - int proxyFreeList = b3SnapR_I32( r ); - bool dfsOrdered = b3SnapR_I32( r ) != 0; - if ( r->ok && b3SnapCheckCount( r, nodeEnd, (int)sizeof( b3TreeNode ), (int)sizeof( b3TreeNode ) ) == false ) + if ( r->ok && b3SnapCheckCount( r, nodeCapacity, (int)sizeof( b3TreeNode ), (int)sizeof( b3TreeNode ) ) == false ) { r->ok = false; } - if ( r->ok && b3SnapCheckCount( r, proxyCapacity, (int)sizeof( b3TreeProxy ), (int)sizeof( b3TreeProxy ) ) == false ) - { - r->ok = false; - } - - if ( r->ok && ( nodeEnd < 2 || ( nodeEnd & 1 ) != 0 || proxyCapacity < 1 ) ) - { - r->ok = false; - } - - // Free existing allocation including the spare array and any rebuild scratch + // Free existing allocation including any rebuild scratch b3Free( tree->nodes, tree->nodeCapacity * (int)sizeof( b3TreeNode ) ); - b3Free( tree->parents, tree->nodeCapacity * (int)sizeof( int32_t ) ); - b3Free( tree->proxies, tree->proxyCapacity * (int)sizeof( b3TreeProxy ) ); - b3Free( tree->swapNodes, tree->nodeCapacity * (int)sizeof( b3TreeNode ) ); b3Free( tree->leafIndices, tree->rebuildCapacity * (int)sizeof( int ) ); - b3Free( tree->leafNodes, tree->rebuildCapacity * (int)sizeof( b3TreeNode ) ); b3Free( tree->leafBoxes, tree->rebuildCapacity * (int)sizeof( b3AABB ) ); b3Free( tree->leafCenters, tree->rebuildCapacity * (int)sizeof( b3Vec3 ) ); b3Free( tree->binIndices, tree->rebuildCapacity * (int)sizeof( int ) ); tree->nodes = NULL; - tree->parents = NULL; - tree->proxies = NULL; - tree->swapNodes = NULL; tree->leafIndices = NULL; - tree->leafNodes = NULL; tree->leafBoxes = NULL; tree->leafCenters = NULL; tree->binIndices = NULL; - tree->nodeEnd = 0; tree->nodeCapacity = 0; - tree->proxyCapacity = 0; tree->rebuildCapacity = 0; if ( !r->ok ) @@ -377,21 +327,17 @@ static void b3DesTree( b3SnapReader* r, b3DynamicTree* tree ) } tree->version = version; - tree->nodeEnd = nodeEnd; - tree->nodeCapacity = nodeEnd; - tree->pairFreeList = pairFreeList; + tree->root = root; + tree->nodeCount = nodeCount; + tree->nodeCapacity = nodeCapacity; + tree->freeList = freeList; tree->proxyCount = proxyCount; - tree->proxyCapacity = proxyCapacity; - tree->proxyFreeList = proxyFreeList; - tree->dfsOrdered = dfsOrdered; - tree->nodes = (b3TreeNode*)b3Alloc( nodeEnd * (int)sizeof( b3TreeNode ) ); - tree->parents = (int32_t*)b3Alloc( nodeEnd * (int)sizeof( int32_t ) ); - b3SnapR_Bytes( r, tree->nodes, nodeEnd * (int)sizeof( b3TreeNode ) ); - b3SnapR_Bytes( r, tree->parents, nodeEnd * (int)sizeof( int32_t ) ); - - tree->proxies = (b3TreeProxy*)b3Alloc( proxyCapacity * (int)sizeof( b3TreeProxy ) ); - b3SnapR_Bytes( r, tree->proxies, proxyCapacity * (int)sizeof( b3TreeProxy ) ); + if ( nodeCapacity > 0 ) + { + tree->nodes = (b3TreeNode*)b3Alloc( nodeCapacity * (int)sizeof( b3TreeNode ) ); + b3SnapR_Bytes( r, tree->nodes, nodeCapacity * (int)sizeof( b3TreeNode ) ); + } } // Solver set: setIndex + 4 arrays (note: contactIndices is int array, not contactSims) @@ -415,50 +361,6 @@ static void b3DesSolverSet( b3SnapReader* r, b3SolverSet* set ) b3DesPodArray( r, set->islandSims ); } -static void b3SerNames( b3RecBuffer* buf, const b3NameCache* cache ) -{ - b3SnapW_I32( buf, cache->entries.count ); - int count = cache->entries.count; - for ( int i = 0; i < count; ++i ) - { - const b3NameEntry* entry = cache->entries.data + i; - b3SnapW_U32( buf, entry->hash ); - b3SnapW_I32( buf, entry->length ); - b3RecBufAppend( buf, entry->name, entry->length ); - } -} - -static void b3DesNames( b3SnapReader* r, b3NameCache* cache ) -{ - int count = b3SnapR_I32( r ); - - if ( r->ok && b3SnapCheckCount( r, count, (int)sizeof( b3NameEntry ), 8 ) == false ) - { - r->ok = false; - } - - if ( r->ok == false ) - { - return; - } - - b3Array_Reserve( cache->entries, count ); - for ( int i = 0; i < count; ++i ) - { - uint32_t hash = b3SnapR_U32( r ); - int length = b3SnapR_I32( r ); - if ( r->ok == false || length < 0 || length > r->size - r->cursor ) - { - r->ok = false; - return; - } - char* name = b3Alloc( length + 1 ); - b3SnapR_Bytes( r, name, length ); - name[length] = 0; - b3LoadName( cache, hash, name, length ); - } -} - // Graph color: bodySet (non-overflow only) + jointSims + convexContacts + contacts static void b3SerGraphColor( b3RecBuffer* buf, const b3GraphColor* color, bool isOverflow ) { @@ -490,9 +392,7 @@ static void b3SerWorldConfig( b3RecBuffer* buf, const b3World* world ) b3SnapW_Bytes( buf, &world->gravity, sizeof( b3Vec3 ) ); b3SnapW_Bytes( buf, &world->hitEventThreshold, sizeof( float ) ); b3SnapW_Bytes( buf, &world->restitutionThreshold, sizeof( float ) ); - b3SnapW_I32( buf, world->restitutionIterations ); b3SnapW_Bytes( buf, &world->maxLinearSpeed, sizeof( float ) ); - b3SnapW_Bytes( buf, &world->isotropicInertiaTolerance, sizeof( float ) ); b3SnapW_Bytes( buf, &world->contactSpeed, sizeof( float ) ); b3SnapW_Bytes( buf, &world->contactHertz, sizeof( float ) ); b3SnapW_Bytes( buf, &world->contactDampingRatio, sizeof( float ) ); @@ -502,14 +402,12 @@ static void b3SerWorldConfig( b3RecBuffer* buf, const b3World* world ) b3SnapW_Bytes( buf, &world->inv_h, sizeof( float ) ); b3SnapW_Bytes( buf, &world->inv_dt, sizeof( float ) ); b3SnapW_I32( buf, world->endEventArrayIndex ); - b3SnapW_I32( buf, world->compoundShapeCount ); b3SnapW_Bytes( buf, &world->maxCapacity, sizeof( b3Capacity ) ); uint8_t flags = 0; flags |= world->enableSleep ? 0x01u : 0u; flags |= world->enableWarmStarting ? 0x02u : 0u; flags |= world->enableContinuous ? 0x04u : 0u; flags |= world->enableSpeculative ? 0x08u : 0u; - flags |= world->enableRestitutionPropagation ? 0x10u : 0u; b3RecBufAppend( buf, &flags, 1 ); } @@ -518,9 +416,7 @@ static void b3DesWorldConfig( b3SnapReader* r, b3World* world ) b3SnapR_Bytes( r, &world->gravity, sizeof( b3Vec3 ) ); b3SnapR_Bytes( r, &world->hitEventThreshold, sizeof( float ) ); b3SnapR_Bytes( r, &world->restitutionThreshold, sizeof( float ) ); - world->restitutionIterations = b3SnapR_I32( r ); b3SnapR_Bytes( r, &world->maxLinearSpeed, sizeof( float ) ); - b3SnapR_Bytes( r, &world->isotropicInertiaTolerance, sizeof( float ) ); b3SnapR_Bytes( r, &world->contactSpeed, sizeof( float ) ); b3SnapR_Bytes( r, &world->contactHertz, sizeof( float ) ); b3SnapR_Bytes( r, &world->contactDampingRatio, sizeof( float ) ); @@ -530,7 +426,6 @@ static void b3DesWorldConfig( b3SnapReader* r, b3World* world ) b3SnapR_Bytes( r, &world->inv_h, sizeof( float ) ); b3SnapR_Bytes( r, &world->inv_dt, sizeof( float ) ); world->endEventArrayIndex = b3SnapR_I32( r ); - world->compoundShapeCount = b3SnapR_I32( r ); b3SnapR_Bytes( r, &world->maxCapacity, sizeof( b3Capacity ) ); uint8_t flags = 0; b3SnapR_Bytes( r, &flags, 1 ); @@ -538,12 +433,11 @@ static void b3DesWorldConfig( b3SnapReader* r, b3World* world ) world->enableWarmStarting = ( flags & 0x02u ) != 0; world->enableContinuous = ( flags & 0x04u ) != 0; world->enableSpeculative = ( flags & 0x08u ) != 0; - world->enableRestitutionPropagation = ( flags & 0x10u ) != 0; } // Shapes carry pointer fields: materials, userData, userShape, and the geometry union. // Serialize the POD scalars with pointers nulled, then the owned materials array, then geometry. -// A single material lives inline in the struct image. +// A single material lives inline in the struct image. The name is a fixed array, also inline. // Hull/mesh/heightField/compound are interned into the recording registry; sphere/capsule inline. static void b3SerShapes( b3RecBuffer* buf, b3World* world, b3Recording* rec ) { @@ -654,7 +548,7 @@ static void b3DesShapes( b3SnapReader* r, b3World* world, b3RecReader* rdr ) // shape with the same geometry. Carrying its handle over avoids tearing down and rebuilding every // GPU mesh on each seek, which the host (a 3D renderer) would otherwise pay for. Handles that are // not reclaimed below belong to shapes that are gone or were replaced, and get released so the host - // pool does not leak across seeks. + // pool does not leak across seeks. Box2D has no such handles, so its restore skips all of this. int oldShapeCount = world->shapes.count; void** savedUserShape = NULL; uint16_t* savedGeneration = NULL; @@ -747,13 +641,13 @@ static void b3DesShapes( b3SnapReader* r, b3World* world, b3RecReader* rdr ) { break; } - b3RegistrySlot* slot = b3RecGetSlot( rdr, gid, b3_geometryHull ); - if ( slot == NULL ) + if ( rdr == NULL || gid >= (uint32_t)rdr->slotCount ) { r->ok = false; break; } // Hull is cloned into the world DB; pass raw bytes directly + b3RegistrySlot* slot = rdr->slots + gid; dst->hull = b3AddHullToDatabase( world, (const b3HullData*)slot->bytes ); break; } @@ -766,12 +660,12 @@ static void b3DesShapes( b3SnapReader* r, b3World* world, b3RecReader* rdr ) { break; } - b3RegistrySlot* slot = b3RecGetSlot( rdr, gid, b3_geometryMesh ); - if ( slot == NULL ) + if ( rdr == NULL || gid >= (uint32_t)rdr->slotCount ) { r->ok = false; break; } + b3RegistrySlot* slot = rdr->slots + gid; // Mesh is a self-contained blob used by reference; point straight at the pristine bytes. dst->mesh.data = (const b3MeshData*)slot->bytes; dst->mesh.scale = scale; @@ -784,12 +678,12 @@ static void b3DesShapes( b3SnapReader* r, b3World* world, b3RecReader* rdr ) { break; } - b3RegistrySlot* slot = b3RecGetSlot( rdr, gid, b3_geometryHeightField ); - if ( slot == NULL ) + if ( rdr == NULL || gid >= (uint32_t)rdr->slotCount ) { r->ok = false; break; } + b3RegistrySlot* slot = rdr->slots + gid; // Self-contained blob used by reference; point straight at the pristine bytes. dst->heightField = (const b3HeightFieldData*)slot->bytes; break; @@ -801,13 +695,19 @@ static void b3DesShapes( b3SnapReader* r, b3World* world, b3RecReader* rdr ) { break; } - b3RegistrySlot* slot = b3RecGetSlot( rdr, gid, b3_geometryCompound ); - if ( slot == NULL ) + if ( rdr == NULL || gid >= (uint32_t)rdr->slotCount ) { r->ok = false; break; } - dst->compound = (const b3CompoundData*)slot->bytes; + b3RegistrySlot* slot = rdr->slots + gid; + if ( slot->live == NULL ) + { + slot->live = b3Alloc( (size_t)slot->byteCount ); + memcpy( slot->live, slot->bytes, (size_t)slot->byteCount ); + b3ConvertBytesToCompound( (uint8_t*)slot->live, slot->byteCount ); + } + dst->compound = (const b3CompoundData*)slot->live; break; } default: @@ -851,6 +751,8 @@ static void b3SerContacts( b3RecBuffer* buf, b3World* world ) // Write raw struct with pointer fields zeroed b3Contact copy = *c; copy.manifolds = NULL; + copy.bodySimIndexA = B3_NULL_INDEX; + copy.bodySimIndexB = B3_NULL_INDEX; if ( copy.flags & b3_simMeshContact ) { copy.meshContact.triangleCache.data = NULL; @@ -907,6 +809,8 @@ static void b3DesContacts( b3SnapReader* r, b3World* world ) b3Contact* dst = world->contacts.data + i; b3SnapR_Bytes( r, dst, sizeof( b3Contact ) ); dst->manifolds = NULL; + dst->bodySimIndexA = B3_NULL_INDEX; + dst->bodySimIndexB = B3_NULL_INDEX; if ( dst->flags & b3_simMeshContact ) { dst->meshContact.triangleCache.data = NULL; @@ -925,8 +829,7 @@ static void b3DesContacts( b3SnapReader* r, b3World* world ) if ( isLive && manifoldCount > 0 ) { - if ( manifoldCount > B3_MAX_MANIFOLDS || - b3SnapCheckCount( r, manifoldCount, (int)sizeof( b3Manifold ), (int)sizeof( b3Manifold ) ) == false ) + if ( b3SnapCheckCount( r, manifoldCount, (int)sizeof( b3Manifold ), (int)sizeof( b3Manifold ) ) == false ) { r->ok = false; break; @@ -1057,11 +960,11 @@ int b3SerializeWorld( b3World* world, b3RecBuffer* buf, b3Recording* rec ) b3SerIdPool( buf, &world->solverSetIdPool ); // Solver sets - int setCount = b3GetSolverSetCount( world ); + int setCount = world->solverSets.count; b3SnapW_I32( buf, setCount ); for ( int i = 0; i < setCount; ++i ) { - b3SerSolverSet( buf, b3GetSolverSet( world, i ) ); + b3SerSolverSet( buf, world->solverSets.data + i ); } // Sparse body array (userData is host wiring, zero it on the copy) @@ -1079,8 +982,6 @@ int b3SerializeWorld( b3World* world, b3RecBuffer* buf, b3Recording* rec ) // Shape sparse array with geometry interning b3SerShapes( buf, world, rec ); - b3SerPodArray( buf, world->fatAABBs ); - // Contact sparse array with manifold and mesh triangleCache b3SerContacts( buf, world ); @@ -1133,6 +1034,11 @@ int b3SerializeWorld( b3World* world, b3RecBuffer* buf, b3Recording* rec ) { b3SerTree( buf, &bp->trees[t] ); } + for ( int t = 0; t < b3_bodyTypeCount; ++t ) + { + b3SerBitSet( buf, &bp->movedProxies[t] ); + } + b3SerPodArray( buf, bp->moveArray ); b3SerHashSet( buf, &bp->pairSet ); // Constraint graph @@ -1142,8 +1048,6 @@ int b3SerializeWorld( b3World* world, b3RecBuffer* buf, b3Recording* rec ) b3SerGraphColor( buf, &graph->colors[c], c == B3_OVERFLOW_INDEX ); } - b3SerNames( buf, &world->names ); - return buf->size - startSize; } @@ -1201,10 +1105,9 @@ bool b3DeserializeIntoShell( const uint8_t* data, int size, b3World* world, b3Re b3DesIdPool( r, &world->solverSetIdPool ); // 3. Solver sets: destroy inner arrays of existing sets first - int oldSetCount = b3GetSolverSetCount( world ); - for ( int i = 0; i < oldSetCount; ++i ) + for ( int i = 0; i < world->solverSets.count; ++i ) { - b3SolverSet* set = b3GetSolverSet( world, i ); + b3SolverSet* set = world->solverSets.data + i; b3Array_Destroy( set->bodySims ); b3Array_Destroy( set->bodyStates ); b3Array_Destroy( set->jointSims ); @@ -1213,24 +1116,17 @@ bool b3DeserializeIntoShell( const uint8_t* data, int size, b3World* world, b3Re } int setCount = b3SnapR_I32( r ); - if ( r->ok && ( setCount < b3_firstSleepingSet || - b3SnapCheckCount( r, setCount, (int)sizeof( b3SolverSet ), 6 * (int)sizeof( int ) ) == false ) ) + if ( r->ok && b3SnapCheckCount( r, setCount, (int)sizeof( b3SolverSet ), 6 * (int)sizeof( int ) ) == false ) { r->ok = false; } if ( r->ok ) { - int sleepingSetCount = setCount - b3_firstSleepingSet; - b3Array_Resize( world->sleepingSets, sleepingSetCount ); - memset( world->fixedSets, 0, sizeof( world->fixedSets ) ); - if ( sleepingSetCount > 0 ) - { - memset( world->sleepingSets.data, 0, (size_t)sleepingSetCount * sizeof( b3SolverSet ) ); - } - + b3Array_Resize( world->solverSets, setCount ); + memset( world->solverSets.data, 0, (size_t)setCount * sizeof( b3SolverSet ) ); for ( int i = 0; i < setCount; ++i ) { - b3DesSolverSet( r, b3GetSolverSet( world, i ) ); + b3DesSolverSet( r, world->solverSets.data + i ); } } @@ -1270,13 +1166,6 @@ bool b3DeserializeIntoShell( const uint8_t* data, int size, b3World* world, b3Re return false; } - b3DesPodArray( r, world->fatAABBs ); - - if ( !r->ok ) - { - return false; - } - // 6. Contact sparse array b3DesContacts( r, world ); @@ -1372,8 +1261,17 @@ bool b3DeserializeIntoShell( const uint8_t* data, int size, b3World* world, b3Re { b3DesTree( r, &bp->trees[t] ); } + for ( int t = 0; t < b3_bodyTypeCount; ++t ) + { + b3DesBitSet( r, &bp->movedProxies[t] ); + } + + b3Array_Destroy( bp->moveArray ); + b3Array_Create( bp->moveArray ); + b3DesPodArray( r, bp->moveArray ); + b3DesHashSet( r, &bp->pairSet ); - // The gathered moved siblings are per step scratch and stay at the shell's NULL + // Transient moveResults/movePairs stay at shell's NULL/0 } // 11. Constraint graph @@ -1385,7 +1283,5 @@ bool b3DeserializeIntoShell( const uint8_t* data, int size, b3World* world, b3Re } } - b3DesNames( r, &world->names ); - return r->ok; } diff --git a/src/world_snapshot.h b/src/world_snapshot.h index f58aa06..7bf0065 100644 --- a/src/world_snapshot.h +++ b/src/world_snapshot.h @@ -4,7 +4,7 @@ #pragma once #include "recording.h" -#include "replay.h" +#include "recording_replay.h" #include #include diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b73e089..1635ca7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,30 +6,21 @@ set(BOX3D_TEST_FILES test_bitset.c test_body.c test_body_query.c - test_broad_phase.c test_collision.c test_compound.c test_container.c test_determinism.c test_distance.c - test_dynamic_tree.c - test_hash.c test_height_field.c test_hull.c test_id.c test_joint.c test_large_world.c test_macros.h - test_manifold.c test_math.c - test_mesh.c test_mover.c - test_name_cache.c test_recording.c - test_restitution.c - test_sat.c test_shape.c - test_step.c test_table.c test_world.c ) @@ -42,15 +33,8 @@ set_target_properties(test PROPERTIES C_EXTENSIONS NO ) -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. +# Special access to Box3D internals for testing 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) diff --git a/test/main.c b/test/main.c index 37980e7..fb8fc20 100644 --- a/test/main.c +++ b/test/main.c @@ -29,29 +29,20 @@ extern int AllocatorTest( void ); extern int BitTest( void ); extern int BodyTest( void ); extern int BodyQueryTest( void ); -extern int BroadPhaseTest( void ); extern int CollisionTest( void ); extern int CompoundTest( void ); extern int ContainerTest( void ); extern int DeterminismTest( void ); extern int DistanceTest( void ); -extern int DynamicTreeTest( void ); -extern int HashTest( void ); extern int HeightFieldTest( void ); extern int HullTest( void ); extern int IdTest( void ); extern int JointTest( void ); extern int LargeWorldTest( void ); -extern int ManifoldTest( void ); extern int MathTest( void ); -extern int MeshTest( void ); extern int MoverTest( void ); -extern int NameCacheTest( void ); extern int RecordingTest( void ); -extern int RestitutionTest( void ); -extern int SeparatingAxisTest( void ); extern int ShapeTest( void ); -extern int StepTest( void ); extern int TableTest( void ); extern int WorldTest( void ); @@ -108,29 +99,20 @@ int main( int argc, char** argv ) MAYBE_RUN_TEST( BitTest ); MAYBE_RUN_TEST( BodyTest ); MAYBE_RUN_TEST( BodyQueryTest ); - MAYBE_RUN_TEST( BroadPhaseTest ); MAYBE_RUN_TEST( CollisionTest ); MAYBE_RUN_TEST( CompoundTest ); MAYBE_RUN_TEST( ContainerTest ); MAYBE_RUN_TEST( DeterminismTest ); MAYBE_RUN_TEST( DistanceTest ); - MAYBE_RUN_TEST( DynamicTreeTest ); - MAYBE_RUN_TEST( HashTest ); MAYBE_RUN_TEST( HeightFieldTest ); MAYBE_RUN_TEST( HullTest ); MAYBE_RUN_TEST( IdTest ); MAYBE_RUN_TEST( JointTest ); MAYBE_RUN_TEST( LargeWorldTest ); - MAYBE_RUN_TEST( ManifoldTest ); MAYBE_RUN_TEST( MathTest ); - MAYBE_RUN_TEST( MeshTest ); MAYBE_RUN_TEST( MoverTest ); - MAYBE_RUN_TEST( NameCacheTest ); MAYBE_RUN_TEST( RecordingTest ); - MAYBE_RUN_TEST( RestitutionTest ); - MAYBE_RUN_TEST( SeparatingAxisTest ); MAYBE_RUN_TEST( ShapeTest ); - MAYBE_RUN_TEST( StepTest ); MAYBE_RUN_TEST( TableTest ); MAYBE_RUN_TEST( WorldTest ); diff --git a/test/test_allocator.c b/test/test_allocator.c index b8bd2bd..ca7acaf 100644 --- a/test/test_allocator.c +++ b/test/test_allocator.c @@ -2,11 +2,8 @@ // SPDX-License-Identifier: MIT #include "block_allocator.h" -#include "core.h" #include "test_macros.h" -#include "box3d/types.h" - typedef struct { int value1; @@ -43,57 +40,10 @@ static int TestBlockClear( void ) return 0; } -// The free list link is a pointer stored in the element, so a stride that is not a multiple -// of the alignment leaves odd elements on a bad boundary. See issue #78. -static int TestBlockAlignment( void ) -{ - // The manifold sizes are the reported case - int elementSizes[] = { 12, (int)sizeof( b3Manifold ), 3 * (int)sizeof( b3Manifold ) }; - - for ( int i = 0; i < ARRAY_COUNT( elementSizes ); ++i ) - { - b3BlockAllocator allocator = b3CreateBlockAllocator( elementSizes[i], 0 ); - - // Hold the elements so the indices advance and a block boundary is crossed - void* elements[B3_BLOCK_SIZE + 8]; - int count = ARRAY_COUNT( elements ); - - for ( int j = 0; j < count; ++j ) - { - elements[j] = b3AllocateElement( &allocator ); - ENSURE( elements[j] != NULL ); - ENSURE( ( (uintptr_t)elements[j] & ( B3_BLOCK_ALIGNMENT - 1 ) ) == 0 ); - } - - for ( int j = 0; j < count; ++j ) - { - b3FreeElement( &allocator, elements[j] ); - } - - // Now drain the free list - for ( int j = 0; j < count; ++j ) - { - elements[j] = b3AllocateElement( &allocator ); - ENSURE( elements[j] != NULL ); - ENSURE( ( (uintptr_t)elements[j] & ( B3_BLOCK_ALIGNMENT - 1 ) ) == 0 ); - } - - for ( int j = 0; j < count; ++j ) - { - b3FreeElement( &allocator, elements[j] ); - } - - b3DestroyBlockAllocator( &allocator ); - } - - return 0; -} - int AllocatorTest( void ) { RUN_SUBTEST( TestBlockAllocate ); RUN_SUBTEST( TestBlockClear ); - RUN_SUBTEST( TestBlockAlignment ); return 0; } diff --git a/test/test_body.c b/test/test_body.c index 22337c7..10e7853 100644 --- a/test/test_body.c +++ b/test/test_body.c @@ -7,10 +7,6 @@ #include "box3d/collision.h" #include "box3d/math_functions.h" -// Reach into internals to observe body extents and the dirty mass flag. -#include "body.h" -#include "physics_world.h" - #include // b3UpdateBodyMassData shifts each shape's inertia to the body center of mass with the parallel @@ -121,540 +117,9 @@ static int FarCubeSphereMass( void ) return 0; } -// Shapes added with updateBodyMass = false defer the mass update, which is also the only place -// body extents are computed. A body that reaches the solver with minExtent == B3_HUGE never passes -// the continuous collision gate. The dirty mass flag must track the deferral, and both -// ApplyMassFromShapes and SetMassData must leave finite extents behind. -static int DeferredMassExtents( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.updateBodyMass = false; - - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - - // Deferred create leaves mass and extents untouched but marks the body dirty. - b3BodyId applyId = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( applyId, &shapeDef, &sphere ); - - b3World* world = b3GetWorld( applyId.world0 ); - b3Body* applyBody = b3GetBodyFullId( world, applyId ); - b3BodySim* applySim = b3GetBodySim( world, applyBody ); - - ENSURE( ( applyBody->flags & b3_dirtyMass ) != 0 ); - ENSURE( applySim->minExtent == B3_HUGE ); - - // ApplyMassFromShapes computes extents and clears the flag. - b3Body_ApplyMassFromShapes( applyId ); - ENSURE( ( applyBody->flags & b3_dirtyMass ) == 0 ); - ENSURE( applySim->minExtent < B3_HUGE ); - - // SetMassData alone must also produce finite extents and clear the flag (the issue #35 repro). - b3BodyId massId = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( massId, &shapeDef, &sphere ); - - b3Body* massBody = b3GetBodyFullId( world, massId ); - b3BodySim* massSim = b3GetBodySim( world, massBody ); - ENSURE( ( massBody->flags & b3_dirtyMass ) != 0 ); - - b3Matrix3 inertia = { { 0.2f, 0.0f, 0.0f }, { 0.0f, 0.2f, 0.0f }, { 0.0f, 0.0f, 0.2f } }; - b3MassData massData = { 2.0f, { 0.0f, 0.0f, 0.0f }, inertia }; - b3Body_SetMassData( massId, massData ); - - ENSURE( ( massBody->flags & b3_dirtyMass ) == 0 ); - ENSURE( massSim->minExtent < B3_HUGE ); - - b3DestroyWorld( worldId ); - return 0; -} - -// b3Body_SetMassData overrides the mass properties directly, bypassing the shapes. It must derive -// everything the solver reads from the supplied tensor: the inverse mass, the local inverse inertia, -// and the world inverse inertia rotated by the body orientation. Fixed rotation zeros the angular part. -// These tests drive it through the public getters, no shapes required. - -// Diagonal inertia with inverses that are exact in float, so tolerances stay tight. -static const b3Matrix3 kDiagInertia = { { 2.0f, 0.0f, 0.0f }, { 0.0f, 4.0f, 0.0f }, { 0.0f, 0.0f, 8.0f } }; - -static int SetMassDataRoundTrip( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 5.0f, -3.0f, 2.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3Vec3 center = { 0.1f, 0.2f, 0.3f }; - b3MassData massData = { 3.0f, center, kDiagInertia }; - b3Body_SetMassData( bodyId, massData ); - - ENSURE_SMALL( b3Body_GetMass( bodyId ) - 3.0f, 1e-6f ); - ENSURE_SMALL( b3Body_GetInverseMass( bodyId ) - 1.0f / 3.0f, 1e-6f ); - - b3MassData md = b3Body_GetMassData( bodyId ); - ENSURE_SMALL( md.mass - 3.0f, 1e-6f ); - ENSURE_SMALL( md.center.x - center.x, 1e-6f ); - ENSURE_SMALL( md.center.y - center.y, 1e-6f ); - ENSURE_SMALL( md.center.z - center.z, 1e-6f ); - ENSURE_SMALL( md.inertia.cx.x - 2.0f, 1e-6f ); - ENSURE_SMALL( md.inertia.cy.y - 4.0f, 1e-6f ); - ENSURE_SMALL( md.inertia.cz.z - 8.0f, 1e-6f ); - - b3Vec3 localCenter = b3Body_GetLocalCenter( bodyId ); - ENSURE_SMALL( localCenter.x - center.x, 1e-6f ); - ENSURE_SMALL( localCenter.y - center.y, 1e-6f ); - ENSURE_SMALL( localCenter.z - center.z, 1e-6f ); - - b3Matrix3 localInertia = b3Body_GetLocalRotationalInertia( bodyId ); - ENSURE_SMALL( localInertia.cx.x - 2.0f, 1e-6f ); - ENSURE_SMALL( localInertia.cy.y - 4.0f, 1e-6f ); - ENSURE_SMALL( localInertia.cz.z - 8.0f, 1e-6f ); - - // Identity rotation, so the world inverse inertia is just the local inverse: diag(1/2, 1/4, 1/8). - b3Matrix3 invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - ENSURE_SMALL( invWorld.cx.x - 0.5f, 1e-5f ); - ENSURE_SMALL( invWorld.cy.y - 0.25f, 1e-5f ); - ENSURE_SMALL( invWorld.cz.z - 0.125f, 1e-5f ); - ENSURE_SMALL( invWorld.cy.x, 1e-5f ); - ENSURE_SMALL( invWorld.cz.x, 1e-5f ); - ENSURE_SMALL( invWorld.cx.y, 1e-5f ); - ENSURE_SMALL( invWorld.cz.y, 1e-5f ); - ENSURE_SMALL( invWorld.cx.z, 1e-5f ); - ENSURE_SMALL( invWorld.cy.z, 1e-5f ); - - // World center of mass is the body origin plus the local center under identity rotation. - b3Pos worldCenter = b3Body_GetWorldCenter( bodyId ); - ENSURE_SMALL( worldCenter.x - ( 5.0f + center.x ), 1e-5f ); - ENSURE_SMALL( worldCenter.y - ( -3.0f + center.y ), 1e-5f ); - ENSURE_SMALL( worldCenter.z - ( 2.0f + center.z ), 1e-5f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// The world inverse inertia must be the local inverse rotated into world space. A 90 degree turn about -// z swaps the x and y principal moments, so diag(1/2, 1/4, 1/8) becomes diag(1/4, 1/2, 1/8). This is the -// regression guard: before SetMassData rotated the tensor it left the world inverse inertia stale. -static int SetMassDataWorldInertiaRotated( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MassData massData = { 1.0f, { 0.0f, 0.0f, 0.0f }, kDiagInertia }; - b3Body_SetMassData( bodyId, massData ); - - // The local inertia is stored untouched by the world transform. - b3Matrix3 localInertia = b3Body_GetLocalRotationalInertia( bodyId ); - ENSURE_SMALL( localInertia.cx.x - 2.0f, 1e-6f ); - ENSURE_SMALL( localInertia.cy.y - 4.0f, 1e-6f ); - ENSURE_SMALL( localInertia.cz.z - 8.0f, 1e-6f ); - - b3Matrix3 invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - ENSURE_SMALL( invWorld.cx.x - 0.25f, 1e-4f ); - ENSURE_SMALL( invWorld.cy.y - 0.5f, 1e-4f ); - ENSURE_SMALL( invWorld.cz.z - 0.125f, 1e-4f ); - ENSURE_SMALL( invWorld.cy.x, 1e-4f ); - ENSURE_SMALL( invWorld.cz.x, 1e-4f ); - ENSURE_SMALL( invWorld.cx.y, 1e-4f ); - ENSURE_SMALL( invWorld.cz.y, 1e-4f ); - ENSURE_SMALL( invWorld.cx.z, 1e-4f ); - ENSURE_SMALL( invWorld.cy.z, 1e-4f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Fixed rotation must leave the mass intact but drive the whole angular inertia to zero, even when the -// caller hands in a real tensor. -static int SetMassDataFixedRotation( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.motionLocks.angularX = true; - bodyDef.motionLocks.angularY = true; - bodyDef.motionLocks.angularZ = true; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MassData massData = { 5.0f, { 0.0f, 0.0f, 0.0f }, kDiagInertia }; - b3Body_SetMassData( bodyId, massData ); - - ENSURE_SMALL( b3Body_GetMass( bodyId ) - 5.0f, 1e-6f ); - ENSURE_SMALL( b3Body_GetInverseMass( bodyId ) - 0.2f, 1e-6f ); - - b3Matrix3 localInertia = b3Body_GetLocalRotationalInertia( bodyId ); - ENSURE_SMALL( localInertia.cx.x, 1e-6f ); - ENSURE_SMALL( localInertia.cy.y, 1e-6f ); - ENSURE_SMALL( localInertia.cz.z, 1e-6f ); - - b3Matrix3 invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - ENSURE_SMALL( invWorld.cx.x, 1e-6f ); - ENSURE_SMALL( invWorld.cy.y, 1e-6f ); - ENSURE_SMALL( invWorld.cz.z, 1e-6f ); - - b3MassData md = b3Body_GetMassData( bodyId ); - ENSURE_SMALL( md.inertia.cx.x, 1e-6f ); - ENSURE_SMALL( md.inertia.cy.y, 1e-6f ); - ENSURE_SMALL( md.inertia.cz.z, 1e-6f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Zero mass and a zero tensor have zero determinant, so the inverses must collapse to zero rather than -// divide by it. -static int SetMassDataZeroMass( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MassData massData = { 0.0f, { 0.0f, 0.0f, 0.0f }, b3Mat3_zero }; - b3Body_SetMassData( bodyId, massData ); - - ENSURE_SMALL( b3Body_GetInverseMass( bodyId ), 1e-6f ); - - b3Matrix3 localInertia = b3Body_GetLocalRotationalInertia( bodyId ); - ENSURE_SMALL( localInertia.cx.x, 1e-6f ); - ENSURE_SMALL( localInertia.cy.y, 1e-6f ); - ENSURE_SMALL( localInertia.cz.z, 1e-6f ); - - b3Matrix3 invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - ENSURE_SMALL( invWorld.cx.x, 1e-6f ); - ENSURE_SMALL( invWorld.cy.y, 1e-6f ); - ENSURE_SMALL( invWorld.cz.z, 1e-6f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// The stored linear velocity tracks the center of mass. Moving the center picks a different material -// point, so a spinning body must have its velocity re-referenced by omega x (newCenter - oldCenter), -// otherwise the mass edit silently injects or drains kinetic energy. Under identity rotation the world -// shift equals the supplied local center, keeping the expected values exact in float. -static int SetMassDataConsistentVelocity( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 7.0f, 1.0f, -4.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - // Spin about the origin center, then shift the center of mass off the origin. - b3Vec3 omega = { 1.0f, 2.0f, 4.0f }; - b3Body_SetLinearVelocity( bodyId, (b3Vec3){ 1.0f, -2.0f, 3.0f } ); - b3Body_SetAngularVelocity( bodyId, omega ); - - b3Vec3 center = { 0.5f, 0.25f, 0.125f }; - b3MassData massData = { 3.0f, center, kDiagInertia }; - b3Body_SetMassData( bodyId, massData ); - - // omega x center = ( 2*0.125 - 4*0.25, 4*0.5 - 1*0.125, 1*0.25 - 2*0.5 ) = ( -0.75, 1.875, -0.75 ) - b3Vec3 v = b3Body_GetLinearVelocity( bodyId ); - ENSURE_SMALL( v.x - ( 1.0f - 0.75f ), 1e-6f ); - ENSURE_SMALL( v.y - ( -2.0f + 1.875f ), 1e-6f ); - ENSURE_SMALL( v.z - ( 3.0f - 0.75f ), 1e-6f ); - - // Only the reference point moved, the angular velocity is untouched. - b3Vec3 w = b3Body_GetAngularVelocity( bodyId ); - ENSURE_SMALL( w.x - omega.x, 1e-6f ); - ENSURE_SMALL( w.y - omega.y, 1e-6f ); - ENSURE_SMALL( w.z - omega.z, 1e-6f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Extents bound the shapes about the center of mass, per axis. An offset shape must count its -// offset, not just its own size. -static int ShapeExtents( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - - // Kinematic bodies measure from the body origin - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_kinematicBody; - - b3BodyId capsuleId = b3CreateBody( worldId, &bodyDef ); - b3Capsule capsule = { { -2.0f, 0.0f, 0.0f }, { -1.0f, 0.0f, 0.0f }, 0.2f }; - b3CreateCapsuleShape( capsuleId, &shapeDef, &capsule ); - - b3Vec3 maxExtent = b3Body_GetMaxExtent( capsuleId ); - ENSURE_SMALL( maxExtent.x - 2.2f, 1e-5f ); - ENSURE_SMALL( maxExtent.y - 0.2f, 1e-5f ); - ENSURE_SMALL( maxExtent.z - 0.2f, 1e-5f ); - ENSURE_SMALL( b3Body_GetMinExtent( capsuleId ) - 0.2f, 1e-5f ); - - b3BodyId sphereId = b3CreateBody( worldId, &bodyDef ); - b3Sphere sphere = { { 1.0f, 2.0f, 3.0f }, 0.5f }; - b3CreateSphereShape( sphereId, &shapeDef, &sphere ); - - maxExtent = b3Body_GetMaxExtent( sphereId ); - ENSURE_SMALL( maxExtent.x - 1.5f, 1e-5f ); - ENSURE_SMALL( maxExtent.y - 2.5f, 1e-5f ); - ENSURE_SMALL( maxExtent.z - 3.5f, 1e-5f ); - ENSURE_SMALL( b3Body_GetMinExtent( sphereId ) - 0.5f, 1e-5f ); - - // Dynamic bodies measure from the center of mass. A light sphere hung off a cube pulls the - // center toward it, so the far side of the sphere is the widest point. - bodyDef.type = b3_dynamicBody; - b3BodyId cubeId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull cube = b3MakeCubeHull( 0.5f ); - b3CreateHullShape( cubeId, &shapeDef, &cube.base ); - b3Sphere offsetSphere = { { 1.0f, 0.0f, 0.0f }, 0.2f }; - b3CreateSphereShape( cubeId, &shapeDef, &offsetSphere ); - - b3Vec3 localCenter = b3Body_GetLocalCenter( cubeId ); - ENSURE( 0.0f < localCenter.x && localCenter.x < 0.5f ); - - maxExtent = b3Body_GetMaxExtent( cubeId ); - ENSURE_SMALL( maxExtent.x - ( 1.2f - localCenter.x ), 1e-5f ); - ENSURE_SMALL( maxExtent.y - 0.5f, 1e-5f ); - ENSURE_SMALL( maxExtent.z - 0.5f, 1e-5f ); - ENSURE_SMALL( b3Body_GetMinExtent( cubeId ) - 0.2f, 1e-5f ); - - b3Vec3 originExtent = b3Body_GetMaxExtentOrigin( cubeId ); - ENSURE_SMALL( originExtent.x - 1.2f, 1e-5f ); - ENSURE_SMALL( originExtent.y - 0.5f, 1e-5f ); - ENSURE_SMALL( originExtent.z - 0.5f, 1e-5f ); - - // A mesh has no mass, so the sphere alone places the center at x = 1 and the far edge of the - // mesh at x = -3 is four units out. - b3Vec3 vertices[6] = { - { -3.0f, 0.0f, -1.0f }, { -2.0f, 0.0f, 1.0f }, { -1.0f, 0.0f, -1.0f }, - { 1.0f, 0.0f, -1.0f }, { 2.0f, 0.0f, 1.0f }, { 3.0f, 0.0f, -1.0f }, - }; - int32_t indices[6] = { 0, 1, 2, 3, 4, 5 }; - b3MeshDef meshDef = { 0 }; - meshDef.vertices = vertices; - meshDef.stride = sizeof( b3Vec3 ); - meshDef.indices = indices; - meshDef.vertexCount = 6; - meshDef.triangleCount = 2; - b3MeshData* mesh = b3CreateMesh( &meshDef, NULL, 0 ); - - b3BodyId meshId = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( meshId, &shapeDef, &offsetSphere ); - b3CreateMeshShape( meshId, &shapeDef, mesh, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - - localCenter = b3Body_GetLocalCenter( meshId ); - ENSURE_SMALL( localCenter.x - 1.0f, 1e-5f ); - - maxExtent = b3Body_GetMaxExtent( meshId ); - ENSURE_SMALL( maxExtent.x - 4.0f, 1e-4f ); - ENSURE_SMALL( maxExtent.y - 0.2f, 1e-4f ); - ENSURE_SMALL( maxExtent.z - 1.0f, 1e-4f ); - ENSURE_SMALL( b3Body_GetMinExtent( meshId ) - 0.2f, 1e-5f ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -static int CompoundInertiaConsistency( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Normalize( (b3Vec3){ 0.3f, -0.8f, 0.5f } ), 1.3f ); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull boxA = b3MakeOffsetBoxHull( 0.5f, 0.25f, 0.5f, (b3Vec3){ 1.0f, 1.0f, 0.0f } ); - b3BoxHull boxB = b3MakeOffsetBoxHull( 0.3f, 0.6f, 0.2f, (b3Vec3){ -0.8f, -0.4f, 0.3f } ); - b3CreateHullShape( bodyId, &shapeDef, &boxA.base ); - b3CreateHullShape( bodyId, &shapeDef, &boxB.base ); - b3Body_ApplyMassFromShapes( bodyId ); - - b3Matrix3 local = b3Body_GetLocalRotationalInertia( bodyId ); - ENSURE( b3AbsFloat( local.cy.x ) > 0.1f ); - - b3Matrix3 r = b3MakeMatrixFromQuat( bodyDef.rotation ); - b3Matrix3 world = b3MulMM( b3MulMM( r, local ), b3Transpose( r ) ); - b3Matrix3 invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - b3Matrix3 product = b3MulMM( invWorld, world ); - - ENSURE_SMALL( product.cx.x - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cy.y - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cz.z - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cx.y, 1.0e-4f ); - ENSURE_SMALL( product.cx.z, 1.0e-4f ); - ENSURE_SMALL( product.cy.x, 1.0e-4f ); - ENSURE_SMALL( product.cy.z, 1.0e-4f ); - ENSURE_SMALL( product.cz.x, 1.0e-4f ); - ENSURE_SMALL( product.cz.y, 1.0e-4f ); - - b3Quat q2 = b3MakeQuatFromAxisAngle( b3Normalize( (b3Vec3){ -1.0f, 0.2f, 0.4f } ), -2.1f ); - b3Body_SetTransform( bodyId, b3Body_GetPosition( bodyId ), q2 ); - r = b3MakeMatrixFromQuat( q2 ); - world = b3MulMM( b3MulMM( r, local ), b3Transpose( r ) ); - invWorld = b3Body_GetWorldInverseRotationalInertia( bodyId ); - product = b3MulMM( invWorld, world ); - ENSURE_SMALL( product.cx.x - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cy.y - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cz.z - 1.0f, 1.0e-4f ); - ENSURE_SMALL( product.cy.x, 1.0e-4f ); - ENSURE_SMALL( product.cz.y, 1.0e-4f ); - - b3DestroyWorld( worldId ); - return 0; -} - -static b3BodyId CreateSpinningHullBody( b3WorldId worldId, float x, const b3HullData* hull ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position.x = x; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Normalize( (b3Vec3){ 0.3f, -0.8f, 0.5f } ), 1.3f ); - bodyDef.angularVelocity = (b3Vec3){ 1.0f, -2.0f, 3.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, hull ); - return bodyId; -} - -static bool HasGyroscopicTorque( b3BodyId bodyId ) -{ - b3World* world = b3GetWorld( bodyId.world0 ); - b3Body* body = b3GetBodyFullId( world, bodyId ); - return ( body->flags & b3_enableGyroscopicTorque ) != 0; -} - -// Bodies within the isotropic tolerance skip the gyroscopic solve, so in free flight the world -// angular velocity is untouched. Anisotropic bodies precess. -static int IsotropicInertiaTolerance( void ) -{ - b3Vec3 w0 = { 1.0f, -2.0f, 3.0f }; - - b3HullData* rock = b3CreateRock( 0.5f ); - b3HullData* complex = b3CreateComplexHull( 0.5f ); - b3BoxHull cube = b3MakeCubeHull( 0.5f ); - b3Transform cubeTransform = { b3Vec3_zero, b3MakeQuatFromAxisAngle( b3Normalize( (b3Vec3){ 1.0f, 2.0f, 3.0f } ), 0.7f ) }; - b3BoxHull rotatedCube = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, cubeTransform ); - b3BoxHull plank = b3MakeBoxHull( 0.5f, 1.0f, 0.25f ); - - { - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyId rockId = CreateSpinningHullBody( worldId, 0.0f, rock ); - b3BodyId complexId = CreateSpinningHullBody( worldId, 5.0f, complex ); - b3BodyId cubeId = CreateSpinningHullBody( worldId, 10.0f, &cube.base ); - b3BodyId rotatedCubeId = CreateSpinningHullBody( worldId, 15.0f, &rotatedCube.base ); - b3BodyId plankId = CreateSpinningHullBody( worldId, 20.0f, &plank.base ); - - ENSURE( HasGyroscopicTorque( rockId ) == false ); - ENSURE( HasGyroscopicTorque( complexId ) == false ); - ENSURE( HasGyroscopicTorque( cubeId ) == false ); - ENSURE( HasGyroscopicTorque( rotatedCubeId ) == false ); - ENSURE( HasGyroscopicTorque( plankId ) ); - - for ( int i = 0; i < 10; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3Vec3 w = b3Body_GetAngularVelocity( rockId ); - ENSURE( w.x == w0.x && w.y == w0.y && w.z == w0.z ); - w = b3Body_GetAngularVelocity( complexId ); - ENSURE( w.x == w0.x && w.y == w0.y && w.z == w0.z ); - w = b3Body_GetAngularVelocity( rotatedCubeId ); - ENSURE( w.x == w0.x && w.y == w0.y && w.z == w0.z ); - w = b3Body_GetAngularVelocity( plankId ); - ENSURE( b3Length( b3Sub( w, w0 ) ) > 0.01f ); - - b3Body_SetMotionLocks( plankId, (b3MotionLocks){ .angularX = true, .angularY = true, .angularZ = true } ); - ENSURE( HasGyroscopicTorque( plankId ) == false ); - - // Gyroscopic torque stays off until a mass update proves the body anisotropic - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position.x = 25.0f; - bodyDef.angularVelocity = w0; - b3BodyId emptyId = b3CreateBody( worldId, &bodyDef ); - ENSURE( HasGyroscopicTorque( emptyId ) == false ); - - bodyDef.position.x = 30.0f; - b3BodyId deferredId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.updateBodyMass = false; - b3CreateHullShape( deferredId, &shapeDef, &plank.base ); - ENSURE( HasGyroscopicTorque( deferredId ) == false ); - - b3Body_ApplyMassFromShapes( deferredId ); - ENSURE( HasGyroscopicTorque( deferredId ) ); - - b3DestroyWorld( worldId ); - } - - { - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - worldDef.isotropicInertiaTolerance = 0.0f; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyId rockId = CreateSpinningHullBody( worldId, 0.0f, rock ); - b3BodyId cubeId = CreateSpinningHullBody( worldId, 10.0f, &cube.base ); - - ENSURE( HasGyroscopicTorque( rockId ) ); - ENSURE( HasGyroscopicTorque( cubeId ) == false ); - - for ( int i = 0; i < 10; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3Vec3 w = b3Body_GetAngularVelocity( rockId ); - ENSURE( b3Length( b3Sub( w, w0 ) ) > 0.001f ); - - b3DestroyWorld( worldId ); - } - - b3DestroyHull( rock ); - b3DestroyHull( complex ); - return 0; -} - int BodyTest( void ) { RUN_SUBTEST( FarSingleSphereMass ); RUN_SUBTEST( FarCubeSphereMass ); - RUN_SUBTEST( DeferredMassExtents ); - RUN_SUBTEST( SetMassDataRoundTrip ); - RUN_SUBTEST( SetMassDataWorldInertiaRotated ); - RUN_SUBTEST( SetMassDataFixedRotation ); - RUN_SUBTEST( SetMassDataZeroMass ); - RUN_SUBTEST( SetMassDataConsistentVelocity ); - RUN_SUBTEST( ShapeExtents ); - RUN_SUBTEST( CompoundInertiaConsistency ); - RUN_SUBTEST( IsotropicInertiaTolerance ); return 0; } diff --git a/test/test_body_query.c b/test/test_body_query.c index 586a21b..a2939cb 100644 --- a/test/test_body_query.c +++ b/test/test_body_query.c @@ -355,169 +355,6 @@ static int OverlapFilter( void ) return 0; } -static bool CountOverlapCallback( b3ShapeId shapeId, void* context ) -{ - (void)shapeId; - *(int*)context += 1; - return true; -} - -// A baked compound keeps its tree and its child placements in the compound frame while the query -// proxy is in world space, so a compound on a turned body only answers correctly if the proxy is -// brought back into that frame first. -static int OverlapCompoundRotatedBody( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3CompoundSphereDef spheres[2] = { - { .sphere = { { -3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat }, - { .sphere = { { 3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat }, - }; - b3CompoundDef compoundDef = { .spheres = spheres, .sphereCount = 2 }; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - - b3Transform pose = { .p = { 10.0f, 20.0f, 30.0f }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ) }; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ pose.p.x, pose.p.y, pose.p.z }; - bodyDef.rotation = pose.q; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); - - b3QueryFilter filter = b3DefaultQueryFilter(); - - // Sitting on the second child, which the body pose has swung onto the +Y side - b3Vec3 onChild = b3TransformPoint( pose, (b3Vec3){ 3.0f, 0.0f, 0.0f } ); - b3ShapeProxy hitProxy = { &onChild, 1, 0.1f }; - - int hits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &hitProxy, filter, CountOverlapCallback, &hits ); - ENSURE( hits == 1 ); - - b3WorldTransform bodyTransform = { .p = bodyDef.position, .q = bodyDef.rotation }; - ENSURE( b3Body_OverlapShape( bodyId, b3Pos_zero, &hitProxy, filter, bodyTransform ) ); - - // The gap between the two children stays empty - b3Vec3 inGap = b3TransformPoint( pose, (b3Vec3){ 0.0f, 0.0f, 0.0f } ); - b3ShapeProxy gapProxy = { &inGap, 1, 0.25f }; - - hits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &gapProxy, filter, CountOverlapCallback, &hits ); - ENSURE( hits == 0 ); - ENSURE( b3Body_OverlapShape( bodyId, b3Pos_zero, &gapProxy, filter, bodyTransform ) == false ); - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - return 0; -} - -// A box hull proxy built around a world target with a zero origin must hit the same shapes as the -// same box built at the local origin and queried with the target as origin. This is the origin -// relative equivalence the world query promises, and the pattern users reach for when they bake a -// query box with b3MakeTransformedBoxHull. -static int OverlapHullProxyEquivalence( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 10.0f, 0.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull box = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3World_Step( worldId, 1.0f / 60.0f, 1 ); - - b3QueryFilter filter = b3DefaultQueryFilter(); - - // Overlapping target: a 10 wide query box centered on the body. - { - b3Vec3 offset = { 10.0f, 0.0f, 0.0f }; - - b3BoxHull baked = b3MakeTransformedBoxHull( 5.0f, 5.0f, 5.0f, (b3Transform){ offset, b3Quat_identity } ); - b3ShapeProxy bakedProxy = { baked.boxPoints, baked.base.vertexCount, 0.0f }; - int bakedHits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &bakedProxy, filter, CountOverlapCallback, &bakedHits ); - - b3Pos origin = b3OffsetPos( b3Pos_zero, offset ); - b3BoxHull local = b3MakeBoxHull( 5.0f, 5.0f, 5.0f ); - b3ShapeProxy localProxy = { local.boxPoints, local.base.vertexCount, 0.0f }; - int localHits = 0; - b3World_OverlapShape( worldId, origin, &localProxy, filter, CountOverlapCallback, &localHits ); - - ENSURE( bakedHits == 1 ); - ENSURE( localHits == bakedHits ); - } - - // Clearing target: same box far from the body, both formulations agree on the miss. - { - b3Vec3 offset = { 100.0f, 0.0f, 0.0f }; - - b3BoxHull baked = b3MakeTransformedBoxHull( 5.0f, 5.0f, 5.0f, (b3Transform){ offset, b3Quat_identity } ); - b3ShapeProxy bakedProxy = { baked.boxPoints, baked.base.vertexCount, 0.0f }; - int bakedHits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &bakedProxy, filter, CountOverlapCallback, &bakedHits ); - - b3Pos origin = b3OffsetPos( b3Pos_zero, offset ); - b3BoxHull local = b3MakeBoxHull( 5.0f, 5.0f, 5.0f ); - b3ShapeProxy localProxy = { local.boxPoints, local.base.vertexCount, 0.0f }; - int localHits = 0; - b3World_OverlapShape( worldId, origin, &localProxy, filter, CountOverlapCallback, &localHits ); - - ENSURE( bakedHits == 0 ); - ENSURE( localHits == bakedHits ); - } - - b3DestroyWorld( worldId ); - return 0; -} - -// A quarter turn baked into the query hull must reach the overlap test. A long thin bar hits a body -// off the origin when aligned along X and clears it once rotated to lie along Z. -static int OverlapHullProxyRotation( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 3.0f, 0.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3World_Step( worldId, 1.0f / 60.0f, 1 ); - - b3QueryFilter filter = b3DefaultQueryFilter(); - - // Bar long in local X, centered at the origin, reaches the body at x = 3. - b3BoxHull aligned = b3MakeTransformedBoxHull( 4.0f, 0.3f, 0.3f, b3Transform_identity ); - b3ShapeProxy alignedProxy = { aligned.boxPoints, aligned.base.vertexCount, 0.0f }; - int alignedHits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &alignedProxy, filter, CountOverlapCallback, &alignedHits ); - ENSURE( alignedHits == 1 ); - - // Rotated a quarter turn about Y the long axis points along Z, so the bar no longer reaches x = 3. - b3Quat q = b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.5f * B3_PI ); - b3BoxHull turned = b3MakeTransformedBoxHull( 4.0f, 0.3f, 0.3f, (b3Transform){ b3Vec3_zero, q } ); - b3ShapeProxy turnedProxy = { turned.boxPoints, turned.base.vertexCount, 0.0f }; - int turnedHits = 0; - b3World_OverlapShape( worldId, b3Pos_zero, &turnedProxy, filter, CountOverlapCallback, &turnedHits ); - ENSURE( turnedHits == 0 ); - - b3DestroyWorld( worldId ); - return 0; -} - // CollideMover ----------------------------------------------------------------------------- static int MoverTouchesBox( void ) @@ -620,412 +457,6 @@ static int MoverCapacity( void ) return 0; } -// TimeOfImpactMover ------------------------------------------------------------------------ - -// The mover capsule is expressed in the query frame, so a core segment starting at the origin -// stands the character on the query point. Targets sit on the sweep line at y = 0. -static b3Capsule MakeStandingMover( void ) -{ - return (b3Capsule){ { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.25f }; -} - -static int MoverTOIHitsBox( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3ShapeId shapeId = b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - // Face at x = 4.5, mover radius 0.25, so 4.25 of the 10 unit sweep is free. - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 5.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 0.425f, 1e-2f ); - ENSURE( b3IsNormalized( result.normal ) ); - ENSURE_SMALL( result.normal.x + 1.0f, 1e-3f ); - - // The result carries a shape id, so the hit shape must come back identified. - ENSURE( b3Shape_IsValid( result.shapeId ) ); - ENSURE( result.shapeId.index1 == shapeId.index1 ); - ENSURE( result.shapeId.generation == shapeId.generation ); - - b3DestroyWorld( worldId ); - return 0; -} - -static int MoverTOISeparated( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - // Sweeping along +Y holds the X gap at 4.25 for the whole interval. - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 5.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 0.0f, 10.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 1.0f, 1e-6f ); - ENSURE( b3Shape_IsValid( result.shapeId ) == false ); - - b3DestroyWorld( worldId ); - return 0; -} - -static int MoverTOIOverlapped( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - // Mover starts buried in the box, so there is no free interval to search. - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 0.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - // Overlap should be ignored. - ENSURE_SMALL( result.fraction - 1.0f, 1e-6f ); - ENSURE( B3_IS_NULL(result.shapeId) ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Two shapes on the sweep line must resolve to the nearer one whatever order the shape list -// hands them to the loop. Shapes are pushed on the head of the list, so the two bodies below -// walk their shapes in opposite orders. -static int MoverTOIClosestShape( void ) -{ - b3BodyId nearFirstId; - b3WorldId worldId = CreateQueryWorld( &nearFirstId ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId nearLastId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere nearSphere = { { 5.0f, 0.0f, 0.0f }, 0.5f }; - b3Sphere farSphere = { { 9.0f, 0.0f, 0.0f }, 0.5f }; - - b3ShapeId nearFirstHit = b3CreateSphereShape( nearFirstId, &shapeDef, &nearSphere ); - b3CreateSphereShape( nearFirstId, &shapeDef, &farSphere ); - - b3CreateSphereShape( nearLastId, &shapeDef, &farSphere ); - b3ShapeId nearLastHit = b3CreateSphereShape( nearLastId, &shapeDef, &nearSphere ); - - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 0.0f, 0.0f, 0.0f ); - b3Vec3 translation = { 10.0f, 0.0f, 0.0f }; - - b3BodyTOIResult nearFirst = b3Body_TimeOfImpactMover( nearFirstId, b3Pos_zero, &mover, translation, b3DefaultQueryFilter(), - bodyTransform, bodyTransform ); - b3BodyTOIResult nearLast = b3Body_TimeOfImpactMover( nearLastId, b3Pos_zero, &mover, translation, b3DefaultQueryFilter(), - bodyTransform, bodyTransform ); - - ENSURE_SMALL( nearFirst.fraction - 0.425f, 1e-2f ); - ENSURE( nearFirst.shapeId.index1 == nearFirstHit.index1 ); - - ENSURE_SMALL( nearLast.fraction - nearFirst.fraction, 1e-4f ); - ENSURE( nearLast.shapeId.index1 == nearLastHit.index1 ); - - b3DestroyWorld( worldId ); - return 0; -} - -// A shape the sweep clears must not erase a hit found earlier in the list. The off path sphere -// is created first so the list hands it over last. -static int MoverTOIKeepsHitAfterMiss( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere offPath = { { 5.0f, 0.0f, 20.0f }, 0.5f }; - b3Sphere onPath = { { 5.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( bodyId, &shapeDef, &offPath ); - b3ShapeId onPathId = b3CreateSphereShape( bodyId, &shapeDef, &onPath ); - - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 0.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 0.425f, 1e-2f ); - ENSURE( result.shapeId.index1 == onPathId.index1 ); - - b3DestroyWorld( worldId ); - return 0; -} - -// The mover capsule points live in the query frame, so sliding both the mover and the body by -// the same offset must not move the impact. -static int MoverTOIMoverOffset( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3Vec3 translation = { 10.0f, 0.0f, 0.0f }; - b3QueryFilter filter = b3DefaultQueryFilter(); - - b3Capsule atOrigin = MakeStandingMover(); - b3WorldTransform transformA = IdentityAt( 5.0f, 0.0f, 0.0f ); - b3BodyTOIResult resultA = - b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &atOrigin, translation, filter, transformA, transformA ); - - b3Capsule offset = { { 2.0f, 0.0f, 0.0f }, { 2.0f, 1.0f, 0.0f }, 0.25f }; - b3WorldTransform transformB = IdentityAt( 7.0f, 0.0f, 0.0f ); - b3BodyTOIResult resultB = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &offset, translation, filter, transformB, transformB ); - - ENSURE_SMALL( resultB.fraction - resultA.fraction, 1e-4f ); - ENSURE_SMALL( resultB.point.x - resultA.point.x - 2.0f, 1e-3f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// The body sweeps between the two supplied transforms. A bar spinning a quarter turn about Y -// reaches a mover that its start pose clears. -static int MoverTOIRotatingBody( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull bar = b3MakeBoxHull( 2.0f, 0.25f, 0.25f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &bar.base ); - - // Query origin puts the mover at world (0,0,2.1), just inside the swept end of the bar. - b3Pos origin = { 0.0f, 0.0f, 2.1f }; - b3Capsule mover = MakeStandingMover(); - b3WorldTransform transform1 = IdentityAt( 0.0f, 0.0f, 0.0f ); - b3WorldTransform transform2 = { - .p = (b3Pos){ 0.0f, 0.0f, 0.0f }, - .q = b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.5f * B3_PI ), - }; - - b3BodyTOIResult spinning = - b3Body_TimeOfImpactMover( bodyId, origin, &mover, b3Vec3_zero, b3DefaultQueryFilter(), transform1, transform2 ); - - ENSURE( 0.0f < spinning.fraction && spinning.fraction < 1.0f ); - - // Holding the start pose leaves the bar along X and well clear. - b3BodyTOIResult still = - b3Body_TimeOfImpactMover( bodyId, origin, &mover, b3Vec3_zero, b3DefaultQueryFilter(), transform1, transform1 ); - - ENSURE_SMALL( still.fraction - 1.0f, 1e-6f ); - ENSURE( B3_IS_NULL( still.shapeId ) ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Everything is re-centered on the origin, so a huge origin must not shift the fraction and the -// hit point comes back in the origin frame. -static int MoverTOIFarFromOrigin( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3Pos origin = { 1.0e6f, -2.0e6f, 5.0e5f }; - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = { .p = b3OffsetPos( origin, (b3Vec3){ 5.0f, 0.0f, 0.0f } ), .q = b3Quat_identity }; - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, origin, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 0.425f, 1e-2f ); - ENSURE_SMALL( result.normal.x + 1.0f, 1e-3f ); - ENSURE_SMALL( (result.point.x - origin.x) - 4.4f, 0.5f ); - - b3DestroyWorld( worldId ); - return 0; -} - -static int MoverTOIFilter( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - // Geometry is on the sweep line, but a zero mask rejects every category. - b3Capsule mover = MakeStandingMover(); - b3QueryFilter filter = b3DefaultQueryFilter(); - filter.maskBits = 0; - b3WorldTransform bodyTransform = IdentityAt( 5.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, filter, - bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 1.0f, 1e-6f ); - - b3DestroyWorld( worldId ); - return 0; -} - -// A shape the mover starts inside is skipped, but the sweep still runs against the other shapes -// on the body. -static int MoverTOIOverlapSkipsShape( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3BoxHull buried = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CreateHullShape( bodyId, &shapeDef, &buried.base ); - - // Face at x = 4.5 like MoverTOIHitsBox - b3BoxHull onPath = b3MakeOffsetBoxHull( 0.5f, 0.5f, 0.5f, (b3Vec3){ 5.0f, 0.0f, 0.0f } ); - b3ShapeId onPathId = b3CreateHullShape( bodyId, &shapeDef, &onPath.base ); - - b3Capsule mover = MakeStandingMover(); - b3WorldTransform bodyTransform = IdentityAt( 0.0f, 0.0f, 0.0f ); - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, b3Pos_zero, &mover, (b3Vec3){ 10.0f, 0.0f, 0.0f }, - b3DefaultQueryFilter(), bodyTransform, bodyTransform ); - - ENSURE_SMALL( result.fraction - 0.425f, 1e-2f ); - ENSURE( result.shapeId.index1 == onPathId.index1 ); - ENSURE_SMALL( result.normal.x + 1.0f, 1e-3f ); - - b3DestroyWorld( worldId ); - return 0; -} - -static float RandomFloat( uint32_t* seed, float lower, float upper ) -{ - uint32_t x = *seed; - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - *seed = x; - float unit = (float)( x >> 8 ) / 16777216.0f; - return lower + ( upper - lower ) * unit; -} - -static b3Vec3 RandomVector( uint32_t* seed, float lower, float upper ) -{ - b3Vec3 v; - v.x = RandomFloat( seed, lower, upper ); - v.y = RandomFloat( seed, lower, upper ); - v.z = RandomFloat( seed, lower, upper ); - return v; -} - -static b3Vec3 RandomDirection( uint32_t* seed ) -{ - for ( ;; ) - { - b3Vec3 v = RandomVector( seed, -1.0f, 1.0f ); - float length = b3Length( v ); - if ( 0.1f < length && length < 1.0f ) - { - return b3MulSV( 1.0f / length, v ); - } - } -} - -// The mover sweep follows the solver's continuous rule: any time of impact strictly inside the -// sweep counts, whatever the root finder reports. A capsule pivoting around a hull vertex can -// exhaust the iteration cap, and that must not read as a clean miss. Compare against the raw -// sweep built from the same inputs. -static int MoverTOIMatchesSweep( void ) -{ - b3BodyId bodyId; - b3WorldId worldId = CreateQueryWorld( &bodyId ); - - b3BoxHull bar = b3MakeBoxHull( 2.0f, 0.25f, 0.25f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3ShapeId shapeId = b3CreateHullShape( bodyId, &shapeDef, &bar.base ); - - uint32_t seed = 0x9E3779B9u; - int hitCount = 0; - for ( int i = 0; i < 2000; ++i ) - { - b3Capsule mover; - mover.center1 = RandomVector( &seed, -0.2f, 0.2f ); - mover.center2 = b3MulAdd( mover.center1, RandomFloat( &seed, 0.05f, 1.5f ), RandomDirection( &seed ) ); - mover.radius = RandomFloat( &seed, 0.05f, 0.5f ); - b3Vec3 capsulePoints[2] = { mover.center1, mover.center2 }; - - b3Vec3 o = RandomVector( &seed, -3.5f, 3.5f ); - b3Pos origin = { o.x, o.y, o.z }; - b3Vec3 translation = b3MulSV( RandomFloat( &seed, 0.0f, 3.0f ), RandomDirection( &seed ) ); - - b3WorldTransform transform1 = { - .p = b3Pos_zero, - .q = b3MakeQuatFromAxisAngle( RandomDirection( &seed ), RandomFloat( &seed, 0.0f, B3_PI ) ), - }; - b3Quat spin = b3MakeQuatFromAxisAngle( RandomDirection( &seed ), RandomFloat( &seed, 0.001f, B3_PI ) ); - b3Vec3 shift = RandomVector( &seed, -1.0f, 1.0f ); - b3WorldTransform transform2 = { - .p = (b3Pos){ shift.x, shift.y, shift.z }, - .q = b3MulQuat( spin, transform1.q ), - }; - - b3BodyTOIResult result = b3Body_TimeOfImpactMover( bodyId, origin, &mover, translation, b3DefaultQueryFilter(), - transform1, transform2 ); - - // Same sweep the body query builds. The static body keeps its center at the body origin. - b3Transform xf1 = b3ToRelativeTransform( transform1, origin ); - b3Transform xf2 = b3ToRelativeTransform( transform2, origin ); - - b3TOIInput input = { 0 }; - input.proxyA = (b3ShapeProxy){ b3GetHullPoints( &bar.base ), bar.base.vertexCount, 0.0f }; - input.proxyB = (b3ShapeProxy){ capsulePoints, 2, mover.radius }; - input.sweepA.c1 = xf1.p; - input.sweepA.c2 = xf2.p; - input.sweepA.q1 = transform1.q; - input.sweepA.q2 = transform2.q; - input.sweepA.localCenter = b3Vec3_zero; - input.sweepB.c1 = b3Vec3_zero; - input.sweepB.c2 = translation; - input.sweepB.q1 = b3Quat_identity; - input.sweepB.q2 = b3Quat_identity; - input.sweepB.localCenter = b3Vec3_zero; - input.maxFraction = 1.0f; - - b3TOIOutput raw = b3TimeOfImpact( &input ); - - if ( 0.0f < raw.fraction && raw.fraction < 1.0f ) - { - ENSURE_SMALL( result.fraction - raw.fraction, 1e-6f ); - ENSURE( result.shapeId.index1 == shapeId.index1 ); - ENSURE( b3IsNormalized( result.normal ) ); - ENSURE_SMALL( b3Distance( b3SubPos( result.point, origin ), raw.point ), 1e-4f ); - hitCount += 1; - } - else - { - ENSURE_SMALL( result.fraction - 1.0f, 1e-6f ); - ENSURE( B3_IS_NULL( result.shapeId ) ); - } - } - - ENSURE( hitCount > 0 ); - - b3DestroyWorld( worldId ); - return 0; -} - int BodyQueryTest( void ) { RUN_SUBTEST( CastRayHitsSphere ); @@ -1043,25 +474,11 @@ int BodyQueryTest( void ) RUN_SUBTEST( OverlapFalse ); RUN_SUBTEST( OverlapRespectsBodyTransform ); RUN_SUBTEST( OverlapFilter ); - RUN_SUBTEST( OverlapHullProxyEquivalence ); - RUN_SUBTEST( OverlapHullProxyRotation ); - RUN_SUBTEST( OverlapCompoundRotatedBody ); RUN_SUBTEST( MoverTouchesBox ); RUN_SUBTEST( MoverSeparated ); RUN_SUBTEST( MoverRotatedBody ); RUN_SUBTEST( MoverCapacity ); - RUN_SUBTEST( MoverTOIHitsBox ); - RUN_SUBTEST( MoverTOISeparated ); - RUN_SUBTEST( MoverTOIOverlapped ); - RUN_SUBTEST( MoverTOIClosestShape ); - RUN_SUBTEST( MoverTOIKeepsHitAfterMiss ); - RUN_SUBTEST( MoverTOIMoverOffset ); - RUN_SUBTEST( MoverTOIRotatingBody ); - RUN_SUBTEST( MoverTOIFarFromOrigin ); - RUN_SUBTEST( MoverTOIFilter ); - RUN_SUBTEST( MoverTOIOverlapSkipsShape ); - RUN_SUBTEST( MoverTOIMatchesSweep ); return 0; } diff --git a/test/test_broad_phase.c b/test/test_broad_phase.c deleted file mode 100644 index 85adbf6..0000000 --- a/test/test_broad_phase.c +++ /dev/null @@ -1,488 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "body.h" -#include "broad_phase.h" -#include "physics_world.h" -#include "shape.h" -#include "table.h" -#include "test_macros.h" - -#include "box3d/box3d.h" -#include "box3d/math_functions.h" - -#include - -// Brute force check of the broad-phase pair set against every live shape pair. Must run right -// after a zero time step so the pair update and the disjoint contact purge have both happened -// against the current fat boxes. -static int CheckPairSet( b3WorldId worldId ) -{ - b3World* world = b3GetWorldFromId( worldId ); - b3BroadPhase* bp = &world->broadPhase; - const b3Shape* shapes = world->shapes.data; - const b3AABB* fatAABBs = world->fatAABBs.data; - int shapeCount = world->shapes.count; - - for ( int i = 0; i < shapeCount; ++i ) - { - const b3Shape* shapeA = shapes + i; - if ( shapeA->id == B3_NULL_INDEX || shapeA->proxyKey == B3_NULL_INDEX || shapeA->sensorIndex != B3_NULL_INDEX ) - { - continue; - } - - b3Body* bodyA = b3Array_Get( world->bodies, shapeA->bodyId ); - - for ( int j = i + 1; j < shapeCount; ++j ) - { - const b3Shape* shapeB = shapes + j; - if ( shapeB->id == B3_NULL_INDEX || shapeB->proxyKey == B3_NULL_INDEX || shapeB->sensorIndex != B3_NULL_INDEX ) - { - continue; - } - - if ( shapeA->bodyId == shapeB->bodyId ) - { - continue; - } - - b3Body* bodyB = b3Array_Get( world->bodies, shapeB->bodyId ); - - bool expected = b3ShouldShapesCollide( shapeA->filter, shapeB->filter ) && - b3ShouldBodiesCollide( world, bodyA, bodyB ) && b3AABB_Overlaps( fatAABBs[i], fatAABBs[j] ); - - bool actual = b3ContainsKey( &bp->pairSet, b3ShapePairKey( i, j, 0 ) ); - - // A sleeping contact is never refreshed, so a stale pair can outlive the overlap when - // the other body is teleported, and a set woken by the narrow phase carries its stale - // contacts into the awake set one collide late. With sleeping on only a missing pair - // is a bug. - if ( world->enableSleep && actual && expected == false ) - { - continue; - } - - if ( expected != actual ) - { - printf( " pair mismatch: shapes %d (body %d type %d set %d) and %d (body %d type %d set %d), expected %d, " - "actual %d\n", - i, shapeA->bodyId, bodyA->type, bodyA->setIndex, j, shapeB->bodyId, bodyB->type, bodyB->setIndex, - expected, actual ); - fflush( stdout ); - return 1; - } - } - } - - return 0; -} - -typedef struct RandomState -{ - uint32_t seed; -} RandomState; - -static uint32_t NextRandom( RandomState* state ) -{ - // xorshift32 - uint32_t x = state->seed; - x ^= x << 13; - x ^= x >> 17; - x ^= x << 5; - state->seed = x; - return x; -} - -static float RandomFloat( RandomState* state, float lower, float upper ) -{ - float u = (float)( NextRandom( state ) & 0xFFFFFF ) / (float)0x1000000; - return lower + ( upper - lower ) * u; -} - -static int RandomInt( RandomState* state, int count ) -{ - return (int)( NextRandom( state ) % (uint32_t)count ); -} - -#define MAX_BODIES 64 -#define STATIC_COUNT 60 -#define TILE_COUNT 9 - -typedef struct BodySlot -{ - b3BodyId bodyId; - bool active; -} BodySlot; - -typedef struct StressContext -{ - b3WorldId worldId; - RandomState random; - b3Pos origin; - float extent; - BodySlot slots[MAX_BODIES]; - b3JointId joints[4]; - int jointCount; - b3BoxHull box; -} StressContext; - -static b3Pos RandomPosition( StressContext* context ) -{ - float e = context->extent; - b3Vec3 offset = { RandomFloat( &context->random, -e, e ), RandomFloat( &context->random, -e, e ), - RandomFloat( &context->random, -e, e ) }; - return b3OffsetPos( context->origin, offset ); -} - -static b3Vec3 RandomVelocity( StressContext* context ) -{ - // Some bodies outrun their margin every step and go through continuous collision - float s = RandomInt( &context->random, 4 ) == 0 ? 40.0f : 12.0f; - return (b3Vec3){ RandomFloat( &context->random, -s, s ), RandomFloat( &context->random, -s, s ), - RandomFloat( &context->random, -s, s ) }; -} - -static void CreateSlotBody( StressContext* context, int slot ) -{ - RandomState* random = &context->random; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = RandomInt( random, 10 ) == 0 ? b3_kinematicBody : b3_dynamicBody; - bodyDef.position = RandomPosition( context ); - bodyDef.linearVelocity = RandomVelocity( context ); - bodyDef.isBullet = RandomInt( random, 3 ) == 0; - bodyDef.gravityScale = 0.0f; - b3BodyId bodyId = b3CreateBody( context->worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.filter.categoryBits = 1ull << RandomInt( random, 3 ); - shapeDef.filter.maskBits = RandomInt( random, 4 ) == 0 ? 0x5ull : B3_DEFAULT_MASK_BITS; - - int shapeCount = 1 + RandomInt( random, 2 ); - for ( int i = 0; i < shapeCount; ++i ) - { - if ( RandomInt( random, 2 ) == 0 ) - { - b3Sphere sphere = { { RandomFloat( random, -1.0f, 1.0f ), 0.0f, 0.0f }, RandomFloat( random, 0.2f, 1.5f ) }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - else - { - b3CreateHullShape( bodyId, &shapeDef, &context->box.base ); - } - } - - context->slots[slot].bodyId = bodyId; - context->slots[slot].active = true; -} - -// A swarm of bodies churning through every proxy mutation the world API offers, with the pair -// set checked against a brute force scan after every step. -static int RunBroadPhaseStress( int workerCount, uint32_t seed, bool enableSleep ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - worldDef.enableSleep = enableSleep; - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - StressContext context = { 0 }; - context.worldId = worldId; - context.random.seed = seed; - context.origin = (b3Pos){ -1900.0, 0.0, 1330.0 }; - context.extent = 12.0f; - context.box = b3MakeBoxHull( 0.95f, 0.6f, 2.2f ); - - // Kilometre tiles far from the origin under the swarm, like a streamed terrain - b3HeightFieldData* tile = b3CreateGrid( 65, 65, (b3Vec3){ 16.0f, 1.0f, 16.0f }, false ); - for ( int i = 0; i < TILE_COUNT; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ -3072.0 + 1024.0 * ( i % 3 ), -30.0, 1024.0 * ( i / 3 ) }; - b3BodyId tileId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.enableSpeculativeContact = false; - b3CreateHeightFieldShape( tileId, &shapeDef, tile ); - } - - // Static clutter inside the swarm. Some pieces ask for contacts on creation. - b3BodyId staticIds[STATIC_COUNT]; - b3HeightFieldData* grid = b3CreateGrid( 5, 5, (b3Vec3){ 2.0f, 1.0f, 2.0f }, false ); - b3BoxHull staticBox = b3MakeBoxHull( 3.0f, 0.5f, 3.0f ); - for ( int i = 0; i < STATIC_COUNT; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = RandomPosition( &context ); - staticIds[i] = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.invokeContactCreation = ( i % 4 ) == 0; - shapeDef.enableSpeculativeContact = ( i % 2 ) == 0; - - if ( i % 3 == 0 ) - { - b3CreateHeightFieldShape( staticIds[i], &shapeDef, grid ); - } - else - { - b3CreateHullShape( staticIds[i], &shapeDef, &staticBox.base ); - } - } - - for ( int i = 0; i < MAX_BODIES; ++i ) - { - if ( RandomInt( &context.random, 4 ) != 0 ) - { - CreateSlotBody( &context, i ); - } - } - - float timeStep = 1.0f / 60.0f; - int stepCount = 400; - - for ( int step = 0; step < stepCount; ++step ) - { - RandomState* random = &context.random; - - int mutationCount = RandomInt( random, 4 ); - for ( int m = 0; m < mutationCount; ++m ) - { - int slot = RandomInt( random, MAX_BODIES ); - BodySlot* body = context.slots + slot; - int action = RandomInt( random, 12 ); - - if ( body->active == false ) - { - if ( action < 6 ) - { - CreateSlotBody( &context, slot ); - } - continue; - } - - switch ( action ) - { - case 0: - b3DestroyBody( body->bodyId ); - body->active = false; - break; - - case 1: - case 2: - b3Body_SetTransform( body->bodyId, RandomPosition( &context ), b3Quat_identity ); - break; - - case 3: - b3Body_SetLinearVelocity( body->bodyId, RandomVelocity( &context ) ); - break; - - case 4: - b3Body_Disable( body->bodyId ); - break; - - case 5: - b3Body_Enable( body->bodyId ); - break; - - case 6: - b3Body_SetBullet( body->bodyId, RandomInt( random, 2 ) == 0 ); - break; - - case 7: - { - b3BodyType types[3] = { b3_staticBody, b3_kinematicBody, b3_dynamicBody }; - b3Body_SetType( body->bodyId, types[RandomInt( random, 3 )] ); - if ( b3Body_GetType( body->bodyId ) != b3_staticBody ) - { - b3Body_SetLinearVelocity( body->bodyId, RandomVelocity( &context ) ); - } - } - break; - - case 8: - { - // Add a joint that blocks collision, or toggle one - if ( context.jointCount < 4 ) - { - int otherSlot = RandomInt( random, MAX_BODIES ); - BodySlot* other = context.slots + otherSlot; - if ( otherSlot != slot && other->active && b3Body_GetType( body->bodyId ) == b3_dynamicBody && - b3Body_GetType( other->bodyId ) == b3_dynamicBody ) - { - b3WeldJointDef jointDef = b3DefaultWeldJointDef(); - jointDef.base.bodyIdA = body->bodyId; - jointDef.base.bodyIdB = other->bodyId; - jointDef.base.collideConnected = false; - context.joints[context.jointCount++] = b3CreateWeldJoint( worldId, &jointDef ); - } - } - else - { - b3JointId jointId = context.joints[RandomInt( random, context.jointCount )]; - if ( b3Joint_IsValid( jointId ) ) - { - b3Joint_SetCollideConnected( jointId, RandomInt( random, 2 ) == 0 ); - } - } - } - break; - - case 9: - { - int staticIndex = RandomInt( random, STATIC_COUNT ); - b3Body_SetTransform( staticIds[staticIndex], RandomPosition( &context ), b3Quat_identity ); - } - break; - - case 10: - b3World_RebuildStaticTree( worldId ); - break; - - default: - break; - } - } - - // Joints whose bodies were destroyed are gone too - for ( int j = 0; j < context.jointCount; ) - { - if ( b3Joint_IsValid( context.joints[j] ) == false ) - { - context.joints[j] = context.joints[context.jointCount - 1]; - context.jointCount -= 1; - } - else - { - j += 1; - } - } - - // Keep the swarm inside the clutter - for ( int i = 0; i < MAX_BODIES; ++i ) - { - BodySlot* body = context.slots + i; - if ( body->active == false || b3Body_IsEnabled( body->bodyId ) == false ) - { - continue; - } - - b3Pos p = b3Body_GetPosition( body->bodyId ); - b3Vec3 d = b3SubPos( p, context.origin ); - if ( b3AbsFloat( d.x ) > 2.0f * context.extent || b3AbsFloat( d.y ) > 2.0f * context.extent || - b3AbsFloat( d.z ) > 2.0f * context.extent ) - { - b3Body_SetTransform( body->bodyId, RandomPosition( &context ), b3Quat_identity ); - b3Body_SetLinearVelocity( body->bodyId, RandomVelocity( &context ) ); - } - } - - b3World_Step( worldId, timeStep, 4 ); - - // A zero step finds pairs and purges disjoint contacts without moving anything - b3World_Step( worldId, 0.0f, 1 ); - - if ( CheckPairSet( worldId ) != 0 ) - { - printf( " workers=%d seed=%u sleep=%d step=%d\n", workerCount, seed, enableSleep, step ); - fflush( stdout ); - b3DestroyWorld( worldId ); - b3DestroyHeightField( grid ); - b3DestroyHeightField( tile ); - return 1; - } - } - - b3DestroyWorld( worldId ); - b3DestroyHeightField( grid ); - b3DestroyHeightField( tile ); - return 0; -} - -static int BroadPhaseStressTest( void ) -{ - uint32_t seeds[3] = { 12345u, 0xC0FFEEu, 777u }; - for ( int i = 0; i < 3; ++i ) - { - ENSURE( RunBroadPhaseStress( 1, seeds[i], false ) == 0 ); - ENSURE( RunBroadPhaseStress( 4, seeds[i], false ) == 0 ); - ENSURE( RunBroadPhaseStress( 3, seeds[i], true ) == 0 ); - } - - return 0; -} - -// The broad-phase keeps its pending pair marks inside the static tree, so a full rebuild between -// a static mutation and the next step used to wipe them and the contact never appeared. Covers -// both ways a static proxy gets marked: a teleport and a shape created with invokeContactCreation. -static int RunStaticRebuildKeepsMarks( bool useInvoke ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0, 1.0, 0.0 }; - b3BodyId sphereId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( sphereId, &shapeDef, &sphere ); - - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 100.0, 0.0, 0.0 }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull box = b3MakeBoxHull( 2.0f, 0.5f, 2.0f ); - if ( useInvoke == false ) - { - b3CreateHullShape( groundId, &shapeDef, &box.base ); - } - - // Settle so the resting sphere carries no mark of its own - for ( int i = 0; i < 3; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3Body_SetTransform( groundId, b3Pos_zero, b3Quat_identity ); - if ( useInvoke ) - { - b3ShapeDef invokeDef = b3DefaultShapeDef(); - invokeDef.invokeContactCreation = true; - b3CreateHullShape( groundId, &invokeDef, &box.base ); - } - - b3World_RebuildStaticTree( worldId ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - ENSURE( b3Body_GetContactCapacity( sphereId ) == 1 ); - - b3DestroyWorld( worldId ); - return 0; -} - -static int StaticRebuildKeepsMarks( void ) -{ - ENSURE( RunStaticRebuildKeepsMarks( false ) == 0 ); - ENSURE( RunStaticRebuildKeepsMarks( true ) == 0 ); - return 0; -} - -static int FlushingAssert( const char* condition, const char* fileName, int lineNumber ) -{ - printf( "BOX3D ASSERTION: %s, %s, line %d\n", condition, fileName, lineNumber ); - fflush( stdout ); - return 1; -} - -int BroadPhaseTest( void ) -{ - // A crash through a pipe loses buffered output, so flush the assertion first - b3SetAssertFcn( FlushingAssert ); - - RUN_SUBTEST( StaticRebuildKeepsMarks ); - RUN_SUBTEST( BroadPhaseStressTest ); - return 0; -} diff --git a/test/test_compound.c b/test/test_compound.c index 0a2ef9e..7fac23f 100644 --- a/test/test_compound.c +++ b/test/test_compound.c @@ -6,7 +6,6 @@ // b3CollideMoverAndCompound, b3GetCompoundChild, b3QueryCompound are internal #include "compound.h" -#include "box3d/box3d.h" #include "box3d/collision.h" #include "box3d/math_functions.h" @@ -77,9 +76,8 @@ static int CompoundCreateMixed( void ) ENSURE( compound->sharedHullCount == 1 ); ENSURE( compound->sharedMeshCount == 1 ); - ENSURE( compound->nodeCount >= 2 ); - ENSURE( compound->nodeOffset > 0 ); - ENSURE( compound->bounds.lowerBound.x < compound->bounds.upperBound.x ); + ENSURE( compound->tree.nodeCount > 0 ); + ENSURE( compound->tree.nodes != NULL ); b3DestroyCompound( compound ); b3DestroyMesh( meshData ); @@ -180,7 +178,7 @@ static int CompoundMaterialDistinct( void ) for ( int i = 0; i < 3; ++i ) { b3CompoundCapsule cc = b3GetCompoundCapsule( c, i ); - ENSURE( cc.materialIndex < 3 ); + ENSURE( cc.materialIndex >= 0 && cc.materialIndex < 3 ); ENSURE( mats[cc.materialIndex].userMaterialId == (uint64_t)( i + 1 ) ); } @@ -190,7 +188,7 @@ static int CompoundMaterialDistinct( void ) static int CompoundMaterialCrossShape( void ) { - // One material shared across capsule, hull, and sphere -> 1 material slot. + // One material shared across capsule, hull, and sphere → 1 material slot. b3SurfaceMaterial mat = MakeMaterial( 0.5f, 99 ); b3CompoundCapsuleDef cap = { .capsule = { { 0, 0, 0 }, { 1, 0, 0 }, 0.25f }, .material = mat }; @@ -424,14 +422,14 @@ static int CompoundChildDispatch( void ) }; b3CompoundData* c = b3CreateCompound( &def ); - // Index ordering is capsules -> hulls -> meshes -> spheres. + // Index ordering is capsules → hulls → meshes → spheres. ENSURE( b3GetCompoundChild( c, 0 ).type == b3_capsuleShape ); ENSURE( b3GetCompoundChild( c, 1 ).type == b3_capsuleShape ); ENSURE( b3GetCompoundChild( c, 2 ).type == b3_hullShape ); ENSURE( b3GetCompoundChild( c, 3 ).type == b3_meshShape ); ENSURE( b3GetCompoundChild( c, 4 ).type == b3_sphereShape ); - // Capsule and sphere children always report identity transform. The position + // Capsule and sphere children always report identity transform — the position // is encoded in the shape itself (capsule->center{1,2}, sphere->center). b3ChildShape cap0 = b3GetCompoundChild( c, 0 ); ENSURE_SMALL( cap0.transform.p.x, FLT_EPSILON ); @@ -516,7 +514,7 @@ static int CompoundRayCastClosest( void ) b3CastOutput out = b3RayCastCompound( c, &input ); ENSURE( out.hit == true ); - // Front face of the nearer sphere is at x=4 -> fraction 4/20 = 0.2. + // Front face of the nearer sphere is at x=4 → fraction 4/20 = 0.2. ENSURE_SMALL( out.fraction - 0.2f, 1e-4f ); ENSURE_SMALL( out.normal.x + 1.0f, 1e-4f ); ENSURE( out.childIndex == 0 ); @@ -530,7 +528,7 @@ static int CompoundRayCastClosest( void ) static int CompoundRayCastHullNormalRotation( void ) { - // A unit box rotated 90 degrees about Z, placed at compound +X. The ray hits the + // A unit box rotated 90° about Z, placed at compound +X. The ray hits the // face that, in compound space, points back toward -X. Verifies that the // normal returned by the cast has been rotated from hull-local space back // into compound space. @@ -577,7 +575,7 @@ static int CompoundShapeCastClosest( void ) }; b3CastOutput out = b3ShapeCastCompound( c, &input ); ENSURE( out.hit == true ); - // Closest contact: caster radius 0.25 + sphere radius 1.0 -> first contact at x ~= 3.75. + // Closest contact: caster radius 0.25 + sphere radius 1.0 → first contact at x ≈ 3.75. ENSURE_SMALL( out.fraction - 3.75f / 20.0f, 1e-3f ); ENSURE( out.childIndex == 0 ); @@ -585,328 +583,6 @@ static int CompoundShapeCastClosest( void ) return 0; } -static int CompoundShapeCastMiss( void ) -{ - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3CompoundSphereDef sph = { .sphere = { { 5, 0, 0 }, 1.0f }, .material = mat }; - b3CompoundDef def = { .spheres = &sph, .sphereCount = 1 }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Vec3 point = { 0, 5, 0 }; - b3ShapeCastInput input = { - .proxy = { .points = &point, .count = 1, .radius = 0.25f }, - .translation = { 20, 0, 0 }, - .maxFraction = 1.0f, - .canEncroach = false, - }; - ENSURE( b3ShapeCastCompound( c, &input ).hit == false ); - - // An empty proxy has nothing to sweep - input.proxy.count = 0; - ENSURE( b3ShapeCastCompound( c, &input ).hit == false ); - - b3DestroyCompound( c ); - return 0; -} - -static int CompoundShapeCastHullNormalRotation( void ) -{ - // Same setup as the ray cast rotation test. The result comes back in compound space, so the - // hull local face the sweep lands on says nothing about the reported normal and point. - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3BoxHull box = b3MakeBoxHull( 1, 1, 1 ); - - b3CompoundHullDef hull = { - .hull = &box.base, - .transform = { .p = { 5, 0, 0 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ) }, - .material = mat, - }; - b3CompoundDef def = { .hulls = &hull, .hullCount = 1 }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Vec3 point = { 0, 0, 0 }; - b3ShapeCastInput input = { - .proxy = { .points = &point, .count = 1, .radius = 0.25f }, - .translation = { 20, 0, 0 }, - .maxFraction = 1.0f, - .canEncroach = false, - }; - b3CastOutput out = b3ShapeCastCompound( c, &input ); - ENSURE( out.hit == true ); - - // Near face at x=4, caster radius 0.25 so contact at x=3.75 - ENSURE_SMALL( out.fraction - 3.75f / 20.0f, 1e-3f ); - ENSURE_SMALL( out.normal.x + 1.0f, 1e-3f ); - ENSURE_SMALL( out.normal.y, 1e-3f ); - ENSURE_SMALL( out.normal.z, 1e-3f ); - ENSURE_SMALL( out.point.x - 4.0f, 1e-3f ); - ENSURE_SMALL( out.point.y, 1e-3f ); - ENSURE_SMALL( out.point.z, 1e-3f ); - ENSURE( out.childIndex == 0 ); - - b3DestroyCompound( c ); - return 0; -} - -// Two separated upward facing triangles on the y = 0 plane, one per material. The bake may -// reorder triangles but always keeps a triangle paired with its material index. -static b3MeshData* MakeTwoMaterialMesh( void ) -{ - b3Vec3 vertices[6] = { - { -3.0f, 0.0f, -1.0f }, { -2.0f, 0.0f, 1.0f }, { -1.0f, 0.0f, -1.0f }, - { 1.0f, 0.0f, -1.0f }, { 2.0f, 0.0f, 1.0f }, { 3.0f, 0.0f, -1.0f }, - }; - int32_t indices[6] = { 0, 1, 2, 3, 4, 5 }; - uint8_t materialIndices[2] = { 0, 1 }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.stride = sizeof( b3Vec3 ); - def.indices = indices; - def.materialIndices = materialIndices; - def.vertexCount = 6; - def.triangleCount = 2; - - return b3CreateMesh( &def, NULL, 0 ); -} - -static int CompoundMeshMaterialRemap( void ) -{ - // A mesh child carries its own small material table. Casts report the triangle material - // after it has been remapped into the compound material array. - b3SurfaceMaterial matA = MakeMaterial( 0.3f, 100 ); - b3SurfaceMaterial matB = MakeMaterial( 0.7f, 200 ); - b3SurfaceMaterial materials[2] = { matA, matB }; - - b3MeshData* md = MakeTwoMaterialMesh(); - b3CompoundMeshDef mesh = { - .meshData = md, - .transform = b3Transform_identity, - .scale = { 1, 1, 1 }, - .materials = materials, - .materialCount = 2, - }; - b3CompoundDef def = { .meshes = &mesh, .meshCount = 1 }; - b3CompoundData* c = b3CreateCompound( &def ); - - const b3SurfaceMaterial* table = b3GetCompoundMaterials( c ); - - // Straight down onto the material 0 triangle - b3RayCastInput rayA = { .origin = { -2, 5, 0 }, .translation = { 0, -10, 0 }, .maxFraction = 1.0f }; - b3CastOutput outA = b3RayCastCompound( c, &rayA ); - ENSURE( outA.hit == true ); - ENSURE( table[outA.materialIndex].userMaterialId == 100 ); - - b3RayCastInput rayB = { .origin = { 2, 5, 0 }, .translation = { 0, -10, 0 }, .maxFraction = 1.0f }; - b3CastOutput outB = b3RayCastCompound( c, &rayB ); - ENSURE( outB.hit == true ); - ENSURE( table[outB.materialIndex].userMaterialId == 200 ); - - // The shape cast path does the same remap - b3Vec3 point = { 2, 5, 0 }; - b3ShapeCastInput castInput = { - .proxy = { .points = &point, .count = 1, .radius = 0.1f }, - .translation = { 0, -10, 0 }, - .maxFraction = 1.0f, - .canEncroach = false, - }; - b3CastOutput outCast = b3ShapeCastCompound( c, &castInput ); - ENSURE( outCast.hit == true ); - ENSURE( table[outCast.materialIndex].userMaterialId == 200 ); - - b3DestroyCompound( c ); - b3DestroyMesh( md ); - return 0; -} - -// Six separated upward facing triangles, one per material index 0 to 5 -static b3MeshData* MakeSixMaterialMesh( void ) -{ - b3Vec3 vertices[18]; - int32_t indices[18]; - uint8_t materialIndices[6]; - - for ( int i = 0; i < 6; ++i ) - { - float x = 3.0f * (float)i; - vertices[3 * i + 0] = (b3Vec3){ x - 1.0f, 0.0f, -1.0f }; - vertices[3 * i + 1] = (b3Vec3){ x, 0.0f, 1.0f }; - vertices[3 * i + 2] = (b3Vec3){ x + 1.0f, 0.0f, -1.0f }; - - indices[3 * i + 0] = 3 * i + 0; - indices[3 * i + 1] = 3 * i + 1; - indices[3 * i + 2] = 3 * i + 2; - - materialIndices[i] = (uint8_t)i; - } - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.stride = sizeof( b3Vec3 ); - def.indices = indices; - def.materialIndices = materialIndices; - def.vertexCount = 18; - def.triangleCount = 6; - - return b3CreateMesh( &def, NULL, 0 ); -} - -static int CompoundMeshManyMaterials( void ) -{ - // The capsule material bakes first so the mesh map is not the identity - b3SurfaceMaterial capsuleMat = MakeMaterial( 0.4f, 1000 ); - - b3MeshData* md = MakeSixMaterialMesh(); - ENSURE( md->materialCount == 6 ); - - b3SurfaceMaterial meshMats[6]; - for ( int i = 0; i < 6; ++i ) - { - meshMats[i] = MakeMaterial( 0.2f + 0.1f * (float)i, (uint64_t)( i + 1 ) ); - } - - b3CompoundCapsuleDef cap = { .capsule = { { -10.0f, 0.0f, 0.0f }, { -9.0f, 0.0f, 0.0f }, 0.25f }, .material = capsuleMat }; - b3CompoundMeshDef mesh = { - .meshData = md, - .transform = b3Transform_identity, - .scale = { 1.0f, 1.0f, 1.0f }, - .materials = meshMats, - .materialCount = 6, - }; - - b3CompoundDef def = { - .capsules = &cap, - .capsuleCount = 1, - .meshes = &mesh, - .meshCount = 1, - }; - b3CompoundData* c = b3CreateCompound( &def ); - ENSURE( c != NULL ); - ENSURE( c->materialCount == 7 ); - - const b3SurfaceMaterial* table = b3GetCompoundMaterials( c ); - - b3ChildShape capChild = b3GetCompoundChild( c, 0 ); - ENSURE( capChild.type == b3_capsuleShape ); - ENSURE( capChild.materialCount == 1 ); - ENSURE( table[capChild.materialIndices[0]].userMaterialId == 1000 ); - - b3ChildShape meshChild = b3GetCompoundChild( c, 1 ); - ENSURE( meshChild.type == b3_meshShape ); - ENSURE( meshChild.materialCount == 6 ); - for ( int k = 0; k < 6; ++k ) - { - ENSURE( table[meshChild.materialIndices[k]].userMaterialId == (uint64_t)( k + 1 ) ); - } - - // Sixth triangle, material index 5 - const uint8_t* triangleMaterials = b3GetMeshMaterialIndices( md ); - b3RayCastInput ray = { .origin = { 15.0f, 5.0f, 0.0f }, .translation = { 0.0f, -10.0f, 0.0f }, .maxFraction = 1.0f }; - b3CastOutput out = b3RayCastCompound( c, &ray ); - ENSURE( out.hit == true ); - ENSURE( out.childIndex == 1 ); - int rawIndex = triangleMaterials[out.triangleIndex]; - ENSURE( rawIndex >= 4 ); - ENSURE( table[out.materialIndex].userMaterialId == (uint64_t)( rawIndex + 1 ) ); - - b3DestroyCompound( c ); - b3DestroyMesh( md ); - return 0; -} - -// Flat quad with every triangle on material index 5, so the mesh has six materials -static b3MeshData* MakeFlatMaterial5Mesh( void ) -{ - b3Vec3 vertices[4] = { - { -5.0f, 0.0f, -5.0f }, - { -5.0f, 0.0f, 5.0f }, - { 5.0f, 0.0f, -5.0f }, - { 5.0f, 0.0f, 5.0f }, - }; - int32_t indices[6] = { 0, 1, 3, 3, 2, 0 }; - uint8_t materialIndices[2] = { 5, 5 }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.stride = sizeof( b3Vec3 ); - def.indices = indices; - def.materialIndices = materialIndices; - def.vertexCount = 4; - def.triangleCount = 2; - - return b3CreateMesh( &def, NULL, 0 ); -} - -static uint64_t s_compoundContactMaterialId; - -static float CompoundContactFrictionCallback( float frictionA, uint64_t userMaterialIdA, float frictionB, - uint64_t userMaterialIdB ) -{ - if ( userMaterialIdA == 6 || userMaterialIdB == 6 ) - { - s_compoundContactMaterialId = 6; - } - return 0.5f * ( frictionA + frictionB ); -} - -static int CompoundMeshContactMaterial( void ) -{ - s_compoundContactMaterialId = 0; - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3World_SetFrictionCallback( worldId, CompoundContactFrictionCallback ); - - b3BodyDef groundBodyDef = b3DefaultBodyDef(); - groundBodyDef.type = b3_staticBody; - b3BodyId groundBodyId = b3CreateBody( worldId, &groundBodyDef ); - - b3MeshData* md = MakeFlatMaterial5Mesh(); - ENSURE( md->materialCount == 6 ); - - b3SurfaceMaterial meshMats[6]; - for ( int i = 0; i < 6; ++i ) - { - meshMats[i] = MakeMaterial( 0.5f, (uint64_t)( i + 1 ) ); - } - - b3CompoundMeshDef meshChild = { - .meshData = md, - .transform = b3Transform_identity, - .scale = { 1.0f, 1.0f, 1.0f }, - .materials = meshMats, - .materialCount = 6, - }; - b3CompoundDef compoundDef = { .meshes = &meshChild, .meshCount = 1 }; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - - b3ShapeDef groundShapeDef = b3DefaultShapeDef(); - b3ShapeId compoundShapeId = b3CreateBakedCompoundShape( groundBodyId, &groundShapeDef, compound ); - ENSURE( b3Shape_GetCompound( compoundShapeId ) == compound ); - - b3BodyDef sphereBodyDef = b3DefaultBodyDef(); - sphereBodyDef.type = b3_dynamicBody; - sphereBodyDef.position = (b3Pos){ 0.0f, 3.0f, 0.0f }; - b3BodyId sphereBodyId = b3CreateBody( worldId, &sphereBodyDef ); - b3ShapeDef sphereShapeDef = b3DefaultShapeDef(); - sphereShapeDef.density = 1.0f; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( sphereBodyId, &sphereShapeDef, &sphere ); - - for ( int i = 0; i < 120; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - ENSURE( s_compoundContactMaterialId == 6 ); - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - b3DestroyMesh( md ); - return 0; -} - static int CompoundOverlap( void ) { b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); @@ -931,132 +607,6 @@ static int CompoundOverlap( void ) return 0; } -static int CompoundOverlapTransformed( void ) -{ - // The tree and the child geometry live in the compound frame while the proxy arrives in world - // space, so a compound that is moved and turned has to pull the proxy back before querying. - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3CompoundSphereDef spheres[2] = { - { .sphere = { { -3, 0, 0 }, 0.5f }, .material = mat }, - { .sphere = { { 3, 0, 0 }, 0.5f }, .material = mat }, - }; - b3CompoundDef def = { .spheres = spheres, .sphereCount = 2 }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Transform transform = { .p = { 10, 20, 30 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ) }; - - b3Vec3 gapPoint = b3TransformPoint( transform, (b3Vec3){ 0, 0, 0 } ); - b3ShapeProxy gap = { .points = &gapPoint, .count = 1, .radius = 0.25f }; - ENSURE( b3OverlapCompound( c, transform, &gap ) == false ); - - b3Vec3 hitPoint = b3TransformPoint( transform, (b3Vec3){ 3, 0, 0 } ); - b3ShapeProxy hit = { .points = &hitPoint, .count = 1, .radius = 0.1f }; - ENSURE( b3OverlapCompound( c, transform, &hit ) == true ); - - // A proxy left in the compound frame must not register against the moved compound - b3Vec3 localPoint = { 3, 0, 0 }; - b3ShapeProxy stale = { .points = &localPoint, .count = 1, .radius = 0.1f }; - ENSURE( b3OverlapCompound( c, transform, &stale ) == false ); - - b3DestroyCompound( c ); - return 0; -} - -static int CompoundOverlapChildTypes( void ) -{ - // One child of every type, spaced far enough apart that a hit names the type it came from. - // Hull and mesh children add a child transform underneath the compound transform. - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3MeshData* md = b3CreateBoxMesh( b3Vec3_zero, (b3Vec3){ 0.5f, 0.5f, 0.5f }, false ); - - b3CompoundCapsuleDef capsule = { .capsule = { { -10, 0, 0 }, { -9, 0, 0 }, 0.25f }, .material = mat }; - b3CompoundHullDef hull = { - .hull = &box.base, - .transform = { .p = { 0, 0, 0 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.25f * B3_PI ) }, - .material = mat, - }; - b3CompoundMeshDef mesh = { - .meshData = md, - .transform = { .p = { 10, 0, 0 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.5f * B3_PI ) }, - .scale = { 1, 1, 1 }, - .materials = &mat, - .materialCount = 1, - }; - b3CompoundSphereDef sphere = { .sphere = { { 20, 0, 0 }, 0.5f }, .material = mat }; - - b3CompoundDef def = { - .capsules = &capsule, - .capsuleCount = 1, - .hulls = &hull, - .hullCount = 1, - .meshes = &mesh, - .meshCount = 1, - .spheres = &sphere, - .sphereCount = 1, - }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Transform transform = { .p = { 100, 200, 300 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ) }; - - // Points sitting on or inside each child, then carried out to world space - b3Vec3 localPoints[4] = { - { -9.5f, 0, 0 }, // capsule axis - { 0, 0, 0 }, // hull center - { 10, 0.45f, 0 }, // just under a mesh face - { 20, 0, 0 }, // sphere center - }; - - for ( int i = 0; i < 4; ++i ) - { - b3Vec3 worldPoint = b3TransformPoint( transform, localPoints[i] ); - b3ShapeProxy proxy = { .points = &worldPoint, .count = 1, .radius = 0.1f }; - ENSURE( b3OverlapCompound( c, transform, &proxy ) == true ); - } - - // A gap between the hull and the mesh - b3Vec3 gapPoint = b3TransformPoint( transform, (b3Vec3){ 5, 0, 0 } ); - b3ShapeProxy gap = { .points = &gapPoint, .count = 1, .radius = 0.1f }; - ENSURE( b3OverlapCompound( c, transform, &gap ) == false ); - - b3DestroyCompound( c ); - b3DestroyMesh( md ); - return 0; -} - -static int CompoundOverlapSegmentProxy( void ) -{ - // A multi point proxy has to be carried into the compound frame point by point - b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); - b3CompoundSphereDef spheres[2] = { - { .sphere = { { -3, 0, 0 }, 0.5f }, .material = mat }, - { .sphere = { { 3, 0, 0 }, 0.5f }, .material = mat }, - }; - b3CompoundDef def = { .spheres = spheres, .sphereCount = 2 }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Transform transform = { .p = { -40, 15, 7 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisY, 0.5f * B3_PI ) }; - - // Segment that stays inside the gap - b3Vec3 inGap[2] = { - b3TransformPoint( transform, (b3Vec3){ -1, 0, 0 } ), - b3TransformPoint( transform, (b3Vec3){ 1, 0, 0 } ), - }; - b3ShapeProxy gap = { .points = inGap, .count = 2, .radius = 0.25f }; - ENSURE( b3OverlapCompound( c, transform, &gap ) == false ); - - // Same segment stretched until one end reaches the second sphere - b3Vec3 reaching[2] = { - b3TransformPoint( transform, (b3Vec3){ -1, 0, 0 } ), - b3TransformPoint( transform, (b3Vec3){ 2.9f, 0, 0 } ), - }; - b3ShapeProxy hit = { .points = reaching, .count = 2, .radius = 0.25f }; - ENSURE( b3OverlapCompound( c, transform, &hit ) == true ); - - b3DestroyCompound( c ); - return 0; -} - struct QueryAccumulator { int childIndices[8]; @@ -1090,7 +640,7 @@ static int CompoundQuery( void ) b3CompoundDef def = { .spheres = spheres, .sphereCount = 3 }; b3CompoundData* c = b3CreateCompound( &def ); - // Tight box around the middle sphere. Only it should be reported. + // Tight box around the middle sphere — only it should be reported. b3AABB middle = { { -1, -1, -1 }, { 1, 1, 1 } }; struct QueryAccumulator acc = { .stopAfter = -1 }; b3QueryCompound( c, middle, QueryCallback, &acc ); @@ -1154,41 +704,6 @@ static int CompoundMover( void ) return 0; } -static int CompoundMoverRotatedChild( void ) -{ - // The child solves the mover in its own frame, so the plane it returns has to be carried - // back into the compound frame before the caller sees it. - b3SurfaceMaterial mat = MakeMaterial( 0.25f, 77 ); - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - // Quarter turn about z, so the compound space top face is a side face of the hull - b3CompoundHullDef hull = { - .hull = &box.base, - .transform = { .p = { 0, 0, 0 }, .q = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, 0.5f * B3_PI ) }, - .material = mat, - }; - b3CompoundDef def = { .hulls = &hull, .hullCount = 1 }; - b3CompoundData* c = b3CreateCompound( &def ); - - b3Capsule mover = { { -0.1f, 0.6f, 0 }, { 0.1f, 0.6f, 0 }, 0.2f }; - - b3PlaneResult planes[8] = { 0 }; - int planeCount = b3CollideMoverAndCompound( planes, 8, c, &mover ); - ENSURE( planeCount >= 1 ); - - ENSURE_SMALL( planes[0].plane.normal.x, 1e-3f ); - ENSURE_SMALL( planes[0].plane.normal.y - 1.0f, 1e-3f ); - ENSURE_SMALL( planes[0].plane.normal.z, 1e-3f ); - ENSURE_SMALL( planes[0].point.y - 0.5f, 1e-3f ); - - ENSURE( planes[0].childIndex == 0 ); - const b3SurfaceMaterial* table = b3GetCompoundMaterials( c ); - ENSURE( table[planes[0].materialIndex].userMaterialId == 77 ); - - b3DestroyCompound( c ); - return 0; -} - static b3CompoundData* BuildSerializableCompound( b3MeshData* md ) { b3SurfaceMaterial mat = b3DefaultSurfaceMaterial(); @@ -1233,24 +748,18 @@ static int CompoundSerializeRoundtrip( void ) uint8_t* buffer = (uint8_t*)malloc( (size_t)byteCount ); ENSURE( buffer != NULL ); - uint8_t* reference = (uint8_t*)malloc( (size_t)byteCount ); - ENSURE( reference != NULL ); - - memcpy( buffer, a, (size_t)byteCount ); - memcpy( reference, a, (size_t)byteCount ); + uint8_t* serialized = b3ConvertCompoundToBytes( a ); + memcpy( buffer, serialized, (size_t)byteCount ); b3DestroyCompound( a ); - const b3CompoundData* b = b3ValidateCompound( buffer, byteCount ); + b3CompoundData* b = b3ConvertBytesToCompound( buffer, byteCount ); ENSURE( b != NULL ); - ENSURE( (const uint8_t*)b == buffer ); ENSURE( b->byteCount == byteCount ); ENSURE( b->capsuleCount == 1 ); ENSURE( b->hullCount == 1 ); ENSURE( b->meshCount == 1 ); ENSURE( b->sphereCount == 1 ); - - // Validation must not touch the bytes - ENSURE( memcmp( buffer, reference, (size_t)byteCount ) == 0 ); + ENSURE( b->tree.nodes != NULL ); // Bounds and ray cast on the deserialized compound match the original. b3AABB aabbB = b3ComputeCompoundAABB( b, b3Transform_identity ); @@ -1262,7 +771,6 @@ static int CompoundSerializeRoundtrip( void ) ENSURE_SMALL( rayB.fraction - rayA.fraction, 1e-5f ); ENSURE( rayB.childIndex == rayA.childIndex ); - free( reference ); free( buffer ); b3DestroyMesh( md ); return 0; @@ -1275,13 +783,13 @@ static int CompoundSerializeBadVersion( void ) int byteCount = a->byteCount; uint8_t* buffer = (uint8_t*)malloc( (size_t)byteCount ); - memcpy( buffer, a, (size_t)byteCount ); + memcpy( buffer, b3ConvertCompoundToBytes( a ), (size_t)byteCount ); b3DestroyCompound( a ); // Corrupt the version word (first 8 bytes of b3Compound). ( (b3CompoundData*)buffer )->version ^= 0x1ull; - const b3CompoundData* b = b3ValidateCompound( buffer, byteCount ); + b3CompoundData* b = b3ConvertBytesToCompound( buffer, byteCount ); ENSURE( b == NULL ); free( buffer ); @@ -1296,11 +804,11 @@ static int CompoundSerializeWrongByteCount( void ) int byteCount = a->byteCount; uint8_t* buffer = (uint8_t*)malloc( (size_t)byteCount ); - memcpy( buffer, a, (size_t)byteCount ); + memcpy( buffer, b3ConvertCompoundToBytes( a ), (size_t)byteCount ); b3DestroyCompound( a ); // Off-by-one in the declared length is rejected. - const b3CompoundData* b = b3ValidateCompound( buffer, byteCount + 1 ); + b3CompoundData* b = b3ConvertBytesToCompound( buffer, byteCount + 1 ); ENSURE( b == NULL ); free( buffer ); @@ -1308,35 +816,6 @@ static int CompoundSerializeWrongByteCount( void ) return 0; } -static int CompoundSerializeBadNodeCount( void ) -{ - b3MeshData* md = b3CreateBoxMesh( b3Vec3_zero, (b3Vec3){ 0.5f, 0.5f, 0.5f }, false ); - b3CompoundData* a = BuildSerializableCompound( md ); - - int byteCount = a->byteCount; - uint8_t* buffer = (uint8_t*)malloc( (size_t)byteCount ); - memcpy( buffer, a, (size_t)byteCount ); - b3DestroyCompound( a ); - - b3CompoundData* header = (b3CompoundData*)buffer; - int nodeCount = header->nodeCount; - - // Node array runs off the end of the buffer - header->nodeCount = byteCount; - ENSURE( b3ValidateCompound( buffer, byteCount ) == NULL ); - - // Overflow in 32 bit arithmetic must still be caught - header->nodeCount = INT32_MAX; - ENSURE( b3ValidateCompound( buffer, byteCount ) == NULL ); - - header->nodeCount = nodeCount; - ENSURE( b3ValidateCompound( buffer, byteCount ) != NULL ); - - free( buffer ); - b3DestroyMesh( md ); - return 0; -} - int CompoundTest( void ) { RUN_SUBTEST( CompoundCreateMixed ); @@ -1362,25 +841,15 @@ int CompoundTest( void ) RUN_SUBTEST( CompoundRayCastClosest ); RUN_SUBTEST( CompoundRayCastHullNormalRotation ); RUN_SUBTEST( CompoundShapeCastClosest ); - RUN_SUBTEST( CompoundShapeCastMiss ); - RUN_SUBTEST( CompoundShapeCastHullNormalRotation ); - RUN_SUBTEST( CompoundMeshMaterialRemap ); - RUN_SUBTEST( CompoundMeshManyMaterials ); - RUN_SUBTEST( CompoundMeshContactMaterial ); RUN_SUBTEST( CompoundOverlap ); - RUN_SUBTEST( CompoundOverlapTransformed ); - RUN_SUBTEST( CompoundOverlapChildTypes ); - RUN_SUBTEST( CompoundOverlapSegmentProxy ); RUN_SUBTEST( CompoundQuery ); RUN_SUBTEST( CompoundMover ); - RUN_SUBTEST( CompoundMoverRotatedChild ); RUN_SUBTEST( CompoundSerializeRoundtrip ); RUN_SUBTEST( CompoundSerializeBadVersion ); RUN_SUBTEST( CompoundSerializeWrongByteCount ); - RUN_SUBTEST( CompoundSerializeBadNodeCount ); return 0; } diff --git a/test/test_container.c b/test/test_container.c index 0f93e7e..e3df4d3 100644 --- a/test/test_container.c +++ b/test/test_container.c @@ -8,7 +8,7 @@ #include #include -// uint64_t is already declared in container.h for the broad-phase pair keys +b3DeclareArrayNative( uint64_t ); b3DeclareArrayNative( int16_t ); b3DeclareArrayNative( uint8_t ); diff --git a/test/test_determinism.c b/test/test_determinism.c index ae60cb4..888a0d6 100644 --- a/test/test_determinism.c +++ b/test/test_determinism.c @@ -3,8 +3,6 @@ #include "box3d/box3d.h" #include "determinism.h" -#include "simd.h" -#include "stability.h" #include "test_macros.h" #include @@ -19,67 +17,14 @@ // Double precision accumulates body positions in double, so the settle/sleep step and the // state hash differ from the float build. Both modes are internally deterministic. #if defined( BOX3D_DOUBLE_PRECISION ) -#define RAGDOLL_SLEEP_STEP 282 -#define RAGDOLL_HASH 0x6E4B13AD -#define WAVE_PILE_SLEEP_STEP 316 -#define WAVE_PILE_HASH 0x7CB7D931 -#define QUERY_SPAWN_SLEEP_STEP 242 -#define QUERY_SPAWN_HASH 0x489585E6 -#define QUERY_SPAWN_HIT_COUNT 59 -#define QUERY_SPAWN_QUERY_HASH 0x5B4429DC -#define MESH_DROP_SLEEP_STEP 197 -#define MESH_DROP_HASH 0xA2E8BB21 +#define EXPECTED_SLEEP_STEP 301 +#define EXPECTED_HASH 0xE4844A97 #else -#define RAGDOLL_SLEEP_STEP 277 -#define RAGDOLL_HASH 0x5E042B6E -#define WAVE_PILE_SLEEP_STEP 300 -#define WAVE_PILE_HASH 0x3155DA54 -#define QUERY_SPAWN_SLEEP_STEP 242 -#define QUERY_SPAWN_HASH 0xF3AD9BA6 -#define QUERY_SPAWN_HIT_COUNT 59 -#define QUERY_SPAWN_QUERY_HASH 0xE3271F3D -#define MESH_DROP_SLEEP_STEP 197 -#define MESH_DROP_HASH 0x96B62947 +#define EXPECTED_SLEEP_STEP 269 +#define EXPECTED_HASH 0x50313037 #endif -// The goldens above pin exact values for the default four point manifold. A build that -// overrides B3_MAX_MANIFOLD_POINTS produces a different contact set, so those checks drop -// out and only the run to run agreement below applies. -#if B3_MAX_MANIFOLD_POINTS == 4 -#define ENSURE_GOLDEN( condition ) ENSURE( condition ) -#else -#define ENSURE_GOLDEN( condition ) ( (void)0 ) -#endif - -typedef struct DeterminismResult -{ - int sleepStep; - uint32_t hash; - int queryHitCount; - uint32_t queryHash; - bool seeded; -} DeterminismResult; - -// Every worker count has to reproduce the first run exactly. Scenarios without queries leave -// the query fields zero in both the reference and the result. -static int EnsureRepeatable( DeterminismResult* reference, DeterminismResult result ) -{ - if ( reference->seeded == false ) - { - result.seeded = true; - *reference = result; - return 0; - } - - ENSURE( result.sleepStep == reference->sleepStep ); - ENSURE( result.hash == reference->hash ); - ENSURE( result.queryHitCount == reference->queryHitCount ); - ENSURE( result.queryHash == reference->queryHash ); - - return 0; -} - -static int SingleMultithreadingTest( int workerCount, DeterminismResult* reference ) +static int SingleMultithreadingTest( int workerCount ) { b3WorldDef worldDef = b3DefaultWorldDef(); worldDef.workerCount = workerCount; @@ -106,14 +51,13 @@ static int SingleMultithreadingTest( int workerCount, DeterminismResult* referen b3DestroyWorld( worldId ); - if ( data.sleepStep != RAGDOLL_SLEEP_STEP || data.hash != RAGDOLL_HASH ) + if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH ) { printf( " workers=%d sleepStep=%d hash=0x%08X\n", workerCount, data.sleepStep, data.hash ); } - ENSURE_GOLDEN( data.sleepStep == RAGDOLL_SLEEP_STEP ); - ENSURE_GOLDEN( data.hash == RAGDOLL_HASH ); - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = data.sleepStep, .hash = data.hash } ) == 0 ); + ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP ); + ENSURE( data.hash == EXPECTED_HASH ); DestroyFallingRagdolls( &data ); @@ -123,10 +67,9 @@ static int SingleMultithreadingTest( int workerCount, DeterminismResult* referen // Test multithreaded determinism. static int MultithreadingTest( void ) { - DeterminismResult reference = { 0 }; for ( int workerCount = 1; workerCount < 6; ++workerCount ) { - int result = SingleMultithreadingTest( workerCount, &reference ); + int result = SingleMultithreadingTest( workerCount ); ENSURE( result == 0 ); } @@ -153,13 +96,13 @@ static int CrossPlatformTest( void ) done = UpdateFallingRagdolls( worldId, &data ); } - if ( data.sleepStep != RAGDOLL_SLEEP_STEP || data.hash != RAGDOLL_HASH ) + if ( data.sleepStep != EXPECTED_SLEEP_STEP || data.hash != EXPECTED_HASH ) { printf( " cross-platform sleepStep=%d hash=0x%08X\n", data.sleepStep, data.hash ); } - ENSURE_GOLDEN( data.sleepStep == RAGDOLL_SLEEP_STEP ); - ENSURE_GOLDEN( data.hash == RAGDOLL_HASH ); + ENSURE( data.sleepStep == EXPECTED_SLEEP_STEP ); + ENSURE( data.hash == EXPECTED_HASH ); DestroyFallingRagdolls( &data ); @@ -168,439 +111,10 @@ static int CrossPlatformTest( void ) return 0; } -static int SingleWavePileTest( int workerCount, DeterminismResult* reference ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - - b3WorldId worldId = b3CreateWorld( &worldDef ); - - WavePileData data = CreateWavePile( worldId ); - - float timeStep = 1.0f / 60.0f; - - // Rolling resistance must put the pile to sleep within 500 steps - bool done = false; - for ( int i = 0; i < 500 && done == false; ++i ) - { - int subStepCount = 4; - b3World_Step( worldId, timeStep, subStepCount ); - TracyCFrameMark; - - done = UpdateWavePile( worldId, &data ); - } - - b3DestroyWorld( worldId ); - - if ( data.sleepStep != WAVE_PILE_SLEEP_STEP || data.hash != WAVE_PILE_HASH ) - { - printf( " wave pile workers=%d sleepStep=%d hash=0x%08X\n", workerCount, data.sleepStep, data.hash ); - } - - ENSURE( done == true ); - ENSURE_GOLDEN( data.sleepStep == WAVE_PILE_SLEEP_STEP ); - ENSURE_GOLDEN( data.hash == WAVE_PILE_HASH ); - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = data.sleepStep, .hash = data.hash } ) == 0 ); - - DestroyWavePile( &data ); - - return 0; -} - -// Test multithreaded determinism of a mixed convex pile on a wave height field. -static int WavePileTest( void ) -{ - DeterminismResult reference = { 0 }; - for ( int workerCount = 1; workerCount <= 4; ++workerCount ) - { - int result = SingleWavePileTest( workerCount, &reference ); - ENSURE( result == 0 ); - } - - return 0; -} - -static int SingleQuerySpawnTest( int workerCount, DeterminismResult* reference ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - - b3WorldId worldId = b3CreateWorld( &worldDef ); - - QuerySpawnData data = CreateQuerySpawn( worldId ); - - float timeStep = 1.0f / 60.0f; - - bool done = false; - for ( int i = 0; i < 1000 && done == false; ++i ) - { - int subStepCount = 4; - b3World_Step( worldId, timeStep, subStepCount ); - TracyCFrameMark; - - done = UpdateQuerySpawn( worldId, &data ); - } - - b3DestroyWorld( worldId ); - - if ( data.sleepStep != QUERY_SPAWN_SLEEP_STEP || data.hash != QUERY_SPAWN_HASH || data.queryHitCount != QUERY_SPAWN_HIT_COUNT || - data.queryHash != QUERY_SPAWN_QUERY_HASH ) - { - printf( " query spawn workers=%d sleepStep=%d hash=0x%08X hits=%d queryHash=0x%08X\n", workerCount, data.sleepStep, - data.hash, data.queryHitCount, data.queryHash ); - } - - ENSURE( done == true ); - ENSURE( data.spawnCount == QUERY_SPAWN_COUNT ); - ENSURE_GOLDEN( data.sleepStep == QUERY_SPAWN_SLEEP_STEP ); - ENSURE_GOLDEN( data.hash == QUERY_SPAWN_HASH ); - ENSURE_GOLDEN( data.queryHitCount == QUERY_SPAWN_HIT_COUNT ); - ENSURE_GOLDEN( data.queryHash == QUERY_SPAWN_QUERY_HASH ); - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = data.sleepStep, - .hash = data.hash, - .queryHitCount = data.queryHitCount, - .queryHash = data.queryHash } ) == 0 ); - - DestroyQuerySpawn( &data ); - - return 0; -} - -// Test determinism of world queries by feeding their results back into the simulation. -static int QuerySpawnTest( void ) -{ - DeterminismResult reference = { 0 }; - for ( int workerCount = 1; workerCount <= 4; ++workerCount ) - { - int result = SingleQuerySpawnTest( workerCount, &reference ); - ENSURE( result == 0 ); - } - - return 0; -} - -static int SingleMeshDropTest( int workerCount, DeterminismResult* reference ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - - b3WorldId worldId = b3CreateWorld( &worldDef ); - - MeshDropData data = CreateMeshDrop( worldId, b3Pos_zero ); - - float timeStep = 1.0f / 60.0f; - - bool done = false; - for ( int i = 0; i < 400 && done == false; ++i ) - { - int subStepCount = 4; - b3World_Step( worldId, timeStep, subStepCount ); - TracyCFrameMark; - - done = UpdateMeshDrop( worldId, &data ); - } - - b3DestroyWorld( worldId ); - - if ( data.sleepStep != MESH_DROP_SLEEP_STEP || data.hash != MESH_DROP_HASH ) - { - printf( " mesh drop workers=%d sleepStep=%d hash=0x%08X\n", workerCount, data.sleepStep, data.hash ); - } - - ENSURE( done == true ); - ENSURE_GOLDEN( data.sleepStep == MESH_DROP_SLEEP_STEP ); - ENSURE_GOLDEN( data.hash == MESH_DROP_HASH ); - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = data.sleepStep, .hash = data.hash } ) == 0 ); - - DestroyMeshDrop( &data ); - - return 0; -} - -// Test continuous collision determinism. Thin fast boxes need CCD against the wave mesh. -// The scene is large, so only the single threaded and widest schedules run. -static int MeshDropTest( void ) -{ - DeterminismResult reference = { 0 }; - int workerCounts[2] = { 1, 4 }; - for ( int i = 0; i < 2; ++i ) - { - int result = SingleMeshDropTest( workerCounts[i], &reference ); - ENSURE( result == 0 ); - } - - return 0; -} - -static uint32_t HashFloats( uint32_t hash, const float* values, int count ) -{ - return b3Hash( hash, (const uint8_t*)values, count * (int)sizeof( float ) ); -} - -// Rolling resistance is mixed per contact and the manifolds have one, two, and four points, so a width 8 -// constraint can mix lanes that width 4 keeps in separate constraints. The hash covers the stored contact -// impulses bitwise, including the sign of zero, because those survive into warm starting and contact data. -static int SingleRollingMixTest( int workerCount, DeterminismResult* reference ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3ShapeDef groundShapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &groundShapeDef, &groundBox.base ); - - enum - { - rowCount = 8, - columnCount = 8, - bodyCount = rowCount * columnCount - }; - - b3BodyId bodyIds[bodyCount]; - b3BoxHull box = b3MakeBoxHull( 0.4f, 0.4f, 0.4f ); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.4f }; - b3Capsule capsule = { { -0.3f, 0.0f, 0.0f }, { 0.3f, 0.0f, 0.0f }, 0.25f }; - - uint32_t seed = 271828u; - for ( int i = 0; i < bodyCount; ++i ) - { - int row = i / columnCount; - int column = i % columnCount; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 2.0f * (float)column - 7.0f, 1.45f, 2.0f * (float)row - 7.0f }; - bodyIds[i] = b3CreateBody( worldId, &bodyDef ); - - seed = seed * 1664525u + 1013904223u; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.rollingResistance = ( seed >> 28 ) < 5 ? 0.2f : 0.0f; - - switch ( i % 3 ) - { - case 0: - b3CreateSphereShape( bodyIds[i], &shapeDef, &sphere ); - break; - case 1: - b3CreateCapsuleShape( bodyIds[i], &shapeDef, &capsule ); - break; - default: - b3CreateHullShape( bodyIds[i], &shapeDef, &box.base ); - break; - } - - float sign = ( i & 1 ) ? -1.0f : 1.0f; - b3Body_SetLinearVelocity( bodyIds[i], (b3Vec3){ -0.0f, -0.5f, sign * 0.5f } ); - b3Body_SetAngularVelocity( bodyIds[i], (b3Vec3){ sign * 3.0f, -0.0f, -2.0f * sign } ); - } - - uint32_t hash = B3_HASH_INIT; - int stepCount = 120; - for ( int step = 0; step < stepCount; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - for ( int i = 0; i < bodyCount; ++i ) - { - b3WorldTransform xf = b3Body_GetTransform( bodyIds[i] ); - hash = b3Hash( hash, (const uint8_t*)&xf, sizeof( b3WorldTransform ) ); - - b3ContactData contactData[4]; - int contactCount = b3Body_GetContactData( bodyIds[i], contactData, ARRAY_COUNT( contactData ) ); - for ( int c = 0; c < contactCount; ++c ) - { - for ( int m = 0; m < contactData[c].manifoldCount; ++m ) - { - const b3Manifold* manifold = contactData[c].manifolds + m; - hash = HashFloats( hash, &manifold->rollingImpulse.x, 3 ); - hash = HashFloats( hash, &manifold->frictionImpulse.x, 3 ); - hash = HashFloats( hash, &manifold->twistImpulse, 1 ); - - for ( int p = 0; p < manifold->pointCount; ++p ) - { - hash = HashFloats( hash, &manifold->points[p].normalImpulse, 1 ); - hash = HashFloats( hash, &manifold->points[p].totalNormalImpulse, 1 ); - } - } - } - } - } - - b3DestroyWorld( worldId ); - - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = stepCount, .hash = hash } ) == 0 ); - return 0; -} - -// Mesh contacts are grouped across lanes by manifold count and padded to the largest count in the group. Width 8 groups -// differ from width 4 groups, so mixing large and small shapes on a fine mesh gives each body a width dependent number -// of padded manifolds. The hash covers velocities and impulses bitwise to catch a padded manifold flipping a signed zero. -static int SingleMeshMixTest( int workerCount, DeterminismResult* reference ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3MeshData* mesh = b3CreateWaveMesh( 40, 40, 0.5f, 0.3f, 0.2f, 0.3f ); - { - b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.position = (b3Pos){ -10.0f, 0.0f, -10.0f }; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one ); - } - - enum - { - rowCount = 8, - columnCount = 8, - bodyCount = rowCount * columnCount - }; - - b3BodyId bodyIds[bodyCount]; - b3BoxHull smallBox = b3MakeBoxHull( 0.2f, 0.2f, 0.2f ); - b3BoxHull largeBox = b3MakeBoxHull( 0.9f, 0.3f, 0.9f ); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.3f }; - b3Capsule capsule = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, 0.2f }; - - uint32_t seed = 314159u; - for ( int i = 0; i < bodyCount; ++i ) - { - int row = i / columnCount; - int column = i % columnCount; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 2.2f * (float)column - 7.7f, 1.2f, 2.2f * (float)row - 7.7f }; - bodyIds[i] = b3CreateBody( worldId, &bodyDef ); - - seed = seed * 1664525u + 1013904223u; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.rollingResistance = ( seed >> 28 ) < 5 ? 0.2f : 0.0f; - - switch ( ( seed >> 24 ) & 3 ) - { - case 0: - b3CreateHullShape( bodyIds[i], &shapeDef, &largeBox.base ); - break; - case 1: - b3CreateHullShape( bodyIds[i], &shapeDef, &smallBox.base ); - break; - case 2: - b3CreateSphereShape( bodyIds[i], &shapeDef, &sphere ); - break; - default: - b3CreateCapsuleShape( bodyIds[i], &shapeDef, &capsule ); - break; - } - - float sign = ( i & 1 ) ? -1.0f : 1.0f; - b3Body_SetLinearVelocity( bodyIds[i], (b3Vec3){ -0.0f, -0.5f, -0.0f } ); - b3Body_SetAngularVelocity( bodyIds[i], (b3Vec3){ -0.0f, sign * 0.5f, -0.0f } ); - } - - uint32_t hash = B3_HASH_INIT; - int stepCount = 180; - for ( int step = 0; step < stepCount; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - for ( int i = 0; i < bodyCount; ++i ) - { - b3WorldTransform xf = b3Body_GetTransform( bodyIds[i] ); - hash = b3Hash( hash, (const uint8_t*)&xf, sizeof( b3WorldTransform ) ); - - b3Vec3 v = b3Body_GetLinearVelocity( bodyIds[i] ); - b3Vec3 w = b3Body_GetAngularVelocity( bodyIds[i] ); - hash = HashFloats( hash, &v.x, 3 ); - hash = HashFloats( hash, &w.x, 3 ); - - b3ContactData contactData[8]; - int contactCount = b3Body_GetContactData( bodyIds[i], contactData, ARRAY_COUNT( contactData ) ); - for ( int c = 0; c < contactCount; ++c ) - { - for ( int m = 0; m < contactData[c].manifoldCount; ++m ) - { - const b3Manifold* manifold = contactData[c].manifolds + m; - hash = HashFloats( hash, &manifold->rollingImpulse.x, 3 ); - hash = HashFloats( hash, &manifold->frictionImpulse.x, 3 ); - hash = HashFloats( hash, &manifold->twistImpulse, 1 ); - - for ( int p = 0; p < manifold->pointCount; ++p ) - { - hash = HashFloats( hash, &manifold->points[p].normalImpulse, 1 ); - hash = HashFloats( hash, &manifold->points[p].totalNormalImpulse, 1 ); - } - } - } - } - } - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - - ENSURE( EnsureRepeatable( reference, (DeterminismResult){ .sleepStep = stepCount, .hash = hash } ) == 0 ); - return 0; -} - -typedef int SceneFcn( int workerCount, DeterminismResult* reference ); - -static int RunSceneAtWidth( SceneFcn* scene, int width, DeterminismResult* result ) -{ - b3SetSIMDWidth( width ); - int status = scene( 1, result ); - b3SetSIMDWidth( 0 ); - return status; -} - -// Width 4 and the native width must produce bitwise identical simulations. -static int SIMDWidthTest( void ) -{ - b3SetSIMDWidth( 0 ); - int nativeWidth = b3GetSIMDWidth(); - if ( nativeWidth == 4 ) - { - printf( " subtest skipped: SIMDWidthTest, native SIMD width is 4\n" ); - return 0; - } - - SceneFcn* scenes[] = { - SingleMultithreadingTest, SingleWavePileTest, SingleQuerySpawnTest, SingleMeshDropTest, SingleRollingMixTest, SingleMeshMixTest, - }; - - for ( int i = 0; i < ARRAY_COUNT( scenes ); ++i ) - { - DeterminismResult narrow = { 0 }; - DeterminismResult wide = { 0 }; - - int narrowStatus = RunSceneAtWidth( scenes[i], 4, &narrow ); - int wideStatus = RunSceneAtWidth( scenes[i], nativeWidth, &wide ); - - ENSURE( narrowStatus == 0 ); - ENSURE( wideStatus == 0 ); - ENSURE( narrow.seeded && wide.seeded ); - ENSURE( narrow.sleepStep == wide.sleepStep ); - ENSURE( narrow.hash == wide.hash ); - ENSURE( narrow.queryHitCount == wide.queryHitCount ); - ENSURE( narrow.queryHash == wide.queryHash ); - } - - return 0; -} - int DeterminismTest( void ) { RUN_SUBTEST( MultithreadingTest ); RUN_SUBTEST( CrossPlatformTest ); - RUN_SUBTEST( WavePileTest ); - RUN_SUBTEST( QuerySpawnTest ); - RUN_SUBTEST( MeshDropTest ); - RUN_SUBTEST( SIMDWidthTest ); return 0; } diff --git a/test/test_distance.c b/test/test_distance.c index 59254f5..97d3881 100644 --- a/test/test_distance.c +++ b/test/test_distance.c @@ -79,136 +79,6 @@ static int ShapeCastTest( void ) return 0; } -// unit box with a segment resting 2mm from its +x face: inside the cast -// target distance, not overlapped -static b3ShapeCastPairInput EncroachCastInput( b3Vec3 translationB ) -{ - static const b3Vec3 vas[] = { { -1.0f, -1.0f, 0.0f }, { 1.0f, -1.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, { -1.0f, 1.0f, 0.0f } }; - static const b3Vec3 vbs[] = { - { 1.002f, -1.0f, 0.0f }, - { 1.002f, 1.0f, 0.0f }, - }; - - b3ShapeCastPairInput input; - input.proxyA = (b3ShapeProxy){ vas, ARRAY_COUNT( vas ), 0.0f }; - input.proxyB = (b3ShapeProxy){ vbs, ARRAY_COUNT( vbs ), 0.0f }; - input.transform = b3Transform_identity; - input.translationB = translationB; - input.maxFraction = 1.0f; - input.canEncroach = true; - return input; -} - -static int ShapeCastEncroachRecedeTest( void ) -{ - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ 1.0f, 0.0f, 0.0f } ); - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit == false ); - - return 0; -} - -static int ShapeCastEncroachSlideTest( void ) -{ - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ 0.0f, 2.0f, 0.0f } ); - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit == false ); - - return 0; -} - -static int ShapeCastEncroachClosingTest( void ) -{ - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ -1.0f, 0.0f, 0.0f } ); - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit ); - ENSURE_SMALL( output.fraction, FLT_EPSILON ); - ENSURE_SMALL( output.normal.x - 1.0f, 0.001f ); - - return 0; -} - -static int ShapeCastEncroachGradedTest( void ) -{ - // 5mm gap: closing consumes the gap down to the retained rest separation - static const b3Vec3 vbs[] = { - { 1.005f, -1.0f, 0.0f }, - { 1.005f, 1.0f, 0.0f }, - }; - - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ -1.0f, 0.0f, 0.0f } ); - input.proxyB = (b3ShapeProxy){ vbs, ARRAY_COUNT( vbs ), 0.0f }; - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit ); - ENSURE_SMALL( output.fraction - 0.0025f, 0.0005f ); - ENSURE_SMALL( output.normal.x - 1.0f, 0.001f ); - - return 0; -} - -static int ShapeCastEncroachMaxFractionTest( void ) -{ - // 5mm gap closes at fraction 0.0025 - static const b3Vec3 vbs[] = { - { 1.005f, -1.0f, 0.0f }, - { 1.005f, 1.0f, 0.0f }, - }; - - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ -1.0f, 0.0f, 0.0f } ); - input.proxyB = (b3ShapeProxy){ vbs, ARRAY_COUNT( vbs ), 0.0f }; - input.maxFraction = 0.002f; - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit == false ); - - input.maxFraction = 0.003f; - output = b3ShapeCast( &input ); - ENSURE( output.hit ); - ENSURE_SMALL( output.fraction - 0.0025f, 0.0005f ); - - return 0; -} - -static int ShapeCastEncroachGrazeTest( void ) -{ - // mostly tangential slide with a slight closing component: free - static const b3Vec3 vbs[] = { - { 1.005f, -1.0f, 0.0f }, - { 1.005f, 1.0f, 0.0f }, - }; - - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ -0.001f, 2.0f, 0.0f } ); - input.proxyB = (b3ShapeProxy){ vbs, ARRAY_COUNT( vbs ), 0.0f }; - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit == false ); - - return 0; -} - -static int ShapeCastStartTouchingDefaultTest( void ) -{ - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ 1.0f, 0.0f, 0.0f } ); - input.canEncroach = false; - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit ); - - return 0; -} - -static int ShapeCastEncroachOverlapTest( void ) -{ - static const b3Vec3 vcs[] = { - { 0.5f, -1.0f, 0.0f }, - { 0.5f, 1.0f, 0.0f }, - }; - - b3ShapeCastPairInput input = EncroachCastInput( (b3Vec3){ 1.0f, 0.0f, 0.0f } ); - input.proxyB = (b3ShapeProxy){ vcs, ARRAY_COUNT( vcs ), 0.0f }; - b3CastOutput output = b3ShapeCast( &input ); - ENSURE( output.hit ); - - return 0; -} - static int TimeOfImpactTest( void ) { b3Vec3 vas[] = { { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f } }; @@ -238,14 +108,6 @@ int DistanceTest( void ) RUN_SUBTEST( SegmentDistanceTest ); RUN_SUBTEST( ShapeDistanceTest ); RUN_SUBTEST( ShapeCastTest ); - RUN_SUBTEST( ShapeCastEncroachRecedeTest ); - RUN_SUBTEST( ShapeCastEncroachSlideTest ); - RUN_SUBTEST( ShapeCastEncroachClosingTest ); - RUN_SUBTEST( ShapeCastEncroachGradedTest ); - RUN_SUBTEST( ShapeCastEncroachMaxFractionTest ); - RUN_SUBTEST( ShapeCastEncroachGrazeTest ); - RUN_SUBTEST( ShapeCastStartTouchingDefaultTest ); - RUN_SUBTEST( ShapeCastEncroachOverlapTest ); RUN_SUBTEST( TimeOfImpactTest ); return 0; diff --git a/test/test_dynamic_tree.c b/test/test_dynamic_tree.c deleted file mode 100644 index 0561d2e..0000000 --- a/test/test_dynamic_tree.c +++ /dev/null @@ -1,684 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "aabb.h" -#include "dynamic_tree.h" -#include "test_macros.h" - -#include "box3d/collision.h" -#include "box3d/constants.h" -#include "box3d/math_functions.h" - -#include -#include -#include - -#define PROXY_COUNT 300 - -static uint32_t s_seed = 12345; - -static uint32_t NextRandom( void ) -{ - s_seed = 1664525u * s_seed + 1013904223u; - return s_seed; -} - -static float RandomFloat( float lo, float hi ) -{ - float t = (float)( NextRandom() >> 8 ) / (float)( 1 << 24 ); - return lo + t * ( hi - lo ); -} - -static b3AABB RandomBox( float extent, float size ) -{ - b3Vec3 center = { RandomFloat( -extent, extent ), RandomFloat( -extent, extent ), RandomFloat( -extent, extent ) }; - b3Vec3 half = { RandomFloat( 0.1f, size ), RandomFloat( 0.1f, size ), RandomFloat( 0.1f, size ) }; - return (b3AABB){ b3Sub( center, half ), b3Add( center, half ) }; -} - -typedef struct HitSet -{ - int ids[PROXY_COUNT]; - int count; - bool bad; -} HitSet; - -// Every test seeds user data with the index of the box it created the proxy from, so the sets -// are keyed on user data. Proxy ids recycle, box indices do not. -// A callback cannot fail the test directly, so bad news rides back on the context. -static bool CollectCallback( int proxyId, uint64_t userData, void* context ) -{ - HitSet* set = context; - if ( set->count >= PROXY_COUNT || (int)userData < 0 || (int)userData >= PROXY_COUNT ) - { - set->bad = true; - return false; - } - - (void)proxyId; - set->ids[set->count] = (int)userData; - set->count += 1; - return true; -} - -static int CompareInt( const void* a, const void* b ) -{ - int x = *(const int*)a; - int y = *(const int*)b; - return x < y ? -1 : ( x > y ? 1 : 0 ); -} - -static int SameSet( HitSet* a, HitSet* b ) -{ - ENSURE( a->bad == false ); - ENSURE( b->bad == false ); - ENSURE( a->count == b->count ); - qsort( a->ids, (size_t)a->count, sizeof( int ), CompareInt ); - qsort( b->ids, (size_t)b->count, sizeof( int ), CompareInt ); - for ( int i = 0; i < a->count; ++i ) - { - ENSURE( a->ids[i] == b->ids[i] ); - } - - return 0; -} - -// The tree must agree with a linear scan over the stored boxes. This is the gate on the -// SIMD box helpers, which have three separate lane layouts. -static int TreeQueryBruteForce( void ) -{ - s_seed = 12345; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 6.0f, 1.5f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - ENSURE( proxies[i] == i ); - } - - b3DynamicTree_Validate( &tree ); - ENSURE( b3DynamicTree_GetProxyCount( &tree ) == PROXY_COUNT ); - - int totalHits = 0; - for ( int round = 0; round < 200; ++round ) - { - b3AABB queryBox = RandomBox( 7.0f, 3.0f ); - - HitSet treeHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, B3_DEFAULT_MASK_BITS, false, CollectCallback, &treeHits ); - - HitSet bruteHits = { 0 }; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - if ( b3AABB_Overlaps( boxes[i], queryBox ) ) - { - bruteHits.ids[bruteHits.count] = i; - bruteHits.count += 1; - } - } - - ENSURE( SameSet( &treeHits, &bruteHits ) == 0 ); - totalHits += treeHits.count; - } - - // Guard against the comparison above agreeing on nothing - ENSURE( totalHits > 1000 ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -// Moving and enlarging every proxy exercises remove, insert, the ordered flag, the sweep refit -// and the partial rebuild, then the query has to still agree with the scan. -static int TreeMoveRefitRebuild( void ) -{ - s_seed = 777; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 6.0f, 1.0f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - } - - b3DynamicTree_Rebuild( &tree, true ); - b3DynamicTree_Validate( &tree ); - ENSURE( tree.dfsOrdered ); - - int totalHits = 0; - for ( int round = 0; round < 8; ++round ) - { - // Half the proxies move, half grow in place - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - if ( ( i & 1 ) == 0 ) - { - boxes[i] = RandomBox( 6.0f, 1.0f ); - b3DynamicTree_MoveProxy( &tree, proxies[i], boxes[i] ); - } - else - { - b3AABB grown = b3AABB_Inflate( boxes[i], 0.35f ); - boxes[i] = grown; - b3DynamicTree_EnlargeProxy( &tree, proxies[i], grown ); - } - } - - b3DynamicTree_Refit( &tree ); - b3DynamicTree_Validate( &tree ); - - b3DynamicTree_Rebuild( &tree, false ); - b3DynamicTree_Validate( &tree ); - b3DynamicTree_ValidateNoMoved( &tree ); - ENSURE( tree.dfsOrdered ); - - // Every stored box must still be inside its leaf and inside the root - b3AABB rootBounds = b3DynamicTree_GetRootBounds( &tree ); - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - ENSURE( b3AABB_Contains( b3DynamicTree_GetAABB( &tree, proxies[i] ), boxes[i] ) ); - ENSURE( b3AABB_Contains( rootBounds, boxes[i] ) ); - ENSURE( (int)b3DynamicTree_GetUserData( &tree, proxies[i] ) == i ); - } - - b3AABB queryBox = RandomBox( 7.0f, 3.0f ); - - HitSet treeHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, B3_DEFAULT_MASK_BITS, false, CollectCallback, &treeHits ); - - HitSet bruteHits = { 0 }; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - if ( b3AABB_Overlaps( boxes[i], queryBox ) ) - { - bruteHits.ids[bruteHits.count] = i; - bruteHits.count += 1; - } - } - - ENSURE( SameSet( &treeHits, &bruteHits ) == 0 ); - totalHits += treeHits.count; - } - - // Guard against the comparison above agreeing on nothing - ENSURE( totalHits > 50 ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -// Destroying proxies in a scrambled order recycles sibling pairs through the free list and -// leaves the array unordered, which is the path the fallback refit has to handle. -static int TreeDestroyScrambled( void ) -{ - s_seed = 4242; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - bool alive[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 10.0f, 0.8f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - alive[i] = true; - } - - for ( int i = 0; i < PROXY_COUNT; i += 3 ) - { - b3DynamicTree_DestroyProxy( &tree, proxies[i] ); - alive[i] = false; - } - - b3DynamicTree_Validate( &tree ); - - // Re-create into the holes - for ( int i = 0; i < PROXY_COUNT; i += 3 ) - { - boxes[i] = RandomBox( 10.0f, 0.8f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - alive[i] = true; - } - - b3DynamicTree_Validate( &tree ); - ENSURE( b3DynamicTree_GetProxyCount( &tree ) == PROXY_COUNT ); - - // The user data has to have followed each proxy through the churn - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - ENSURE( alive[i] ); - ENSURE( (int)b3DynamicTree_GetUserData( &tree, proxies[i] ) == i ); - ENSURE( b3AABB_Contains( b3DynamicTree_GetAABB( &tree, proxies[i] ), boxes[i] ) ); - } - - b3AABB queryBox = { { -10.0f, -10.0f, -10.0f }, { 10.0f, 10.0f, 10.0f } }; - HitSet treeHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, B3_DEFAULT_MASK_BITS, false, CollectCallback, &treeHits ); - - HitSet bruteHits = { 0 }; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - if ( b3AABB_Overlaps( boxes[i], queryBox ) ) - { - bruteHits.ids[bruteHits.count] = i; - bruteHits.count += 1; - } - } - - ENSURE( SameSet( &treeHits, &bruteHits ) == 0 ); - ENSURE( treeHits.count == PROXY_COUNT ); - - // Empty the tree - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - b3DynamicTree_DestroyProxy( &tree, proxies[i] ); - } - - b3DynamicTree_Validate( &tree ); - ENSURE( b3DynamicTree_GetProxyCount( &tree ) == 0 ); - ENSURE( b3DynamicTree_GetHeight( &tree ) == 0 ); - - // Queries on an empty tree must be silent - HitSet emptyHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, B3_DEFAULT_MASK_BITS, false, CollectCallback, &emptyHits ); - ENSURE( emptyHits.count == 0 ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -typedef struct LeafRootHit -{ - int count; - int proxyId; - uint64_t userData; -} LeafRootHit; - -static bool LeafRootCallback( int proxyId, uint64_t userData, void* context ) -{ - LeafRootHit* hit = context; - hit->count += 1; - hit->proxyId = proxyId; - hit->userData = userData; - return true; -} - -// A one proxy tree is a leaf at the root with an empty node beside it, which every traversal -// has to survive. -static int TreeLeafRoot( void ) -{ - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB box = { { -1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, 1.0f } }; - int proxyId = b3DynamicTree_CreateProxy( &tree, box, B3_DEFAULT_CATEGORY_BITS, 7 ); - - b3DynamicTree_Validate( &tree ); - ENSURE( b3DynamicTree_GetProxyCount( &tree ) == 1 ); - ENSURE( b3DynamicTree_GetHeight( &tree ) == 0 ); - ENSURE( b3DynamicTree_GetAreaRatio( &tree ) == 0.0f ); - ENSURE( b3DynamicTree_GetUserData( &tree, proxyId ) == 7 ); - - LeafRootHit hit = { 0 }; - b3AABB hitBox = { { 0.5f, 0.5f, 0.5f }, { 2.0f, 2.0f, 2.0f } }; - b3DynamicTree_Query( &tree, hitBox, B3_DEFAULT_MASK_BITS, false, LeafRootCallback, &hit ); - ENSURE( hit.count == 1 ); - ENSURE( hit.proxyId == proxyId ); - ENSURE( hit.userData == 7 ); - - hit.count = 0; - b3AABB missBox = { { 4.0f, 4.0f, 4.0f }, { 5.0f, 5.0f, 5.0f } }; - b3DynamicTree_Query( &tree, missBox, B3_DEFAULT_MASK_BITS, false, LeafRootCallback, &hit ); - ENSURE( hit.count == 0 ); - - // The rebuild has one build leaf and the refit has nothing above it - b3DynamicTree_Rebuild( &tree, true ); - b3DynamicTree_Validate( &tree ); - b3DynamicTree_Refit( &tree ); - b3DynamicTree_Validate( &tree ); - ENSURE( b3DynamicTree_GetProxyCount( &tree ) == 1 ); - - b3AABB grown = b3AABB_Inflate( box, 1.0f ); - b3DynamicTree_EnlargeProxy( &tree, proxyId, grown ); - ENSURE( b3AABB_Contains( b3DynamicTree_GetAABB( &tree, proxyId ), grown ) ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -// Category bits live on the proxy now, so the filter has to bite at the leaf. -static int TreeCategoryFilter( void ) -{ - s_seed = 99; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - uint64_t bits[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 8.0f, 0.6f ); - bits[i] = 1ull << ( i % 3 ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], bits[i], (uint64_t)i ); - ENSURE( b3DynamicTree_GetCategoryBits( &tree, proxies[i] ) == bits[i] ); - } - - b3AABB queryBox = { { -8.0f, -8.0f, -8.0f }, { 8.0f, 8.0f, 8.0f } }; - - // A single bit mask makes requireAll equivalent to the any-bit test, so the last pass is - // the one that proves requireAll accepts rather than just rejects - static const uint64_t masks[3] = { 0x1ull, 0x3ull, 0x2ull }; - static const bool requireAlls[3] = { false, false, true }; - - for ( int pass = 0; pass < 3; ++pass ) - { - uint64_t mask = masks[pass]; - bool requireAll = requireAlls[pass]; - - HitSet treeHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, mask, requireAll, CollectCallback, &treeHits ); - - HitSet bruteHits = { 0 }; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - bool accept = requireAll ? ( bits[i] & mask ) == mask : ( bits[i] & mask ) != 0; - if ( accept && b3AABB_Overlaps( boxes[i], queryBox ) ) - { - bruteHits.ids[bruteHits.count] = i; - bruteHits.count += 1; - } - } - - ENSURE( SameSet( &treeHits, &bruteHits ) == 0 ); - ENSURE( treeHits.count > PROXY_COUNT / 4 ); - } - - // requireAll with two bits can never match a single bit proxy - HitSet noHits = { 0 }; - b3DynamicTree_Query( &tree, queryBox, 0x5ull, true, CollectCallback, &noHits ); - ENSURE( noHits.count == 0 ); - - // Changing the bits has to change the filter without touching the structure - b3DynamicTree_SetCategoryBits( &tree, proxies[0], 0x8ull ); - ENSURE( b3DynamicTree_GetCategoryBits( &tree, proxies[0] ) == 0x8ull ); - b3DynamicTree_Validate( &tree ); - - HitSet oneHit = { 0 }; - b3DynamicTree_Query( &tree, queryBox, 0x8ull, false, CollectCallback, &oneHit ); - ENSURE( oneHit.count == 1 ); - ENSURE( oneHit.ids[0] == 0 ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -// Returning -1 skips the proxy without shrinking the fraction, so the traversal keeps going -// and reports every proxy whose node box the segment crosses. -static float RayCastCollectCallback( const b3RayCastInput* input, int proxyId, uint64_t userData, void* context ) -{ - (void)input; - (void)proxyId; - HitSet* set = context; - if ( set->count >= PROXY_COUNT || (int)userData < 0 || (int)userData >= PROXY_COUNT ) - { - set->bad = true; - return 0.0f; - } - - set->ids[set->count] = (int)userData; - set->count += 1; - return -1.0f; -} - -static float BoxCastCollectCallback( const b3BoxCastInput* input, int proxyId, uint64_t userData, void* context ) -{ - (void)input; - (void)proxyId; - HitSet* set = context; - if ( set->count >= PROXY_COUNT || (int)userData < 0 || (int)userData >= PROXY_COUNT ) - { - set->bad = true; - return 0.0f; - } - - set->ids[set->count] = (int)userData; - set->count += 1; - return -1.0f; -} - -// The casts pop a pair, test both nodes and order the survivors. A ray that skips every hit -// must still reach every proxy its segment crosses. -static int TreeCastBruteForce( void ) -{ - s_seed = 31337; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 6.0f, 1.0f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - } - - b3DynamicTree_Rebuild( &tree, true ); - b3DynamicTree_Validate( &tree ); - - int totalCrossings = 0; - for ( int round = 0; round < 100; ++round ) - { - b3Vec3 origin = { RandomFloat( -8.0f, 8.0f ), RandomFloat( -8.0f, 8.0f ), RandomFloat( -8.0f, 8.0f ) }; - b3Vec3 translation = { RandomFloat( -16.0f, 16.0f ), RandomFloat( -16.0f, 16.0f ), RandomFloat( -16.0f, 16.0f ) }; - - b3RayCastInput rayInput = { .origin = origin, .translation = translation, .maxFraction = 1.0f }; - - HitSet treeHits = { 0 }; - b3DynamicTree_RayCast( &tree, &rayInput, B3_DEFAULT_MASK_BITS, false, RayCastCollectCallback, &treeHits ); - ENSURE( treeHits.bad == false ); - - // The tree may report a superset because it tests the node box, not the shape. Every - // proxy the segment actually crosses has to be in there. - b3Vec3 p2 = b3MulAdd( origin, 1.0f, translation ); - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - float minFraction = 0.0f; - float maxFraction = 1.0f; - if ( b3RayCastAABB( boxes[i], origin, p2, &minFraction, &maxFraction ) == false ) - { - continue; - } - - bool found = false; - for ( int j = 0; j < treeHits.count; ++j ) - { - if ( treeHits.ids[j] == i ) - { - found = true; - break; - } - } - - ENSURE( found ); - totalCrossings += 1; - } - - // Every reported proxy has to at least overlap the segment box - b3AABB segmentBox = { b3Min( origin, p2 ), b3Max( origin, p2 ) }; - for ( int j = 0; j < treeHits.count; ++j ) - { - ENSURE( b3AABB_Overlaps( boxes[treeHits.ids[j]], segmentBox ) ); - } - - // A zero extent box cast has to reach the same proxies as the ray - b3AABB castBox = { origin, origin }; - b3BoxCastInput boxInput = { .box = castBox, .translation = translation, .maxFraction = 1.0f }; - - HitSet boxHits = { 0 }; - b3DynamicTree_BoxCast( &tree, &boxInput, B3_DEFAULT_MASK_BITS, false, BoxCastCollectCallback, &boxHits ); - ENSURE( boxHits.bad == false ); - - for ( int j = 0; j < treeHits.count; ++j ) - { - bool found = false; - for ( int k = 0; k < boxHits.count; ++k ) - { - if ( boxHits.ids[k] == treeHits.ids[j] ) - { - found = true; - break; - } - } - - ENSURE( found ); - } - } - - // Guard against the comparisons above agreeing on nothing - ENSURE( totalCrossings > 100 ); - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -typedef struct ClosestResult -{ - const b3AABB* boxes; - b3Vec3 point; - bool bad; -} ClosestResult; - -static float DistanceToBoxSqr( b3Vec3 point, b3AABB box ) -{ - b3Vec3 r = b3Sub( point, b3Clamp( point, box.lowerBound, box.upperBound ) ); - return b3Dot( r, r ); -} - -static float ClosestCollectCallback( float distanceSqrMin, int proxyId, uint64_t userData, void* context ) -{ - ClosestResult* result = context; - if ( (int)userData != proxyId ) - { - result->bad = true; - return distanceSqrMin; - } - - float d = DistanceToBoxSqr( result->point, result->boxes[proxyId] ); - return d < distanceSqrMin ? d : distanceSqrMin; -} - -// The closest query orders by distance and prunes on the running minimum, so seeding it from -// the root pair has to be right or it prunes away a whole half of the tree. -static int TreeQueryClosest( void ) -{ - s_seed = 5150; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 6.0f, 0.9f ); - int proxyId = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - ENSURE( proxyId == i ); - } - - for ( int round = 0; round < 100; ++round ) - { - b3Vec3 point = { RandomFloat( -8.0f, 8.0f ), RandomFloat( -8.0f, 8.0f ), RandomFloat( -8.0f, 8.0f ) }; - - float bruteBest = FLT_MAX; - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - float d = DistanceToBoxSqr( point, boxes[i] ); - if ( d < bruteBest ) - { - bruteBest = d; - } - } - - // The callback reports the exact box distance, so the pruned search has to land on the - // same minimum as the scan. Same arithmetic both ways, so this is an exact compare. - ClosestResult result = { .boxes = boxes, .point = point }; - float minDistanceSqr = FLT_MAX; - b3DynamicTree_QueryClosest( &tree, point, B3_DEFAULT_MASK_BITS, false, ClosestCollectCallback, &result, - &minDistanceSqr ); - - ENSURE( result.bad == false ); - ENSURE( minDistanceSqr == bruteBest ); - } - - b3DynamicTree_Destroy( &tree ); - return 0; -} - -// A saved tree carries only its live node range. -static int TreeSaveLoadRoundtrip( void ) -{ - s_seed = 4242; - - b3DynamicTree tree = b3DynamicTree_Create( 16 ); - - b3AABB boxes[PROXY_COUNT]; - int proxies[PROXY_COUNT]; - - for ( int i = 0; i < PROXY_COUNT; ++i ) - { - boxes[i] = RandomBox( 6.0f, 1.0f ); - proxies[i] = b3DynamicTree_CreateProxy( &tree, boxes[i], B3_DEFAULT_CATEGORY_BITS, (uint64_t)i ); - } - - // Destroy a few so the pair free list is populated and the node tail is stale - for ( int i = 0; i < PROXY_COUNT; i += 37 ) - { - b3DynamicTree_DestroyProxy( &tree, proxies[i] ); - } - - b3DynamicTree_Rebuild( &tree, true ); - b3DynamicTree_Validate( &tree ); - - const char* treePath = "test_dynamic_tree_roundtrip.dat"; - b3DynamicTree_Save( &tree, treePath ); - - b3DynamicTree loaded = b3DynamicTree_Load( treePath, 1.0f ); - remove( treePath ); - - ENSURE( loaded.nodes != NULL ); - ENSURE( loaded.nodeEnd == tree.nodeEnd ); - ENSURE( loaded.nodeCapacity == tree.nodeEnd ); - ENSURE( b3DynamicTree_GetProxyCount( &loaded ) == b3DynamicTree_GetProxyCount( &tree ) ); - ENSURE( memcmp( loaded.nodes, tree.nodes, (size_t)tree.nodeEnd * sizeof( b3TreeNode ) ) == 0 ); - ENSURE( memcmp( loaded.parents, tree.parents, (size_t)tree.nodeEnd * sizeof( int32_t ) ) == 0 ); - b3DynamicTree_Validate( &loaded ); - - b3DynamicTree_Destroy( &loaded ); - b3DynamicTree_Destroy( &tree ); - return 0; -} - -int DynamicTreeTest( void ) -{ - RUN_SUBTEST( TreeLeafRoot ); - RUN_SUBTEST( TreeQueryBruteForce ); - RUN_SUBTEST( TreeCategoryFilter ); - RUN_SUBTEST( TreeMoveRefitRebuild ); - RUN_SUBTEST( TreeDestroyScrambled ); - RUN_SUBTEST( TreeCastBruteForce ); - RUN_SUBTEST( TreeQueryClosest ); - RUN_SUBTEST( TreeSaveLoadRoundtrip ); - - return 0; -} diff --git a/test/test_hash.c b/test/test_hash.c deleted file mode 100644 index f6271b9..0000000 --- a/test/test_hash.c +++ /dev/null @@ -1,620 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "core.h" -#include "hull.h" -#include "physics_world.h" -#include "table.h" -#include "test_macros.h" - -#include "box3d/box3d.h" -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include -#include - -// Separates the two things a repeated hash can mean. Identical bytes repeating is normal, since -// distinct generator parameters can still bake to the same geometry. Distinct bytes sharing a hash -// is the failure this file exists to catch, so the invariant under test is that different content -// gets different digests, never that different parameters do. -// -// Zero doubles as "no collision", since the hash reserves that value. Results are read back only -// after teardown so a failing test does not also dump a leak and bury which condition broke. -typedef struct HashEntry -{ - uint64_t hash; - int byteCount; - uint8_t* bytes; -} HashEntry; - -typedef struct HashProbe -{ - b3HashSet set; - HashEntry* entries; - int count; - int capacity; - uint64_t collision; - int duplicates; - bool sawZero; - bool overflow; -} HashProbe; - -typedef struct HashResult -{ - uint64_t collision; - int count; - int duplicates; - bool sawZero; - bool overflow; -} HashResult; - -static HashProbe ProbeBegin( int capacity ) -{ - HashProbe probe = { 0 }; - probe.set = b3CreateSet( capacity ); - probe.entries = B3_ALLOC( HashEntry, capacity ); - probe.capacity = capacity; - return probe; -} - -// Pass NULL bytes when the caller builds provably distinct inputs, so any repeat is a collision by -// construction and there is nothing to compare against. -static void ProbeAdd( HashProbe* probe, uint64_t hash, const void* bytes, int byteCount ) -{ - if ( hash == 0 ) - { - probe->sawZero = true; - } - - if ( probe->count == probe->capacity ) - { - probe->overflow = true; - return; - } - - if ( b3AddKey( &probe->set, hash ) ) - { - bool sameContent = false; - if ( bytes != NULL ) - { - for ( int i = 0; i < probe->count; ++i ) - { - if ( probe->entries[i].hash != hash ) - { - continue; - } - - sameContent = probe->entries[i].byteCount == byteCount && - memcmp( probe->entries[i].bytes, bytes, (size_t)byteCount ) == 0; - break; - } - } - - if ( sameContent ) - { - probe->duplicates += 1; - } - else if ( probe->collision == 0 ) - { - probe->collision = hash; - } - } - - HashEntry* entry = probe->entries + probe->count; - entry->hash = hash; - entry->byteCount = 0; - entry->bytes = NULL; - - if ( bytes != NULL && byteCount > 0 ) - { - entry->byteCount = byteCount; - entry->bytes = B3_ALLOC( uint8_t, byteCount ); - memcpy( entry->bytes, bytes, (size_t)byteCount ); - } - - probe->count += 1; -} - -static HashResult ProbeEnd( HashProbe* probe ) -{ - HashResult result = { probe->collision, probe->count, probe->duplicates, probe->sawZero, probe->overflow }; - - for ( int i = 0; i < probe->count; ++i ) - { - if ( probe->entries[i].bytes != NULL ) - { - B3_FREE( probe->entries[i].bytes, uint8_t, probe->entries[i].byteCount ); - } - } - - B3_FREE( probe->entries, HashEntry, probe->capacity ); - b3DestroySet( &probe->set ); - return result; -} - -// Pins that the upper bytes of each 8 byte word reach the low bits of the hash. Multiply carries -// bits upward only, so a hash that keeps just the low half of its product leaves the low bits blind -// to those bytes, and blobs differing only up there collapse onto a tiny range no finalizer can -// spread back out. Varying the top byte of two words is the sharp case. A pairwise avalanche check -// cannot catch this, since a finalizer scatters any single difference across all bits no matter how -// weak the mixing behind it. -static int HashWordFamily( void ) -{ - enum - { - blobSize = 16, - familySize = 256 * 256 - }; - - HashProbe probe = ProbeBegin( familySize ); - - uint8_t blob[blobSize]; - for ( int i = 0; i < blobSize; ++i ) - { - blob[i] = (uint8_t)( 0x5A + i ); - } - - for ( int a = 0; a < 256; ++a ) - { - for ( int b = 0; b < 256; ++b ) - { - blob[7] = (uint8_t)a; - blob[15] = (uint8_t)b; - ProbeAdd( &probe, b3Hash64NonZero( blob, blobSize ), NULL, 0 ); - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == familySize ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Every input bit must move the digest, at every offset. Flipping one byte in one position is a -// weak check: a mixer can pass it while still being blind to whole regions of a longer blob. -static int HashBitSweep( void ) -{ - enum - { - blobSize = 32, - bitCount = 8 * blobSize - }; - - HashProbe probe = ProbeBegin( bitCount + 1 ); - - uint8_t blob[blobSize]; - for ( int i = 0; i < blobSize; ++i ) - { - blob[i] = (uint8_t)( 0xA5 ^ ( i * 17 ) ); - } - - ProbeAdd( &probe, b3Hash64NonZero( blob, blobSize ), NULL, 0 ); - - for ( int bit = 0; bit < bitCount; ++bit ) - { - uint8_t mask = (uint8_t)( 1u << ( bit & 7 ) ); - blob[bit >> 3] ^= mask; - ProbeAdd( &probe, b3Hash64NonZero( blob, blobSize ), NULL, 0 ); - blob[bit >> 3] ^= mask; - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == bitCount + 1 ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Baked blobs carry explicit padding and unused array slots, so long runs of zeros are common and -// content alone cannot separate them. Length has to reach the digest. -static int HashZeroLengths( void ) -{ - enum - { - maxLength = 4096 - }; - - uint8_t* zeros = B3_ALLOC( uint8_t, maxLength ); - memset( zeros, 0, maxLength ); - - HashProbe probe = ProbeBegin( maxLength ); - for ( int n = 0; n < maxLength; ++n ) - { - ProbeAdd( &probe, b3Hash64NonZero( zeros, n ), NULL, 0 ); - } - - HashResult result = ProbeEnd( &probe ); - B3_FREE( zeros, uint8_t, maxLength ); - - ENSURE( result.overflow == false ); - ENSURE( result.count == maxLength ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Mirrored geometry differs from its original only in sign bits, which sit at the top of every -// float. A mixer that cannot carry high bits downward maps the whole family onto a few digests. -static int HashFloatSigns( void ) -{ - enum - { - floatCount = 12, - comboCount = 1 << floatCount - }; - - HashProbe probe = ProbeBegin( comboCount ); - - float values[floatCount]; - for ( int i = 0; i < floatCount; ++i ) - { - values[i] = 1.0f + 0.25f * (float)i; - } - - for ( int mask = 0; mask < comboCount; ++mask ) - { - float flipped[floatCount]; - for ( int i = 0; i < floatCount; ++i ) - { - flipped[i] = ( mask & ( 1 << i ) ) != 0 ? -values[i] : values[i]; - } - - ProbeAdd( &probe, b3Hash64NonZero( (const uint8_t*)flipped, (int)sizeof( flipped ) ), NULL, 0 ); - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == comboCount ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Procedurally placed vertices land one ulp apart. Those blobs differ in a single low mantissa bit -// buried in a long run of identical bytes. -static int HashFloatUlp( void ) -{ - enum - { - floatCount = 64 - }; - - HashProbe probe = ProbeBegin( floatCount + 1 ); - - float values[floatCount]; - for ( int i = 0; i < floatCount; ++i ) - { - values[i] = 100.0f + (float)i; - } - - ProbeAdd( &probe, b3Hash64NonZero( (const uint8_t*)values, (int)sizeof( values ) ), NULL, 0 ); - - for ( int i = 0; i < floatCount; ++i ) - { - float saved = values[i]; - uint32_t bits; - memcpy( &bits, &saved, sizeof( bits ) ); - bits += 1; - memcpy( values + i, &bits, sizeof( bits ) ); - - ProbeAdd( &probe, b3Hash64NonZero( (const uint8_t*)values, (int)sizeof( values ) ), NULL, 0 ); - values[i] = saved; - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == floatCount + 1 ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Real baked hulls. Every box shares its entire topology section and differs in a handful of floats, -// which is the closest thing the engine produces to a worst case for a content hash. -static int HashBoxHulls( void ) -{ - enum - { - steps = 16 - }; - - HashProbe probe = ProbeBegin( steps * steps * steps ); - - for ( int i = 0; i < steps; ++i ) - { - for ( int j = 0; j < steps; ++j ) - { - for ( int k = 0; k < steps; ++k ) - { - b3BoxHull box = b3MakeBoxHull( 0.5f + 0.25f * (float)i, 0.5f + 0.25f * (float)j, 0.5f + 0.25f * (float)k ); - ProbeAdd( &probe, box.base.hash, &box, box.base.byteCount ); - } - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == steps * steps * steps ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Same box, moved and turned. The extent bytes are identical across the family so the hash has to -// separate these on transform alone. -static int HashTransformedBoxHulls( void ) -{ - enum - { - steps = 12 - }; - - HashProbe probe = ProbeBegin( steps * steps ); - - for ( int i = 0; i < steps; ++i ) - { - for ( int j = 0; j < steps; ++j ) - { - b3Vec3 axis = b3Normalize( (b3Vec3){ 1.0f, 0.5f + 0.1f * (float)j, 0.25f } ); - b3Transform transform = { - .p = { 0.125f * (float)i, -0.25f * (float)j, 0.5f * (float)( i + j ) }, - .q = b3MakeQuatFromAxisAngle( axis, 0.05f * (float)( i * steps + j ) ), - }; - - b3BoxHull box = b3MakeTransformedBoxHull( 1.0f, 2.0f, 3.0f, transform ); - ProbeAdd( &probe, box.base.hash, &box, box.base.byteCount ); - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count == steps * steps ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Tessellated hulls across a parameter sweep. Neighboring parameters produce blobs that agree -// almost everywhere, including identical vertex counts and topology. -static int HashProceduralHulls( void ) -{ - HashProbe probe = ProbeBegin( 1024 ); - - for ( int sides = 3; sides <= 18; ++sides ) - { - for ( int r = 1; r <= 5; ++r ) - { - for ( int h = 1; h <= 4; ++h ) - { - b3HullData* cylinder = b3CreateCylinder( 0.5f * (float)h, 0.25f * (float)r, 0.0f, sides ); - if ( cylinder != NULL ) - { - ProbeAdd( &probe, cylinder->hash, cylinder, cylinder->byteCount ); - b3DestroyHull( cylinder ); - } - - // Cones need at least four slices - if ( sides >= 4 ) - { - b3HullData* cone = b3CreateCone( 0.5f * (float)h, 0.25f * (float)r, 0.1f * (float)r, sides ); - if ( cone != NULL ) - { - ProbeAdd( &probe, cone->hash, cone, cone->byteCount ); - b3DestroyHull( cone ); - } - } - } - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count > 0 ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Height fields are mostly a flat array of heights, so grids of nearby dimensions differ in very -// little beyond their counts. Small wave grids flatten to the plain grid, which is why the probe -// has to tell a duplicate blob apart from a collision. -static int HashHeightFields( void ) -{ - HashProbe probe = ProbeBegin( 512 ); - - for ( int rows = 2; rows <= 14; ++rows ) - { - for ( int cols = 2; cols <= 14; ++cols ) - { - b3Vec3 scale = { 1.0f, 1.0f, 1.0f }; - - b3HeightFieldData* grid = b3CreateGrid( rows, cols, scale, false ); - ProbeAdd( &probe, grid->hash, grid, grid->byteCount ); - b3DestroyHeightField( grid ); - - b3HeightFieldData* wave = b3CreateWave( rows, cols, scale, 0.25f * (float)rows, 0.125f * (float)cols, false ); - ProbeAdd( &probe, wave->hash, wave, wave->byteCount ); - b3DestroyHeightField( wave ); - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count > 0 ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Meshes carry a baked BVH, so most of the blob is derived data that moves in lockstep with small -// parameter changes. -static int HashMeshes( void ) -{ - HashProbe probe = ProbeBegin( 256 ); - - for ( int x = 2; x <= 10; ++x ) - { - for ( int z = 2; z <= 10; ++z ) - { - b3MeshData* grid = b3CreateGridMesh( x, z, 1.0f, 1, false ); - ProbeAdd( &probe, grid->hash, grid, grid->byteCount ); - b3DestroyMesh( grid ); - } - } - - for ( int radial = 3; radial <= 12; ++radial ) - { - for ( int tubular = 3; tubular <= 12; ++tubular ) - { - b3MeshData* torus = b3CreateTorusMesh( radial, tubular, 1.0f, 0.25f ); - ProbeAdd( &probe, torus->hash, torus, torus->byteCount ); - b3DestroyMesh( torus ); - } - } - - HashResult result = ProbeEnd( &probe ); - ENSURE( result.overflow == false ); - ENSURE( result.count > 0 ); - ENSURE( result.sawZero == false ); - ENSURE( result.collision == 0 ); - return 0; -} - -// Voxel colliders sit on a regular grid, so their coordinate floats vary only in high bits. The -// hull database takes its home bucket from the low bits of the hash, so a mixer that cannot carry -// high bits downward funnels every hull into one bucket. The digests stay distinct throughout, -// which is exactly why the collision tests above cannot see it. From issue 120. -static int HashVoxelDispersion( void ) -{ - enum - { - hullCount = 3000, - lowBits = 13, - lowCount = 1 << lowBits - }; - - bool* seen = B3_ALLOC( bool, lowCount ); - memset( seen, 0, lowCount * sizeof( bool ) ); - - int distinctLow = 0; - for ( int i = 0; i < hullCount; ++i ) - { - const float cell = 0.25f; - b3Vec3 offset = { - (float)( i % 15 ) * cell, - (float)( ( i / 15 ) % 20 ) * cell, - (float)( i / 300 ) * cell, - }; - - b3BoxHull hull = b3MakeOffsetBoxHull( 0.5f * cell, 0.5f * cell, 0.5f * cell, offset ); - - int low = (int)( hull.base.hash & ( lowCount - 1 ) ); - if ( seen[low] == false ) - { - seen[low] = true; - distinctLow += 1; - } - } - - B3_FREE( seen, bool, lowCount ); - - // Filling 8192 slots with 3000 draws tops out near 2500. The 32 bit hash this replaced reached 1. - ENSURE( distinctLow > hullCount / 2 ); - return 0; -} - -// The consequence of the above, measured where it hurt. These hulls drove the world hull database -// to two million buckets and a hundred and fifty milliseconds, since every insert walked one chain. -static int HashVoxelHullDatabase( void ) -{ - enum - { - hullCount = 3000 - }; - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3World* world = b3GetWorldFromId( worldId ); - b3HullMap* map = (b3HullMap*)world->hullDatabase; - - bool created = true; - for ( int i = 0; i < hullCount; ++i ) - { - const float cell = 0.25f; - b3Vec3 offset = { - (float)( i % 15 ) * cell, - (float)( ( i / 15 ) % 20 ) * cell, - (float)( i / 300 ) * cell, - }; - - b3BoxHull hull = b3MakeOffsetBoxHull( 0.5f * cell, 0.5f * cell, 0.5f * cell, offset ); - b3ShapeId shapeId = b3CreateHullShape( bodyId, &shapeDef, &hull.base ); - if ( shapeId.index1 == 0 ) - { - created = false; - break; - } - } - - size_t entryCount = b3HullMap_size( map ); - size_t bucketCount = b3HullMap_bucket_count( map ); - - b3DestroyWorld( worldId ); - - ENSURE( created ); - ENSURE( entryCount == hullCount ); - - // Healthy growth settles at 4096 for this many distinct hulls - ENSURE( bucketCount <= 4 * hullCount ); - return 0; -} - -// Identical input must bake to an identical hash, or dedup silently stops working. -static int HashStability( void ) -{ - b3BoxHull box1 = b3MakeBoxHull( 1.0f, 2.0f, 3.0f ); - b3BoxHull box2 = b3MakeBoxHull( 1.0f, 2.0f, 3.0f ); - ENSURE( box1.base.hash == box2.base.hash ); - - b3HullData* cylinder1 = b3CreateCylinder( 1.0f, 0.5f, 0.0f, 12 ); - b3HullData* cylinder2 = b3CreateCylinder( 1.0f, 0.5f, 0.0f, 12 ); - bool sameHash = cylinder1->hash == cylinder2->hash; - bool sameSize = cylinder1->byteCount == cylinder2->byteCount; - bool sameBytes = sameSize && memcmp( cylinder1, cylinder2, (size_t)cylinder1->byteCount ) == 0; - b3DestroyHull( cylinder1 ); - b3DestroyHull( cylinder2 ); - - ENSURE( sameHash ); - ENSURE( sameBytes ); - - // An empty blob has no content to mix, so it takes the reserved value - ENSURE( b3Hash64NonZero( NULL, 0 ) == 1 ); - return 0; -} - -int HashTest( void ) -{ - RUN_SUBTEST( HashWordFamily ); - RUN_SUBTEST( HashBitSweep ); - RUN_SUBTEST( HashZeroLengths ); - RUN_SUBTEST( HashFloatSigns ); - RUN_SUBTEST( HashFloatUlp ); - RUN_SUBTEST( HashBoxHulls ); - RUN_SUBTEST( HashTransformedBoxHulls ); - RUN_SUBTEST( HashProceduralHulls ); - RUN_SUBTEST( HashHeightFields ); - RUN_SUBTEST( HashMeshes ); - RUN_SUBTEST( HashVoxelDispersion ); - RUN_SUBTEST( HashVoxelHullDatabase ); - RUN_SUBTEST( HashStability ); - return 0; -} diff --git a/test/test_height_field.c b/test/test_height_field.c index 55621e9..2dd3fc6 100644 --- a/test/test_height_field.c +++ b/test/test_height_field.c @@ -11,7 +11,6 @@ #include "box3d/math_functions.h" #include -#include #include static int HeightFieldCreate( void ) @@ -144,7 +143,7 @@ static int RayCastFlatField( void ) b3HeightFieldData* hf = b3CreateHeightField( &def ); - // Origin sits clearly inside triangle 0 of cell (1, 1). Off the cell + // Origin sits clearly inside triangle 0 of cell (1, 1) — off the cell // diagonal x+z = 3. The translation overshoots the surface so the hit // fraction is strictly less than maxFraction. b3RayCastInput input = { 0 }; @@ -169,13 +168,13 @@ static int OverlapAtSurface( void ) b3Vec3 scale = { 1.0f, 1.0f, 1.0f }; b3HeightFieldData* hf = b3CreateGrid( 4, 4, scale, false ); - // Sphere center 1.0 above the surface, radius 0.5. Clear gap. + // Sphere center 1.0 above the surface, radius 0.5 — clear gap. b3Vec3 above = { 1.5f, 1.0f, 1.5f }; b3ShapeProxy proxyAbove = { &above, 1, 0.5f }; bool hitAbove = b3OverlapHeightField( hf, b3Transform_identity, &proxyAbove ); ENSURE( hitAbove == false ); - // Sphere centered on the surface. Radius pokes through. + // Sphere centered on the surface — radius pokes through. b3Vec3 through = { 1.5f, 0.0f, 1.5f }; b3ShapeProxy proxyThrough = { &through, 1, 0.5f }; bool hitThrough = b3OverlapHeightField( hf, b3Transform_identity, &proxyThrough ); @@ -432,7 +431,7 @@ static int ShapeCastBruteForce( void ) // Brute-force ray cast: cast the ray against every (non-hole) triangle and keep // the closest hit. b3GetHeightFieldTriangle returns vertices in the same winding // order that b3ShapeCastHeightField feeds to b3IntersectRayTriangle, so this is a -// pure traversal/culling check. The per-triangle math is identical. +// pure traversal/culling check — the per-triangle math is identical. static b3CastOutput BruteForceRayCast( const b3HeightFieldData* hf, const b3RayCastInput* input ) { b3CastOutput best = { 0 }; @@ -527,293 +526,6 @@ static int RayCastBruteForce( void ) return 0; } -// Flat 3x3 vertex field at y = 0, one cell material per entry. Caller destroys. -static b3HeightFieldData* MakeFlatField( uint8_t* materials, bool clockwise ) -{ - float heights[9] = { 0 }; - - b3HeightFieldDef def = { 0 }; - def.heights = heights; - def.materialIndices = materials; - def.scale = (b3Vec3){ 1.0f, 1.0f, 1.0f }; - def.countX = 3; - def.countZ = 3; - def.globalMinimumHeight = -1.0f; - def.globalMaximumHeight = 1.0f; - def.clockwiseWinding = clockwise; - - return b3CreateHeightField( &def ); -} - -static int ShapeCastBackside( void ) -{ - uint8_t materials[4] = { 1, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, false ); - - // Falling onto the front (upper) face reports the hit, the triangle, and its material. - // The surface sits at y = 0, so a sphere of radius 0.2 stops with its center at y = 0.2. - b3Vec3 above = { 0.3f, 5.0f, 0.25f }; - b3ShapeCastInput down = { 0 }; - down.proxy = (b3ShapeProxy){ &above, 1, 0.2f }; - down.translation = (b3Vec3){ 0.0f, -10.0f, 0.0f }; - down.maxFraction = 1.0f; - - b3CastOutput out = b3ShapeCastHeightField( hf, &down ); - ENSURE( out.hit == true ); - ENSURE_SMALL( out.fraction - 0.48f, 1e-2f ); - ENSURE( out.normal.y > 0.99f ); - ENSURE( out.triangleIndex == 0 || out.triangleIndex == 1 ); - ENSURE( out.materialIndex == 1 ); - - // Rising from behind the face is culled - b3Vec3 below = { 0.3f, -5.0f, 0.25f }; - b3ShapeCastInput up = { 0 }; - up.proxy = (b3ShapeProxy){ &below, 1, 0.2f }; - up.translation = (b3Vec3){ 0.0f, 10.0f, 0.0f }; - up.maxFraction = 1.0f; - - b3CastOutput missed = b3ShapeCastHeightField( hf, &up ); - ENSURE( missed.hit == false ); - - b3DestroyHeightField( hf ); - return 0; -} - -// A clockwise height field faces down, see HeightFieldWinding. Shape cast backside -// culling must respect the flag: a rising sphere hits from below, not from above. -static int ShapeCastClockwiseWinding( void ) -{ - uint8_t materials[4] = { 1, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, true ); - - b3Vec3 below = { 0.3f, -5.0f, 0.25f }; - b3ShapeCastInput up = { 0 }; - up.proxy = (b3ShapeProxy){ &below, 1, 0.2f }; - up.translation = (b3Vec3){ 0.0f, 10.0f, 0.0f }; - up.maxFraction = 1.0f; - - b3CastOutput out = b3ShapeCastHeightField( hf, &up ); - ENSURE( out.hit == true ); - ENSURE_SMALL( out.fraction - 0.48f, 1e-2f ); - ENSURE( out.normal.y < -0.99f ); - ENSURE( out.triangleIndex == 0 || out.triangleIndex == 1 ); - ENSURE( out.materialIndex == 1 ); - - b3Vec3 above = { 0.3f, 5.0f, 0.25f }; - b3ShapeCastInput down = { 0 }; - down.proxy = (b3ShapeProxy){ &above, 1, 0.2f }; - down.translation = (b3Vec3){ 0.0f, -10.0f, 0.0f }; - down.maxFraction = 1.0f; - - b3CastOutput missed = b3ShapeCastHeightField( hf, &down ); - ENSURE( missed.hit == false ); - - b3DestroyHeightField( hf ); - return 0; -} - -// Ray casts run through the shape cast. The default winding faces up, so a ray from below is the -// back side and gets culled. -static int RayCastBackside( void ) -{ - uint8_t materials[4] = { 1, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, false ); - - b3RayCastInput down = { 0 }; - down.origin = (b3Vec3){ 0.3f, 5.0f, 0.25f }; - down.translation = (b3Vec3){ 0.0f, -10.0f, 0.0f }; - down.maxFraction = 1.0f; - - b3CastOutput out = b3RayCastHeightField( hf, &down ); - ENSURE( out.hit == true ); - ENSURE_SMALL( out.fraction - 0.5f, 1e-3f ); - ENSURE( out.normal.y > 0.99f ); - ENSURE( out.triangleIndex == 0 || out.triangleIndex == 1 ); - ENSURE( out.materialIndex == 1 ); - - b3RayCastInput up = { 0 }; - up.origin = (b3Vec3){ 0.3f, -5.0f, 0.25f }; - up.translation = (b3Vec3){ 0.0f, 10.0f, 0.0f }; - up.maxFraction = 1.0f; - - b3CastOutput missed = b3RayCastHeightField( hf, &up ); - ENSURE( missed.hit == false ); - - b3DestroyHeightField( hf ); - return 0; -} - -// A clockwise field faces down. The winding swap already flips the triangle, so the ray normal -// must not be flipped a second time. -static int RayCastClockwiseWinding( void ) -{ - uint8_t materials[4] = { 1, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, true ); - - b3RayCastInput up = { 0 }; - up.origin = (b3Vec3){ 0.3f, -5.0f, 0.25f }; - up.translation = (b3Vec3){ 0.0f, 10.0f, 0.0f }; - up.maxFraction = 1.0f; - - b3CastOutput out = b3RayCastHeightField( hf, &up ); - ENSURE( out.hit == true ); - ENSURE_SMALL( out.fraction - 0.5f, 1e-3f ); - ENSURE( out.normal.y < -0.99f ); - ENSURE( out.triangleIndex == 0 || out.triangleIndex == 1 ); - ENSURE( out.materialIndex == 1 ); - - b3RayCastInput down = { 0 }; - down.origin = (b3Vec3){ 0.3f, 5.0f, 0.25f }; - down.translation = (b3Vec3){ 0.0f, -10.0f, 0.0f }; - down.maxFraction = 1.0f; - - b3CastOutput missed = b3RayCastHeightField( hf, &down ); - ENSURE( missed.hit == false ); - - b3DestroyHeightField( hf ); - return 0; -} - -#define BUMPY_COUNT_X 9 -#define BUMPY_COUNT_Z 7 - -// A bumpy field with holes, so cells have every mix of interior, border and hole neighbors -static b3HeightFieldData* MakeBumpyField( bool clockwise ) -{ - float heights[BUMPY_COUNT_X * BUMPY_COUNT_Z]; - for ( int i = 0; i < BUMPY_COUNT_Z; ++i ) - { - for ( int j = 0; j < BUMPY_COUNT_X; ++j ) - { - heights[i * BUMPY_COUNT_X + j] = sinf( 0.9f * (float)i ) * cosf( 0.7f * (float)j ) + 0.1f * (float)( ( i * j ) % 3 ); - } - } - - uint8_t materials[( BUMPY_COUNT_X - 1 ) * ( BUMPY_COUNT_Z - 1 )] = { 0 }; - materials[9] = B3_HEIGHT_FIELD_HOLE; - materials[20] = B3_HEIGHT_FIELD_HOLE; - materials[47] = B3_HEIGHT_FIELD_HOLE; - - b3HeightFieldDef def = { 0 }; - def.heights = heights; - def.materialIndices = materials; - def.scale = (b3Vec3){ 1.5f, 0.8f, 0.5f }; - def.countX = BUMPY_COUNT_X; - def.countZ = BUMPY_COUNT_Z; - def.globalMinimumHeight = -2.0f; - def.globalMaximumHeight = 2.0f; - def.clockwiseWinding = clockwise; - return b3CreateHeightField( &def ); -} - -static bool IsHole( const b3HeightFieldData* hf, int triangleIndex ) -{ - return b3GetHeightFieldMaterial( hf, triangleIndex ) == B3_HEIGHT_FIELD_HOLE; -} - -static b3Vec3 TriangleNormal( b3Triangle triangle ) -{ - b3Vec3 e1 = b3Sub( triangle.vertices[1], triangle.vertices[0] ); - b3Vec3 e2 = b3Sub( triangle.vertices[2], triangle.vertices[0] ); - return b3Normalize( b3Cross( e1, e2 ) ); -} - -// Neighbors found by brute force over shared grid points must match the grid walk -static int HeightFieldNeighborNormals( void ) -{ - for ( int pass = 0; pass < 2; ++pass ) - { - b3HeightFieldData* hf = MakeBumpyField( pass == 1 ); - int triangleCount = b3GetHeightFieldTriangleCount( hf ); - int interiorCount = 0; - int boundaryCount = 0; - - for ( int i = 0; i < triangleCount; ++i ) - { - if ( IsHole( hf, i ) ) - { - continue; - } - - b3Triangle triangle = b3GetHeightFieldTriangle( hf, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - - for ( int k = 0; k < 3; ++k ) - { - int a = indices[k]; - int b = indices[( k + 1 ) % 3]; - - int neighbor = B3_NULL_INDEX; - for ( int j = 0; j < triangleCount && neighbor == B3_NULL_INDEX; ++j ) - { - if ( j == i || IsHole( hf, j ) ) - { - continue; - } - - b3Triangle other = b3GetHeightFieldTriangle( hf, j ); - int otherIndices[3] = { other.i1, other.i2, other.i3 }; - for ( int m = 0; m < 3; ++m ) - { - if ( otherIndices[m] == b && otherIndices[( m + 1 ) % 3] == a ) - { - neighbor = j; - } - } - } - - b3Vec3 normal; - bool found = b3GetHeightFieldNeighborNormal( hf, i, k, &normal ); - ENSURE( found == ( neighbor != B3_NULL_INDEX ) ); - - if ( found == false ) - { - boundaryCount += 1; - continue; - } - - interiorCount += 1; - b3Vec3 expected = TriangleNormal( b3GetHeightFieldTriangle( hf, neighbor ) ); - ENSURE( b3Dot( normal, expected ) > 0.99999f ); - } - } - - ENSURE( interiorCount > 0 ); - ENSURE( boundaryCount > 0 ); - b3DestroyHeightField( hf ); - } - - return 0; -} - -// The shape level lookup dispatches to the mesh and height field versions -static int NeighborNormalDispatch( void ) -{ - b3HeightFieldData* hf = MakeBumpyField( false ); - b3Shape heightShape = { 0 }; - heightShape.type = b3_heightShape; - heightShape.heightField = hf; - - b3Vec3 normal1, normal2; - ENSURE( b3GetNeighborNormal( &heightShape, 1, 1, &normal1 ) ); - ENSURE( b3GetHeightFieldNeighborNormal( hf, 1, 1, &normal2 ) ); - ENSURE( normal1.x == normal2.x && normal1.y == normal2.y && normal1.z == normal2.z ); - b3DestroyHeightField( hf ); - - b3MeshData* data = b3CreateWaveMesh( 4, 4, 1.0f, 0.5f, 0.2f, 0.15f ); - b3Shape meshShape = { 0 }; - meshShape.type = b3_meshShape; - meshShape.mesh = (b3Mesh){ data, { 2.0f, 0.5f, -1.0f } }; - - bool found1 = b3GetNeighborNormal( &meshShape, 5, 1, &normal1 ); - bool found2 = b3GetMeshNeighborNormal( &meshShape.mesh, 5, 1, &normal2 ); - ENSURE( found1 && found2 ); - ENSURE( normal1.x == normal2.x && normal1.y == normal2.y && normal1.z == normal2.z ); - b3DestroyMesh( data ); - - return 0; -} - int HeightFieldTest( void ) { RUN_SUBTEST( HeightFieldCreate ); @@ -825,12 +537,6 @@ int HeightFieldTest( void ) RUN_SUBTEST( ShapeCastVerticalStraddle ); RUN_SUBTEST( ShapeCastBruteForce ); RUN_SUBTEST( RayCastBruteForce ); - RUN_SUBTEST( ShapeCastBackside ); - RUN_SUBTEST( ShapeCastClockwiseWinding ); - RUN_SUBTEST( RayCastBackside ); - RUN_SUBTEST( RayCastClockwiseWinding ); - RUN_SUBTEST( HeightFieldNeighborNormals ); - RUN_SUBTEST( NeighborNormalDispatch ); return 0; } diff --git a/test/test_hull.c b/test/test_hull.c index 7696f8c..46ccc84 100644 --- a/test/test_hull.c +++ b/test/test_hull.c @@ -4,12 +4,10 @@ #include "test_macros.h" #include "box3d/collision.h" -#include "box3d/constants.h" #include "box3d/math_functions.h" #include #include -#include #include static const b3Vec3 s_cubeCorners[8] = { @@ -148,13 +146,13 @@ static int CreateHullMaxVertexTest( void ) // Below the floor: clamps up to 4. b3HullData* h2 = b3CreateHull( points, count, 1 ); ENSURE( h2 != NULL ); - ENSURE( h2->vertexCount >= 4 && h2->vertexCount <= B3_MAX_HULL_VERTICES ); + ENSURE( h2->vertexCount >= 4 && h2->vertexCount <= 255 ); b3DestroyHull( h2 ); - // Above the ceiling: clamps down to B3_MAX_HULL_VERTICES. + // Above the ceiling: clamps down to 255. b3HullData* h3 = b3CreateHull( points, count, 1000 ); ENSURE( h3 != NULL ); - ENSURE( h3->vertexCount >= 4 && h3->vertexCount <= B3_MAX_HULL_VERTICES ); + ENSURE( h3->vertexCount >= 4 && h3->vertexCount <= 255 ); b3DestroyHull( h3 ); return 0; @@ -343,8 +341,9 @@ static void FillCubeSample( b3Vec3* points, int count, uint32_t seed ) // 24*M - 48 in src/hull.c::b3ComputeHullWorkSizes) close to their peak by sweeping M // on a dense random sphere. If the peak face/edge count exceeds the cap and the free // list fails to reclaim slots in time, the assertion at src/hull.c::NewFace/NewEdge -// fires (exit code 3). A dense sphere hull is fully triangulated, so F = 2M - 4 and the -// final face limit B3_MAX_HULL_FACES binds well before the vertex or edge limits. +// fires (exit code 3). M is held <= 80 because the finalization stage caps the final +// hull's face/edge count at B3_HULL_LIMIT (255), and a fully-triangulated hull with +// V > 87 vertices has 3V - 6 > 255 edges (src/hull.c:2010 returns NULL). static int CreateHullSphereStressTest( void ) { enum { N = 512 }; @@ -353,8 +352,8 @@ static int CreateHullSphereStressTest( void ) // Multiple seeds exercise different horizon-size / merge-cascade sequences. const uint32_t seeds[] = { 12345u, 1u, 0xdeadbeefu, 0xcafef00du }; - // M kept <= 32 so the final face count 2M - 4 stays under B3_MAX_HULL_FACES - const int M_values[] = { 16, 24, 32 }; + // M kept <= 40: random sphere inputs at higher M exceed the half edge limit of UINT8_MAX + const int M_values[] = { 16, 24, 32, 40 }; for ( int s = 0; s < ARRAY_COUNT( seeds ); ++s ) { @@ -411,107 +410,6 @@ static int CreateHullMergeChurnStressTest( void ) return 0; } -// b3ComputeCosSin is a coarse approximation, so build rotations from libm to keep the -// analytic corner and plane positions exact. -static b3Quat ExactQuat( b3Vec3 axis, float radians ) -{ - float half = 0.5f * radians; - float s = sinf( half ); - return (b3Quat){ { s * axis.x, s * axis.y, s * axis.z }, cosf( half ) }; -} - -// Corner sign pattern baked by b3MakeTransformedBoxHull, in order. -static const b3Vec3 s_boxCornerSigns[8] = { - { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, - { 1.0f, 1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f }, { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, -}; - -// The baked box hull is only exercised elsewhere through mass properties, which are analytic -// and never read boxPoints or boxPlanes. Pin the geometry itself against the transform so an -// axis swap in the point or plane bake cannot pass silently. -static int CheckTransformedBox( b3Vec3 h, b3Transform xf ) -{ - b3BoxHull box = b3MakeTransformedBoxHull( h.x, h.y, h.z, xf ); - - const float tol = 1e-5f; - - // Each corner is the transform of the signed half extent. - for ( int i = 0; i < 8; ++i ) - { - b3Vec3 local = { s_boxCornerSigns[i].x * h.x, s_boxCornerSigns[i].y * h.y, s_boxCornerSigns[i].z * h.z }; - b3Vec3 expected = b3TransformPoint( xf, local ); - ENSURE_SMALL( box.boxPoints[i].x - expected.x, tol ); - ENSURE_SMALL( box.boxPoints[i].y - expected.y, tol ); - ENSURE_SMALL( box.boxPoints[i].z - expected.z, tol ); - } - - // Face normals rotate with the box, offsets carry the rotated normal through the translation. - b3Vec3 localNormals[6] = { - b3Neg( b3Vec3_axisX ), b3Vec3_axisX, b3Neg( b3Vec3_axisY ), b3Vec3_axisY, b3Neg( b3Vec3_axisZ ), b3Vec3_axisZ, - }; - float localOffsets[6] = { h.x, h.x, h.y, h.y, h.z, h.z }; - for ( int i = 0; i < 6; ++i ) - { - b3Vec3 n = b3RotateVector( xf.q, localNormals[i] ); - float offset = localOffsets[i] + b3Dot( n, xf.p ); - ENSURE_SMALL( box.boxPlanes[i].normal.x - n.x, tol ); - ENSURE_SMALL( box.boxPlanes[i].normal.y - n.y, tol ); - ENSURE_SMALL( box.boxPlanes[i].normal.z - n.z, tol ); - ENSURE_SMALL( box.boxPlanes[i].offset - offset, tol ); - } - - // SoA vertex mirrors match the AoS points on all eight lanes. - for ( int i = 0; i < 8; ++i ) - { - ENSURE_SMALL( box.vx[i] - box.boxPoints[i].x, tol ); - ENSURE_SMALL( box.vy[i] - box.boxPoints[i].y, tol ); - ENSURE_SMALL( box.vz[i] - box.boxPoints[i].z, tol ); - } - - // SoA normal mirrors carry the six real faces and zero the two pad lanes. - for ( int i = 0; i < 6; ++i ) - { - ENSURE_SMALL( box.nx[i] - box.boxPlanes[i].normal.x, tol ); - ENSURE_SMALL( box.ny[i] - box.boxPlanes[i].normal.y, tol ); - ENSURE_SMALL( box.nz[i] - box.boxPlanes[i].normal.z, tol ); - } - ENSURE( box.nx[6] == 0.0f && box.nx[7] == 0.0f ); - ENSURE( box.ny[6] == 0.0f && box.ny[7] == 0.0f ); - ENSURE( box.nz[6] == 0.0f && box.nz[7] == 0.0f ); - - // The stored AABB bounds every baked corner. - b3AABB pointBox = b3MakeAABB( box.boxPoints, 8, 0.0f ); - ENSURE( b3AABB_Contains( box.base.aabb, pointBox ) ); - - return 0; -} - -static int TransformedBoxHullTest( void ) -{ - b3Vec3 h = { 0.25f, 0.5f, 0.3f }; - - // Identity. - if ( CheckTransformedBox( h, b3Transform_identity ) ) - return 1; - - // Translation only. - b3Transform translated = { { 0.4f, -0.7f, 0.1f }, b3Quat_identity }; - if ( CheckTransformedBox( h, translated ) ) - return 1; - - // Rotation only. A quarter turn about Y swaps the world X and Z extents. - b3Transform rotated = { b3Vec3_zero, ExactQuat( b3Vec3_axisY, 0.25f * B3_PI ) }; - if ( CheckTransformedBox( h, rotated ) ) - return 1; - - // Translation and rotation together. - b3Transform transformed = { { 3.0f, -2.0f, 1.5f }, ExactQuat( b3Vec3_axisZ, 0.25f * B3_PI ) }; - if ( CheckTransformedBox( h, transformed ) ) - return 1; - - return 0; -} - static int CreateHullDegenerateTest( void ) { // Real (non-null) buffer; pointCount < 4 cases are guarded inside Construct(). @@ -546,338 +444,6 @@ static int CreateHullDegenerateTest( void ) return 0; } -static void FillPoints2D( b3Point2D* pts, const b3Vec2* input, int count ) -{ - for ( int i = 0; i < count; ++i ) - { - pts[i].p = input[i]; - pts[i].separation = 0.0f; - pts[i].originalIndex = i; - } -} - -static float Hull2DArea( const b3Point2D* hull, int count ) -{ - float sum = 0.0f; - for ( int i = 0; i < count; ++i ) - { - int next = ( i + 1 ) % count; - sum += hull[i].p.x * hull[next].p.y - hull[i].p.y * hull[next].p.x; - } - - return 0.5f * sum; -} - -// Interior points contribute no area, so they must not survive the hull. -static int Hull2DSquareTest( void ) -{ - b3Vec2 input[8] = { - { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }, - { 0.0f, 0.0f }, { 0.5f, 0.25f }, { -0.3f, 0.6f }, { 0.1f, -0.4f }, - }; - - b3Point2D pts[8]; - b3Point2D hull[16]; - FillPoints2D( pts, input, 8 ); - - int count = b3Hull2D( pts, 8, hull, 0 ); - ENSURE( count == 4 ); - - // The reduction code assumes counter clockwise winding - ENSURE( Hull2DArea( hull, count ) > 0.0f ); - - bool onHull[8] = { false }; - for ( int i = 0; i < count; ++i ) - { - ENSURE( 0 <= hull[i].originalIndex && hull[i].originalIndex < 8 ); - onHull[hull[i].originalIndex] = true; - } - - for ( int i = 0; i < 4; ++i ) - { - ENSURE( onHull[i] == true ); - } - - for ( int i = 4; i < 8; ++i ) - { - ENSURE( onHull[i] == false ); - } - - return 0; -} - -static int Hull2DCollinearTest( void ) -{ - b3Vec2 input[5] = { - { 0.0f, 0.0f }, { 1.0f, 0.0f }, { 2.0f, 0.0f }, { 3.0f, 0.0f }, { 4.0f, 0.0f }, - }; - - b3Point2D pts[5]; - b3Point2D hull[10]; - FillPoints2D( pts, input, 5 ); - - ENSURE( b3Hull2D( pts, 5, hull, 0 ) == 2 ); - - return 0; -} - -// Coincident points weld and the lower input index wins, so a sort order change cannot -// swap which of the two survives. -static int Hull2DWeldTest( void ) -{ - float offset = 0.1f * B3_LINEAR_SLOP; - - b3Vec2 input[5] = { - { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }, { -1.0f + offset, -1.0f + offset }, - }; - - b3Point2D pts[5]; - b3Point2D hull[10]; - FillPoints2D( pts, input, 5 ); - - int count = b3Hull2D( pts, 5, hull, 0 ); - ENSURE( count == 4 ); - - for ( int i = 0; i < count; ++i ) - { - ENSURE( hull[i].originalIndex != 4 ); - } - - return 0; -} - -static int SimplifyHull2DTargetTest( void ) -{ - b3Point2D pts[20]; - b3Point2D hull[40]; - - for ( int i = 0; i < 20; ++i ) - { - float angle = 2.0f * B3_PI * (float)i / 20.0f; - pts[i].p = (b3Vec2){ cosf( angle ), sinf( angle ) }; - pts[i].separation = 0.0f; - pts[i].originalIndex = i; - } - - int hullCount = b3Hull2D( pts, 20, hull, 0 ); - ENSURE( hullCount == 20 ); - - int count = b3SimplifyHull2D( hull, hullCount, 6 ); - ENSURE( count == 6 ); - ENSURE( Hull2DArea( hull, count ) > 0.0f ); - - return 0; -} - -static int SimplifyHull2DNoopTest( void ) -{ - b3Vec2 input[4] = { - { -1.0f, -1.0f }, - { 1.0f, -1.0f }, - { 1.0f, 1.0f }, - { -1.0f, 1.0f }, - }; - - b3Point2D pts[4]; - b3Point2D hull[8]; - FillPoints2D( pts, input, 4 ); - - int hullCount = b3Hull2D( pts, 4, hull, 0 ); - ENSURE( hullCount == 4 ); - - ENSURE( b3SimplifyHull2D( hull, hullCount, 8 ) == 4 ); - ENSURE( b3SimplifyHull2D( hull, hullCount, 4 ) == 4 ); - - return 0; -} - -// The surviving point set must not depend on the order the points arrive in. The reduction -// runs inside the solver, so an input order dependence would show up as a determinism bug. -static int Hull2DOrderTest( void ) -{ - b3Vec2 input[8] = { - { -2.0f, -1.0f }, { 0.0f, -1.5f }, { 2.0f, -1.0f }, { 2.5f, 0.5f }, - { 1.0f, 2.0f }, { -1.0f, 1.8f }, { -2.5f, 0.4f }, { 0.2f, 0.1f }, - }; - - int permutation[8] = { 5, 2, 7, 0, 4, 6, 1, 3 }; - - b3Point2D pts[8]; - b3Point2D hull[16]; - FillPoints2D( pts, input, 8 ); - - int count1 = b3Hull2D( pts, 8, hull, 0 ); - ENSURE( count1 == 7 ); - - bool onHull1[8] = { false }; - for ( int i = 0; i < count1; ++i ) - { - onHull1[hull[i].originalIndex] = true; - } - - b3Point2D shuffled[8]; - b3Point2D shuffledHull[16]; - for ( int i = 0; i < 8; ++i ) - { - shuffled[i].p = input[permutation[i]]; - shuffled[i].separation = 0.0f; - shuffled[i].originalIndex = i; - } - - int count2 = b3Hull2D( shuffled, 8, shuffledHull, 0 ); - ENSURE( count2 == count1 ); - - bool onHull2[8] = { false }; - for ( int i = 0; i < count2; ++i ) - { - onHull2[permutation[shuffledHull[i].originalIndex]] = true; - } - - for ( int i = 0; i < 8; ++i ) - { - ENSURE( onHull1[i] == onHull2[i] ); - } - - return 0; -} - -// Float rounding can call the middle of three nearly collinear points a left turn in both chains. -// Listing it twice gave the mesh manifold a duplicate point. -static int Hull2DNearCollinearTest( void ) -{ - b3Vec2 input[3] = { - { 0.42742428183555603f, -0.9914372563362122f }, - { 0.8582707643508911f, -0.7915351390838623f }, - { 1.5856003761291504f, -0.45407217741012573f }, - }; - - b3Point2D pts[3]; - b3Point2D hull[6]; - FillPoints2D( pts, input, 3 ); - - int count = b3Hull2D( pts, 3, hull, 0 ); - ENSURE( 2 <= count && count <= 3 ); - - for ( int i = 0; i < count; ++i ) - { - for ( int j = i + 1; j < count; ++j ) - { - ENSURE( hull[i].originalIndex != hull[j].originalIndex ); - } - } - - return 0; -} - -// A 3 by 3 grid has three points on each side. Only the corners are strict hull vertices. -static int Hull2DKeepCollinearTest( void ) -{ - b3Vec2 input[9]; - for ( int i = 0; i < 9; ++i ) - { - input[i] = (b3Vec2){ (float)( i % 3 ), (float)( i / 3 ) }; - } - - b3Point2D pts[9]; - b3Point2D hull[18]; - FillPoints2D( pts, input, 9 ); - ENSURE( b3Hull2D( pts, 9, hull, 0 ) == 4 ); - - FillPoints2D( pts, input, 9 ); - int count = b3Hull2D( pts, 9, hull, b3_hull2DKeepCollinear ); - ENSURE( count == 8 ); - ENSURE( Hull2DArea( hull, count ) > 0.0f ); - - for ( int i = 0; i < count; ++i ) - { - ENSURE( hull[i].originalIndex != 4 ); - } - - // All collinear keeps every point - b3Vec2 line[4] = { { 0.0f, 0.0f }, { 1.0f, 0.0f }, { 2.0f, 0.0f }, { 3.0f, 0.0f } }; - FillPoints2D( pts, line, 4 ); - ENSURE( b3Hull2D( pts, 4, hull, b3_hull2DKeepCollinear ) == 4 ); - - return 0; -} - -// Coincident points under the exact merge: the earlier point survives unless a later one is deeper by -// more than the linear slop. The default weld always keeps the earlier point. -static int Hull2DExactMergeTest( void ) -{ - b3Vec2 input[5] = { - { -1.0f, -1.0f }, { 1.0f, -1.0f }, { 1.0f, 1.0f }, { -1.0f, 1.0f }, { -1.0f, -1.0f }, - }; - - float depths[2] = { 2.0f * B3_LINEAR_SLOP, 0.5f * B3_LINEAR_SLOP }; - int expected[2] = { 4, 0 }; - - for ( int k = 0; k < 2; ++k ) - { - b3Point2D pts[5]; - b3Point2D hull[10]; - FillPoints2D( pts, input, 5 ); - pts[4].separation = -depths[k]; - - int count = b3Hull2D( pts, 5, hull, b3_hull2DExactMerge ); - ENSURE( count == 4 ); - - int survivor = -1; - for ( int i = 0; i < count; ++i ) - { - if ( hull[i].originalIndex == 0 || hull[i].originalIndex == 4 ) - { - survivor = hull[i].originalIndex; - } - } - ENSURE( survivor == expected[k] ); - - FillPoints2D( pts, input, 5 ); - pts[4].separation = -depths[k]; - count = b3Hull2D( pts, 5, hull, 0 ); - ENSURE( count == 4 ); - - for ( int i = 0; i < count; ++i ) - { - ENSURE( hull[i].originalIndex != 4 ); - } - } - - return 0; -} - -// The index order flag returns the same points sorted by input index -static int Hull2DIndexOrderTest( void ) -{ - b3Vec2 input[8] = { - { 1.0f, 2.0f }, { -2.5f, 0.4f }, { 2.0f, -1.0f }, { 0.2f, 0.1f }, - { -2.0f, -1.0f }, { 2.5f, 0.5f }, { 0.0f, -1.5f }, { -1.0f, 1.8f }, - }; - - b3Point2D pts[8]; - b3Point2D hull[16]; - FillPoints2D( pts, input, 8 ); - int count1 = b3Hull2D( pts, 8, hull, 0 ); - - bool onHull[8] = { false }; - for ( int i = 0; i < count1; ++i ) - { - onHull[hull[i].originalIndex] = true; - } - - FillPoints2D( pts, input, 8 ); - int count2 = b3Hull2D( pts, 8, hull, b3_hull2DIndexOrder ); - ENSURE( count2 == count1 ); - - for ( int i = 0; i < count2; ++i ) - { - ENSURE( onHull[hull[i].originalIndex] ); - ENSURE( i == 0 || hull[i - 1].originalIndex < hull[i].originalIndex ); - } - - return 0; -} - int HullTest( void ) { RUN_SUBTEST( CreateHullCubeTest ); @@ -891,17 +457,6 @@ int HullTest( void ) RUN_SUBTEST( CreateHullSphereStressTest ); RUN_SUBTEST( CreateHullMergeChurnStressTest ); RUN_SUBTEST( CreateHullDegenerateTest ); - RUN_SUBTEST( TransformedBoxHullTest ); - RUN_SUBTEST( Hull2DSquareTest ); - RUN_SUBTEST( Hull2DCollinearTest ); - RUN_SUBTEST( Hull2DWeldTest ); - RUN_SUBTEST( Hull2DOrderTest ); - RUN_SUBTEST( Hull2DNearCollinearTest ); - RUN_SUBTEST( Hull2DKeepCollinearTest ); - RUN_SUBTEST( Hull2DExactMergeTest ); - RUN_SUBTEST( Hull2DIndexOrderTest ); - RUN_SUBTEST( SimplifyHull2DTargetTest ); - RUN_SUBTEST( SimplifyHull2DNoopTest ); return 0; } diff --git a/test/test_joint.c b/test/test_joint.c index 103e6d7..582e68c 100644 --- a/test/test_joint.c +++ b/test/test_joint.c @@ -296,116 +296,6 @@ static int TestMotorJoint( void ) return FinishJoint( jointId, f.worldId ); } -static int TestMoverJoint( void ) -{ - JointFixture f = CreateJointFixture(); - - b3MoverJointDef def = b3DefaultMoverJointDef(); - SetCommonFrames( &def.base, &f ); - b3JointId jointId = b3CreateMoverJoint( f.worldId, &def ); - - if ( ExerciseJointBase( jointId, f.worldId, f.groundId, f.bodyId, b3_moverJoint ) != 0 ) - { - return 1; - } - - b3Vec3 velocity = { 1.0f, 2.0f, -3.0f }; - b3MoverJoint_SetLinearVelocity( jointId, velocity ); - b3Vec3 gotVelocity = b3MoverJoint_GetLinearVelocity( jointId ); - ENSURE( gotVelocity.x == 1.0f && gotVelocity.y == 2.0f && gotVelocity.z == -3.0f ); - - // The y axis has no force budget, so it must stay at rest while x and z reach the target - float maxForce = 1000.0f; - b3MoverJoint_SetMaxVelocityForce( jointId, maxForce ); - float gotForce = b3MoverJoint_GetMaxVelocityForce( jointId ); - ENSURE( gotForce == 1000.0f ); - - for ( int i = 0; i < 30; ++i ) - { - b3World_Step( f.worldId, 1.0f / 60.0f, 4 ); - } - - b3Vec3 v = b3Body_GetLinearVelocity( f.bodyId ); - ENSURE_SMALL( v.x - 1.0f, 1.0e-4f ); - ENSURE_SMALL( v.y, 1.0e-4f ); - ENSURE_SMALL( v.z + 3.0f, 1.0e-4f ); - - b3Vec3 w = b3Body_GetAngularVelocity( f.bodyId ); - ENSURE( w.x == 0.0f && w.y == 0.0f && w.z == 0.0f ); - - return FinishJoint( jointId, f.worldId ); -} - -// A box held up by a pogo spring under gravity should settle at the rest length -static int TestPogoJoint( void ) -{ - JointFixture f = CreateJointFixture(); - b3World_SetGravity( f.worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); - - float restLength = 2.0f; - float mass = b3Body_GetMass( f.bodyId ); - - b3PogoJointDef def = b3DefaultPogoJointDef(); - def.base.bodyIdA = f.groundId; - def.base.bodyIdB = f.bodyId; - def.base.localFrameA.p = (b3Vec3){ 0.0f, 1.0f, 0.0f }; - def.base.localFrameB.p = (b3Vec3){ 0.0f, 0.0f, 0.0f }; - def.normal = b3Vec3_axisY; - def.restLength = restLength; - def.hertz = 2.0f; - def.dampingRatio = 1.0f; - def.maxCompressionForce = 100.0f * 10.0f * mass; - def.maxTensionForce = 100.0f * 10.0f * mass; - b3JointId jointId = b3CreatePogoJoint( f.worldId, &def ); - - if ( ExerciseJointBase( jointId, f.worldId, f.groundId, f.bodyId, b3_pogoJoint ) != 0 ) - { - return 1; - } - - b3PogoJoint_SetRestLength( jointId, restLength ); - ENSURE( b3PogoJoint_GetRestLength( jointId ) == restLength ); - - b3PogoJoint_SetSpringHertz( jointId, 3.0f ); - ENSURE( b3PogoJoint_GetSpringHertz( jointId ) == 3.0f ); - - b3PogoJoint_SetSpringDampingRatio( jointId, 0.9f ); - ENSURE( b3PogoJoint_GetSpringDampingRatio( jointId ) == 0.9f ); - - float maxTension = 50.0f * 10.0f * mass; - b3PogoJoint_SetMaxTensionForce( jointId, maxTension ); - ENSURE( b3PogoJoint_GetMaxTensionForce( jointId ) == maxTension ); - - float maxCompression = 60.0f * 10.0f * mass; - b3PogoJoint_SetMaxCompressionForce( jointId, maxCompression ); - ENSURE( b3PogoJoint_GetMaxCompressionForce( jointId ) == maxCompression ); - - b3Vec3 normal = b3Normalize( (b3Vec3){ 0.2f, 1.0f, 0.0f } ); - b3PogoJoint_SetNormal( jointId, normal ); - b3Vec3 gotNormal = b3PogoJoint_GetNormal( jointId ); - ENSURE( gotNormal.x == normal.x && gotNormal.y == normal.y && gotNormal.z == normal.z ); - b3PogoJoint_SetNormal( jointId, b3Vec3_axisY ); - - // Starts stretched by one meter - ENSURE_SMALL( b3PogoJoint_GetCurrentLength( jointId ) - 3.0f, 1.0e-5f ); - - for ( int i = 0; i < 300; ++i ) - { - b3World_Step( f.worldId, 1.0f / 60.0f, 4 ); - } - - ENSURE_SMALL( b3PogoJoint_GetCurrentLength( jointId ) - restLength, 0.01f ); - ENSURE_SMALL( b3Body_GetLinearVelocity( f.bodyId ).y, 0.01f ); - - // Holding the weight takes an impulse of m * g * h each sub-step - ENSURE_SMALL( b3PogoJoint_GetImpulse( jointId ) - mass * 10.0f / 240.0f, 0.001f * mass ); - - b3Vec3 force = b3Joint_GetConstraintForce( jointId ); - ENSURE_SMALL( force.y - mass * 10.0f, 0.1f * mass ); - - return FinishJoint( jointId, f.worldId ); -} - static int TestPrismaticJoint( void ) { JointFixture f = CreateJointFixture(); @@ -675,123 +565,17 @@ static int TestWheelJoint( void ) return FinishJoint( jointId, f.worldId ); } -// Issue #117: a joint created with collideConnected false must clear contacts -// that already exist between the two bodies. -static int TestCreateJointClearsContacts( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - bodyDef.position = (b3Pos){ 0.0f, 0.0f, 0.0f }; - b3BodyId bodyIdA = b3CreateBody( worldId, &bodyDef ); - - // Overlapping so a touching contact forms - bodyDef.position = (b3Pos){ 0.5f, 0.0f, 0.0f }; - b3BodyId bodyIdB = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CreateHullShape( bodyIdA, &shapeDef, &box.base ); - b3CreateHullShape( bodyIdB, &shapeDef, &box.base ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( b3Body_GetContactCapacity( bodyIdA ) > 0 ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = bodyIdA; - jointDef.base.bodyIdB = bodyIdB; - jointDef.base.collideConnected = false; - b3CreateRevoluteJoint( worldId, &jointDef ); - - ENSURE( b3Body_GetContactCapacity( bodyIdA ) == 0 ); - ENSURE( b3Body_GetContactCapacity( bodyIdB ) == 0 ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( b3Body_GetContactCapacity( bodyIdA ) == 0 ); - - b3DestroyWorld( worldId ); - return 0; -} - -// Issue #164: a joint with no dynamic body lives in the static set even when one body is an awake -// kinematic. Disabling and enabling that body has to respect this, whether the joint was created -// that way or got there through body type changes. -static int TestNonDynamicJointDisable( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3BodyId bodyIdA = b3CreateBody( worldId, &bodyDef ); - bodyDef.position = (b3Pos){ 2.0f, 0.0f, 0.0f }; - b3BodyId bodyIdB = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeCubeHull( 0.5f ); - b3CreateHullShape( bodyIdA, &shapeDef, &box.base ); - b3CreateHullShape( bodyIdB, &shapeDef, &box.base ); - - b3WeldJointDef jointDef = b3DefaultWeldJointDef(); - jointDef.base.bodyIdA = bodyIdA; - jointDef.base.bodyIdB = bodyIdB; - b3JointId weldId = b3CreateWeldJoint( worldId, &jointDef ); - - b3Body_SetType( bodyIdA, b3_staticBody ); - b3Body_SetType( bodyIdB, b3_kinematicBody ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3Body_Disable( bodyIdB ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - b3Body_Enable( bodyIdB ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( b3Joint_IsValid( weldId ) ); - - b3Body_SetType( bodyIdB, b3_dynamicBody ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( b3Joint_IsAwake( weldId ) ); - - // Created directly between a static and a kinematic body - bodyDef.type = b3_kinematicBody; - bodyDef.position = (b3Pos){ 4.0f, 0.0f, 0.0f }; - b3BodyId bodyIdC = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyIdC, &shapeDef, &box.base ); - - b3RevoluteJointDef revoluteDef = b3DefaultRevoluteJointDef(); - revoluteDef.base.bodyIdA = bodyIdA; - revoluteDef.base.bodyIdB = bodyIdC; - b3JointId revoluteId = b3CreateRevoluteJoint( worldId, &revoluteDef ); - - b3Body_Disable( bodyIdC ); - b3Body_Enable( bodyIdC ); - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( b3Joint_IsAwake( revoluteId ) == false ); - - b3DestroyWorld( worldId ); - return 0; -} - int JointTest( void ) { RUN_SUBTEST( TestParallelJoint ); RUN_SUBTEST( TestDistanceJoint ); RUN_SUBTEST( TestFilterJoint ); RUN_SUBTEST( TestMotorJoint ); - RUN_SUBTEST( TestMoverJoint ); - RUN_SUBTEST( TestPogoJoint ); RUN_SUBTEST( TestPrismaticJoint ); RUN_SUBTEST( TestRevoluteJoint ); RUN_SUBTEST( TestSphericalJoint ); RUN_SUBTEST( TestWeldJoint ); RUN_SUBTEST( TestWheelJoint ); - RUN_SUBTEST( TestCreateJointClearsContacts ); - RUN_SUBTEST( TestNonDynamicJointDisable ); return 0; } diff --git a/test/test_manifold.c b/test/test_manifold.c deleted file mode 100644 index 819440e..0000000 --- a/test/test_manifold.c +++ /dev/null @@ -1,1398 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "test_macros.h" - -#include "box3d/collision.h" -#include "box3d/constants.h" -#include "box3d/math_functions.h" - -#include -#include - -// A face contact keeps the whole clipped polygon when the manifold has room for it, so a build -// with a larger B3_MAX_MANIFOLD_POINTS legitimately reports more than four points. At the default -// this is still an exact count. -#define ENSURE_FACE_POINTS( count ) ENSURE( 4 <= ( count ) && ( count ) <= B3_MAX_MANIFOLD_POINTS ) - -static const float kRoot2 = 1.41421356f; -static const float kHalfRoot2 = 0.70710678f; - -static const b3Vec3 kAxisX = { 1.0f, 0.0f, 0.0f }; -static const b3Vec3 kAxisY = { 0.0f, 1.0f, 0.0f }; -static const b3Vec3 kAxisZ = { 0.0f, 0.0f, 1.0f }; - -// b3ComputeCosSin is a rational approximation good to about 1e-3. That is coarse enough to -// shift an edge off the position the analytic result expects, so these fixtures need libm. -static b3Quat ExactQuat( b3Vec3 axis, float radians ) -{ - float half = 0.5f * radians; - float s = sinf( half ); - return (b3Quat){ { s * axis.x, s * axis.y, s * axis.z }, cosf( half ) }; -} - -static b3Transform ExactRotation( b3Vec3 axis, float radians ) -{ - return (b3Transform){ b3Vec3_zero, ExactQuat( axis, radians ) }; -} - -// Cube A yawed 45 degrees presents an edge along y at x = +h*root2. -// Cube B rolled 45 degrees presents an edge along z at x = -h*root2. -// Sliding B along x makes those two edges the closest features, so the axis of minimum -// penetration is x, the separation is d - 2*h*root2 and the contact point sits at x = d/2. -// Both hulls are far from a face axis here, which keeps the edge query in charge. -static void MakeCrossedEdgeHulls( b3BoxHull* hullA, b3BoxHull* hullB, float halfWidth ) -{ - *hullA = b3MakeTransformedBoxHull( halfWidth, halfWidth, halfWidth, ExactRotation( kAxisY, 0.25f * B3_PI ) ); - *hullB = b3MakeTransformedBoxHull( halfWidth, halfWidth, halfWidth, ExactRotation( kAxisZ, 0.25f * B3_PI ) ); -} - -static b3Transform SlideX( float x ) -{ - return (b3Transform){ { x, 0.0f, 0.0f }, b3Quat_identity }; -} - -static b3Transform SlideY( float y ) -{ - return (b3Transform){ { 0.0f, y, 0.0f }, b3Quat_identity }; -} - -static float MinSeparation( const b3LocalManifold* manifold ) -{ - float minSeparation = FLT_MAX; - for ( int i = 0; i < manifold->pointCount; ++i ) - { - minSeparation = b3MinFloat( minSeparation, manifold->points[i].separation ); - } - - return minSeparation; -} - -// The edge pair axis is built by intersecting the two Gauss map arcs. Walk the crossed edges from -// speculative contact into deep overlap and check the axis, the separation and the point. -static int CrossedEdgeTest( void ) -{ - b3BoxHull hullA, hullB; - MakeCrossedEdgeHulls( &hullA, &hullB, 0.5f ); - - float distances[] = { 1.42f, kRoot2, 1.41f, 1.3f }; - - for ( int i = 0; i < ARRAY_COUNT( distances ); ++i ) - { - float d = distances[i]; - float expected = d - kRoot2; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( d ), &cache ); - - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( manifold.normal.x - 1.0f, 1e-6f ); - ENSURE_SMALL( manifold.normal.y, 1e-6f ); - ENSURE_SMALL( manifold.normal.z, 1e-6f ); - ENSURE_SMALL( manifold.points[0].separation - expected, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.x - 0.5f * d, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.y, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.z, 1e-5f ); - - // The forced edge query must agree with what the full solver chose - b3LocalManifold manual = { 0 }; - manual.points = points; - b3SATCache manualCache = { .type = b3_manualEdgePairAxis }; - b3CollideHulls( &manual, 8, &hullA.base, &hullB.base, SlideX( d ), &manualCache ); - - ENSURE( manual.pointCount == 1 ); - ENSURE_SMALL( manual.points[0].separation - expected, 1e-5f ); - } - - // Beyond the speculative distance the query reports the axis without building a contact. - // The axis carries its own orientation now, so a sign error here would read as deep overlap. - { - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( 1.5f ), &cache ); - - ENSURE( manifold.pointCount == 0 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( cache.separation - ( 1.5f - kRoot2 ), 1e-5f ); - } - - return 0; -} - -// The parallel edge rejection compares dot products against the edge length, so it is a sine -// threshold and must hold at any size. -static int EdgeAxisScaleTest( void ) -{ - float scales[] = { 100.0f, 1.0f, 0.2f }; - - for ( int i = 0; i < ARRAY_COUNT( scales ); ++i ) - { - float s = scales[i]; - b3BoxHull hullA, hullB; - MakeCrossedEdgeHulls( &hullA, &hullB, 0.5f * s ); - - float expected = -0.002f; - float d = s * kRoot2 + expected; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( d ), &cache ); - - // Differencing coordinates of magnitude d costs precision proportional to the scale - float tolerance = 1e-5f * s + 1e-6f; - - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( manifold.normal.x - 1.0f, 1e-6f ); - ENSURE_SMALL( manifold.points[0].separation - expected, tolerance ); - ENSURE_SMALL( manifold.points[0].point.x - 0.5f * d, tolerance ); - ENSURE_SMALL( manifold.points[0].point.y, tolerance ); - ENSURE_SMALL( manifold.points[0].point.z, tolerance ); - } - - return 0; -} - -// The cached edge pair rebuilds the axis without a fresh query. An untouched cache proves the -// cached branch answered rather than falling through to the full SAT. -static int EdgeCacheTest( void ) -{ - b3BoxHull hullA, hullB; - MakeCrossedEdgeHulls( &hullA, &hullB, 0.5f ); - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( 1.41f ), &cache ); - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.type == b3_edgePairAxis ); - // Cached edges are the even half of each twin pair - ENSURE( ( cache.indexA & 1 ) == 0 && cache.indexA < hullA.base.edgeCount ); - ENSURE( ( cache.indexB & 1 ) == 0 && cache.indexB < hullB.base.edgeCount ); - - float seededSeparation = cache.separation; - ENSURE_SMALL( seededSeparation - ( 1.41f - kRoot2 ), 1e-5f ); - - // Small motion, the cached features still describe the contact - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( 1.4105f ), &cache ); - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.separation == seededSeparation ); - ENSURE_SMALL( manifold.points[0].separation - ( 1.4105f - kRoot2 ), 1e-5f ); - ENSURE_SMALL( manifold.normal.x - 1.0f, 1e-6f ); - - // Jump past the speculative distance. The cached axis alone must report the separation. - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, SlideX( 1.5f ), &cache ); - ENSURE( manifold.pointCount == 0 ); - ENSURE( cache.separation == seededSeparation ); - - return 0; -} - -// Sliding B along the direction of edge A walks the closest point off the end of the segment. -static int EdgeEndpointTest( void ) -{ - b3BoxHull hullA, hullB; - MakeCrossedEdgeHulls( &hullA, &hullB, 0.5f ); - - float d = 1.41f; - float expected = d - kRoot2; - - // Just inside the end of edge A - { - b3Transform transform = { { d, 0.49f, 0.0f }, b3Quat_identity }; - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { .type = b3_manualEdgePairAxis }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - ENSURE( manifold.pointCount == 1 ); - ENSURE_SMALL( manifold.points[0].separation - expected, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.y - 0.49f, 1e-5f ); - } - - // Off the end. The edge pair no longer describes a contact, so the builder rejects it and - // clears the cache rather than clamping to a point that is not on the hulls. - { - b3Transform transform = { { d, 0.55f, 0.0f }, b3Quat_identity }; - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { .type = b3_manualEdgePairAxis }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - ENSURE( manifold.pointCount == 0 ); - ENSURE( cache.type == b3_invalidAxis ); - - // The true gap is a vertex to edge distance well past the speculative distance - b3SATCache freshCache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &freshCache ); - ENSURE( manifold.pointCount == 0 ); - ENSURE( freshCache.separation > 0.0f ); - } - - return 0; -} - -static const b3Vec3 kTiltAxes[] = { - { 0.57735027f, 0.57735027f, 0.57735027f }, - { 0.70710678f, 0.0f, 0.70710678f }, - { 0.26726124f, 0.53452248f, 0.80178373f }, - { -0.48507125f, 0.72760688f, -0.48507125f }, -}; - -// Angles that straddle the 0.005 rejection threshold -static const float kTiltAngles[] = { 0.0f, 1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 0.004f, 0.005f, 0.006f, 0.01f, 0.05f }; - -// A cube corner is root3/2 from the center of rotation -static const float kHalfDiagonal = 0.87f; - -// Cubes stacked face to face and tipped by a hair. A third of the edge pairs are then nearly -// parallel, the angle between them is at the noise floor and the arc intersection carries no -// information. The face contact has to survive that untouched. -static int ParallelEdgeTest( void ) -{ - b3BoxHull hullA = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float overlap = 0.01f; - - for ( int i = 0; i < ARRAY_COUNT( kTiltAxes ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( kTiltAngles ); ++j ) - { - float angle = kTiltAngles[j]; - b3Transform transform = { { 0.0f, 1.0f - overlap, 0.0f }, ExactQuat( kTiltAxes[i], angle ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - ENSURE_FACE_POINTS( manifold.pointCount ); - ENSURE( cache.type == b3_faceAxisA || cache.type == b3_faceAxisB ); - ENSURE( b3Dot( manifold.normal, kAxisY ) > 0.998f ); - - // The tilt can only lift or sink a face point by the length of the arc it sweeps - float bound = kHalfDiagonal * angle + 1e-5f; - for ( int k = 0; k < manifold.pointCount; ++k ) - { - ENSURE_SMALL( manifold.points[k].separation + overlap, bound ); - } - } - } - - return 0; -} - -// Same stack, but force the edge query to answer. With the edges exactly parallel no pair forms a -// Minkowski face at all, and once a pair does form its separation can never be positive because -// the hulls overlap. -static int ParallelEdgeManualTest( void ) -{ - b3BoxHull hullA = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float overlap = 0.01f; - - for ( int i = 0; i < ARRAY_COUNT( kTiltAxes ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( kTiltAngles ); ++j ) - { - float angle = kTiltAngles[j]; - b3Transform transform = { { 0.0f, 1.0f - overlap, 0.0f }, ExactQuat( kTiltAxes[i], angle ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { .type = b3_manualEdgePairAxis }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - if ( angle == 0.0f ) - { - // Every pair is parallel so the query finds nothing and leaves the cache alone - ENSURE( manifold.pointCount == 0 ); - ENSURE( cache.type == b3_manualEdgePairAxis ); - continue; - } - - // The closest points can fall off the ends of the segments - if ( manifold.pointCount == 0 ) - { - continue; - } - - ENSURE( manifold.pointCount == 1 ); - ENSURE( b3Dot( manifold.normal, kAxisY ) > 0.99f ); - - float separation = manifold.points[0].separation; - ENSURE( separation <= 0.0f ); - ENSURE( separation >= -overlap - kHalfDiagonal * angle - 1e-4f ); - } - } - - return 0; -} - -static uint32_t g_seed = 12345; - -static float NextFloat( float lower, float upper ) -{ - g_seed = 1664525u * g_seed + 1013904223u; - float t = (float)( g_seed >> 8 ) / (float)( 1 << 24 ); - return lower + t * ( upper - lower ); -} - -static b3Vec3 NextDirection( void ) -{ - b3Vec3 v = { NextFloat( -1.0f, 1.0f ), NextFloat( -1.0f, 1.0f ), NextFloat( -1.0f, 1.0f ) }; - return b3Normalize( v ); -} - -// Overlapping hulls admit no separating axis, so an edge separation that comes back positive is -// always noise. It shows up as a manifold with no points, which the solver reads as no contact. -static int OverlapNeverEmptyTest( void ) -{ - b3BoxHull hullA = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BoxHull hullB = b3MakeBoxHull( 0.4f, 0.6f, 0.5f ); - - for ( int i = 0; i < 2000; ++i ) - { - b3Vec3 axis = NextDirection(); - - // Half the samples are nearly aligned, where the edge cross products are smallest - float angle = ( i & 1 ) ? NextFloat( -0.01f, 0.01f ) : NextFloat( -B3_PI, B3_PI ); - - // Shorter than the smallest half width, so the center of B is inside A - b3Vec3 offset = b3MulSV( 0.4f, NextDirection() ); - - b3Transform transform = { offset, ExactQuat( axis, angle ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - ENSURE( manifold.pointCount > 0 ); - ENSURE_SMALL( b3Length( manifold.normal ) - 1.0f, 1e-5f ); - - // Clipping keeps points that are separated, but the deepest one must penetrate - ENSURE( MinSeparation( &manifold ) < 0.0f ); - } - - return 0; -} - -// A cube pitched 45 degrees rests on an edge along x at y = -h*root2. The two faces meeting there -// have normals (0,-r,r) and (0,-r,-r), so the arc between them spans the whole lower quadrant. -// A triangle edge crossing under it at an angle picks out an interior point of that arc, which is -// where a wrong lerp parameter would show up. -static int TriangleEdgeTest( void ) -{ - float beta = 20.0f * B3_PI / 180.0f; - float gamma = 30.0f * B3_PI / 180.0f; - - b3BoxHull hull = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisX, 0.25f * B3_PI ) ); - - // Tipping the triangle plane about z keeps its normal off the hull edge, which the Minkowski - // test needs. Tipping the edge within that plane moves the arc intersection off the midpoint. - b3Vec3 triNormal = { sinf( beta ), cosf( beta ), 0.0f }; - b3Vec3 triEdge = { sinf( gamma ) * cosf( beta ), -sinf( gamma ) * sinf( beta ), cosf( gamma ) }; - - // Perpendicular to both edges and pointing out of the hull - b3Vec3 axis = b3Normalize( b3Cross( kAxisX, triEdge ) ); - b3Vec3 hullPoint = { 0.0f, -kHalfRoot2, 0.0f }; - - float gaps[] = { 0.03f, 0.01f, 0.0f, -0.01f, -0.1f }; - - for ( int i = 0; i < ARRAY_COUNT( gaps ); ++i ) - { - float gap = gaps[i]; - b3Vec3 trianglePoint = b3MulAdd( hullPoint, gap, axis ); - - b3Vec3 v1 = b3MulAdd( trianglePoint, -1.0f, triEdge ); - b3Vec3 v2 = b3MulAdd( trianglePoint, 1.0f, triEdge ); - b3Vec3 v3 = b3MulAdd( v1, 1.5f, b3Cross( triNormal, triEdge ) ); - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { .type = b3_manualEdgePairAxis }; - b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true ); - - b3Vec3 expectedNormal = b3Neg( axis ); - b3Vec3 expectedPoint = b3MulAdd( hullPoint, 0.5f * gap, axis ); - - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( manifold.normal.x - expectedNormal.x, 1e-5f ); - ENSURE_SMALL( manifold.normal.y - expectedNormal.y, 1e-5f ); - ENSURE_SMALL( manifold.normal.z - expectedNormal.z, 1e-5f ); - ENSURE_SMALL( manifold.points[0].separation - gap, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.x - expectedPoint.x, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.y - expectedPoint.y, 1e-5f ); - ENSURE_SMALL( manifold.points[0].point.z - expectedPoint.z, 1e-5f ); - } - - // The tipped triangle plane buries a corner of the hull, so neither face axis separates and - // the edge axis has to carry the speculative cull on its own. - float culled[] = { 0.03f, 0.05f }; - - for ( int i = 0; i < ARRAY_COUNT( culled ); ++i ) - { - float gap = culled[i]; - b3Vec3 trianglePoint = b3MulAdd( hullPoint, gap, axis ); - - b3Vec3 v1 = b3MulAdd( trianglePoint, -1.0f, triEdge ); - b3Vec3 v2 = b3MulAdd( trianglePoint, 1.0f, triEdge ); - b3Vec3 v3 = b3MulAdd( v1, 1.5f, b3Cross( triNormal, triEdge ) ); - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true ); - - ENSURE( manifold.pointCount == 0 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( cache.separation - gap, 1e-5f ); - } - - return 0; -} - -// The same cube resting its bottom edge on a triangle whose first edge runs along x. Tipping the -// triangle takes that pair from exactly parallel through the rejection threshold. -static int TriangleParallelEdgeTest( void ) -{ - b3BoxHull hull = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisX, 0.25f * B3_PI ) ); - - float overlap = 0.01f; - float y = -kHalfRoot2 + overlap; - - for ( int i = 0; i < ARRAY_COUNT( kTiltAxes ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( kTiltAngles ); ++j ) - { - b3Quat q = ExactQuat( kTiltAxes[i], kTiltAngles[j] ); - - b3Vec3 v1 = b3RotateVector( q, ( b3Vec3 ){ -2.0f, y, -1.0f } ); - b3Vec3 v2 = b3RotateVector( q, ( b3Vec3 ){ 0.0f, y, 2.0f } ); - b3Vec3 v3 = b3RotateVector( q, ( b3Vec3 ){ 2.0f, y, -1.0f } ); - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true ); - - ENSURE_FACE_POINTS( manifold.pointCount ); - ENSURE( cache.type == b3_faceAxisA ); - ENSURE( b3Dot( manifold.normal, kAxisY ) > 0.99f ); - - // The tilt can only sink the contact by the length of the arc it sweeps - float bound = kHalfDiagonal * kTiltAngles[j] + 1e-5f; - ENSURE_SMALL( MinSeparation( &manifold ) + overlap, bound ); - } - } - - return 0; -} - -// A crossed ridge pair must land on a four point roof face contact. The clipped face -// separation can be no deeper than root2 times the vertical overlap. -static int CheckRoofFaceContact( const b3LocalManifold* manifold, const b3SATCache* cache, float overlap ) -{ - ENSURE_FACE_POINTS( manifold->pointCount ); - ENSURE( cache->type == b3_faceAxisA || cache->type == b3_faceAxisB ); - - // A roof face of one hull, so 45 degrees off the vertical - ENSURE_SMALL( manifold->normal.y - kHalfRoot2, 1e-4f ); - - float minSeparation = MinSeparation( manifold ); - ENSURE( minSeparation < -kHalfRoot2 * overlap + 1e-4f ); - ENSURE( minSeparation > -kRoot2 * overlap - 1e-4f ); - - return 0; -} - -// Two long roof ridges laid across each other. The axis of minimum penetration is the edge -// pair, but a one point edge contact is weak for stacking. The collider builds the roof face -// contact first and only switches to the edge contact when the edge axis beats the clipped -// face separation by more than the slop. This pins all three regimes of that policy. -static int RidgeCrossingTest( void ) -{ - b3BoxHull hullA = b3MakeTransformedBoxHull( 1.5f, 0.1f, 0.1f, ExactRotation( kAxisX, 0.25f * B3_PI ) ); - b3BoxHull hullB = b3MakeTransformedBoxHull( 1.5f, 0.1f, 0.1f, ExactRotation( kAxisX, 0.25f * B3_PI ) ); - - float ridgeY = 0.1f * kRoot2; - - // Shallow overlap. The edge axis is better by only ( root2 - 1 ) * overlap, inside the - // slop, so the four point face contact carries the crossing at every angle. - { - float overlap = 0.01f; - float lift = 2.0f * ridgeY - overlap; - float crossingAngles[] = { 0.0f, 1e-3f, 0.02f, 0.1f, 0.5f }; - - for ( int i = 0; i < ARRAY_COUNT( crossingAngles ); ++i ) - { - b3Transform transform = { { 0.0f, lift, 0.0f }, ExactQuat( kAxisY, crossingAngles[i] ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - if ( CheckRoofFaceContact( &manifold, &cache, overlap ) != 0 ) - { - return 1; - } - } - } - - // Deep overlap at a clear crossing. The edge axis now beats the clipped face separation - // by more than the slop, so the edge contact replaces the face contact. - { - float overlap = 0.05f; - float lift = 2.0f * ridgeY - overlap; - float crossingAngles[] = { 0.05f, 0.1f, 0.2f, 0.5f }; - - for ( int i = 0; i < ARRAY_COUNT( crossingAngles ); ++i ) - { - b3Transform transform = { { 0.0f, lift, 0.0f }, ExactQuat( kAxisY, crossingAngles[i] ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - ENSURE( manifold.pointCount == 1 ); - ENSURE( cache.type == b3_edgePairAxis ); - ENSURE_SMALL( manifold.normal.x, 1e-4f ); - ENSURE_SMALL( manifold.normal.y - 1.0f, 1e-4f ); - ENSURE_SMALL( manifold.normal.z, 1e-4f ); - ENSURE_SMALL( manifold.points[0].separation + overlap, 1e-4f ); - ENSURE_SMALL( manifold.points[0].point.y - ( ridgeY - 0.5f * overlap ), 1e-4f ); - - // Only has to land near the crossing, not at the end of a three meter beam - ENSURE_SMALL( manifold.points[0].point.x, 0.01f ); - ENSURE_SMALL( manifold.points[0].point.z, 0.01f ); - } - } - - // Deep overlap near parallel. A one point edge contact off a parallel pair would have a - // normal built from noise, so the roof faces keep the contact. - { - float overlap = 0.05f; - float lift = 2.0f * ridgeY - overlap; - float shallowAngles[] = { 0.0f, 1e-4f, 1e-3f, 0.003f }; - - for ( int i = 0; i < ARRAY_COUNT( shallowAngles ); ++i ) - { - b3Transform transform = { { 0.0f, lift, 0.0f }, ExactQuat( kAxisY, shallowAngles[i] ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - if ( CheckRoofFaceContact( &manifold, &cache, overlap ) != 0 ) - { - return 1; - } - } - } - - return 0; -} - -// The edge pair axis produced by the arc intersection must match the classic edge cross product. -// Rebuild the axis, the separation and the contact point from the two contributing edges and the -// convex radius, then compare against the manifold. orientRef fixes the sign of the axis to match -// the manifold normal convention for the shape pair. e1 belongs to the shape whose contact point is -// pulled in by the radius (the hull or triangle when it meets a capsule), e2 to the other edge. -static int CheckEdgeContact( const b3LocalManifold* manifold, b3Vec3 p1, b3Vec3 e1, b3Vec3 p2, b3Vec3 e2, b3Vec3 orientRef, - float radius, float normalTol, float sepTol, float pointTol ) -{ - b3Vec3 axis = b3Normalize( b3Cross( e1, e2 ) ); - if ( b3Dot( axis, orientRef ) < 0.0f ) - { - axis = b3Neg( axis ); - } - - // Normal matches the cross product and is perpendicular to both edges - ENSURE_SMALL( manifold->normal.x - axis.x, normalTol ); - ENSURE_SMALL( manifold->normal.y - axis.y, normalTol ); - ENSURE_SMALL( manifold->normal.z - axis.z, normalTol ); - ENSURE_SMALL( b3Dot( manifold->normal, b3Normalize( e1 ) ), normalTol ); - ENSURE_SMALL( b3Dot( manifold->normal, b3Normalize( e2 ) ), normalTol ); - - b3SegmentDistanceResult closest = b3LineDistance( p1, e1, p2, e2 ); - - // Signed gap between the edge lines along the axis, less the capsule radius - float expectedSeparation = b3Dot( axis, b3Sub( closest.point2, closest.point1 ) ) - radius; - ENSURE_SMALL( manifold->points[0].separation - expectedSeparation, sepTol ); - - // Midpoint of the closest approach, pulling the first point in by the radius - b3Vec3 expectedPoint = b3MulSV( 0.5f, b3Add( b3MulSub( closest.point1, radius, axis ), closest.point2 ) ); - ENSURE_SMALL( manifold->points[0].point.x - expectedPoint.x, pointTol ); - ENSURE_SMALL( manifold->points[0].point.y - expectedPoint.y, pointTol ); - ENSURE_SMALL( manifold->points[0].point.z - expectedPoint.z, pointTol ); - - return 0; -} - -static void HullEdgeSegment( const b3HullData* hull, int edgeIndex, b3Transform transform, b3Vec3* point, b3Vec3* edge ) -{ - const b3HullHalfEdge* edges = b3GetHullEdges( hull ); - const b3Vec3* points = b3GetHullPoints( hull ); - const b3HullHalfEdge* e = edges + edgeIndex; - b3Vec3 tail = b3TransformPoint( transform, points[e->origin] ); - b3Vec3 head = b3TransformPoint( transform, points[edges[e->twin].origin] ); - *point = tail; - *edge = b3Sub( head, tail ); -} - -// Two boxes crossing edge to edge. A holds a vertical edge, B is rolled to present a crossing edge -// and yawed so the arc intersection walks off the midpoint. For every configuration that resolves -// to an edge pair the recovered axis, separation and point must match the cross product oracle to -// tight tolerance. The oracle reads the edges the solver actually latched onto, so the check is -// exact regardless of which pair wins. -static int EdgeAxisOracleTest( void ) -{ - b3BoxHull hullA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisY, 0.25f * B3_PI ) ); - - float rolls[] = { 0.18f * B3_PI, 0.25f * B3_PI, 0.32f * B3_PI }; - float yaws[] = { -0.35f, -0.15f, 0.0f, 0.15f, 0.35f }; - float distances[] = { 1.38f, 1.40f, kRoot2, 1.44f }; - - int edgeContacts = 0; - - for ( int i = 0; i < ARRAY_COUNT( rolls ); ++i ) - { - b3BoxHull hullB = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisZ, rolls[i] ) ); - - for ( int j = 0; j < ARRAY_COUNT( yaws ); ++j ) - { - for ( int k = 0; k < ARRAY_COUNT( distances ); ++k ) - { - b3Transform transform = { { distances[k], 0.0f, 0.0f }, ExactQuat( kAxisY, yaws[j] ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - if ( cache.type != b3_edgePairAxis || manifold.pointCount != 1 ) - { - continue; - } - - b3Vec3 p1, e1, p2, e2; - HullEdgeSegment( &hullA.base, cache.indexA, b3Transform_identity, &p1, &e1 ); - HullEdgeSegment( &hullB.base, cache.indexB, transform, &p2, &e2 ); - - b3Vec3 centerA = hullA.base.center; - b3Vec3 centerB = b3TransformPoint( transform, hullB.base.center ); - b3Vec3 orientRef = b3Sub( centerB, centerA ); - - if ( CheckEdgeContact( &manifold, p1, e1, p2, e2, orientRef, 0.0f, 2e-4f, 2e-4f, 2e-3f ) != 0 ) - { - return 1; - } - - ++edgeContacts; - } - } - } - - // The sweep is only meaningful if it actually drove the edge path - ENSURE( edgeContacts >= 15 ); - - return 0; -} - -// The same oracle over randomly oriented box pairs. Whenever the solver reports an edge pair the -// recovered axis must be perpendicular to both edges and match the cross product. This casts a wide -// net over the arc that the structured sweep cannot reach. -static int EdgeAxisRandomOracleTest( void ) -{ - g_seed = 246813579u; - - int edgeContacts = 0; - - for ( int i = 0; i < 2000; ++i ) - { - float angleA = NextFloat( 0.2f, 0.5f ) * B3_PI; - float angleB = NextFloat( 0.2f, 0.5f ) * B3_PI; - b3BoxHull hullA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( NextDirection(), angleA ) ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float d = NextFloat( 1.2f, 1.55f ); - b3Transform transform = { b3MulSV( d, NextDirection() ), ExactQuat( NextDirection(), angleB ) }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, 8, &hullA.base, &hullB.base, transform, &cache ); - - if ( cache.type != b3_edgePairAxis || manifold.pointCount != 1 ) - { - continue; - } - - b3Vec3 p1, e1, p2, e2; - HullEdgeSegment( &hullA.base, cache.indexA, b3Transform_identity, &p1, &e1 ); - HullEdgeSegment( &hullB.base, cache.indexB, transform, &p2, &e2 ); - - // Skip crossings near parallel where the closest point solve is ill conditioned. The - // parallel rejection itself is covered by ParallelEdgeTest. - float sine = b3Length( b3Cross( b3Normalize( e1 ), b3Normalize( e2 ) ) ); - if ( sine < 0.1f ) - { - continue; - } - - b3Vec3 orientRef = b3Sub( b3TransformPoint( transform, hullB.base.center ), hullA.base.center ); - - if ( CheckEdgeContact( &manifold, p1, e1, p2, e2, orientRef, 0.0f, 1e-3f, 1e-3f, 5e-3f ) != 0 ) - { - return 1; - } - - ++edgeContacts; - } - - ENSURE( edgeContacts >= 100 ); - - return 0; -} - -// A thin capsule stabbed through the +x +y edge of a box so the edge pair is the axis of minimum -// penetration. This drives the isolated edge axis (arc versus circle on the Gauss map) that a -// capsule presents. The edge is nearly parallel to a box face normal, exactly where the old center -// based orientation flickered, so the axis, the penetration and the point are all checked. -static int HullCapsuleEdgeDeepTest( void ) -{ - b3BoxHull hull = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - // The +x +y edge runs along z between the +x and +y faces - b3Vec3 edgePoint = { 0.5f, 0.5f, 0.0f }; - b3Vec3 edgeDir = { 0.0f, 0.0f, 1.0f }; - b3Vec3 outward = b3Normalize( ( b3Vec3 ){ 1.0f, 1.0f, 0.0f } ); - - // Penetrate far enough that the core segment clearly overlaps the box so the deep path runs, - // but keep the radius small enough that the edge stays the axis of minimum penetration. - float depths[] = { 0.12f, 0.18f, 0.25f }; - float radii[] = { 0.05f, 0.1f, 0.2f }; - float tilts[] = { 0.0f, 0.25f, -0.25f }; - - int count = 0; - - for ( int i = 0; i < ARRAY_COUNT( depths ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( radii ); ++j ) - { - for ( int k = 0; k < ARRAY_COUNT( tilts ); ++k ) - { - b3Vec3 capsuleDir = b3Normalize( ( b3Vec3 ){ 1.0f, -1.0f, tilts[k] } ); - b3Vec3 mid = b3MulAdd( edgePoint, -depths[i], outward ); - b3Vec3 c1 = b3MulAdd( mid, -0.5f, capsuleDir ); - b3Vec3 c2 = b3MulAdd( mid, 0.5f, capsuleDir ); - b3Capsule capsule = { c1, c2, radii[j] }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideHullAndCapsule( &manifold, 8, &hull.base, &capsule, b3Transform_identity, &cache ); - - ENSURE( manifold.pointCount == 1 ); - ENSURE( manifold.points[0].separation < 0.0f ); - - // Hull edge is e1, capsule axis is e2, normal points out of the hull - if ( CheckEdgeContact( &manifold, edgePoint, edgeDir, c1, b3Sub( c2, c1 ), outward, radii[j], 1e-4f, 1e-4f, - 1e-4f ) != 0 ) - { - return 1; - } - - ++count; - } - } - } - - ENSURE( count == ARRAY_COUNT( depths ) * ARRAY_COUNT( radii ) * ARRAY_COUNT( tilts ) ); - - return 0; -} - -// Force the triangle versus hull edge query over a broad sweep of crossing geometries. A cube tipped -// 45 degrees rests an edge along x at y = -h*root2. A triangle edge is laid across it at a range of -// yaws, plane tips and gaps so the arc intersection lands all over the arc. The manual axis hands -// the winning pair to the builder, and the recovered axis must match the cross product of the chosen -// triangle and hull edges and point from the triangle into the hull. -static int TriangleHullEdgeSweepTest( void ) -{ - b3BoxHull hull = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisX, 0.25f * B3_PI ) ); - b3Vec3 hullEdgePoint = { 0.0f, -kHalfRoot2, 0.0f }; - - // Degrees: triangle plane tip about z, and triangle edge yaw - float betas[] = { 8.0f, 20.0f, 32.0f }; - float gammas[] = { 20.0f, 35.0f, 50.0f, 70.0f }; - float gaps[] = { 0.02f, 0.0f, -0.03f, -0.08f }; - - int edgeContacts = 0; - - for ( int a = 0; a < ARRAY_COUNT( betas ); ++a ) - { - for ( int b = 0; b < ARRAY_COUNT( gammas ); ++b ) - { - for ( int c = 0; c < ARRAY_COUNT( gaps ); ++c ) - { - float beta = betas[a] * B3_PI / 180.0f; - float gamma = gammas[b] * B3_PI / 180.0f; - - // Tip the plane off the hull edge so the Minkowski test holds, then yaw the edge - b3Vec3 triNormal = { sinf( beta ), cosf( beta ), 0.0f }; - b3Vec3 triEdge = { sinf( gamma ) * cosf( beta ), -sinf( gamma ) * sinf( beta ), cosf( gamma ) }; - - // Perpendicular to both edges and pointing out of the hull - b3Vec3 axis = b3Normalize( b3Cross( kAxisX, triEdge ) ); - b3Vec3 trianglePoint = b3MulAdd( hullEdgePoint, gaps[c], axis ); - - b3Vec3 v1 = b3MulAdd( trianglePoint, -1.0f, triEdge ); - b3Vec3 v2 = b3MulAdd( trianglePoint, 1.0f, triEdge ); - b3Vec3 v3 = b3MulAdd( v1, 1.5f, b3Cross( triNormal, triEdge ) ); - - b3Vec3 triangleVerts[] = { v1, v2, v3 }; - b3Vec3 triangleEdges[] = { b3Sub( v2, v1 ), b3Sub( v3, v2 ), b3Sub( v1, v3 ) }; - b3Vec3 triangleCenter = b3MulSV( 1.0f / 3.0f, b3Add( v1, b3Add( v2, v3 ) ) ); - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SATCache cache = { .type = b3_manualEdgePairAxis }; - b3CollideTriangleAndHull( &manifold, 8, v1, v2, v3, &hull.base, &cache, true ); - - if ( cache.type != b3_edgePairAxis || manifold.pointCount != 1 ) - { - continue; - } - - b3Vec3 p1 = triangleVerts[cache.indexA]; - b3Vec3 e1 = triangleEdges[cache.indexA]; - - b3Vec3 p2, e2; - HullEdgeSegment( &hull.base, cache.indexB, b3Transform_identity, &p2, &e2 ); - - // Normal points from the triangle into the hull - b3Vec3 orientRef = b3Sub( hull.base.center, triangleCenter ); - - if ( CheckEdgeContact( &manifold, p1, e1, p2, e2, orientRef, 0.0f, 1e-4f, 1e-4f, 1e-3f ) != 0 ) - { - return 1; - } - - ++edgeContacts; - } - } - } - - ENSURE( edgeContacts >= 30 ); - - return 0; -} - -// A capsule laid nearly in a triangle plane and pushed across one edge so the edge pair drives the -// deep contact. This exercises the two sided triangle edge, where the side normal trick chooses -// which half of the arc holds the axis. Validate every edge contact the sweep produces. -static int CapsuleTriangleEdgeDeepTest( void ) -{ - // Triangle in the y = 0 plane. The v1 v2 edge runs along x at z = 0, the interior lies at z < 0. - b3Vec3 v1 = { -2.0f, 0.0f, 0.0f }; - b3Vec3 v2 = { 2.0f, 0.0f, 0.0f }; - b3Vec3 v3 = { 0.0f, 0.0f, -2.0f }; - b3Vec3 triangle[] = { v1, v2, v3 }; - b3Vec3 triangleEdges[] = { b3Sub( v2, v1 ), b3Sub( v3, v2 ), b3Sub( v1, v3 ) }; - b3Vec3 triangleCenter = b3MulSV( 1.0f / 3.0f, b3Add( v1, b3Add( v2, v3 ) ) ); - - // A nearly in plane core crossing the edge at (0,0,z0) with a small out of plane tilt. The core - // pierces the triangle just inside the edge so the deep path runs and the tilted edge pair wins. - float z0s[] = { -0.05f, -0.03f, -0.01f }; - float tilts[] = { 0.2f, 0.3f, 0.4f }; - float yaws[] = { 0.4f, 0.6f, 0.8f }; - float radii[] = { 0.05f, 0.1f }; - - int edgeContacts = 0; - - for ( int i = 0; i < ARRAY_COUNT( z0s ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( tilts ); ++j ) - { - for ( int y = 0; y < ARRAY_COUNT( yaws ); ++y ) - { - for ( int r = 0; r < ARRAY_COUNT( radii ); ++r ) - { - b3Vec3 capsuleDir = b3Normalize( ( b3Vec3 ){ sinf( yaws[y] ), tilts[j], cosf( yaws[y] ) } ); - b3Vec3 mid = { 0.0f, 0.0f, z0s[i] }; - b3Vec3 c1 = b3MulAdd( mid, -0.6f, capsuleDir ); - b3Vec3 c2 = b3MulAdd( mid, 0.6f, capsuleDir ); - b3Capsule capsule = { c1, c2, radii[r] }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideTriangleAndCapsule( &manifold, 8, triangle, &capsule, &cache ); - - // Only the edge contacts exercise the new axis. Face contacts are handled elsewhere. - if ( manifold.pointCount != 1 || manifold.feature < b3_featureEdge1 || manifold.feature > b3_featureEdge3 ) - { - continue; - } - - int edgeIndex = manifold.feature - b3_featureEdge1; - b3Vec3 p1 = triangle[edgeIndex]; - b3Vec3 e1 = triangleEdges[edgeIndex]; - - // Normal points from the triangle toward the capsule - b3Vec3 capsuleEdge = b3Sub( c2, c1 ); - b3Vec3 capsuleCenter = b3Lerp( c1, c2, 0.5f ); - b3Vec3 orientRef = b3Sub( capsuleCenter, triangleCenter ); - - if ( CheckEdgeContact( &manifold, p1, e1, c1, capsuleEdge, orientRef, radii[r], 1e-4f, 1e-4f, 2e-4f ) != 0 ) - { - return 1; - } - - ++edgeContacts; - } - } - } - } - - // The sweep must actually reach the edge path - ENSURE( edgeContacts >= 15 ); - - return 0; -} - -// A sphere driven straight through a box face, from separated, across the surface where the collider -// switches from GJK closest points to the SAT face pick, and on into deep overlap. The separation -// must stay the analytic gap the whole way and the normal must not flip. A jump at the seam would -// read as a pop in the solver. The sweep is fine enough to land samples on both sides of the seam. -static int SphereHullSeamTest( void ) -{ - b3BoxHull hull = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - float radius = 0.15f; - - float yStart = 0.5f + radius + 0.4f * B3_SPECULATIVE_DISTANCE; - float yEnd = 0.1f; - int steps = 400; - float dy = ( yStart - yEnd ) / steps; - - float previous = 0.0f; - int shallowSamples = 0; - int deepSamples = 0; - - for ( int i = 0; i <= steps; ++i ) - { - float y = yStart - i * dy; - b3Sphere sphere = { { 0.0f, y, 0.0f }, radius }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideHullAndSphere( &manifold, 8, &hull.base, &sphere, b3Transform_identity, &cache ); - - ENSURE( manifold.pointCount == 1 ); - - float separation = manifold.points[0].separation; - float expected = ( y - 0.5f ) - radius; - - // Separation is the analytic gap on both sides of the seam - ENSURE_SMALL( separation - expected, 1e-5f ); - - // Normal holds the face direction with no flip - ENSURE_SMALL( manifold.normal.x, 1e-5f ); - ENSURE_SMALL( manifold.normal.y - 1.0f, 1e-5f ); - ENSURE_SMALL( manifold.normal.z, 1e-5f ); - - // No jump across the seam: consecutive separations track the step - if ( i > 0 ) - { - ENSURE_SMALL( ( previous - separation ) - dy, 1e-5f ); - } - previous = separation; - - if ( y > 0.5f ) - { - shallowSamples += 1; - } - else - { - deepSamples += 1; - } - } - - // The sweep must straddle the surface so both the GJK and the SAT branch run - ENSURE( shallowSamples > 0 && deepSamples > 0 ); - - return 0; -} - -// The same seam for a capsule laid parallel to the face. Above the surface the shallow path clips two -// points, in overlap the face path builds two, and every point must sit at the analytic gap through -// the transition with the normal fixed on the face. -static int CapsuleHullSeamTest( void ) -{ - b3BoxHull hull = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - float radius = 0.15f; - float halfLength = 0.3f; - - float yStart = 0.5f + radius + 0.4f * B3_SPECULATIVE_DISTANCE; - float yEnd = 0.1f; - int steps = 400; - float dy = ( yStart - yEnd ) / steps; - - float previous = 0.0f; - int shallowSamples = 0; - int deepSamples = 0; - - for ( int i = 0; i <= steps; ++i ) - { - float y = yStart - i * dy; - b3Capsule capsule = { { -halfLength, y, 0.0f }, { halfLength, y, 0.0f }, radius }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideHullAndCapsule( &manifold, 8, &hull.base, &capsule, b3Transform_identity, &cache ); - - ENSURE( manifold.pointCount >= 1 ); - - float expected = ( y - 0.5f ) - radius; - - // Every point sits at the analytic gap - for ( int k = 0; k < manifold.pointCount; ++k ) - { - ENSURE_SMALL( manifold.points[k].separation - expected, 1e-5f ); - } - - // Normal holds the face direction with no flip - ENSURE_SMALL( manifold.normal.x, 1e-5f ); - ENSURE_SMALL( manifold.normal.y - 1.0f, 1e-5f ); - ENSURE_SMALL( manifold.normal.z, 1e-5f ); - - // No jump across the seam - float minSeparation = MinSeparation( &manifold ); - if ( i > 0 ) - { - ENSURE_SMALL( ( previous - minSeparation ) - dy, 1e-5f ); - } - previous = minSeparation; - - if ( y > 0.5f ) - { - shallowSamples += 1; - } - else - { - deepSamples += 1; - } - } - - ENSURE( shallowSamples > 0 && deepSamples > 0 ); - - return 0; -} - -// A capsule core straddling a triangle face inside the interior. The core pierces the plane so the -// deep path runs, and with the tilt kept small the face stays the axis of minimum penetration, so the -// clip must return two points on the triangle face. This is the branch that had no coverage. -static int CapsuleTriangleFaceDeepTest( void ) -{ - // Triangle in the y = 0 plane, normal +y, centroid at the origin - b3Vec3 v1 = { -3.0f, 0.0f, -2.0f }; - b3Vec3 v2 = { 0.0f, 0.0f, 4.0f }; - b3Vec3 v3 = { 3.0f, 0.0f, -2.0f }; - b3Vec3 triangle[] = { v1, v2, v3 }; - - float yaws[] = { 0.0f, 0.6f, 1.2f, 1.8f, 2.4f }; - float tilts[] = { 0.06f, 0.1f, 0.15f }; - float radii[] = { 0.05f, 0.1f, 0.2f }; - - // Bias the center just above the plane so the back side cull passes while the lower endpoint dips through - float bias = 0.01f; - float halfLength = 1.0f; - - int faceContacts = 0; - - for ( int i = 0; i < ARRAY_COUNT( yaws ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( tilts ); ++j ) - { - for ( int r = 0; r < ARRAY_COUNT( radii ); ++r ) - { - // Axis is the in-plane heading tipped up so the segment straddles the plane - b3Vec3 axis = { cosf( tilts[j] ) * cosf( yaws[i] ), sinf( tilts[j] ), cosf( tilts[j] ) * sinf( yaws[i] ) }; - b3Vec3 center = { 0.0f, bias, 0.0f }; - b3Vec3 c1 = b3MulAdd( center, -halfLength, axis ); - b3Vec3 c2 = b3MulAdd( center, halfLength, axis ); - b3Capsule capsule = { c1, c2, radii[r] }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideTriangleAndCapsule( &manifold, 8, triangle, &capsule, &cache ); - - // Two points on the triangle face with the plane normal - ENSURE( manifold.pointCount == 2 ); - ENSURE( manifold.feature == b3_featureTriangleFace ); - ENSURE_SMALL( manifold.normal.x, 1e-5f ); - ENSURE_SMALL( manifold.normal.y - 1.0f, 1e-5f ); - ENSURE_SMALL( manifold.normal.z, 1e-5f ); - - // Separations are the endpoint heights pulled in by the radius. The lower endpoint is below - // the plane, so the deepest separation is negative. - float lower = b3MinFloat( c1.y, c2.y ) - radii[r]; - float upper = b3MaxFloat( c1.y, c2.y ) - radii[r]; - float minSep = b3MinFloat( manifold.points[0].separation, manifold.points[1].separation ); - float maxSep = b3MaxFloat( manifold.points[0].separation, manifold.points[1].separation ); - ENSURE_SMALL( minSep - lower, 1e-5f ); - ENSURE_SMALL( maxSep - upper, 1e-5f ); - ENSURE( minSep < 0.0f ); - - ++faceContacts; - } - } - } - - // Every configuration must reach the face path - ENSURE( faceContacts == ARRAY_COUNT( yaws ) * ARRAY_COUNT( tilts ) * ARRAY_COUNT( radii ) ); - - return 0; -} - -// A capsule laid flat with its core below a box top face. The core sits inside the box so the deep -// path runs, and across a sweep of depths, headings and radii the face clip must return two points. -static int HullCapsuleFaceDeepTest( void ) -{ - b3BoxHull hull = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float depths[] = { 0.1f, 0.2f, 0.3f, 0.4f, 0.45f }; - float yaws[] = { 0.0f, 0.4f, 0.8f, 1.2f }; - float radii[] = { 0.1f, 0.15f, 0.2f }; - float offsets[] = { -0.1f, 0.0f, 0.1f }; - float halfLength = 0.3f; - - int faceContacts = 0; - - for ( int i = 0; i < ARRAY_COUNT( depths ); ++i ) - { - for ( int j = 0; j < ARRAY_COUNT( yaws ); ++j ) - { - for ( int r = 0; r < ARRAY_COUNT( radii ); ++r ) - { - for ( int o = 0; o < ARRAY_COUNT( offsets ); ++o ) - { - float y = depths[i]; - b3Vec3 dir = { cosf( yaws[j] ), 0.0f, sinf( yaws[j] ) }; - b3Vec3 center = { offsets[o], y, 0.0f }; - b3Vec3 c1 = b3MulAdd( center, -halfLength, dir ); - b3Vec3 c2 = b3MulAdd( center, halfLength, dir ); - b3Capsule capsule = { c1, c2, radii[r] }; - - b3LocalManifoldPoint points[8]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - b3SimplexCache cache = { 0 }; - b3CollideHullAndCapsule( &manifold, 8, &hull.base, &capsule, b3Transform_identity, &cache ); - - // Two points on the top face. The hull path does not tag a feature, so the face is - // identified by the normal and the point count. - ENSURE( manifold.pointCount == 2 ); - ENSURE_SMALL( manifold.normal.x, 1e-5f ); - ENSURE_SMALL( manifold.normal.y - 1.0f, 1e-5f ); - ENSURE_SMALL( manifold.normal.z, 1e-5f ); - - // Flat capsule, so both points sit at the same analytic gap - float expected = ( y - 0.5f ) - radii[r]; - ENSURE_SMALL( manifold.points[0].separation - expected, 1e-5f ); - ENSURE_SMALL( manifold.points[1].separation - expected, 1e-5f ); - ENSURE( expected < 0.0f ); - - ++faceContacts; - } - } - } - } - - ENSURE( faceContacts == ARRAY_COUNT( depths ) * ARRAY_COUNT( yaws ) * ARRAY_COUNT( radii ) * ARRAY_COUNT( offsets ) ); - - return 0; -} - -static int CheckSpeculativePoints( const b3LocalManifold* manifold, float gap ) -{ - ENSURE( manifold->pointCount > 0 ); - ENSURE_SMALL( MinSeparation( manifold ) - gap, 1e-4f ); - return 0; -} - -// Contact recycling treats a pair without points as separated by at least the speculative distance. -// Every manifold routine must report a pair inside that distance or recycling can skip real overlap. -// Discussion #175. -static int SpeculativeMarginTest( void ) -{ - float gaps[] = { 0.0f, 0.25f * B3_SPECULATIVE_DISTANCE, 0.75f * B3_SPECULATIVE_DISTANCE }; - int gapCount = sizeof( gaps ) / sizeof( gaps[0] ); - - b3Sphere sphere = { b3Vec3_zero, 0.25f }; - b3Sphere bigSphere = { b3Vec3_zero, 0.5f }; - b3Capsule capsuleX = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, 0.25f }; - b3Capsule capsuleZ = { { 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, 0.5f }, 0.25f }; - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - // Normal is +y - b3Vec3 triangle[3] = { { -2.0f, 0.0f, -2.0f }, { 0.0f, 0.0f, 2.0f }, { 2.0f, 0.0f, -2.0f } }; - - b3LocalManifoldPoint points[B3_MAX_MANIFOLD_POINTS]; - b3LocalManifold manifold = { 0 }; - manifold.points = points; - - for ( int i = 0; i < gapCount; ++i ) - { - float gap = gaps[i]; - - manifold.pointCount = 0; - b3CollideSpheres( &manifold, B3_MAX_MANIFOLD_POINTS, &bigSphere, &sphere, SlideY( 0.75f + gap ) ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - - manifold.pointCount = 0; - b3CollideCapsuleAndSphere( &manifold, B3_MAX_MANIFOLD_POINTS, &capsuleX, &sphere, SlideY( 0.5f + gap ) ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - - manifold.pointCount = 0; - b3CollideCapsules( &manifold, B3_MAX_MANIFOLD_POINTS, &capsuleX, &capsuleZ, SlideY( 0.5f + gap ) ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - - { - manifold.pointCount = 0; - b3SimplexCache cache = { 0 }; - b3CollideHullAndSphere( &manifold, B3_MAX_MANIFOLD_POINTS, &box.base, &sphere, SlideY( 0.75f + gap ), &cache ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - - { - manifold.pointCount = 0; - b3SimplexCache cache = { 0 }; - b3CollideHullAndCapsule( &manifold, B3_MAX_MANIFOLD_POINTS, &box.base, &capsuleX, SlideY( 0.75f + gap ), &cache ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - - { - manifold.pointCount = 0; - b3SATCache cache = { 0 }; - b3CollideHulls( &manifold, B3_MAX_MANIFOLD_POINTS, &box.base, &box.base, SlideY( 1.0f + gap ), &cache ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - - { - manifold.pointCount = 0; - b3Sphere raised = { { 0.0f, 0.25f + gap, 0.0f }, 0.25f }; - b3CollideTriangleAndSphere( &manifold, B3_MAX_MANIFOLD_POINTS, triangle, &raised ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - - { - manifold.pointCount = 0; - b3Capsule raised = capsuleX; - raised.center1.y = 0.25f + gap; - raised.center2.y = 0.25f + gap; - b3SimplexCache cache = { 0 }; - b3CollideTriangleAndCapsule( &manifold, B3_MAX_MANIFOLD_POINTS, triangle, &raised, &cache ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - - { - manifold.pointCount = 0; - b3BoxHull raised = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, SlideY( 0.5f + gap ) ); - b3SATCache cache = { 0 }; - b3CollideTriangleAndHull( &manifold, B3_MAX_MANIFOLD_POINTS, triangle[0], triangle[1], triangle[2], &raised.base, - &cache, true ); - ENSURE( CheckSpeculativePoints( &manifold, gap ) == 0 ); - } - } - - // Beyond the speculative distance the closed form routines report nothing - float farGap = 1.5f * B3_SPECULATIVE_DISTANCE; - - manifold.pointCount = 0; - b3CollideSpheres( &manifold, B3_MAX_MANIFOLD_POINTS, &bigSphere, &sphere, SlideY( 0.75f + farGap ) ); - ENSURE( manifold.pointCount == 0 ); - - manifold.pointCount = 0; - b3CollideCapsuleAndSphere( &manifold, B3_MAX_MANIFOLD_POINTS, &capsuleX, &sphere, SlideY( 0.5f + farGap ) ); - ENSURE( manifold.pointCount == 0 ); - - return 0; -} - -// The library reports the point count it was built with. A mismatch against the manifold -// this translation unit sees means the app and the library disagree on b3Manifold. -static int MaxPointCountTest( void ) -{ - b3Manifold manifold; - ENSURE( b3GetMaxManifoldPoints() == (int)( sizeof( manifold.points ) / sizeof( manifold.points[0] ) ) ); - - return 0; -} - -int ManifoldTest( void ) -{ - RUN_SUBTEST( MaxPointCountTest ); - RUN_SUBTEST( CrossedEdgeTest ); - RUN_SUBTEST( EdgeAxisScaleTest ); - RUN_SUBTEST( EdgeCacheTest ); - RUN_SUBTEST( EdgeEndpointTest ); - RUN_SUBTEST( ParallelEdgeTest ); - RUN_SUBTEST( ParallelEdgeManualTest ); - RUN_SUBTEST( OverlapNeverEmptyTest ); - RUN_SUBTEST( RidgeCrossingTest ); - RUN_SUBTEST( TriangleEdgeTest ); - RUN_SUBTEST( TriangleParallelEdgeTest ); - RUN_SUBTEST( EdgeAxisOracleTest ); - RUN_SUBTEST( EdgeAxisRandomOracleTest ); - RUN_SUBTEST( HullCapsuleEdgeDeepTest ); - RUN_SUBTEST( TriangleHullEdgeSweepTest ); - RUN_SUBTEST( CapsuleTriangleEdgeDeepTest ); - RUN_SUBTEST( CapsuleTriangleFaceDeepTest ); - RUN_SUBTEST( HullCapsuleFaceDeepTest ); - RUN_SUBTEST( SphereHullSeamTest ); - RUN_SUBTEST( CapsuleHullSeamTest ); - RUN_SUBTEST( SpeculativeMarginTest ); - - return 0; -} diff --git a/test/test_mesh.c b/test/test_mesh.c deleted file mode 100644 index 6c436cb..0000000 --- a/test/test_mesh.c +++ /dev/null @@ -1,1372 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "ghost_collisions.h" -#include "ghost_oracle.h" -#include "shape.h" -#include "test_macros.h" - -#include "box3d/box3d.h" -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include -#include -#include -#include -#include - -// Two quads meeting at a concave crease along the shared edge 1-4. The crease exercises -// edge identification, which reads the baked winding rather than the input winding. -#define VALLEY_VERTEX_COUNT 6 -#define VALLEY_TRIANGLE_COUNT 4 - -static void MakeValley( b3Vec3* vertices, int32_t* indices ) -{ - b3Vec3 v[VALLEY_VERTEX_COUNT] = { - { -1.0f, 1.0f, -1.0f }, { 0.0f, 0.0f, -1.0f }, { 1.0f, 1.0f, -1.0f }, - { -1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, - }; - - int32_t i[3 * VALLEY_TRIANGLE_COUNT] = { - 0, 3, 1, // left quad - 3, 4, 1, - 1, 4, 2, // right quad - 4, 5, 2, - }; - - memcpy( vertices, v, sizeof( v ) ); - memcpy( indices, i, sizeof( i ) ); -} - -// A vertex laid out the way a renderer would hand it over. The position sits off the -// front of the struct so a non-zero base offset gets exercised too. -typedef struct FatVertex -{ - float weight; - b3Vec3 position; - float uv[2]; -} FatVertex; - -static void MakeFatVertices( FatVertex* fat, const b3Vec3* vertices, int count ) -{ - for ( int i = 0; i < count; ++i ) - { - // Poison the padding so a stride mistake bakes obvious garbage instead of near misses - fat[i].weight = 1000.0f + (float)i; - fat[i].position = vertices[i]; - fat[i].uv[0] = -1000.0f; - fat[i].uv[1] = -2000.0f; - } -} - -static void ReverseWinding( int32_t* indices, int triangleCount ) -{ - for ( int i = 0; i < triangleCount; ++i ) - { - int32_t temp = indices[3 * i + 1]; - indices[3 * i + 1] = indices[3 * i + 2]; - indices[3 * i + 2] = temp; - } -} - -// The hash covers every byte of the mesh block, so this compares the tree, the vertices, -// the baked triangles and the edge flags in one shot. -static bool MeshesMatch( const b3MeshData* mesh1, const b3MeshData* mesh2 ) -{ - return mesh1->byteCount == mesh2->byteCount && mesh1->hash == mesh2->hash; -} - -static bool VerticesMatch( const b3MeshData* mesh, const b3Vec3* expected, int count ) -{ - if ( mesh->vertexCount != count ) - { - return false; - } - - const b3Vec3* vertices = b3GetMeshVertices( mesh ); - for ( int i = 0; i < count; ++i ) - { - if ( b3DistanceSquared( vertices[i], expected[i] ) > FLT_EPSILON ) - { - return false; - } - } - - return true; -} - -// The valley faces up, so every baked triangle should wind counter clockwise about +Y -static bool FacesUp( const b3MeshData* mesh ) -{ - const b3Vec3* vertices = b3GetMeshVertices( mesh ); - const b3MeshTriangle* triangles = b3GetMeshTriangles( mesh ); - - for ( int i = 0; i < mesh->triangleCount; ++i ) - { - b3Vec3 v1 = vertices[triangles[i].index1]; - b3Vec3 v2 = vertices[triangles[i].index2]; - b3Vec3 v3 = vertices[triangles[i].index3]; - - b3Vec3 normal = b3Cross( b3Sub( v2, v1 ), b3Sub( v3, v1 ) ); - if ( normal.y <= 0.0f ) - { - return false; - } - } - - return true; -} - -static bool HasConcaveEdge( const b3MeshData* mesh ) -{ - const uint8_t* flags = b3GetMeshFlags( mesh ); - - for ( int i = 0; i < mesh->triangleCount; ++i ) - { - if ( ( flags[i] & b3_allConcaveEdges ) != 0 ) - { - return true; - } - } - - return false; -} - -static b3MeshDef MakeValleyDef( b3Vec3* vertices, int32_t* indices ) -{ - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.stride = sizeof( b3Vec3 ); - def.indices = indices; - def.vertexCount = VALLEY_VERTEX_COUNT; - def.triangleCount = VALLEY_TRIANGLE_COUNT; - def.identifyEdges = true; - return def; -} - -// Dense input is the reference the other cases are measured against -static int MeshDenseStride( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - - b3MeshDef def = MakeValleyDef( vertices, indices ); - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - ENSURE( mesh != NULL ); - - ENSURE( mesh->vertexCount == VALLEY_VERTEX_COUNT ); - ENSURE( mesh->triangleCount == VALLEY_TRIANGLE_COUNT ); - ENSURE( mesh->degenerateCount == 0 ); - ENSURE( VerticesMatch( mesh, vertices, VALLEY_VERTEX_COUNT ) ); - ENSURE( FacesUp( mesh ) ); - ENSURE( HasConcaveEdge( mesh ) ); - - b3DestroyMesh( mesh ); - return 0; -} - -// Interleaved input must bake to exactly the same mesh as dense input -static int MeshFatStride( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - - b3MeshDef denseDef = MakeValleyDef( vertices, indices ); - b3MeshData* denseMesh = b3CreateMesh( &denseDef, NULL, 0 ); - ENSURE( denseMesh != NULL ); - - FatVertex fat[VALLEY_VERTEX_COUNT]; - MakeFatVertices( fat, vertices, VALLEY_VERTEX_COUNT ); - - b3MeshDef fatDef = MakeValleyDef( &fat[0].position, indices ); - fatDef.stride = sizeof( FatVertex ); - b3MeshData* fatMesh = b3CreateMesh( &fatDef, NULL, 0 ); - ENSURE( fatMesh != NULL ); - - ENSURE( VerticesMatch( fatMesh, vertices, VALLEY_VERTEX_COUNT ) ); - ENSURE( FacesUp( fatMesh ) ); - ENSURE( MeshesMatch( denseMesh, fatMesh ) ); - - b3DestroyMesh( fatMesh ); - b3DestroyMesh( denseMesh ); - return 0; -} - -// Welding reads the source vertices through the stride as well -static int MeshStrideWeld( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - - // Split the crease so each quad owns a copy of the shared edge - b3Vec3 splitVertices[8]; - memcpy( splitVertices, vertices, sizeof( vertices ) ); - splitVertices[6] = vertices[1]; - splitVertices[7] = vertices[4]; - - // Point the right quad at the copies - int32_t splitIndices[3 * VALLEY_TRIANGLE_COUNT]; - memcpy( splitIndices, indices, sizeof( indices ) ); - splitIndices[6] = 6; - splitIndices[7] = 7; - splitIndices[9] = 7; - - FatVertex fat[8]; - MakeFatVertices( fat, splitVertices, 8 ); - - b3MeshDef def = MakeValleyDef( &fat[0].position, splitIndices ); - def.stride = sizeof( FatVertex ); - def.vertexCount = 8; - def.weldVertices = true; - def.weldTolerance = 0.01f; - - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - ENSURE( mesh != NULL ); - - ENSURE( mesh->vertexCount == VALLEY_VERTEX_COUNT ); - ENSURE( mesh->triangleCount == VALLEY_TRIANGLE_COUNT ); - ENSURE( VerticesMatch( mesh, vertices, VALLEY_VERTEX_COUNT ) ); - ENSURE( FacesUp( mesh ) ); - ENSURE( HasConcaveEdge( mesh ) ); - - b3DestroyMesh( mesh ); - return 0; -} - -// Clockwise input plus the flag must bake to the same mesh as counter clockwise input -static int MeshClockWise( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - - b3MeshDef ccwDef = MakeValleyDef( vertices, indices ); - b3MeshData* ccwMesh = b3CreateMesh( &ccwDef, NULL, 0 ); - ENSURE( ccwMesh != NULL ); - - int32_t reversed[3 * VALLEY_TRIANGLE_COUNT]; - memcpy( reversed, indices, sizeof( indices ) ); - ReverseWinding( reversed, VALLEY_TRIANGLE_COUNT ); - - b3MeshDef cwDef = MakeValleyDef( vertices, reversed ); - cwDef.clockWiseWinding = true; - b3MeshData* cwMesh = b3CreateMesh( &cwDef, NULL, 0 ); - ENSURE( cwMesh != NULL ); - - ENSURE( FacesUp( cwMesh ) ); - ENSURE( HasConcaveEdge( cwMesh ) ); - ENSURE( MeshesMatch( ccwMesh, cwMesh ) ); - - b3DestroyMesh( cwMesh ); - b3DestroyMesh( ccwMesh ); - return 0; -} - -// Without the flag the same clockwise input must bake inside out -static int MeshClockWiseIgnored( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - ReverseWinding( indices, VALLEY_TRIANGLE_COUNT ); - - b3MeshDef def = MakeValleyDef( vertices, indices ); - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - ENSURE( mesh != NULL ); - - ENSURE( FacesUp( mesh ) == false ); - - b3DestroyMesh( mesh ); - return 0; -} - -// Winding, stride and welding have to compose -static int MeshClockWiseStrideWeld( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - - b3MeshDef ccwDef = MakeValleyDef( vertices, indices ); - ccwDef.weldVertices = true; - ccwDef.weldTolerance = 0.01f; - b3MeshData* ccwMesh = b3CreateMesh( &ccwDef, NULL, 0 ); - ENSURE( ccwMesh != NULL ); - - int32_t reversed[3 * VALLEY_TRIANGLE_COUNT]; - memcpy( reversed, indices, sizeof( indices ) ); - ReverseWinding( reversed, VALLEY_TRIANGLE_COUNT ); - - FatVertex fat[VALLEY_VERTEX_COUNT]; - MakeFatVertices( fat, vertices, VALLEY_VERTEX_COUNT ); - - b3MeshDef cwDef = MakeValleyDef( &fat[0].position, reversed ); - cwDef.stride = sizeof( FatVertex ); - cwDef.clockWiseWinding = true; - cwDef.weldVertices = true; - cwDef.weldTolerance = 0.01f; - b3MeshData* cwMesh = b3CreateMesh( &cwDef, NULL, 0 ); - ENSURE( cwMesh != NULL ); - - ENSURE( FacesUp( cwMesh ) ); - ENSURE( MeshesMatch( ccwMesh, cwMesh ) ); - - b3DestroyMesh( cwMesh ); - b3DestroyMesh( ccwMesh ); - return 0; -} - -// The built in creators fill their own def, so a missed stride shows up here -static int MeshCreators( void ) -{ - b3Vec3 center = { 1.0f, 2.0f, 3.0f }; - b3Vec3 extent = { 0.5f, 1.0f, 1.5f }; - - b3MeshData* meshes[] = { - b3CreateGridMesh( 4, 4, 1.0f, 2, true ), - b3CreateWaveMesh( 4, 4, 1.0f, 0.5f, 1.0f, 1.0f ), - b3CreateTorusMesh( 8, 6, 2.0f, 0.5f ), - b3CreateBoxMesh( center, extent, true ), - b3CreateHollowBoxMesh( center, extent ), - b3CreatePlatformMesh( center, 2.0f, 1.0f, 2.0f ), - }; - - for ( int i = 0; i < ARRAY_COUNT( meshes ); ++i ) - { - ENSURE( meshes[i] != NULL ); - ENSURE( meshes[i]->vertexCount >= 3 ); - ENSURE( meshes[i]->triangleCount >= 1 ); - ENSURE( b3IsSaneAABB( meshes[i]->bounds ) ); - - b3DestroyMesh( meshes[i] ); - } - - return 0; -} - -// Brute force search for the triangle across edge a-b, walked b to a with consistent winding -static int FindNeighbor( const b3Mesh* mesh, int triangleIndex, int a, int b, int* edgeIndex ) -{ - for ( int i = 0; i < mesh->data->triangleCount; ++i ) - { - if ( i == triangleIndex ) - { - continue; - } - - b3Triangle triangle = b3GetMeshTriangle( mesh, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - for ( int j = 0; j < 3; ++j ) - { - if ( indices[j] == b && indices[( j + 1 ) % 3] == a ) - { - *edgeIndex = j; - return i; - } - } - } - - return B3_NULL_INDEX; -} - -// Both sides of an edge store the same angle -static bool EdgeAnglesAreSymmetric( const b3MeshData* data, int* boundaryCount ) -{ - b3Mesh mesh = { .data = data, .scale = b3Vec3_one }; - const int8_t* edgeAngles = b3GetMeshEdgeAngles( data ); - *boundaryCount = 0; - - for ( int i = 0; i < data->triangleCount; ++i ) - { - b3Triangle triangle = b3GetMeshTriangle( &mesh, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - - for ( int k = 0; k < 3; ++k ) - { - int8_t angle = edgeAngles[3 * i + k]; - if ( angle == B3_BOUNDARY_EDGE_ANGLE ) - { - *boundaryCount += 1; - continue; - } - - int edgeIndex = -1; - int neighbor = FindNeighbor( &mesh, i, indices[k], indices[( k + 1 ) % 3], &edgeIndex ); - if ( neighbor == B3_NULL_INDEX || edgeAngles[3 * neighbor + edgeIndex] != angle ) - { - return false; - } - } - } - - return true; -} - -// The rebuilt neighbor normal must match the real one under any scale. A non-uniform scale -// stretches the quantization error by up to the ratio of its largest and smallest components. -static bool NeighborNormalsMatch( const b3MeshData* data, b3Vec3 scale ) -{ - b3Mesh mesh = { .data = data, .scale = scale }; - - b3Vec3 s = b3Abs( scale ); - float spread = b3MaxFloat( s.x, b3MaxFloat( s.y, s.z ) ) / b3MinFloat( s.x, b3MinFloat( s.y, s.z ) ); - float tolerance = 0.8f * spread * B3_PI / 180.0f; - float cosTolerance = cosf( tolerance ); - - for ( int i = 0; i < data->triangleCount; ++i ) - { - b3Triangle triangle = b3GetMeshTriangle( &mesh, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - - for ( int k = 0; k < 3; ++k ) - { - int edgeIndex = -1; - int neighbor = FindNeighbor( &mesh, i, indices[k], indices[( k + 1 ) % 3], &edgeIndex ); - - b3Vec3 rebuilt; - bool found = b3GetMeshNeighborNormal( &mesh, i, k, &rebuilt ); - if ( found != ( neighbor != B3_NULL_INDEX ) ) - { - return false; - } - - if ( found == false ) - { - continue; - } - - b3Triangle other = b3GetMeshTriangle( &mesh, neighbor ); - b3Vec3 e1 = b3Sub( other.vertices[1], other.vertices[0] ); - b3Vec3 e2 = b3Sub( other.vertices[2], other.vertices[0] ); - b3Vec3 actual = b3Normalize( b3Cross( e1, e2 ) ); - if ( b3Dot( rebuilt, actual ) < cosTolerance ) - { - return false; - } - } - } - - return true; -} - -// Positive angles are convex, negative are concave. A right angle sits on a rounding boundary. -static bool HasRightAngle( const b3MeshData* data, int sign ) -{ - const int8_t* edgeAngles = b3GetMeshEdgeAngles( data ); - for ( int i = 0; i < 3 * data->triangleCount; ++i ) - { - int angle = sign * edgeAngles[i]; - if ( angle == 63 || angle == 64 ) - { - return true; - } - } - - return false; -} - -static int MeshEdgeAngles( void ) -{ - { - b3MeshData* grid = b3CreateGridMesh( 4, 4, 1.0f, 0, true ); - ENSURE( b3GetMeshEdgeAngles( grid ) != NULL ); - - int boundaryCount = 0; - ENSURE( EdgeAnglesAreSymmetric( grid, &boundaryCount ) ); - ENSURE( boundaryCount == 16 ); - - const int8_t* edgeAngles = b3GetMeshEdgeAngles( grid ); - for ( int i = 0; i < 3 * grid->triangleCount; ++i ) - { - ENSURE( edgeAngles[i] == 0 || edgeAngles[i] == B3_BOUNDARY_EDGE_ANGLE ); - } - - b3DestroyMesh( grid ); - } - - { - b3MeshData* grid = b3CreateGridMesh( 4, 4, 1.0f, 0, false ); - ENSURE( b3GetMeshEdgeAngles( grid ) == NULL ); - b3DestroyMesh( grid ); - } - - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - b3MeshDef def = MakeValleyDef( vertices, indices ); - - b3MeshData* meshes[] = { - b3CreateMesh( &def, NULL, 0 ), - b3CreateBoxMesh( b3Vec3_zero, (b3Vec3){ 1.0f, 2.0f, 3.0f }, true ), - b3CreateWaveMesh( 8, 8, 1.0f, 0.5f, 0.2f, 0.15f ), - b3CreateTorusMesh( 8, 6, 2.0f, 0.5f ), - }; - - b3MeshData* valley = meshes[0]; - b3MeshData* box = meshes[1]; - ENSURE( HasRightAngle( valley, -1 ) ); - ENSURE( HasRightAngle( box, 1 ) ); - - int boundaryCount = 0; - ENSURE( EdgeAnglesAreSymmetric( box, &boundaryCount ) ); - ENSURE( boundaryCount == 0 ); - - b3Vec3 scales[] = { - { 1.0f, 1.0f, 1.0f }, { 3.0f, 3.0f, 3.0f }, { -1.0f, 1.0f, 1.0f }, - { 2.0f, 0.5f, 1.5f }, { 0.5f, -2.0f, 1.0f }, { -1.0f, -1.0f, -1.0f }, - }; - - for ( int i = 0; i < ARRAY_COUNT( meshes ); ++i ) - { - ENSURE( meshes[i] != NULL ); - ENSURE( EdgeAnglesAreSymmetric( meshes[i], &boundaryCount ) ); - - for ( int j = 0; j < ARRAY_COUNT( scales ); ++j ) - { - ENSURE( NeighborNormalsMatch( meshes[i], scales[j] ) ); - } - - b3DestroyMesh( meshes[i] ); - } - - { - // Three triangles on edge 0-1 are non-manifold. The last two share edge 5-6 walked the - // same way, which is inconsistent winding. Neither gets an angle. - b3Vec3 finVertices[] = { - { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, { 0.0f, 0.0f, -1.0f }, - { 0.0f, 1.0f, 0.0f }, { 5.0f, 0.0f, 0.0f }, { 5.0f, 0.0f, 1.0f }, { 5.0f, 1.0f, 0.0f }, - }; - - int32_t finIndices[] = { - 0, 1, 2, 1, 0, 3, 0, 1, 4, 5, 6, 7, 5, 6, 2, - }; - - b3MeshDef finDef = { 0 }; - finDef.vertices = finVertices; - finDef.vertexCount = ARRAY_COUNT( finVertices ); - finDef.indices = finIndices; - finDef.triangleCount = ARRAY_COUNT( finIndices ) / 3; - finDef.identifyEdges = true; - b3MeshData* fin = b3CreateMesh( &finDef, NULL, 0 ); - ENSURE( fin != NULL ); - - ENSURE( EdgeAnglesAreSymmetric( fin, &boundaryCount ) ); - ENSURE( boundaryCount == 15 ); - b3DestroyMesh( fin ); - } - - return 0; -} - -// A wide box sliding over a fine grid sits on hundreds of flat internal edges. With no friction -// any manifold off the face normal is a ghost that slows or lifts the box. -static int WideHullSlide( b3Vec3 meshScale ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3MeshData* mesh = b3CreateGridMesh( 120, 40, 0.25f, 0, true ); - ENSURE( mesh != NULL ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, mesh, meshScale ); - - float speed = 4.0f; - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -10.0f, 0.5f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ speed, 0.0f, 0.0f }; - b3BodyId boxId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 1.25f, 0.5f, 1.25f ); - shapeDef.baseMaterial.friction = 0.0f; - b3CreateHullShape( boxId, &shapeDef, &box.base ); - - int ghostCount = 0; - for ( int step = 0; step < 120; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3ContactData contacts[4]; - int contactCount = b3Body_GetContactData( boxId, contacts, ARRAY_COUNT( contacts ) ); - for ( int i = 0; i < contactCount; ++i ) - { - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - if ( b3AbsFloat( contacts[i].manifolds[j].normal.y ) < 0.99f ) - { - ghostCount += 1; - } - } - } - } - - b3Vec3 velocity = b3Body_GetLinearVelocity( boxId ); - - ENSURE( ghostCount == 0 ); - ENSURE( velocity.x > 0.99f * speed ); - ENSURE( b3AbsFloat( velocity.y ) < 0.01f ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -// The box overlaps more than a thousand grid triangles. All of them must reach the narrow -// phase, so the reduced manifold reaches all four sides of the footprint. -static int MeshManyTriangles( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3MeshData* mesh = b3CreateGridMesh( 40, 40, 0.25f, 0, true ); - ENSURE( mesh != NULL ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one ); - - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.5f, 0.0f }; - b3BodyId boxId = b3CreateBody( worldId, &bodyDef ); - - b3BoxHull box = b3MakeBoxHull( 3.0f, 0.5f, 3.0f ); - b3ShapeId boxShapeId = b3CreateHullShape( boxId, &shapeDef, &box.base ); - - for ( int step = 0; step < 30; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3Pos position = b3Body_GetPosition( boxId ); - b3Quat rotation = b3Body_GetRotation( boxId ); - - ENSURE( b3AbsFloat( (float)position.y - 0.5f ) < 0.02f ); - ENSURE( b3AbsFloat( rotation.v.x ) < 0.001f ); - ENSURE( b3AbsFloat( rotation.v.z ) < 0.001f ); - - b3Vec3 lower = { FLT_MAX, FLT_MAX, FLT_MAX }; - b3Vec3 upper = { -FLT_MAX, -FLT_MAX, -FLT_MAX }; - - b3ContactData contacts[4]; - int contactCount = b3Body_GetContactData( boxId, contacts, ARRAY_COUNT( contacts ) ); - for ( int i = 0; i < contactCount; ++i ) - { - bool boxIsA = B3_ID_EQUALS( contacts[i].shapeIdA, boxShapeId ); - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - const b3Manifold* manifold = contacts[i].manifolds + j; - for ( int k = 0; k < manifold->pointCount; ++k ) - { - b3Vec3 anchor = boxIsA ? manifold->points[k].anchorA : manifold->points[k].anchorB; - lower = b3Min( lower, anchor ); - upper = b3Max( upper, anchor ); - } - } - } - - ENSURE( lower.x < -2.5f && upper.x > 2.5f ); - ENSURE( lower.z < -2.5f && upper.z > 2.5f ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -// The grid is symmetric in x, so the mirror only changes the winding -static int MeshWideHullSlide( void ) -{ - ENSURE( WideHullSlide( b3Vec3_one ) == 0 ); - ENSURE( WideHullSlide( (b3Vec3){ -1.0f, 1.0f, 1.0f } ) == 0 ); - return 0; -} - -static bool HasVertex( const b3MeshData* mesh, int triangleIndex, b3Vec3 point ) -{ - const b3MeshTriangle* triangle = b3GetMeshTriangles( mesh ) + triangleIndex; - const b3Vec3* vertices = b3GetMeshVertices( mesh ); - int indices[3] = { triangle->index1, triangle->index2, triangle->index3 }; - for ( int i = 0; i < 3; ++i ) - { - if ( b3DistanceSquared( vertices[indices[i]], point ) < 1.0e-8f ) - { - return true; - } - } - - return false; -} - -// A box face rests on a ridge that runs into a rising wall, so the ridge end is a saddle vertex. The -// ridge sags slightly away from the saddle, leaving the saddle the deepest point by less than linear -// slop. The ridge edge admits the up normal and the saddle cone does not, so the deepest points have -// to be taken as the edge they span, not as the single deepest vertex, or the contact snaps to a slope. -static int MeshHullOnSaddleRidge( void ) -{ - b3Vec3 ridgeStart = { -2.0f, -0.004f, 0.0f }; - b3Vec3 saddle = { 0.0f, 0.0f, 0.0f }; - - b3Vec3 vertices[] = { - { -2.0f, -0.7f, -1.0f }, - ridgeStart, - { -2.0f, -0.7f, 1.0f }, - { 0.0f, -0.7f, -1.0f }, - saddle, - { 0.0f, -0.7f, 1.0f }, - { 1.0f, -0.4f, -1.0f }, - { 1.0f, 0.3f, 0.0f }, - { 1.0f, -0.4f, 1.0f }, - }; - - int32_t indices[] = { - 0, 1, 3, 3, 1, 4, 1, 2, 4, 4, 2, 5, 3, 4, 6, 6, 4, 7, 4, 5, 7, 7, 5, 8, - }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.vertexCount = ARRAY_COUNT( vertices ); - def.indices = indices; - def.triangleCount = ARRAY_COUNT( indices ) / 3; - def.identifyEdges = true; - b3MeshData* meshData = b3CreateMesh( &def, NULL, 0 ); - ENSURE( meshData != NULL ); - - // The footprint covers the saddle and a stretch of the ridge, slightly overlapping - float hy = 0.1f; - b3BoxHull box = b3MakeBoxHull( 0.46f, hy, 0.5f ); - b3Transform transform = { { -0.44f, hy - 0.004f, 0.0f }, b3Quat_identity }; - - b3Mesh mesh = { .data = meshData, .scale = b3Vec3_one }; - b3Manifold manifolds[16]; - int manifoldCount = - b3CollideMeshAndHull( manifolds, ARRAY_COUNT( manifolds ), &mesh, &box.base, transform, true, true ); - - int ridgePointCount = 0; - for ( int i = 0; i < manifoldCount; ++i ) - { - const b3Manifold* manifold = manifolds + i; - for ( int j = 0; j < manifold->pointCount; ++j ) - { - int triangleIndex = manifold->points[j].triangleIndex; - if ( HasVertex( meshData, triangleIndex, ridgeStart ) && HasVertex( meshData, triangleIndex, saddle ) ) - { - ridgePointCount += 1; - ENSURE( manifold->normal.y > 0.999f ); - } - } - } - - ENSURE( ridgePointCount > 0 ); - - b3DestroyMesh( meshData ); - return 0; -} - -// A sphere balanced on a convex ridge is held up by edge contacts alone. Their normals lie between -// the two face normals, so neighbor validation must keep them. -static int MeshSphereOnRidge( void ) -{ - b3Vec3 vertices[] = { - { -2.0f, -0.7f, -1.0f }, { 0.0f, 0.0f, -1.0f }, { 2.0f, -0.7f, -1.0f }, - { -2.0f, -0.7f, 1.0f }, { 0.0f, 0.0f, 1.0f }, { 2.0f, -0.7f, 1.0f }, - }; - - int32_t indices[] = { - 0, 3, 1, 3, 4, 1, 1, 4, 2, 4, 5, 2, - }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.vertexCount = ARRAY_COUNT( vertices ); - def.indices = indices; - def.triangleCount = ARRAY_COUNT( indices ) / 3; - def.identifyEdges = true; - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - ENSURE( mesh != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one ); - - float radius = 0.25f; - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, radius, 0.0f }; - b3BodyId sphereId = b3CreateBody( worldId, &bodyDef ); - b3Sphere sphere = { b3Vec3_zero, radius }; - b3CreateSphereShape( sphereId, &shapeDef, &sphere ); - - for ( int step = 0; step < 30; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3ContactData contacts[4]; - int contactCount = b3Body_GetContactData( sphereId, contacts, ARRAY_COUNT( contacts ) ); - ENSURE( contactCount == 1 ); - ENSURE( contacts[0].manifoldCount >= 1 ); - - for ( int j = 0; j < contacts[0].manifoldCount; ++j ) - { - ENSURE( b3AbsFloat( contacts[0].manifolds[j].normal.y ) > 0.99f ); - } - } - - b3Pos position = b3Body_GetPosition( sphereId ); - ENSURE( position.y > 0.9f * radius ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -// The normal points from the mesh to the body. Any normal in the span of the face normals under -// the body is real, anything else is a ghost. -static bool IsProfileGhost( const b3Vec2* profile, int count, b3Vec3 normal, float xMin, float xMax ) -{ - float tolerance = 5.0f * B3_PI / 180.0f; - if ( b3AbsFloat( normal.z ) > sinf( tolerance ) ) - { - return true; - } - - float lower = B3_PI; - float upper = -B3_PI; - for ( int k = 0; k + 1 < count; ++k ) - { - if ( profile[k + 1].x < xMin || xMax < profile[k].x ) - { - continue; - } - - b3Vec2 a = profile[k]; - b3Vec2 b = profile[k + 1]; - float angle = atan2f( b.x - a.x, a.y - b.y ); - lower = b3MinFloat( lower, angle ); - upper = b3MaxFloat( upper, angle ); - } - - float angle = atan2f( normal.y, normal.x ); - return angle < lower - tolerance || upper + tolerance < angle; -} - -// A capsule lying across the slide direction crosses a 5.7 degree crest at speed, like the crest -// scene in the ghost collision sample. The edges are flat, convex and concave, and a capsule edge -// contact on the wrong side of a fold kicks the capsule. -static int CapsuleOverCrest( bool mirror ) -{ - b3Vec2 profile[] = { { -20.0f, 0.0f }, { -10.0f, 0.0f }, { 0.0f, 1.0f }, { 10.0f, 0.0f }, { 20.0f, 0.0f } }; - int profileCount = ARRAY_COUNT( profile ); - - // Quarter meter cells with alternating diagonals, like cooked level geometry - float cellSize = 0.25f; - b3Vec2 points[256]; - int pointCount = 0; - points[pointCount++] = profile[0]; - for ( int k = 0; k + 1 < profileCount; ++k ) - { - b3Vec2 a = profile[k]; - b3Vec2 b = profile[k + 1]; - float length = sqrtf( ( b.x - a.x ) * ( b.x - a.x ) + ( b.y - a.y ) * ( b.y - a.y ) ); - int n = (int)ceilf( length / cellSize - 0.01f ); - for ( int s = 1; s <= n; ++s ) - { - ENSURE( pointCount < ARRAY_COUNT( points ) ); - float t = (float)s / (float)n; - points[pointCount++] = (b3Vec2){ a.x + t * ( b.x - a.x ), a.y + t * ( b.y - a.y ) }; - } - } - - // Mirror the data and flip it back with the mesh scale, so the world geometry is the same - float halfWidth = 3.0f; - int zCount = 24; - int stride = zCount + 1; - float sign = mirror ? -1.0f : 1.0f; - - int vertexCount = pointCount * stride; - b3Vec3* vertices = malloc( vertexCount * sizeof( b3Vec3 ) ); - for ( int i = 0; i < pointCount; ++i ) - { - for ( int j = 0; j <= zCount; ++j ) - { - float z = -halfWidth + 2.0f * halfWidth * (float)j / (float)zCount; - vertices[i * stride + j] = (b3Vec3){ sign * points[i].x, points[i].y, z }; - } - } - - int triangleCount = 2 * ( pointCount - 1 ) * zCount; - int32_t* indices = malloc( 3 * triangleCount * sizeof( int32_t ) ); - int indexCount = 0; - for ( int i = 0; i + 1 < pointCount; ++i ) - { - for ( int j = 0; j < zCount; ++j ) - { - int a = i * stride + j; - int b = a + 1; - int c = a + stride + 1; - int d = a + stride; - - int corners[6] = { a, b, c, c, d, a }; - if ( ( i + j ) & 1 ) - { - int alternate[6] = { a, b, d, b, c, d }; - memcpy( corners, alternate, sizeof( corners ) ); - } - - for ( int k = 0; k < 6; k += 3 ) - { - indices[indexCount++] = corners[k]; - indices[indexCount++] = mirror ? corners[k + 2] : corners[k + 1]; - indices[indexCount++] = mirror ? corners[k + 1] : corners[k + 2]; - } - } - } - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.vertexCount = vertexCount; - def.indices = indices; - def.triangleCount = triangleCount; - def.identifyEdges = true; - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - free( vertices ); - free( indices ); - ENSURE( mesh != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Vec3 scale = mirror ? (b3Vec3){ -1.0f, 1.0f, 1.0f } : b3Vec3_one; - b3CreateMeshShape( groundId, &shapeDef, mesh, scale ); - - float radius = 0.2f; - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -16.0f, radius + 0.01f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 6.0f, 0.0f, 0.0f }; - bodyDef.enableSleep = false; - b3BodyId capsuleId = b3CreateBody( worldId, &bodyDef ); - - b3Capsule capsule = { { 0.0f, 0.0f, -0.4f }, { 0.0f, 0.0f, 0.4f }, radius }; - shapeDef.baseMaterial.friction = 0.0f; - b3ShapeId capsuleShapeId = b3CreateCapsuleShape( capsuleId, &shapeDef, &capsule ); - - int ghostCount = 0; - for ( int step = 0; step < 600 && b3Body_GetPosition( capsuleId ).x < 15.0f; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3AABB bounds = b3Shape_GetAABB( capsuleShapeId ); - float xMin = (float)bounds.lowerBound.x - 0.1f; - float xMax = (float)bounds.upperBound.x + 0.1f; - - b3ContactData contacts[4]; - int contactCount = b3Body_GetContactData( capsuleId, contacts, ARRAY_COUNT( contacts ) ); - for ( int i = 0; i < contactCount; ++i ) - { - bool capsuleIsA = B3_ID_EQUALS( contacts[i].shapeIdA, capsuleShapeId ); - for ( int j = 0; j < contacts[i].manifoldCount; ++j ) - { - const b3Manifold* manifold = contacts[i].manifolds + j; - - // Speculative points that never pushed are harmless - float impulse = 0.0f; - for ( int k = 0; k < manifold->pointCount; ++k ) - { - impulse += manifold->points[k].totalNormalImpulse; - } - - b3Vec3 normal = capsuleIsA ? b3Neg( manifold->normal ) : manifold->normal; - if ( impulse > 0.0f && IsProfileGhost( profile, profileCount, normal, xMin, xMax ) ) - { - ghostCount += 1; - } - } - } - } - - ENSURE( ghostCount == 0 ); - ENSURE( b3Body_GetPosition( capsuleId ).x >= 15.0f ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -static int MeshCapsuleOverCrest( void ) -{ - ENSURE( CapsuleOverCrest( false ) == 0 ); - ENSURE( CapsuleOverCrest( true ) == 0 ); - return 0; -} - -// Fires a sphere or the end of a capsule at the apex along the given direction, without gravity, -// and returns the deepest separation from the apex. -static float ApexImpact( b3MeshData* mesh, b3Vec3 direction, bool useCapsule ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateMeshShape( groundId, &shapeDef, mesh, b3Vec3_one ); - - float radius = 0.25f; - bodyDef.type = b3_dynamicBody; - bodyDef.position = b3ToPos( b3MulSV( radius + 0.1f, direction ) ); - bodyDef.linearVelocity = b3MulSV( -2.0f, direction ); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - // The capsule points away from the apex, so its lower end is the closest point - b3Vec3 tip = b3MulSV( 0.5f, direction ); - if ( useCapsule ) - { - b3Capsule capsule = { b3Vec3_zero, tip, radius }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - } - else - { - b3Sphere sphere = { b3Vec3_zero, radius }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - } - - float minSeparation = FLT_MAX; - for ( int step = 0; step < 60; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3Pos p1 = b3Body_GetWorldPoint( bodyId, b3Vec3_zero ); - b3Pos p2 = b3Body_GetWorldPoint( bodyId, useCapsule ? tip : b3Vec3_zero ); - b3Vec3 a = b3ToVec3( p1 ); - b3Vec3 segment = b3Sub( b3ToVec3( p2 ), a ); - float lengthSquared = b3LengthSquared( segment ); - float t = lengthSquared > 0.0f ? b3ClampFloat( -b3Dot( a, segment ) / lengthSquared, 0.0f, 1.0f ) : 0.0f; - float distance = b3Length( b3MulAdd( a, t, segment ) ); - minSeparation = b3MinFloat( minSeparation, distance - radius ); - } - - b3DestroyWorld( worldId ); - return minSeparation; -} - -// A vertex manifold that fails a neighbor test is dropped. That relies on some triangle around a -// convex vertex admitting every normal in the vertex normal cone. On this irregular valence 6 apex -// each direction is inside the cone and exactly one of the six triangles admits it. -static int MeshApexContact( void ) -{ - b3Vec3 vertices[] = { - { 0.0f, 0.0f, 0.0f }, { 1.08f, -1.9f, -0.45f }, { -1.1f, -0.89f, -0.35f }, { -1.73f, -1.91f, -0.06f }, - { -0.8f, -1.45f, 0.27f }, { 0.35f, -1.63f, 0.35f }, { 0.79f, -1.96f, 0.07f }, - }; - - int32_t indices[] = { - 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, - }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.vertexCount = ARRAY_COUNT( vertices ); - def.indices = indices; - def.triangleCount = ARRAY_COUNT( indices ) / 3; - def.identifyEdges = true; - b3MeshData* mesh = b3CreateMesh( &def, NULL, 0 ); - ENSURE( mesh != NULL ); - - b3Vec3 directions[] = { - { -0.5703f, 0.7369f, 0.3629f }, - { 0.8019f, 0.4956f, 0.3337f }, - }; - - // Dropping every vertex manifold here lets the body sink a full step before the deep overlap - // fallback catches it - for ( int i = 0; i < ARRAY_COUNT( directions ); ++i ) - { - b3Vec3 direction = b3Normalize( directions[i] ); - ENSURE( ApexImpact( mesh, direction, false ) > -B3_LINEAR_SLOP ); - ENSURE( ApexImpact( mesh, direction, true ) > -B3_LINEAR_SLOP ); - } - - b3DestroyMesh( mesh ); - return 0; -} - -// Runs a Mesh / Ghost Collisions scene with the cylinder and returns the ghost count -static int CountCylinderGhosts( GhostScene scene, int peelPreset, bool mirror, int* runCount ) -{ - GhostSettings settings = GetDefaultGhostSettings(); - settings.scene = scene; - settings.peelPreset = peelPreset; - settings.body = e_ghostCylinder; - settings.mirror = mirror; - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - GhostCollisionsData data = CreateGhostCollisions( worldId, settings ); - - for ( int step = 0; step < 900; ++step ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - UpdateGhostCollisions( worldId, &data, NULL, 0 ); - } - - *runCount = data.runCount; - int ghostCount = data.ghostCount; - - b3DestroyWorld( worldId ); - DestroyGhostCollisions( &data ); - return ghostCount; -} - -// The PEEL cylinder slides along its axis on a polygon edge that runs along an internal edge of the -// strip. Deep edge contacts on the far side fail the neighbor test and their face snap is empty, so -// the triangles under the cylinder own the contact. -static int MeshPeelCylinder( void ) -{ - int runCount; - ENSURE( CountCylinderGhosts( e_ghostInternal, 2, false, &runCount ) == 0 ); - ENSURE( runCount >= 1 ); - return 0; -} - -// Exact vertex cone from every triangle at the vertex. Returns the largest lean of the normal past -// an edge at the vertex or past the cliff below a boundary edge. -static float ExactVertexLean( const b3Mesh* mesh, int vertex, b3Vec3 normal ) -{ - float lean = -FLT_MAX; - for ( int i = 0; i < mesh->data->triangleCount; ++i ) - { - b3Triangle triangle = b3GetMeshTriangle( mesh, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - int k = indices[0] == vertex ? 0 : ( indices[1] == vertex ? 1 : ( indices[2] == vertex ? 2 : -1 ) ); - if ( k < 0 ) - { - continue; - } - - int next = ( k + 1 ) % 3; - int previous = ( k + 2 ) % 3; - b3Vec3 edges[2] = { b3Sub( triangle.vertices[next], triangle.vertices[k] ), - b3Sub( triangle.vertices[previous], triangle.vertices[k] ) }; - int edgeIndices[2] = { k, previous }; - b3Vec3 faceNormal = b3MakeNormalFromPoints( triangle.vertices[0], triangle.vertices[1], triangle.vertices[2] ); - - for ( int j = 0; j < 2; ++j ) - { - lean = b3MaxFloat( lean, b3Dot( normal, b3Normalize( edges[j] ) ) ); - - b3Vec3 neighborNormal; - if ( b3GetMeshNeighborNormal( mesh, i, edgeIndices[j], &neighborNormal ) == false ) - { - lean = b3MaxFloat( lean, -b3Dot( normal, faceNormal ) ); - } - } - } - - return lean; -} - -static uint32_t NextRandom( uint32_t* state ) -{ - *state = *state * 1664525u + 1013904223u; - return *state; -} - -static float RandomFloat( uint32_t* state ) -{ - return (float)( NextRandom( state ) >> 8 ) / (float)( 1 << 24 ) * 2.0f - 1.0f; -} - -// The quantized ring must admit normals well inside the exact cone and reject normals well outside. -// The band between is quantization noise. A non-uniform scale stretches it. -static bool VertexRingMatches( const b3MeshData* data, b3Vec3 scale, int* insideCount, int* outsideCount ) -{ - b3Mesh mesh = { .data = data, .scale = scale }; - - b3Vec3 s = b3Abs( scale ); - float spread = b3MaxFloat( s.x, b3MaxFloat( s.y, s.z ) ) / b3MinFloat( s.x, b3MinFloat( s.y, s.z ) ); - float tolerance = 0.0175f; - float margin = 0.025f * spread; - uint32_t state = 12345; - - for ( int i = 0; i < data->triangleCount; ++i ) - { - b3Triangle triangle = b3GetMeshTriangle( &mesh, i ); - int indices[3] = { triangle.i1, triangle.i2, triangle.i3 }; - b3Vec3 faceNormal = b3MakeNormalFromPoints( triangle.vertices[0], triangle.vertices[1], triangle.vertices[2] ); - - for ( int k = 0; k < 3; ++k ) - { - b3Vec3 samples[24]; - int sampleCount = 0; - samples[sampleCount++] = faceNormal; - - // Fan normals and their blends land near the cone - for ( int j = 0; j < data->triangleCount && sampleCount < 12; ++j ) - { - b3Triangle other = b3GetMeshTriangle( &mesh, j ); - if ( j == i || ( other.i1 != indices[k] && other.i2 != indices[k] && other.i3 != indices[k] ) ) - { - continue; - } - - b3Vec3 otherNormal = b3MakeNormalFromPoints( other.vertices[0], other.vertices[1], other.vertices[2] ); - samples[sampleCount++] = otherNormal; - samples[sampleCount++] = b3Normalize( b3Add( faceNormal, otherNormal ) ); - } - - while ( sampleCount < 24 ) - { - b3Vec3 tilt = { RandomFloat( &state ), RandomFloat( &state ), RandomFloat( &state ) }; - float amount = sampleCount % 2 == 0 ? 0.1f : 1.0f; - samples[sampleCount++] = b3Normalize( b3MulAdd( faceNormal, amount, tilt ) ); - } - - for ( int j = 0; j < sampleCount; ++j ) - { - b3Vec3 normal = samples[j]; - float lean = ExactVertexLean( &mesh, indices[k], normal ); - bool admit = b3IsInMeshVertexRing( &mesh, i, k, normal, tolerance ); - - if ( lean <= tolerance - margin ) - { - *insideCount += 1; - if ( admit == false ) - { - return false; - } - } - else if ( lean > tolerance + margin ) - { - *outsideCount += 1; - if ( admit ) - { - return false; - } - } - } - } - } - - return true; -} - -static int MeshVertexRing( void ) -{ - b3Vec3 vertices[VALLEY_VERTEX_COUNT]; - int32_t indices[3 * VALLEY_TRIANGLE_COUNT]; - MakeValley( vertices, indices ); - b3MeshDef def = MakeValleyDef( vertices, indices ); - - b3MeshData* meshes[] = { - b3CreateMesh( &def, NULL, 0 ), - b3CreateBoxMesh( b3Vec3_zero, (b3Vec3){ 1.0f, 2.0f, 3.0f }, true ), - b3CreateWaveMesh( 8, 8, 1.0f, 0.5f, 0.2f, 0.15f ), - b3CreateTorusMesh( 8, 6, 2.0f, 0.5f ), - b3CreateGridMesh( 4, 4, 1.0f, 0, true ), - }; - - b3Vec3 scales[] = { - { 1.0f, 1.0f, 1.0f }, { 3.0f, 3.0f, 3.0f }, { -1.0f, 1.0f, 1.0f }, - { 2.0f, 0.5f, 1.5f }, { 0.5f, -2.0f, 1.0f }, { -1.0f, -1.0f, -1.0f }, - }; - - for ( int i = 0; i < ARRAY_COUNT( meshes ); ++i ) - { - ENSURE( meshes[i] != NULL ); - - for ( int j = 0; j < ARRAY_COUNT( scales ); ++j ) - { - int insideCount = 0; - int outsideCount = 0; - ENSURE( VertexRingMatches( meshes[i], scales[j], &insideCount, &outsideCount ) ); - ENSURE( insideCount > 0 && outsideCount > 0 ); - } - - b3DestroyMesh( meshes[i] ); - } - - // Without edge data every normal passes - b3MeshData* bare = b3CreateGridMesh( 4, 4, 1.0f, 0, false ); - b3Mesh mesh = { .data = bare, .scale = b3Vec3_one }; - ENSURE( b3IsInMeshVertexRing( &mesh, 0, 0, (b3Vec3){ 1.0f, 0.0f, 0.0f }, 0.0175f ) ); - b3DestroyMesh( bare ); - - return 0; -} - -/// Separated poses have an exact reference, the union of the triangles, see ghost_oracle.h. Without ghost -// handling the oracle has to find ghosts in every scene, which shows it has teeth. -// -// With ghost handling a pose fails as a ghost when a manifold carries a normal the union lacks at its -// deep points, and as a miss when the union closest pair goes unrepresented with ghost handling but not -// without it. Both are rare rather than absent, so each has a budget holding the current count. The -// counts belong to the first ORACLE_SCAN_POSES poses, so a change to a scene or to the pose stream moves -// them without the collider changing. Lower a budget when a case is fixed. -// -// The remaining ghost, wave pose 291, is a hull face normal admitted by a vertex cone with the deepest -// point half a linear slop from the vertex, where the oracle only accepts the normal at the vertex. -static int MeshGhostOracle( void ) -{ - int ghostBudget[e_oracleSceneCount] = { 0, 0, 0, 0, 0, 0, 0, 1 }; - int missedBudget[e_oracleSceneCount] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - - for ( int scene = 0; scene < e_oracleSceneCount; ++scene ) - { - b3MeshData* mesh = CreateOracleMesh( (OracleScene)scene ); - ENSURE( mesh != NULL ); - - OracleScan scan = ScanGhostOracle( mesh, (OracleScene)scene, ORACLE_SCAN_POSES ); - b3DestroyMesh( mesh ); - - if ( scan.validCount <= ORACLE_SCAN_POSES / 2 || scan.rawGhostPoses == 0 || scan.ghostPoses != ghostBudget[scene] || - scan.missedPoses != missedBudget[scene] ) - { - printf( " oracle %s: valid %d, unhandled ghosts %d, ghosts %d of %d (first pose %d), missed %d of %d " - "(first pose %d)\n", - g_oracleSceneNames[scene], scan.validCount, scan.rawGhostPoses, scan.ghostPoses, ghostBudget[scene], - scan.firstGhost, scan.missedPoses, missedBudget[scene], scan.firstMissed ); - } - - ENSURE( scan.validCount > ORACLE_SCAN_POSES / 2 ); - ENSURE( scan.rawGhostPoses > 0 ); - ENSURE( scan.ghostPoses <= ghostBudget[scene] ); - ENSURE( scan.missedPoses <= missedBudget[scene] ); - } - - return 0; -} - -int MeshTest( void ) -{ - RUN_SUBTEST( MeshDenseStride ); - RUN_SUBTEST( MeshFatStride ); - RUN_SUBTEST( MeshStrideWeld ); - RUN_SUBTEST( MeshClockWise ); - RUN_SUBTEST( MeshClockWiseIgnored ); - RUN_SUBTEST( MeshClockWiseStrideWeld ); - RUN_SUBTEST( MeshCreators ); - RUN_SUBTEST( MeshWideHullSlide ); - RUN_SUBTEST( MeshManyTriangles ); - RUN_SUBTEST( MeshEdgeAngles ); - RUN_SUBTEST( MeshVertexRing ); - RUN_SUBTEST( MeshSphereOnRidge ); - RUN_SUBTEST( MeshHullOnSaddleRidge ); - RUN_SUBTEST( MeshCapsuleOverCrest ); - RUN_SUBTEST( MeshApexContact ); - RUN_SUBTEST( MeshPeelCylinder ); - RUN_SUBTEST( MeshGhostOracle ); - - return 0; -} diff --git a/test/test_mover.c b/test/test_mover.c index b82ab4e..89e16ca 100644 --- a/test/test_mover.c +++ b/test/test_mover.c @@ -6,7 +6,6 @@ // b3CollideMoverAndSphere / Capsule / Hull are internal #include "shape.h" -#include "box3d/box3d.h" #include "box3d/collision.h" static int ParallelPlanes( void ) @@ -55,11 +54,15 @@ static int GamePlanes( void ) return 0; } +// --------------------------------------------------------------------------- // Mover-collide overlap handling +// // b3CollideMoverAndSphere / Capsule / Hull must never emit a plane with a // degenerate (zero) normal, even when the mover deeply penetrates the shape. // On deep overlap the GJK path returns a {0,0,0} normal; these tests guard the // fix that replaces it with an analytic (sphere/capsule) or dropped (hull) result. +// --------------------------------------------------------------------------- + static int MoverSphereSeparated( void ) { b3Sphere shape = { { 0.0f, 0.0f, 0.0f }, 0.5f }; @@ -230,467 +233,6 @@ static int MoverHullDeepOverlap( void ) return 0; } -// Mover queries report which material a contact plane came from -// b3PlaneResult::materialIndex follows different paths per shape type. Meshes -// report the per triangle material index. Compounds remap the child result -// through the child material table. Convex shapes report index 0. -static b3SurfaceMaterial MakeMaterial( float friction, uint64_t userId ) -{ - b3SurfaceMaterial m = b3DefaultSurfaceMaterial(); - m.friction = friction; - m.userMaterialId = userId; - return m; -} - -// Two separated upward facing triangles on the y = 0 plane, one per material. The bake may -// reorder triangles but always keeps a triangle paired with its material index. -static b3MeshData* MakeTwoMaterialMesh( void ) -{ - b3Vec3 vertices[6] = { - { -3.0f, 0.0f, -1.0f }, { -2.0f, 0.0f, 1.0f }, { -1.0f, 0.0f, -1.0f }, - { 1.0f, 0.0f, -1.0f }, { 2.0f, 0.0f, 1.0f }, { 3.0f, 0.0f, -1.0f }, - }; - int32_t indices[6] = { 0, 1, 2, 3, 4, 5 }; - uint8_t materialIndices[2] = { 0, 1 }; - - b3MeshDef def = { 0 }; - def.vertices = vertices; - def.stride = sizeof( b3Vec3 ); - def.indices = indices; - def.materialIndices = materialIndices; - def.vertexCount = 6; - def.triangleCount = 2; - - return b3CreateMesh( &def, NULL, 0 ); -} - -// Flat 3x3 vertex field at y = 0, one cell material per entry. Caller destroys. -static b3HeightFieldData* MakeFlatField( uint8_t* materials, bool clockwise ) -{ - float heights[9] = { 0 }; - - b3HeightFieldDef def = { 0 }; - def.heights = heights; - def.materialIndices = materials; - def.scale = (b3Vec3){ 1.0f, 1.0f, 1.0f }; - def.countX = 3; - def.countZ = 3; - def.globalMinimumHeight = -1.0f; - def.globalMaximumHeight = 1.0f; - def.clockwiseWinding = clockwise; - - return b3CreateHeightField( &def ); -} - -typedef struct PlaneCapture -{ - b3PlaneResult planes[16]; - int count; -} PlaneCapture; - -static bool CapturePlaneFcn( b3ShapeId shapeId, const b3PlaneResult* planes, int planeCount, void* context ) -{ - (void)shapeId; - PlaneCapture* capture = context; - for ( int i = 0; i < planeCount && capture->count < 16; ++i ) - { - capture->planes[capture->count++] = planes[i]; - } - return true; -} - -static int MoverWorldMeshMaterials( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MeshData* mesh = MakeTwoMaterialMesh(); - ENSURE( mesh != NULL ); - ENSURE( mesh->materialCount == 2 ); - - b3SurfaceMaterial materials[2] = { MakeMaterial( 0.2f, 1 ), MakeMaterial( 0.8f, 2 ) }; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.materials = materials; - shapeDef.materialCount = 2; - b3CreateMeshShape( bodyId, &shapeDef, mesh, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - - b3World_Step( worldId, 1.0f / 60.0f, 1 ); - - const uint8_t* bakedMaterialIndices = b3GetMeshMaterialIndices( mesh ); - - // Mover hanging just above the first triangle so its radius reaches 0.05 into the surface - b3Capsule mover = { { -2.0f, 0.15f, 0.0f }, { -2.0f, 0.35f, 0.0f }, 0.2f }; - - PlaneCapture capture = { 0 }; - b3World_CollideMover( worldId, b3Pos_zero, &mover, b3DefaultQueryFilter(), CapturePlaneFcn, &capture ); - - ENSURE( capture.count == 1 ); - ENSURE( capture.planes[0].plane.normal.y > 0.99f ); - ENSURE_SMALL( capture.planes[0].plane.offset - 0.05f, 1e-4f ); - ENSURE_SMALL( capture.planes[0].point.y, 1e-4f ); - ENSURE( capture.planes[0].materialIndex == 0 ); - ENSURE( capture.planes[0].triangleIndex >= 0 ); - ENSURE( capture.planes[0].triangleIndex < mesh->triangleCount ); - ENSURE( bakedMaterialIndices[capture.planes[0].triangleIndex] == 0 ); - - // Same mover over the second triangle - b3Capsule mover2 = { { 2.0f, 0.15f, 0.0f }, { 2.0f, 0.35f, 0.0f }, 0.2f }; - - PlaneCapture capture2 = { 0 }; - b3World_CollideMover( worldId, b3Pos_zero, &mover2, b3DefaultQueryFilter(), CapturePlaneFcn, &capture2 ); - - ENSURE( capture2.count == 1 ); - ENSURE( capture2.planes[0].plane.normal.y > 0.99f ); - ENSURE( capture2.planes[0].materialIndex == 1 ); - ENSURE( bakedMaterialIndices[capture2.planes[0].triangleIndex] == 1 ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - -static int MoverWorldCompoundMeshMaterials( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MeshData* mesh = MakeTwoMaterialMesh(); - - // The hull material and the two mesh materials are distinct, so the compound material - // table gets one slot per material. Children bake in hull then mesh order. - b3SurfaceMaterial meshMaterials[2] = { MakeMaterial( 0.3f, 101 ), MakeMaterial( 0.6f, 202 ) }; - b3SurfaceMaterial hullMaterial = MakeMaterial( 0.9f, 303 ); - - b3CompoundMeshDef meshChild = { - .meshData = mesh, - .transform = b3Transform_identity, - .scale = { 1.0f, 1.0f, 1.0f }, - .materials = meshMaterials, - .materialCount = 2, - }; - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CompoundHullDef hullChild = { - .hull = &box.base, - .transform = { .p = { -8.0f, 0.0f, 0.0f }, .q = b3Quat_identity }, - .material = hullMaterial, - }; - - b3CompoundDef compoundDef = { - .hulls = &hullChild, - .hullCount = 1, - .meshes = &meshChild, - .meshCount = 1, - }; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - ENSURE( compound->materialCount == 3 ); - - const b3SurfaceMaterial* bakedMaterials = b3GetCompoundMaterials( compound ); - ENSURE( bakedMaterials[0].userMaterialId == 303 ); - ENSURE( bakedMaterials[1].userMaterialId == 101 ); - ENSURE( bakedMaterials[2].userMaterialId == 202 ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); - - b3World_Step( worldId, 1.0f / 60.0f, 1 ); - - // Mover on top of the hull child face at y = 0.5 - b3Capsule hullMover = { { -8.0f, 0.65f, 0.0f }, { -8.0f, 0.85f, 0.0f }, 0.2f }; - - PlaneCapture hullCapture = { 0 }; - b3World_CollideMover( worldId, b3Pos_zero, &hullMover, b3DefaultQueryFilter(), CapturePlaneFcn, &hullCapture ); - - ENSURE( hullCapture.count == 1 ); - ENSURE( hullCapture.planes[0].plane.normal.y > 0.99f ); - ENSURE( hullCapture.planes[0].childIndex == 0 ); - ENSURE( hullCapture.planes[0].materialIndex == 0 ); - ENSURE( bakedMaterials[hullCapture.planes[0].materialIndex].userMaterialId == 303 ); - - // Mover over the second mesh triangle. The mesh reports triangle material 1, which the - // compound remaps through the child material table to the shared slot of meshMaterials[1]. - b3Capsule meshMover = { { 2.0f, 0.15f, 0.0f }, { 2.0f, 0.35f, 0.0f }, 0.2f }; - - PlaneCapture meshCapture = { 0 }; - b3World_CollideMover( worldId, b3Pos_zero, &meshMover, b3DefaultQueryFilter(), CapturePlaneFcn, &meshCapture ); - - ENSURE( meshCapture.count == 1 ); - ENSURE( meshCapture.planes[0].plane.normal.y > 0.99f ); - ENSURE( meshCapture.planes[0].childIndex == 1 ); - ENSURE( meshCapture.planes[0].materialIndex == 2 ); - ENSURE( bakedMaterials[meshCapture.planes[0].materialIndex].userMaterialId == 202 ); - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - b3DestroyMesh( mesh ); - return 0; -} - -static int MoverBodyMaterialIndices( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - // One shape of each convex type, spaced out along X - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3Sphere sphere = { { 0.0f, 0.5f, 0.0f }, 0.5f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - b3BoxHull box = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, - (b3Transform){ .p = { 5.0f, 0.0f, 0.0f }, .q = b3Quat_identity } ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - b3Capsule capsule = { { 9.0f, 0.0f, 0.0f }, { 11.0f, 0.0f, 0.0f }, 0.3f }; - b3CreateCapsuleShape( bodyId, &shapeDef, &capsule ); - - b3WorldTransform bodyTransform = { .p = b3Pos_zero, .q = b3Quat_identity }; - - // Convex shapes report the base material as index 0 - b3Capsule movers[3] = { - { { 0.0f, 1.15f, 0.0f }, { 0.0f, 1.35f, 0.0f }, 0.2f }, - { { 5.0f, 0.65f, 0.0f }, { 5.0f, 0.85f, 0.0f }, 0.2f }, - { { 10.0f, 0.45f, 0.0f }, { 10.0f, 0.65f, 0.0f }, 0.2f }, - }; - - for ( int i = 0; i < 3; ++i ) - { - b3BodyPlaneResult planes[4]; - int count = b3Body_CollideMover( bodyId, planes, 4, b3Pos_zero, &movers[i], b3DefaultQueryFilter(), bodyTransform ); - - ENSURE( count == 1 ); - ENSURE( b3Shape_IsValid( planes[0].shapeId ) ); - ENSURE( planes[0].result.plane.normal.y > 0.99f ); - ENSURE( planes[0].result.materialIndex == 0 ); - ENSURE( planes[0].result.childIndex == 0 ); - } - - b3DestroyWorld( worldId ); - return 0; -} - -static int MoverBodySkipsMeshAndCompound( void ) -{ - // The body level mover query handles convex shapes only. Mesh and compound shapes are - // skipped, so their material indices are only available through b3World_CollideMover. - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - b3MeshData* mesh = MakeTwoMaterialMesh(); - ENSURE( mesh != NULL ); - b3CreateMeshShape( bodyId, &shapeDef, mesh, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CompoundHullDef hullChild = { - .hull = &box.base, - .transform = { .p = { 10.0f, 0.0f, 0.0f }, .q = b3Quat_identity }, - }; - b3CompoundDef compoundDef = { - .hulls = &hullChild, - .hullCount = 1, - }; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); - - b3WorldTransform bodyTransform = { .p = b3Pos_zero, .q = b3Quat_identity }; - - // Mover over the mesh triangle and mover over the compound hull child both find nothing - b3Capsule meshMover = { { -2.0f, 0.15f, 0.0f }, { -2.0f, 0.35f, 0.0f }, 0.2f }; - b3Capsule compoundMover = { { 10.0f, 0.65f, 0.0f }, { 10.0f, 0.85f, 0.0f }, 0.2f }; - - b3Capsule movers[2] = { meshMover, compoundMover }; - for ( int i = 0; i < 2; ++i ) - { - b3BodyPlaneResult planes[4]; - int count = b3Body_CollideMover( bodyId, planes, 4, b3Pos_zero, &movers[i], b3DefaultQueryFilter(), bodyTransform ); - ENSURE( count == 0 ); - } - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - b3DestroyMesh( mesh ); - return 0; -} - -// One sided mover collision. -// Mover queries keep only triangles facing the mover. The front side follows the -// baked winding: up for a default mesh or height field, down when the height -// field carries clockwiseWinding. A mirror in the mesh scale must not flip it. -static int MoverMeshBackside( void ) -{ - b3MeshData* mesh = MakeTwoMaterialMesh(); - b3Mesh shape = { .data = mesh, .scale = { 1.0f, 1.0f, 1.0f } }; - - b3PlaneResult planes[4]; - - // On the front of the left triangle, so a plane comes back - b3Capsule above = { { -2.0f, 0.15f, 0.0f }, { -2.0f, 0.35f, 0.0f }, 0.2f }; - int count = b3CollideMoverAndMesh( planes, 4, &shape, &above ); - ENSURE( count == 1 ); - ENSURE( planes[0].plane.normal.y > 0.99f ); - ENSURE( planes[0].childIndex == 0 ); - ENSURE( planes[0].triangleIndex >= 0 && planes[0].triangleIndex < mesh->triangleCount ); - - // The same spot seen from behind the face is culled - b3Capsule below = { { -2.0f, -0.35f, 0.0f }, { -2.0f, -0.15f, 0.0f }, 0.2f }; - count = b3CollideMoverAndMesh( planes, 4, &shape, &below ); - ENSURE( count == 0 ); - - b3DestroyMesh( mesh ); - return 0; -} - -static int MoverMeshMirroredScale( void ) -{ - b3MeshData* mesh = MakeTwoMaterialMesh(); - - // Reflecting the scale flips the triangle winding, the collision swaps it back, - // so the front stays up. Local x = -2 maps onto the source right triangle, material 1. - b3Mesh shape = { .data = mesh, .scale = { -1.0f, 1.0f, 1.0f } }; - - b3PlaneResult planes[4]; - - b3Capsule above = { { -2.0f, 0.15f, 0.0f }, { -2.0f, 0.35f, 0.0f }, 0.2f }; - int count = b3CollideMoverAndMesh( planes, 4, &shape, &above ); - ENSURE( count == 1 ); - ENSURE( planes[0].plane.normal.y > 0.99f ); - ENSURE( planes[0].materialIndex == 1 ); - ENSURE( b3GetMeshMaterialIndices( mesh )[planes[0].triangleIndex] == 1 ); - - b3Capsule below = { { -2.0f, -0.35f, 0.0f }, { -2.0f, -0.15f, 0.0f }, 0.2f }; - count = b3CollideMoverAndMesh( planes, 4, &shape, &below ); - ENSURE( count == 0 ); - - b3DestroyMesh( mesh ); - return 0; -} - -static int MoverHeightFieldBackside( void ) -{ - uint8_t materials[4] = { 0, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, false ); - - b3PlaneResult planes[4]; - - // Standing on the front (upper) face of the default winding - b3Capsule above = { { 0.3f, 0.15f, 0.25f }, { 0.3f, 0.35f, 0.25f }, 0.2f }; - int count = b3CollideMoverAndHeightField( planes, 4, hf, &above ); - ENSURE( count == 1 ); - ENSURE( planes[0].plane.normal.y > 0.99f ); - ENSURE_SMALL( planes[0].plane.offset - 0.05f, 1e-4f ); - - // Under the surface is the back side and gets culled - b3Capsule below = { { 0.3f, -0.35f, 0.25f }, { 0.3f, -0.15f, 0.25f }, 0.2f }; - count = b3CollideMoverAndHeightField( planes, 4, hf, &below ); - ENSURE( count == 0 ); - - b3DestroyHeightField( hf ); - return 0; -} - -static int MoverHeightFieldReport( void ) -{ - uint8_t materials[4] = { 1, 2, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, false ); - - b3PlaneResult planes[4]; - - // (0.3, 0.25) sits on the x + z <= 1 side of cell (0,0), which holds triangle 0 - b3Capsule first = { { 0.3f, 0.15f, 0.25f }, { 0.3f, 0.35f, 0.25f }, 0.2f }; - int count = b3CollideMoverAndHeightField( planes, 4, hf, &first ); - ENSURE( count == 1 ); - ENSURE( planes[0].triangleIndex == 0 ); - ENSURE( planes[0].childIndex == 0 ); - ENSURE( planes[0].materialIndex == 1 ); - - // (1.3, 0.3) sits on the x + z <= 2 side of cell (0,1), which holds triangle 2 - b3Capsule second = { { 1.3f, 0.15f, 0.3f }, { 1.3f, 0.35f, 0.3f }, 0.2f }; - count = b3CollideMoverAndHeightField( planes, 4, hf, &second ); - ENSURE( count == 1 ); - ENSURE( planes[0].triangleIndex == 2 ); - ENSURE( planes[0].materialIndex == 2 ); - - b3DestroyHeightField( hf ); - return 0; -} - -// A clockwise height field faces down, see HeightFieldWinding. Backside culling -// must respect the flag: below the surface is the front side, above is the back. -static int MoverHeightFieldClockwise( void ) -{ - uint8_t materials[4] = { 0, 0, 0, 0 }; - b3HeightFieldData* hf = MakeFlatField( materials, true ); - - b3PlaneResult planes[4]; - - b3Capsule below = { { 0.3f, -0.35f, 0.25f }, { 0.3f, -0.15f, 0.25f }, 0.2f }; - int count = b3CollideMoverAndHeightField( planes, 4, hf, &below ); - ENSURE( count == 1 ); - ENSURE( planes[0].plane.normal.y < -0.99f ); - ENSURE_SMALL( planes[0].plane.offset - 0.05f, 1e-4f ); - ENSURE( planes[0].triangleIndex == 0 || planes[0].triangleIndex == 1 ); - - b3Capsule above = { { 0.3f, 0.15f, 0.25f }, { 0.3f, 0.35f, 0.25f }, 0.2f }; - count = b3CollideMoverAndHeightField( planes, 4, hf, &above ); - ENSURE( count == 0 ); - - b3DestroyHeightField( hf ); - return 0; -} - -// A mesh can be baked with more materials than the shape carries. The reported index must stay -// inside the shape's material array. -static int MoverWorldMeshMaterialClamp( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3MeshData* mesh = MakeTwoMaterialMesh(); - ENSURE( mesh->materialCount == 2 ); - - // Base material only - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3ShapeId shapeId = b3CreateMeshShape( bodyId, &shapeDef, mesh, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - int shapeMaterialCount = b3Shape_GetMeshMaterialCount( shapeId ); - ENSURE( shapeMaterialCount == 1 ); - - b3World_Step( worldId, 1.0f / 60.0f, 1 ); - - // Over the triangle baked with material 1 - b3Capsule mover = { { 2.0f, 0.15f, 0.0f }, { 2.0f, 0.35f, 0.0f }, 0.2f }; - PlaneCapture capture = { 0 }; - b3World_CollideMover( worldId, b3Pos_zero, &mover, b3DefaultQueryFilter(), CapturePlaneFcn, &capture ); - - ENSURE( capture.count == 1 ); - ENSURE( capture.planes[0].materialIndex == shapeMaterialCount - 1 ); - - b3DestroyWorld( worldId ); - b3DestroyMesh( mesh ); - return 0; -} - int MoverTest( void ) { RUN_SUBTEST( GamePlanes ); @@ -709,16 +251,5 @@ int MoverTest( void ) RUN_SUBTEST( MoverHullTouching ); RUN_SUBTEST( MoverHullDeepOverlap ); - RUN_SUBTEST( MoverWorldMeshMaterials ); - RUN_SUBTEST( MoverWorldCompoundMeshMaterials ); - RUN_SUBTEST( MoverBodyMaterialIndices ); - RUN_SUBTEST( MoverBodySkipsMeshAndCompound ); - RUN_SUBTEST( MoverMeshBackside ); - RUN_SUBTEST( MoverMeshMirroredScale ); - RUN_SUBTEST( MoverHeightFieldBackside ); - RUN_SUBTEST( MoverHeightFieldReport ); - RUN_SUBTEST( MoverHeightFieldClockwise ); - RUN_SUBTEST( MoverWorldMeshMaterialClamp ); - return 0; } diff --git a/test/test_name_cache.c b/test/test_name_cache.c deleted file mode 100644 index 4066017..0000000 --- a/test/test_name_cache.c +++ /dev/null @@ -1,212 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "name_cache.h" -#include "test_macros.h" - -#include "box3d/base.h" -#include "box3d/box3d.h" - -#include - -// Direct unit test of the cache: dedup, reverse lookup, empty/null, arbitrary length, no leak. -static int CacheUnit( void ) -{ - int64_t base = b3GetByteCount(); - - b3NameCache cache = b3CreateNameCache(); - - // Empty and NULL map to the null id, which resolves to no string. - ENSURE( b3AddName( &cache, "" ) == B3_NULL_NAME ); - ENSURE( b3AddName( &cache, NULL ) == B3_NULL_NAME ); - ENSURE( b3FindName( &cache, B3_NULL_NAME ) == NULL ); - - // Distinct strings get distinct ids and round-trip. - uint32_t crate = b3AddName( &cache, "crate" ); - uint32_t barrel = b3AddName( &cache, "barrel" ); - ENSURE( crate != B3_NULL_NAME && barrel != B3_NULL_NAME && crate != barrel ); - ENSURE( strcmp( b3FindName( &cache, crate ), "crate" ) == 0 ); - ENSURE( strcmp( b3FindName( &cache, barrel ), "barrel" ) == 0 ); - - // Re-interning the same bytes returns the same id and stores no second entry. - ENSURE( b3AddName( &cache, "crate" ) == crate ); - ENSURE( cache.entries.count == 2 ); - - // A name far longer than any inline buffer round-trips exactly. - char longName[4096]; - for ( int i = 0; i < (int)sizeof( longName ) - 1; ++i ) - { - longName[i] = (char)( 'a' + i % 26 ); - } - longName[sizeof( longName ) - 1] = 0; - uint32_t longId = b3AddName( &cache, longName ); - ENSURE( strcmp( b3FindName( &cache, longId ), longName ) == 0 ); - ENSURE( cache.entries.count == 3 ); - - b3DestroyNameCache( &cache ); - - // The cache owns every interned copy, so all of it comes back on destroy. - ENSURE( b3GetByteCount() == base ); - return 0; -} - -// Build a ground plus named dynamic boxes. Two share a name to exercise dedup and one is longer -// than the old inline buffer to exercise variable length. Ground is ordinal 0, boxes 1..N. -static const char* s_bodyNames[] = { - "crate", - "barrel", - "crate", - "a_very_long_body_name_that_exceeds_any_inline_name_buffer", -}; - -// Each box also carries a named hull shape. Shapes could not hold a name at all before the cache -// (the old inline shape buffer had length 0), so this is a new path. Two shapes share a name for -// dedup, one shape shares a body's name to prove shape ids intern independently, and one is far -// longer than any inline buffer. -static const char* s_shapeNames[] = { - "box_hull", - "box_hull", - "crate", - "a_very_long_shape_name_that_never_fit_the_old_inline_buffer", -}; - -_Static_assert( ARRAY_COUNT( s_shapeNames ) == ARRAY_COUNT( s_bodyNames ), "name arrays must stay parallel" ); - -static void BuildNamedScene( b3WorldId worldId ) -{ - b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3ShapeDef groundShape = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &groundShape, &groundBox.base ); - - b3ShapeDef boxShape = b3DefaultShapeDef(); - boxShape.density = 1.0f; - for ( int i = 0; i < ARRAY_COUNT( s_bodyNames ); ++i ) - { - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 1.0f + 1.1f * (float)i, 0.0f }; - bodyDef.name = s_bodyNames[i]; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - boxShape.name = s_shapeNames[i]; - b3CreateHullShape( bodyId, &boxShape, &box.base ); - } -} - -static int CheckReplayNames( b3RecPlayer* player ) -{ - for ( int i = 0; i < ARRAY_COUNT( s_bodyNames ); ++i ) - { - b3BodyId id = b3RecPlayer_GetBodyId( player, 1 + i ); // ordinal 0 is the ground - ENSURE( b3Body_IsValid( id ) ); - const char* name = b3Body_GetName( id ); - ENSURE( name != NULL && strcmp( name, s_bodyNames[i] ) == 0 ); - - // Shape names ride the same world cache, so the snapshot must restore them too. - b3ShapeId shapeId; - ENSURE( b3Body_GetShapes( id, &shapeId, 1 ) == 1 ); - const char* shapeName = b3Shape_GetName( shapeId ); - ENSURE( shapeName != NULL && strcmp( shapeName, s_shapeNames[i] ) == 0 ); - } - return 0; -} - -// Names live on the world, so the world snapshot must carry them. Record a snapshot-seeded session -// and confirm every body and shape name resolves on the reconstructed replay world. -static int NameRoundTrip( void ) -{ - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - BuildNamedScene( worldId ); - - // Record from a snapshot of the populated world, so names ride in the frame-0 image. - b3World_StartRecording( worldId, rec ); - for ( int i = 0; i < 20; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - - ENSURE( b3ValidateReplay( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ) ); - - b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); - ENSURE( player != NULL ); - - b3RecPlayer_SeekFrame( player, 20 ); - ENSURE( !b3RecPlayer_HasDiverged( player ) ); - ENSURE( CheckReplayNames( player ) == 0 ); - - b3DestroyPlayer( player ); - b3DestroyRecording( rec ); - return 0; -} - -// Rollback preserves names: a backward seek restores from a keyframe, which rebuilds world->names -// on each restore. Scrub across keyframe boundaries, confirm names resolve every time, and require -// the tracked byte count to return to baseline so a re-load that drops duplicate copies leaks nothing. -static int RollbackNames( void ) -{ - int64_t base = b3GetByteCount(); - - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - BuildNamedScene( worldId ); - - // Settle, then record a snapshot-seeded session long enough to span several keyframes. - for ( int i = 0; i < 10; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - b3World_StartRecording( worldId, rec ); - const int totalFrames = 80; - for ( int i = 0; i < totalFrames; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - - b3RecPlayer* player = b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); - ENSURE( player != NULL ); - - // Play to the end so the keyframe ring is populated. - b3RecPlayer_SeekFrame( player, totalFrames ); - ENSURE( !b3RecPlayer_HasDiverged( player ) ); - - // Scrub backward and forward across keyframe boundaries. Each restore rebuilds the name table. - int targets[] = { 10, 60, 5, 70, 1, 40 }; - for ( int k = 0; k < ARRAY_COUNT( targets ); ++k ) - { - b3RecPlayer_SeekFrame( player, targets[k] ); - ENSURE( b3RecPlayer_GetFrame( player ) == targets[k] ); - ENSURE( !b3RecPlayer_HasDiverged( player ) ); - ENSURE( CheckReplayNames( player ) == 0 ); - } - - b3DestroyPlayer( player ); - b3DestroyRecording( rec ); - - // Every restore reloaded the name table; dropped duplicate copies must be freed, not leaked. - ENSURE( b3GetByteCount() == base ); - return 0; -} - -int NameCacheTest( void ) -{ - RUN_SUBTEST( CacheUnit ); - RUN_SUBTEST( NameRoundTrip ); - RUN_SUBTEST( RollbackNames ); - return 0; -} diff --git a/test/test_recording.c b/test/test_recording.c index 46f1e30..ba068e5 100644 --- a/test/test_recording.c +++ b/test/test_recording.c @@ -5,13 +5,12 @@ #define _CRT_SECURE_NO_WARNINGS #endif -#include "physics_world.h" -#include "recording.h" -#include "simd.h" -#include "test_macros.h" - #include "box3d/box3d.h" #include "box3d/collision.h" +#include "test_macros.h" + +#include "physics_world.h" +#include "recording.h" #include #include @@ -26,7 +25,7 @@ static int SphereRoundTrip( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_StartRecording( worldId, rec ); @@ -35,28 +34,28 @@ static int SphereRoundTrip( void ) // Static ground b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); + groundDef.type = b3_staticBody; + b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); + b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); b3ShapeDef groundShapeDef = b3DefaultShapeDef(); b3CreateHullShape( groundId, &groundShapeDef, &groundBox.base ); // Dynamic body with a sphere shape b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 5.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ 0.0f, 5.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3Sphere sphere; sphere.center = (b3Vec3){ 0.0f, 0.0f, 0.0f }; sphere.radius = 0.5f; - b3ShapeDef sphereDef = b3DefaultShapeDef(); - sphereDef.density = 1.0f; + b3ShapeDef sphereDef = b3DefaultShapeDef(); + sphereDef.density = 1.0f; b3CreateSphereShape( bodyId, &sphereDef, &sphere ); - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; + float timeStep = 1.0f / 60.0f; + int subStepCount = 4; for ( int i = 0; i < 30; ++i ) { b3World_Step( worldId, timeStep, subStepCount ); @@ -76,9 +75,10 @@ static int HullDedup( void ) { // Build a small convex hull b3Vec3 pts[8] = { - { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, -1.0f }, - { -1.0f, 1.0f, -1.0f }, { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, - { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, + { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, + { 1.0f, 1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f }, + { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, }; b3HullData* hull = b3CreateHull( pts, 8, 8 ); ENSURE( hull != NULL ); @@ -87,19 +87,19 @@ static int HullDedup( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_StartRecording( worldId, rec ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; + shapeDef.density = 1.0f; for ( int i = 0; i < 3; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ (float)( i * 3 ), 5.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ (float)( i * 3 ), 5.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3CreateHullShape( bodyId, &shapeDef, hull ); } @@ -119,7 +119,7 @@ static int HullDedup( void ) // Confirm the registry was deduped to 1 hull entry. // Parse registryOffset from the header and count entries. const uint8_t* bytes = b3Recording_GetData( rec ); - int sz = b3Recording_GetSize( rec ); + int sz = b3Recording_GetSize( rec ); ENSURE( sz >= 48 ); uint64_t regOff = 0; @@ -127,123 +127,20 @@ static int HullDedup( void ) ENSURE( regOff != 0 && (int)regOff + 4 <= sz ); // entryCount is a little-endian u32 at the start of the registry block - const uint8_t* rp = bytes + (int)regOff; - uint32_t entryCount = (uint32_t)rp[0] | ( (uint32_t)rp[1] << 8 ) | ( (uint32_t)rp[2] << 16 ) | - ( (uint32_t)rp[3] << 24 ); + const uint8_t* rp = bytes + (int)regOff; + uint32_t entryCount = (uint32_t)rp[0] | ( (uint32_t)rp[1] << 8 ) | + ( (uint32_t)rp[2] << 16 ) | ( (uint32_t)rp[3] << 24 ); ENSURE( entryCount == 1 ); b3DestroyRecording( rec ); return 0; } -static int ValidateReplayAtWidth( const b3Recording* rec, int width ) -{ - b3SetSIMDWidth( width ); - bool valid = b3ValidateReplay( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); - b3SetSIMDWidth( 0 ); - return valid ? 0 : 1; -} - -// A recording made at the native SIMD width must replay at width 4 and vice versa. -static int CrossWidthReplay( void ) -{ - b3SetSIMDWidth( 0 ); - int nativeWidth = b3GetSIMDWidth(); - if ( nativeWidth == 4 ) - { - printf( " subtest skipped: CrossWidthReplay, native SIMD width is 4\n" ); - return 0; - } - - enum - { - hullCount = 6 - }; - - b3HullData* hulls[hullCount] = { 0 }; - hulls[0] = b3CreateRock( 0.5f ); - hulls[1] = b3CreateComplexHull( 0.5f ); - hulls[2] = b3CreateCylinder( 0.8f, 0.4f, 0.0f, 8 ); - hulls[3] = b3CreateCone( 0.8f, 0.5f, 0.2f, 7 ); - - uint32_t seed = 12345u; - for ( int hullIndex = 4; hullIndex < hullCount; ++hullIndex ) - { - b3Vec3 points[20]; - for ( int i = 0; i < 20; ++i ) - { - float v[3]; - for ( int k = 0; k < 3; ++k ) - { - seed = seed * 1664525u + 1013904223u; - v[k] = - ( (float)( seed >> 8 ) / (float)( 1 << 24 ) - 0.5f ) * ( k == 1 ? 0.6f : 1.0f ); - } - points[i] = (b3Vec3){ v[0], v[1], v[2] }; - } - hulls[hullIndex] = b3CreateHull( points, 20, 20 ); - } - - b3Recording* rec = b3CreateRecording( 0 ); - - b3SetSIMDWidth( nativeWidth ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3World_StartRecording( worldId, rec ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3ShapeDef groundShape = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &groundShape, &groundBox.base ); - - b3ShapeDef dynamicShape = b3DefaultShapeDef(); - dynamicShape.density = 1.0f; - - for ( int i = 0; i < 18; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.4f * (float)( i % 3 ) - 0.4f, 1.5f + 0.9f * (float)i, - 0.3f * (float)( i % 2 ) }; - bodyDef.rotation = - b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.37f * (float)i ); - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &dynamicShape, hulls[i % hullCount] ); - } - - float timeStep = 1.0f / 60.0f; - for ( int i = 0; i < 120; ++i ) - { - b3World_Step( worldId, timeStep, 4 ); - } - - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - b3SetSIMDWidth( 0 ); - - int narrowStatus = ValidateReplayAtWidth( rec, 4 ); - int nativeStatus = ValidateReplayAtWidth( rec, nativeWidth ); - - b3DestroyRecording( rec ); - for ( int i = 0; i < hullCount; ++i ) - { - b3DestroyHull( hulls[i] ); - } - - ENSURE( narrowStatus == 0 ); - ENSURE( nativeStatus == 0 ); - return 0; -} - // Mid-stream snapshot with only dynamic bodies floating in air (no contacts). static int MidStreamNoContacts( void ) { b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); @@ -251,20 +148,20 @@ static int MidStreamNoContacts( void ) sphere.center = (b3Vec3){ 0.0f, 0.0f, 0.0f }; sphere.radius = 0.5f; b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; + shapeDef.density = 1.0f; // A few dynamic bodies well apart from each other so no contacts form for ( int i = 0; i < 4; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ (float)( i * 10 ), 50.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ (float)( i * 10 ), 50.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3CreateSphereShape( bodyId, &shapeDef, &sphere ); } - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; + float timeStep = 1.0f / 60.0f; + int subStepCount = 4; for ( int i = 0; i < 10; ++i ) { b3World_Step( worldId, timeStep, subStepCount ); @@ -293,23 +190,23 @@ static int MidStreamNoContacts( void ) static int MidStreamContacts( void ) { b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); // Static ground using a box hull { b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); + groundDef.type = b3_staticBody; + b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); + b3BoxHull groundBox = b3MakeBoxHull( 50.0f, 1.0f, 50.0f ); b3ShapeDef groundShape = b3DefaultShapeDef(); b3CreateHullShape( groundId, &groundShape, &groundBox.base ); } b3ShapeDef dynamicShape = b3DefaultShapeDef(); - dynamicShape.density = 1.0f; + dynamicShape.density = 1.0f; // A few dynamic boxes dropped onto the ground for ( int i = 0; i < 3; ++i ) @@ -317,14 +214,14 @@ static int MidStreamContacts( void ) b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ (float)( i * 2 ) - 2.0f, 5.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ (float)( i * 2 ) - 2.0f, 5.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3CreateHullShape( bodyId, &dynamicShape, &box.base ); } - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; + float timeStep = 1.0f / 60.0f; + int subStepCount = 4; // Let the scene settle: bodies hit ground, build manifolds, islands, graph colors for ( int i = 0; i < 60; ++i ) @@ -360,7 +257,7 @@ static int ScrubBackward( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); @@ -390,8 +287,8 @@ static int ScrubBackward( void ) } float timeStep = 1.0f / 60.0f; - int subStepCount = 4; - int totalFrames = 80; + int subStepCount = 4; + int totalFrames = 80; for ( int i = 0; i < totalFrames; ++i ) { b3World_Step( worldId, timeStep, subStepCount ); @@ -401,10 +298,10 @@ static int ScrubBackward( void ) b3DestroyWorld( worldId ); const uint8_t* data = b3Recording_GetData( rec ); - int sz = b3Recording_GetSize( rec ); + int sz = b3Recording_GetSize( rec ); // Create the player - b3RecPlayer* player = b3CreatePlayer( data, sz, 1 ); + b3RecPlayer* player = b3RecPlayer_Create( data, sz, 1 ); ENSURE( player != NULL ); ENSURE( b3RecPlayer_GetFrameCount( player ) == totalFrames ); @@ -446,7 +343,7 @@ static int ScrubBackward( void ) } b3Free( hashes, (size_t)( totalFrames + 1 ) * sizeof( uint64_t ) ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( rec ); return 0; } @@ -457,9 +354,10 @@ static int ScrubBackward( void ) static int SeekWithHull( void ) { b3Vec3 pts[8] = { - { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, -1.0f }, - { -1.0f, 1.0f, -1.0f }, { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, - { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, + { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, + { 1.0f, 1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f }, + { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, }; b3HullData* hull = b3CreateHull( pts, 8, 8 ); ENSURE( hull != NULL ); @@ -468,7 +366,7 @@ static int SeekWithHull( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); b3World_StartRecording( worldId, rec ); @@ -489,14 +387,14 @@ static int SeekWithHull( void ) for ( int i = 0; i < 3; ++i ) { b3BodyDef bd = b3DefaultBodyDef(); - bd.type = b3_dynamicBody; - bd.position = (b3Pos){ (float)( i * 4 ) - 4.0f, 5.0f, 0.0f }; + bd.type = b3_dynamicBody; + bd.position = (b3Pos){ (float)( i * 4 ) - 4.0f, 5.0f, 0.0f }; b3BodyId bodyId = b3CreateBody( worldId, &bd ); b3CreateHullShape( bodyId, &sd, hull ); } float timeStep = 1.0f / 60.0f; - int totalFrames = 40; + int totalFrames = 40; for ( int i = 0; i < totalFrames; ++i ) { b3World_Step( worldId, timeStep, 4 ); @@ -507,9 +405,9 @@ static int SeekWithHull( void ) b3DestroyHull( hull ); const uint8_t* data = b3Recording_GetData( rec ); - int sz = b3Recording_GetSize( rec ); + int sz = b3Recording_GetSize( rec ); - b3RecPlayer* player = b3CreatePlayer( data, sz, 1 ); + b3RecPlayer* player = b3RecPlayer_Create( data, sz, 1 ); ENSURE( player != NULL ); // Step to end @@ -527,7 +425,7 @@ static int SeekWithHull( void ) b3RecPlayer_SeekFrame( player, 0 ); ENSURE( b3RecPlayer_GetFrame( player ) == 0 ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( rec ); return 0; } @@ -555,13 +453,13 @@ static void RecTestDestroyDebugShape( void* userShape, void* userContext ) counters->destroyed += 1; } -static void RecTestDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, - void* context ) +static bool RecTestDrawShape( void* userShape, b3WorldTransform transform, b3HexColor color, void* context ) { (void)userShape; (void)transform; (void)color; (void)context; + return true; } // b3World_Draw lazily fires createDebugShape for shapes entering the draw set, the same way the @@ -586,13 +484,13 @@ static int DebugShapeCallbacks( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_StartRecording( worldId, rec ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; + groundDef.type = b3_staticBody; b3BodyId groundId = b3CreateBody( worldId, &groundDef ); b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); b3ShapeDef groundShape = b3DefaultShapeDef(); @@ -605,9 +503,9 @@ static int DebugShapeCallbacks( void ) for ( int i = 0; i < 4; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; + bodyDef.type = b3_dynamicBody; bodyDef.position = (b3Pos){ 0.0f, 1.0f + 1.1f * (float)i, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3CreateHullShape( bodyId, &boxShape, &box.base ); } @@ -625,14 +523,12 @@ static int DebugShapeCallbacks( void ) b3Recording* loaded = b3LoadRecordingFromFile( path ); ENSURE( loaded != NULL ); - b3RecPlayer* player = - b3CreatePlayer( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 ); + b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 ); ENSURE( player != NULL ); // Wiring the callbacks rebuilds the world and rewinds to frame 0. DebugShapeCounters counters = { 0, 0 }; - b3RecPlayer_SetDebugShapeCallbacks( player, RecTestCreateDebugShape, RecTestDestroyDebugShape, - &counters ); + b3RecPlayer_SetDebugShapeCallbacks( player, RecTestCreateDebugShape, RecTestDestroyDebugShape, &counters ); ENSURE( b3RecPlayer_GetFrame( player ) == 0 ); // Replay to the end, then draw: createDebugShape fires once per shape (ground + 4 boxes = 5). @@ -644,8 +540,8 @@ static int DebugShapeCallbacks( void ) ENSURE( counters.created >= 5 ); ENSURE( !b3RecPlayer_HasDiverged( player ) ); - // A backward seek restores the empty seed in place, releasing the live debug shapes, then - // forward stepping recreates them through the callbacks, so more creates fire. + // A backward seek restores the empty seed in place, releasing the live debug shapes, then forward + // stepping recreates them through the callbacks, so more creates fire. int createdBefore = counters.created; b3RecPlayer_SeekFrame( player, 0 ); b3RecPlayer_SeekFrame( player, totalFrames ); @@ -653,7 +549,7 @@ static int DebugShapeCallbacks( void ) ENSURE( counters.created > createdBefore ); // Teardown destroys the final world; every live shape is released, so the counts balance. - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); ENSURE( counters.created == counters.destroyed ); b3DestroyRecording( loaded ); @@ -668,7 +564,7 @@ static int DebugShapeCallbacks( void ) static int PlayerAccessors( void ) { b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); // Static ground (creation ordinal 0) @@ -694,7 +590,7 @@ static int PlayerAccessors( void ) } float timeStep = 1.0f / 60.0f; - int subStepCount = 4; + int subStepCount = 4; // Settle, then record with a snapshot of the populated world. for ( int i = 0; i < 10; ++i ) @@ -714,8 +610,7 @@ static int PlayerAccessors( void ) b3World_StopRecording( worldId ); b3DestroyWorld( worldId ); - b3RecPlayer* player = - b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); + b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); ENSURE( player != NULL ); // Info reflects the recorded tuning and a non-degenerate bounds. @@ -759,24 +654,23 @@ static int PlayerAccessors( void ) ENSURE( b3RecPlayer_GetKeyframeBudget( player ) == (size_t)256 * 1024 * 1024 ); ENSURE( b3RecPlayer_GetKeyframeBytes( player ) == 0 ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( rec ); return 0; } -// A keyframe restore is a deterministic replay state, so shapes that persist must keep their -// renderer handle rather than being torn down and rebuilt every seek. Record a snapshot-seeded -// session (shapes exist at frame 0), replay with handle callbacks, scrub backward across keyframes -// repeatedly, and verify no new handles are built per restore and the create/destroy counts still -// balance at teardown. +// A keyframe restore is a deterministic replay state, so shapes that persist must keep their renderer +// handle rather than being torn down and rebuilt every seek. Record a snapshot-seeded session (shapes +// exist at frame 0), replay with handle callbacks, scrub backward across keyframes repeatedly, and +// verify no new handles are built per restore and the create/destroy counts still balance at teardown. static int KeyframeHandleReuse( void ) { b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; + groundDef.type = b3_staticBody; b3BodyId groundId = b3CreateBody( worldId, &groundDef ); b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); b3ShapeDef groundShape = b3DefaultShapeDef(); @@ -789,9 +683,9 @@ static int KeyframeHandleReuse( void ) for ( int i = 0; i < dynamicCount; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; + bodyDef.type = b3_dynamicBody; bodyDef.position = (b3Pos){ 0.0f, 1.0f + 1.1f * (float)i, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3CreateHullShape( bodyId, &boxShape, &box.base ); } int shapeCount = 1 + dynamicCount; @@ -814,13 +708,11 @@ static int KeyframeHandleReuse( void ) b3World_StopRecording( worldId ); b3DestroyWorld( worldId ); - b3RecPlayer* player = - b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); + b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); ENSURE( player != NULL ); DebugShapeCounters counters = { 0, 0 }; - b3RecPlayer_SetDebugShapeCallbacks( player, RecTestCreateDebugShape, RecTestDestroyDebugShape, - &counters ); + b3RecPlayer_SetDebugShapeCallbacks( player, RecTestCreateDebugShape, RecTestDestroyDebugShape, &counters ); // Replay to the end and draw: one handle per shape. b3RecPlayer_SeekFrame( player, totalFrames ); @@ -828,8 +720,8 @@ static int KeyframeHandleReuse( void ) ENSURE( !b3RecPlayer_HasDiverged( player ) ); ENSURE( counters.created == shapeCount ); - // Scrub backward and forward across keyframes. Each restore keeps the persistent shapes' - // handles, so drawing builds no new ones. + // Scrub backward and forward across keyframes. Each restore keeps the persistent shapes' handles, + // so drawing builds no new ones. int createdAfterFirstDraw = counters.created; int seekTargets[] = { 40, 70, 20, 60, 8, 75 }; for ( int k = 0; k < (int)( sizeof( seekTargets ) / sizeof( seekTargets[0] ) ); ++k ) @@ -840,7 +732,7 @@ static int KeyframeHandleReuse( void ) ENSURE( counters.created == createdAfterFirstDraw ); // Teardown releases exactly the live handles, so the leak-free invariant holds. - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); ENSURE( counters.created == counters.destroyed ); b3DestroyRecording( rec ); @@ -854,9 +746,8 @@ static bool QueryReplayOverlapFcn( b3ShapeId shapeId, void* context ) return true; } -static float QueryReplayCastFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, - uint64_t userMaterialId, int triangleIndex, int childIndex, - void* context ) +static float QueryReplayCastFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, + int triangleIndex, int childIndex, void* context ) { (void)shapeId; (void)point; @@ -869,25 +760,7 @@ static float QueryReplayCastFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, return fraction; } -static float CompoundHitCastFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, - uint64_t userMaterialId, int triangleIndex, int childIndex, - void* context ) -{ - (void)point; - (void)normal; - (void)fraction; - (void)userMaterialId; - (void)triangleIndex; - (void)childIndex; - if ( b3Shape_GetType( shapeId ) == b3_compoundShape ) - { - *(bool*)context = true; - } - return 1.0f; -} - -static bool QueryReplayPlaneFcn( b3ShapeId shapeId, const b3PlaneResult* planes, int planeCount, - void* context ) +static bool QueryReplayPlaneFcn( b3ShapeId shapeId, const b3PlaneResult* planes, int planeCount, void* context ) { (void)shapeId; (void)planes; @@ -903,22 +776,22 @@ static bool QueryReplayMoverFilterFcn( b3ShapeId shapeId, void* context ) return true; } -// Issue all seven world queries each frame, then replay. Every query is re-issued against the -// replay world and compared to what was recorded, so a clean (non-diverged) replay proves the -// queries reproduce. Also opens a player and confirms the per-frame query store surfaces all seven. +// Issue all seven world queries each frame, then replay. Every query is re-issued against the replay +// world and compared to what was recorded, so a clean (non-diverged) replay proves the queries +// reproduce. Also opens a player and confirms the per-frame query store surfaces all seven. static int QueryReplay( void ) { b3Recording* rec = b3CreateRecording( 0 ); ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); + groundDef.type = b3_staticBody; + b3BodyId groundId = b3CreateBody( worldId, &groundDef ); + b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); b3ShapeDef groundShape = b3DefaultShapeDef(); b3CreateHullShape( groundId, &groundShape, &groundBox.base ); @@ -926,12 +799,12 @@ static int QueryReplay( void ) for ( int i = 0; i < 4; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; + bodyDef.type = b3_dynamicBody; bodyDef.position = (b3Pos){ (float)i - 1.5f, 3.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; b3ShapeDef sphereDef = b3DefaultShapeDef(); - sphereDef.density = 1.0f; + sphereDef.density = 1.0f; b3CreateSphereShape( bodyId, &sphereDef, &sphere ); } @@ -942,21 +815,20 @@ static int QueryReplay( void ) const int totalFrames = 30; for ( int i = 0; i < totalFrames; ++i ) { - b3Pos origin = { 0.0f, 6.0f, 0.0f }; + b3Pos origin = { 0.0f, 6.0f, 0.0f }; b3Vec3 translation = { 0.0f, -8.0f, 0.0f }; - b3AABB aabb = { { -5.0f, -1.0f, -5.0f }, { 5.0f, 6.0f, 5.0f } }; + b3AABB aabb = { { -5.0f, -1.0f, -5.0f }, { 5.0f, 6.0f, 5.0f } }; - b3Vec3 proxyPts = { 0.0f, 0.0f, 0.0f }; - b3ShapeProxy proxy = { &proxyPts, 1, 0.5f }; - b3Capsule mover = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.3f }; + b3Vec3 proxyPts = { 0.0f, 0.0f, 0.0f }; + b3ShapeProxy proxy = { &proxyPts, 1, 0.5f }; + b3Capsule mover = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.3f }; b3World_OverlapAABB( worldId, aabb, filter, QueryReplayOverlapFcn, NULL ); b3World_OverlapShape( worldId, origin, &proxy, filter, QueryReplayOverlapFcn, NULL ); b3World_CastRay( worldId, origin, translation, filter, QueryReplayCastFcn, NULL ); b3World_CastRayClosest( worldId, origin, translation, filter ); b3World_CastShape( worldId, origin, &proxy, translation, filter, QueryReplayCastFcn, NULL ); - b3World_CastMover( worldId, origin, &mover, translation, filter, QueryReplayMoverFilterFcn, - NULL ); + b3World_CastMover( worldId, origin, &mover, translation, filter, QueryReplayMoverFilterFcn, NULL ); b3World_CollideMover( worldId, origin, &mover, filter, QueryReplayPlaneFcn, NULL ); b3World_Step( worldId, 1.0f / 60.0f, 4 ); @@ -969,8 +841,7 @@ static int QueryReplay( void ) ENSURE( b3ValidateReplay( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ) ); // Player path: seek to a mid frame and confirm the per-frame store holds all seven queries. - b3RecPlayer* player = - b3CreatePlayer( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); + b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( rec ), b3Recording_GetSize( rec ), 1 ); ENSURE( player != NULL ); b3RecPlayer_SeekFrame( player, 15 ); @@ -993,27 +864,27 @@ static int QueryReplay( void ) } ENSURE( sawCastRay ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( rec ); return 0; } -// Tagged queries: the caller (id, label) is hashed into a key that rides the QueryTag op, with the -// id and label interned in the trailing tag table. The same label under two entity ids is two -// distinct keys. All survive a file round-trip and resolve back through b3RecQueryInfo; untagged -// queries report key 0 / id 0 / name NULL. +// Tagged queries: the caller (id, label) is hashed into a key that rides the QueryTag op, with the id +// and label interned in the trailing tag table. The same label under two entity ids is two distinct +// keys. All survive a file round-trip and resolve back through b3RecQueryInfo; untagged queries report +// key 0 / id 0 / name NULL. static int TaggedQuery( void ) { b3Recording* rec = b3CreateRecording( 0 ); ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.type = b3_staticBody; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); + groundDef.type = b3_staticBody; + b3BodyId groundId = b3CreateBody( worldId, &groundDef ); + b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); b3ShapeDef groundShape = b3DefaultShapeDef(); b3CreateHullShape( groundId, &groundShape, &groundBox.base ); @@ -1021,11 +892,11 @@ static int TaggedQuery( void ) // Same label, different entity ids: distinct logical queries with distinct keys. b3QueryFilter bullet53 = b3DefaultQueryFilter(); - bullet53.id = 53; + bullet53.id = 53; bullet53.name = "bullet"; b3QueryFilter bullet54 = b3DefaultQueryFilter(); - bullet54.id = 54; + bullet54.id = 54; bullet54.name = "bullet"; b3QueryFilter untagged = b3DefaultQueryFilter(); @@ -1037,9 +908,9 @@ static int TaggedQuery( void ) const int totalFrames = 10; for ( int i = 0; i < totalFrames; ++i ) { - b3Pos origin = { 0.0f, 6.0f, 0.0f }; + b3Pos origin = { 0.0f, 6.0f, 0.0f }; b3Vec3 translation = { 0.0f, -8.0f, 0.0f }; - b3AABB aabb = { { -5.0f, -1.0f, -5.0f }, { 5.0f, 6.0f, 5.0f } }; + b3AABB aabb = { { -5.0f, -1.0f, -5.0f }, { 5.0f, 6.0f, 5.0f } }; // Two tagged rays sharing the label "bullet" plus one untagged overlap, every frame. b3World_CastRay( worldId, origin, translation, bullet53, QueryReplayCastFcn, NULL ); @@ -1060,8 +931,7 @@ static int TaggedQuery( void ) b3Recording* loaded = b3LoadRecordingFromFile( path ); ENSURE( loaded != NULL ); - b3RecPlayer* player = - b3CreatePlayer( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 ); + b3RecPlayer* player = b3RecPlayer_Create( b3Recording_GetData( loaded ), b3Recording_GetSize( loaded ), 1 ); ENSURE( player != NULL ); b3RecPlayer_SeekFrame( player, 5 ); @@ -1090,7 +960,7 @@ static int TaggedQuery( void ) } ENSURE( saw53 && saw54 && sawUntagged ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( loaded ); b3DestroyRecording( rec ); return 0; @@ -1105,7 +975,7 @@ static int EmptyWorldRoundTrip( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_StartRecording( worldId, rec ); b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); @@ -1119,7 +989,7 @@ static int EmptyWorldRoundTrip( void ) b3DestroyWorld( worldId ); const uint8_t* data = b3Recording_GetData( rec ); - int size = b3Recording_GetSize( rec ); + int size = b3Recording_GetSize( rec ); // The seed snapshot is written even with no bodies. b3RecHeader hdr; @@ -1129,7 +999,7 @@ static int EmptyWorldRoundTrip( void ) ENSURE( b3ValidateReplay( data, size, 1 ) ); // Restart restores in place, so the replay world id survives a rewind. - b3RecPlayer* player = b3CreatePlayer( data, size, 1 ); + b3RecPlayer* player = b3RecPlayer_Create( data, size, 1 ); ENSURE( player != NULL ); uint32_t worldKey = b3StoreWorldId( b3RecPlayer_GetWorldId( player ) ); @@ -1142,29 +1012,14 @@ static int EmptyWorldRoundTrip( void ) ENSURE( b3RecPlayer_GetFrame( player ) == 0 ); ENSURE( !b3RecPlayer_HasDiverged( player ) ); - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); b3DestroyRecording( rec ); return 0; } -// Safety factor of the named body in a replay world, or -1 if the body is not in the list -static float ReplaySafetyFactor( b3RecPlayer* player, const char* name ) -{ - int count = b3RecPlayer_GetBodyCount( player ); - for ( int i = 0; i < count; ++i ) - { - b3BodyId bodyId = b3RecPlayer_GetBodyId( player, i ); - if ( b3Body_IsValid( bodyId ) && strcmp( b3Body_GetName( bodyId ), name ) == 0 ) - { - return b3Body_GetSafetyFactor( bodyId ); - } - } - - return -1.0f; -} - // Exercise every recorded op in a single session, then validate replay at two worker -// counts, round-trip through a file, and drive the incremental player. +// counts, round-trip through a file, and drive the incremental player. Mirrors the +// comprehensive RecordingTest in Box2D's test suite (box2d/test/test_recording.c). static int AllOps( void ) { b3Recording* rec = b3CreateRecording( 0 ); @@ -1187,19 +1042,17 @@ static int AllOps( void ) b3ShapeId groundShapeId = b3CreateHullShape( groundId, &groundShapeDef, &groundBox.base ); ENSURE( b3Shape_IsValid( groundShapeId ) ); - // Dynamic body with a sphere shape. + // Dynamic body with a sphere shape. The name is intentionally longer than B3_BODY_NAME_LENGTH so + // replay exercises the over-length name path in the body def reader. b3BodyDef bodyDef = b3DefaultBodyDef(); bodyDef.type = b3_dynamicBody; bodyDef.position = (b3Pos){ 0.0f, 5.0f, 0.0f }; - bodyDef.name = "testBodyWithVeryLongNameThatIsAVeryLongNameLength"; + bodyDef.name = "testBodyWithVeryLongNameThatExceedsTheNameLength"; b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); ENSURE( b3Body_IsValid( bodyId ) ); b3ShapeDef sphereShapeDef = b3DefaultShapeDef(); sphereShapeDef.density = 1.0f; - // Over-length shape name so replay exercises the clamp in the shape def reader, like the body - // above. - sphereShapeDef.name = "sphereNameThatExceedsTheLimit"; b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; b3ShapeId sphereShapeId = b3CreateSphereShape( bodyId, &sphereShapeDef, &sphere ); ENSURE( b3Shape_IsValid( sphereShapeId ) ); @@ -1219,9 +1072,10 @@ static int AllOps( void ) // Custom hull shape on a third dynamic body b3Vec3 hullPts[8] = { - { -0.5f, -0.5f, -0.5f }, { 0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, -0.5f }, - { -0.5f, 0.5f, -0.5f }, { -0.5f, -0.5f, 0.5f }, { 0.5f, -0.5f, 0.5f }, - { 0.5f, 0.5f, 0.5f }, { -0.5f, 0.5f, 0.5f }, + { -0.5f, -0.5f, -0.5f }, { 0.5f, -0.5f, -0.5f }, + { 0.5f, 0.5f, -0.5f }, { -0.5f, 0.5f, -0.5f }, + { -0.5f, -0.5f, 0.5f }, { 0.5f, -0.5f, 0.5f }, + { 0.5f, 0.5f, 0.5f }, { -0.5f, 0.5f, 0.5f }, }; b3HullData* customHull = b3CreateHull( hullPts, 8, 8 ); ENSURE( customHull != NULL ); @@ -1258,10 +1112,9 @@ static int AllOps( void ) ENSURE( b3Body_IsValid( xformBodyId ) ); b3ShapeDef xformShapeDef = b3DefaultShapeDef(); xformShapeDef.density = 1.0f; - b3Transform xformXf = { (b3Vec3){ 0.1f, 0.2f, -0.1f }, - b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.4f ) }; - b3ShapeId xformShapeId = b3CreateTransformedHullShape( - xformBodyId, &xformShapeDef, customHull, xformXf, (b3Vec3){ 1.25f, 0.75f, 1.5f } ); + b3Transform xformXf = { (b3Vec3){ 0.1f, 0.2f, -0.1f }, b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.4f ) }; + b3ShapeId xformShapeId = b3CreateTransformedHullShape( xformBodyId, &xformShapeDef, customHull, xformXf, + (b3Vec3){ 1.25f, 0.75f, 1.5f } ); ENSURE( b3Shape_IsValid( xformShapeId ) ); // Mesh, height field, and compound static shapes (3D-only) @@ -1271,12 +1124,8 @@ static int AllOps( void ) b3BodyId meshBodyId = b3CreateBody( worldId, &meshBodyDef ); b3MeshData* meshData = b3CreateGridMesh( 3, 3, 2.0f, 0, false ); ENSURE( meshData != NULL ); - b3MeshData* swapMeshData = b3CreateGridMesh( 4, 4, 1.5f, 0, false ); - ENSURE( swapMeshData != NULL ); b3ShapeDef meshShapeDef = b3DefaultShapeDef(); - b3ShapeId meshShapeId = - b3CreateMeshShape( meshBodyId, &meshShapeDef, meshData, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - ENSURE( b3Shape_IsValid( meshShapeId ) ); + b3CreateMeshShape( meshBodyId, &meshShapeDef, meshData, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); b3BodyDef hfBodyDef = b3DefaultBodyDef(); hfBodyDef.type = b3_staticBody; @@ -1294,43 +1143,23 @@ static int AllOps( void ) b3CompoundSphereDef compSphere; compSphere.sphere = (b3Sphere){ { 0.0f, 0.0f, 0.0f }, 1.0f }; compSphere.material = b3DefaultSurfaceMaterial(); - - // Mesh child with five materials so the compound material map is recorded - b3MeshData* compoundMeshData = b3CreateGridMesh( 1, 5, 1.0f, 5, false ); - ENSURE( compoundMeshData != NULL ); - ENSURE( compoundMeshData->materialCount == 5 ); - b3SurfaceMaterial compoundMeshMaterials[5]; - for ( int i = 0; i < 5; ++i ) - { - compoundMeshMaterials[i] = b3DefaultSurfaceMaterial(); - } - b3CompoundMeshDef compMesh; - memset( &compMesh, 0, sizeof( compMesh ) ); - compMesh.meshData = compoundMeshData; - compMesh.transform = b3Transform_identity; - compMesh.scale = (b3Vec3){ 1.0f, 1.0f, 1.0f }; - compMesh.materials = compoundMeshMaterials; - compMesh.materialCount = 5; - b3CompoundDef compoundDef; memset( &compoundDef, 0, sizeof( compoundDef ) ); compoundDef.spheres = &compSphere; compoundDef.sphereCount = 1; - compoundDef.meshes = &compMesh; - compoundDef.meshCount = 1; b3CompoundData* compound = b3CreateCompound( &compoundDef ); ENSURE( compound != NULL ); b3ShapeDef compoundShapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( compoundBodyId, &compoundShapeDef, compound ); + b3CreateCompoundShape( compoundBodyId, &compoundShapeDef, compound ); // Throwaway shape to exercise DestroyShape b3Sphere tmpSphere = { { 0.0f, 0.0f, 0.0f }, 0.1f }; b3ShapeId tmpShapeId = b3CreateSphereShape( capsuleBodyId, &capsuleShapeDef, &tmpSphere ); b3DestroyShape( tmpShapeId, true ); - // Shape mutators: SetFriction, SetRestitution, SetDensity, SetSurfaceMaterial, SetMeshMaterial, - // SetFilter, EnableSensorEvents, EnableContactEvents, EnableHitEvents, EnablePreSolveEvents, - // ApplyWind, SetSphere, SetCapsule, SetHull, SetMesh, SetName + // Shape mutators: SetFriction, SetRestitution, SetDensity, SetSurfaceMaterial, SetFilter, + // EnableSensorEvents, EnableContactEvents, EnableHitEvents, EnablePreSolveEvents, ApplyWind, + // SetSphere, SetCapsule b3Shape_SetFriction( boxShapeId, 0.3f ); b3Shape_SetRestitution( capsuleShapeId, 0.5f ); b3Shape_SetDensity( boxShapeId, 3.0f, true ); @@ -1350,20 +1179,11 @@ static int AllOps( void ) b3Shape_SetSphere( sphereShapeId, &newSphere ); b3Capsule newCapsule = { { 0.0f, -0.3f, 0.0f }, { 0.0f, 0.3f, 0.0f }, 0.3f }; b3Shape_SetCapsule( capsuleShapeId, &newCapsule ); - b3Shape_SetName( boxShapeId, "box" ); - - // Geometry swaps intern into the registry at the record site. The repeated SetHull takes the - // shared hull short circuit, which changes nothing and so must leave the stream alone. - b3BoxHull swapHull = b3MakeBoxHull( 0.3f, 0.7f, 0.4f ); - b3Shape_SetHull( boxShapeId, &swapHull.base ); - b3Shape_SetHull( boxShapeId, &swapHull.base ); - b3Shape_SetMesh( meshShapeId, swapMeshData, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - b3Shape_SetMeshMaterial( meshShapeId, surfMat, 0 ); // Body mutators: SetTransform, SetLinearVelocity/AngularVelocity (Vec3), SetName, // damping, gravity scale, sleep threshold, SetAwake, EnableSleep, SetBullet, SetMotionLocks, - // SetMassData, ApplyMassFromShapes, SetType, SetTargetTransform, Disable/Enable, - // EnableContactRecycling, EnableHitEvents, all force/impulse/torque variants + // SetMassData, ApplyMassFromShapes, SetType, SetTargetTransform, Disable/Enable, EnableContactRecycling, + // EnableHitEvents, all force/impulse/torque variants b3Body_SetTransform( bodyId, (b3Pos){ 1.0f, 6.0f, 0.0f }, b3Quat_identity ); b3Body_SetLinearVelocity( bodyId, (b3Vec3){ 0.5f, 0.0f, 0.0f } ); b3Body_SetAngularVelocity( bodyId, (b3Vec3){ 0.0f, 0.25f, 0.0f } ); @@ -1404,34 +1224,17 @@ static int AllOps( void ) b3BodyDef disableDef = b3DefaultBodyDef(); disableDef.type = b3_dynamicBody; disableDef.position = (b3Pos){ 9.0f, 5.0f, 0.0f }; - disableDef.name = "dropBody"; b3BodyId disableId = b3CreateBody( worldId, &disableDef ); b3Sphere disableSphere = { { 0.0f, 0.0f, 0.0f }, 0.3f }; b3CreateSphereShape( disableId, &sphereShapeDef, &disableSphere ); b3Body_Disable( disableId ); b3Body_Enable( disableId ); - b3Body_SetSafetyFactor( disableId, 0.25f ); - - // A body that falls fast enough to stay on the continuous path for the whole session. The - // non-default factor is what proves the widened body def payload round-trips, since every - // other body records the default. Named so the replay check can find it. - b3BodyDef fastDef = b3DefaultBodyDef(); - fastDef.type = b3_dynamicBody; - fastDef.position = (b3Pos){ -14.0f, 30.0f, 0.0f }; - fastDef.linearVelocity = (b3Vec3){ 0.0f, -8.0f, 0.0f }; - fastDef.safetyFactor = 0.1f; - fastDef.name = "fastBody"; - b3BodyId fastId = b3CreateBody( worldId, &fastDef ); - ENSURE( b3Body_GetSafetyFactor( fastId ) == 0.1f ); - b3BoxHull fastBox = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CreateHullShape( fastId, &sphereShapeDef, &fastBox.base ); // Force/impulse/torque (Vec3 args in 3D) b3Body_ApplyForce( bodyId, (b3Vec3){ 0.0f, 50.0f, 0.0f }, (b3Pos){ 1.0f, 6.0f, 0.0f }, true ); b3Body_ApplyForceToCenter( bodyId, (b3Vec3){ 5.0f, 0.0f, 0.0f }, true ); b3Body_ApplyTorque( bodyId, (b3Vec3){ 0.0f, 1.0f, 0.0f }, true ); - b3Body_ApplyLinearImpulse( bodyId, (b3Vec3){ 0.1f, 0.0f, 0.0f }, (b3Pos){ 1.0f, 6.0f, 0.0f }, - true ); + b3Body_ApplyLinearImpulse( bodyId, (b3Vec3){ 0.1f, 0.0f, 0.0f }, (b3Pos){ 1.0f, 6.0f, 0.0f }, true ); b3Body_ApplyLinearImpulseToCenter( bodyId, (b3Vec3){ 0.0f, 0.1f, 0.0f }, true ); b3Body_ApplyAngularImpulse( bodyId, (b3Vec3){ 0.0f, 0.05f, 0.0f }, true ); @@ -1467,8 +1270,7 @@ static int AllOps( void ) b3RevoluteJoint_SetSpringDampingRatio( revId, 0.5f ); b3RevoluteJoint_SetTargetAngle( revId, 0.25f ); b3Joint_SetLocalFrameA( revId, (b3Transform){ (b3Vec3){ 1.0f, 0.0f, 0.0f }, b3Quat_identity } ); - b3Joint_SetLocalFrameB( revId, - (b3Transform){ (b3Vec3){ -1.0f, 0.0f, 0.0f }, b3Quat_identity } ); + b3Joint_SetLocalFrameB( revId, (b3Transform){ (b3Vec3){ -1.0f, 0.0f, 0.0f }, b3Quat_identity } ); b3Joint_SetConstraintTuning( revId, 60.0f, 2.0f ); b3Joint_SetForceThreshold( revId, 100.0f ); b3Joint_SetTorqueThreshold( revId, 50.0f ); @@ -1594,46 +1396,6 @@ static int AllOps( void ) b3ParallelJoint_SetSpringDampingRatio( parallelId, 0.5f ); b3ParallelJoint_SetMaxTorque( parallelId, 20.0f ); - // Dynamic mover: a rotation locked capsule driven by a mover joint and held up by a pogo joint - b3BodyDef moverBodyDef = b3DefaultBodyDef(); - moverBodyDef.type = b3_dynamicBody; - moverBodyDef.position = (b3Pos){ -20.0f, 3.0f, 0.0f }; - moverBodyDef.motionLocks = - (b3MotionLocks){ .angularX = true, .angularY = true, .angularZ = true }; - b3BodyId moverBodyId = b3CreateBody( worldId, &moverBodyDef ); - b3ShapeDef moverShapeDef = b3DefaultShapeDef(); - moverShapeDef.density = 1.0f; - moverShapeDef.baseMaterial.friction = 0.0f; - b3Capsule moverCapsule = { { 0.0f, -0.5f, 0.0f }, { 0.0f, 0.5f, 0.0f }, 0.3f }; - b3CreateCapsuleShape( moverBodyId, &moverShapeDef, &moverCapsule ); - - b3MoverJointDef moverDef = b3DefaultMoverJointDef(); - moverDef.base.bodyIdA = groundId; - moverDef.base.bodyIdB = moverBodyId; - moverDef.base.collideConnected = true; - moverDef.linearVelocity = (b3Vec3){ 1.0f, 0.0f, 0.5f }; - moverDef.maxForce = 0.5f; - b3JointId moverJointId = b3CreateMoverJoint( worldId, &moverDef ); - - b3PogoJointDef pogoDef = b3DefaultPogoJointDef(); - pogoDef.base.bodyIdA = groundId; - pogoDef.base.bodyIdB = moverBodyId; - pogoDef.base.localFrameA.p = (b3Vec3){ -20.0f, 1.0f, 0.0f }; - pogoDef.base.localFrameB.p = moverCapsule.center1; - pogoDef.base.collideConnected = true; - pogoDef.restLength = 1.0f; - pogoDef.hertz = 5.0f; - pogoDef.dampingRatio = 0.8f; - pogoDef.maxCompressionForce = 1000.0f; - pogoDef.maxTensionForce = 1000.0f; - b3JointId pogoJointId = b3CreatePogoJoint( worldId, &pogoDef ); - b3PogoJoint_SetRestLength( pogoJointId, 0.9f ); - b3PogoJoint_SetSpringHertz( pogoJointId, 4.0f ); - b3PogoJoint_SetSpringDampingRatio( pogoJointId, 0.7f ); - b3PogoJoint_SetNormal( pogoJointId, b3Normalize( (b3Vec3){ 0.2f, 1.0f, 0.0f } ) ); - b3PogoJoint_SetMaxTensionForce( pogoJointId, 800.0f ); - b3PogoJoint_SetMaxCompressionForce( pogoJointId, 900.0f ); - // World config mutators b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -9.8f, 0.0f } ); b3World_EnableSleeping( worldId, true ); @@ -1641,29 +1403,12 @@ static int AllOps( void ) b3World_EnableWarmStarting( worldId, true ); b3World_EnableSpeculative( worldId, true ); b3World_SetRestitutionThreshold( worldId, 1.5f ); - b3World_SetRestitutionIterations( worldId, 3 ); - b3World_EnableRestitutionPropagation( worldId, true ); b3World_SetHitEventThreshold( worldId, 2.0f ); b3World_SetContactTuning( worldId, 30.0f, 10.0f, 3.0f ); b3World_SetContactRecycleDistance( worldId, 0.05f ); b3World_SetMaximumLinearSpeed( worldId, 100.0f ); b3World_RebuildStaticTree( worldId ); - // The tolerance only reaches bodies whose mass is computed afterwards. A free spinning rod made - // after the change loses its gyroscopic torque, so replay diverges if the op goes missing. - b3World_SetIsotropicInertiaTolerance( worldId, 1.0f ); - { - b3BodyDef rodDef = b3DefaultBodyDef(); - rodDef.type = b3_dynamicBody; - rodDef.position = (b3Pos){ 40.0f, 10.0f, 0.0f }; - rodDef.gravityScale = 0.0f; - rodDef.angularVelocity = (b3Vec3){ 1.0f, 5.0f, 0.5f }; - b3BodyId rodId = b3CreateBody( worldId, &rodDef ); - b3BoxHull rod = b3MakeBoxHull( 0.1f, 1.0f, 0.1f ); - b3ShapeDef rodShapeDef = b3DefaultShapeDef(); - b3CreateHullShape( rodId, &rodShapeDef, &rod.base ); - } - b3ExplosionDef explosion = b3DefaultExplosionDef(); explosion.position = (b3Pos){ 0.0f, 5.0f, 0.0f }; explosion.radius = 3.0f; @@ -1684,8 +1429,7 @@ static int AllOps( void ) b3World_CastRayClosest( worldId, qorigin, qTranslation, qfilter ); b3World_CastShape( worldId, qorigin, &proxy, qTranslation, qfilter, QueryReplayCastFcn, NULL ); b3Capsule mover = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 0.3f }; - b3World_CastMover( worldId, qorigin, &mover, qTranslation, qfilter, QueryReplayMoverFilterFcn, - NULL ); + b3World_CastMover( worldId, qorigin, &mover, qTranslation, qfilter, QueryReplayMoverFilterFcn, NULL ); b3World_CollideMover( worldId, qorigin, &mover, qfilter, QueryReplayPlaneFcn, NULL ); float timeStep = 1.0f / 60.0f; @@ -1697,22 +1441,8 @@ static int AllOps( void ) { b3Body_ApplyLinearImpulseToCenter( capsuleBodyId, (b3Vec3){ 2.0f, 0.0f, 0.0f }, true ); b3Body_SetGravityScale( bodyId, 1.0f ); - b3Body_SetSafetyFactor( fastId, 0.4f ); - b3MoverJoint_SetMaxVelocityForce( moverJointId, 60.0f ); } - // The dynamic mover rebuilds its pogo every step, warm started from the old one - if ( i >= 6 ) - { - pogoDef.impulse = b3PogoJoint_GetImpulse( pogoJointId ); - pogoDef.velocity = b3PogoJoint_GetCurrentSpeed( pogoJointId ); - pogoDef.base.localFrameA.p = - b3Body_GetLocalPoint( groundId, b3Body_GetPosition( moverBodyId ) ); - pogoDef.base.localFrameA.p.y = 1.0f; - b3DestroyJoint( pogoJointId, false ); - pogoJointId = b3CreatePogoJoint( worldId, &pogoDef ); - b3MoverJoint_SetLinearVelocity( moverJointId, (b3Vec3){ -0.5f, 0.0f, 1.0f } ); - } // Issue queries mid-loop to exercise recording across steps if ( i == 3 ) { @@ -1729,10 +1459,8 @@ static int AllOps( void ) // Free geometry allocated for this subtest b3DestroyHull( customHull ); b3DestroyMesh( meshData ); - b3DestroyMesh( swapMeshData ); b3DestroyHeightField( hf ); b3DestroyCompound( compound ); - b3DestroyMesh( compoundMeshData ); const uint8_t* recData = b3Recording_GetData( rec ); int recSize = b3Recording_GetSize( rec ); @@ -1752,13 +1480,9 @@ static int AllOps( void ) // Drive the incremental player. Exercises per-frame stepping, restart, getters, and the // draw path beyond what b3ValidateReplay covers. { - b3RecPlayer* player = b3CreatePlayer( recData, recSize, 1 ); + b3RecPlayer* player = b3RecPlayer_Create( recData, recSize, 1 ); ENSURE( player != NULL ); - // Capture keyframes while every geometry kind is live. The default interval is longer - // than this recording. - b3RecPlayer_SetKeyframePolicy( player, b3RecPlayer_GetKeyframeBudget( player ), 4 ); - b3RecPlayerInfo info = b3RecPlayer_GetInfo( player ); b3Vec3 recExtents = b3Sub( info.bounds.upperBound, info.bounds.lowerBound ); ENSURE( recExtents.x > 0.0f && recExtents.y > 0.0f ); @@ -1782,28 +1506,6 @@ static int AllOps( void ) ENSURE( b3RecPlayer_GetFrame( player ) == 12 ); ENSURE( b3RecPlayer_IsAtEnd( player ) ); ENSURE( b3RecPlayer_HasDiverged( player ) == false ); - ENSURE( b3RecPlayer_GetKeyframeBytes( player ) > 0 ); - - // Seek back onto the frame 4 keyframe, then skip forward onto the frame 8 keyframe. Each - // restore rebuilds the compound from the registry, so a ray must still reach its tree and - // the state hashes must hold through the re-stepped frames. - int seekTargets[] = { 6, 9 }; - for ( int k = 0; k < 2; ++k ) - { - b3RecPlayer_SeekFrame( player, seekTargets[k] ); - ENSURE( b3RecPlayer_GetFrame( player ) == seekTargets[k] ); - - bool hitCompound = false; - b3World_CastRay( b3RecPlayer_GetWorldId( player ), (b3Pos){ 30.0f, 10.0f, 0.0f }, - (b3Vec3){ 0.0f, -20.0f, 0.0f }, b3DefaultQueryFilter(), - CompoundHitCastFcn, &hitCompound ); - ENSURE( hitCompound ); - } - while ( b3RecPlayer_StepFrame( player ) ) - { - } - ENSURE( b3RecPlayer_GetFrame( player ) == 12 ); - ENSURE( b3RecPlayer_HasDiverged( player ) == false ); // The trailing DestroyWorld is an end marker; the world stays valid after end ENSURE( b3World_IsValid( b3RecPlayer_GetWorldId( player ) ) ); @@ -1821,27 +1523,7 @@ static int AllOps( void ) ENSURE( frames2 == 12 ); ENSURE( b3RecPlayer_HasDiverged( player ) == false ); - b3DestroyPlayer( player ); - } - - // The state hash only proves the op stream stayed aligned. Read the safety factor back out of - // the replay world so a value that is written but never restored is caught too. - { - b3RecPlayer* player = b3CreatePlayer( recData, recSize, 1 ); - ENSURE( player != NULL ); - - // Frame 0 replays the pre-step creates, so the def value is in place - ENSURE( b3RecPlayer_StepFrame( player ) ); - ENSURE( ReplaySafetyFactor( player, "fastBody" ) == 0.1f ); - ENSURE( ReplaySafetyFactor( player, "dropBody" ) == 0.25f ); - - // The setter is injected at frame 6 - while ( b3RecPlayer_StepFrame( player ) ) - { - } - ENSURE( ReplaySafetyFactor( player, "fastBody" ) == 0.4f ); - - b3DestroyPlayer( player ); + b3RecPlayer_Destroy( player ); } b3DestroyRecording( rec ); @@ -1855,9 +1537,10 @@ static int AllOps( void ) static int TransformedHullRoundTrip( void ) { b3Vec3 pts[8] = { - { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, { 1.0f, 1.0f, -1.0f }, - { -1.0f, 1.0f, -1.0f }, { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, - { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, + { -1.0f, -1.0f, -1.0f }, { 1.0f, -1.0f, -1.0f }, + { 1.0f, 1.0f, -1.0f }, { -1.0f, 1.0f, -1.0f }, + { -1.0f, -1.0f, 1.0f }, { 1.0f, -1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, { -1.0f, 1.0f, 1.0f }, }; b3HullData* hull = b3CreateHull( pts, 8, 8 ); ENSURE( hull != NULL ); @@ -1866,42 +1549,39 @@ static int TransformedHullRoundTrip( void ) ENSURE( rec != NULL ); b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); + b3WorldId worldId = b3CreateWorld( &worldDef ); b3World_StartRecording( worldId, rec ); b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; + shapeDef.density = 1.0f; - // Baked transform with a rotation and non-uniform scale, the path Unreal uses for instanced - // hulls. - b3Transform xf = { (b3Vec3){ 0.25f, 0.0f, -0.5f }, - b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 0.0f, 1.0f }, 0.3f ) }; - b3Vec3 scl = { 1.5f, 0.5f, 2.0f }; + // Baked transform with a rotation and non-uniform scale, the path Unreal uses for instanced hulls. + b3Transform xf = { (b3Vec3){ 0.25f, 0.0f, -0.5f }, b3MakeQuatFromAxisAngle( (b3Vec3){ 0.0f, 0.0f, 1.0f }, 0.3f ) }; + b3Vec3 scl = { 1.5f, 0.5f, 2.0f }; for ( int i = 0; i < 3; ++i ) { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ (float)( i * 3 ), 5.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ (float)( i * 3 ), 5.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3ShapeId sid = b3CreateTransformedHullShape( bodyId, &shapeDef, hull, xf, scl ); ENSURE( b3Shape_IsValid( sid ) ); } - // A plain hull after the transformed ones: if the transformed creates desynced the id pool, - // this shape's recorded id would not match what replay allocates and b3ValidateReplay would - // fail. + // A plain hull after the transformed ones: if the transformed creates desynced the id pool, this + // shape's recorded id would not match what replay allocates and b3ValidateReplay would fail. { b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 10.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); + bodyDef.type = b3_dynamicBody; + bodyDef.position = (b3Pos){ 0.0f, 10.0f, 0.0f }; + b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); b3ShapeId sid = b3CreateHullShape( bodyId, &shapeDef, hull ); ENSURE( b3Shape_IsValid( sid ) ); } - // Step past the keyframe interval so replay captures a keyframe. That path re-serializes the - // live world and interns the baked hull, which must already be in the pre-seeded registry. + // Step past the keyframe interval so replay captures a keyframe. That path re-serializes the live + // world and interns the baked hull, which must already be in the pre-seeded registry. for ( int i = 0; i < 20; ++i ) { b3World_Step( worldId, 1.0f / 60.0f, 4 ); @@ -1973,112 +1653,33 @@ static int ReservedHeaderBytes( void ) return 0; } -// A corrupt compound in the geometry registry must fail the replay cleanly. A stale version or a -// wrong kind is rejected when the shape is created and a truncated entry is rejected at load. -static int CorruptCompound( void ) -{ - b3CompoundSphereDef sphereDef; - sphereDef.sphere = (b3Sphere){ { 0.0f, 0.0f, 0.0f }, 1.0f }; - sphereDef.material = b3DefaultSurfaceMaterial(); - b3CompoundDef compoundDef; - memset( &compoundDef, 0, sizeof( compoundDef ) ); - compoundDef.spheres = &sphereDef; - compoundDef.sphereCount = 1; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - int compoundByteCount = compound->byteCount; - - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3World_StartRecording( worldId, rec ); - - b3BodyDef bd = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &bd ); - b3ShapeDef sd = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( groundId, &sd, compound ); - - bd.type = b3_dynamicBody; - bd.position = (b3Pos){ 0.0f, 3.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bd ); - b3Sphere s = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( bodyId, &sd, &s ); - - for ( int i = 0; i < 10; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - - const uint8_t* recData = b3Recording_GetData( rec ); - int recSize = b3Recording_GetSize( rec ); - ENSURE( b3ValidateReplay( recData, recSize, 1 ) ); - - // The registry entry is a kind byte and a 4 byte length, then the blob, which leads with its - // version - uint64_t version = B3_COMPOUND_VERSION; - int blobOffset = -1; - for ( int i = 5; i + (int)sizeof( version ) <= recSize; ++i ) - { - if ( memcmp( recData + i, &version, sizeof( version ) ) == 0 ) - { - blobOffset = i; - break; - } - } - ENSURE( blobOffset > 0 ); - ENSURE( recData[blobOffset - 5] == (uint8_t)b3_geometryCompound ); - int32_t storedByteCount; - memcpy( &storedByteCount, recData + blobOffset - 4, sizeof( storedByteCount ) ); - ENSURE( storedByteCount == compoundByteCount ); - - uint8_t* patched = (uint8_t*)b3Alloc( (size_t)recSize ); - - memcpy( patched, recData, (size_t)recSize ); - patched[blobOffset] ^= 0xFF; - ENSURE( b3ValidateReplay( patched, recSize, 1 ) == false ); - - memcpy( patched, recData, (size_t)recSize ); - int32_t shortByteCount = 8; - memcpy( patched + blobOffset - 4, &shortByteCount, sizeof( shortByteCount ) ); - ENSURE( b3CreatePlayer( patched, recSize, 1 ) == NULL ); - - memcpy( patched, recData, (size_t)recSize ); - int32_t zeroByteCount = 0; - memcpy( patched + blobOffset - 4, &zeroByteCount, sizeof( zeroByteCount ) ); - ENSURE( b3CreatePlayer( patched, recSize, 1 ) == NULL ); - - memcpy( patched, recData, (size_t)recSize ); - patched[blobOffset - 5] = (uint8_t)b3_geometryMesh; - ENSURE( b3ValidateReplay( patched, recSize, 1 ) == false ); - - b3Free( patched, (size_t)recSize ); - b3DestroyRecording( rec ); - return 0; -} - // Geometry that shares a content hash but differs in bytes must dedup exactly. Mirrors the keyframe -// flow that crashed: the seed appends every slot 1:1 (even byte-identical duplicates a hash -// collision left in an already-recorded file), then capture must resolve a live blob back to an -// existing slot without growing the registry. Forces the collision by handing the same hash to -// distinct blobs. +// flow that crashed: the seed appends every slot 1:1 (even byte-identical duplicates a hash collision +// left in an already-recorded file), then capture must resolve a live blob back to an existing slot +// without growing the registry. Forces the collision by handing the same hash to distinct blobs. static int GeometryHashCollision( void ) { - enum - { - n = 16 - }; + const int n = 16; const uint64_t sharedHash = 0xABCD1234ull; + // The content hash must use its full width: a one-byte change in a same-length blob has to perturb + // the high word too, not just the low one, which is the trap a reseeded 32-bit djb2 fell into. + { + uint8_t p[16]; + uint8_t q[16]; + memset( p, 0x11, sizeof( p ) ); + memset( q, 0x11, sizeof( q ) ); + q[7] = 0x12; + uint64_t hp = b3Hash64Blob( p, (int)sizeof( p ) ); + uint64_t hq = b3Hash64Blob( q, (int)sizeof( q ) ); + ENSURE( hp != hq ); + ENSURE( (uint32_t)( hp >> 32 ) != (uint32_t)( hq >> 32 ) ); + } + b3GeometryRegistry reg = { 0 }; - uint8_t blobA[n]; - uint8_t blobB[n]; + uint8_t* blobA = (uint8_t*)b3Alloc( (size_t)n ); + uint8_t* blobB = (uint8_t*)b3Alloc( (size_t)n ); memset( blobA, 0xAA, (size_t)n ); memset( blobB, 0xBB, (size_t)n ); @@ -2086,29 +1687,29 @@ static int GeometryHashCollision( void ) uint32_t idA = b3InternGeometry( ®, b3_geometryHull, sharedHash, blobA, n ); uint32_t idB = b3InternGeometry( ®, b3_geometryHull, sharedHash, blobB, n ); ENSURE( idA != idB ); - ENSURE( reg.entries.count == 2 ); + ENSURE( reg.count == 2 ); // Re-interning either blob must find it through the hash chain and never grow the registry, // including the one shadowed behind the bucket head. The old single-entry lookup missed the // shadowed blob and appended a duplicate, which is exactly what tripped the keyframe assert. - uint8_t blobA2[n]; + uint8_t* blobA2 = (uint8_t*)b3Alloc( (size_t)n ); memset( blobA2, 0xAA, (size_t)n ); ENSURE( b3InternGeometry( ®, b3_geometryHull, sharedHash, blobA2, n ) == idA ); - ENSURE( reg.entries.count == 2 ); + ENSURE( reg.count == 2 ); - uint8_t blobB2[n]; + uint8_t* blobB2 = (uint8_t*)b3Alloc( (size_t)n ); memset( blobB2, 0xBB, (size_t)n ); ENSURE( b3InternGeometry( ®, b3_geometryHull, sharedHash, blobB2, n ) == idB ); - ENSURE( reg.entries.count == 2 ); + ENSURE( reg.count == 2 ); b3FreeRegistry( ® ); - // Seed-then-capture: appending byte-identical duplicate slots keeps id == slot index, and a - // later exact intern still resolves to one of them without appending a new entry. + // Seed-then-capture: appending byte-identical duplicate slots keeps id == slot index, and a later + // exact intern still resolves to one of them without appending a new entry. b3GeometryRegistry seeded = { 0 }; - uint8_t slot0[n]; - uint8_t slot1[n]; - uint8_t slot2[n]; + uint8_t* slot0 = (uint8_t*)b3Alloc( (size_t)n ); + uint8_t* slot1 = (uint8_t*)b3Alloc( (size_t)n ); + uint8_t* slot2 = (uint8_t*)b3Alloc( (size_t)n ); memset( slot0, 0xAA, (size_t)n ); memset( slot1, 0xBB, (size_t)n ); memset( slot2, 0xAA, (size_t)n ); // duplicate of slot0 @@ -2116,381 +1717,26 @@ static int GeometryHashCollision( void ) ENSURE( b3AppendGeometry( &seeded, b3_geometryHull, sharedHash, slot1, n ) == 1 ); ENSURE( b3AppendGeometry( &seeded, b3_geometryHull, sharedHash, slot2, n ) == 2 ); - uint8_t live[n]; + uint8_t* live = (uint8_t*)b3Alloc( (size_t)n ); memset( live, 0xAA, (size_t)n ); uint32_t resolved = b3InternGeometry( &seeded, b3_geometryHull, sharedHash, live, n ); - ENSURE( seeded.entries.count == 3 ); // no growth - ENSURE( resolved == 0 || resolved == 2 ); // a valid slot index for that content - ENSURE( seeded.entries.data[resolved].byteCount == n ); - ENSURE( memcmp( seeded.entries.data[resolved].bytes, slot0, (size_t)n ) == 0 ); + ENSURE( seeded.count == 3 ); // no growth + ENSURE( resolved == 0 || resolved == 2 ); // a valid slot index for that content + ENSURE( seeded.entries[resolved].byteCount == n ); + ENSURE( memcmp( seeded.entries[resolved].bytes, slot0, (size_t)n ) == 0 ); b3FreeRegistry( &seeded ); return 0; } -// Staged stepping must reveal a mid-stream body at its creation transform. A body created and given -// an impulse in one recorded step is first placed by CreateBody, then displaced by the following -// Step. Atomic replay fuses the two, so the body is only ever seen already moved. Staged replay -// parks between them so the pre-integration pose is drawable. Verify the parked pose is the -// creation transform, that atomic replay does not show it, and that the extra park does not perturb -// the end state. -static int StagedStepCreationPose( void ) -{ - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3World_SetGravity( worldId, (b3Vec3){ 0.0f, -10.0f, 0.0f } ); - - b3World_StartRecording( worldId, rec ); - - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; - - // A few empty steps so the creation lands inside the stream, not at frame 0. - const int leadFrames = 3; - for ( int i = 0; i < leadFrames; ++i ) - { - b3World_Step( worldId, timeStep, subStepCount ); - } - - // The creation transform under test. No ground, so the body is the only create and stays - // ballistic. Components are exact in float so the round-trip pose compares tight. - const b3Pos spawn = { 1.0, 20.0, -2.0 }; - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = spawn; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - // Impulse along +x so the first integrated step moves the body a visible distance off the - // spawn. - b3Body_ApplyLinearImpulseToCenter( bodyId, (b3Vec3){ 5.0f, 0.0f, 0.0f }, true ); - - const int creationFrame = leadFrames + 1; - b3World_Step( worldId, timeStep, subStepCount ); // advances to creationFrame - - const int totalFrames = creationFrame + 3; - for ( int i = creationFrame; i < totalFrames; ++i ) - { - b3World_Step( worldId, timeStep, subStepCount ); - } - - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - - const uint8_t* data = b3Recording_GetData( rec ); - int sz = b3Recording_GetSize( rec ); - - // Atomic replay fuses the create and its step, so at the creation frame the body is already - // integrated and displaced along +x. Capture that pose and the final state hash. - b3RecPlayer* atomic = b3CreatePlayer( data, sz, 1 ); - ENSURE( atomic != NULL ); - b3Pos atomicPose = { 0.0, 0.0, 0.0 }; - while ( !b3RecPlayer_IsAtEnd( atomic ) ) - { - b3RecPlayer_StepFrame( atomic ); - if ( b3RecPlayer_GetFrame( atomic ) == creationFrame ) - { - b3BodyId id = b3RecPlayer_GetBodyId( atomic, 0 ); - ENSURE( b3Body_IsValid( id ) ); - atomicPose = b3Body_GetPosition( id ); - } - } - ENSURE( b3RecPlayer_GetFrame( atomic ) == totalFrames ); - ENSURE( !b3RecPlayer_HasDiverged( atomic ) ); - ENSURE( atomicPose.x - spawn.x > 0.01 ); // the impulse moved it before it was ever seen - uint64_t atomicHash = b3HashWorldState( b3GetWorldFromId( b3RecPlayer_GetWorldId( atomic ) ) ); - b3DestroyPlayer( atomic ); - - // Staged replay: step forward until the first pre-step park. It must sit at the creation - // frame's pre-integration state with the new body at exactly its spawn transform. - b3RecPlayer* staged = b3CreatePlayer( data, sz, 1 ); - ENSURE( staged != NULL ); - while ( !b3RecPlayer_IsAtEnd( staged ) ) - { - b3RecPlayer_SubStepFrame( staged ); - if ( b3RecPlayer_IsAtPreStep( staged ) ) - { - break; - } - } - ENSURE( b3RecPlayer_IsAtPreStep( staged ) ); - ENSURE( b3RecPlayer_GetFrame( staged ) == - creationFrame - 1 ); // parked before the step, frame not advanced - - b3BodyId stagedId = b3RecPlayer_GetBodyId( staged, 0 ); - ENSURE( b3Body_IsValid( stagedId ) ); - b3Pos parkPose = b3Body_GetPosition( stagedId ); - ENSURE_SMALL( parkPose.x - spawn.x, 1.0e-4 ); - ENSURE_SMALL( parkPose.y - spawn.y, 1.0e-4 ); - ENSURE_SMALL( parkPose.z - spawn.z, 1.0e-4 ); - - // Finishing the frame integrates the body, so it leaves the spawn pose on the next advance. - b3RecPlayer_SubStepFrame( staged ); - ENSURE( b3RecPlayer_GetFrame( staged ) == creationFrame ); - ENSURE( !b3RecPlayer_IsAtPreStep( staged ) ); - - // Run staged to the end: the same op stream, so it must land on the atomic end state bit for - // bit. - while ( !b3RecPlayer_IsAtEnd( staged ) ) - { - b3RecPlayer_SubStepFrame( staged ); - } - ENSURE( b3RecPlayer_GetFrame( staged ) == totalFrames ); - ENSURE( !b3RecPlayer_HasDiverged( staged ) ); - uint64_t stagedHash = b3HashWorldState( b3GetWorldFromId( b3RecPlayer_GetWorldId( staged ) ) ); - ENSURE( stagedHash == atomicHash ); - b3DestroyPlayer( staged ); - - b3DestroyRecording( rec ); - return 0; -} - -// Shape names are debug only and do not feed the determinism hash, so b3ValidateReplay cannot catch -// a broken name round-trip. Replay through the player and read the names back to prove the def -// field and the ShapeSetName op survive serialization. -static int ShapeNameReplay( void ) -{ - const char* names[3] = { - "def", - "set", - "abcdefghijklmnopqrstuvwxyz", - }; - - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3World_StartRecording( worldId, rec ); - - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - - // One shape per body so read-back never depends on per-body shape ordering. - for ( int i = 0; i < 3; ++i ) - { - b3BodyDef bd = b3DefaultBodyDef(); - bd.type = b3_dynamicBody; - bd.position = (b3Pos){ 3.0f * (float)i, 5.0f, 0.0f }; - b3BodyId body = b3CreateBody( worldId, &bd ); - - b3ShapeDef sd = b3DefaultShapeDef(); - sd.density = 1.0f; - if ( i != 1 ) - { - sd.name = names[i]; - } - b3ShapeId shape = b3CreateSphereShape( body, &sd, &sphere ); - if ( i == 1 ) - { - b3Shape_SetName( shape, names[i] ); - } - } - - for ( int i = 0; i < 4; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - - const uint8_t* data = b3Recording_GetData( rec ); - int sz = b3Recording_GetSize( rec ); - - b3RecPlayer* player = b3CreatePlayer( data, sz, 1 ); - ENSURE( player != NULL ); - while ( b3RecPlayer_StepFrame( player ) ) - { - } - ENSURE( b3RecPlayer_HasDiverged( player ) == false ); - - // Body ordinals follow creation order in the replayed world. - for ( int i = 0; i < 3; ++i ) - { - b3BodyId body = b3RecPlayer_GetBodyId( player, i ); - ENSURE( b3Body_IsValid( body ) ); - - b3ShapeId shape; - ENSURE( b3Body_GetShapes( body, &shape, 1 ) == 1 ); - const char* got = b3Shape_GetName( shape ); - ENSURE( got != NULL ); - - int srcLen = (int)strlen( names[i] ); - ENSURE( (int)strlen( got ) == srcLen ); - if ( srcLen > 0 ) - { - ENSURE( strncmp( got, names[i], (size_t)srcLen ) == 0 ); - } - } - - b3DestroyPlayer( player ); - b3DestroyRecording( rec ); - return 0; -} - -// A box sliding across a mesh floor, with the option to swap both geometries and retune a -// per-triangle material part way through. Returns the final state hash so the caller can prove the -// mutations move the simulation. Recording is optional so the same scene serves as the control. -static uint64_t RunGeometryMutatorScene( b3Recording* rec, bool mutate, const b3MeshData* meshA, - const b3MeshData* meshB, const b3HullData* swapHull, - float swapFriction ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 1; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - if ( rec != NULL ) - { - b3World_StartRecording( worldId, rec ); - } - - // The mesh body is created first so its ordinal is stable for the read back after replay. - b3SurfaceMaterial meshMaterials[2] = { b3DefaultSurfaceMaterial(), b3DefaultSurfaceMaterial() }; - meshMaterials[1].friction = 0.05f; - - b3BodyDef meshBodyDef = b3DefaultBodyDef(); - meshBodyDef.type = b3_staticBody; - b3BodyId meshBodyId = b3CreateBody( worldId, &meshBodyDef ); - - b3ShapeDef meshShapeDef = b3DefaultShapeDef(); - meshShapeDef.materials = meshMaterials; - meshShapeDef.materialCount = 2; - b3ShapeId meshShapeId = - b3CreateMeshShape( meshBodyId, &meshShapeDef, meshA, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - - b3BodyDef boxBodyDef = b3DefaultBodyDef(); - boxBodyDef.type = b3_dynamicBody; - boxBodyDef.position = (b3Pos){ -2.0f, 2.0f, 0.0f }; - boxBodyDef.linearVelocity = (b3Vec3){ 4.0f, 0.0f, 0.0f }; - b3BodyId boxBodyId = b3CreateBody( worldId, &boxBodyDef ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef boxShapeDef = b3DefaultShapeDef(); - boxShapeDef.density = 1.0f; - b3ShapeId boxShapeId = b3CreateHullShape( boxBodyId, &boxShapeDef, &box.base ); - - float timeStep = 1.0f / 60.0f; - for ( int i = 0; i < 10; ++i ) - { - b3World_Step( worldId, timeStep, 4 ); - } - - if ( mutate ) - { - b3Shape_SetHull( boxShapeId, swapHull ); - b3Shape_SetMesh( meshShapeId, meshB, (b3Vec3){ 1.0f, 1.0f, 1.0f } ); - - b3SurfaceMaterial grippy = b3DefaultSurfaceMaterial(); - grippy.friction = swapFriction; - b3Shape_SetMeshMaterial( meshShapeId, grippy, 1 ); - } - - for ( int i = 0; i < 30; ++i ) - { - b3World_Step( worldId, timeStep, 4 ); - } - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - - if ( rec != NULL ) - { - b3World_StopRecording( worldId ); - } - b3DestroyWorld( worldId ); - - return hash; -} - -// Swapping a shape's hull or mesh, or retuning one of its per-triangle materials, is a world -// mutation like any other and has to ride the stream. The geometry pair interns into the registry -// at the record site so replay rebuilds the same shape instead of running on the geometry it was -// created with. The control run proves the mutations move the simulation, so the state hash gate -// has teeth, and the read back covers each op on its own where dynamics alone would not. -static int GeometryMutatorReplay( void ) -{ - // Two flat floors with different triangulations, both carrying two material slots so the - // material index stays live across the swap. - b3MeshData* meshA = b3CreateGridMesh( 8, 8, 2.0f, 2, false ); - ENSURE( meshA != NULL ); - b3MeshData* meshB = b3CreateGridMesh( 12, 12, 1.5f, 2, false ); - ENSURE( meshB != NULL ); - ENSURE( meshA->triangleCount != meshB->triangleCount ); - - b3BoxHull swapHull = b3MakeBoxHull( 0.25f, 1.5f, 0.25f ); - const float swapFriction = 0.95f; - - uint64_t controlHash = - RunGeometryMutatorScene( NULL, false, meshA, meshB, &swapHull.base, swapFriction ); - - b3Recording* rec = b3CreateRecording( 0 ); - ENSURE( rec != NULL ); - uint64_t mutatedHash = - RunGeometryMutatorScene( rec, true, meshA, meshB, &swapHull.base, swapFriction ); - - // Without this the replay gate below could pass on a recording that never carried the ops. - ENSURE( mutatedHash != controlHash ); - - const uint8_t* data = b3Recording_GetData( rec ); - int size = b3Recording_GetSize( rec ); - ENSURE( size > 0 ); - - ENSURE( b3ValidateReplay( data, size, 1 ) ); - ENSURE( b3ValidateReplay( data, size, 4 ) ); - - b3RecPlayer* player = b3CreatePlayer( data, size, 1 ); - ENSURE( player != NULL ); - while ( b3RecPlayer_StepFrame( player ) ) - { - } - ENSURE( b3RecPlayer_HasDiverged( player ) == false ); - - // Body ordinals follow creation order in the replayed world. - b3BodyId replayMeshBody = b3RecPlayer_GetBodyId( player, 0 ); - b3BodyId replayBoxBody = b3RecPlayer_GetBodyId( player, 1 ); - ENSURE( b3Body_IsValid( replayMeshBody ) && b3Body_IsValid( replayBoxBody ) ); - - b3ShapeId replayMeshShape; - ENSURE( b3Body_GetShapes( replayMeshBody, &replayMeshShape, 1 ) == 1 ); - b3ShapeId replayBoxShape; - ENSURE( b3Body_GetShapes( replayBoxBody, &replayBoxShape, 1 ) == 1 ); - - const b3HullData* replayHull = b3Shape_GetHull( replayBoxShape ); - ENSURE( replayHull != NULL ); - ENSURE( replayHull->hash == swapHull.base.hash ); - - b3Mesh replayMesh = b3Shape_GetMesh( replayMeshShape ); - ENSURE( replayMesh.data != NULL ); - ENSURE( replayMesh.data->hash == meshB->hash ); - ENSURE( replayMesh.data->triangleCount == meshB->triangleCount ); - - b3SurfaceMaterial replayMaterial = b3Shape_GetMeshSurfaceMaterial( replayMeshShape, 1 ); - ENSURE( replayMaterial.friction == swapFriction ); - - b3DestroyPlayer( player ); - b3DestroyRecording( rec ); - b3DestroyMesh( meshA ); - b3DestroyMesh( meshB ); - return 0; -} - int RecordingTest( void ) { RUN_SUBTEST( GeometryHashCollision ); - RUN_SUBTEST( ShapeNameReplay ); RUN_SUBTEST( SphereRoundTrip ); RUN_SUBTEST( EmptyWorldRoundTrip ); RUN_SUBTEST( HullDedup ); RUN_SUBTEST( MidStreamNoContacts ); RUN_SUBTEST( MidStreamContacts ); - RUN_SUBTEST( CrossWidthReplay ); - RUN_SUBTEST( StagedStepCreationPose ); RUN_SUBTEST( ScrubBackward ); RUN_SUBTEST( SeekWithHull ); RUN_SUBTEST( DebugShapeCallbacks ); @@ -2499,9 +1745,7 @@ int RecordingTest( void ) RUN_SUBTEST( QueryReplay ); RUN_SUBTEST( TaggedQuery ); RUN_SUBTEST( TransformedHullRoundTrip ); - RUN_SUBTEST( GeometryMutatorReplay ); RUN_SUBTEST( AllOps ); RUN_SUBTEST( ReservedHeaderBytes ); - RUN_SUBTEST( CorruptCompound ); return 0; } diff --git a/test/test_restitution.c b/test/test_restitution.c deleted file mode 100644 index 3c1b6b2..0000000 --- a/test/test_restitution.c +++ /dev/null @@ -1,1302 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "body.h" -#include "physics_world.h" -#include "recording.h" -#include "test_macros.h" - -#include "box3d/box3d.h" -#include "box3d/collision.h" -#include "box3d/math_functions.h" - -#include -#include -#include - -#define TIME_STEP ( 1.0f / 60.0f ) -#define SUB_STEP_COUNT 4 - -// A flat landing converges its Gauss-Seidel coupling in four stage iterations and the default is two, -// so the tests that read the coefficient or the spin of a flat landing pin the count -#define RESTITUTION_ITERATIONS 4 - -// Impact speed shared by every scenario that measures a coefficient. Well above the default -// restitution threshold so the bounce is always armed. -#define IMPACT_SPEED 5.0f - -// Each subtest prints all of its measurements before asserting, and the battery runs every subtest -// so one bad scenario does not hide the rest. -#define RUN_MEASUREMENT( T ) \ - do \ - { \ - if ( T() != 0 ) \ - { \ - printf( " subtest failed: " #T "\n" ); \ - failureCount += 1; \ - } \ - else \ - { \ - printf( " subtest passed: " #T "\n" ); \ - } \ - } \ - while ( false ) - -static b3WorldId MakeWorld( float gravityY ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = (b3Vec3){ 0.0f, gravityY, 0.0f }; - worldDef.enableSleep = false; - return b3CreateWorld( &worldDef ); -} - -static b3WorldId MakeWorldIterations( float gravityY, int restitutionIterations ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = (b3Vec3){ 0.0f, gravityY, 0.0f }; - worldDef.enableSleep = false; - worldDef.restitutionIterations = restitutionIterations; - return b3CreateWorld( &worldDef ); -} - -// Ground with its top surface at y = 0 -static void MakeGround( b3WorldId worldId, float restitution ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = restitution; - b3BoxHull box = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundId, &shapeDef, &box.base ); -} - -static b3BodyId MakeBall( b3WorldId worldId, float x, float y, float velocityY, float restitution ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ x, y, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, velocityY, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = restitution; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - return bodyId; -} - -// Two free spheres closing head on with no gravity. The coefficient is the ratio of relative normal -// speeds at the contact, which is the mass independent definition. -static float MeasureHeadOn( float restitution, float densityB, float* momentumError ) -{ - b3WorldId worldId = MakeWorld( 0.0f ); - - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = restitution; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -1.0f, 0.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.5f * IMPACT_SPEED, 0.0f, 0.0f }; - b3BodyId idA = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( idA, &shapeDef, &sphere ); - - bodyDef.position = (b3Pos){ 1.0f, 0.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ -0.5f * IMPACT_SPEED, 0.0f, 0.0f }; - b3BodyId idB = b3CreateBody( worldId, &bodyDef ); - shapeDef.density = densityB; - b3CreateSphereShape( idB, &shapeDef, &sphere ); - - float massA = b3Body_GetMass( idA ); - float massB = b3Body_GetMass( idB ); - float momentum0 = massA * b3Body_GetLinearVelocity( idA ).x + massB * b3Body_GetLinearVelocity( idB ).x; - - for ( int i = 0; i < 120; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float vA = b3Body_GetLinearVelocity( idA ).x; - float vB = b3Body_GetLinearVelocity( idB ).x; - float momentum1 = massA * vA + massB * vB; - - b3DestroyWorld( worldId ); - - *momentumError = ( momentum1 - momentum0 ) / ( massA + massB ); - return ( vB - vA ) / IMPACT_SPEED; -} - -// Ball driven into static ground with no gravity so the measurement carries no gravity bias. The -// gap shifts where inside the time step the impact lands. -static float MeasureGroundBounce( float restitution, float gap ) -{ - b3WorldId worldId = MakeWorld( 0.0f ); - MakeGround( worldId, 0.0f ); - - b3BodyId ballId = MakeBall( worldId, 0.0f, 0.5f + gap, -IMPACT_SPEED, restitution ); - - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float speed = b3Body_GetLinearVelocity( ballId ).y; - b3DestroyWorld( worldId ); - return speed / IMPACT_SPEED; -} - -// Impactor driven onto a column of resting balls pinned against the ground. The support balls are -// dead so only the top contact can bounce. A supported target has infinite effective mass along the -// normal, so the coefficient must not depend on the column height. -static float MeasureSupportedBounce( float restitution, int supportCount, bool propagate ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - worldDef.enableSleep = false; - worldDef.enableRestitutionPropagation = propagate; - worldDef.restitutionIterations = RESTITUTION_ITERATIONS; - b3WorldId worldId = b3CreateWorld( &worldDef ); - MakeGround( worldId, 0.0f ); - - for ( int i = 0; i < supportCount; ++i ) - { - MakeBall( worldId, 0.0f, 0.5f + 1.0f * i, 0.0f, 0.0f ); - } - - float y = 0.5f + 1.0f * supportCount + 0.5f * IMPACT_SPEED * TIME_STEP; - b3BodyId ballId = MakeBall( worldId, 0.0f, y, -IMPACT_SPEED, restitution ); - - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float speed = b3Body_GetLinearVelocity( ballId ).y; - b3DestroyWorld( worldId ); - return speed / IMPACT_SPEED; -} - -// Flat box landing on all four corners at once with no gravity -static float MeasureFlatBounce( float restitution, int subStepCount, float* spin ) -{ - b3WorldId worldId = MakeWorldIterations( 0.0f, RESTITUTION_ITERATIONS ); - MakeGround( worldId, 0.0f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.25f + 0.5f * IMPACT_SPEED * TIME_STEP, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, -IMPACT_SPEED, 0.0f }; - b3BodyId boxId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = restitution; - b3BoxHull box = b3MakeBoxHull( 1.0f, 0.25f, 1.0f ); - b3CreateHullShape( boxId, &shapeDef, &box.base ); - - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, TIME_STEP, subStepCount ); - } - - float speed = b3Body_GetLinearVelocity( boxId ).y; - *spin = b3Length( b3Body_GetAngularVelocity( boxId ) ); - b3DestroyWorld( worldId ); - return speed / IMPACT_SPEED; -} - -// Perfectly elastic ball dropped under gravity -static int MeasureDrop( float dropHeight, float* apexes, int capacity ) -{ - b3WorldId worldId = MakeWorld( -10.0f ); - MakeGround( worldId, 0.0f ); - - b3BodyId ballId = MakeBall( worldId, 0.0f, dropHeight, 0.0f, 1.0f ); - - int apexCount = 0; - float previousSpeed = 0.0f; - - for ( int i = 0; i < 4000 && apexCount < capacity; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - - float speed = b3Body_GetLinearVelocity( ballId ).y; - if ( previousSpeed > 0.0f && speed <= 0.0f ) - { - apexes[apexCount] = (float)b3Body_GetPosition( ballId ).y; - apexCount += 1; - } - previousSpeed = speed; - } - - b3DestroyWorld( worldId ); - return apexCount; -} - -static int HeadOnTest( void ) -{ - static const float restitutions[] = { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f }; - static const float densities[] = { 1.0f, 10.0f, 100.0f }; - const float tolerance = 0.02f; - - int failed = 0; - - for ( int i = 0; i < ARRAY_COUNT( densities ); ++i ) - { - float worstError = 0.0f; - float worstMomentum = 0.0f; - - for ( int j = 0; j < ARRAY_COUNT( restitutions ); ++j ) - { - float momentumError = 0.0f; - float measured = MeasureHeadOn( restitutions[j], densities[i], &momentumError ); - - float error = b3AbsFloat( measured - restitutions[j] ); - if ( error > worstError ) - { - worstError = error; - } - - if ( b3AbsFloat( momentumError ) > b3AbsFloat( worstMomentum ) ) - { - worstMomentum = momentumError; - } - - if ( error > tolerance ) - { - printf( " head on density %.0f e %.2f -> %.4f\n", densities[i], restitutions[j], measured ); - failed = 1; - } - } - - printf( " head on density %6.1f worst error %.4f momentum drift %.2e\n", densities[i], worstError, worstMomentum ); - - if ( b3AbsFloat( worstMomentum ) > 1.0e-4f ) - { - failed = 1; - } - } - - return failed; -} - -static int PhaseTest( void ) -{ - static const float restitutions[] = { 0.25f, 0.5f, 0.9f }; - const int sampleCount = 16; - const float tolerance = 0.05f; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( restitutions ); ++j ) - { - float minimum = FLT_MAX; - float maximum = -FLT_MAX; - float sum = 0.0f; - - for ( int i = 0; i < sampleCount; ++i ) - { - // Sweep the gap across one step of travel so the impact lands at every phase - float gap = ( (float)i / (float)sampleCount ) * IMPACT_SPEED * TIME_STEP; - float measured = MeasureGroundBounce( restitutions[j], gap ); - minimum = b3MinFloat( minimum, measured ); - maximum = b3MaxFloat( maximum, measured ); - sum += measured; - } - - float mean = sum / sampleCount; - float spread = maximum - minimum; - printf( " phase e %.2f -> mean %.4f spread %.4f [%.4f, %.4f]\n", restitutions[j], mean, spread, minimum, maximum ); - - if ( spread > tolerance || b3AbsFloat( mean - restitutions[j] ) > tolerance ) - { - failed = 1; - } - } - - return failed; -} - -// By default the restitution stage sweeps only the contacts that carry restitution, so the ball -// pushes the column down and the ground under it gets no say until the next step: e = 0.9 gives -// about 0.52 on one support. With propagation enabled the stage sweeps every contact, the ground -// contact supplies the reaction within the stage and e = 0.9 gives 0.85 on one support and 0.72 on -// three at the pinned four iterations, decaying with depth because the column needs an iteration per -// level. Propagation costs a normal pass over every contact per iteration, hence the option. Both -// modes are gated: never above the free coefficient, which would be energy from nowhere, and never -// collapsed. -static int SupportedTest( void ) -{ - static const float restitutions[] = { 0.5f, 0.9f }; - - int failed = 0; - - for ( int propagate = 0; propagate <= 1; ++propagate ) - { - float floor = propagate ? 0.75f : 0.5f; - - for ( int j = 0; j < ARRAY_COUNT( restitutions ); ++j ) - { - for ( int n = 0; n <= 3; ++n ) - { - float measured = MeasureSupportedBounce( restitutions[j], n, propagate == 1 ); - printf( " supported e %.2f supports %d propagation %d -> %.4f\n", restitutions[j], n, propagate, measured ); - - if ( measured > restitutions[j] + 0.01f || measured < floor * restitutions[j] ) - { - failed = 1; - } - } - } - } - - return failed; -} - -// A symmetric four point landing. The stage solves the points in sequence, so a single sweep leaves -// the box spinning: the first impulse tilts it and the next point sees a larger closing speed. Four -// stage iterations converge the coupling and leave a small residual. The tolerance admits that -// residual and rejects the single sweep behavior. -static int FlatLandingTest( void ) -{ - static const float restitutions[] = { 0.5f, 0.9f }; - static const int subStepCounts[] = { 4, 8 }; - const float speedTolerance = 0.01f; - const float spinTolerance = 0.03f; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( restitutions ); ++j ) - { - for ( int k = 0; k < ARRAY_COUNT( subStepCounts ); ++k ) - { - float spin = 0.0f; - float measured = MeasureFlatBounce( restitutions[j], subStepCounts[k], &spin ); - printf( " flat e %.2f substeps %d -> %.4f spin %.4f\n", restitutions[j], subStepCounts[k], measured, spin ); - - // Only the shipping sub step count is a gate. The wider count is reported so a - // convergence problem can be told apart from a formulation problem. - if ( subStepCounts[k] != SUB_STEP_COUNT ) - { - continue; - } - - if ( b3AbsFloat( measured - restitutions[j] ) > speedTolerance || spin > spinTolerance ) - { - failed = 1; - } - } - } - - return failed; -} - -// A flat box carrying spin about a horizontal axis. All four corners stay in contact and the normal -// constraints are linear in the body velocity, so perfect restitution reverses linear and angular -// velocity. Four stage iterations bring both within a few thousandths. -static int SpinTest( void ) -{ - static const float spins[] = { 0.0f, 0.5f, 1.0f, 2.0f }; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( spins ); ++j ) - { - b3WorldId worldId = MakeWorldIterations( 0.0f, RESTITUTION_ITERATIONS ); - MakeGround( worldId, 0.0f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.25f + 0.5f * IMPACT_SPEED * TIME_STEP, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, -IMPACT_SPEED, 0.0f }; - bodyDef.angularVelocity = (b3Vec3){ 0.0f, 0.0f, spins[j] }; - b3BodyId boxId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 1.0f; - b3BoxHull box = b3MakeBoxHull( 1.0f, 0.25f, 1.0f ); - b3CreateHullShape( boxId, &shapeDef, &box.base ); - - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float speed = b3Body_GetLinearVelocity( boxId ).y; - float spin = b3Body_GetAngularVelocity( boxId ).z; - b3DestroyWorld( worldId ); - - printf( " spin in %+.2f -> vy %+.4f (want %+.4f) wz %+.4f (want %+.4f)\n", spins[j], speed, IMPACT_SPEED, spin, - -spins[j] ); - - if ( b3AbsFloat( speed - IMPACT_SPEED ) > 0.05f || b3AbsFloat( spin + spins[j] ) > 0.05f ) - { - failed = 1; - } - } - - return failed; -} - -// Perfectly elastic ball under gravity. Only heights where continuous collision engages are used. -// Continuous collision lands the ball on the surface, so the bounce is armed from the true impact -// speed and the apex holds. Slower drops resolve the impact inside the overlap and the penetration -// recovery adds height, by design. The 10 m case is the long horizon read. -static int DropTest( void ) -{ - static const float heights[] = { 40.0f, 20.0f, 10.0f }; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( heights ); ++j ) - { - float apexes[6] = { 0 }; - int apexCount = MeasureDrop( heights[j], apexes, ARRAY_COUNT( apexes ) ); - - printf( " drop %5.1f ->", heights[j] ); - for ( int i = 0; i < apexCount; ++i ) - { - printf( " %8.3f", apexes[i] ); - } - printf( "\n" ); - - if ( apexCount < ARRAY_COUNT( apexes ) ) - { - failed = 1; - continue; - } - - float highest = apexes[0]; - for ( int i = 1; i < apexCount; ++i ) - { - highest = b3MaxFloat( highest, apexes[i] ); - } - - // A later apex above the first, or a first apex above the drop, is energy from nowhere - if ( highest > 1.001f * apexes[0] || apexes[0] > 1.001f * heights[j] || apexes[apexCount - 1] < 0.8f * apexes[0] ) - { - failed = 1; - } - } - - return failed; -} - -// A cube dropped flat with an aggressive continuous safety factor so it lands square on the surface. -// Perfectly elastic and frictionless, so it should come back to the drop height with no rotation. A -// flat landing solves four coplanar points in sequence and one sweep over-delivers: the first impulse -// tilts the cube, the next point sees a larger closing speed and the sum overshoots the rigid body -// answer, leaving spin that tilts the cube for the next landing. Four stage iterations converge the -// coupling. The bounds below reject the single sweep behavior and any apex above the drop. -static int SingleBoxTest( void ) -{ - b3WorldId worldId = MakeWorldIterations( -10.0f, RESTITUTION_ITERATIONS ); - MakeGround( worldId, 0.0f ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 1.0f; - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - const float dropHeight = 10.0f; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, dropHeight, 0.0f }; - bodyDef.safetyFactor = 0.01f; - b3BodyId boxId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( boxId, &shapeDef, &box.base ); - - float firstSpin = 0.0f; - float apexes[4] = { 0 }; - float spins[4] = { 0 }; - int apexCount = 0; - float previousSpeed = 0.0f; - - // A nearly elastic bounce from 10 m takes about 165 steps, so budget for four of them - for ( int i = 0; i < 1200 && apexCount < ARRAY_COUNT( apexes ); ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - - float speed = b3Body_GetLinearVelocity( boxId ).y; - - if ( apexCount == 0 && previousSpeed <= 0.0f && speed > 0.0f ) - { - firstSpin = b3Length( b3Body_GetAngularVelocity( boxId ) ); - } - - if ( previousSpeed > 0.0f && speed <= 0.0f ) - { - apexes[apexCount] = (float)b3Body_GetPosition( boxId ).y; - spins[apexCount] = b3Length( b3Body_GetAngularVelocity( boxId ) ); - apexCount += 1; - } - previousSpeed = speed; - } - - b3DestroyWorld( worldId ); - - printf( " single box first bounce spin %.4f apexes", firstSpin ); - for ( int i = 0; i < apexCount; ++i ) - { - printf( " %7.3f (spin %5.2f)", apexes[i], spins[i] ); - } - printf( "\n" ); - - ENSURE( apexCount == ARRAY_COUNT( apexes ) ); - - int failed = 0; - - if ( firstSpin > 0.01f ) - { - failed = 1; - } - - for ( int i = 0; i < apexCount; ++i ) - { - if ( apexes[i] < 0.95f * dropHeight || apexes[i] > 1.001f * dropHeight ) - { - failed = 1; - } - } - - return failed; -} - -static int ThresholdTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - float threshold = worldDef.restitutionThreshold; - - static const float scales[] = { 0.5f, 0.9f, 1.5f, 4.0f }; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( scales ); ++j ) - { - float speed = scales[j] * threshold; - - b3WorldId worldId = MakeWorld( 0.0f ); - MakeGround( worldId, 0.0f ); - b3BodyId ballId = MakeBall( worldId, 0.0f, 0.5f + 0.5f * speed * TIME_STEP, -speed, 1.0f ); - - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float ratio = b3Body_GetLinearVelocity( ballId ).y / speed; - b3DestroyWorld( worldId ); - - printf( " threshold %.2fx -> %.4f\n", scales[j], ratio ); - - if ( scales[j] < 1.0f && ratio > 0.05f ) - { - failed = 1; - } - - if ( scales[j] > 1.0f && ratio < 0.9f ) - { - failed = 1; - } - } - - return failed; -} - -// High restitution must not wake a settled stack back up -static int RestingTest( void ) -{ - b3WorldId worldId = MakeWorld( -10.0f ); - MakeGround( worldId, 0.9f ); - - const int boxCount = 10; - b3BodyId boxIds[10]; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = 0.6f; - shapeDef.baseMaterial.restitution = 0.9f; - b3BoxHull box = b3MakeCubeHull( 0.5f ); - - for ( int i = 0; i < boxCount; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.5f + 1.0f * i, 0.0f }; - boxIds[i] = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( boxIds[i], &shapeDef, &box.base ); - } - - for ( int i = 0; i < 240; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - float settled = (float)b3Body_GetPosition( boxIds[boxCount - 1] ).y; - float drift = 0.0f; - float peakSpeed = 0.0f; - - for ( int i = 0; i < 300; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - - float y = (float)b3Body_GetPosition( boxIds[boxCount - 1] ).y; - drift = b3MaxFloat( drift, b3AbsFloat( y - settled ) ); - - for ( int j = 0; j < boxCount; ++j ) - { - peakSpeed = b3MaxFloat( peakSpeed, b3Length( b3Body_GetLinearVelocity( boxIds[j] ) ) ); - } - } - - b3DestroyWorld( worldId ); - - printf( " resting drift %.5f peak speed %.5f\n", drift, peakSpeed ); - - ENSURE( drift < 0.01f ); - ENSURE( peakSpeed < 0.05f ); - return 0; -} - -static uint64_t RunWorkerScene( int workerCount ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = (b3Vec3){ 0.0f, -10.0f, 0.0f }; - worldDef.enableSleep = false; - worldDef.workerCount = workerCount; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - MakeGround( worldId, 0.6f ); - - for ( int i = 0; i < 20; ++i ) - { - MakeBall( worldId, -10.0f + 1.05f * i, 3.0f + 0.13f * i, 0.0f, 0.6f ); - } - - for ( int i = 0; i < 200; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - } - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// The manifold point approach speed is published only for contacts that opted into hit events. It -// is not a stale value otherwise, it is zero, so a reader can tell "not measured" from "measured -// zero" by whether the shape enables the events. Restitution no longer reads it at all, so this is -// the only thing keeping the field alive. -static float MeasureFirstTouchNormalVelocity( bool enableHitEvents ) -{ - b3WorldId worldId = MakeWorld( 0.0f ); - MakeGround( worldId, 0.0f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.6f, 0.0f }; - b3BodyId ballId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.baseMaterial.friction = 0.0f; - shapeDef.baseMaterial.restitution = 0.0f; - shapeDef.enableHitEvents = enableHitEvents; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( ballId, &shapeDef, &sphere ); - - float normalVelocity = FLT_MAX; - - // Hold the closing speed so the sampled value does not depend on which step the pair is created - for ( int i = 0; i < 20; ++i ) - { - b3Body_SetLinearVelocity( ballId, (b3Vec3){ 0.0f, -IMPACT_SPEED, 0.0f } ); - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - - b3ContactData contactData; - if ( b3Body_GetContactData( ballId, &contactData, 1 ) == 1 && contactData.manifoldCount > 0 && - contactData.manifolds[0].pointCount > 0 ) - { - normalVelocity = contactData.manifolds[0].points[0].normalVelocity; - break; - } - } - - b3DestroyWorld( worldId ); - return normalVelocity; -} - -static int NormalVelocityTest( void ) -{ - float quiet = MeasureFirstTouchNormalVelocity( false ); - float published = MeasureFirstTouchNormalVelocity( true ); - - printf( " normal velocity hit events off %.4f on %.4f (closing at %.4f)\n", quiet, published, -IMPACT_SPEED ); - - int failed = 0; - - if ( quiet != 0.0f ) - { - failed = 1; - } - - if ( published > -0.8f * IMPACT_SPEED ) - { - failed = 1; - } - - return failed; -} - -// Mechanical energy of a body as symplectic Euler conserves it. The integrator updates velocity -// before position, so the quantity that is exactly constant in free flight is not kinetic plus -// potential but that plus half a sub-step of the gravity power, m * dot(v, g) * h / 2. Plain -// kinetic plus potential sampled at step boundaries jumps by about g * v * h at every bounce and -// drifts down by g^2 h^2 / 2 each sub-step, which would hide a real gain or fake one. With this -// measure a contact that never does positive work leaves the energy flat to round-off. -static float MeasureEnergy( b3BodyId bodyId, b3WorldId worldId ) -{ - b3MassData massData = b3Body_GetMassData( bodyId ); - b3Vec3 v = b3Body_GetLinearVelocity( bodyId ); - b3Vec3 gravity = b3MulSV( b3Body_GetGravityScale( bodyId ), b3World_GetGravity( worldId ) ); - float h = TIME_STEP / SUB_STEP_COUNT; - - // The inertia tensor is in the body frame, so bring the angular velocity back to it - b3Vec3 wLocal = b3InvRotateVector( b3Body_GetRotation( bodyId ), b3Body_GetAngularVelocity( bodyId ) ); - - float kinetic = 0.5f * massData.mass * b3Dot( v, v ) + 0.5f * b3Dot( wLocal, b3MulMV( massData.inertia, wLocal ) ); - float potential = -massData.mass * b3Dot( gravity, b3ToVec3( b3Body_GetWorldCenter( bodyId ) ) ); - float phase = 0.5f * h * massData.mass * b3Dot( v, gravity ); - - return kinetic + potential + phase; -} - -typedef struct OvershootResult -{ - float firstApex; - float firstEnergyRatio; - float peakEnergyRatio; - float speedRatio; - int bounceCount; -} OvershootResult; - -// Mirrors the Restitution Overshoot sample in samples/sample_issues.cpp: a unit cube dropped flat on -// a floor narrower than itself, perfectly elastic, so the four contact points sit inboard of the box -// corners. A perfectly elastic bounce cannot come back higher than it was dropped from and cannot -// gain energy. -static OvershootResult MeasureOvershoot( bool continuous ) -{ - b3WorldId worldId = MakeWorldIterations( -10.0f, RESTITUTION_ITERATIONS ); - - b3BodyDef floorDef = b3DefaultBodyDef(); - floorDef.position = (b3Pos){ 0.0f, -0.25f, 0.0f }; - b3BodyId floorId = b3CreateBody( worldId, &floorDef ); - - b3ShapeDef floorShape = b3DefaultShapeDef(); - b3BoxHull floor = b3MakeBoxHull( 0.375f, 0.25f, 0.375f ); - b3CreateHullShape( floorId, &floorShape, &floor.base ); - - const float dropHeight = 10.0f; - - b3BodyDef boxDef = b3DefaultBodyDef(); - boxDef.type = b3_dynamicBody; - boxDef.position = (b3Pos){ 0.0f, dropHeight, 0.0f }; - if ( continuous ) - { - boxDef.safetyFactor = 0.1f; - } - b3BodyId boxId = b3CreateBody( worldId, &boxDef ); - - b3ShapeDef boxShape = b3DefaultShapeDef(); - boxShape.baseMaterial.restitution = 1.0f; - b3BoxHull box = b3MakeCubeHull( 0.5f ); - b3CreateHullShape( boxId, &boxShape, &box.base ); - - OvershootResult result = { 0 }; - - float startEnergy = MeasureEnergy( boxId, worldId ); - float impactSpeed = 0.0f; - float reboundSpeed = 0.0f; - float bounceHeight = 0.0f; - float previousSpeed = 0.0f; - - for ( int i = 0; i < 600 && result.bounceCount < 2; ++i ) - { - float before = b3Body_GetLinearVelocity( boxId ).y; - float heightBefore = (float)b3Body_GetPosition( boxId ).y; - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - float speed = b3Body_GetLinearVelocity( boxId ).y; - - if ( reboundSpeed == 0.0f && before < 0.0f && speed > 0.0f ) - { - impactSpeed = -before; - reboundSpeed = speed; - bounceHeight = heightBefore; - } - - if ( reboundSpeed == 0.0f ) - { - continue; - } - - // Every step, not just at the apexes, because that is what the sample checks and the impact - // step itself is where any gain appears - float ratio = MeasureEnergy( boxId, worldId ) / startEnergy; - if ( ratio > result.peakEnergyRatio ) - { - result.peakEnergyRatio = ratio; - } - - if ( previousSpeed > 0.0f && speed <= 0.0f ) - { - if ( result.bounceCount == 0 ) - { - result.firstApex = (float)b3Body_GetPosition( boxId ).y; - result.firstEnergyRatio = ratio; - } - - result.bounceCount += 1; - } - - previousSpeed = speed; - } - - b3DestroyWorld( worldId ); - - result.speedRatio = reboundSpeed / impactSpeed; - - printf( " overshoot continuous %d apex %.4f of %.4f at y %.4f, speed ratio %.4f, energy %.4f then %.4f\n", - continuous ? 1 : 0, result.firstApex, dropHeight, bounceHeight, result.speedRatio, result.firstEnergyRatio, - result.peakEnergyRatio ); - - return result; -} - -// Two runs, because two unrelated effects were tangled together here. -// -// The impulse must never return more speed than it received. That is the restitution invariant and it -// is checked in both runs; the unconverged four point solve failed it by 7.9 percent. -// -// Everything else depends on whether continuous collision engages. Without it the cube moves 0.23 m -// in the step before contact, just under the 0.25 m trigger, so the first manifold appears with the -// cube already 0.10 m deep. It bounces from down there and climbs back through that depth for free, -// which is worth about a tenth of a metre of apex and one percent of energy, and none of it is -// restitution. With continuous collision the cube lands on the surface and both the apex and the -// energy come in under where they started. The safety factor here matches the one the sample sets, -// which is the supported answer for a body whose elastic accuracy matters. -// -// The discrete run is only gated on its first bounce. Later bounces there are a genuine blow-up, not -// a tolerance question: the free height makes the cube tilt, the next landing is a deep corner impact -// at 14 m/s, and energy reaches 159 percent with the cube spinning at 26 rad/s. Lowering the safety -// factor is the fix and the sample does that; the discrete run is kept to pin what happens when it is -// left alone, and because its speed ratio is what caught the real bug. Details in -// .claude/same_step_restitution.md. -static int OvershootTest( void ) -{ - const float dropHeight = 10.0f; - - OvershootResult discrete = MeasureOvershoot( false ); - OvershootResult continuous = MeasureOvershoot( true ); - - // Perfectly elastic returns exactly the speed it received, so any excess is round-off. The - // overflow and colored solvers round differently and either can land an ulp over one. - const float speedTolerance = 1.0e-5f; - - int failed = 0; - - if ( discrete.speedRatio > 1.0f + speedTolerance || continuous.speedRatio > 1.0f + speedTolerance ) - { - failed = 1; - } - - if ( continuous.firstApex > dropHeight || continuous.peakEnergyRatio > 1.001f ) - { - failed = 1; - } - - if ( discrete.firstApex > dropHeight + 0.15f || discrete.firstEnergyRatio > 1.02f ) - { - failed = 1; - } - - // The continuous landing leaves the cube sliding sideways a few tenths of a metre per second, from - // friction during the sub-steps, and a floor narrower than the cube does not catch it on the way - // back down. That is sub-step friction, not restitution, so only the first bounce is required. - if ( discrete.bounceCount < 2 || continuous.bounceCount < 1 ) - { - failed = 1; - } - - return failed; -} - -typedef struct ImpulseResult -{ - float worstError; - float approachSpeed; - float firstSeparation; - float bounceImpulse; - int contactSteps; - int toiSteps; - int toiImpulseSteps; -} ImpulseResult; - -// Ball dropped under gravity with the contact impulse read back every step. Nothing else touches the -// ball, so once gravity is taken out the change in momentum over a step is the impulse the contact -// applied, and that is what the total normal impulse must report. A time of impact step is left out -// of the balance: no contact was solved on it, and the sweep hands back the gravity of the time it -// cut short. -static ImpulseResult MeasureDropImpulse( float restitution, float dropHeight ) -{ - b3WorldId worldId = MakeWorld( -10.0f ); - MakeGround( worldId, 0.0f ); - - b3BodyId ballId = MakeBall( worldId, 0.0f, 0.5f + dropHeight, 0.0f, restitution ); - b3World* world = b3GetWorldFromId( worldId ); - - float mass = b3Body_GetMass( ballId ); - float gravityY = b3World_GetGravity( worldId ).y; - - ImpulseResult result = { 0 }; - bool touched = false; - bool bouncing = false; - - // Enough for the longest fall and the bounce that follows it - for ( int i = 0; i < 240; ++i ) - { - float speedBefore = b3Body_GetLinearVelocity( ballId ).y; - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - float speedAfter = b3Body_GetLinearVelocity( ballId ).y; - - float measured = 0.0f; - float separation = 0.0f; - b3ContactData contactData[4]; - int contactCount = b3Body_GetContactData( ballId, contactData, ARRAY_COUNT( contactData ) ); - for ( int c = 0; c < contactCount; ++c ) - { - for ( int m = 0; m < contactData[c].manifoldCount; ++m ) - { - const b3Manifold* manifold = contactData[c].manifolds + m; - for ( int p = 0; p < manifold->pointCount; ++p ) - { - measured += manifold->points[p].totalNormalImpulse; - separation = manifold->points[p].separation; - } - } - } - - // Transient body flags are cleared and rewritten every step - b3Body* ball = b3GetBodyFullId( world, ballId ); - b3BodySim* ballSim = b3GetBodySim( world, ball ); - if ( ballSim->flags & b3_hadTimeOfImpact ) - { - result.toiSteps += 1; - if ( measured != 0.0f ) - { - result.toiImpulseSteps += 1; - } - continue; - } - - float expected = mass * ( speedAfter - speedBefore ) - mass * gravityY * TIME_STEP; - result.worstError = b3MaxFloat( result.worstError, b3AbsFloat( measured - expected ) ); - - if ( contactCount > 0 ) - { - if ( touched == false ) - { - touched = true; - bouncing = true; - result.approachSpeed = -speedBefore; - result.firstSeparation = separation; - } - - if ( bouncing ) - { - result.bounceImpulse += measured; - result.contactSteps += 1; - } - } - else - { - bouncing = false; - } - } - - b3DestroyWorld( worldId ); - return result; -} - -// Heights on both sides of the continuous collision threshold, so the impulse is checked for a ball -// that lands inside the overlap and for one the sweep sets down on the surface. The threshold is -// derived from the body so the split survives a change to the default safety factor. -// -// The step balance is the real gate. The bounce total is bracketed as well so the restitution sweep -// means something: the contact has to reverse the approach at the coefficient and may carry the -// weight for at most as long as it lasted. The stage runs after the sub-steps, so the reversal -// lands a step late and the ball can come in up to a step of gravity under it. -static int ImpulseTest( void ) -{ - static const float restitutions[] = { 0.0f, 0.25f, 0.5f, 0.75f, 1.0f }; - static const float heights[] = { 1.0f, 5.0f, 20.0f, 45.0f }; - - float mass; - float fastSpeed; - { - b3WorldId worldId = MakeWorld( -10.0f ); - b3BodyId ballId = MakeBall( worldId, 0.0f, 0.5f, 0.0f, 0.0f ); - mass = b3Body_GetMass( ballId ); - fastSpeed = b3Body_GetSafetyFactor( ballId ) * b3Body_GetMinExtent( ballId ) / TIME_STEP; - b3DestroyWorld( worldId ); - } - - const float weightImpulse = mass * 10.0f * TIME_STEP; - - int failed = 0; - - for ( int j = 0; j < ARRAY_COUNT( heights ); ++j ) - { - float impactSpeed = sqrtf( 20.0f * heights[j] ); - bool expectToi = impactSpeed > fastSpeed; - - // Float noise in the solver velocities scales with the impact speed, and the ball is heavy - float tolerance = 1e-5f * mass * ( 10.0f + impactSpeed ); - - for ( int k = 0; k < ARRAY_COUNT( restitutions ); ++k ) - { - ImpulseResult result = MeasureDropImpulse( restitutions[k], heights[j] ); - - float reversal = ( 1.0f + restitutions[k] ) * mass * result.approachSpeed; - float lower = reversal - weightImpulse; - float upper = reversal + weightImpulse * result.contactSteps; - - printf( " impulse drop %4.1f e %.2f toi %d at %+.4f -> worst step error %.1e, bounce %.1f in [%.1f, %.1f] over %d " - "steps\n", - heights[j], restitutions[k], result.toiSteps, result.firstSeparation, result.worstError, result.bounceImpulse, - lower, upper, result.contactSteps ); - - if ( result.worstError > tolerance ) - { - failed = 1; - } - - if ( result.contactSteps == 0 || result.toiImpulseSteps > 0 ) - { - failed = 1; - } - - float slack = result.contactSteps * tolerance; - if ( result.bounceImpulse < lower - slack || result.bounceImpulse > upper + slack ) - { - failed = 1; - } - - if ( ( result.toiSteps > 0 ) != expectToi ) - { - printf( " continuous collision %s at %.1f m/s (threshold %.1f m/s)\n", expectToi ? "expected" : "unexpected", - impactSpeed, fastSpeed ); - failed = 1; - } - } - } - - return failed; -} - -typedef struct EnergyScene -{ - const char* name; - float safetyFactor; - float friction; - float angle; - float spin; - float height; - float velocityY; - float halfWidth; - float halfHeight; - bool bullet; - bool stack; - int stepCount; -} EnergyScene; - -// Peak energy over the run relative to the start, for every dynamic body in the scene. Perfectly -// elastic and the energy may still only go down: friction and the soft contact position correction -// dissipate, and a bounce may return at most what the contact absorbed. -static float MeasurePeakEnergy( const EnergyScene* scene ) -{ - b3WorldId worldId = MakeWorld( -10.0f ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - groundDef.position = (b3Pos){ 0.0f, -1.0f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3ShapeDef groundShape = b3DefaultShapeDef(); - groundShape.baseMaterial.friction = scene->friction; - b3BoxHull ground = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundId, &groundShape, &ground.base ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.baseMaterial.friction = scene->friction; - shapeDef.baseMaterial.restitution = 1.0f; - b3BoxHull box = b3MakeBoxHull( scene->halfWidth, scene->halfHeight, scene->halfWidth ); - - b3BodyId bodyIds[4]; - int bodyCount = 0; - - if ( scene->stack ) - { - // Resting box under the dropped one, like the TwoBoxRestitution sample - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, scene->halfHeight, 0.0f }; - bodyDef.safetyFactor = scene->safetyFactor; - bodyIds[bodyCount] = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyIds[bodyCount], &shapeDef, &box.base ); - bodyCount += 1; - } - - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, scene->height, 0.0f }; - bodyDef.rotation = b3MakeQuatFromAxisAngle( b3Vec3_axisZ, scene->angle ); - bodyDef.angularVelocity = (b3Vec3){ 0.0f, 0.0f, scene->spin }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, scene->velocityY, 0.0f }; - bodyDef.safetyFactor = scene->safetyFactor; - bodyDef.isBullet = scene->bullet; - bodyIds[bodyCount] = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyIds[bodyCount], &shapeDef, &box.base ); - bodyCount += 1; - } - - float start = 0.0f; - for ( int k = 0; k < bodyCount; ++k ) - { - start += MeasureEnergy( bodyIds[k], worldId ); - } - - float peak = start; - int peakStep = -1; - - for ( int i = 0; i < scene->stepCount; ++i ) - { - b3World_Step( worldId, TIME_STEP, SUB_STEP_COUNT ); - - float energy = 0.0f; - for ( int k = 0; k < bodyCount; ++k ) - { - energy += MeasureEnergy( bodyIds[k], worldId ); - } - - if ( energy > peak ) - { - peak = energy; - peakStep = i; - } - } - - b3DestroyWorld( worldId ); - - float ratio = peak / start; - printf( " energy %-24s peak %.5f at step %d\n", scene->name, ratio, peakStep ); - return ratio; -} - -// Perfectly elastic material with friction, dropped every way that used to gain energy: a spinning -// edge landing, tumbling, a flat landing with spin, a box falling on a resting box, and a tall box -// landing flat on its narrow end. Energy must never rise above the start. This is the load bearing -// property of restitution. Accuracy of the coefficient and freedom from spin are secondary. -// -// The tall boxes guard the stage iteration count. Their contact points sit close together while the -// inertia is long, so the off diagonal of the multi point normal mass is large and one sweep -// overshoots. -static int EnergyTest( void ) -{ - static const EnergyScene scenes[] = { - { "spinning edge", 0.01f, 0.6f, -1.43f, 7.9f, 0.7f, -1.9f, 0.5f, 0.5f, false, false, 300 }, - { "spinning edge fast", 0.01f, 0.6f, -0.8f, 12.0f, 3.0f, -8.0f, 0.5f, 0.5f, false, false, 300 }, - { "tumble", 0.01f, 0.6f, -0.3f, 3.0f, 8.0f, 0.0f, 0.5f, 0.5f, false, false, 600 }, - { "tumble discrete", 0.5f, 0.6f, -0.3f, 3.0f, 8.0f, 0.0f, 0.5f, 0.5f, false, false, 600 }, - { "flat with spin", 0.01f, 0.6f, 0.0f, 2.0f, 2.0f, -5.0f, 0.5f, 0.5f, false, false, 300 }, - { "flat frictionless", 0.01f, 0.0f, 0.0f, 0.0f, 10.0f, 0.0f, 0.5f, 0.5f, false, false, 1200 }, - { "edge", 0.01f, 0.6f, -0.2f, 0.0f, 5.0f, 0.0f, 0.5f, 0.5f, false, false, 600 }, - { "two box", 0.02f, 0.6f, 0.0f, 0.0f, 4.0f, 0.0f, 0.5f, 0.5f, true, true, 1500 }, - { "two box discrete", 0.5f, 0.6f, 0.0f, 0.0f, 4.0f, 0.0f, 0.5f, 0.5f, false, true, 1500 }, - { "tall flat frictionless", 0.01f, 0.0f, 0.0f, 0.0f, 10.0f, 0.0f, 0.5f, 1.0f, false, false, 1200 }, - { "tall flat friction", 0.01f, 0.6f, 0.0f, 0.0f, 10.0f, 0.0f, 0.5f, 1.0f, false, false, 1200 }, - { "narrow flat frictionless", 0.01f, 0.0f, 0.0f, 0.0f, 10.0f, 0.0f, 0.25f, 1.0f, false, false, 1200 }, - { "narrow flat friction", 0.01f, 0.6f, 0.0f, 0.0f, 10.0f, 0.0f, 0.25f, 1.0f, false, false, 1200 }, - }; - - // The soft contact position correction lifts a body that lands inside the ground, which is - // potential energy from nowhere at any restitution. Continuous collision keeps landings on the - // surface, so the tolerance only has to cover the stage. A four point flat landing does not - // converge at the default two stage iterations the way the two point landing does in 2D: the cube - // comes back with 0.2% extra. The in-relax scheme this replaced gained 2.5% to 29% on these scenes, - // so the tolerance still separates the two. - const float tolerance = 5.0e-3f; - const float discreteTolerance = 2.0e-2f; - - int failed = 0; - - for ( int i = 0; i < ARRAY_COUNT( scenes ); ++i ) - { - float ratio = MeasurePeakEnergy( scenes + i ); - float limit = scenes[i].safetyFactor < 0.1f ? tolerance : discreteTolerance; - if ( ratio > 1.0f + limit ) - { - failed = 1; - } - } - - return failed; -} - -// The sampled approach speed and the Poisson accumulator are per manifold point state, so they must -// survive the split across workers -static int WorkerParityTest( void ) -{ - uint64_t hash1 = RunWorkerScene( 1 ); - uint64_t hash2 = RunWorkerScene( 2 ); - uint64_t hash4 = RunWorkerScene( 4 ); - - printf( " worker hashes 0x%016llx 0x%016llx 0x%016llx\n", (unsigned long long)hash1, (unsigned long long)hash2, - (unsigned long long)hash4 ); - - ENSURE( hash1 == hash2 ); - ENSURE( hash1 == hash4 ); - return 0; -} - -int RestitutionTest( void ) -{ - int failureCount = 0; - - RUN_MEASUREMENT( HeadOnTest ); - RUN_MEASUREMENT( PhaseTest ); - RUN_MEASUREMENT( SupportedTest ); - RUN_MEASUREMENT( FlatLandingTest ); - RUN_MEASUREMENT( SpinTest ); - RUN_MEASUREMENT( DropTest ); - RUN_MEASUREMENT( SingleBoxTest ); - RUN_MEASUREMENT( ThresholdTest ); - RUN_MEASUREMENT( RestingTest ); - RUN_MEASUREMENT( NormalVelocityTest ); - RUN_MEASUREMENT( OvershootTest ); - RUN_MEASUREMENT( EnergyTest ); - RUN_MEASUREMENT( ImpulseTest ); - RUN_MEASUREMENT( WorkerParityTest ); - - return failureCount > 0 ? 1 : 0; -} diff --git a/test/test_sat.c b/test/test_sat.c deleted file mode 100644 index ac633db..0000000 --- a/test/test_sat.c +++ /dev/null @@ -1,493 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "test_macros.h" - -#include "manifold.h" - -#include "box3d/collision.h" -#include "box3d/constants.h" -#include "box3d/math_functions.h" - -#include -#include - -static const float kRoot2 = 1.41421356f; -static const b3Vec3 kAxisY = { 0.0f, 1.0f, 0.0f }; -static const b3Vec3 kAxisZ = { 0.0f, 0.0f, 1.0f }; - -// b3ComputeCosSin is a coarse rational approximation, so the fixtures build their rotations from -// libm to keep the analytic edge and face positions exact. -static b3Quat ExactQuat( b3Vec3 axis, float radians ) -{ - float half = 0.5f * radians; - float s = sinf( half ); - return (b3Quat){ { s * axis.x, s * axis.y, s * axis.z }, cosf( half ) }; -} - -static b3Transform ExactRotation( b3Vec3 axis, float radians ) -{ - return (b3Transform){ b3Vec3_zero, ExactQuat( axis, radians ) }; -} - -// Directed separation along a unit axis n pointing from A to B. Positive means B clears A along n. -// This is the projection gap min over B minus max over A, which is exactly what a valid separating -// axis measures, so the winning face or edge axis must reproduce it. -static float SepAlong( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, b3Vec3 n ) -{ - const b3Vec3* pointsA = b3GetHullPoints( hullA ); - float maxA = -FLT_MAX; - for ( int i = 0; i < hullA->vertexCount; ++i ) - { - maxA = b3MaxFloat( maxA, b3Dot( n, pointsA[i] ) ); - } - - const b3Vec3* pointsB = b3GetHullPoints( hullB ); - float minB = FLT_MAX; - for ( int i = 0; i < hullB->vertexCount; ++i ) - { - minB = b3MinFloat( minB, b3Dot( n, b3TransformPoint( xfB, pointsB[i] ) ) ); - } - - return minB - maxA; -} - -static void TryAxis( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, b3Vec3 n, float* best, - b3Vec3* bestNormal ) -{ - float s = SepAlong( hullA, hullB, xfB, n ); - if ( s > *best ) - { - *best = s; - *bestNormal = n; - } -} - -// Brute force SAT. The maximum separation over every face normal and every edge cross product is -// the true answer the SIMD query has to match. Each undirected axis is tried both ways so the -// winner comes out oriented from A to B with no sign bookkeeping. -static float OracleSeparation( const b3HullData* hullA, const b3HullData* hullB, b3Transform xfB, b3Vec3* outNormal ) -{ - float best = -FLT_MAX; - b3Vec3 bestNormal = { 0.0f, 0.0f, 0.0f }; - - const b3Plane* planesA = b3GetHullPlanes( hullA ); - for ( int i = 0; i < hullA->faceCount; ++i ) - { - TryAxis( hullA, hullB, xfB, planesA[i].normal, &best, &bestNormal ); - TryAxis( hullA, hullB, xfB, b3Neg( planesA[i].normal ), &best, &bestNormal ); - } - - const b3Plane* planesB = b3GetHullPlanes( hullB ); - for ( int i = 0; i < hullB->faceCount; ++i ) - { - b3Vec3 n = b3RotateVector( xfB.q, planesB[i].normal ); - TryAxis( hullA, hullB, xfB, n, &best, &bestNormal ); - TryAxis( hullA, hullB, xfB, b3Neg( n ), &best, &bestNormal ); - } - - const b3HullHalfEdge* edgesA = b3GetHullEdges( hullA ); - const b3Vec3* pointsA = b3GetHullPoints( hullA ); - const b3HullHalfEdge* edgesB = b3GetHullEdges( hullB ); - const b3Vec3* pointsB = b3GetHullPoints( hullB ); - - // Half edges are stored as adjacent twin pairs, so the even index and its successor bound one edge. - for ( int i = 0; i < hullA->edgeCount; i += 2 ) - { - b3Vec3 dirA = b3Sub( pointsA[edgesA[i + 1].origin], pointsA[edgesA[i].origin] ); - for ( int j = 0; j < hullB->edgeCount; j += 2 ) - { - b3Vec3 dirB = b3RotateVector( xfB.q, b3Sub( pointsB[edgesB[j + 1].origin], pointsB[edgesB[j].origin] ) ); - b3Vec3 cross = b3Cross( dirA, dirB ); - - // Near parallel edges give no useful axis and cannot be the true maximum. - if ( b3Dot( cross, cross ) < 1e-10f ) - { - continue; - } - - cross = b3Normalize( cross ); - TryAxis( hullA, hullB, xfB, cross, &best, &bestNormal ); - TryAxis( hullA, hullB, xfB, b3Neg( cross ), &best, &bestNormal ); - } - } - - *outNormal = bestNormal; - return best; -} - -// Two axis aligned cubes pushed apart along x. A's plus x face is the separating axis, the gap is -// large enough to trip the speculative early out, and the reference vertex on B is its minus x side. -static int FaceAxisASeparatedTest( void ) -{ - b3BoxHull hullA = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - b3Transform xfB = { { 1.2f, 0.0f, 0.0f }, b3Quat_identity }; - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - ENSURE( q.type == b3_faceAxisA ); - ENSURE_SMALL( q.separation - 0.2f, 1e-5f ); - ENSURE_SMALL( q.normal.x - 1.0f, 1e-6f ); - ENSURE_SMALL( q.normal.y, 1e-6f ); - ENSURE_SMALL( q.normal.z, 1e-6f ); - - const b3Plane* planesA = b3GetHullPlanes( &hullA.base ); - ENSURE_SMALL( planesA[q.indexA].normal.x - 1.0f, 1e-6f ); - - const b3Vec3* pointsB = b3GetHullPoints( &hullB.base ); - ENSURE_SMALL( pointsB[q.indexB].x + 0.5f, 1e-6f ); - - ENSURE_SMALL( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation, 1e-5f ); - return 0; -} - -// A yawed 45 degrees about z so all of its faces sit oblique to x. Only B still has a face square to -// the gap, so the reference has to be B's minus x face. This is the case that ties when both hulls -// are aligned, and the tie is what a face A bias would hide. -static int FaceAxisBSeparatedTest( void ) -{ - b3BoxHull hullA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisZ, 0.25f * B3_PI ) ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float aExtent = 0.5f * kRoot2; - float gap = 0.2f; - float d = aExtent + 0.5f + gap; - b3Transform xfB = { { d, 0.0f, 0.0f }, b3Quat_identity }; - - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - ENSURE( q.type == b3_faceAxisB ); - ENSURE_SMALL( q.separation - gap, 1e-5f ); - ENSURE_SMALL( q.normal.x - 1.0f, 1e-5f ); - ENSURE_SMALL( q.normal.y, 1e-5f ); - ENSURE_SMALL( q.normal.z, 1e-5f ); - - const b3Plane* planesB = b3GetHullPlanes( &hullB.base ); - ENSURE_SMALL( planesB[q.indexB].normal.x + 1.0f, 1e-5f ); - - const b3Vec3* pointsA = b3GetHullPoints( &hullA.base ); - ENSURE_SMALL( pointsA[q.indexA].x - aExtent, 1e-4f ); - - ENSURE_SMALL( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation, 1e-4f ); - return 0; -} - -// Well beyond the speculative distance the face phase must report the axis and separation without -// running the edge phase. A sign slip in the early out would read as deep overlap. -static int FaceFarSeparatedTest( void ) -{ - b3BoxHull hullA = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - b3Transform xfB = { { 3.0f, 0.0f, 0.0f }, b3Quat_identity }; - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - ENSURE( q.type == b3_faceAxisA ); - ENSURE_SMALL( q.separation - 2.0f, 1e-5f ); - ENSURE_SMALL( q.normal.x - 1.0f, 1e-6f ); - - b3Vec3 oracleNormal; - float oracleSep = OracleSeparation( &hullA.base, &hullB.base, xfB, &oracleNormal ); - ENSURE_SMALL( q.separation - oracleSep, 1e-5f ); - return 0; -} - -// The support bias is derived from each hull's AABB, not from an origin assumed to sit inside it. A -// box built far from its own local origin is the case the old diagonal bias got wrong. A is yawed -// and pushed out to x = 5, so the face B query has to run getSupport over vertices clustered near -// x = 5 and still pick the right one. -static int OffsetFaceAxisBTest( void ) -{ - float cx = 5.0f; - b3Transform placeA = { { cx, 0.0f, 0.0f }, ExactQuat( kAxisZ, 0.25f * B3_PI ) }; - b3BoxHull hullA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, placeA ); - b3BoxHull hullB = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - float aExtent = cx + 0.5f * kRoot2; - float gap = 0.2f; - float d = aExtent + 0.5f + gap; - b3Transform xfB = { { d, 0.0f, 0.0f }, b3Quat_identity }; - - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - ENSURE( q.type == b3_faceAxisB ); - ENSURE_SMALL( q.separation - gap, 1e-4f ); - ENSURE_SMALL( q.normal.x - 1.0f, 1e-5f ); - ENSURE_SMALL( q.normal.y, 1e-5f ); - ENSURE_SMALL( q.normal.z, 1e-5f ); - - const b3Plane* planesB = b3GetHullPlanes( &hullB.base ); - ENSURE_SMALL( planesB[q.indexB].normal.x + 1.0f, 1e-5f ); - - const b3Vec3* pointsA = b3GetHullPoints( &hullA.base ); - ENSURE_SMALL( pointsA[q.indexA].x - aExtent, 1e-4f ); - - b3Vec3 oracleNormal; - float oracleSep = OracleSeparation( &hullA.base, &hullB.base, xfB, &oracleNormal ); - ENSURE_SMALL( q.separation - oracleSep, 1e-4f ); - ENSURE_SMALL( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation, 1e-4f ); - return 0; -} - -// Cube A yawed 45 about y presents an edge along y at x = h*root2. Cube B rolled 45 about z presents -// an edge along z at x = -h*root2. Sliding B along x makes those edges the closest features, so the -// axis is x and the separation is d - root2. The sweep straddles contact into overlap while staying -// under the speculative distance, so no face axis can short circuit the edge phase. The overlap rows -// pin the maximum separation, which is where a premature edge early out shows up. -static int EdgePairSweepTest( void ) -{ - b3BoxHull hullA = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisY, 0.25f * B3_PI ) ); - b3BoxHull hullB = b3MakeTransformedBoxHull( 0.5f, 0.5f, 0.5f, ExactRotation( kAxisZ, 0.25f * B3_PI ) ); - - float distances[] = { 1.43f, 1.42f, kRoot2, 1.40f, 1.38f, 1.35f, 1.30f }; - - for ( int i = 0; i < ARRAY_COUNT( distances ); ++i ) - { - float d = distances[i]; - float expected = d - kRoot2; - - b3Transform xfB = { { d, 0.0f, 0.0f }, b3Quat_identity }; - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - ENSURE( q.type == b3_edgePairAxis ); - ENSURE_SMALL( q.separation - expected, 1e-4f ); - ENSURE_SMALL( q.normal.x - 1.0f, 1e-4f ); - ENSURE_SMALL( q.normal.y, 1e-4f ); - ENSURE_SMALL( q.normal.z, 1e-4f ); - - // Half edge indices are the even twin of each pair. - ENSURE( ( q.indexA & 1 ) == 0 ); - ENSURE( ( q.indexB & 1 ) == 0 ); - - b3Vec3 oracleNormal; - float oracleSep = OracleSeparation( &hullA.base, &hullB.base, xfB, &oracleNormal ); - ENSURE_SMALL( q.separation - oracleSep, 1e-4f ); - ENSURE_SMALL( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation, 1e-4f ); - } - - return 0; -} - -static uint32_t g_seed = 987654321u; - -static float NextFloat( float lower, float upper ) -{ - g_seed = 1664525u * g_seed + 1013904223u; - float t = (float)( g_seed >> 8 ) / (float)( 1 << 24 ); - return lower + t * ( upper - lower ); -} - -static b3Vec3 NextDirection( void ) -{ - b3Vec3 v = { NextFloat( -1.0f, 1.0f ), NextFloat( -1.0f, 1.0f ), NextFloat( -1.0f, 1.0f ) }; - return b3Normalize( v ); -} - -// A wide net over randomly oriented box pairs, from clearly separated to deep overlap. The brute -// force oracle is the source of truth. Whatever axis the query returns it must be a unit vector that -// reproduces its own separation, it must not exceed the true maximum, and it must not fall short of -// it. The short fall bound is what a suboptimal edge pick trips. Thin boxes are mixed in because a -// crossed pair of long edges stays the axis of minimum penetration even deep in overlap, which is -// the hardest case for the edge phase. -static int SeparatingAxisOracleTest( void ) -{ - g_seed = 987654321u; - - int separated = 0; - int penetrating = 0; - int edgeWins = 0; - float worstBandShortfall = 0.0f; - float worstExcess = 0.0f; - - for ( int i = 0; i < 4000; ++i ) - { - b3Vec3 halfA, halfB; - float reach; - - if ( i & 1 ) - { - // Thin crossed beams driven into deep overlap. - halfA = (b3Vec3){ NextFloat( 1.0f, 1.6f ), NextFloat( 0.08f, 0.15f ), NextFloat( 0.08f, 0.15f ) }; - halfB = (b3Vec3){ NextFloat( 1.0f, 1.6f ), NextFloat( 0.08f, 0.15f ), NextFloat( 0.08f, 0.15f ) }; - reach = NextFloat( 0.0f, 0.4f ); - } - else - { - // Chunky boxes across the whole separated to overlapping range. - halfA = (b3Vec3){ NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ) }; - halfB = (b3Vec3){ NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ) }; - reach = NextFloat( 0.0f, 1.7f ); - } - - // Rotate A in place so it stays centered on the origin, which keeps the support bias valid. - b3BoxHull hullA = - b3MakeTransformedBoxHull( halfA.x, halfA.y, halfA.z, ExactRotation( NextDirection(), NextFloat( 0.0f, B3_PI ) ) ); - b3BoxHull hullB = b3MakeBoxHull( halfB.x, halfB.y, halfB.z ); - - b3Transform xfB = { b3MulSV( reach, NextDirection() ), ExactQuat( NextDirection(), NextFloat( 0.0f, B3_PI ) ) }; - - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - b3Vec3 oracleNormal; - float oracleSep = OracleSeparation( &hullA.base, &hullB.base, xfB, &oracleNormal ); - - ENSURE_SMALL( b3Length( q.normal ) - 1.0f, 1e-3f ); - ENSURE_SMALL( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation, 2e-3f ); - - worstExcess = b3MaxFloat( worstExcess, q.separation - oracleSep ); - - // Never overstate the true maximum. This holds on every path since the reported axis is real. - ENSURE( q.separation <= oracleSep + 2e-3f ); - - // The scan stops at the first axis that clears the speculative band, so a widely separated pair - // reports some separating axis rather than the deepest one. That is all the collide path needs, - // since past the band it drops the pair either way. Inside the band nothing stops the scan, so - // the result there is the exhaustive maximum, and that is what a manifold gets built from. - if ( q.separation <= B3_SPECULATIVE_DISTANCE ) - { - worstBandShortfall = b3MaxFloat( worstBandShortfall, oracleSep - q.separation ); - - // A suboptimal axis pick lands a discrete step below the true maximum. The bound sits well - // under that step yet clear of the edge normalization noise floor near 6e-4. - ENSURE( q.separation >= oracleSep - 4e-3f ); - } - - if ( oracleSep > 0.0f ) - { - separated += 1; - } - else - { - penetrating += 1; - } - - if ( q.type == b3_edgePairAxis ) - { - edgeWins += 1; - } - } - - printf( " oracle: separated=%d penetrating=%d edgeWins=%d worstBandShortfall=%.2e worstExcess=%.2e\n", separated, - penetrating, edgeWins, worstBandShortfall, worstExcess ); - - // The sweep has to cover both regimes and actually drive the edge path. - ENSURE( separated > 100 ); - ENSURE( penetrating > 100 ); - ENSURE( edgeWins > 20 ); - return 0; -} - -// The oracle over hulls whose vertices sit far from their own local origin, which the AABB based -// bias must handle. Half the pairs offset A in its own frame, half offset B, and B is placed so the -// two centers land near each other across the separated to overlapping range. Any bias that assumed -// the origin was inside the hull would pick the wrong support and blow the separation. -static int OffsetHullOracleTest( void ) -{ - g_seed = 24681012u; - - int separated = 0; - int penetrating = 0; - int edgeWins = 0; - float worstBandShortfall = 0.0f; - float worstExcess = 0.0f; - float worstConsistency = 0.0f; - - for ( int i = 0; i < 3000; ++i ) - { - b3Vec3 halfA = { NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ) }; - b3Vec3 halfB = { NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ), NextFloat( 0.3f, 0.8f ) }; - - b3Vec3 offset = b3MulSV( NextFloat( 2.0f, 6.0f ), NextDirection() ); - float reach = NextFloat( 0.0f, 1.7f ); - b3Vec3 dir = NextDirection(); - - b3BoxHull hullA; - b3BoxHull hullB; - b3Transform xfB; - - if ( i & 1 ) - { - // A carries the offset in its own frame. B is centered and dropped near A's center. - b3Transform placeA = { offset, ExactQuat( NextDirection(), NextFloat( 0.0f, B3_PI ) ) }; - hullA = b3MakeTransformedBoxHull( halfA.x, halfA.y, halfA.z, placeA ); - hullB = b3MakeBoxHull( halfB.x, halfB.y, halfB.z ); - xfB = (b3Transform){ b3MulAdd( offset, reach, dir ), ExactQuat( NextDirection(), NextFloat( 0.0f, B3_PI ) ) }; - } - else - { - // B carries the offset in its own frame. Place it so its world center lands near the origin. - b3Quat qB = ExactQuat( NextDirection(), NextFloat( 0.0f, B3_PI ) ); - hullA = b3MakeBoxHull( halfA.x, halfA.y, halfA.z ); - hullB = b3MakeOffsetBoxHull( halfB.x, halfB.y, halfB.z, offset ); - xfB = (b3Transform){ b3Sub( b3MulSV( reach, dir ), b3RotateVector( qB, offset ) ), qB }; - } - - b3AxisQuery aq = b3ComputeSeparatingAxis( &hullA.base, &hullB.base, xfB, true ); - b3SeparatingAxis q = b3GetBestAxis( &aq ); - - b3Vec3 oracleNormal; - float oracleSep = OracleSeparation( &hullA.base, &hullB.base, xfB, &oracleNormal ); - - float consistency = b3AbsFloat( SepAlong( &hullA.base, &hullB.base, xfB, q.normal ) - q.separation ); - worstConsistency = b3MaxFloat( worstConsistency, consistency ); - worstExcess = b3MaxFloat( worstExcess, q.separation - oracleSep ); - - // Consistency is the sharp bias check: a wrong support pick on an offset hull would throw the - // returned normal off its own separation by a vertex spacing, not a noise floor. It holds on - // every path, early out or not, so it stays unconditional. The oracle bounds are looser since - // differencing coordinates out at radius six costs a few more digits. - ENSURE_SMALL( b3Length( q.normal ) - 1.0f, 1e-3f ); - ENSURE( consistency < 1e-3f ); - ENSURE( q.separation <= oracleSep + 3e-3f ); - - // Only the in band result feeds a manifold, and only there does the scan run to completion. - if ( q.separation <= B3_SPECULATIVE_DISTANCE ) - { - worstBandShortfall = b3MaxFloat( worstBandShortfall, oracleSep - q.separation ); - ENSURE( q.separation >= oracleSep - 8e-3f ); - } - - if ( oracleSep > 0.0f ) - { - separated += 1; - } - else - { - penetrating += 1; - } - - if ( q.type == b3_edgePairAxis ) - { - edgeWins += 1; - } - } - - printf( - " offset: separated=%d penetrating=%d edgeWins=%d worstBandShortfall=%.2e worstExcess=%.2e worstConsistency=%.2e\n", - separated, penetrating, edgeWins, worstBandShortfall, worstExcess, worstConsistency ); - - ENSURE( separated > 100 ); - ENSURE( penetrating > 100 ); - ENSURE( edgeWins > 20 ); - return 0; -} - -int SeparatingAxisTest( void ) -{ - RUN_SUBTEST( FaceAxisASeparatedTest ); - RUN_SUBTEST( FaceAxisBSeparatedTest ); - RUN_SUBTEST( FaceFarSeparatedTest ); - RUN_SUBTEST( OffsetFaceAxisBTest ); - RUN_SUBTEST( EdgePairSweepTest ); - RUN_SUBTEST( SeparatingAxisOracleTest ); - RUN_SUBTEST( OffsetHullOracleTest ); - - return 0; -} diff --git a/test/test_shape.c b/test/test_shape.c index b5b7369..db07f83 100644 --- a/test/test_shape.c +++ b/test/test_shape.c @@ -3,13 +3,11 @@ #include "test_macros.h" -#include "box3d/box3d.h" #include "box3d/collision.h" #include "box3d/math_functions.h" #include #include -#include static b3Capsule capsule = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, 1.0f }; static b3Sphere sphere = { { 1.0f, 0.0f, 0.0f }, 1.0f }; @@ -277,8 +275,8 @@ static int PointInShapeTest( void ) // Shared assertions for a surface hit. The normal points outward toward the ray, // the point sits on the surface, and the point lies on the ray at the reported fraction. -static int CheckCastHit( b3CastOutput out, b3Vec3 origin, b3Vec3 translation, b3Vec3 point, b3Vec3 normal, float fraction, - float tol ) +static int CheckCastHit( b3CastOutput out, b3Vec3 origin, b3Vec3 translation, b3Vec3 point, b3Vec3 normal, + float fraction, float tol ) { ENSURE( out.hit ); ENSURE_SMALL( out.fraction - fraction, tol ); @@ -313,22 +311,22 @@ static int RayCastSphereHitTest( void ) { b3RayCastInput input = { { -4.0f, 0.0f, 0.0f }, { 8.0f, 0.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastSphere( &s, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -1.0f, 0.0f, 0.0f }, (b3Vec3){ -1.0f, 0.0f, 0.0f }, - 3.0f / 8.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -1.0f, 0.0f, 0.0f }, + ( b3Vec3 ){ -1.0f, 0.0f, 0.0f }, 3.0f / 8.0f, 1e-5f ) ) return 1; } { b3RayCastInput input = { { 0.0f, 4.0f, 0.0f }, { 0.0f, -8.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastSphere( &s, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 0.0f, 1.0f, 0.0f }, (b3Vec3){ 0.0f, 1.0f, 0.0f }, - 3.0f / 8.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, + ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, 3.0f / 8.0f, 1e-5f ) ) return 1; } { b3RayCastInput input = { { 0.0f, 0.0f, -4.0f }, { 0.0f, 0.0f, 8.0f }, 1.0f }; b3CastOutput out = b3RayCastSphere( &s, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 0.0f, 0.0f, -1.0f }, (b3Vec3){ 0.0f, 0.0f, -1.0f }, - 3.0f / 8.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 0.0f, 0.0f, -1.0f }, + ( b3Vec3 ){ 0.0f, 0.0f, -1.0f }, 3.0f / 8.0f, 1e-5f ) ) return 1; } @@ -337,8 +335,8 @@ static int RayCastSphereHitTest( void ) b3Sphere s2 = { { 5.0f, 0.0f, 0.0f }, 2.0f }; b3RayCastInput input = { { 0.0f, 0.0f, 0.0f }, { 10.0f, 0.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastSphere( &s2, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 3.0f, 0.0f, 0.0f }, (b3Vec3){ -1.0f, 0.0f, 0.0f }, - 0.3f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 3.0f, 0.0f, 0.0f }, + ( b3Vec3 ){ -1.0f, 0.0f, 0.0f }, 0.3f, 1e-5f ) ) return 1; } @@ -347,8 +345,8 @@ static int RayCastSphereHitTest( void ) float k = 0.70710678f; b3RayCastInput input = { { -3.0f, -3.0f, 0.0f }, { 6.0f, 6.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastSphere( &s, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -k, -k, 0.0f }, (b3Vec3){ -k, -k, 0.0f }, 0.382149f, - 1e-4f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -k, -k, 0.0f }, + ( b3Vec3 ){ -k, -k, 0.0f }, 0.382149f, 1e-4f ) ) return 1; } @@ -447,24 +445,24 @@ static int RayCastCapsuleSideTest( void ) { b3RayCastInput input = { { 0.0f, 3.0f, 0.0f }, { 0.0f, -6.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 0.0f, 1.0f, 0.0f }, (b3Vec3){ 0.0f, 1.0f, 0.0f }, - 1.0f / 3.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, + ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, 1.0f / 3.0f, 1e-5f ) ) return 1; } // Same from +z to exercise the other transverse direction. { b3RayCastInput input = { { 0.0f, 0.0f, 3.0f }, { 0.0f, 0.0f, -6.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 0.0f, 0.0f, 1.0f }, (b3Vec3){ 0.0f, 0.0f, 1.0f }, - 1.0f / 3.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 0.0f, 0.0f, 1.0f }, + ( b3Vec3 ){ 0.0f, 0.0f, 1.0f }, 1.0f / 3.0f, 1e-5f ) ) return 1; } // Side hit nearer the c1 end. { b3RayCastInput input = { { -1.0f, 3.0f, 0.0f }, { 0.0f, -6.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -1.0f, 1.0f, 0.0f }, (b3Vec3){ 0.0f, 1.0f, 0.0f }, - 1.0f / 3.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -1.0f, 1.0f, 0.0f }, + ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, 1.0f / 3.0f, 1e-5f ) ) return 1; } return 0; @@ -477,8 +475,8 @@ static int RayCastCapsuleObliqueTest( void ) // dot(axis, rayAxis) != 0. b3RayCastInput input = { { -3.0f, 3.0f, 0.0f }, { 4.0f, -4.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - return CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -1.0f, 1.0f, 0.0f }, (b3Vec3){ 0.0f, 1.0f, 0.0f }, 0.5f, - 1e-4f ); + return CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -1.0f, 1.0f, 0.0f }, + ( b3Vec3 ){ 0.0f, 1.0f, 0.0f }, 0.5f, 1e-4f ); } static int RayCastCapsuleCapTest( void ) @@ -489,24 +487,24 @@ static int RayCastCapsuleCapTest( void ) { b3RayCastInput input = { { 5.0f, 0.0f, 0.0f }, { -8.0f, 0.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 3.0f, 0.0f, 0.0f }, (b3Vec3){ 1.0f, 0.0f, 0.0f }, - 1.0f / 4.0f, 1e-5f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 3.0f, 0.0f, 0.0f }, + ( b3Vec3 ){ 1.0f, 0.0f, 0.0f }, 1.0f / 4.0f, 1e-5f ) ) return 1; } // Off-axis ray through the c2 cap center, approaching from outside the cylinder. { b3RayCastInput input = { { 4.0f, 2.0f, 0.0f }, { -4.0f, -4.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ 2.0f + k, k, 0.0f }, (b3Vec3){ k, k, 0.0f }, 0.323223f, - 1e-4f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ 2.0f + k, k, 0.0f }, + ( b3Vec3 ){ k, k, 0.0f }, 0.323223f, 1e-4f ) ) return 1; } // Mirror through the c1 cap center. { b3RayCastInput input = { { -4.0f, 2.0f, 0.0f }, { 4.0f, -4.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &rayCapsule, &input ); - if ( CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -2.0f - k, k, 0.0f }, (b3Vec3){ -k, k, 0.0f }, - 0.323223f, 1e-4f ) ) + if ( CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -2.0f - k, k, 0.0f }, + ( b3Vec3 ){ -k, k, 0.0f }, 0.323223f, 1e-4f ) ) return 1; } return 0; @@ -581,8 +579,8 @@ static int RayCastCapsuleDegenerateTest( void ) b3Capsule c = { { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, 1.0f }; b3RayCastInput input = { { -4.0f, 0.0f, 0.0f }, { 8.0f, 0.0f, 0.0f }, 1.0f }; b3CastOutput out = b3RayCastCapsule( &c, &input ); - return CheckCastHit( out, input.origin, input.translation, (b3Vec3){ -1.0f, 0.0f, 0.0f }, (b3Vec3){ -1.0f, 0.0f, 0.0f }, - 3.0f / 8.0f, 1e-5f ); + return CheckCastHit( out, input.origin, input.translation, ( b3Vec3 ){ -1.0f, 0.0f, 0.0f }, + ( b3Vec3 ){ -1.0f, 0.0f, 0.0f }, 3.0f / 8.0f, 1e-5f ); } static int RayCastCapsuleClipTest( void ) @@ -774,7 +772,7 @@ static int RayCastFarOriginTest( void ) { for ( int ib = 0; ib < ARRAY_COUNT( offsets ); ++ib ) { - b3Vec3 u = b3Normalize( (b3Vec3){ offsets[ia], offsets[ib], 1.0f } ); + b3Vec3 u = b3Normalize( ( b3Vec3 ){ offsets[ia], offsets[ib], 1.0f } ); b3Vec3 origin = b3MulAdd( h, d, u ); b3Vec3 translation = b3MulSV( -2.0f * d, u ); b3RayCastInput input = { origin, translation, 1.0f }; @@ -854,131 +852,12 @@ static int RayCastShapeTest( void ) return 0; } -static int CheckShapeName( b3ShapeId shapeId, const char* expected ) -{ - const char* got = b3Shape_GetName( shapeId ); - ENSURE( got != NULL || expected == NULL ); - if ( got == NULL ) - { - return 0; - } - - int srcLen = expected != NULL ? (int)strlen( expected ) : 0; - ENSURE( (int)strlen( got ) == srcLen ); - if ( srcLen > 0 ) - { - ENSURE( strncmp( got, expected, (size_t)srcLen ) == 0 ); - } - return 0; -} - -// Cover the def path, the setter, over-length truncation, and the NULL clear. A zero cap collapses every -// case to the empty string, which the length-derived check handles without a special branch. -static int ShapeNameTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3Sphere s = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - - // Default def leaves the name empty. - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - b3ShapeId shapeId = b3CreateSphereShape( bodyId, &shapeDef, &s ); - if ( CheckShapeName( shapeId, NULL ) ) - return 1; - - // Name carried on the def. - shapeDef.name = "box"; - b3ShapeId namedId = b3CreateSphereShape( bodyId, &shapeDef, &s ); - if ( CheckShapeName( namedId, "box" ) ) - return 1; - - // Setter overwrites. - b3Shape_SetName( shapeId, "wheel" ); - if ( CheckShapeName( shapeId, "wheel" ) ) - return 1; - - // Over-length name truncates to the cap. - b3Shape_SetName( shapeId, "abcdefghijklmnopqrstuvwxyz" ); - if ( CheckShapeName( shapeId, "abcdefghijklmnopqrstuvwxyz" ) ) - return 1; - - // NULL clears the name. - b3Shape_SetName( shapeId, NULL ); - if ( CheckShapeName( shapeId, NULL ) ) - return 1; - - b3DestroyWorld( worldId ); - return 0; -} - -// The event enables moved from separate bools to a shared bit field. Each accessor must touch only its own -// bit, so start with all set and flip them one at a time, checking the rest hold. -static int ShapeFlagsTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3Sphere s = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - shapeDef.enableSensorEvents = true; - shapeDef.enableContactEvents = true; - shapeDef.enableHitEvents = true; - shapeDef.enablePreSolveEvents = true; - b3ShapeId shapeId = b3CreateSphereShape( bodyId, &shapeDef, &s ); - - // The def carries every enable through to the shape. - ENSURE( b3Shape_AreSensorEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreContactEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreHitEventsEnabled( shapeId ) ); - ENSURE( b3Shape_ArePreSolveEventsEnabled( shapeId ) ); - - // Clearing one leaves the rest set. - b3Shape_EnableSensorEvents( shapeId, false ); - ENSURE( b3Shape_AreSensorEventsEnabled( shapeId ) == false ); - ENSURE( b3Shape_AreContactEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreHitEventsEnabled( shapeId ) ); - ENSURE( b3Shape_ArePreSolveEventsEnabled( shapeId ) ); - - // Setting it back does not disturb the others. - b3Shape_EnableSensorEvents( shapeId, true ); - b3Shape_EnableHitEvents( shapeId, false ); - ENSURE( b3Shape_AreSensorEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreContactEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreHitEventsEnabled( shapeId ) == false ); - ENSURE( b3Shape_ArePreSolveEventsEnabled( shapeId ) ); - - // Clear two more and confirm only the remaining bit stays set. - b3Shape_EnableContactEvents( shapeId, false ); - b3Shape_EnablePreSolveEvents( shapeId, false ); - ENSURE( b3Shape_AreSensorEventsEnabled( shapeId ) ); - ENSURE( b3Shape_AreContactEventsEnabled( shapeId ) == false ); - ENSURE( b3Shape_AreHitEventsEnabled( shapeId ) == false ); - ENSURE( b3Shape_ArePreSolveEventsEnabled( shapeId ) == false ); - - b3DestroyWorld( worldId ); - return 0; -} - int ShapeTest( void ) { box = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); RUN_SUBTEST( ShapeMassTest ); RUN_SUBTEST( ShapeAABBTest ); - RUN_SUBTEST( ShapeNameTest ); - RUN_SUBTEST( ShapeFlagsTest ); // RUN_SUBTEST( PointInShapeTest ); RUN_SUBTEST( RayCastShapeTest ); diff --git a/test/test_step.c b/test/test_step.c deleted file mode 100644 index 97ff13c..0000000 --- a/test/test_step.c +++ /dev/null @@ -1,829 +0,0 @@ -// SPDX-FileCopyrightText: 2026 Erin Catto -// SPDX-License-Identifier: MIT - -#include "core.h" -#include "determinism.h" -#include "physics_world.h" -#include "platform.h" -#include "recording.h" -#include "test_macros.h" - -#include "box3d/box3d.h" -#include "box3d/types.h" - -#include -#include - -#define MAX_BATCH_TASKS ( B3_MAX_WORKERS + 2 ) - -typedef enum TaskOrder -{ - e_forward, - e_reverse, -} TaskOrder; - -// Runs every batch on the calling thread. Honoring the deferred flag holds the tree rebuild back until -// right before the Continue that joins it, which catches a join list placed on the wrong batch. -typedef struct SerialHost -{ - TaskOrder order; - bool honorDeferred; - int batchCount; - int deferredBatch; - int joinBatch; - int deferredOnlyBatchCount; - int maxBatchSize; - int taskCount; - const b3Task* heldTask; -} SerialHost; - -static void RunSerialBatch( SerialHost* host, b3TaskBatch batch ) -{ - host->maxBatchSize = batch.count > host->maxBatchSize ? batch.count : host->maxBatchSize; - - int deferredCount = 0; - for ( int k = 0; k < batch.count; ++k ) - { - int i = host->order == e_forward ? k : batch.count - 1 - k; - const b3Task* task = batch.tasks + i; - if ( task->deferred ) - { - deferredCount += 1; - host->deferredBatch = host->batchCount; - if ( host->honorDeferred ) - { - host->heldTask = task; - continue; - } - } - - task->fcn( task->context ); - } - - if ( deferredCount == batch.count ) - { - host->deferredOnlyBatchCount += 1; - } - - if ( batch.joinCount > 0 ) - { - host->joinBatch = host->batchCount; - if ( host->heldTask != NULL ) - { - host->heldTask->fcn( host->heldTask->context ); - host->heldTask = NULL; - } - } - - host->batchCount += 1; -} - -static int SerialPhasedStep( SerialHost* host, b3WorldId worldId, float timeStep, int subStepCount ) -{ - host->batchCount = 0; - host->taskCount = 0; - host->deferredBatch = -1; - host->joinBatch = -1; - host->heldTask = NULL; - - b3TaskBatch batch = b3World_BeginStep( worldId, timeStep, subStepCount ); - while ( batch.count > 0 ) - { - ENSURE( batch.count <= MAX_BATCH_TASKS ); - ENSURE( batch.joinCount == 0 || batch.joinCount == 1 ); - for ( int i = 0; i < batch.count; ++i ) - { - b3TaskType type = batch.tasks[i].type; - ENSURE( 0 <= type && type < b3_taskTypeCount ); - ENSURE( batch.tasks[i].deferred == false || type == b3_taskTreeRebuild ); - } - host->taskCount += batch.count; - RunSerialBatch( host, batch ); - batch = b3World_ContinueStep( worldId ); - } - - ENSURE( host->heldTask == NULL ); - ENSURE( b3World_GetCounters( worldId ).taskCount == host->taskCount ); - ENSURE( b3World_GetCounters( worldId ).enqueueCount == 0 ); - ENSURE( ( host->deferredBatch == -1 ) == ( host->joinBatch == -1 ) ); - ENSURE( host->deferredBatch < host->joinBatch || host->deferredBatch == -1 ); - return 0; -} - -// A pool of threads draining a queue that only grows. Slots are never reused, so producers and -// consumers need no reset handshake. -#define POOL_SLOT_CAPACITY ( 1 << 18 ) -#define POOL_MAX_THREADS 8 - -typedef struct PoolSlot -{ - b3TaskCallback* fcn; - void* context; - b3AtomicInt* counter; -} PoolSlot; - -typedef struct Pool -{ - PoolSlot* slots; - b3AtomicInt published; - b3AtomicInt claimed; - b3AtomicInt quit; - b3Thread* threads[POOL_MAX_THREADS]; - int threadCount; -} Pool; - -static bool PoolRunOne( Pool* pool ) -{ - int claimed = b3AtomicLoadInt( &pool->claimed ); - int published = b3AtomicLoadInt( &pool->published ); - if ( claimed >= published ) - { - return false; - } - - if ( b3AtomicCompareExchangeInt( &pool->claimed, claimed, claimed + 1 ) == false ) - { - return true; - } - - PoolSlot* slot = pool->slots + claimed; - slot->fcn( slot->context ); - if ( slot->counter != NULL ) - { - b3AtomicFetchAddInt( slot->counter, -1 ); - } - - return true; -} - -static void PoolThreadMain( void* context ) -{ - Pool* pool = context; - while ( b3AtomicLoadInt( &pool->quit ) == 0 ) - { - if ( PoolRunOne( pool ) == false ) - { - b3Yield(); - } - } -} - -static void PoolPush( Pool* pool, b3TaskCallback* fcn, void* context, b3AtomicInt* counter ) -{ - int index = b3AtomicLoadInt( &pool->published ); - B3_ASSERT( index < POOL_SLOT_CAPACITY ); - pool->slots[index] = (PoolSlot){ fcn, context, counter }; - b3AtomicStoreInt( &pool->published, index + 1 ); -} - -static void PoolHelpUntilZero( Pool* pool, b3AtomicInt* counter ) -{ - while ( b3AtomicLoadInt( counter ) > 0 ) - { - if ( PoolRunOne( pool ) == false ) - { - b3Yield(); - } - } -} - -static void CreatePool( Pool* pool, int threadCount ) -{ - memset( pool, 0, sizeof( Pool ) ); - pool->slots = b3Alloc( POOL_SLOT_CAPACITY * sizeof( PoolSlot ) ); - pool->threadCount = threadCount; - for ( int i = 0; i < threadCount; ++i ) - { - pool->threads[i] = b3CreateThread( PoolThreadMain, pool, "step_test" ); - } -} - -static void DestroyPool( Pool* pool ) -{ - b3AtomicStoreInt( &pool->quit, 1 ); - for ( int i = 0; i < pool->threadCount; ++i ) - { - b3JoinThread( pool->threads[i] ); - } - b3Free( pool->slots, POOL_SLOT_CAPACITY * sizeof( PoolSlot ) ); -} - -// Pull host on the pool. The rebuild stays in flight across Continue calls until a batch joins it. -static void PooledPhasedStep( Pool* pool, b3WorldId worldId, float timeStep, int subStepCount ) -{ - b3AtomicInt batchCounter; - b3AtomicInt treeCounter; - b3AtomicStoreInt( &treeCounter, 0 ); - - b3TaskBatch batch = b3World_BeginStep( worldId, timeStep, subStepCount ); - while ( batch.count > 0 ) - { - int nonDeferred = 0; - for ( int i = 0; i < batch.count; ++i ) - { - nonDeferred += batch.tasks[i].deferred ? 0 : 1; - } - - b3AtomicStoreInt( &batchCounter, nonDeferred ); - - for ( int i = 0; i < batch.count; ++i ) - { - const b3Task* task = batch.tasks + i; - if ( task->deferred ) - { - b3AtomicStoreInt( &treeCounter, 1 ); - PoolPush( pool, task->fcn, task->context, &treeCounter ); - } - else - { - PoolPush( pool, task->fcn, task->context, &batchCounter ); - } - } - - PoolHelpUntilZero( pool, &batchCounter ); - - if ( batch.joinCount > 0 ) - { - PoolHelpUntilZero( pool, &treeCounter ); - } - - batch = b3World_ContinueStep( worldId ); - } - - B3_ASSERT( b3AtomicLoadInt( &treeCounter ) == 0 ); -} - -static int enqueueOnlyCount; - -static void* EnqueueOnlyTask( b3TaskCallback* task, void* taskContext, void* userContext, b3TaskType taskType ) -{ - B3_UNUSED( taskType ); - enqueueOnlyCount += 1; - Pool* pool = userContext; - PoolPush( pool, task, taskContext, NULL ); - return pool; -} - -typedef enum HostKind -{ - e_syncHost, - e_serialHost, - e_pooledHost, -} HostKind; - -typedef struct HostConfig -{ - HostKind kind; - TaskOrder order; - bool honorDeferred; - int workerCount; - int threadCount; -} HostConfig; - -static int RunFallingHinges( HostConfig config ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = config.workerCount; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - Pool pool; - if ( config.kind == e_pooledHost ) - { - CreatePool( &pool, config.threadCount - 1 ); - } - - SerialHost serialHost = { .order = config.order, .honorDeferred = config.honorDeferred }; - - FallingHingeData data = CreateFallingHinges( worldId ); - - float timeStep = 1.0f / 60.0f; - int stepLimit = 1000; - for ( int i = 0; i < stepLimit; ++i ) - { - int subStepCount = 4; - if ( config.kind == e_serialHost ) - { - int result = SerialPhasedStep( &serialHost, worldId, timeStep, subStepCount ); - ENSURE( result == 0 ); - } - else if ( config.kind == e_pooledHost ) - { - PooledPhasedStep( &pool, worldId, timeStep, subStepCount ); - } - else - { - b3World_Step( worldId, timeStep, subStepCount ); - } - - if ( UpdateFallingHinges( worldId, &data ) ) - { - break; - } - } - - if ( config.kind != e_syncHost ) - { - ENSURE( b3GetWorldFromId( worldId )->scheduler == NULL ); - } - - ENSURE( serialHost.maxBatchSize <= config.workerCount + 2 ); - - b3DestroyWorld( worldId ); - - if ( config.kind == e_pooledHost ) - { - DestroyPool( &pool ); - } - - if ( data.sleepStep != FALLING_HINGE_SLEEP_STEP || data.hash != FALLING_HINGE_HASH ) - { - printf( " host=%d order=%d deferred=%d workers=%d threads=%d sleepStep=%d hash=0x%08X\n", config.kind, config.order, - config.honorDeferred ? 1 : 0, config.workerCount, config.threadCount, data.sleepStep, data.hash ); - } - - ENSURE( data.sleepStep == FALLING_HINGE_SLEEP_STEP ); - ENSURE( data.hash == FALLING_HINGE_HASH ); - - DestroyFallingHinges( &data ); - - return 0; -} - -static int SerialPullTest( void ) -{ - int workerCounts[] = { 1, 4, 8 }; - for ( int i = 0; i < 3; ++i ) - { - HostConfig config = { .kind = e_serialHost, .order = e_forward, .workerCount = workerCounts[i] }; - ENSURE( RunFallingHinges( config ) == 0 ); - } - - return 0; -} - -// The first solver task to run must orchestrate whatever its slot, or a serial host strands a spinner -static int ReverseOrderTest( void ) -{ - int workerCounts[] = { 4, 8 }; - for ( int i = 0; i < 2; ++i ) - { - HostConfig config = { .kind = e_serialHost, .order = e_reverse, .workerCount = workerCounts[i] }; - ENSURE( RunFallingHinges( config ) == 0 ); - } - - return 0; -} - -static int DeferredJoinTest( void ) -{ - int workerCounts[] = { 1, 4 }; - for ( int i = 0; i < 2; ++i ) - { - HostConfig config = { - .kind = e_serialHost, .order = e_forward, .honorDeferred = true, .workerCount = workerCounts[i] }; - ENSURE( RunFallingHinges( config ) == 0 ); - - config.order = e_reverse; - ENSURE( RunFallingHinges( config ) == 0 ); - } - - return 0; -} - -static int PooledPullTest( void ) -{ - int pairs[][2] = { { 1, 1 }, { 2, 2 }, { 4, 4 }, { 8, 8 }, { 8, 2 }, { 2, 8 } }; - for ( int i = 0; i < 6; ++i ) - { - HostConfig config = { .kind = e_pooledHost, .workerCount = pairs[i][0], .threadCount = pairs[i][1] }; - ENSURE( RunFallingHinges( config ) == 0 ); - } - - return 0; -} - -static int EnqueueOnlyTest( void ) -{ - int workerCounts[] = { 2, 4 }; - for ( int i = 0; i < 2; ++i ) - { - Pool pool; - CreatePool( &pool, 3 ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCounts[i]; - worldDef.enqueueTask = EnqueueOnlyTask; - worldDef.finishTask = NULL; - worldDef.userTaskContext = &pool; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - FallingHingeData data = CreateFallingHinges( worldId ); - - float timeStep = 1.0f / 60.0f; - for ( int step = 0; step < 1000; ++step ) - { - enqueueOnlyCount = 0; - b3World_Step( worldId, timeStep, 4 ); - b3Counters counters = b3World_GetCounters( worldId ); - ENSURE( counters.enqueueCount == enqueueOnlyCount ); - ENSURE( counters.enqueueCount <= counters.taskCount ); - - if ( UpdateFallingHinges( worldId, &data ) ) - { - break; - } - } - - ENSURE( b3GetWorldFromId( worldId )->scheduler == NULL ); - - b3DestroyWorld( worldId ); - DestroyPool( &pool ); - - ENSURE( data.sleepStep == FALLING_HINGE_SLEEP_STEP ); - ENSURE( data.hash == FALLING_HINGE_HASH ); - - DestroyFallingHinges( &data ); - } - - return 0; -} - -static int AlternateTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 4; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - FallingHingeData data = CreateFallingHinges( worldId ); - SerialHost host = { .order = e_reverse, .honorDeferred = true }; - - float timeStep = 1.0f / 60.0f; - for ( int i = 0; i < 1000; ++i ) - { - if ( ( i & 1 ) == 0 ) - { - b3World_Step( worldId, timeStep, 4 ); - } - else - { - ENSURE( SerialPhasedStep( &host, worldId, timeStep, 4 ) == 0 ); - } - - if ( UpdateFallingHinges( worldId, &data ) ) - { - break; - } - } - - b3DestroyWorld( worldId ); - - ENSURE( data.sleepStep == FALLING_HINGE_SLEEP_STEP ); - ENSURE( data.hash == FALLING_HINGE_HASH ); - - DestroyFallingHinges( &data ); - - return 0; -} - -static int EmptyWorldTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 4; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - SerialHost host = { .order = e_forward }; - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - ENSURE( host.batchCount == 0 ); - ENSURE( host.deferredBatch == -1 ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - ENSURE( SerialPhasedStep( &host, worldId, 0.0f, 4 ) == 0 ); - ENSURE( host.batchCount == 0 ); - - b3DestroyWorld( worldId ); - return 0; -} - -static b3BodyId CreateBall( b3WorldId worldId, b3Pos position ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = position; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - return bodyId; -} - -// The rebuild must join on the solve batch normally and on the collide batch when solve is skipped -static int JoinPlacementTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 4; - - // A lone ball, no contacts. A zero step skips solve, so the collide batch is the rebuild alone and - // nothing later can join it. It runs as a regular task. - { - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3BodyId bodyId = CreateBall( worldId, (b3Pos){ 0.0f, 4.0f, 0.0f } ); - - SerialHost host = { .order = e_forward, .honorDeferred = true }; - ENSURE( SerialPhasedStep( &host, worldId, 0.0f, 4 ) == 0 ); - ENSURE( host.batchCount > 0 ); - ENSURE( host.deferredBatch == -1 ); - ENSURE( host.deferredOnlyBatchCount == 0 ); - - b3Pos p = b3Body_GetPosition( bodyId ); - ENSURE( p.x == 0.0f && p.y == 4.0f ); - - b3DestroyWorld( worldId ); - } - - // A lone moving ball, no contacts. The collide batch is empty, so the rebuild rides with the solver - // tasks as a regular task instead of running alone. - { - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3BodyId bodyId = CreateBall( worldId, (b3Pos){ 0.0f, 4.0f, 0.0f } ); - b3Body_SetLinearVelocity( bodyId, (b3Vec3){ 10.0f, 0.0f, 0.0f } ); - - SerialHost host = { .order = e_forward, .honorDeferred = true }; - for ( int i = 0; i < 4; ++i ) - { - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - ENSURE( host.deferredBatch == -1 ); - } - - ENSURE( host.deferredOnlyBatchCount == 0 ); - - b3DestroyWorld( worldId ); - } - - // Touching balls on the ground with a zero step: the collide batch has contacts and the join - { - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3ShapeDef groundShapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 20.0f, 1.0f, 20.0f ); - b3CreateHullShape( groundId, &groundShapeDef, &groundBox.base ); - - for ( int i = 0; i < 8; ++i ) - { - CreateBall( worldId, (b3Pos){ -4.0f + 1.0f * i, 0.5f, 0.0f } ); - } - - SerialHost host = { .order = e_forward, .honorDeferred = true }; - ENSURE( SerialPhasedStep( &host, worldId, 0.0f, 4 ) == 0 ); - ENSURE( SerialPhasedStep( &host, worldId, 0.0f, 4 ) == 0 ); - - // Moving step: the join lands on a later batch than the rebuild - for ( int i = 0; i < 4; ++i ) - { - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - if ( host.deferredBatch >= 0 ) - { - ENSURE( host.joinBatch > host.deferredBatch ); - } - } - - b3DestroyWorld( worldId ); - } - - return 0; -} - -// No contacts, a moving ball that keeps the rebuild staged, and a resting pair whose joint is destroyed. -// The pair can only sleep after its island splits, so the solve batch carries the rebuild, the split and -// the solver tasks together. -static int SplitBatchTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 4; - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyId bodyA = CreateBall( worldId, (b3Pos){ 0.0f, 0.0f, 0.0f } ); - b3BodyId bodyB = CreateBall( worldId, (b3Pos){ 2.0f, 0.0f, 0.0f } ); - b3BodyId ballId = CreateBall( worldId, (b3Pos){ 0.0f, 20.0f, 0.0f } ); - b3Body_SetLinearVelocity( ballId, (b3Vec3){ 10.0f, 0.0f, 0.0f } ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = bodyA; - jointDef.base.bodyIdB = bodyB; - jointDef.base.localFrameA.p = (b3Vec3){ 1.0f, 0.0f, 0.0f }; - jointDef.base.localFrameB.p = (b3Vec3){ -1.0f, 0.0f, 0.0f }; - b3JointId jointId = b3CreateRevoluteJoint( worldId, &jointDef ); - - SerialHost host = { .order = e_forward, .honorDeferred = true }; - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - - b3DestroyJoint( jointId, true ); - - int stepCount = 0; - while ( b3Body_IsAwake( bodyA ) && stepCount < 120 ) - { - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - stepCount += 1; - } - - ENSURE( host.maxBatchSize == worldDef.workerCount + 2 ); - ENSURE( b3Body_IsAwake( bodyA ) == false ); - ENSURE( b3Body_IsAwake( ballId ) ); - - b3DestroyWorld( worldId ); - return 0; -} - -// A scene with bullets, a sensor, joints and sleeping islands, checked against the synchronous step -// every step by state hash. -static b3WorldId CreateMixedScene( int workerCount ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef groundDef = b3DefaultBodyDef(); - b3BodyId groundId = b3CreateBody( worldId, &groundDef ); - b3ShapeDef groundShapeDef = b3DefaultShapeDef(); - b3BoxHull groundBox = b3MakeBoxHull( 40.0f, 1.0f, 40.0f ); - b3CreateHullShape( groundId, &groundShapeDef, &groundBox.base ); - - b3ShapeDef sensorDef = b3DefaultShapeDef(); - sensorDef.isSensor = true; - sensorDef.enableSensorEvents = true; - b3BoxHull sensorBox = b3MakeOffsetBoxHull( 4.0f, 2.0f, 4.0f, (b3Vec3){ 10.0f, 2.0f, 0.0f } ); - b3CreateHullShape( groundId, &sensorDef, &sensorBox.base ); - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3ShapeDef boxDef = b3DefaultShapeDef(); - boxDef.enableSensorEvents = true; - boxDef.enableHitEvents = true; - - for ( int row = 0; row < 10; ++row ) - { - for ( int col = 0; col < 10 - row; ++col ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -5.0f + col * 1.05f + row * 0.525f, 0.5f + row * 1.0f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &boxDef, &box.base ); - } - } - - b3BodyId prevId = groundId; - for ( int i = 0; i < 6; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 12.0f + i * 1.0f, 8.0f, 0.0f }; - b3BodyId linkId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull link = b3MakeBoxHull( 0.5f, 0.125f, 0.125f ); - b3CreateHullShape( linkId, &boxDef, &link.base ); - - b3RevoluteJointDef jointDef = b3DefaultRevoluteJointDef(); - jointDef.base.bodyIdA = prevId; - jointDef.base.bodyIdB = linkId; - jointDef.base.localFrameA.p = - prevId.index1 == groundId.index1 ? (b3Vec3){ 11.5f, 8.0f, 0.0f } : (b3Vec3){ 0.5f, 0.0f, 0.0f }; - jointDef.base.localFrameB.p = (b3Vec3){ -0.5f, 0.0f, 0.0f }; - b3CreateRevoluteJoint( worldId, &jointDef ); - prevId = linkId; - } - - for ( int i = 0; i < 4; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.isBullet = true; - bodyDef.position = (b3Pos){ -30.0f, 1.0f + 2.0f * i, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 200.0f, 0.0f, 0.0f }; - b3BodyId bulletId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef bulletDef = b3DefaultShapeDef(); - bulletDef.enableSensorEvents = true; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.1f }; - b3CreateSphereShape( bulletId, &bulletDef, &sphere ); - } - - return worldId; -} - -static uint64_t StateHash( b3WorldId worldId ) -{ - return b3HashWorldState( b3GetWorldFromId( worldId ) ); -} - -static int MixedSceneTest( void ) -{ - int workerCounts[] = { 1, 4, 8 }; - for ( int w = 0; w < 3; ++w ) - { - int workerCount = workerCounts[w]; - b3WorldId syncId = CreateMixedScene( workerCount ); - b3WorldId serialId = CreateMixedScene( workerCount ); - b3WorldId pooledId = CreateMixedScene( workerCount ); - - Pool pool; - CreatePool( &pool, 3 ); - SerialHost host = { .order = e_reverse, .honorDeferred = true }; - - int sensorBeginTotal = 0; - int hitTotal = 0; - int maxBatchCount = 0; - float timeStep = 1.0f / 60.0f; - for ( int i = 0; i < 400; ++i ) - { - b3World_Step( syncId, timeStep, 4 ); - ENSURE( SerialPhasedStep( &host, serialId, timeStep, 4 ) == 0 ); - PooledPhasedStep( &pool, pooledId, timeStep, 4 ); - - uint64_t syncHash = StateHash( syncId ); - ENSURE( StateHash( serialId ) == syncHash ); - ENSURE( StateHash( pooledId ) == syncHash ); - - b3SensorEvents syncSensors = b3World_GetSensorEvents( syncId ); - b3SensorEvents serialSensors = b3World_GetSensorEvents( serialId ); - ENSURE( syncSensors.beginCount == serialSensors.beginCount ); - ENSURE( syncSensors.endCount == serialSensors.endCount ); - - b3ContactEvents syncContacts = b3World_GetContactEvents( syncId ); - b3ContactEvents serialContacts = b3World_GetContactEvents( serialId ); - ENSURE( syncContacts.beginCount == serialContacts.beginCount ); - ENSURE( syncContacts.hitCount == serialContacts.hitCount ); - - b3BodyEvents syncBodies = b3World_GetBodyEvents( syncId ); - b3BodyEvents serialBodies = b3World_GetBodyEvents( serialId ); - ENSURE( syncBodies.moveCount == serialBodies.moveCount ); - - sensorBeginTotal += serialSensors.beginCount; - hitTotal += serialContacts.hitCount; - maxBatchCount = host.batchCount > maxBatchCount ? host.batchCount : maxBatchCount; - } - - ENSURE( sensorBeginTotal > 0 ); - ENSURE( hitTotal > 0 ); - ENSURE( maxBatchCount == 7 ); - ENSURE( b3World_GetAwakeBodyCount( serialId ) < 55 + 6 + 4 ); - - ENSURE( b3World_GetAwakeBodyCount( syncId ) == b3World_GetAwakeBodyCount( serialId ) ); - ENSURE( b3World_GetCounters( serialId ).taskCount > 0 ); - - DestroyPool( &pool ); - b3DestroyWorld( syncId ); - b3DestroyWorld( serialId ); - b3DestroyWorld( pooledId ); - } - - return 0; -} - -static int PhasedRecordingTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 1; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3Recording* recording = b3CreateRecording( 0 ); - b3World_StartRecording( worldId, recording ); - - FallingHingeData data = CreateFallingHinges( worldId ); - - SerialHost host = { .order = e_reverse, .honorDeferred = true }; - for ( int i = 0; i < 120; ++i ) - { - ENSURE( SerialPhasedStep( &host, worldId, 1.0f / 60.0f, 4 ) == 0 ); - UpdateFallingHinges( worldId, &data ); - } - - b3World_StopRecording( worldId ); - b3DestroyWorld( worldId ); - DestroyFallingHinges( &data ); - - const uint8_t* bytes = b3Recording_GetData( recording ); - int size = b3Recording_GetSize( recording ); - ENSURE( b3ValidateReplay( bytes, size, 1 ) ); - ENSURE( b3ValidateReplay( bytes, size, 4 ) ); - - b3DestroyRecording( recording ); - return 0; -} - -int StepTest( void ) -{ - RUN_SUBTEST( SerialPullTest ); - RUN_SUBTEST( ReverseOrderTest ); - RUN_SUBTEST( DeferredJoinTest ); - RUN_SUBTEST( PooledPullTest ); - RUN_SUBTEST( EnqueueOnlyTest ); - RUN_SUBTEST( AlternateTest ); - RUN_SUBTEST( EmptyWorldTest ); - RUN_SUBTEST( JoinPlacementTest ); - RUN_SUBTEST( SplitBatchTest ); - RUN_SUBTEST( MixedSceneTest ); - RUN_SUBTEST( PhasedRecordingTest ); - - return 0; -} diff --git a/test/test_world.c b/test/test_world.c index 298e514..062dca3 100644 --- a/test/test_world.c +++ b/test/test_world.c @@ -2,12 +2,8 @@ // SPDX-License-Identifier: MIT #include "benchmarks.h" -#include "body.h" -#include "dynamic_tree.h" #include "overflow_color.h" -#include "physics_world.h" -#include "platform.h" -#include "recording.h" +#include "stability.h" #include "test_macros.h" #include "box3d/box3d.h" @@ -15,9 +11,7 @@ #include "box3d/constants.h" #include "box3d/math_functions.h" -#include #include -#include // This is a simple example of building and running a simulation // using Box3D. Here we create a large ground box and a small dynamic @@ -316,14 +310,6 @@ int TestWorldCoverage( void ) value = b3World_GetMaximumLinearSpeed( worldId ); ENSURE( value == 10.0f ); - b3World_SetIsotropicInertiaTolerance( worldId, 0.5f ); - value = b3World_GetIsotropicInertiaTolerance( worldId ); - ENSURE( value == 0.5f ); - - b3World_SetIsotropicInertiaTolerance( worldId, 2.0f ); - value = b3World_GetIsotropicInertiaTolerance( worldId ); - ENSURE( value == 1.0f ); - b3World_EnableWarmStarting( worldId, true ); flag = b3World_IsWarmStartingEnabled( worldId ); ENSURE( flag == true ); @@ -584,7 +570,7 @@ static int TestCompoundHitEvents( void ) bodyDef.type = b3_staticBody; b3BodyId compoundBodyId = b3CreateBody( worldId, &bodyDef ); b3ShapeDef compoundShapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( compoundBodyId, &compoundShapeDef, compound ); + b3CreateCompoundShape( compoundBodyId, &compoundShapeDef, compound ); // Sphere driven straight down onto the chosen child bodyDef = b3DefaultBodyDef(); @@ -632,139 +618,6 @@ static int TestCompoundHitEvents( void ) return 0; } -enum -{ - kChild0MaterialId = 101, - kChild1MaterialId = 202, - kProbeMaterialId = 999, -}; - -// No context pointer on mixing callbacks, so capture through file scope -static struct -{ - int callCount; - bool sawChild0; - bool sawChild1; - float mixedFriction; -} materialCapture; - -static float CaptureFrictionMix( float frictionA, uint64_t userMaterialIdA, float frictionB, uint64_t userMaterialIdB ) -{ - materialCapture.callCount += 1; - - if ( userMaterialIdA == kChild0MaterialId || userMaterialIdB == kChild0MaterialId ) - { - materialCapture.sawChild0 = true; - } - - if ( userMaterialIdA == kChild1MaterialId || userMaterialIdB == kChild1MaterialId ) - { - materialCapture.sawChild1 = true; - materialCapture.mixedFriction = sqrtf( frictionA * frictionB ); - } - - return sqrtf( frictionA * frictionB ); -} - -// Contact material selection must use the struck compound child's material, not entry 0 -// of the compound material table. Child 0 gets low friction, child 1 high friction, and a -// unit friction sphere strikes only child 1, so the mixing callback must see child 1's -// values. Covers sphere, capsule, and hull children. Issue #69. -static int TestCompoundContactMaterials( void ) -{ - b3SurfaceMaterial mat0 = b3DefaultSurfaceMaterial(); - mat0.friction = 0.04f; - mat0.userMaterialId = kChild0MaterialId; - - b3SurfaceMaterial mat1 = b3DefaultSurfaceMaterial(); - mat1.friction = 0.81f; - mat1.userMaterialId = kChild1MaterialId; - - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - - // Children at x = -3 and x = +3, all with their top face or surface at y = 0.5 - b3CompoundSphereDef spheres[2] = { - { .sphere = { { -3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat0 }, - { .sphere = { { 3.0f, 0.0f, 0.0f }, 0.5f }, .material = mat1 }, - }; - - b3CompoundCapsuleDef capsules[2] = { - { .capsule = { { -3.0f, 0.0f, -0.5f }, { -3.0f, 0.0f, 0.5f }, 0.5f }, .material = mat0 }, - { .capsule = { { 3.0f, 0.0f, -0.5f }, { 3.0f, 0.0f, 0.5f }, 0.5f }, .material = mat1 }, - }; - - b3CompoundHullDef hulls[2] = { - { .hull = &box.base, .transform = { { -3.0f, 0.0f, 0.0f }, b3Quat_identity }, .material = mat0 }, - { .hull = &box.base, .transform = { { 3.0f, 0.0f, 0.0f }, b3Quat_identity }, .material = mat1 }, - }; - - for ( int childType = 0; childType < 3; ++childType ) - { - b3CompoundDef compoundDef = { 0 }; - if ( childType == 0 ) - { - compoundDef.spheres = spheres; - compoundDef.sphereCount = 2; - } - else if ( childType == 1 ) - { - compoundDef.capsules = capsules; - compoundDef.capsuleCount = 2; - } - else - { - compoundDef.hulls = hulls; - compoundDef.hullCount = 2; - } - - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - - memset( &materialCapture, 0, sizeof( materialCapture ) ); - - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.frictionCallback = CaptureFrictionMix; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3BodyId compoundBodyId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef compoundShapeDef = b3DefaultShapeDef(); - b3CreateBakedCompoundShape( compoundBodyId, &compoundShapeDef, compound ); - - // Sphere driven straight down onto child 1 - bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.gravityScale = 0.0f; - bodyDef.position = (b3Pos){ 3.0f, 3.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, -30.0f, 0.0f }; - b3BodyId sphereBodyId = b3CreateBody( worldId, &bodyDef ); - b3ShapeDef sphereShapeDef = b3DefaultShapeDef(); - sphereShapeDef.density = 1.0f; - sphereShapeDef.baseMaterial.friction = 1.0f; - sphereShapeDef.baseMaterial.userMaterialId = kProbeMaterialId; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.5f }; - b3CreateSphereShape( sphereBodyId, &sphereShapeDef, &sphere ); - - for ( int i = 0; i < 30; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - - ENSURE( materialCapture.callCount > 0 ); - // The pre-fix code fed material table entry 0 to the mixing callback for every child - ENSURE( materialCapture.sawChild0 == false ); - ENSURE( materialCapture.sawChild1 == true ); - // sqrt(0.81 * 1.0) - ENSURE_SMALL( materialCapture.mixedFriction - 0.9f, 1e-5f ); - } - - return 0; -} - static int TestSetWorkerCount( void ) { b3WorldDef worldDef = b3DefaultWorldDef(); @@ -806,6 +659,47 @@ static int TestSetWorkerCount( void ) return 0; } +// This tests continuous collision and mesh contact stability +static int TestMeshDrop( void ) +{ + b3WorldDef worldDef = b3DefaultWorldDef(); + // todo GetCoreCount + worldDef.workerCount = 4; + + b3WorldId worldId = b3CreateWorld( &worldDef ); + + MeshDropData data = CreateMeshDrop( worldId, b3Pos_zero ); + + float timeStep = 1.0f / 60.0f; + + int stepIndex = 0; + int stepLimit = 400; + + while ( stepIndex < stepLimit ) + { + int subStepCount = 4; + b3World_Step( worldId, timeStep, subStepCount ); + + b3BodyEvents events = b3World_GetBodyEvents( worldId ); + if (events.moveCount == 0) + { + // All bodies sleeping + break; + } + + stepIndex += 1; + } + + printf( " TestMeshDrop stepIndex = %d\n", stepIndex ); + + DestroyMeshDrop( &data ); + b3DestroyWorld( worldId ); + + ENSURE( stepIndex < stepLimit ); + + return 0; +} + // Verifies the b3*_Overflow solver path. The scene puts >B3_DYNAMIC_COLOR_COUNT // dyn-dyn contacts on a single hub body so several land in the overflow color. // The new Prepare/Store contactId-pairing asserts in contact_solver.c fire here @@ -984,290 +878,6 @@ static int EnableContactRecyclingTest( void ) return 0; } -// A slow sphere closes on a static round shape from just outside contact. The step is too short -// to make the sphere fast, so the pair is eligible for recycling. A routine without a speculative -// margin left the pair empty and recycling then let the sphere sink without a contact. Discussion #175. -static int RunRecycledApproach( bool capsuleTarget ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3BodyId targetId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - float targetRadius = 0.5f; - if ( capsuleTarget ) - { - b3Capsule capsule = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, targetRadius }; - b3CreateCapsuleShape( targetId, &shapeDef, &capsule ); - } - else - { - b3Sphere sphere = { b3Vec3_zero, targetRadius }; - b3CreateSphereShape( targetId, &shapeDef, &sphere ); - } - - float radius = 0.25f; - float totalRadius = targetRadius + radius; - float timeStep = 1.0f / 60.0f; - - // Half the speculative distance per step - float speed = 0.5f * B3_SPECULATIVE_DISTANCE / timeStep; - - bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, totalRadius + 0.25f * B3_SPECULATIVE_DISTANCE, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 0.0f, -speed, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3Sphere sphere = { b3Vec3_zero, radius }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - float minSeparation = FLT_MAX; - for ( int i = 0; i < 20; ++i ) - { - b3World_Step( worldId, timeStep, 4 ); - - b3Pos p = b3Body_GetPosition( bodyId ); - minSeparation = b3MinFloat( minSeparation, (float)p.y - totalRadius ); - } - - b3DestroyWorld( worldId ); - - ENSURE( minSeparation > -B3_LINEAR_SLOP ); - - return 0; -} - -static int RecycledSphereApproachTest( void ) -{ - ENSURE( RunRecycledApproach( false ) == 0 ); - ENSURE( RunRecycledApproach( true ) == 0 ); - return 0; -} - -static bool PreSolveReject( b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point, b3Vec3 normal, void* context ) -{ - (void)shapeIdA; - (void)shapeIdB; - (void)point; - (void)normal; - bool* reject = context; - return *reject == false; -} - -// A rejected pre-solve frees the manifold while the shapes may already touch. The next step must -// rebuild the contact and ask again instead of recycling the empty pair. -static int PreSolveRejectRecycleTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.enableSleep = false; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - bool reject = true; - b3World_SetPreSolveCallback( worldId, PreSolveReject, &reject ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 0.0f, -0.5f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 10.0f, 0.5f, 10.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - - float radius = 0.25f; - bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, radius, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - shapeDef.enablePreSolveEvents = true; - b3Sphere sphere = { b3Vec3_zero, radius }; - b3CreateSphereShape( bodyId, &shapeDef, &sphere ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - reject = false; - - float minSeparation = FLT_MAX; - for ( int i = 0; i < 30; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3Pos p = b3Body_GetPosition( bodyId ); - minSeparation = b3MinFloat( minSeparation, (float)p.y - radius ); - } - - b3DestroyWorld( worldId ); - - ENSURE( minSeparation > -B3_LINEAR_SLOP ); - - return 0; -} - -static int CountRecycledResting( bool enableSpeculative ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.enableSleep = false; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 0.0f, -0.5f, 0.0f }; - b3BodyId groundId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull groundBox = b3MakeBoxHull( 10.0f, 0.5f, 10.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( groundId, &shapeDef, &groundBox.base ); - - bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ 0.0f, 0.5f, 0.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - shapeDef.enableSpeculativeContact = enableSpeculative; - b3BoxHull box = b3MakeBoxHull( 0.5f, 0.5f, 0.5f ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - int recycledCount = 0; - for ( int i = 0; i < 60; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - recycledCount += b3World_GetCounters( worldId ).recycledContactCount; - } - - b3DestroyWorld( worldId ); - - return recycledCount; -} - -// Without speculative points an empty pair may be closer than the speculative distance, so these -// contacts must never recycle -static int SpeculativeOffRecycleTest( void ) -{ - ENSURE( CountRecycledResting( true ) > 0 ); - ENSURE( CountRecycledResting( false ) == 0 ); - return 0; -} - -static int CountMovedNodes( const b3DynamicTree* tree ) -{ - int count = 0; - for ( int i = 0; i < tree->nodeEnd; ++i ) - { - const b3TreeNode* node = tree->nodes + i; - if ( b3IsEmptyNode( node ) == false && b3IsNodeMoved( node ) ) - { - count += 1; - } - } - - return count; -} - -// A proxy can be enlarged in one step and destroyed before the next, emptying the move buffer. -// The trees must still be rebuilt or the enlarged nodes survive into the next step. Issue #149. -static int TestEnlargedProxyDestroyed( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.gravity = b3Vec3_zero; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3World* world = b3GetWorldFromId( worldId ); - const b3DynamicTree* tree = world->broadPhase.trees + b3_dynamicBody; - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere sphere = { b3Vec3_zero, 0.25f }; - - // Resting bodies keep the tree deep enough that the mover has an ancestor that outlives it - for ( int i = 0; i < 8; ++i ) - { - bodyDef.position = (b3Pos){ 2.0f * i, 0.0f, 0.0f }; - b3BodyId restingId = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( restingId, &shapeDef, &sphere ); - } - - // This body outruns its AABB margin every step - bodyDef.position = (b3Pos){ 7.0f, 1.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 6.0f, 0.0f, 0.0f }; - b3BodyId moverId = b3CreateBody( worldId, &bodyDef ); - b3CreateSphereShape( moverId, &shapeDef, &sphere ); - - float timeStep = 1.0f / 60.0f; - b3World_Step( worldId, timeStep, 4 ); - - ENSURE( CountMovedNodes( tree ) > 0 ); - - b3DestroyBody( moverId ); - - // Removing the leaf re-derives the marks along its path, so the tree is already consistent - // here and nothing is left marked to drive a rebuild. What the destroy can still leave - // stale is the DFS order the sweep refit needs, so the step has to rebuild regardless. - b3DynamicTree_Validate( tree ); - ENSURE( CountMovedNodes( tree ) == 0 ); - - b3World_Step( worldId, timeStep, 4 ); - - ENSURE( CountMovedNodes( tree ) == 0 ); - ENSURE( tree->dfsOrdered ); - - b3DestroyWorld( worldId ); - return 0; -} - -// b3DestroyBody tears shapes down inline instead of going through the shape destroy path, so it -// needs its own compound census decrement. A leaked count pins the broad-phase on the slow -// per-candidate compound path for the life of the world and rides along into snapshots. -static int TestCompoundShapeCount( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3World* world = b3GetWorldFromId( worldId ); - ENSURE( world->compoundShapeCount == 0 ); - - b3BoxHull box = b3MakeBoxHull( 1.0f, 1.0f, 1.0f ); - - b3CompoundHullDef hull; - hull.hull = &box.base; - hull.transform = (b3Transform){ b3Vec3_zero, b3Quat_identity }; - hull.material = b3DefaultSurfaceMaterial(); - - b3CompoundDef compoundDef = { 0 }; - compoundDef.hulls = &hull; - compoundDef.hullCount = 1; - b3CompoundData* compound = b3CreateCompound( &compoundDef ); - ENSURE( compound != NULL ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - b3ShapeDef shapeDef = b3DefaultShapeDef(); - - // Shape destroyed on its own - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3ShapeId shapeId = b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); - ENSURE( world->compoundShapeCount == 1 ); - b3DestroyShape( shapeId, true ); - ENSURE( world->compoundShapeCount == 0 ); - b3DestroyBody( bodyId ); - - // Shape carried away by its body - bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateBakedCompoundShape( bodyId, &shapeDef, compound ); - ENSURE( world->compoundShapeCount == 1 ); - b3DestroyBody( bodyId ); - ENSURE( world->compoundShapeCount == 0 ); - - b3DestroyWorld( worldId ); - b3DestroyCompound( compound ); - return 0; -} - // Identical hull data is shared through a reference counted world database. static int TestHullDatabase( void ) { @@ -1385,639 +995,6 @@ static int TestExplosion( void ) return 0; } -// Ensure correct move events from bodies involved in CCD. -static int TestContinuousMoveEvent( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - b3World_EnableContinuous( worldId, true ); - - // Thin static wall, near face at x = 0.1 - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_staticBody; - bodyDef.position = (b3Pos){ 0.0f, 0.0f, 0.0f }; - b3BodyId wallId = b3CreateBody( worldId, &bodyDef ); - b3BoxHull wallBox = b3MakeBoxHull( 0.1f, 5.0f, 5.0f ); - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3CreateHullShape( wallId, &shapeDef, &wallBox.base ); - - // Fast dynamic sphere fired at the wall. - bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.gravityScale = 0.0f; - bodyDef.position = (b3Pos){ 3.0f, 0.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ -30.0f, 0.0f, 0.0f }; - b3BodyId ballId = b3CreateBody( worldId, &bodyDef ); - shapeDef = b3DefaultShapeDef(); - shapeDef.density = 1.0f; - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.25f }; - b3CreateSphereShape( ballId, &shapeDef, &sphere ); - - float timeStep = 1.0f / 60.0f; - int subStepCount = 4; - bool haveMove = false; - - for ( int step = 0; step < 30; ++step ) - { - b3World_Step( worldId, timeStep, subStepCount ); - - b3WorldTransform xf = b3Body_GetTransform( ballId ); - - b3BodyEvents events = b3World_GetBodyEvents( worldId ); - for ( int i = 0; i < events.moveCount; ++i ) - { - b3BodyMoveEvent* event = events.moveEvents + i; - if ( B3_ID_EQUALS( event->bodyId, ballId ) == false ) - { - continue; - } - - haveMove = true; - - // The move event must carry the same pose the body reports, CCD rewind included - ENSURE( event->transform.p.x == xf.p.x ); - ENSURE( event->transform.p.y == xf.p.y ); - ENSURE( event->transform.p.z == xf.p.z ); - ENSURE( event->transform.q.v.x == xf.q.v.x ); - ENSURE( event->transform.q.v.y == xf.q.v.y ); - ENSURE( event->transform.q.v.z == xf.q.v.z ); - ENSURE( event->transform.q.s == xf.q.s ); - } - } - - ENSURE( haveMove == true ); - - // Tunnel check - b3Pos finalPos = b3Body_GetPosition( ballId ); - ENSURE( 0.2f < finalPos.x && finalPos.x < 0.8f ); - - b3DestroyWorld( worldId ); - - return 0; -} - -// The contact body sim locators are persistent state. Every contact in every set carries the -// current encoding for both of its bodies: the awake local index, a static tag, or null for a -// body that fell asleep. The scenes below drive each site that can invalidate one. The gate is -// b3ValidateSolverSets, which asserts the invariant on every mutation and every step, so a -// dropped refresh trips there rather than producing a plausible but wrong simulation. Each scene -// also runs at worker counts 1 and 4 with the state hashes compared. - -static b3WorldId CreateLocatorWorld( int workerCount ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = workerCount; - return b3CreateWorld( &worldDef ); -} - -static b3BodyId CreateLocatorBody( b3WorldId worldId, b3BodyType type, b3Pos position, float hx, float hy, float hz ) -{ - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = type; - bodyDef.position = position; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull box = b3MakeBoxHull( hx, hy, hz ); - b3CreateHullShape( bodyId, &shapeDef, &box.base ); - - return bodyId; -} - -static void StepLocatorWorld( b3WorldId worldId, int stepCount ) -{ - for ( int i = 0; i < stepCount; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - } -} - -// Steps until the body sleeps or the budget runs out. Returns the steps taken. -static int StepUntilAsleep( b3WorldId worldId, b3BodyId bodyId, int maxSteps ) -{ - for ( int i = 0; i < maxSteps; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - if ( b3Body_IsAwake( bodyId ) == false ) - { - return i + 1; - } - } - - return maxSteps; -} - -// Sleep and wake: first touch puts contacts in the graph, sleeping nulls the locators of the -// island bodies, waking restores their awake indices. The plate beside the stack holds a -// non-touching contact across the whole cycle, and that is the contact the wake path has to fix up -// itself. A touching contact would get a fresh encoding from the graph add and hide a dropped -// refresh. -static uint64_t LocatorSleepWakeScene( int workerCount, int* failed ) -{ - b3WorldId worldId = CreateLocatorWorld( workerCount ); - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 5.0f, 1.0f, 5.0f ); - - b3BodyId stackId[3]; - for ( int i = 0; i < 3; ++i ) - { - stackId[i] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 0.0f, 0.5f + i, 0.0f }, 0.5f, 0.5f, 0.5f ); - } - - // Beside the top box, close enough that the fat bounds overlap and far enough that the - // shapes never touch. Kinematic and awake, so the contact stays in the awake set while the - // stack sleeps. Off to the side so it does not catch the body dropped later. - b3BodyId plateId = CreateLocatorBody( worldId, b3_kinematicBody, (b3Pos){ 1.04f, 2.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - b3Body_EnableSleep( plateId, false ); - - int steps = StepUntilAsleep( worldId, stackId[0], 300 ); - if ( steps == 300 || b3Body_IsAwake( stackId[2] ) == true ) - { - *failed = 1; - } - - // Wake without contact so the non-touching contact keeps its stale locator if the wake - // path forgets to refresh - b3Body_SetAwake( stackId[0], true ); - StepLocatorWorld( worldId, 5 ); - - if ( b3Body_IsAwake( stackId[2] ) == false ) - { - *failed = 1; - } - - steps = StepUntilAsleep( worldId, stackId[0], 300 ); - if ( steps == 300 ) - { - *failed = 1; - } - - // Dropping a body on the pile drives the wake path through first touch. The pile can settle - // and sleep again, so catch the wake as it happens. - CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 0.0f, 8.0f, 0.0f }, 0.5f, 0.5f, 0.5f ); - - bool woke = false; - for ( int i = 0; i < 180; ++i ) - { - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - woke = woke || b3Body_IsAwake( stackId[0] ); - } - - if ( woke == false ) - { - *failed = 1; - } - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// An island falling asleep and a body leaving the awake set both swap the last awake sim into -// the hole. The pile that never sleeps supplies a moved body that still owns contacts. -static uint64_t LocatorAwakeNeighborScene( int workerCount, int* failed ) -{ - b3WorldId worldId = CreateLocatorWorld( workerCount ); - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 30.0f, 1.0f, 5.0f ); - - // This island sleeps - b3BodyId sleeperId[2]; - for ( int i = 0; i < 2; ++i ) - { - sleeperId[i] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ -10.0f, 0.5f + i, 0.0f }, 0.5f, 0.5f, 0.5f ); - } - - // Created after the sleepers so its sims sit at the end of the awake set and get swapped - // into the holes the sleeping island leaves behind - b3BodyId spareId = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 20.0f, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - b3Body_EnableSleep( spareId, false ); - - b3BodyId awakeId[3]; - for ( int i = 0; i < 3; ++i ) - { - awakeId[i] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 10.0f, 0.5f + i, 0.0f }, 0.5f, 0.5f, 0.5f ); - b3Body_EnableSleep( awakeId[i], false ); - } - - int steps = StepUntilAsleep( worldId, sleeperId[0], 300 ); - if ( steps == 300 || b3Body_IsAwake( awakeId[0] ) == false ) - { - *failed = 1; - } - - StepLocatorWorld( worldId, 10 ); - - // Leaving the awake set swaps a body that owns contacts into the spare's slot - b3Body_Disable( spareId ); - StepLocatorWorld( worldId, 10 ); - - b3Body_Enable( spareId ); - StepLocatorWorld( worldId, 10 ); - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// Destroying a body swaps the last sim of its set into the hole. The moved body keeps its -// contacts, so its side of each one has to follow it. -static uint64_t LocatorDestroyScene( int workerCount, int* failed ) -{ - b3WorldId worldId = CreateLocatorWorld( workerCount ); - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 5.0f, 1.0f, 5.0f ); - - b3BodyId stackId[4]; - for ( int i = 0; i < 4; ++i ) - { - stackId[i] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 0.0f, 0.5f + i, 0.0f }, 0.5f, 0.5f, 0.5f ); - } - - StepLocatorWorld( worldId, 30 ); - - // The last awake sim moves into this hole while its contacts live - b3DestroyBody( stackId[0] ); - StepLocatorWorld( worldId, 30 ); - - // Three static boxes, one resting box each. Destroying the first moves the last static sim. - b3BodyId staticId[3]; - for ( int i = 0; i < 3; ++i ) - { - float x = 10.0f + 4.0f * i; - staticId[i] = CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ x, -1.0f, 0.0f }, 1.0f, 1.0f, 1.0f ); - CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ x, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - } - - StepLocatorWorld( worldId, 30 ); - - b3DestroyBody( staticId[0] ); - StepLocatorWorld( worldId, 30 ); - - B3_UNUSED( failed ); - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// A kinematic body parked a hair above a pile keeps a non-touching contact to a body that falls -// asleep, which is the one case the locator cannot name and has to leave to the cold path. -static uint64_t LocatorKinematicScene( int workerCount, int* failed ) -{ - b3WorldId worldId = CreateLocatorWorld( workerCount ); - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 5.0f, 1.0f, 5.0f ); - - b3BodyId boxId = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 0.0f, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - - // Close enough that the fat bounds overlap and a non-touching contact exists - b3BodyId plateId = CreateLocatorBody( worldId, b3_kinematicBody, (b3Pos){ 0.0f, 1.52f, 0.0f }, 1.0f, 0.5f, 1.0f ); - - int steps = StepUntilAsleep( worldId, boxId, 300 ); - if ( steps == 300 ) - { - *failed = 1; - } - - // Drive the plate down to touch and wake the sleeper - b3Body_SetLinearVelocity( plateId, (b3Vec3){ 0.0f, -1.0f, 0.0f } ); - StepLocatorWorld( worldId, 60 ); - - if ( b3Body_IsAwake( boxId ) == false ) - { - *failed = 1; - } - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// Set type and disable move a body between solver sets, which changes the encoding of every -// contact it has. A joint across two sleeping sets drives the merge path. -static uint64_t LocatorTransferScene( int workerCount, int* failed ) -{ - b3WorldId worldId = CreateLocatorWorld( workerCount ); - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 20.0f, 1.0f, 5.0f ); - - b3BodyId boxId = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 0.0f, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - StepLocatorWorld( worldId, 30 ); - - b3Body_SetType( boxId, b3_staticBody ); - StepLocatorWorld( worldId, 5 ); - b3Body_SetType( boxId, b3_dynamicBody ); - StepLocatorWorld( worldId, 5 ); - - b3Body_Disable( boxId ); - StepLocatorWorld( worldId, 5 ); - b3Body_Enable( boxId ); - StepLocatorWorld( worldId, 30 ); - - // Two piles far enough apart to sleep in separate sets - b3BodyId sleeperId[2]; - sleeperId[0] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ -12.0f, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - sleeperId[1] = CreateLocatorBody( worldId, b3_dynamicBody, (b3Pos){ 12.0f, 0.5f, 0.0f }, 0.5f, 0.5f, 0.5f ); - - int steps = StepUntilAsleep( worldId, sleeperId[0], 300 ); - if ( steps == 300 || b3Body_IsAwake( sleeperId[1] ) == true ) - { - *failed = 1; - } - - b3SphericalJointDef jointDef = b3DefaultSphericalJointDef(); - jointDef.base.bodyIdA = sleeperId[0]; - jointDef.base.bodyIdB = sleeperId[1]; - b3CreateSphericalJoint( worldId, &jointDef ); - - StepLocatorWorld( worldId, 30 ); - - uint64_t hash = b3HashWorldState( b3GetWorldFromId( worldId ) ); - b3DestroyWorld( worldId ); - return hash; -} - -// The fast flag lives on the body sim and gates contact recycling, but a flag sync rebuilds the -// sim flags from the body row, which never carries it. A public setter called on a body in -// flight must not drop it, or the recycle path can take a fast pair. -static int LocatorFastFlagTest( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - b3WorldId worldId = b3CreateWorld( &worldDef ); - - CreateLocatorBody( worldId, b3_staticBody, (b3Pos){ 0.0f, -1.0f, 0.0f }, 5.0f, 1.0f, 5.0f ); - - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -20.0f, 2.0f, 0.0f }; - bodyDef.linearVelocity = (b3Vec3){ 400.0f, 0.0f, 0.0f }; - b3BodyId bulletId = b3CreateBody( worldId, &bodyDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3Sphere sphere = { { 0.0f, 0.0f, 0.0f }, 0.1f }; - b3CreateSphereShape( bulletId, &shapeDef, &sphere ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3World* world = b3GetWorldFromId( worldId ); - b3Body* body = b3GetBodyFullId( world, bulletId ); - b3BodySim* sim = b3GetBodySim( world, body ); - ENSURE( ( sim->flags & b3_isFast ) != 0 ); - - // Any public setter that syncs flags. The locks have to actually change or the setter - // returns early and never syncs. - b3MotionLocks locks = { 0 }; - locks.angularX = true; - b3Body_SetMotionLocks( bulletId, locks ); - - sim = b3GetBodySim( world, b3GetBodyFullId( world, bulletId ) ); - ENSURE( ( sim->flags & b3_isFast ) != 0 ); - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3DestroyWorld( worldId ); - return 0; -} - -static int BodySimLocatorTest( void ) -{ - typedef uint64_t ( *LocatorScene )( int workerCount, int* failed ); - LocatorScene scenes[5] = { - LocatorSleepWakeScene, - LocatorAwakeNeighborScene, - LocatorDestroyScene, - LocatorKinematicScene, - LocatorTransferScene, - }; - - for ( int i = 0; i < 5; ++i ) - { - int failed = 0; - uint64_t hash1 = scenes[i]( 1, &failed ); - uint64_t hash4 = scenes[i]( 4, &failed ); - ENSURE( failed == 0 ); - ENSURE( hash1 == hash4 ); - } - - return LocatorFastFlagTest(); -} - -// A query thread runs static overlaps while the main thread steps. A static body is added before -// each step so the step clears moved flags in the static tree under the reader. Run under TSan -// to check the relaxed flag access. -typedef struct StaticQueryShared -{ - b3WorldId worldId; - b3AtomicInt stepping; - b3AtomicInt quit; - b3AtomicInt idle; - b3AtomicInt started; - b3AtomicInt expectedCount; - b3AtomicInt queryCount; - b3AtomicInt failCount; -} StaticQueryShared; - -typedef struct StaticQueryHits -{ - b3WorldId worldId; - int count; - bool nonStatic; -} StaticQueryHits; - -static bool StaticQueryFcn( b3ShapeId shapeId, void* context ) -{ - StaticQueryHits* hits = context; - b3BodyId bodyId = b3Shape_GetBody( shapeId ); - hits->count += 1; - - // Body type is read through the body array, which the step mutates for awake bodies. Static - // bodies are not touched by the step. - if ( b3Body_GetType( bodyId ) != b3_staticBody ) - { - hits->nonStatic = true; - } - return true; -} - -typedef struct StaticCastHit -{ - int count; - float fraction; - bool nonStatic; -} StaticCastHit; - -static float StaticCastFcn( b3ShapeId shapeId, b3Pos point, b3Vec3 normal, float fraction, uint64_t userMaterialId, - int triangleIndex, int childIndex, void* context ) -{ - B3_UNUSED( point, normal, userMaterialId, triangleIndex, childIndex ); - - StaticCastHit* hit = context; - hit->count += 1; - hit->fraction = fraction; - if ( b3Body_GetType( b3Shape_GetBody( shapeId ) ) != b3_staticBody ) - { - hit->nonStatic = true; - } - return fraction; -} - -static bool CheckStaticQueries( b3WorldId worldId, int expectedCount ) -{ - b3QueryFilter filter = b3DefaultQueryFilter(); - - b3Vec3 corners[8]; - for ( int i = 0; i < 8; ++i ) - { - corners[i] = (b3Vec3){ ( i & 1 ) ? 100.0f : -100.0f, ( i & 2 ) ? 10.0f : -10.0f, ( i & 4 ) ? 100.0f : -100.0f }; - } - b3ShapeProxy boxProxy = { corners, 8, 0.0f }; - - StaticQueryHits hits = { worldId, 0, false }; - b3World_OverlapShape_Static( worldId, b3Pos_zero, &boxProxy, filter, StaticQueryFcn, &hits ); - if ( hits.count != expectedCount || hits.nonStatic ) - { - return false; - } - - // Straight down through the column of a dynamic cube, so only the static tile can answer - b3Pos origin = { 0.5f, 5.0f, -9.5f }; - b3Vec3 translation = { 0.0f, -10.0f, 0.0f }; - - StaticCastHit rayHit = { 0, 1.0f, false }; - b3World_CastRay_Static( worldId, origin, translation, filter, StaticCastFcn, &rayHit ); - if ( rayHit.count == 0 || rayHit.nonStatic || b3AbsFloat( rayHit.fraction - 0.5f ) > 0.001f ) - { - return false; - } - - b3Vec3 center = b3Vec3_zero; - b3ShapeProxy sphereProxy = { ¢er, 1, 0.25f }; - StaticCastHit shapeHit = { 0, 1.0f, false }; - b3World_CastShape_Static( worldId, origin, &sphereProxy, translation, filter, StaticCastFcn, &shapeHit ); - if ( shapeHit.count == 0 || shapeHit.nonStatic || b3AbsFloat( shapeHit.fraction - 0.475f ) > 0.001f ) - { - return false; - } - - return true; -} - -static void StaticQueryThread( void* context ) -{ - StaticQueryShared* shared = context; - b3AABB box = { { -100.0f, -10.0f, -100.0f }, { 100.0f, 10.0f, 100.0f } }; - b3QueryFilter filter = b3DefaultQueryFilter(); - - while ( b3AtomicLoadInt( &shared->quit ) == 0 ) - { - if ( b3AtomicLoadInt( &shared->stepping ) == 0 ) - { - b3AtomicStoreInt( &shared->idle, 1 ); - b3Yield(); - continue; - } - - b3AtomicStoreInt( &shared->idle, 0 ); - b3AtomicStoreInt( &shared->started, 1 ); - int expected = b3AtomicLoadInt( &shared->expectedCount ); - - StaticQueryHits hits = { shared->worldId, 0, false }; - b3World_OverlapAABB_Static( shared->worldId, box, filter, StaticQueryFcn, &hits ); - bool castsPassed = CheckStaticQueries( shared->worldId, expected ); - b3AtomicFetchAddInt( &shared->queryCount, 1 ); - - if ( hits.count != expected || hits.nonStatic || castsPassed == false ) - { - b3AtomicFetchAddInt( &shared->failCount, 1 ); - } - } -} - -static int TestOverlapStaticDuringStep( void ) -{ - b3WorldDef worldDef = b3DefaultWorldDef(); - worldDef.workerCount = 4; - b3WorldId worldId = b3CreateWorld( &worldDef ); - - b3ShapeDef shapeDef = b3DefaultShapeDef(); - b3BoxHull tile = b3MakeBoxHull( 1.0f, 0.5f, 1.0f ); - int staticCount = 0; - - for ( int i = -10; i < 10; ++i ) - { - for ( int j = -10; j < 10; ++j ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ 2.0f * i + 1.0f, -0.5f, 2.0f * j + 1.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &tile.base ); - staticCount += 1; - } - } - - b3BoxHull cube = b3MakeBoxHull( 0.4f, 0.4f, 0.4f ); - for ( int i = 0; i < 400; ++i ) - { - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.type = b3_dynamicBody; - bodyDef.position = (b3Pos){ -9.5f + ( i % 20 ), 1.0f + 0.9f * ( i / 100 ), -9.5f + ( ( i / 20 ) % 5 ) * 4.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &cube.base ); - } - - StaticQueryShared shared = { 0 }; - shared.worldId = worldId; - b3Thread* thread = b3CreateThread( StaticQueryThread, &shared, "static query" ); - - b3BoxHull post = b3MakeBoxHull( 0.1f, 1.0f, 0.1f ); - for ( int step = 0; step < 120; ++step ) - { - // The query thread is idle, so the static tree may change. - b3BodyDef bodyDef = b3DefaultBodyDef(); - bodyDef.position = (b3Pos){ -50.0f + step, 1.0f, 50.0f }; - b3BodyId bodyId = b3CreateBody( worldId, &bodyDef ); - b3CreateHullShape( bodyId, &shapeDef, &post.base ); - staticCount += 1; - - ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) ); - - b3AtomicStoreInt( &shared.expectedCount, staticCount ); - b3AtomicStoreInt( &shared.started, 0 ); - b3AtomicStoreInt( &shared.stepping, 1 ); - - // Scheduling decides how many rounds land inside the step, so only wait for one to begin - while ( b3AtomicLoadInt( &shared.started ) == 0 ) - { - b3Yield(); - } - - b3World_Step( worldId, 1.0f / 60.0f, 4 ); - - b3AtomicStoreInt( &shared.stepping, 0 ); - b3AtomicStoreInt( &shared.idle, 0 ); - while ( b3AtomicLoadInt( &shared.idle ) == 0 ) - { - b3Yield(); - } - - ENSURE( b3HasTreeMoved( b3GetWorldFromId( worldId )->broadPhase.trees + b3_staticBody ) == false ); - } - - b3AtomicStoreInt( &shared.quit, 1 ); - b3JoinThread( thread ); - - // Each step started a round, and the thread cannot report idle until that round finishes - ENSURE( b3AtomicLoadInt( &shared.queryCount ) >= 120 ); - ENSURE( b3AtomicLoadInt( &shared.failCount ) == 0 ); - - // The serial path agrees with the regular overlap filtered to static bodies. - StaticQueryHits hits = { worldId, 0, false }; - b3AABB box = { { -100.0f, -10.0f, -100.0f }, { 100.0f, 10.0f, 100.0f } }; - b3World_OverlapAABB_Static( worldId, box, b3DefaultQueryFilter(), StaticQueryFcn, &hits ); - ENSURE( hits.count == staticCount ); - ENSURE( hits.nonStatic == false ); - ENSURE( CheckStaticQueries( worldId, staticCount ) ); - - b3DestroyWorld( worldId ); - return 0; -} - int WorldTest( void ) { RUN_SUBTEST( HelloWorld ); @@ -2028,25 +1005,17 @@ int WorldTest( void ) RUN_SUBTEST( TestWorldCoverage ); RUN_SUBTEST( TestExplosion ); RUN_SUBTEST( TestSensor ); - RUN_SUBTEST( TestContinuousMoveEvent ); RUN_SUBTEST( TestContactEvents ); RUN_SUBTEST( TestHitEvents ); RUN_SUBTEST( TestCompoundHitEvents ); - RUN_SUBTEST( TestCompoundContactMaterials ); + RUN_SUBTEST( TestMeshDrop ); RUN_SUBTEST( TestOverflowColorPile ); RUN_SUBTEST( SetBulletDriftTest ); RUN_SUBTEST( EnableSleepFlagSyncTest ); RUN_SUBTEST( EnableSleepNoopUnlockTest ); RUN_SUBTEST( EnableContactRecyclingTest ); - RUN_SUBTEST( RecycledSphereApproachTest ); - RUN_SUBTEST( PreSolveRejectRecycleTest ); - RUN_SUBTEST( SpeculativeOffRecycleTest ); RUN_SUBTEST( TestSetWorkerCount ); RUN_SUBTEST( TestHullDatabase ); - RUN_SUBTEST( TestEnlargedProxyDestroyed ); - RUN_SUBTEST( TestCompoundShapeCount ); - RUN_SUBTEST( BodySimLocatorTest ); - RUN_SUBTEST( TestOverlapStaticDuringStep ); return 0; }